-rw-r--r-- | core/applets/vmemo/vmemo.cpp | 106 |
1 files changed, 59 insertions, 47 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp index 10a947e..b29ee62 100644 --- a/core/applets/vmemo/vmemo.cpp +++ b/core/applets/vmemo/vmemo.cpp @@ -363,255 +363,267 @@ void VMemo::stopRecording() { 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_RDWR); //Zaurus needs /dev/dsp1 channels=1; //zaurus has one input channel } else { dsp = open("/dev/dsp", O_RDWR); } 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(); WaveHeader wh; wh.main_chunk = RIFF; wh.length=0; wh.chunk_type = WAVE; wh.sub_chunk = FMT; wh.sc_len = 16; 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; } void VMemo::record(void) { int length=0, result, value; QString msg; msg.sprintf("Recording format %d", format); qDebug(msg); if(systemZaurus) { - msg.sprintf("Recording format zaurus"); - qDebug(msg); + msg.sprintf("Recording format zaurus"); + qDebug(msg); signed short sound[512], monoBuffer[512]; if(format==AFMT_S16_LE) { + + while(recording) { result = read(dsp, sound, 512); // 8192 int j=0; - if(systemZaurus) { - for (int i = 0; i < result; i++) { //since Z is mono do normally - monoBuffer[i] = sound[i]; - } + // if(systemZaurus) { + for (int i = 0; i < result; i++) { //since Z is mono do normally + monoBuffer[i] = sound[i]; + } - length+=write(wav, monoBuffer, result); - if(length<0) - recording=false; + length+=write(wav, monoBuffer, result); + if(length<0) + recording=false; - } else { //ipaq /stereo inputs + // } else { //ipaq /stereo inputs - for (int i = 0; i < result; i+=2) { - monoBuffer[j] = sound[i]; - // monoBuffer[j] = (sound[i]+sound[i+1])/2; + // for (int i = 0; i < result; i+=2) { + // monoBuffer[j] = sound[i]; + // // monoBuffer[j] = (sound[i]+sound[i+1])/2; - j++; - } + // j++; + // } - length+=write(wav, monoBuffer, result); - if(length<0) - recording=false; - // length+=write(wav, monoBuffer, result/2); - } + // length+=write(wav, monoBuffer, result); + // if(length<0) + // recording=false; + // // length+=write(wav, monoBuffer, result/2); + // } qApp->processEvents(); -// printf("%d\r",length); -// fflush(stdout); + // printf("%d\r",length); + // fflush(stdout); } -} else { //AFMT_U8 + } else { //AFMT_U8 // 8bit unsigned unsigned short sound[512], monoBuffer[512]; while(recording) { result = read(dsp, sound, 512); // 8192 int j=0; - if(systemZaurus) { + // if(systemZaurus) { - for (int i = 0; i < result; i++) { //since Z is mono do normally - monoBuffer[i] = sound[i]; - } + for (int i = 0; i < result; i++) { //since Z is mono do normally + monoBuffer[i] = sound[i]; + } - length+=write(wav, monoBuffer, result); + length+=write(wav, monoBuffer, result); - } else { //ipaq /stereo inputs + // } else { //ipaq /stereo inputs - for (int i = 0; i < result; i+=2) { - monoBuffer[j] = (sound[i]+sound[i+1])/2; - j++; - } + // for (int i = 0; i < result; i+=2) { + // monoBuffer[j] = (sound[i]+sound[i+1])/2; + // j++; + // } - length+=write(wav, monoBuffer, result/2); + // length+=write(wav, monoBuffer, result/2); - if(length<0) - recording=false; + // if(length<0) + // recording=false; - } + // } length += result; -// printf("%d\r",length); -// fflush(stdout); + // printf("%d\r",length); + // fflush(stdout); } qApp->processEvents(); } - } else { // this is specific for ipaqs that do not have 8 bit capabilities + } else { // 16 bit only capabilities - msg.sprintf("Recording format other"); - qDebug(msg); + + msg.sprintf("Recording format other"); + qDebug(msg); signed short sound[512], monoBuffer[512]; while(recording) { result = read(dsp, sound, 512); // 8192 write(wav, sound, result); length += result; if(length<0) { - recording=false; - perror("dev/dsp's is a lookin' messy"); - QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); + recording=false; + perror("dev/dsp's is a lookin' messy"); + QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); } -// printf("%d\r",length); -// fflush(stdout); + // printf("%d\r",length); + // fflush(stdout); qApp->processEvents(); } // qDebug("file has length of %d lasting %d seconds", // length, (( length / speed) / channels) / 2 ); // medialplayer states wrong length in secs } //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<// value = length+36; lseek(wav, 4, SEEK_SET); write(wav, &value, 4); lseek(wav, 40, SEEK_SET); write(wav, &length, 4); track.close(); qDebug("Tracvk 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 + } 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; }; } } |