Mercurial > hg > svapp
diff audio/AudioRecordTarget.cpp @ 570:6f54789f3127 3.0-integration
Fix race condition in first-time recording, where adding the recording wave model would prompt the audio play source to note that its channel count had increased (from 0 to, say, 2) and thus to cause the audio device to be reopened, stopping recording. Fix is to make this only happen if channel count increases beyond that of the device, which shouldn't happen in the recording case
author | Chris Cannam |
---|---|
date | Wed, 04 Jan 2017 11:48:03 +0000 |
parents | e348e0c52115 |
children | 9fb190c6521b |
line wrap: on
line diff
--- a/audio/AudioRecordTarget.cpp Wed Jan 04 09:57:13 2017 +0000 +++ b/audio/AudioRecordTarget.cpp Wed Jan 04 11:48:03 2017 +0000 @@ -102,8 +102,10 @@ } void -AudioRecordTarget::setInputLevels(float, float) +AudioRecordTarget::setInputLevels(float left, float right) { + cerr << "AudioRecordTarget::setInputLevels(" << left << "," << right << ")" + << endl; } void @@ -123,7 +125,7 @@ QString subdirname("recorded"); if (!parent.mkpath(subdirname)) { - cerr << "ERROR: AudioRecordTarget::getRecordContainerFolder: Failed to create recorded dir in \"" << parent.canonicalPath() << "\"" << endl; + SVCERR << "ERROR: AudioRecordTarget::getRecordContainerFolder: Failed to create recorded dir in \"" << parent.canonicalPath() << "\"" << endl; return ""; } else { return parent.filePath(subdirname); @@ -138,7 +140,7 @@ QString subdirname = QString("%1").arg(now.toString("yyyyMMdd")); if (!parent.mkpath(subdirname)) { - cerr << "ERROR: AudioRecordTarget::getRecordFolder: Failed to create recorded dir in \"" << parent.canonicalPath() << "\"" << endl; + SVCERR << "ERROR: AudioRecordTarget::getRecordFolder: Failed to create recorded dir in \"" << parent.canonicalPath() << "\"" << endl; return ""; } else { return parent.filePath(subdirname); @@ -149,43 +151,46 @@ AudioRecordTarget::startRecording() { { - QMutexLocker locker(&m_mutex); + QMutexLocker locker(&m_mutex); - if (m_recording) { - cerr << "WARNING: AudioRecordTarget::startRecording: We are already recording" << endl; - return 0; - } + if (m_recording) { + SVCERR << "WARNING: AudioRecordTarget::startRecording: We are already recording" << endl; + return 0; + } - m_model = 0; - m_frameCount = 0; + m_model = 0; + m_frameCount = 0; - QString folder = getRecordFolder(); - if (folder == "") return 0; - QDir recordedDir(folder); + QString folder = getRecordFolder(); + if (folder == "") return 0; + QDir recordedDir(folder); - QDateTime now = QDateTime::currentDateTime(); + QDateTime now = QDateTime::currentDateTime(); - // Don't use QDateTime::toString(Qt::ISODate) as the ":" character - // isn't permitted in filenames on Windows - QString filename = QString("recorded-%1.wav") - .arg(now.toString("yyyyMMdd-HHmmss-zzz")); + // Don't use QDateTime::toString(Qt::ISODate) as the ":" character + // isn't permitted in filenames on Windows + QString nowString = now.toString("yyyyMMdd-HHmmss-zzz"); + + QString filename = tr("recorded-%1.wav").arg(nowString); + QString label = tr("Recorded %1").arg(nowString); - m_audioFileName = recordedDir.filePath(filename); + m_audioFileName = recordedDir.filePath(filename); - m_model = new WritableWaveFileModel(m_recordSampleRate, - m_recordChannelCount, - m_audioFileName); + m_model = new WritableWaveFileModel(m_recordSampleRate, + m_recordChannelCount, + m_audioFileName); - if (!m_model->isOK()) { - cerr << "ERROR: AudioRecordTarget::startRecording: Recording failed" - << endl; - //!!! and throw? - delete m_model; - m_model = 0; - return 0; - } + if (!m_model->isOK()) { + SVCERR << "ERROR: AudioRecordTarget::startRecording: Recording failed" + << endl; + //!!! and throw? + delete m_model; + m_model = 0; + return 0; + } - m_recording = true; + m_model->setObjectName(label); + m_recording = true; } emit recordStatusChanged(true); @@ -196,15 +201,15 @@ AudioRecordTarget::stopRecording() { { - QMutexLocker locker(&m_mutex); - if (!m_recording) { - cerr << "WARNING: AudioRecordTarget::startRecording: Not recording" << endl; - return; - } + QMutexLocker locker(&m_mutex); + if (!m_recording) { + SVCERR << "WARNING: AudioRecordTarget::startRecording: Not recording" << endl; + return; + } - m_model->writeComplete(); - m_model = 0; - m_recording = false; + m_model->writeComplete(); + m_model = 0; + m_recording = false; } emit recordStatusChanged(false);