-rw-r--r-- | core/applets/vmemo/moc_vmemo.cpp | 2 | ||||
-rw-r--r-- | core/applets/vmemo/vmemo.cpp | 222 |
2 files changed, 108 insertions, 116 deletions
diff --git a/core/applets/vmemo/moc_vmemo.cpp b/core/applets/vmemo/moc_vmemo.cpp index 7e68ac1..fbe1f6b 100644 --- a/core/applets/vmemo/moc_vmemo.cpp +++ b/core/applets/vmemo/moc_vmemo.cpp | |||
@@ -1,8 +1,8 @@ | |||
1 | /**************************************************************************** | 1 | /**************************************************************************** |
2 | ** VMemo meta object code from reading C++ file 'vmemo.h' | 2 | ** VMemo meta object code from reading C++ file 'vmemo.h' |
3 | ** | 3 | ** |
4 | ** Created: Wed Feb 13 17:52:12 2002 | 4 | ** Created: Wed Feb 13 21:49:42 2002 |
5 | ** by: The Qt MOC ($Id$) | 5 | ** by: The Qt MOC ($Id$) |
6 | ** | 6 | ** |
7 | ** WARNING! All changes made in this file will be lost! | 7 | ** WARNING! All changes made in this file will be lost! |
8 | *****************************************************************************/ | 8 | *****************************************************************************/ |
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp index 6bd1622..73bd996 100644 --- a/core/applets/vmemo/vmemo.cpp +++ b/core/applets/vmemo/vmemo.cpp | |||
@@ -1,5 +1,5 @@ | |||
1 | /**************************************************************************************94x78** | 1 | /************************************************************************************ |
2 | ** | 2 | ** |
3 | ** This file may be distributed and/or modified under the terms of the | 3 | ** This file may be distributed and/or modified under the terms of the |
4 | ** GNU General Public License version 2 as published by the Free Software | 4 | ** GNU General Public License version 2 as published by the Free Software |
5 | ** Foundation and appearing in the file LICENSE.GPL included in the | 5 | ** Foundation and appearing in the file LICENSE.GPL included in the |
@@ -7,9 +7,9 @@ | |||
7 | ** | 7 | ** |
8 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 8 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
9 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 9 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
10 | ** | 10 | ** |
11 | *********************************************************************************************/ | 11 | ************************************************************************************/ |
12 | 12 | ||
13 | /* | 13 | /* |
14 | * $Id$ | 14 | * $Id$ |
15 | */ | 15 | */ |
@@ -26,31 +26,31 @@ | |||
26 | #include <string.h> | 26 | #include <string.h> |
27 | #include <stdlib.h> | 27 | #include <stdlib.h> |
28 | 28 | ||
29 | typedef struct _waveheader { | 29 | typedef struct _waveheader { |
30 | u_long main_chunk; /* 'RIFF' */ | 30 | u_long main_chunk; /* 'RIFF' */ |
31 | u_long length; /* filelen */ | 31 | u_long length; /* filelen */ |
32 | u_long chunk_type; /* 'WAVE' */ | 32 | u_long chunk_type; /* 'WAVE' */ |
33 | 33 | ||
34 | u_long sub_chunk; /* 'fmt ' */ | 34 | u_long sub_chunk; /* 'fmt ' */ |
35 | u_long sc_len; /* length of sub_chunk, =16 (chunckSize) */ | 35 | u_long sc_len; /* length of sub_chunk, =16 (chunckSize) */ |
36 | u_short format; /* should be 1 for PCM-code (formatTag) */ | 36 | u_short format; /* should be 1 for PCM-code (formatTag) */ |
37 | u_short modus; /* 1 Mono, 2 Stereo (channels) */ | 37 | u_short modus; /* 1 Mono, 2 Stereo (channels) */ |
38 | u_long sample_fq; /* samples per second (samplesPerSecond) */ | 38 | u_long sample_fq; /* samples per second (samplesPerSecond) */ |
39 | u_long byte_p_sec; /* avg bytes per second (avgBytePerSecond) */ | 39 | u_long byte_p_sec; /* avg bytes per second (avgBytePerSecond) */ |
40 | u_short byte_p_spl; /* samplesize; 1 or 2 bytes (blockAlign) */ | 40 | u_short byte_p_spl; /* samplesize; 1 or 2 bytes (blockAlign) */ |
41 | u_short bit_p_spl; /* 8, 12 or 16 bit (bitsPerSample) */ | 41 | u_short bit_p_spl; /* 8, 12 or 16 bit (bitsPerSample) */ |
42 | 42 | ||
43 | u_long data_chunk; /* 'data' */ | 43 | u_long data_chunk; /* 'data' */ |
44 | u_long data_length; /* samplecount */ | 44 | u_long data_length;/* samplecount */ |
45 | } WaveHeader; | 45 | } WaveHeader; |
46 | 46 | ||
47 | #define RIFF 0x46464952 | 47 | #define RIFF 0x46464952 |
48 | #define WAVE 0x45564157 | 48 | #define WAVE 0x45564157 |
49 | #define FMT 0x20746D66 | 49 | #define FMT 0x20746D66 |
50 | #define DATA 0x61746164 | 50 | #define DATA 0x61746164 |
51 | #define PCM_CODE 1 | 51 | #define PCM_CODE 1 |
52 | #define WAVE_MONO 1 | 52 | #define WAVE_MONO 1 |
53 | #define WAVE_STEREO 2 | 53 | #define WAVE_STEREO 2 |
54 | 54 | ||
55 | #include "vmemo.h" | 55 | #include "vmemo.h" |
56 | 56 | ||
@@ -61,8 +61,9 @@ typedef struct _waveheader { | |||
61 | #include <qpainter.h> | 61 | #include <qpainter.h> |
62 | #include <qdatetime.h> | 62 | #include <qdatetime.h> |
63 | #include <qsound.h> | 63 | #include <qsound.h> |
64 | #include <qfile.h> | 64 | #include <qfile.h> |
65 | #include <qmessagebox.h> | ||
65 | 66 | ||
66 | int seq = 0; | 67 | int seq = 0; |
67 | 68 | ||
68 | /* XPM */ | 69 | /* XPM */ |
@@ -137,18 +138,21 @@ VMemo::VMemo( QWidget *parent, const char *name ) | |||
137 | setFixedWidth( 14 ); | 138 | setFixedWidth( 14 ); |
138 | 139 | ||
139 | recording = FALSE; | 140 | recording = FALSE; |
140 | 141 | ||
141 | struct utsname name; //check for embedix kernel running on the zaurus, if lineo change string, this break | 142 | struct utsname name; /* check for embedix kernel running on the zaurus, if |
142 | if (uname(&name) != -1) { | 143 | lineo change string, this break |
143 | QString release=name.release; | 144 | */ |
144 | if(release.find("embedix",0,TRUE) !=-1) { | 145 | if (uname(&name) != -1) |
145 | systemZaurus=TRUE; | 146 | { |
146 | printf("System release: %s\n", name.release); | 147 | QString release=name.release; |
147 | } else | 148 | qWarning("System release: %s\n", name.release); |
148 | systemZaurus=FALSE; | 149 | if(release.find("embedix",0,TRUE) !=-1) |
149 | } | 150 | systemZaurus=TRUE; |
150 | 151 | else | |
152 | systemZaurus=FALSE; | ||
153 | } | ||
154 | |||
151 | } | 155 | } |
152 | 156 | ||
153 | VMemo::~VMemo() | 157 | VMemo::~VMemo() |
154 | { | 158 | { |
@@ -161,30 +165,37 @@ void VMemo::paintEvent( QPaintEvent* ) | |||
161 | } | 165 | } |
162 | 166 | ||
163 | void VMemo::mousePressEvent( QMouseEvent * ) | 167 | void VMemo::mousePressEvent( QMouseEvent * ) |
164 | { | 168 | { |
169 | // just to be safe | ||
170 | if (recording) | ||
171 | { | ||
172 | recording = FALSE; | ||
173 | return; | ||
174 | } | ||
175 | |||
165 | qWarning("VMemo::mousePress()"); | 176 | qWarning("VMemo::mousePress()"); |
166 | QSound::play(Resource::findSound("vmemob")); | 177 | QSound::play(Resource::findSound("vmemob")); |
167 | 178 | ||
168 | recording = TRUE; | 179 | recording = TRUE; |
169 | qWarning("VMemo::mousePress() -> Starting to record"); | 180 | qWarning("VMemo::mousePress() -> Starting to record"); |
170 | if (openDSP() == -1) | 181 | if (openDSP() == -1) |
171 | { | 182 | { |
172 | // ### Display an error box | 183 | // ### Display an error box |
173 | qWarning("VMemo::mousePress() -> DSP error"); | 184 | QMessageBox::critical(0, "VMemo", "Could not open dsp device.", "Abort"); |
174 | recording = FALSE; | 185 | recording = FALSE; |
175 | return; | 186 | return; |
176 | } | 187 | } |
177 | 188 | ||
178 | Config vmCfg("VMemo"); | 189 | Config vmCfg("VMemo"); |
179 | vmCfg.setGroup("Defaults"); | 190 | vmCfg.setGroup("Defaults"); |
180 | 191 | ||
181 | QDateTime dt = QDateTime::currentDateTime(); | 192 | QDateTime dt = QDateTime::currentDateTime(); |
182 | QString fileName; | 193 | QString fileName; |
183 | if(systemZaurus) | 194 | if(systemZaurus) |
184 | fileName=vmCfg.readEntry("Dir", "/mnt/cf/"); // zaurus does not have /mnt/ramfs | 195 | fileName=vmCfg.readEntry("Dir", "/mnt/cf/"); // zaurus does not have /mnt/ramfs |
185 | else | 196 | else |
186 | fileName=vmCfg.readEntry("Dir", "/mnt/ramfs/"); | 197 | fileName=vmCfg.readEntry("Dir", "/mnt/ramfs/"); |
187 | 198 | ||
188 | fileName += "vm_"; | 199 | fileName += "vm_"; |
189 | fileName += dt.toString(); | 200 | fileName += dt.toString(); |
190 | fileName += ".wav"; | 201 | fileName += ".wav"; |
@@ -195,15 +206,15 @@ void VMemo::mousePressEvent( QMouseEvent * ) | |||
195 | fileName.replace(QRegExp(":"),"."); | 206 | fileName.replace(QRegExp(":"),"."); |
196 | fileName.replace(QRegExp(","),""); | 207 | fileName.replace(QRegExp(","),""); |
197 | 208 | ||
198 | if(openWAV(fileName.latin1()) == -1) | 209 | if(openWAV(fileName.latin1()) == -1) |
199 | { | 210 | { |
200 | // ### Display an error box | 211 | // ### Display an error box |
201 | qWarning("VMemo::mousePress() -> WAV error"); | 212 | qWarning("VMemo::mousePress() -> WAV error"); |
202 | close(dsp); | 213 | close(dsp); |
203 | return; | 214 | return; |
204 | } | 215 | } |
205 | 216 | ||
206 | QArray<int> cats(1); | 217 | QArray<int> cats(1); |
207 | cats[0] = vmCfg.readNumEntry("Category", 0); | 218 | cats[0] = vmCfg.readNumEntry("Category", 0); |
208 | 219 | ||
209 | QString dlName("vm_"); | 220 | QString dlName("vm_"); |
@@ -221,9 +232,8 @@ void VMemo::mousePressEvent( QMouseEvent * ) | |||
221 | void VMemo::mouseReleaseEvent( QMouseEvent * ) | 232 | void VMemo::mouseReleaseEvent( QMouseEvent * ) |
222 | { | 233 | { |
223 | qWarning("VMemo::mouseRelese() -> Done recording"); | 234 | qWarning("VMemo::mouseRelese() -> Done recording"); |
224 | recording = FALSE; | 235 | recording = FALSE; |
225 | QSound::play(Resource::findSound("vmemoe")); | ||
226 | } | 236 | } |
227 | 237 | ||
228 | int VMemo::openDSP() | 238 | int VMemo::openDSP() |
229 | { | 239 | { |
@@ -232,83 +242,66 @@ int VMemo::openDSP() | |||
232 | 242 | ||
233 | speed = cfg.readNumEntry("SampleRate", 11025); | 243 | speed = cfg.readNumEntry("SampleRate", 11025); |
234 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) | 244 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) |
235 | if (cfg.readNumEntry("SixteenBit", 1)) | 245 | if (cfg.readNumEntry("SixteenBit", 1)) |
236 | { | 246 | { |
237 | format = AFMT_S16_LE; | 247 | format = AFMT_S16_LE; |
238 | resolution = 16; | 248 | resolution = 16; |
239 | } | 249 | } |
240 | else | 250 | else |
241 | { | 251 | { |
242 | format = AFMT_U8; | 252 | format = AFMT_U8; |
243 | resolution = 8; | 253 | resolution = 8; |
244 | } | 254 | } |
245 | 255 | ||
246 | if(systemZaurus) | 256 | if(systemZaurus) |
247 | dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1 | 257 | dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1 |
248 | else | 258 | else |
249 | dsp = open("/dev/dsp", O_RDWR); | 259 | dsp = open("/dev/dsp", O_RDWR); |
250 | 260 | ||
251 | qWarning("speed = %i", speed); | ||
252 | |||
253 | if(dsp == -1) | 261 | if(dsp == -1) |
254 | { | 262 | { |
255 | perror("open(\"/dev/dsp\")"); | 263 | perror("open(\"/dev/dsp\")"); |
256 | return -1; | 264 | return -1; |
257 | } | 265 | } |
258 | 266 | ||
259 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { | 267 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) |
260 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); | 268 | { |
261 | return -1; | 269 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); |
262 | } | 270 | return -1; |
263 | if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { | 271 | } |
264 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); | 272 | if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) |
265 | return -1; | 273 | { |
266 | } | 274 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); |
267 | if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { | 275 | return -1; |
268 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); | 276 | } |
269 | return -1; | 277 | if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) |
270 | } | 278 | { |
271 | if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { | 279 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); |
272 | perror("ioctl(\"SOUND_PCM_READ_RATE\")"); | 280 | return -1; |
273 | return -1; | 281 | } |
274 | } | 282 | if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) |
275 | qWarning("speed = %i", speed); | 283 | { |
276 | 284 | perror("ioctl(\"SOUND_PCM_READ_RATE\")"); | |
285 | return -1; | ||
286 | } | ||
287 | |||
277 | return 1; | 288 | return 1; |
278 | } | 289 | } |
279 | 290 | ||
280 | int VMemo::openWAV(const char *filename) | 291 | int VMemo::openWAV(const char *filename) |
281 | { | 292 | { |
282 | char buffer[256]; | ||
283 | |||
284 | qDebug("Creating %s ",filename); | 293 | qDebug("Creating %s ",filename); |
285 | track.setName(filename); | 294 | track.setName(filename); |
286 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) | 295 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) |
287 | { | 296 | { |
288 | qDebug("Could not open file"); | 297 | qDebug("Could not open file"); |
289 | return -1; | 298 | return -1; |
290 | } | 299 | } |
291 | wav=track.handle(); | 300 | wav=track.handle(); |
292 | 301 | ||
293 | WaveHeader wh; | 302 | WaveHeader wh; |
294 | 303 | ||
295 | /* | ||
296 | wh.main_chunk = RIFF; | ||
297 | wh.length = 0; | ||
298 | wh.chunk_type = WAVE; | ||
299 | wh.sub_chunk = FMT; | ||
300 | wh.sc_len = 16; | ||
301 | wh.format = PCM_CODE; | ||
302 | wh.modus = channels; | ||
303 | wh.sample_fq = speed; | ||
304 | wh.byte_p_spl = ((resolution == 8) ? 1 : 2) * (channels ? 2 : 1); | ||
305 | wh.byte_p_sec = resolution; //speed * wh.modus * wh.byte_p_spl; | ||
306 | wh.bit_p_spl = resolution; | ||
307 | wh.data_chunk = DATA; | ||
308 | wh.data_length= 0; | ||
309 | */ | ||
310 | |||
311 | wh.main_chunk = RIFF; | 304 | wh.main_chunk = RIFF; |
312 | wh.length = 0; | 305 | wh.length = 0; |
313 | wh.chunk_type = WAVE; | 306 | wh.chunk_type = WAVE; |
314 | 307 | ||
@@ -320,14 +313,8 @@ int VMemo::openWAV(const char *filename) | |||
320 | wh.bit_p_spl = resolution; | 313 | wh.bit_p_spl = resolution; |
321 | wh.byte_p_sec = wh.sample_fq * wh.bit_p_spl; | 314 | wh.byte_p_sec = wh.sample_fq * wh.bit_p_spl; |
322 | wh.byte_p_spl = channels * (wh.bit_p_spl % 8); | 315 | wh.byte_p_spl = channels * (wh.bit_p_spl % 8); |
323 | 316 | ||
324 | qWarning("channels = %i\n" | ||
325 | "samplesPerSecond = %i\n" | ||
326 | "avgBytesPerSecond = %i\n" | ||
327 | "blockAlign = %i\n" | ||
328 | "bitsPerSecond = %i\n", wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl); | ||
329 | |||
330 | wh.data_chunk = DATA; | 317 | wh.data_chunk = DATA; |
331 | wh.data_length= 0; | 318 | wh.data_length= 0; |
332 | 319 | ||
333 | write (wav, &wh, sizeof(WaveHeader)); | 320 | write (wav, &wh, sizeof(WaveHeader)); |
@@ -342,15 +329,17 @@ void VMemo::record(void) | |||
342 | 329 | ||
343 | qWarning("VMemo::record()"); | 330 | qWarning("VMemo::record()"); |
344 | 331 | ||
345 | while(recording) | 332 | while(recording) |
346 | { | 333 | { |
347 | result = read(dsp, sound, 8192); | 334 | result = read(dsp, sound, 512); // 8192 |
348 | write(wav, sound, result); | 335 | qApp->processEvents(); |
349 | length += result; | 336 | write(wav, sound, result); |
350 | qApp->processEvents(); | 337 | qApp->processEvents(); |
351 | } | 338 | length += result; |
352 | 339 | qApp->processEvents(); | |
340 | } | ||
341 | |||
353 | qWarning("VMemo::record() -> Done recording"); | 342 | qWarning("VMemo::record() -> Done recording"); |
354 | qWarning("VMemo::record() -> Closing dsp"); | 343 | qWarning("VMemo::record() -> Closing dsp"); |
355 | 344 | ||
356 | value = length+36; | 345 | value = length+36; |
@@ -360,9 +349,12 @@ void VMemo::record(void) | |||
360 | write(wav, &length, 4); | 349 | write(wav, &length, 4); |
361 | track.close(); | 350 | track.close(); |
362 | 351 | ||
363 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1)// ); //tell driver to stop for a while | 352 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1)// ); //tell driver to stop for a while |
364 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); | 353 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); |
365 | ::close(dsp); | 354 | ::close(dsp); |
366 | 355 | ||
356 | qWarning("VMemo::record() -> playing done recording sound"); | ||
357 | QSound::play(Resource::findSound("vmemoe")); | ||
367 | qWarning("VMemo::record() -> terminating"); | 358 | qWarning("VMemo::record() -> terminating"); |
359 | QMessageBox::information(0, "VMemo", "Recording Done", 1); | ||
368 | } | 360 | } |