-rw-r--r-- | noncore/multimedia/opierec/device.cpp | 16 | ||||
-rw-r--r-- | noncore/multimedia/opierec/opierec.pro | 1 | ||||
-rw-r--r-- | noncore/multimedia/opierec/qtrec.cpp | 21 | ||||
-rw-r--r-- | noncore/multimedia/opierec/wavFile.cpp | 40 |
4 files changed, 43 insertions, 35 deletions
diff --git a/noncore/multimedia/opierec/device.cpp b/noncore/multimedia/opierec/device.cpp index e7e0f4b..a76665e 100644 --- a/noncore/multimedia/opierec/device.cpp +++ b/noncore/multimedia/opierec/device.cpp @@ -53,48 +53,51 @@ Device::Device( QObject * parent, bool record ) : QObject( parent) { // dspstr = dsp; devForm = -1; devCh = -1; devRate = -1; if( !record){ //playing - owarn << "setting up DSP for playing" << oendl; - flags = O_WRONLY; + owarn << "New Sound device DSP for playing" << oendl; + flags = O_RDWR; +// flags = O_WRONLY; } else { //recording - owarn << "setting up DSP for recording" << oendl; + owarn << "New Sound device DSP for recording" << oendl; flags = O_RDWR; // flags = O_RDONLY; selectMicInput(); } } bool Device::openDsp() { + qWarning("Device::openDsp()"); if( openDevice( flags) == -1) { perror("<<<<<<<<<<<<<<ioctl(\"Open device\")"); return false; } return true; } int Device::openDevice( int flags) { - owarn << "Opening"<< dspstr; + owarn << "Opening sound device:"<< DSPSTROUT << oendl; - if (( sd = ::open( DSPSTROUT, flags)) == -1) { - perror("open(\"/dev/dsp\")"); + if (( sd = ::open( DSPSTROUT, O_RDWR)) == -1) { + perror("open(\"/dev/dsp\")\n"); QString errorMsg="Could not open audio device\n /dev/dsp\n" +(QString)strerror(errno); qDebug( "XXXXXXXXXXXXXXXXXXXXXXX "+errorMsg ); return -1; } if(ioctl(sd,SNDCTL_DSP_RESET,0)<0){ perror("ioctl RESET"); } + qWarning("opened!"); return sd; } int Device::getInVolume() { unsigned int volume = 0; Config cfg("qpe"); cfg.setGroup("Volume"); @@ -145,16 +148,17 @@ bool Device::selectMicInput() { return false; } ::close(md); return true; } bool Device::closeDevice( bool) { + if(sd) ::close( sd); //close sound device return true; } bool Device::setDeviceFormat( int form) { qDebug( "set device res %d: %d ",form, sd ); if (ioctl( sd, SNDCTL_DSP_SETFMT, &form)==-1) { //set format perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); diff --git a/noncore/multimedia/opierec/opierec.pro b/noncore/multimedia/opierec/opierec.pro index 6a5838a..6008bf7 100644 --- a/noncore/multimedia/opierec/opierec.pro +++ b/noncore/multimedia/opierec/opierec.pro @@ -26,13 +26,14 @@ contains(CONFIG, pdaudio) { # DESTDIR=$(QPEDIR)/bin } !contains(CONFIG, pdaudio) { INCLUDEPATH += $(OPIEDIR)/include DEPENDPATH += $(OPIEDIR)/include LIBS += -lqpe -lopiecore2 -lpthread + DEFINES += THREADED TARGET = opierec include( $(OPIEDIR)/include.pro ) } diff --git a/noncore/multimedia/opierec/qtrec.cpp b/noncore/multimedia/opierec/qtrec.cpp index e827083..9b761aa 100644 --- a/noncore/multimedia/opierec/qtrec.cpp +++ b/noncore/multimedia/opierec/qtrec.cpp @@ -151,28 +151,28 @@ void quickRec() odebug << "" << filePara.fileName << " " << number << "" << oendl; stopped = true; return; } //if(stereo == 2) { // adpcm_coder( sbuf2, abuf, number/2, &encoder_state); adpcm_coder( sbuf, abuf, number/2, &encoder_state); - bytesWritten = ::write( filePara.fd , (short *)abuf, number/4); + bytesWritten = ::write( filePara.fd , abuf, number/4); waveform->newSamples( sbuf, number ); total += bytesWritten; filePara.numberSamples = total; timeSlider->setValue( total); printf("%d, bytes %d,total %d\r", number, bytesWritten, total); fflush(stdout); - filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate * (float)2 / filePara.channels; + filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate * (float)2;// / filePara.channels; qApp->processEvents(); if( total >= filePara.samplesToRecord) { stopped = true; break; } } } else { @@ -296,18 +296,20 @@ void playIt() }// stop if playing was set to false number = ::read( filePara.fd, abuf, BUFSIZE / 2); adpcm_decoder( abuf, sbuf, number * 2, &decoder_state); // for (int i=0;i< number * 2; 2 * i++) { //2*i is left channel // sbuf2[i+1]=sbuf2[i]=sbuf[i]; // } - bytesWritten = write ( filePara.sd, sbuf, number * 4); - waveform->newSamples( (const short *)sbuf, number *4); + bytesWritten = write ( soundDevice->sd , sbuf, number * 4); + + waveform->newSamples( sbuf, number ); + // if(filePara.channels==1) // total += bytesWritten/2; //mono // else total += bytesWritten; filePara.numberSamples = total/4; filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / 2; timeSlider->setValue( total/4); @@ -337,17 +339,17 @@ void playIt() return; } // stop if playing was set to false number = ::read( filePara.fd, inbuffer, BUFSIZE); // for (int i=0;i< number * 2; 2 * i++) { //2*i is left channel // // for (int i=0;i< number ; i++) { //2*i is left channel // outbuffer[i+1]= outbuffer[i]=inbuffer[i]; // } - bytesWritten = ::write( filePara.sd, inbuffer, number); + bytesWritten = ::write( soundDevice->sd, inbuffer, number); waveform->newSamples( inbuffer, number); //-------------->>>> out to device // total+=bytesWritten; // if(filePara.channels==1) // total += bytesWritten/2; //mono // else total += bytesWritten; timeSlider->setValue( total); @@ -783,18 +785,18 @@ void QtRec::initConfig() { if( stereoCheckBox->isChecked()) { filePara.channels = 2; } else { filePara.channels = 1; } compressionCheckBox->setChecked( cfg.readBoolEntry("wavCompression",1)); if( compressionCheckBox->isChecked()) { + bitRateComboBox->setCurrentItem(1); bitRateComboBox->setEnabled(false); - bitRateComboBox->setCurrentItem(0); filePara.resolution=16; } autoMuteCheckBox->setChecked( cfg.readBoolEntry("useAutoMute",0)); if( autoMuteCheckBox->isChecked()) slotAutoMute(true); else slotAutoMute(false); @@ -1043,17 +1045,17 @@ bool QtRec::setupAudio( bool b) { stereo = filePara.channels; // filePara.sampleRate = sampleRateComboBox->currentText().toInt( &ok,10);//44100; flags= O_RDWR; // flags= O_RDONLY; recording = true; } // if(soundDevice) delete soundDevice; - odebug << "<<<<<<<<<<<<<<<<<<<open dsp " << filePara.sampleRate << " " << filePara.channels << " " << sampleformat << "" << oendl; + owarn << "<<<<<<<<<<<<<<<<<<<open dsp " << filePara.sampleRate << " " << filePara.channels << " " << sampleformat << "" << oendl; // owarn << "change waveform settings" << oendl; waveform->changeSettings( filePara.sampleRate, filePara.channels ); soundDevice = new Device( this, b); //open rec // soundDevice->openDsp(); soundDevice->reset(); odebug << "device has been made " << soundDevice->sd << "" << oendl; @@ -1478,17 +1480,17 @@ void QtRec::endPlaying() { // owarn << "reset slider" << oendl; timeSlider->setValue(0); // if(soundDevice) delete soundDevice; } bool QtRec::openPlayFile() { - + qWarning("opening file"); qApp->processEvents(); if( currentFile.isEmpty()) { QMessageBox::message(tr("Opierec"),tr("Please select file to play")); endPlaying(); return false; } QString currentFileName; Config cfg("OpieRec"); @@ -1721,18 +1723,19 @@ void QtRec::compressionSelected(bool b) { Config cfg("OpieRec"); cfg.setGroup("Settings"); cfg.writeEntry("wavCompression", b); cfg.writeEntry("bitrate", 16); filePara.resolution = 16; cfg.write(); if(b) { - bitRateComboBox->setEnabled( false); + qWarning("set adpcm"); bitRateComboBox->setCurrentItem( 1); + bitRateComboBox->setEnabled( false); filePara.resolution = 16; } else{ bitRateComboBox->setEnabled( true); } } long QtRec::checkDiskSpace(const QString &path) { diff --git a/noncore/multimedia/opierec/wavFile.cpp b/noncore/multimedia/opierec/wavFile.cpp index 80453e1..b53c416 100644 --- a/noncore/multimedia/opierec/wavFile.cpp +++ b/noncore/multimedia/opierec/wavFile.cpp @@ -22,17 +22,17 @@ using namespace Opie::Core; #include <stdio.h> #include <stdlib.h> #include <unistd.h> WavFile::WavFile( QObject * parent,const QString &fileName, bool makeNwFile, int sampleRate, int channels, int resolution, int format ) : QObject( parent) { -//odebug << "new wave file" << oendl; + owarn << "new wave file: " << fileName << oendl; bool b = makeNwFile; wavSampleRate=sampleRate; wavFormat=format; wavChannels=channels; wavResolution=resolution; useTmpFile=false; if( b) { newFile(); @@ -104,17 +104,17 @@ WavFile::~WavFile() { } void WavFile::closeFile() { if(track.isOpen()) track.close(); } int WavFile::openFile(const QString ¤tFileName) { -// odebug << "open play file "+currentFileName << oendl; + qWarning("open play file "+currentFileName);; closeFile(); track.setName(currentFileName); if(!track.open(IO_ReadOnly)) { QString errorMsg=(QString)strerror(errno); odebug << "<<<<<<<<<<< "+errorMsg+currentFileName << oendl; QMessageBox::message("Note", "Error opening file.\n" +errorMsg); @@ -147,104 +147,104 @@ bool WavFile::setWavHeader(int fd, wavhdr *hdr) { (*hdr).sampleRate = wavSampleRate; //samples per second (*hdr).avgBytesPerSec = (wavSampleRate)*( wavChannels*(wavResolution/8)); // bytes per second (*hdr).nBlockAlign = wavChannels*( wavResolution/8); //block align (*hdr).bitsPerSample = wavResolution; //bits per sample 8, or 16 strncpy((*hdr).dataID, "data", 4); write( fd,hdr, sizeof(*hdr)); - odebug << "writing header: bitrate " << wavResolution << ", samplerate " << wavSampleRate << ", channels " << wavChannels << oendl; + owarn << "writing header: bitrate " << wavResolution << ", samplerate " << wavSampleRate << ", channels " << wavChannels << oendl; return true; } bool WavFile::adjustHeaders(int fd, int total) { lseek(fd, 4, SEEK_SET); int i = total + 36; write( fd, &i, sizeof(i)); lseek( fd, 40, SEEK_SET); write( fd, &total, sizeof(total)); - odebug << "adjusting header " << total << "" << oendl; + owarn << "adjusting header " << total << "" << oendl; return true; } int WavFile::parseWavHeader(int fd) { - odebug << "Parsing wav header" << oendl; + owarn << "Parsing wav header" << oendl; char string[4]; int found; short fmt; unsigned short ch, bitrate; unsigned long samplerrate, longdata; if (read(fd, string, 4) < 4) { - odebug << " Could not read from sound file." << oendl; + owarn << " Could not read from sound file." << oendl; return -1; } if (strncmp(string, "RIFF", 4)) { - odebug << " not a valid WAV file." << oendl; + owarn << " not a valid WAV file." << oendl; return -1; } lseek(fd, 4, SEEK_CUR); if (read(fd, string, 4) < 4) { - odebug << "Could not read from sound file." << oendl; + owarn << "Could not read from sound file." << oendl; return -1; } if (strncmp(string, "WAVE", 4)) { - odebug << "not a valid WAV file." << oendl; + owarn << "not a valid WAV file." << oendl; return -1; } found = 0; while (!found) { if (read(fd, string, 4) < 4) { - odebug << "Could not read from sound file." << oendl; + owarn << "Could not read from sound file." << oendl; return -1; } if (strncmp(string, "fmt ", 4)) { if (read(fd, &longdata, 4) < 4) { - odebug << "Could not read from sound file." << oendl; + owarn << "Could not read from sound file." << oendl; return -1; } lseek(fd, longdata, SEEK_CUR); } else { lseek(fd, 4, SEEK_CUR); if (read(fd, &fmt, 2) < 2) { - odebug << "Could not read format chunk." << oendl; + owarn << "Could not read format chunk." << oendl; return -1; } if (fmt != WAVE_FORMAT_PCM && fmt != WAVE_FORMAT_DVI_ADPCM) { - odebug << "Wave file contains unknown format. Unable to continue." << oendl; + owarn << "Wave file contains unknown format. Unable to continue." << oendl; return -1; } wavFormat = fmt; // compressionFormat=fmt; - odebug << "compressionFormat is " << fmt << "" << oendl; + owarn << "compressionFormat is " << fmt << "" << oendl; if (read(fd, &ch, 2) < 2) { - odebug << "Could not read format chunk." << oendl; + owarn << "Could not read format chunk." << oendl; return -1; } else { wavChannels = ch; - odebug << "File has " << ch << " channels" << oendl; + owarn << "File has " << ch << " channels" << oendl; } if (read(fd, &samplerrate, 4) < 4) { - odebug << "Could not read from format chunk." << oendl; + owarn << "Could not read from format chunk." << oendl; return -1; } else { wavSampleRate = samplerrate; // sampleRate = samplerrate; - odebug << "File has samplerate of " << (int) samplerrate << "" << oendl; + owarn << "File has samplerate of " << (int) samplerrate << "" << oendl; } lseek(fd, 6, SEEK_CUR); if (read(fd, &bitrate, 2) < 2) { - odebug << "Could not read format chunk." << oendl; + owarn << "Could not read format chunk." << oendl; return -1; } else { wavResolution=bitrate; // resolution = bitrate; - odebug << "File has bitrate of " << bitrate << "" << oendl; + owarn << "File has bitrate of " << bitrate << "" << oendl; } found++; } } found = 0; while (!found) { if (read(fd, string, 4) < 4) { odebug << "Could not read from sound file." << oendl; |