author | llornkcor <llornkcor> | 2002-07-29 12:30:16 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-07-29 12:30:16 (UTC) |
commit | a7064f7b9a6515cc1e26823a2f969d90feb855a2 (patch) (side-by-side diff) | |
tree | dc3809cff5a147edb1186de689ae9184a99a4209 | |
parent | 0868e96b1737d121733c898ae92348a279e5b53f (diff) | |
download | opie-a7064f7b9a6515cc1e26823a2f969d90feb855a2.zip opie-a7064f7b9a6515cc1e26823a2f969d90feb855a2.tar.gz opie-a7064f7b9a6515cc1e26823a2f969d90feb855a2.tar.bz2 |
fix
-rw-r--r-- | core/applets/vmemo/vmemo.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp index 577db75..4b398ad 100644 --- a/core/applets/vmemo/vmemo.cpp +++ b/core/applets/vmemo/vmemo.cpp @@ -321,326 +321,334 @@ bool VMemo::startRecording() { // if(useAlerts) // QMessageBox::message("VMemo","Really Record?");//) ==1) // return; // } else { // if (!systemZaurus ) // QSound::play(Resource::findSound("vmemob")); // } qDebug("Start recording engines"); recording = TRUE; if (openDSP() == -1) { // QMessageBox::critical(0, "vmemo", "Could not open dsp device.\n"+errorMsg, "Abort"); // delete msgLabel; recording = FALSE; msgLabel=0; delete msgLabel; return FALSE; } config.setGroup("Defaults"); QDateTime dt = QDateTime::currentDateTime(); QString fName; config.setGroup( "System" ); fName = QPEApplication::documentDir() ; fileName = config.readEntry("RecLocation", fName); int s; s=fileName.find(':'); if(s) fileName=fileName.right(fileName.length()-s-2); qDebug("pathname will be "+fileName); if( fileName.left(1).find('/') == -1) fileName="/"+fileName; if( fileName.right(1).find('/') == -1) fileName+="/"; fName = "vm_"+ dt.toString()+ ".wav"; fileName+=fName; // No spaces in the filename fileName.replace(QRegExp("'"),""); fileName.replace(QRegExp(" "),"_"); fileName.replace(QRegExp(":"),"."); fileName.replace(QRegExp(","),""); - fileName += ".wav"; + qDebug("filename is "+fileName); // open tmp file here char *pointer; pointer=tmpnam(NULL); qDebug("Opening tmp file %s",pointer); if(openWAV(pointer ) == -1) { // if(openWAV(fileName.latin1()) == -1) { QString err("Could not open the temp file\n"); err += fileName; QMessageBox::critical(0, "vmemo", err, "Abort"); ::close(dsp); return FALSE; } if( record() ) { QString cmd; + if( fileName.find(".wav",0,TRUE) == -1) + fileName += ".wav"; + cmd.sprintf("mv %s "+fileName, pointer); // move tmp file to regular file here + system(cmd.latin1()); QArray<int> cats(1); cats[0] = config.readNumEntry("Category", 0); QString dlName("vm_"); dlName += dt.toString(); DocLnk l; l.setFile(fileName); l.setName(dlName); l.setType("audio/x-wav"); l.setCategories(cats); l.writeLink(); return TRUE; } else return FALSE; } void VMemo::stopRecording() { show(); qDebug("Stopped recording"); recording = FALSE; if(useAlerts) { msgLabel->close(); msgLabel=0; delete msgLabel; } t_timer->stop(); Config cfg("Vmemo"); cfg.setGroup("Defaults"); if( cfg.readNumEntry("hideIcon",0) == 1 ) hide(); } int VMemo::openDSP() { Config cfg("Vmemo"); cfg.setGroup("Record"); speed = cfg.readNumEntry("SampleRate", 22050); channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) if (cfg.readNumEntry("SixteenBit", 1)==1) { format = AFMT_S16_LE; resolution = 16; } else { format = AFMT_U8; resolution = 8; } qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution); if(systemZaurus) { dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1 channels=1; //zaurus has one input channel } else { dsp = open("/dev/dsp", O_RDONLY); } if(dsp == -1) { perror("open(\"/dev/dsp\")"); errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); QMessageBox::critical(0, "vmemo", errorMsg, "Abort"); return -1; } if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); return -1; } if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); return -1; } if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { perror("ioctl(\"SNDCTL_DSP_SPEED\")"); return -1; } if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { perror("ioctl(\"SOUND_PCM_READ_RATE\")"); return -1; } QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; //mute return 1; } int VMemo::openWAV(const char *filename) { track.setName(filename); if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) { errorMsg=filename; return -1; } wav=track.handle(); + Config vmCfg("Vmemo"); + vmCfg.setGroup("Defaults"); useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); WaveHeader wh; wh.main_chunk = RIFF; wh.length=0; wh.chunk_type = WAVE; wh.sub_chunk = FMT; wh.sc_len = 16; if(useADPCM) wh.format = WAVE_FORMAT_DVI_ADPCM;//PCM_CODE; else wh.format = PCM_CODE; wh.modus = channels; wh.sample_fq = speed; wh.byte_p_sec = speed * channels * resolution/8; wh.byte_p_spl = channels * (resolution / 8); wh.bit_p_spl = resolution; wh.data_chunk = DATA; wh.data_length= 0; // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); write (wav, &wh, sizeof(WaveHeader)); return 1; } bool VMemo::record() { int length=0, result, value; QString msg; msg.sprintf("Recording format %d", format); qDebug(msg); Config config("Vmemo"); config.setGroup("Record"); int sRate=config.readNumEntry("SizeLimit", 30); if(sRate > 0) t_timer->start( sRate * 1000+1000, TRUE); // if(systemZaurus) { // } else { // 16 bit only capabilities msg.sprintf("Recording format other"); qDebug(msg); int bufsize=1024; int bytesWritten=0; signed short sound[1024], monoBuffer[1024]; char abuf[bufsize/2]; short sbuf[bufsize]; + Config vmCfg("Vmemo"); + vmCfg.setGroup("Defaults"); useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); while(recording) { if(useADPCM) result = read( dsp, sbuf, bufsize); // 8192 else result = read(dsp, sound, 1024); // 8192 if( result <= 0) { perror("recording error "); // qDebug(currentFileName); QMessageBox::message(tr("Note"),tr("error recording")); recording=FALSE; break; return FALSE; } if(useADPCM) { adpcm_coder( sbuf, abuf, result/2, &encoder_state); bytesWritten = ::write(wav, abuf, result/4); } else { for (int i = 0; i < result; i++) { //since Z is mono do normally monoBuffer[i] = sound[i]; } length+=write(wav, monoBuffer, result); } length +=bytesWritten; if(length<0) { recording=false; perror("dev/dsp's is a lookin' messy"); QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); break; return FALSE; } // printf("%d\r",length); // fflush(stdout); qApp->processEvents(); } // qDebug("file has length of %d lasting %d seconds", // length, (( length / speed) / channels) / 2 ); // } //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<// value = length+36; lseek(wav, 4, SEEK_SET); write(wav, &value, 4); lseek(wav, 40, SEEK_SET); write(wav, &length, 4); track.close(); qDebug("Track closed"); if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) perror("ioctl(\"SNDCTL_DSP_RESET\")"); ::close(dsp); - fileName = fileName.left(fileName.length()-4); + // if(useAlerts) // QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); qDebug("done recording "+fileName); // QSound::play(Resource::findSound("vmemoe")); Config cfg("qpe"); cfg.setGroup("Volume"); QString foo = cfg.readEntry("Mute","TRUE"); if(foo.find("TRUE",0,TRUE) != -1) QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; //mute return TRUE; } int VMemo::setToggleButton(int tog) { for( int i=0; i < 10;i++) { switch (tog) { case 0: return -1; break; case 1: return 0; break; case 2: return Key_Escape; break; case 3: return Key_Space; break; case 4: return Key_F12; break; case 5: return Key_F9; break; case 6: return Key_F10; break; case 7: return Key_F11; break; case 8: return Key_F13; break; }; } return -1; |