📄 1
字号:
// Open the audio input device and normalize the parameters. if ( audioInput ) delete audioInput; audioInput = new AudioInput( qual->frequency, qual->channels ); qDebug( "channels: %d", audioInput->channels() ); qDebug( "frequency: %d", audioInput->frequency() ); qDebug( "bufferSize: %d", audioInput->bufferSize() ); connect( audioInput, SIGNAL( dataAvailable() ), this, SLOT( processAudioData() ) ); // Create the sample buffer, for recording the data temporarily.#ifdef RECORD_THEN_SAVE if ( samples ) delete samples; samples = new SampleBuffer( audioInput->bufferSize() );#else if ( sampleBuffer ) delete[] sampleBuffer; sampleBuffer = new short [ audioInput->bufferSize() ];#endif // Start the save process. startSave(); configureAction->setEnabled( FALSE ); recordTime = 0; recording = TRUE; contents->recordButton->setText( tr("Stop") ); contents->recordButton->setEnabled( TRUE ); contents->playButton->setEnabled( FALSE ); contents->stopButton->setEnabled( FALSE ); contents->delButton->setEnabled( FALSE ); // Turn on the recording light. setRecordLight( TRUE ); // Some audio devices may start sending us data immediately, but // others may need an initial "read" to start the ball rolling. // Processing at least one data block will prime the device. audioInput->start(); processAudioData();}void MediaRecorder::stopRecording(){ audioInput->stop();// configureAction->setEnabled( TRUE );// contents->recordButton->setEnabled( FALSE ); recording = FALSE;// contents->recordButton->setText( tr("Record") );// contents->choosefileButton->setEnabled( TRUE );// contents->playButton->setEnabled( TRUE );// contents->stopButton->setEnabled( FALSE );// contents->delButton->setEnabled( TRUE ); // Turn off the recording light.// setRecordLight( FALSE ); // Terminate the data save. endSave(); // Re-enable power save.#ifdef Q_WS_QWS QPEApplication::setTempScreenSaverMode( QPEApplication::Enable );#endif close();}void MediaRecorder::recordClicked(){// if ( recording ) {// stopRecording();// } else { startRecording();// }}void MediaRecorder::startPlaying(){ // Do we have a decoder for this type of file?// QString s=findplayfile->getfile();// QString name =s.left(s.length()-4); // DocLnk doc; encoder = recorderPlugins->fromType ( qualities[config->currentQuality()].mimeType, qualities[config->currentQuality()].formatTag ); // doc.setName( name );// doc.setType( encoder->pluginMimeType() );// doc.setLocation( contents->storageLocation->documentPath() );// playFile = doc.file();// playFileLink = doc.linkFile();// playFile=playFile.left(playFile.length()-8)+playFile.right(4); // QDir mydir;// mydir.setPath("/root/Documents/audio/x-wav/");// mydir.setNameFilter("man*.wav"); chooseFile="/root/Documents/audio/x-wav/" + mydir[countnow]; decoder = playerPlugins->fromFile( chooseFile ); if ( decoder == 0 || !( decoder->open( chooseFile ) ) ) { QMessageBox::critical( this, tr( "No playback plugin found" ), tr( "ce Recorder was unable to\n" "locate a suitable plugin to\n" "play the selected format." ) ); return; } // Reconfigure the UI to reflect the current mode. configureAction->setEnabled( FALSE ); recordTime = 0; samplesPlayed = 0; long samples = decoder->audioSamples( 0 ); long freq = decoder->audioFrequency( 0 ); samples = (samples + freq - 1) / freq; playing = TRUE; contents->recordButton->setEnabled( FALSE );// contents->playButton->setText( tr("Stop") ); contents->playButton->setEnabled( FALSE ); contents->stopButton->setEnabled( TRUE ); contents->delButton->setEnabled( FALSE ); // Open the audio output device. audioOutput = new AudioDevice( decoder->audioFrequency( 0 ), decoder->audioChannels( 0 ), 2 ); sampleBuffer = new short [ audioOutput->bufferSize() ];unsigned int leftVolume=(int)0xFFFF,rightVolume=(int)0xFFFF;bool muted=FALSE;audioOutput->setVolume(leftVolume,rightVolume,muted);//QMessageBox::critical( this, tr( "No playback plugin found" ),tr("%d"),leftVolume); printf("<1> %d %d!!!",leftVolume,rightVolume); QObject::connect( audioOutput, SIGNAL(completedIO()), this, SLOT(audioOutputDone()) ); // Force the first block to be played, to prime the device. audioOutputDone();}void MediaRecorder::stopPlaying(){ // Stop playing back the recorded sound if ( audioOutput ) { delete audioOutput; audioOutput = 0; } if ( decoder ) { decoder->close(); decoder = 0; } if ( sampleBuffer ) { delete[] sampleBuffer; sampleBuffer = 0; } // Return the UI to the default state. configureAction->setEnabled( TRUE ); contents->recordButton->setEnabled( TRUE ); playing = FALSE;// contents->choosefileButton->setEnabled( TRUE ); contents->playButton->setEnabled( TRUE ); contents->stopButton->setEnabled( FALSE );// contents->playButton->setText( tr("Play") ); contents->delButton->setEnabled( TRUE );}void MediaRecorder::replayClicked(){// if ( playing ) {// stopPlaying();// } else { startPlaying();// }}void MediaRecorder::deleteClicked(){ chooseFile="/root/Documents//audio/x-wav/Sound_06_25_52_______3____2006_1.wav"; if ( playing ) { stopPlaying(); }// DocLnk doc( lastSaved );// doc.setLinkFile( lastSavedLink ); DocLnk doc( chooseFile ); chooseFileLink="/root/Documents//audio/x-wav/Sound_06_25_52_______3____2006_1.wav.desktop"; doc.setLinkFile( chooseFileLink ); doc.removeFiles(); contents->playButton->setEnabled( FALSE ); contents->delButton->setEnabled( FALSE );}void MediaRecorder::clearData(){#ifdef RECORD_THEN_SAVE samples->clear();#endif configureAction->setEnabled( TRUE ); contents->recordButton->setEnabled( TRUE ); recordTime = 0;}void MediaRecorder::processAudioData(){ int result; long newTime; bool stopped = FALSE;#ifdef RECORD_THEN_SAVE short *buf; unsigned int length; if ( samples->nextWriteBuffer( buf, length ) ) { // Read the next block of samples into the write buffer. result = audioInput->read( buf, length ); samples->commitWriteBuffer( (unsigned int)result ); // Update the waveform display. } else { // The sample buffer is out of space, so stop recording. stopRecording(); stopped = TRUE; }#else result = audioInput->read( sampleBuffer, audioInput->bufferSize() ); while ( result > 0 ) { encoder->writeAudioSamples( sampleBuffer, (long)result ); result = audioInput->read( sampleBuffer, audioInput->bufferSize() ); }#endif // Update the record time if another second has elapsed. newTime = audioInput->position() / (long)(audioInput->frequency()); if ( newTime != recordTime ) { recordTime = newTime;// if ( recordTime >= contents->progress->totalSteps() ) {// // Change the resolution on the progress bar as we've // max'ed out the current limit.// contents->progress->setTotalSteps// (contents->progress->totalSteps() * 4);// }// contents->progress->setProgress( (int)recordTime ); } // Stop recording if we have hit the maximum record time. if ( recordTime >= maxRecordTime && !stopped ) { stopRecording(); }}void MediaRecorder::configure(){ config->processPopup();// contents->qualityCombo->setCurrentItem( config->currentQuality() ); qualityChanged( config->currentQuality() );}void MediaRecorder::noPluginError(){ QMessageBox::critical( this, tr( "No plugin found" ), tr( "Voice Recorder was unable to\n" "locate a suitable plugin to\n" "record in the selected format." ) );}#define RECORD_LIGHT_ID ((int)0x56526563) // "VRec"void MediaRecorder::setRecordLight( bool enable ){ if ( enable ) { QCopEnvelope( "Qt/Tray", "setIcon(int,QPixmap)" ) << RECORD_LIGHT_ID << Resource::loadPixmap( "record-light" ); recordLightState = TRUE; lightTimer->start( 500 ); } else { QCopEnvelope( "Qt/Tray", "remove(int)" ) << RECORD_LIGHT_ID; recordLightState = FALSE; lightTimer->stop(); }}void MediaRecorder::recordLightBlink(){ recordLightState = !recordLightState; if ( recordLightState ) { QCopEnvelope( "Qt/Tray", "setIcon(int,QPixmap)" ) << RECORD_LIGHT_ID << Resource::loadPixmap( "record-light" ); } else { QCopEnvelope( "Qt/Tray", "setIcon(int,QPixmap)" ) << RECORD_LIGHT_ID << Resource::loadPixmap( "record-blank" ); }}void MediaRecorder::closeEvent( QCloseEvent *e ){ // Shut down recording or playback. if ( recording ) { stopRecording(); } else if ( playing ) { stopPlaying(); } // Disable the "Play" and "Delete" buttons so that if we // are restarted in "fast load" mode, we will return to // the initial "nothing is recorded" state in the UI. contents->playButton->setEnabled( FALSE ); contents->delButton->setEnabled( FALSE ); contents->stopButton->setEnabled( FALSE ); e->accept();}void MediaRecorder::audioOutputDone(){ // Read the next block of samples. long samplesRead = 0; if ( !decoder->audioReadSamples( sampleBuffer, 2, 1024, samplesRead, 0 ) ) { stopPlaying(); return; } if ( samplesRead <= 0 ) { stopPlaying(); return; } // Write the samples to the audio output device. audioOutput->write( (char *)sampleBuffer, (int)( samplesRead * 4 ) ); // Update the waveform display.// contents->waveform->newSamples( sampleBuffer, samplesRead ); // Update the playback time if another second has elapsed. samplesPlayed += samplesRead; long newTime = samplesPlayed / (long)(decoder->audioFrequency( 0 )); if ( newTime != recordTime ) { recordTime = newTime;// if ( recordTime > contents->progress->totalSteps() ) {// recordTime = contents->progress->totalSteps();// }// contents->progress->setProgress( (int)recordTime ); }}void MediaRecorder::traySocket( const QCString& msg, const QByteArray &data ){ QDataStream stream( data, IO_ReadOnly ); int id = 0; QPoint p; if ( msg == "popup(int,QPoint)" ) { stream >> id >> p; } else if ( msg == "clicked(int,QPoint)" || msg == "doubleClicked(int,QPoint)" ) { stream >> id >> p; } if ( id == RECORD_LIGHT_ID ) { if ( this->isVisible() ) this->raise(); else this->showMaximized(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -