Diffstat (limited to 'core/applets/vmemo/vmemo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/applets/vmemo/vmemo.cpp | 150 |
1 files changed, 58 insertions, 92 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp index b77e3b8..b5239eb 100644 --- a/core/applets/vmemo/vmemo.cpp +++ b/core/applets/vmemo/vmemo.cpp | |||
@@ -14,6 +14,10 @@ | |||
14 | * $Id$ | 14 | * $Id$ |
15 | */ | 15 | */ |
16 | // Sun 03-17-2002 L.J.Potter <ljp@llornkcor.com> | 16 | // Sun 03-17-2002 L.J.Potter <ljp@llornkcor.com> |
17 | extern "C" { | ||
18 | #include "adpcm.h" | ||
19 | } | ||
20 | |||
17 | #include <sys/utsname.h> | 21 | #include <sys/utsname.h> |
18 | #include <sys/time.h> | 22 | #include <sys/time.h> |
19 | #include <sys/types.h> | 23 | #include <sys/types.h> |
@@ -57,6 +61,13 @@ typedef struct _waveheader { | |||
57 | #define WAVE_MONO 1 | 61 | #define WAVE_MONO 1 |
58 | #define WAVE_STEREO 2 | 62 | #define WAVE_STEREO 2 |
59 | 63 | ||
64 | struct adpcm_state encoder_state; | ||
65 | //struct adpcm_state decoder_state; | ||
66 | |||
67 | #define WAVE_FORMAT_DVI_ADPCM (0x0011) | ||
68 | #define WAVE_FORMAT_PCM (0x0001) | ||
69 | |||
70 | |||
60 | #include "vmemo.h" | 71 | #include "vmemo.h" |
61 | 72 | ||
62 | #include <qpe/qpeapplication.h> | 73 | #include <qpe/qpeapplication.h> |
@@ -196,8 +207,7 @@ static char * vmemo_xpm[] = { | |||
196 | 207 | ||
197 | 208 | ||
198 | VMemo::VMemo( QWidget *parent, const char *_name ) | 209 | VMemo::VMemo( QWidget *parent, const char *_name ) |
199 | : QWidget( parent, _name ) | 210 | : QWidget( parent, _name ) { |
200 | { | ||
201 | setFixedHeight( 18 ); | 211 | setFixedHeight( 18 ); |
202 | setFixedWidth( 14 ); | 212 | setFixedWidth( 14 ); |
203 | 213 | ||
@@ -213,6 +223,7 @@ VMemo::VMemo( QWidget *parent, const char *_name ) | |||
213 | Config vmCfg("Vmemo"); | 223 | Config vmCfg("Vmemo"); |
214 | vmCfg.setGroup("Defaults"); | 224 | vmCfg.setGroup("Defaults"); |
215 | int toggleKey = setToggleButton(vmCfg.readNumEntry("toggleKey", -1)); | 225 | int toggleKey = setToggleButton(vmCfg.readNumEntry("toggleKey", -1)); |
226 | useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); | ||
216 | 227 | ||
217 | qDebug("toggleKey %d", toggleKey); | 228 | qDebug("toggleKey %d", toggleKey); |
218 | 229 | ||
@@ -243,12 +254,10 @@ VMemo::VMemo( QWidget *parent, const char *_name ) | |||
243 | } | 254 | } |
244 | } | 255 | } |
245 | 256 | ||
246 | VMemo::~VMemo() | 257 | VMemo::~VMemo() { |
247 | { | ||
248 | } | 258 | } |
249 | 259 | ||
250 | void VMemo::receive( const QCString &msg, const QByteArray &data ) | 260 | void VMemo::receive( const QCString &msg, const QByteArray &data ) { |
251 | { | ||
252 | qDebug("receive"); | 261 | qDebug("receive"); |
253 | QDataStream stream( data, IO_ReadOnly ); | 262 | QDataStream stream( data, IO_ReadOnly ); |
254 | if (msg == "toggleRecord()") { | 263 | if (msg == "toggleRecord()") { |
@@ -264,14 +273,12 @@ void VMemo::receive( const QCString &msg, const QByteArray &data ) | |||
264 | } | 273 | } |
265 | } | 274 | } |
266 | 275 | ||
267 | void VMemo::paintEvent( QPaintEvent* ) | 276 | void VMemo::paintEvent( QPaintEvent* ) { |
268 | { | ||
269 | QPainter p(this); | 277 | QPainter p(this); |
270 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); | 278 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); |
271 | } | 279 | } |
272 | 280 | ||
273 | void VMemo::mousePressEvent( QMouseEvent * me) | 281 | void VMemo::mousePressEvent( QMouseEvent * me) { |
274 | { | ||
275 | // just to be safe | 282 | // just to be safe |
276 | if (recording) { | 283 | if (recording) { |
277 | recording = FALSE; | 284 | recording = FALSE; |
@@ -279,8 +286,7 @@ void VMemo::mousePressEvent( QMouseEvent * me) | |||
279 | } | 286 | } |
280 | /* No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions | 287 | /* No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions |
281 | mousePressEvent and mouseReleaseEvent with a NULL parameter. */ | 288 | mousePressEvent and mouseReleaseEvent with a NULL parameter. */ |
282 | if ( me->button() != LeftButton) | 289 | if ( me->button() != LeftButton || me != NULL) |
283 | |||
284 | // if (!systemZaurus && me != NULL) | 290 | // if (!systemZaurus && me != NULL) |
285 | return; | 291 | return; |
286 | 292 | ||
@@ -290,8 +296,7 @@ void VMemo::mousePressEvent( QMouseEvent * me) | |||
290 | stopRecording(); | 296 | stopRecording(); |
291 | } | 297 | } |
292 | 298 | ||
293 | void VMemo::mouseReleaseEvent( QMouseEvent * ) | 299 | void VMemo::mouseReleaseEvent( QMouseEvent * ) { |
294 | { | ||
295 | // if(usingIcon && !recording) | 300 | // if(usingIcon && !recording) |
296 | // stopRecording(); | 301 | // stopRecording(); |
297 | } | 302 | } |
@@ -375,9 +380,10 @@ bool VMemo::startRecording() { | |||
375 | ::close(dsp); | 380 | ::close(dsp); |
376 | return FALSE; | 381 | return FALSE; |
377 | } | 382 | } |
378 | QString cmd; | 383 | record(); |
379 | cmd.sprintf("mv %s "+fileName,pointer); | ||
380 | 384 | ||
385 | QString cmd; | ||
386 | cmd.sprintf("mv %s "+fileName, pointer); | ||
381 | // move tmp file to regular file here | 387 | // move tmp file to regular file here |
382 | system(cmd.latin1()); | 388 | system(cmd.latin1()); |
383 | 389 | ||
@@ -392,8 +398,6 @@ bool VMemo::startRecording() { | |||
392 | l.setType("audio/x-wav"); | 398 | l.setType("audio/x-wav"); |
393 | l.setCategories(cats); | 399 | l.setCategories(cats); |
394 | l.writeLink(); | 400 | l.writeLink(); |
395 | |||
396 | record(); | ||
397 | 401 | ||
398 | return TRUE; | 402 | return TRUE; |
399 | } | 403 | } |
@@ -414,8 +418,7 @@ void VMemo::stopRecording() { | |||
414 | hide(); | 418 | hide(); |
415 | } | 419 | } |
416 | 420 | ||
417 | int VMemo::openDSP() | 421 | int VMemo::openDSP() { |
418 | { | ||
419 | Config cfg("Vmemo"); | 422 | Config cfg("Vmemo"); |
420 | cfg.setGroup("Record"); | 423 | cfg.setGroup("Record"); |
421 | 424 | ||
@@ -467,8 +470,7 @@ int VMemo::openDSP() | |||
467 | return 1; | 470 | return 1; |
468 | } | 471 | } |
469 | 472 | ||
470 | int VMemo::openWAV(const char *filename) | 473 | int VMemo::openWAV(const char *filename) { |
471 | { | ||
472 | track.setName(filename); | 474 | track.setName(filename); |
473 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) { | 475 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) { |
474 | errorMsg=filename; | 476 | errorMsg=filename; |
@@ -484,7 +486,10 @@ int VMemo::openWAV(const char *filename) | |||
484 | wh.chunk_type = WAVE; | 486 | wh.chunk_type = WAVE; |
485 | wh.sub_chunk = FMT; | 487 | wh.sub_chunk = FMT; |
486 | wh.sc_len = 16; | 488 | wh.sc_len = 16; |
487 | wh.format = PCM_CODE; | 489 | if(useADPCM) |
490 | wh.format = WAVE_FORMAT_DVI_ADPCM;//PCM_CODE; | ||
491 | else | ||
492 | wh.format = PCM_CODE; | ||
488 | wh.modus = channels; | 493 | wh.modus = channels; |
489 | wh.sample_fq = speed; | 494 | wh.sample_fq = speed; |
490 | wh.byte_p_sec = speed * channels * resolution/8; | 495 | wh.byte_p_sec = speed * channels * resolution/8; |
@@ -499,8 +504,7 @@ int VMemo::openWAV(const char *filename) | |||
499 | return 1; | 504 | return 1; |
500 | } | 505 | } |
501 | 506 | ||
502 | void VMemo::record(void) | 507 | void VMemo::record(void) { |
503 | { | ||
504 | int length=0, result, value; | 508 | int length=0, result, value; |
505 | QString msg; | 509 | QString msg; |
506 | msg.sprintf("Recording format %d", format); | 510 | msg.sprintf("Recording format %d", format); |
@@ -511,84 +515,46 @@ void VMemo::record(void) | |||
511 | 515 | ||
512 | t_timer->start( sRate * 1000+1000, TRUE); | 516 | t_timer->start( sRate * 1000+1000, TRUE); |
513 | 517 | ||
514 | if(systemZaurus) { | 518 | // if(systemZaurus) { |
519 | // } else { // 16 bit only capabilities | ||
515 | 520 | ||
516 | msg.sprintf("Recording format zaurus"); | 521 | msg.sprintf("Recording format other"); |
517 | qDebug(msg); | 522 | qDebug(msg); |
518 | signed short sound[1024], monoBuffer[1024]; | ||
519 | |||
520 | if(format==AFMT_S16_LE) { | ||
521 | 523 | ||
524 | int bufsize=1024; | ||
525 | int bytesWritten=0; | ||
526 | signed short sound[1024], monoBuffer[1024]; | ||
527 | char abuf[bufsize/2]; | ||
528 | short sbuf[bufsize]; | ||
522 | 529 | ||
530 | while(recording) { | ||
523 | 531 | ||
524 | while(recording) { | 532 | if(useADPCM) |
525 | 533 | result = read( dsp, sbuf, bufsize); // 8192 | |
526 | result = read(dsp, sound, 1024); // 8192 | 534 | else |
527 | // int j=0; | 535 | result = read(dsp, sound, 1024); // 8192 |
528 | 536 | if( result <= 0) { | |
529 | for (int i = 0; i < result; i++) { //since Z is mono do normally | 537 | perror("recording error "); |
530 | monoBuffer[i] = sound[i]; | 538 | // qDebug(currentFileName); |
539 | QMessageBox::message(tr("Note"),tr("error recording")); | ||
540 | recording=FALSE;; | ||
541 | break; | ||
531 | } | 542 | } |
532 | 543 | ||
533 | length+=write(wav, monoBuffer, result); | 544 | if(useADPCM) { |
534 | if(length<0) | 545 | adpcm_coder( sbuf, abuf, result/2, &encoder_state); |
535 | recording=false; | 546 | bytesWritten = ::write(wav, abuf, result/4); |
536 | // for (int i = 0; i < result; i+=2) { | ||
537 | // monoBuffer[j] = sound[i]; | ||
538 | // // monoBuffer[j] = (sound[i]+sound[i+1])/2; | ||
539 | |||
540 | // j++; | ||
541 | // } | ||
542 | qApp->processEvents(); | ||
543 | // printf("%d\r",length); | ||
544 | // fflush(stdout); | ||
545 | } | ||
546 | |||
547 | } else { //AFMT_U8 | ||
548 | // 8bit unsigned | ||
549 | unsigned short sound[1024], monoBuffer[1024]; | ||
550 | while(recording) { | ||
551 | result = read(dsp, sound, 1024); // 8192 | ||
552 | // int j=0; | ||
553 | 547 | ||
554 | // if(systemZaurus) { | 548 | } else { |
549 | for (int i = 0; i < result; i++) { //since Z is mono do normally | ||
550 | monoBuffer[i] = sound[i]; | ||
551 | } | ||
555 | 552 | ||
556 | for (int i = 0; i < result; i++) { //since Z is mono do normally | 553 | length+=write(wav, monoBuffer, result); |
557 | monoBuffer[i] = sound[i]; | ||
558 | } | 554 | } |
559 | 555 | length +=bytesWritten; | |
560 | length+=write(wav, monoBuffer, result); | ||
561 | |||
562 | // for (int i = 0; i < result; i+=2) { | ||
563 | // monoBuffer[j] = (sound[i]+sound[i+1])/2; | ||
564 | // j++; | ||
565 | // } | ||
566 | // length+=write(wav, monoBuffer, result/2); | ||
567 | length += result; | ||
568 | // printf("%d\r",length); | ||
569 | // fflush(stdout); | ||
570 | } | ||
571 | |||
572 | qApp->processEvents(); | ||
573 | } | ||
574 | |||
575 | } else { // 16 bit only capabilities | ||
576 | |||
577 | |||
578 | msg.sprintf("Recording format other"); | ||
579 | qDebug(msg); | ||
580 | |||
581 | signed short sound[1024];//, monoBuffer[512]; | ||
582 | |||
583 | while(recording) { | ||
584 | |||
585 | result = read(dsp, sound, 1024); // 8192 | ||
586 | |||
587 | write(wav, sound, result); | ||
588 | length += result; | ||
589 | 556 | ||
590 | if(length<0) { | 557 | if(length<0) { |
591 | |||
592 | recording=false; | 558 | recording=false; |
593 | perror("dev/dsp's is a lookin' messy"); | 559 | perror("dev/dsp's is a lookin' messy"); |
594 | QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); | 560 | QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); |
@@ -600,7 +566,7 @@ void VMemo::record(void) | |||
600 | // qDebug("file has length of %d lasting %d seconds", | 566 | // qDebug("file has length of %d lasting %d seconds", |
601 | // length, (( length / speed) / channels) / 2 ); | 567 | // length, (( length / speed) / channels) / 2 ); |
602 | // medialplayer states wrong length in secs | 568 | // medialplayer states wrong length in secs |
603 | } | 569 | // } |
604 | 570 | ||
605 | //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<// | 571 | //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<// |
606 | 572 | ||