-rw-r--r-- | core/applets/vmemo/vmemo.cpp | 31 |
1 files changed, 11 insertions, 20 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp index 118fcde..e14d532 100644 --- a/core/applets/vmemo/vmemo.cpp +++ b/core/applets/vmemo/vmemo.cpp | |||
@@ -1,35 +1,36 @@ | |||
1 | /************************************************************************************ | 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 |
6 | ** packaging of this file. | 6 | ** packaging of this file. |
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 | // copyright 2002 Jeremy Cowgar <jc@cowgar.com> | ||
12 | /* | 13 | /* |
13 | * $Id$ | 14 | * $Id$ |
14 | */ | 15 | */ |
15 | // Sun 03-17-2002 L.J.Potter <ljp@llornkcor.com> | 16 | // Sun 03-17-2002 L.J.Potter <ljp@llornkcor.com> |
16 | #include <sys/utsname.h> | 17 | #include <sys/utsname.h> |
17 | #include <sys/time.h> | 18 | #include <sys/time.h> |
18 | #include <sys/types.h> | 19 | #include <sys/types.h> |
19 | #include <unistd.h> | 20 | #include <unistd.h> |
20 | #include <stdio.h> | 21 | #include <stdio.h> |
21 | #include <sys/stat.h> | 22 | #include <sys/stat.h> |
22 | #include <fcntl.h> | 23 | #include <fcntl.h> |
23 | #include <sys/ioctl.h> | 24 | #include <sys/ioctl.h> |
24 | #include <linux/soundcard.h> | 25 | #include <linux/soundcard.h> |
25 | 26 | ||
26 | #include <string.h> | 27 | #include <string.h> |
27 | #include <stdlib.h> | 28 | #include <stdlib.h> |
28 | #include <errno.h> | 29 | #include <errno.h> |
29 | 30 | ||
30 | typedef struct _waveheader { | 31 | typedef struct _waveheader { |
31 | u_long main_chunk; /* 'RIFF' */ | 32 | u_long main_chunk; /* 'RIFF' */ |
32 | u_long length; /* filelen */ | 33 | u_long length; /* filelen */ |
33 | u_long chunk_type; /* 'WAVE' */ | 34 | u_long chunk_type; /* 'WAVE' */ |
34 | u_long sub_chunk; /* 'fmt ' */ | 35 | u_long sub_chunk; /* 'fmt ' */ |
35 | u_long sc_len; /* length of sub_chunk, =16 | 36 | u_long sc_len; /* length of sub_chunk, =16 |
@@ -233,52 +234,52 @@ void VMemo::receive( const QCString &msg, const QByteArray &data ) | |||
233 | mouseReleaseEvent(NULL); | 234 | mouseReleaseEvent(NULL); |
234 | else | 235 | else |
235 | mousePressEvent(NULL); | 236 | mousePressEvent(NULL); |
236 | } | 237 | } |
237 | } | 238 | } |
238 | 239 | ||
239 | void VMemo::paintEvent( QPaintEvent* ) | 240 | void VMemo::paintEvent( QPaintEvent* ) |
240 | { | 241 | { |
241 | QPainter p(this); | 242 | QPainter p(this); |
242 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); | 243 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); |
243 | } | 244 | } |
244 | 245 | ||
245 | void VMemo::mousePressEvent( QMouseEvent *me ) | 246 | void VMemo::mousePressEvent( QMouseEvent *me ) |
246 | { | 247 | { |
247 | // just to be safe | 248 | // just to be safe |
248 | if (recording) { | 249 | if (recording) { |
249 | recording = FALSE; | 250 | recording = FALSE; |
250 | return; | 251 | return; |
251 | } | 252 | } |
252 | 253 | ||
253 | /* | 254 | /* |
254 | No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions | 255 | No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions |
255 | mousePressEvent and mouseReleaseEvent with a NULL parameter. | 256 | mousePressEvent and mouseReleaseEvent with a NULL parameter. |
256 | */ | 257 | */ |
257 | #if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) | 258 | // #if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) |
258 | if (!systemZaurus ) | 259 | // if (!systemZaurus ) |
259 | return; | 260 | // return; |
260 | #endif | 261 | // #endif |
261 | 262 | ||
262 | Config config( "Sound" ); | 263 | Config config( "Sound" ); |
263 | config.setGroup( "System" ); | 264 | config.setGroup( "System" ); |
264 | useAlerts = config.readBoolEntry("Alert"); | 265 | useAlerts = config.readBoolEntry("Alert"); |
265 | 266 | ||
266 | // if(useAlerts) | 267 | // if(useAlerts) |
267 | // QMessageBox::message("VMemo","Really Record?");//) ==1) | 268 | // QMessageBox::message("VMemo","Really Record?");//) ==1) |
268 | // return; | 269 | // return; |
269 | // } else { | 270 | // } else { |
270 | if (!systemZaurus ) | 271 | if (!systemZaurus ) |
271 | QSound::play(Resource::findSound("vmemob")); | 272 | QSound::play(Resource::findSound("vmemob")); |
272 | // } | 273 | // } |
273 | qDebug("Start recording"); | 274 | qDebug("Start recording"); |
274 | recording = TRUE; | 275 | recording = TRUE; |
275 | if (openDSP() == -1) { | 276 | if (openDSP() == -1) { |
276 | QMessageBox::critical(0, "VMemo", "Could not open dsp device.\n"+errorMsg, "Abort"); | 277 | QMessageBox::critical(0, "VMemo", "Could not open dsp device.\n"+errorMsg, "Abort"); |
277 | recording = FALSE; | 278 | recording = FALSE; |
278 | return; | 279 | return; |
279 | } | 280 | } |
280 | 281 | ||
281 | Config vmCfg("VMemo"); | 282 | Config vmCfg("VMemo"); |
282 | vmCfg.setGroup("Defaults"); | 283 | vmCfg.setGroup("Defaults"); |
283 | 284 | ||
284 | QDateTime dt = QDateTime::currentDateTime(); | 285 | QDateTime dt = QDateTime::currentDateTime(); |
@@ -415,110 +416,100 @@ int VMemo::openWAV(const char *filename) | |||
415 | wh.modus = channels; | 416 | wh.modus = channels; |
416 | wh.sample_fq = speed; | 417 | wh.sample_fq = speed; |
417 | wh.byte_p_sec = speed * channels * resolution/8; | 418 | wh.byte_p_sec = speed * channels * resolution/8; |
418 | wh.byte_p_spl = channels * (resolution / 8); | 419 | wh.byte_p_spl = channels * (resolution / 8); |
419 | wh.bit_p_spl = resolution; | 420 | wh.bit_p_spl = resolution; |
420 | wh.data_chunk = DATA; | 421 | wh.data_chunk = DATA; |
421 | wh.data_length= 0; | 422 | wh.data_length= 0; |
422 | // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" | 423 | // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" |
423 | // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); | 424 | // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); |
424 | write (wav, &wh, sizeof(WaveHeader)); | 425 | write (wav, &wh, sizeof(WaveHeader)); |
425 | 426 | ||
426 | return 1; | 427 | return 1; |
427 | } | 428 | } |
428 | 429 | ||
429 | void VMemo::record(void) | 430 | void VMemo::record(void) |
430 | { | 431 | { |
431 | int length=0, result, value; | 432 | int length=0, result, value; |
432 | qDebug("Recording"); | 433 | qDebug("Recording"); |
433 | 434 | ||
434 | if(systemZaurus) { | 435 | if(systemZaurus) { |
435 | signed short sound[512], monoBuffer[512]; | 436 | signed short sound[512], monoBuffer[512]; |
436 | if(format==AFMT_S16_LE) { | 437 | if(format==AFMT_S16_LE) { |
437 | while(recording) { | 438 | while(recording) { |
438 | result = read(dsp, sound, 512); // 8192 | 439 | result = read(dsp, sound, 512); // 8192 |
439 | qApp->processEvents(); | ||
440 | int j=0; | 440 | int j=0; |
441 | if(systemZaurus) { | 441 | if(systemZaurus) { |
442 | for (int i = 0; i < result; i++) { //since Z is mono do normally | 442 | for (int i = 0; i < result; i++) { //since Z is mono do normally |
443 | monoBuffer[i] = sound[i]; | 443 | monoBuffer[i] = sound[i]; |
444 | } | 444 | } |
445 | qApp->processEvents(); | ||
446 | length+=write(wav, monoBuffer, result); | 445 | length+=write(wav, monoBuffer, result); |
447 | } else { //ipaq /stereo inputs | 446 | } else { //ipaq /stereo inputs |
448 | for (int i = 0; i < result; i+=2) { | 447 | for (int i = 0; i < result; i+=2) { |
449 | monoBuffer[j] = (sound[i]+sound[i+1])/2; | 448 | monoBuffer[j] = (sound[i]+sound[i+1])/2; |
450 | j++; | 449 | j++; |
451 | } | 450 | } |
452 | qApp->processEvents(); | ||
453 | length+=write(wav, monoBuffer, result/2); | 451 | length+=write(wav, monoBuffer, result/2); |
454 | } | 452 | } |
455 | printf("%d\r",length); | 453 | // printf("%d\r",length); |
456 | fflush(stdout); | 454 | // fflush(stdout); |
457 | } | 455 | } |
458 | } else { //AFMT_U8 | 456 | } else { //AFMT_U8 |
459 | // 8bit unsigned | 457 | // 8bit unsigned |
460 | unsigned short sound[512], monoBuffer[512]; | 458 | unsigned short sound[512], monoBuffer[512]; |
461 | while(recording) { | 459 | while(recording) { |
462 | result = read(dsp, sound, 512); // 8192 | 460 | result = read(dsp, sound, 512); // 8192 |
463 | qApp->processEvents(); | ||
464 | int j=0; | 461 | int j=0; |
465 | if(systemZaurus) { | 462 | if(systemZaurus) { |
466 | for (int i = 0; i < result; i++) { //since Z is mono do normally | 463 | for (int i = 0; i < result; i++) { //since Z is mono do normally |
467 | monoBuffer[i] = sound[i]; | 464 | monoBuffer[i] = sound[i]; |
468 | } | 465 | } |
469 | qApp->processEvents(); | ||
470 | length+=write(wav, monoBuffer, result); | 466 | length+=write(wav, monoBuffer, result); |
471 | } else { //ipaq /stereo inputs | 467 | } else { //ipaq /stereo inputs |
472 | for (int i = 0; i < result; i+=2) { | 468 | for (int i = 0; i < result; i+=2) { |
473 | monoBuffer[j] = (sound[i]+sound[i+1])/2; | 469 | monoBuffer[j] = (sound[i]+sound[i+1])/2; |
474 | j++; | 470 | j++; |
475 | } | 471 | } |
476 | qApp->processEvents(); | ||
477 | length+=write(wav, monoBuffer, result/2); | 472 | length+=write(wav, monoBuffer, result/2); |
478 | } | 473 | } |
479 | length += result; | 474 | length += result; |
480 | printf("%d\r",length); | 475 | // printf("%d\r",length); |
481 | fflush(stdout); | 476 | // fflush(stdout); |
482 | |||
483 | qApp->processEvents(); | ||
484 | } | 477 | } |
485 | 478 | ||
486 | qApp->processEvents(); | 479 | qApp->processEvents(); |
487 | } | 480 | } |
488 | 481 | ||
489 | } else { | 482 | } else { |
490 | 483 | ||
491 | signed short sound[512], monoBuffer[512]; | 484 | signed short sound[512], monoBuffer[512]; |
492 | 485 | ||
493 | while(recording) { | 486 | while(recording) { |
494 | result = read(dsp, sound, 512); // 8192 | 487 | result = read(dsp, sound, 512); // 8192 |
495 | qApp->processEvents(); | ||
496 | |||
497 | write(wav, sound, result); | 488 | write(wav, sound, result); |
498 | length += result; | 489 | length += result; |
499 | 490 | ||
500 | qApp->processEvents(); | 491 | qApp->processEvents(); |
501 | } | 492 | } |
502 | printf("%d\r",length); | 493 | // printf("%d\r",length); |
503 | fflush(stdout); | 494 | // fflush(stdout); |
504 | // qDebug("file has length of %d lasting %d seconds", | 495 | // qDebug("file has length of %d lasting %d seconds", |
505 | // length, (( length / speed) / channels) / 2 ); | 496 | // length, (( length / speed) / channels) / 2 ); |
506 | // medialplayer states wrong length in secs | 497 | // medialplayer states wrong length in secs |
507 | } | 498 | } |
508 | 499 | ||
509 | value = length+36; | 500 | value = length+36; |
510 | lseek(wav, 4, SEEK_SET); | 501 | lseek(wav, 4, SEEK_SET); |
511 | write(wav, &value, 4); | 502 | write(wav, &value, 4); |
512 | lseek(wav, 40, SEEK_SET); | 503 | lseek(wav, 40, SEEK_SET); |
513 | write(wav, &length, 4); | 504 | write(wav, &length, 4); |
514 | track.close(); | 505 | track.close(); |
515 | 506 | ||
516 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) | 507 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) |
517 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); | 508 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); |
518 | ::close(dsp); | 509 | ::close(dsp); |
519 | fileName = fileName.left(fileName.length()-4); | 510 | fileName = fileName.left(fileName.length()-4); |
520 | if(useAlerts) | 511 | if(useAlerts) |
521 | QMessageBox::message("Vmemo"," Done recording\n"+ fileName); | 512 | QMessageBox::message("Vmemo"," Done recording\n"+ fileName); |
522 | qDebug("done recording "+fileName); | 513 | qDebug("done recording "+fileName); |
523 | QSound::play(Resource::findSound("vmemoe")); | 514 | QSound::play(Resource::findSound("vmemoe")); |
524 | } | 515 | } |