=== modified file 'mixxx/src/recording/enginerecord.cpp' --- mixxx/src/recording/enginerecord.cpp 2011-12-18 20:23:14 +0000 +++ mixxx/src/recording/enginerecord.cpp 2012-02-24 14:36:48 +0000 @@ -57,15 +57,15 @@ closeFile(); if(m_recReady) delete m_recReady; if(m_samplerate) delete m_samplerate; +} -} void EngineRecord::updateFromPreferences() { m_Encoding = m_config->getValueString(ConfigKey(RECORDING_PREF_KEY,"Encoding")).toLatin1(); //returns a number from 1 .. 10 m_OGGquality = m_config->getValueString(ConfigKey(RECORDING_PREF_KEY,"OGG_Quality")).toLatin1(); m_MP3quality = m_config->getValueString(ConfigKey(RECORDING_PREF_KEY,"MP3_Quality")).toLatin1(); - m_filename = m_config->getValueString(ConfigKey(RECORDING_PREF_KEY,"Path")).toAscii(); + m_filename = m_config->getValueString(ConfigKey(RECORDING_PREF_KEY,"Path")); m_baTitle = m_config->getValueString(ConfigKey(RECORDING_PREF_KEY, "Title")).toLatin1(); m_baAuthor = m_config->getValueString(ConfigKey(RECORDING_PREF_KEY, "Author")).toLatin1(); m_baAlbum = m_config->getValueString(ConfigKey(RECORDING_PREF_KEY, "Album")).toLatin1(); @@ -126,7 +126,6 @@ { TrackPointer pTrack; - if ( m_iMetaDataLife < 16 ) { m_iMetaDataLife++; return false; @@ -153,71 +152,66 @@ return true; } -void EngineRecord::process(const CSAMPLE * pIn, const CSAMPLE * pOut, const int iBufferSize) -{ +void EngineRecord::process(const CSAMPLE * pIn, const CSAMPLE * pOut, const int iBufferSize) { + Q_UNUSED(pOut); + // Calculate the latency of this buffer m_dLatency = (double)iBufferSize / m_samplerate->get(); //if recording is disabled - if(m_recReady->get() == RECORD_OFF){ + if (m_recReady->get() == RECORD_OFF) { //qDebug("Setting record flag to: OFF"); - if(fileOpen()){ + if (fileOpen()) { closeFile(); //close file and free encoder emit(isRecording(false)); } } //if we are ready for recording, i.e, the output file has been selected, we open a new file - if(m_recReady->get() == RECORD_READY){ + if (m_recReady->get() == RECORD_READY) { updateFromPreferences(); //update file location from pref - if(openFile()){ + if (openFile()) { qDebug("Setting record flag to: ON"); m_recReady->slotSet(RECORD_ON); emit(isRecording(true)); //will notify the RecordingManager - if ( m_bCueIsEnabled ) { + if (m_bCueIsEnabled) { openCueFile(); m_cuesamplepos = 0; m_cuetrack = 0; } - } - else{ //Maybe the encoder could not be initialized + } else { //Maybe the encoder could not be initialized qDebug("Setting record flag to: OFF"); m_recReady->slotSet(RECORD_OFF); emit(isRecording(false)); } } //If recording is enabled process audio to compressed or uncompressed data. - if(m_recReady->get() == RECORD_ON){ - if(m_Encoding == ENCODING_WAVE || m_Encoding == ENCODING_AIFF){ - if(m_sndfile != NULL) + if (m_recReady->get() == RECORD_ON) { + if (m_Encoding == ENCODING_WAVE || m_Encoding == ENCODING_AIFF){ + if (m_sndfile != NULL) { sf_write_float(m_sndfile, pIn, iBufferSize); emit(bytesRecorded(iBufferSize)); + } } else{ - if ( m_encoder) { + if (m_encoder) { //Compress audio. Encoder will call method 'write()' below to write a file stream m_encoder->encodeBuffer(pIn, iBufferSize); } } - if ( m_bCueIsEnabled ) { - - if ( metaDataHasChanged()) { + if (m_bCueIsEnabled) { + if (metaDataHasChanged()) { m_cuetrack++; writeCueLine(); m_cuefile.flush(); } - m_cuesamplepos += iBufferSize; - } - } - } -void EngineRecord::writeCueLine() -{ +void EngineRecord::writeCueLine() { // account for multiple channels unsigned long samplerate = m_samplerate->get() * 2; // CDDA is specified as having 75 frames a second @@ -249,18 +243,17 @@ QString("%1").arg((double)seconds, 2, 'f', 0, '0'), QString("%1").arg((double)frames, 2, 'f', 0, '0')).toLatin1() ); - } /** encoder will call this method to write compressed audio **/ void EngineRecord::write(unsigned char *header, unsigned char *body, int headerLen, int bodyLen) { - if(!fileOpen()){ + if (!fileOpen()) { return; } //Relevant for OGG - if(headerLen > 0){ + if (headerLen > 0) { m_datastream.writeRawData((const char*) header, headerLen); } //always write body @@ -268,19 +261,19 @@ emit(bytesRecorded((headerLen+bodyLen))); } -bool EngineRecord::fileOpen(){ + +bool EngineRecord::fileOpen() { // Both encoder and file must be initalized - if(m_Encoding == ENCODING_WAVE || m_Encoding == ENCODING_AIFF){ + if (m_Encoding == ENCODING_WAVE || m_Encoding == ENCODING_AIFF) { return (m_sndfile != NULL); - } - else{ + } else { return (m_file.handle() != -1); } } + //Creates a new MP3 file -bool EngineRecord::openFile(){ - +bool EngineRecord::openFile() { //Unfortunately, we cannot use QFile for writing WAV and AIFF audio if(m_Encoding == ENCODING_WAVE || m_Encoding == ENCODING_AIFF){ unsigned long samplerate = m_samplerate->get(); @@ -294,9 +287,9 @@ m_sfInfo.format = SF_FORMAT_AIFF | SF_FORMAT_PCM_16; //creates a new WAVE or AIFF file and write header information - m_sndfile = sf_open(m_filename, SFM_WRITE, &m_sfInfo); - if(m_sndfile){ - sf_command (m_sndfile, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ; + m_sndfile = sf_open(m_filename.toLocal8Bit(), SFM_WRITE, &m_sfInfo); + if (m_sndfile) { + sf_command(m_sndfile, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ; //set meta data int ret; @@ -313,24 +306,20 @@ qDebug("libsndfile: %s", sf_error_number(ret)); } - } - else - { + } else { //we can use a QFile to write compressed audio - if(m_encoder){ + if (m_encoder) { m_file.setFileName(m_filename); m_file.open(QIODevice::WriteOnly); - if(m_file.handle() != -1){ + if (m_file.handle() != -1) { m_datastream.setDevice(&m_file); } - } - else{ + } else { return false; } - } //check if file are really open - if(!fileOpen()){ + if (!fileOpen()) { ErrorDialogProperties* props = ErrorDialogHandler::instance()->newDialogProperties(); props->setType(DLG_WARNING); props->setTitle(tr("Recording")); @@ -338,13 +327,11 @@ ErrorDialogHandler::instance()->requestErrorDialog(props); return false; } - return true; } bool EngineRecord::openCueFile() { - if ( m_cuefilename.length() <= 0 ) - { + if (m_cuefilename.length() <= 0) { return false; } @@ -352,37 +339,35 @@ m_cuefile.setFileName(m_cuefilename); m_cuefile.open(QIODevice::WriteOnly); - if ( m_baAuthor.length() > 0 ) { + if (m_baAuthor.length() > 0) { m_cuefile.write(QString("PERFORMER \"%1\"\n") .arg(QString(m_baAuthor).replace(QString("\""), QString("\\\""))) .toLatin1()); } - if ( m_baTitle.length() > 0 ) { + if (m_baTitle.length() > 0) { m_cuefile.write(QString("TITLE \"%1\"\n") .arg(QString(m_baTitle).replace(QString("\""), QString("\\\""))) .toLatin1()); } m_cuefile.write(QString("FILE \"%1\" %2%3\n").arg( - QString(m_filename).replace(QString("\""), QString("\\\"")), - QString(m_Encoding).toUpper(), - m_Encoding == ENCODING_WAVE ? "E" : " ").toLatin1()); - + QString(m_filename).replace(QString("\""), QString("\\\"")), + QString(m_Encoding).toUpper(), + m_Encoding == ENCODING_WAVE ? "E" : " ").toLatin1()); return true; } -void EngineRecord::closeFile(){ - if(m_Encoding == ENCODING_WAVE || m_Encoding == ENCODING_AIFF){ - if(m_sndfile != NULL){ +void EngineRecord::closeFile() { + if (m_Encoding == ENCODING_WAVE || m_Encoding == ENCODING_AIFF) { + if (m_sndfile != NULL) { sf_close(m_sndfile); m_sndfile = NULL; } - } - else{ + } else { //close QFile and encoder, if open - if(m_file.handle() != -1){ - if(m_encoder){ + if (m_file.handle() != -1) { + if (m_encoder) { m_encoder->flush(); delete m_encoder; m_encoder = NULL; === modified file 'mixxx/src/recording/enginerecord.h' --- mixxx/src/recording/enginerecord.h 2011-03-27 09:37:43 +0000 +++ mixxx/src/recording/enginerecord.h 2012-02-24 14:20:35 +0000 @@ -69,7 +69,7 @@ QByteArray m_OGGquality; QByteArray m_MP3quality; QByteArray m_Encoding; - QByteArray m_filename; + QString m_filename; QByteArray m_baTitle; QByteArray m_baAuthor; QByteArray m_baAlbum;