author | llornkcor <llornkcor> | 2004-04-25 20:38:04 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2004-04-25 20:38:04 (UTC) |
commit | 0e3e74030b2a38cfc754d253ab098a1126f382ef (patch) (side-by-side diff) | |
tree | 9eb7544e6c29431cddbcfbc5bfe907d08227dbb2 | |
parent | ae76c412a340a0808ed6ece5e4a8fbc04baa4ff3 (diff) | |
download | opie-0e3e74030b2a38cfc754d253ab098a1126f382ef.zip opie-0e3e74030b2a38cfc754d253ab098a1126f382ef.tar.gz opie-0e3e74030b2a38cfc754d253ab098a1126f382ef.tar.bz2 |
hook things up
-rw-r--r-- | noncore/multimedia/opierec/qtrec.cpp | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/noncore/multimedia/opierec/qtrec.cpp b/noncore/multimedia/opierec/qtrec.cpp index 2187d5a..6eb6524 100644 --- a/noncore/multimedia/opierec/qtrec.cpp +++ b/noncore/multimedia/opierec/qtrec.cpp @@ -130,398 +130,402 @@ void quickRec() int bytesWritten, number; bytesWritten = 0; number = 0; QString num; int level = 0; int threshold = 0; // int bits = filePara.resolution; // odebug << "bits " << bits << "" << oendl; if( filePara.resolution == 16 ) { //AFMT_S16_LE) // odebug << "AFMT_S16_LE size " << filePara.SecondsToRecord << "" << oendl; // odebug << "samples to record " << filePara.samplesToRecord << "" << oendl; // odebug << "" << filePara.sd << "" << oendl; level = 7; threshold = 0; if( filePara.format == WAVE_FORMAT_DVI_ADPCM) { // odebug << "start recording WAVE_FORMAT_DVI_ADPCM" << oendl; // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_DVI_ADPCM >>>>>>>>>>>>>>>>>>>>>> char abuf[ BUFSIZE/2 ]; short sbuf[ BUFSIZE ]; short sbuf2[ BUFSIZE ]; memset( abuf, 0, BUFSIZE/2); memset( sbuf, 0, BUFSIZE); memset( sbuf2, 0, BUFSIZE); for(;;) { if ( stopped) { // odebug << "quickRec:: stopped" << oendl; break; } // number=::read( filePara.sd, sbuf, BUFSIZE); number = soundDevice ->devRead( filePara.sd, sbuf, BUFSIZE); if(number <= 0) { perror("recording error "); 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); - waveform->newSamples( (const short *)abuf, bytesWritten ); + waveform->newSamples( sbuf, number ); total += bytesWritten; filePara.numberSamples = total; timeSlider->setValue( total); - 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 { // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_PCM >>>>>>>>>>>>>>>>>>>>>> odebug << "start recording WAVE_FORMAT_PCM" << oendl; short inbuffer[ BUFSIZE ], outbuffer[ BUFSIZE ]; memset( inbuffer, 0, BUFSIZE); memset( outbuffer, 0, BUFSIZE); for(;;) { if ( stopped) { odebug << "quickRec:: stopped" << oendl; stopped = true; break; // stop if playing was set to false return; } number = soundDevice->devRead( filePara.sd, (short *)inbuffer, BUFSIZE); - waveform->newSamples( inbuffer, number ); if( number <= 0) { perror( "recording error "); odebug << filePara.fileName << oendl; stopped = true; return; } bytesWritten = ::write( filePara.fd , inbuffer, number); + waveform->newSamples( inbuffer, number ); if( bytesWritten < 0) { perror("File writing error "); stopped = true; return; } total += bytesWritten; filePara.numberSamples = total; if( filePara.SecondsToRecord != 0) timeSlider->setValue( total); // printf("Writing number %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; } } } //end main loop } else { // <<<<<<<<<<<<<<<<<<<<<<< format = AFMT_U8; unsigned char unsigned_inbuffer[ BUFSIZE ], unsigned_outbuffer[ BUFSIZE ]; memset( unsigned_inbuffer, 0, BUFSIZE); memset( unsigned_outbuffer, 0, BUFSIZE); for(;;) { if ( stopped) { odebug << "quickRec:: stopped" << oendl; break; // stop if playing was set to false } number = ::read( filePara.sd, unsigned_inbuffer, BUFSIZE); bytesWritten = ::write( filePara.fd , unsigned_inbuffer, number); + waveform->newSamples( (const short *) unsigned_inbuffer, number ); if(bytesWritten < 0) { stopped = true; - QMessageBox::message("Note","There was a problem\nwriting to the file"); + QMessageBox::message("Note","<p>There was a problem writing to the file</p>"); perror("File writing error "); return; } total += bytesWritten; filePara.numberSamples = total; // printf("\nWriting number %d, bytes %d,total %d \r",number, bytesWritten , total); // fflush(stdout); if( filePara.SecondsToRecord !=0) timeSlider->setValue( total); filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate; qApp->processEvents(); if( total >= filePara.samplesToRecord) { stopped = true; break; } } //end main loop } } /// END quickRec() #ifdef THREADED void playIt() #else void QtRec::playIt() #endif { int bytesWritten = 0; int number = 0; int total = 0; // Total number of bytes read in so far. if( filePara.resolution == 16 ) { //AFMT_S16_LE) { if( filePara.format == WAVE_FORMAT_DVI_ADPCM) { char abuf[ BUFSIZE / 2 ]; short sbuf[ BUFSIZE ]; short sbuf2[ BUFSIZE * 2 ]; memset( abuf, 0, BUFSIZE / 2); memset( sbuf, 0, BUFSIZE); memset( sbuf2, 0, BUFSIZE * 2); // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_DVI_ADPCM >>>>>>>>>>>>>>>>>>>>>> for(;;) { // play loop if ( stopped) { break; return; }// 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 ); + waveform->newSamples( (const short *)sbuf, number *4); // 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); // timeString.sprintf("%.2f", filePara.numberOfRecordedSeconds); // if(filePara.numberOfRecordedSeconds>1) // timeLabel->setText( timeString+ tr(" seconds")); // printf("playing number %d, bytes %d, total %d\n",number, bytesWritten, total/4); // fflush(stdout); qApp->processEvents(); if( /*total >= filePara.numberSamples || */ bytesWritten == 0) { // if( total >= filePara.numberSamples ){//|| secCount > filePara.numberOfRecordedSeconds ) { stopped = true; break; } } } else { // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_PCM >>>>>>>>>>>>>>>>>>>>>> short inbuffer[ BUFSIZE ], outbuffer[ BUFSIZE ]; memset( inbuffer, 0, BUFSIZE); memset( outbuffer, 0, BUFSIZE); for(;;) { // play loop if ( stopped) { break; 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); - waveform->newSamples( inbuffer, bytesWritten ); + waveform->newSamples( inbuffer, number); //-------------->>>> out to device // total+=bytesWritten; // if(filePara.channels==1) // total += bytesWritten/2; //mono // else total += bytesWritten; timeSlider->setValue( total); filePara.numberSamples = total; filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / (float)2; // timeString.sprintf("%.2f",filePara.numberOfRecordedSeconds); // timeLabel->setText( timeString + tr(" seconds")); qApp->processEvents(); if( /*total >= filePara.numberSamples || */ bytesWritten == 0) { owarn << "Jane! Stop this crazy thing!" << oendl; stopped = true; // playing = false; break; } } - printf("\nplaying number %d, bytes %d, total %d\r",number, bytesWritten, total); - fflush(stdout); +// printf("\nplaying number %d, bytes %d, total %d\r",number, bytesWritten, total); +// fflush(stdout); } //end loop } else { /////////////////////////////// format = AFMT_U8; unsigned char unsigned_inbuffer[ BUFSIZE ]; //, unsigned_outbuffer[BUFSIZE]; memset( unsigned_inbuffer, 0, BUFSIZE); for(;;) { // main loop if (stopped) { break; // stop if playing was set to false return; } number = ::read( filePara.fd, unsigned_inbuffer, BUFSIZE); //data = (val >> 8) ^ 0x80; // unsigned_outbuffer = (unsigned_inbuffer >> 8) ^ 0x80; bytesWritten = write ( filePara.sd, unsigned_inbuffer, number); waveform->newSamples( (const short *)unsigned_inbuffer, bytesWritten ); total += bytesWritten; timeSlider->setValue( total); filePara.numberSamples = total; filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate; // timeString.sprintf("%.2f",filePara.numberOfRecordedSeconds); // timeLabel->setText( timeString + tr(" seconds")); qApp->processEvents(); if( /*total >= filePara.numberSamples || */ bytesWritten == 0) { // if( total >= filePara.numberSamples ) { stopped = true; break; } // printf("Writing number %d, bytes %d, total %d, numberSamples %d\r",number, bytesWritten , total, filePara.numberSamples); // fflush(stdout); } } } QtRec::QtRec( QWidget* parent, const char* name, WFlags fl ) : QWidget( parent, name, fl ) { if ( !name ) setName( "OpieRec" ); init(); initConfig(); initConnections(); renameBox = 0; // open sound device to get volumes Config hwcfg("OpieRec"); hwcfg.setGroup("Hardware"); soundDevice = new Device( this, hwcfg.readEntry( "Audio",DSPSTROUT), hwcfg.readEntry( "Mixer",DSPSTRMIXEROUT), false); // soundDevice = new Device( this, hwcfg.readEntry( "Audio","hw:0"), hwcfg.readEntry( "Mixer","hw:0"), false); // soundDevice->setDeviceFormat(AFMT_S16_LE); // soundDevice->setDeviceChannels(1); // soundDevice->setDeviceRate( 22050); getInVol(); getOutVol(); soundDevice->closeDevice( true); soundDevice->sd = -1; soundDevice = 0; wavFile = 0; - if( soundDevice) delete soundDevice; +// if( soundDevice) delete soundDevice; initIconView(); if( autoMute) doMute( true); ListView1->setFocus(); playing = false; } QtRec::~QtRec() { +// if( soundDevice) delete soundDevice; } void QtRec::cleanUp() { if( !stopped) { stopped = true; endRecording(); } ListView1->clear(); if( autoMute) doMute(false); - if( wavFile) delete wavFile; +// if( wavFile) delete wavFile; // if(soundDevice) delete soundDevice; } void QtRec::init() { needsStereoOut = false; QPixmap image3( ( const char** ) image3_data ); QPixmap image4( ( const char** ) image4_data ); QPixmap image6( ( const char** ) image6_data ); stopped = true; setCaption( tr( "OpieRecord " ) + QString::number(VERSION) ); QGridLayout *layout = new QGridLayout( this ); layout->setSpacing( 2); layout->setMargin( 2); TabWidget = new QTabWidget( this, "TabWidget" ); layout->addMultiCellWidget(TabWidget, 0, 7, 0, 7); // TabWidget->setTabShape(QTabWidget::Triangular); ///**********<<<<<<<<<<<<>>>>>>>>>>>>*************** tab = new QWidget( TabWidget, "tab" ); QGridLayout *layout1 = new QGridLayout( tab); layout1->setSpacing( 2); layout1->setMargin( 2); timeSlider = new QSlider( 0,100,10,0, QSlider::Horizontal, tab, (const char *) "timeSlider" ); layout1->addMultiCellWidget( timeSlider, 1, 1, 0, 3); timeLabel = new QLabel( tab, "TimeLabel" ); layout1->addMultiCellWidget( timeLabel, 0, 0, 0, 3); playLabel2 = new QLabel(tab, "PlayLabel2" ); playLabel2->setText(tr("Play") ); playLabel2->setFixedHeight( 18); layout1->addMultiCellWidget( playLabel2, 0, 0, 4, 4); Stop_PushButton = new QPushButton( tab, "Stop_PushButton" ); layout1->addMultiCellWidget( Stop_PushButton, 1, 1, 4, 4); Stop_PushButton->setFixedSize( 22, 22); Stop_PushButton->setPixmap( image4 ); toBeginningButton = new QPushButton( tab, "Beginning_PushButton" ); layout1->addMultiCellWidget(toBeginningButton, 1, 1, 5, 5); toBeginningButton->setFixedSize( 22, 22); toBeginningButton->setPixmap( Resource::loadPixmap("fastback") ); @@ -1456,137 +1460,137 @@ void QtRec::endRecording() { toEndButton->setEnabled( true); killTimers(); if(autoMute) doMute( true); soundDevice->closeDevice( true); if( wavFile->track.isOpen()) { wavFile->adjustHeaders( filePara.fd, filePara.numberSamples); // soundDevice->sd=-1; filePara.numberSamples = 0; // filePara.sd=-1; wavFile->closeFile(); filePara.fd=0; if( wavFile->isTempFile()) { // move tmp file to regular file QString cmd; cmd.sprintf("mv "+ wavFile->trackName() + " " + wavFile->currentFileName); // odebug << "moving tmp file to "+currentFileName << oendl; system( cmd.latin1()); } odebug << "Just moved " + wavFile->currentFileName << oendl; Config cfg("OpieRec"); cfg.setGroup("Sounds"); int nFiles = cfg.readNumEntry( "NumberofFiles",0); currentFile = QFileInfo( wavFile->currentFileName).fileName(); currentFile = currentFile.left( currentFile.length() - 4); cfg.writeEntry( "NumberofFiles", nFiles + 1); cfg.writeEntry( QString::number( nFiles + 1), currentFile); cfg.writeEntry( currentFile, wavFile->currentFileName); QString time; time.sprintf("%.2f", filePara.numberOfRecordedSeconds); cfg.writeEntry( wavFile->currentFileName, time ); // odebug << "writing config numberOfRecordedSeconds "+time << oendl; cfg.write(); odebug << "finished recording" << oendl; timeLabel->setText(""); } - if(soundDevice) delete soundDevice; +// if(soundDevice) delete soundDevice; timeSlider->setValue(0); initIconView(); selectItemByName( currentFile); } void QtRec::endPlaying() { monitoring = false; recording = false; playing = false; stopped = true; waveform->reset(); // errorStop(); // odebug << "end playing" << oendl; setRecordButton( false); toBeginningButton->setEnabled( true); toEndButton->setEnabled( true); if(autoMute) doMute( true); soundDevice->closeDevice( false); soundDevice->sd = -1; // if(soundDevice) delete soundDevice; // odebug << "file and sound device closed" << oendl; timeLabel->setText(""); total = 0; filePara.numberSamples = 0; filePara.sd = -1; // wavFile->closeFile(); filePara.fd = 0; // if(wavFile) delete wavFile; //this crashes // odebug << "track closed" << oendl; killTimers(); owarn << "reset slider" << oendl; timeSlider->setValue(0); - if(soundDevice) delete soundDevice; +// if(soundDevice) delete soundDevice; } bool QtRec::openPlayFile() { qApp->processEvents(); if( currentFile.isEmpty()) { QMessageBox::message(tr("Opierec"),tr("Please select file to play")); endPlaying(); return false; } QString currentFileName; Config cfg("OpieRec"); cfg.setGroup("Sounds"); int nFiles = cfg.readNumEntry( "NumberofFiles", 0); for(int i=0;i<nFiles+1;i++) { //look for file if( cfg.readEntry( QString::number(i),"").find( currentFile,0,true) != -1) { currentFileName = cfg.readEntry( currentFile, "" ); odebug << "opening for play: " + currentFileName << oendl; } } wavFile = new WavFile(this, currentFileName, false); filePara.fd = wavFile->wavHandle(); if(filePara.fd == -1) { // if(!track.open(IO_ReadOnly)) { QString errorMsg = (QString)strerror(errno); monitoring = false; setCaption( tr( "OpieRecord " ) + QString::number(VERSION) ); QMessageBox::message(tr("Note"), tr("Could not open audio file.\n") + errorMsg + "\n" + currentFile); return false; } else { filePara.numberSamples = wavFile->getNumberSamples(); filePara.format = wavFile->getFormat(); filePara.sampleRate = wavFile->getSampleRate(); filePara.resolution = wavFile->getResolution(); filePara.channels = wavFile->getChannels(); timeSlider->setPageStep(1); monitoring = true; odebug << "file " << filePara.fd << ", samples " << filePara.numberSamples << " " << filePara.sampleRate << "" << oendl; int sec = (int) (( filePara.numberSamples / filePara.sampleRate) / filePara.channels) / ( filePara.channels*( filePara.resolution/8)); owarn << "seconds " << sec << "" << oendl; @@ -1745,97 +1749,97 @@ bool QtRec::eventFilter( QObject * o, QEvent * e ) { } else if ( ke->key() == Key_Escape ) { cancelRename(); return true; } } else if ( e->type() == QEvent::FocusOut ) { cancelRename(); return true; } } return QWidget::eventFilter( o, e ); } int QtRec::getCurrentSizeLimit() { return sizeLimitCombo->currentItem() * 5; } void QtRec::timerBreak() { endPlaying(); } void QtRec::doVolMuting(bool b) { Config cfg( "qpe" ); cfg. setGroup( "Volume" ); cfg.writeEntry( "Mute",b); cfg.write(); QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << b; } void QtRec::doMicMuting(bool b) { // odebug << "mic mute" << oendl; Config cfg( "qpe" ); cfg. setGroup( "Volume" ); cfg.writeEntry( "MicMute",b); cfg.write(); QCopEnvelope( "QPE/System", "micChange(bool)" ) << b; } 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); - bitRateComboBox->setCurrentItem( 0); + bitRateComboBox->setCurrentItem( 1); filePara.resolution = 16; } else{ bitRateComboBox->setEnabled( true); } } long QtRec::checkDiskSpace(const QString &path) { struct statfs fs; if ( !statfs( path.latin1(), &fs ) ) { int blkSize = fs.f_bsize; int availBlks = fs.f_bavail; long mult = blkSize / 1024; long div = 1024 / blkSize; if ( !mult ) mult = 1; if ( !div ) div = 1; return availBlks * mult / div; } return -1; } // short f_fstyp; /* File system type */ // long f_bsize; /* Block size */ // long f_frsize; /* Fragment size */ // long f_blocks; /* Total number of blocks*/ // long f_bfree; /* Count of free blocks */ // long f_files; /* Total number of file nodes */ // long f_ffree; /* Count of free file nodes */ // char f_fname[6]; /* Volumename */ // char f_fpack[6]; /* Pack name */ void QtRec::receive( const QCString &msg, const QByteArray & ) { odebug << "Voicerecord received message "+msg << oendl; } ///////////////////////////// timerEvent void QtRec::timerEvent( QTimerEvent * ) { // if(!recording) // timeSlider->setValue( secCount); // else |