author | llornkcor <llornkcor> | 2002-03-20 02:23:27 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-03-20 02:23:27 (UTC) |
commit | f1228641b5ee823d309a8e5773e5b6fe94e64a42 (patch) (unidiff) | |
tree | c0134979ae69dab0b0999c0cc83ef941967389b9 | |
parent | ea1f3581a3452f735bb0cf5703b9bf1b20316b71 (diff) | |
download | opie-f1228641b5ee823d309a8e5773e5b6fe94e64a42.zip opie-f1228641b5ee823d309a8e5773e5b6fe94e64a42.tar.gz opie-f1228641b5ee823d309a8e5773e5b6fe94e64a42.tar.bz2 |
fixed my blunder, I hope
-rw-r--r-- | core/applets/vmemo/vmemo.cpp | 118 |
1 files changed, 59 insertions, 59 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp index 9d69130..fea673c 100644 --- a/core/applets/vmemo/vmemo.cpp +++ b/core/applets/vmemo/vmemo.cpp | |||
@@ -119,73 +119,73 @@ static char * vmemo_xpm[] = { | |||
119 | "g c #3D3D3D", | 119 | "g c #3D3D3D", |
120 | "h c #1F1F1F", | 120 | "h c #1F1F1F", |
121 | " .+@ ", | 121 | " .+@ ", |
122 | " #$%&* ", | 122 | " #$%&* ", |
123 | " =-;>,')", | 123 | " =-;>,')", |
124 | " .$;!~,)", | 124 | " .$;!~,)", |
125 | " ;#{]!)", | 125 | " ;#{]!)", |
126 | " ^~/(_)", | 126 | " ^~/(_)", |
127 | " ./:@<[)", | 127 | " ./:@<[)", |
128 | " }. .|]1;;2 ", | 128 | " }. .|]1;;2 ", |
129 | " #-$;^/3&;;4@ ", | 129 | " #-$;^/3&;;4@ ", |
130 | ".$;;#5:67;89 ", | 130 | ".$;;#5:67;89 ", |
131 | ":%;0%&ab;8. ", | 131 | ":%;0%&ab;8. ", |
132 | "@cd%e!fg49 ", | 132 | "@cd%e!fg49 ", |
133 | " h0,!_;2@ ", | 133 | " h0,!_;2@ ", |
134 | " ))))) "}; | 134 | " ))))) "}; |
135 | 135 | ||
136 | VMemo::VMemo( QWidget *parent, const char *name ) | 136 | VMemo::VMemo( QWidget *parent, const char *name ) |
137 | : QWidget( parent, name ) | 137 | : QWidget( parent, name ) |
138 | { | 138 | { |
139 | setFixedHeight( 18 ); | 139 | setFixedHeight( 18 ); |
140 | setFixedWidth( 14 ); | 140 | setFixedWidth( 14 ); |
141 | 141 | ||
142 | recording = FALSE; | 142 | recording = FALSE; |
143 | 143 | ||
144 | struct utsname name; /* check for embedix kernel running on the zaurus*/ | 144 | struct utsname name; /* check for embedix kernel running on the zaurus*/ |
145 | if (uname(&name) != -1) { | 145 | if (uname(&name) != -1) { |
146 | QString release=name.release; | 146 | QString release=name.release; |
147 | if(release.find("embedix",0,TRUE) !=-1) | 147 | if(release.find("embedix",0,TRUE) !=-1) |
148 | systemZaurus=TRUE; | 148 | systemZaurus=TRUE; |
149 | else { | 149 | else { |
150 | systemZaurus=FALSE; | 150 | systemZaurus=FALSE; |
151 | // myChannel = new QCopChannel( "QPE/VMemo", this ); | 151 | myChannel = new QCopChannel( "QPE/VMemo", this ); |
152 | // connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), | 152 | connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), |
153 | // this, SLOT(receive(const QCString&, const QByteArray&)) ); | 153 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
154 | 154 | ||
155 | // // Register the REC key press, for ipaq only | 155 | // // Register the REC key press, for ipaq only |
156 | // QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)"); | 156 | QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)"); |
157 | // e << 4096; | 157 | e << 4096; |
158 | // e << QString("QPE/VMemo"); | 158 | e << QString("QPE/VMemo"); |
159 | // e << QString("toggleRecord()"); | 159 | e << QString("toggleRecord()"); |
160 | } | 160 | } |
161 | } | 161 | } |
162 | } | 162 | } |
163 | 163 | ||
164 | VMemo::~VMemo() | 164 | VMemo::~VMemo() |
165 | { | 165 | { |
166 | } | 166 | } |
167 | 167 | ||
168 | void VMemo::receive( const QCString &msg, const QByteArray &data ) | 168 | void VMemo::receive( const QCString &msg, const QByteArray &data ) |
169 | { | 169 | { |
170 | QDataStream stream( data, IO_ReadOnly ); | 170 | QDataStream stream( data, IO_ReadOnly ); |
171 | if (msg == "toggleRecord()") | 171 | if (msg == "toggleRecord()") |
172 | { | 172 | { |
173 | if (recording) | 173 | if (recording) |
174 | mouseReleaseEvent(NULL); | 174 | mouseReleaseEvent(NULL); |
175 | else | 175 | else |
176 | mousePressEvent(NULL); | 176 | mousePressEvent(NULL); |
177 | } | 177 | } |
178 | } | 178 | } |
179 | 179 | ||
180 | void VMemo::paintEvent( QPaintEvent* ) | 180 | void VMemo::paintEvent( QPaintEvent* ) |
181 | { | 181 | { |
182 | QPainter p(this); | 182 | QPainter p(this); |
183 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); | 183 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); |
184 | } | 184 | } |
185 | 185 | ||
186 | void VMemo::mousePressEvent( QMouseEvent *me ) | 186 | void VMemo::mousePressEvent( QMouseEvent *me ) |
187 | { | 187 | { |
188 | // just to be safe | 188 | // just to be safe |
189 | if (recording) | 189 | if (recording) |
190 | { | 190 | { |
191 | recording = FALSE; | 191 | recording = FALSE; |
@@ -242,193 +242,193 @@ void VMemo::mousePressEvent( QMouseEvent *me ) | |||
242 | 242 | ||
243 | QArray<int> cats(1); | 243 | QArray<int> cats(1); |
244 | cats[0] = vmCfg.readNumEntry("Category", 0); | 244 | cats[0] = vmCfg.readNumEntry("Category", 0); |
245 | 245 | ||
246 | QString dlName("vm_"); | 246 | QString dlName("vm_"); |
247 | dlName += dt.toString(); | 247 | dlName += dt.toString(); |
248 | DocLnk l; | 248 | DocLnk l; |
249 | l.setFile(fileName); | 249 | l.setFile(fileName); |
250 | l.setName(dlName); | 250 | l.setName(dlName); |
251 | l.setType("audio/x-wav"); | 251 | l.setType("audio/x-wav"); |
252 | l.setCategories(cats); | 252 | l.setCategories(cats); |
253 | l.writeLink(); | 253 | l.writeLink(); |
254 | 254 | ||
255 | record(); | 255 | record(); |
256 | } | 256 | } |
257 | 257 | ||
258 | void VMemo::mouseReleaseEvent( QMouseEvent * ) | 258 | void VMemo::mouseReleaseEvent( QMouseEvent * ) |
259 | { | 259 | { |
260 | recording = FALSE; | 260 | recording = FALSE; |
261 | } | 261 | } |
262 | 262 | ||
263 | int VMemo::openDSP() | 263 | int VMemo::openDSP() |
264 | { | 264 | { |
265 | Config cfg("Sound"); | 265 | Config cfg("Sound"); |
266 | cfg.setGroup("Record"); | 266 | cfg.setGroup("Record"); |
267 | 267 | ||
268 | speed = cfg.readNumEntry("SampleRate", 22050); | 268 | speed = cfg.readNumEntry("SampleRate", 22050); |
269 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) | 269 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) |
270 | if (cfg.readNumEntry("SixteenBit", 1)==1) { | 270 | if (cfg.readNumEntry("SixteenBit", 1)==1) { |
271 | format = AFMT_S16_LE; | 271 | format = AFMT_S16_LE; |
272 | resolution = 16; | 272 | resolution = 16; |
273 | } | 273 | } |
274 | // else { | 274 | else { |
275 | // format = AFMT_U8; | 275 | format = AFMT_S8; |
276 | // resolution = 8; | 276 | resolution = 8; |
277 | // } | 277 | } |
278 | 278 | ||
279 | if(systemZaurus) { | 279 | if(systemZaurus) { |
280 | dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1 | 280 | dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1 |
281 | channels=1; //zaurus has one input channel | 281 | channels=1; //zaurus has one input channel |
282 | } else { | 282 | } else { |
283 | dsp = open("/dev/dsp", O_RDWR); | 283 | dsp = open("/dev/dsp", O_RDWR); |
284 | } | 284 | } |
285 | 285 | ||
286 | if(dsp == -1) { | 286 | if(dsp == -1) { |
287 | perror("open(\"/dev/dsp\")"); | 287 | perror("open(\"/dev/dsp\")"); |
288 | return -1; | 288 | return -1; |
289 | } | 289 | } |
290 | 290 | ||
291 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { | 291 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { |
292 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); | 292 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); |
293 | return -1; | 293 | return -1; |
294 | } | 294 | } |
295 | if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { | 295 | if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { |
296 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); | 296 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); |
297 | return -1; | 297 | return -1; |
298 | } | 298 | } |
299 | if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { | 299 | if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { |
300 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); | 300 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); |
301 | return -1; | 301 | return -1; |
302 | } | 302 | } |
303 | if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { | 303 | if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { |
304 | perror("ioctl(\"SOUND_PCM_READ_RATE\")"); | 304 | perror("ioctl(\"SOUND_PCM_READ_RATE\")"); |
305 | return -1; | 305 | return -1; |
306 | } | 306 | } |
307 | 307 | ||
308 | return 1; | 308 | return 1; |
309 | } | 309 | } |
310 | 310 | ||
311 | int VMemo::openWAV(const char *filename) | 311 | int VMemo::openWAV(const char *filename) |
312 | { | 312 | { |
313 | track.setName(filename); | 313 | track.setName(filename); |
314 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) | 314 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) |
315 | return -1; | 315 | return -1; |
316 | 316 | ||
317 | wav=track.handle(); | 317 | wav=track.handle(); |
318 | 318 | ||
319 | WaveHeader wh; | 319 | WaveHeader wh; |
320 | 320 | ||
321 | wh.main_chunk = RIFF; | 321 | wh.main_chunk = RIFF; |
322 | wh.length=0; | 322 | wh.length=0; |
323 | wh.chunk_type = WAVE; | 323 | wh.chunk_type = WAVE; |
324 | wh.sub_chunk = FMT; | 324 | wh.sub_chunk = FMT; |
325 | wh.sc_len = 16; | 325 | wh.sc_len = 16; |
326 | wh.format = PCM_CODE; | 326 | wh.format = PCM_CODE; |
327 | wh.modus = channels; | 327 | wh.modus = channels; |
328 | wh.sample_fq = speed; | 328 | wh.sample_fq = speed; |
329 | wh.byte_p_sec = speed * channels * resolution/8; | 329 | wh.byte_p_sec = speed * channels * resolution/8; |
330 | wh.byte_p_spl = channels * (resolution / 8); | 330 | wh.byte_p_spl = channels * (resolution / 8); |
331 | wh.bit_p_spl = resolution; | 331 | wh.bit_p_spl = resolution; |
332 | wh.data_chunk = DATA; | 332 | wh.data_chunk = DATA; |
333 | wh.data_length= 0; | 333 | wh.data_length= 0; |
334 | // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" | 334 | // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" |
335 | // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); | 335 | // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); |
336 | write (wav, &wh, sizeof(WaveHeader)); | 336 | write (wav, &wh, sizeof(WaveHeader)); |
337 | 337 | ||
338 | return 1; | 338 | return 1; |
339 | } | 339 | } |
340 | 340 | ||
341 | void VMemo::record(void) | 341 | void VMemo::record(void) |
342 | { | 342 | { |
343 | int length=0, result, value; | 343 | int length=0, result, value; |
344 | qDebug("Recording"); | 344 | qDebug("Recording"); |
345 | 345 | ||
346 | if(format==AFMT_S16_LE) { | 346 | if(systemZaurus) { |
347 | signed short sound[512], monoBuffer[512]; | 347 | signed short sound[512], monoBuffer[512]; |
348 | |||
349 | if(format==AFMT_S16_LE) { | ||
348 | while(recording) { | 350 | while(recording) { |
349 | result = read(dsp, sound, 512); // 8192 | 351 | result = read(dsp, sound, 512); // 8192 |
350 | qApp->processEvents(); | 352 | qApp->processEvents(); |
351 | int j=0; | 353 | int j=0; |
352 | if(systemZaurus) { | 354 | if(systemZaurus) { |
353 | for (int i = 0; i < result; i++) { //since Z is mono do normally | 355 | for (int i = 0; i < result; i++) { //since Z is mono do normally |
354 | monoBuffer[i] = sound[i]; | 356 | monoBuffer[i] = sound[i]; |
355 | } | 357 | } |
356 | qApp->processEvents(); | 358 | qApp->processEvents(); |
357 | length+=write(wav, monoBuffer, result); | 359 | length+=write(wav, monoBuffer, result); |
358 | } else { //ipaq /stereo inputs | 360 | } else { //ipaq /stereo inputs |
359 | for (int i = 0; i < result; i+=2) { | 361 | for (int i = 0; i < result; i+=2) { |
360 | monoBuffer[j] = (sound[i]+sound[i+1])/2; | 362 | monoBuffer[j] = (sound[i]+sound[i+1])/2; |
361 | j++; | 363 | j++; |
362 | } | 364 | } |
363 | qApp->processEvents(); | 365 | qApp->processEvents(); |
364 | length+=write(wav, monoBuffer, result/2); | 366 | length+=write(wav, monoBuffer, result/2); |
365 | } | 367 | } |
366 | printf("%d\r",length); | 368 | printf("%d\r",length); |
367 | fflush(stdout); | 369 | fflush(stdout); |
368 | } | 370 | } |
369 | } | 371 | } |
370 | // else { //AFMT_U8 // don't try this yet.. as player doesn't understand | 372 | else { //AFMT_S8 // don't try this yet.. as player doesn't understand 8bit unsigned |
371 | // 8bit unsigned | 373 | while(recording) |
372 | // unsigned short sound[512], monoBuffer[512]; | 374 | { |
373 | // while(recording) | 375 | result = read(dsp, sound, 512); // 8192 |
374 | // { | 376 | qApp->processEvents(); |
375 | // result = read(dsp, sound, 512); // 8192 | 377 | int j=0; |
376 | // qApp->processEvents(); | 378 | if(systemZaurus) |
377 | // int j=0; | 379 | { |
378 | // if(systemZaurus) | 380 | for (int i = 0; i < result; i++) { //since Z is mono do normally |
379 | // { | 381 | monoBuffer[i] = sound[i]; |
380 | // for (int i = 0; i < result; i++) { //since Z is mono do normally | 382 | } |
381 | // monoBuffer[i] = sound[i]; | 383 | qApp->processEvents(); |
382 | // } | 384 | length+=write(wav, monoBuffer, result); |
383 | // qApp->processEvents(); | 385 | } else { //ipaq /stereo inputs |
384 | // length+=write(wav, monoBuffer, result); | 386 | for (int i = 0; i < result; i+=2) { |
385 | // } else { //ipaq /stereo inputs | 387 | monoBuffer[j] = (sound[i]+sound[i+1])/2; |
386 | // for (int i = 0; i < result; i+=2) { | 388 | j++; |
387 | // monoBuffer[j] = (sound[i]+sound[i+1])/2; | 389 | } |
388 | // j++; | 390 | qApp->processEvents(); |
389 | // } | 391 | length+=write(wav, monoBuffer, result/2); |
390 | // qApp->processEvents(); | 392 | } |
391 | // length+=write(wav, monoBuffer, result/2); | 393 | length += result; |
392 | // } | 394 | printf("%d\r",length); |
393 | // // length += result; | 395 | fflush(stdout); |
394 | // printf("%d\r",length); | 396 | |
395 | // fflush(stdout); | 397 | qApp->processEvents(); |
396 | 398 | } | |
397 | // qApp->processEvents(); | 399 | } |
398 | // } | ||
399 | // } | ||
400 | 400 | ||
401 | } else { | ||
401 | 402 | ||
402 | 403 | char sound[512]; //char is 8 bit | |
403 | // char sound[512]; //char is 8 bit | ||
404 | |||
405 | // while(recording) | ||
406 | // { | ||
407 | // result = read(dsp, sound, 512); // 8192 | ||
408 | // qApp->processEvents(); | ||
409 | 404 | ||
410 | // write(wav, sound, result); | 405 | while(recording) |
411 | // length += result; | 406 | { |
407 | result = read(dsp, sound, 512); // 8192 | ||
408 | qApp->processEvents(); | ||
409 | |||
410 | write(wav, sound, result); | ||
411 | length += result; | ||
412 | 412 | ||
413 | // qApp->processEvents(); | 413 | qApp->processEvents(); |
414 | // } | 414 | } |
415 | // qDebug("file has length of %d lasting %d seconds", | 415 | // qDebug("file has length of %d lasting %d seconds", |
416 | // length, (( length / speed) / channels) / 2 ); | 416 | // length, (( length / speed) / channels) / 2 ); |
417 | // medialplayer states wrong length in secs | 417 | // medialplayer states wrong length in secs |
418 | 418 | } | |
419 | 419 | ||
420 | value = length+36; | 420 | value = length+36; |
421 | lseek(wav, 4, SEEK_SET); | 421 | lseek(wav, 4, SEEK_SET); |
422 | write(wav, &value, 4); | 422 | write(wav, &value, 4); |
423 | lseek(wav, 40, SEEK_SET); | 423 | lseek(wav, 40, SEEK_SET); |
424 | write(wav, &length, 4); | 424 | write(wav, &length, 4); |
425 | track.close(); | 425 | track.close(); |
426 | 426 | ||
427 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) | 427 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) |
428 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); | 428 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); |
429 | ::close(dsp); | 429 | ::close(dsp); |
430 | // if(systemZaurus) | 430 | if(systemZaurus) |
431 | QMessageBox::message("Vmemo"," Done recording"); | 431 | QMessageBox::message("Vmemo"," Done recording"); |
432 | 432 | ||
433 | QSound::play(Resource::findSound("vmemoe")); | 433 | QSound::play(Resource::findSound("vmemoe")); |
434 | } | 434 | } |