summaryrefslogtreecommitdiff
path: root/core/applets/vmemo/vmemo.cpp
Unidiff
Diffstat (limited to 'core/applets/vmemo/vmemo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/vmemo/vmemo.cpp150
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
@@ -16,2 +16,6 @@
16// Sun 03-17-2002 L.J.Potter <ljp@llornkcor.com> 16// Sun 03-17-2002 L.J.Potter <ljp@llornkcor.com>
17extern "C" {
18#include "adpcm.h"
19}
20
17#include <sys/utsname.h> 21#include <sys/utsname.h>
@@ -59,2 +63,9 @@ typedef struct _waveheader {
59 63
64struct 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"
@@ -198,4 +209,3 @@ static char * vmemo_xpm[] = {
198VMemo::VMemo( QWidget *parent, const char *_name ) 209VMemo::VMemo( QWidget *parent, const char *_name )
199 : QWidget( parent, _name ) 210 : QWidget( parent, _name ) {
200{
201 setFixedHeight( 18 ); 211 setFixedHeight( 18 );
@@ -215,2 +225,3 @@ VMemo::VMemo( QWidget *parent, const char *_name )
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
@@ -245,8 +256,6 @@ VMemo::VMemo( QWidget *parent, const char *_name )
245 256
246VMemo::~VMemo() 257VMemo::~VMemo() {
247{
248} 258}
249 259
250void VMemo::receive( const QCString &msg, const QByteArray &data ) 260void VMemo::receive( const QCString &msg, const QByteArray &data ) {
251{
252 qDebug("receive"); 261 qDebug("receive");
@@ -266,4 +275,3 @@ void VMemo::receive( const QCString &msg, const QByteArray &data )
266 275
267void VMemo::paintEvent( QPaintEvent* ) 276void VMemo::paintEvent( QPaintEvent* ) {
268{
269 QPainter p(this); 277 QPainter p(this);
@@ -272,4 +280,3 @@ void VMemo::paintEvent( QPaintEvent* )
272 280
273void VMemo::mousePressEvent( QMouseEvent * me) 281void VMemo::mousePressEvent( QMouseEvent * me) {
274{
275 // just to be safe 282 // just to be safe
@@ -281,4 +288,3 @@ void VMemo::mousePressEvent( QMouseEvent * me)
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)
@@ -292,4 +298,3 @@ void VMemo::mousePressEvent( QMouseEvent * me)
292 298
293void VMemo::mouseReleaseEvent( QMouseEvent * ) 299void VMemo::mouseReleaseEvent( QMouseEvent * ) {
294{
295// if(usingIcon && !recording) 300// if(usingIcon && !recording)
@@ -377,5 +382,6 @@ bool VMemo::startRecording() {
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
@@ -394,4 +400,2 @@ bool VMemo::startRecording() {
394 l.writeLink(); 400 l.writeLink();
395
396 record();
397 401
@@ -416,4 +420,3 @@ void VMemo::stopRecording() {
416 420
417int VMemo::openDSP() 421int VMemo::openDSP() {
418{
419 Config cfg("Vmemo"); 422 Config cfg("Vmemo");
@@ -469,4 +472,3 @@ int VMemo::openDSP()
469 472
470int VMemo::openWAV(const char *filename) 473int VMemo::openWAV(const char *filename) {
471{
472 track.setName(filename); 474 track.setName(filename);
@@ -486,3 +488,6 @@ int VMemo::openWAV(const char *filename)
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;
@@ -501,4 +506,3 @@ int VMemo::openWAV(const char *filename)
501 506
502void VMemo::record(void) 507void VMemo::record(void) {
503{
504 int length=0, result, value; 508 int length=0, result, value;
@@ -513,80 +517,42 @@ void VMemo::record(void)
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;
@@ -602,3 +568,3 @@ void VMemo::record(void)
602 // medialplayer states wrong length in secs 568 // medialplayer states wrong length in secs
603 } 569 // }
604 570