summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2004-07-02 21:28:14 (UTC)
committer llornkcor <llornkcor>2004-07-02 21:28:14 (UTC)
commite46eb5eb8bb8a0a34dbc7f4749ff62633261aba0 (patch) (unidiff)
tree0f18b7d34ee6208b18afc45837098c4e11cc5ed5
parent558c37f440baa57213d40639992bd29eaed1e12f (diff)
downloadopie-e46eb5eb8bb8a0a34dbc7f4749ff62633261aba0.zip
opie-e46eb5eb8bb8a0a34dbc7f4749ff62633261aba0.tar.gz
opie-e46eb5eb8bb8a0a34dbc7f4749ff62633261aba0.tar.bz2
fix
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/vmemo/vmemo.cpp42
1 files changed, 26 insertions, 16 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp
index b80b378..e747a19 100644
--- a/core/applets/vmemo/vmemo.cpp
+++ b/core/applets/vmemo/vmemo.cpp
@@ -207,65 +207,66 @@ VMemo::VMemo( QWidget *parent, const char *_name )
207 connect( t_timer, SIGNAL( timeout() ), SLOT( timerBreak() ) ); 207 connect( t_timer, SIGNAL( timeout() ), SLOT( timerBreak() ) );
208 208
209 Config vmCfg("Vmemo"); 209 Config vmCfg("Vmemo");
210 vmCfg.setGroup("Defaults"); 210 vmCfg.setGroup("Defaults");
211 int toggleKey = setToggleButton(vmCfg.readNumEntry("toggleKey", -1)); 211 int toggleKey = setToggleButton(vmCfg.readNumEntry("toggleKey", -1));
212 useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); 212 useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0);
213 213
214 odebug << "toggleKey " << toggleKey << "" << oendl; 214 odebug << "toggleKey " << toggleKey << "" << oendl;
215 215
216// if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" )) 216// if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" ))
217// systemZaurus=TRUE; 217// systemZaurus=TRUE;
218// else 218// else
219 systemZaurus = FALSE; 219 systemZaurus = FALSE;
220 220
221 myChannel = new QCopChannel( "QPE/VMemo", this ); 221 myChannel = new QCopChannel( "QPE/VMemo", this );
222 connect( myChannel, SIGNAL(received(const QCString&,const QByteArray&)), 222 connect( myChannel, SIGNAL(received(const QCString&,const QByteArray&)),
223 this, SLOT(receive(const QCString&,const QByteArray&)) ); 223 this, SLOT(receive(const QCString&,const QByteArray&)) );
224 224
225 if( toggleKey != -1 ) { 225 if( toggleKey != -1 ) {
226 odebug << "Register key " << toggleKey << "" << oendl; 226 odebug << "Register key " << toggleKey << "" << oendl;
227 QCopEnvelope e("QPE/Launcher", "keyRegister(int,QCString,QCString)"); 227 QCopEnvelope e("QPE/Launcher", "keyRegister(int,QCString,QCString)");
228 // e << 4096; // Key_Escape 228 // e << 4096; // Key_Escape
229 // e << Key_F5; //4148 229 // e << Key_F5; //4148
230 e << toggleKey; 230 e << toggleKey;
231 e << QString("QPE/VMemo"); 231 e << QString("QPE/VMemo");
232 e << QString("toggleRecord()"); 232 e << QString("toggleRecord()");
233 } 233 }
234 if(toggleKey == 1) 234 if(toggleKey == 1)
235 usingIcon = TRUE; 235 usingIcon = TRUE;
236 else 236 else
237 usingIcon = FALSE; 237 usingIcon = FALSE;
238// if( vmCfg.readNumEntry("hideIcon",0) == 1) 238// if( vmCfg.readNumEntry("hideIcon",0) == 1)
239// hide(); 239 if (!usingIcon)
240 hide();
240 recording = FALSE; 241 recording = FALSE;
241 // } 242 // }
242} 243}
243 244
244VMemo::~VMemo() { 245VMemo::~VMemo() {
245} 246}
246 247
247int VMemo::position() 248int VMemo::position()
248{ 249{
249 return 6; 250 return 6;
250} 251}
251 252
252void VMemo::receive( const QCString &msg, const QByteArray &data ) { 253void VMemo::receive( const QCString &msg, const QByteArray &data ) {
253 odebug << "Vmemo receive" << oendl; 254 odebug << "Vmemo receive" << oendl;
254 QDataStream stream( data, IO_ReadOnly ); 255 QDataStream stream( data, IO_ReadOnly );
255 256
256 if (msg == "toggleRecord()") { 257 if (msg == "toggleRecord()") {
257 if (recording) { 258 if (recording) {
258 fromToggle = TRUE; 259 fromToggle = TRUE;
259 stopRecording(); 260 stopRecording();
260 } else { 261 } else {
261 fromToggle = TRUE; 262 fromToggle = TRUE;
262 startRecording(); 263 startRecording();
263 } 264 }
264 } 265 }
265} 266}
266 267
267void VMemo::paintEvent( QPaintEvent* ) { 268void VMemo::paintEvent( QPaintEvent* ) {
268 QPainter p(this); 269 QPainter p(this);
269 p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); 270 p.drawPixmap( 0, 1,( const char** ) vmemo_xpm );
270} 271}
271 272
@@ -346,65 +347,65 @@ bool VMemo::startRecording() {
346 ::close(dsp); 347 ::close(dsp);
347 return FALSE; 348 return FALSE;
348 } 349 }
349 if( record() ) { 350 if( record() ) {
350 351
351 QString cmd; 352 QString cmd;
352 if( fileName.find(".wav",0,TRUE) == -1) 353 if( fileName.find(".wav",0,TRUE) == -1)
353 fileName += ".wav"; 354 fileName += ".wav";
354 355
355 cmd.sprintf("mv %s "+fileName, pointer); 356 cmd.sprintf("mv %s "+fileName, pointer);
356// move tmp file to regular file here 357// move tmp file to regular file here
357 358
358 system(cmd.latin1()); 359 system(cmd.latin1());
359 360
360 QArray<int> cats(1); 361 QArray<int> cats(1);
361 cats[0] = config.readNumEntry("Category", 0); 362 cats[0] = config.readNumEntry("Category", 0);
362 363
363 QString dlName("vm_"); 364 QString dlName("vm_");
364 dlName += date; 365 dlName += date;
365 DocLnk l; 366 DocLnk l;
366 l.setFile(fileName); 367 l.setFile(fileName);
367 l.setName(dlName); 368 l.setName(dlName);
368 l.setType("audio/x-wav"); 369 l.setType("audio/x-wav");
369 l.setCategories(cats); 370 l.setCategories(cats);
370 l.writeLink(); 371 l.writeLink();
371 return TRUE; 372 return TRUE;
372 } else 373 } else
373 return FALSE; 374 return FALSE;
374 375
375} 376}
376 377
377void VMemo::stopRecording() { 378void VMemo::stopRecording() {
378 show(); 379// show();
379 odebug << "Stopped recording" << oendl; 380 odebug << "Stopped recording" << oendl;
380 recording = FALSE; 381 recording = FALSE;
381 if(useAlerts) { 382 if(useAlerts) {
382 msgLabel->close(); 383 msgLabel->close();
383 msgLabel=0; 384 msgLabel=0;
384 delete msgLabel; 385 delete msgLabel;
385 } 386 }
386 t_timer->stop(); 387 t_timer->stop();
387 Config cfg("Vmemo"); 388 Config cfg("Vmemo");
388 cfg.setGroup("Defaults"); 389 cfg.setGroup("Defaults");
389// if( cfg.readNumEntry("hideIcon",0) == 1 ) 390// if( cfg.readNumEntry("hideIcon",0) == 1 )
390// hide(); 391// hide();
391} 392}
392 393
393int VMemo::openDSP() { 394int VMemo::openDSP() {
394 Config cfg("Vmemo"); 395 Config cfg("Vmemo");
395 cfg.setGroup("Record"); 396 cfg.setGroup("Record");
396 397
397 speed = cfg.readNumEntry("SampleRate", 22050); 398 speed = cfg.readNumEntry("SampleRate", 22050);
398 channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) 399 channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1)
399 if (cfg.readNumEntry("SixteenBit", 1)==1) { 400 if (cfg.readNumEntry("SixteenBit", 1)==1) {
400 format = AFMT_S16_LE; 401 format = AFMT_S16_LE;
401 resolution = 16; 402 resolution = 16;
402 } else { 403 } else {
403 format = AFMT_U8; 404 format = AFMT_U8;
404 resolution = 8; 405 resolution = 8;
405 } 406 }
406 407
407 odebug << "samplerate: " << speed << ", channels " << channels << ", resolution " << resolution << "" << oendl; 408 odebug << "samplerate: " << speed << ", channels " << channels << ", resolution " << resolution << "" << oendl;
408 409
409 if(systemZaurus) { 410 if(systemZaurus) {
410 dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1 411 dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1
@@ -456,139 +457,148 @@ int VMemo::openWAV(const char *filename) {
456 wav=track.handle(); 457 wav=track.handle();
457 Config vmCfg("Vmemo"); 458 Config vmCfg("Vmemo");
458 vmCfg.setGroup("Defaults"); 459 vmCfg.setGroup("Defaults");
459 useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); 460 useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0);
460 461
461 WaveHeader wh; 462 WaveHeader wh;
462 463
463 wh.main_chunk = RIFF; 464 wh.main_chunk = RIFF;
464 wh.length=0; 465 wh.length=0;
465 wh.chunk_type = WAVE; 466 wh.chunk_type = WAVE;
466 wh.sub_chunk = FMT; 467 wh.sub_chunk = FMT;
467 wh.sc_len = 16; 468 wh.sc_len = 16;
468 if(useADPCM) 469 if(useADPCM)
469 wh.format = WAVE_FORMAT_DVI_ADPCM;//PCM_CODE; 470 wh.format = WAVE_FORMAT_DVI_ADPCM;//PCM_CODE;
470 else 471 else
471 wh.format = PCM_CODE; 472 wh.format = PCM_CODE;
472 wh.modus = channels; 473 wh.modus = channels;
473 wh.sample_fq = speed; 474 wh.sample_fq = speed;
474 wh.byte_p_sec = speed * channels * resolution/8; 475 wh.byte_p_sec = speed * channels * resolution/8;
475 wh.byte_p_spl = channels * (resolution / 8); 476 wh.byte_p_spl = channels * (resolution / 8);
476 wh.bit_p_spl = resolution; 477 wh.bit_p_spl = resolution;
477 wh.data_chunk = DATA; 478 wh.data_chunk = DATA;
478 wh.data_length= 0; 479 wh.data_length= 0;
479 // odebug << "Write header channels " << wh.modus << ", speed " << wh.sample_fq << ", b/s " 480 // odebug << "Write header channels " << wh.modus << ", speed " << wh.sample_fq << ", b/s "
480 // << wh.byte_p_sec << ", blockalign " << wh.byte_p_spl << ", bitrate " << wh.bit_p_spl << oendl; 481 // << wh.byte_p_sec << ", blockalign " << wh.byte_p_spl << ", bitrate " << wh.bit_p_spl << oendl;
481 write (wav, &wh, sizeof(WaveHeader)); 482 write (wav, &wh, sizeof(WaveHeader));
482 483
483 return 1; 484 return 1;
484} 485}
485 486
486bool VMemo::record() { 487bool VMemo::record() {
487 length = 0; 488 length = 0;
488 int bytesWritten = 0; 489 int bytesWritten = 0;
489 int result = 0; 490 int result = 0;
490 int value = 0; 491 int value = 0;
492
491 QString msg; 493 QString msg;
492 msg.sprintf("Recording format %d", format); 494 msg.sprintf("Recording format %d", format);
493 odebug << msg << oendl; 495 odebug << msg << oendl;
496
494 Config config("Vmemo"); 497 Config config("Vmemo");
495 config.setGroup("Record"); 498 config.setGroup("Record");
496 int sRate = config.readNumEntry("SizeLimit", 30); 499 int sRate = config.readNumEntry("SizeLimit", 30);
497 if(sRate > 0) 500 odebug << "VMEMO rate" << sRate << oendl;
498 t_timer->start( sRate * 1000+1000, TRUE);
499 501
500 msg.sprintf("Recording format other"); 502 if(sRate > 0) {
501 odebug << msg << oendl; 503 t_timer->start( sRate * 1000+1000, TRUE);
504 }
505
506 msg.sprintf("Recording format other");
507 odebug << msg << oendl;
502 508
503 config.setGroup("Defaults"); 509 config.setGroup("Defaults");
504 useADPCM = config.readBoolEntry("use_ADPCM", 0); 510 useADPCM = config.readBoolEntry("use_ADPCM", 0);
505 511
506 int bufsize = config.readNumEntry("BufferSize",1024); 512 int bufsize = config.readNumEntry("BufferSize",1024);
507 unsigned short sound[bufsize]; //, monoBuffer[bufsize]; 513 unsigned short sound[bufsize]; //, monoBuffer[bufsize];
508 char abuf[bufsize / 2]; 514 char abuf[bufsize / 2];
509 short sbuf[bufsize]; 515 short sbuf[bufsize];
510 516 odebug << "ready to record"<< oendl;
511 if(useADPCM) { 517 if(useADPCM) {
518 odebug << "usr ADPCM" << oendl;
519
512 while(recording) { 520 while(recording) {
513 result = ::read(dsp, sbuf, bufsize); // adpcm read 521 result = ::read(dsp, sbuf, bufsize); // adpcm read
514 if( result <= 0) { 522 if( result <= 0) {
515 perror("recording error "); 523 perror("recording error ");
516 QMessageBox::message(tr("Note"),tr("error recording")); 524 QMessageBox::message(tr("Note"),tr("error recording"));
517 recording = FALSE; 525 recording = FALSE;
518 break; 526 break;
519 return FALSE; 527 return FALSE;
520 } 528 }
521 adpcm_coder( sbuf, abuf, result/2, &encoder_state); 529 adpcm_coder( sbuf, abuf, result/2, &encoder_state);
522 bytesWritten = ::write(wav, abuf, result/4); // adpcm write 530 bytesWritten = ::write(wav, abuf, result/4); // adpcm write
523 length += bytesWritten; 531 length += bytesWritten;
524 532
525 if(length < 0) { 533 if(length < 0) {
526 recording = false; 534 recording = false;
527 perror("dev/dsp's is a lookin' messy"); 535 perror("dev/dsp's is a lookin' messy");
528 QMessageBox::message("Vmemo","Error writing to file\n"+ fileName); 536 QMessageBox::message("Vmemo","Error writing to file\n"+ fileName);
529 break; 537 break;
530 return FALSE; 538 return FALSE;
531 } 539 }
532 // printf("%d\r", length); 540 printf("%d\r", length);
533 // fflush(stdout); 541 fflush(stdout);
534 qApp->processEvents(); 542 qApp->processEvents();
535 } 543 }
536 } else { 544 } else {
545 odebug << "use regular wav" << oendl;
537 while(recording) { 546 while(recording) {
538 result = ::read(dsp, sound, bufsize); // read 547 result = ::read(dsp, sound, bufsize); // read
539 if( result <= 0) { 548 if( result <= 0) {
540 perror("recording error "); 549 perror("recording error ");
541 QMessageBox::message(tr("Note"),tr("error recording")); 550 QMessageBox::message(tr("Note"),tr("error recording"));
542 recording = FALSE; 551 recording = FALSE;
543 break; 552 break;
544 return FALSE; 553 return FALSE;
554 }
545 555
546 bytesWritten = ::write(wav, sound, result); // write 556 bytesWritten = ::write(wav, sound, result); // write
547 length += bytesWritten; 557 length += bytesWritten;
548 558
549 if(length < 0) { 559 if(length < 0) {
550 recording = false; 560 recording = false;
551 perror("dev/dsp's is a lookin' messy"); 561 perror("dev/dsp's is a lookin' messy");
552 QMessageBox::message("Vmemo","Error writing to file\n"+ fileName); 562 QMessageBox::message("Vmemo","Error writing to file\n"+ fileName);
553 break; 563 break;
554 return FALSE; 564 return FALSE;
555 } 565 }
556 // printf("%d\r", length); 566// printf("%d\r", length);
557 // fflush(stdout); 567// fflush(stdout);
558 qApp->processEvents(); 568 qApp->processEvents();
559 } 569 }
570 // odebug << "result is " << result << oendl;
560 } 571 }
561 } 572 odebug << "file has length of " << length << " lasting " << (( length / speed) / channels) / 2 << " seconds" << oendl;
562 // odebug << "file has length of " << length << " lasting " << (( length / speed) / channels) / 2 ) << " seconds" << oendl;
563 573
564 value = length + 36; 574 value = length + 36;
565 575
566 lseek(wav, 4, SEEK_SET); 576 lseek(wav, 4, SEEK_SET);
567 write(wav, &value, 4); 577 write(wav, &value, 4);
568 lseek(wav, 40, SEEK_SET); 578 lseek(wav, 40, SEEK_SET);
569 579
570 write(wav, &length, 4); 580 write(wav, &length, 4);
571 581
572 track.close(); 582 track.close();
573 odebug << "Track closed" << oendl; 583 odebug << "Track closed" << oendl;
574 584
575 if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) 585 if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1)
576 perror("ioctl(\"SNDCTL_DSP_RESET\")"); 586 perror("ioctl(\"SNDCTL_DSP_RESET\")");
577 587
578 ::close(dsp); 588 ::close(dsp);
579 589
580 Config cfgO("OpieRec"); 590 Config cfgO("OpieRec");
581 cfgO.setGroup("Sounds"); 591 cfgO.setGroup("Sounds");
582 592
583 int nFiles = cfgO.readNumEntry( "NumberofFiles",0); 593 int nFiles = cfgO.readNumEntry( "NumberofFiles",0);
584 594
585 QString currentFileName = fileName; 595 QString currentFileName = fileName;
586 QString currentFile = "vm_"+ date; 596 QString currentFile = "vm_"+ date;
587 597
588 float numberOfRecordedSeconds = (float) length / (float)speed * (float)2; 598 float numberOfRecordedSeconds = (float) length / (float)speed * (float)2;
589 599
590 cfgO.writeEntry( "NumberofFiles", nFiles + 1); 600 cfgO.writeEntry( "NumberofFiles", nFiles + 1);
591 cfgO.writeEntry( QString::number( nFiles + 1), currentFile); 601 cfgO.writeEntry( QString::number( nFiles + 1), currentFile);
592 cfgO.writeEntry( currentFile, currentFileName); 602 cfgO.writeEntry( currentFile, currentFileName);
593 603
594 QString time; 604 QString time;