Skip to content

Commit 4ef45b2

Browse files
committed
Prevent acqusition when audio sample rate is less than 44.1 kHz
1 parent 5314dd0 commit 4ef45b2

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
lines changed

Source/Processors/FileReader/FileReader.cpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ FileReader::FileReader() : GenericProcessor ("File Reader"),
5151
m_sysSampleRate (44100),
5252
playbackActive (true),
5353
gotNewFile (true),
54-
loopPlayback (true)
54+
loopPlayback (true),
55+
sampleRateWarningShown (false)
5556
{
5657
/* Add built-in file source (Binary Format) */
5758
supportedExtensions.set ("oebin", 1);
@@ -500,8 +501,32 @@ void FileReader::updateSettings()
500501
adm.getAudioDeviceSetup (ads);
501502
m_sysSampleRate = ads.sampleRate;
502503
m_bufferSize = ads.bufferSize;
504+
505+
if (m_sysSampleRate < 44100.0)
506+
{
507+
if (! sampleRateWarningShown)
508+
{
509+
LOGE ("File Reader: Sample rate is less than 44100 Hz. Disabling processor.");
510+
511+
if (! headlessMode)
512+
{
513+
AlertWindow::showMessageBox (AlertWindow::WarningIcon,
514+
"[File Reader] Invalid Sample Rate",
515+
"The sample rate of the audio device is less than 44.1 kHz. File Reader is disabled."
516+
"\n\nTry adjusting the sample rate in the audio settings by clicking the 'Latency' button in the Control Panel "
517+
"and setting it to 44.1 kHz or higher. After making this change, please remove and re-add the File Reader to the signal chain.");
518+
}
519+
520+
sampleRateWarningShown = true;
521+
}
522+
523+
isEnabled = false;
524+
return;
525+
}
526+
503527
if (m_bufferSize == 0)
504528
m_bufferSize = 1024;
529+
505530
m_samplesPerBuffer.set (m_bufferSize * (getDefaultSampleRate() / m_sysSampleRate));
506531

507532
bufferA.malloc (currentNumChannels * m_bufferSize * BUFFER_WINDOW_CACHE_SIZE);
@@ -602,7 +627,7 @@ void FileReader::process (AudioBuffer<float>& buffer)
602627

603628
if (! playbackActive && playbackSamplePos + samplesNeededPerBuffer > stopSample)
604629
{
605-
samplesNeededPerBuffer = int(stopSample - playbackSamplePos);
630+
samplesNeededPerBuffer = int (stopSample - playbackSamplePos);
606631
switchNeeded = true;
607632
}
608633
else
@@ -745,7 +770,7 @@ void FileReader::readAndFillBufferCache (HeapBlock<float>& cacheBuffer)
745770
// if reached end of file stream
746771
if ((currentSample + samplesToRead) > stopSample)
747772
{
748-
samplesToRead = int(stopSample - currentSample);
773+
samplesToRead = int (stopSample - currentSample);
749774
if (samplesToRead > 0)
750775
input->readData (cacheBuffer + samplesRead * currentNumChannels, samplesToRead);
751776

Source/Processors/FileReader/FileReader.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ class FileReader : public GenericProcessor,
186186
/** Flag if a new file has been loaded */
187187
bool gotNewFile;
188188

189+
/** Flag if the invalid sample rate warning is shown */
190+
bool sampleRateWarningShown;
191+
189192
/** Total number of samples played back since most recent start of acquisition */
190193
int64 playbackSamplePos;
191194

Source/UI/ControlPanel.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,29 @@ void ControlPanel::startAcquisition (bool recordingShouldAlsoStart)
569569
return;
570570
}
571571

572+
573+
if (audio->getSampleRate() < 44100)
574+
{
575+
playButton->setToggleState (false, dontSendNotification);
576+
recordButton->setToggleState (false, dontSendNotification);
577+
578+
String errorMsg = "Sample rate too low. Unable to start acquisition!";
579+
LOGE (errorMsg);
580+
581+
if (! isConsoleApp)
582+
{
583+
errorMsg += "\n\nThe sample rate must be at least 44.1 kHz to process data. "
584+
"Try changing the sample rate in the audio configuration window (click on the \"Latency\" button in the Control Panel) "
585+
"to a value of 44.1 kHz or higher. If no such option is available, try changing the output device type.";
586+
587+
AlertWindow::showMessageBox (AlertWindow::WarningIcon,
588+
"Acquisition Error!",
589+
errorMsg);
590+
}
591+
592+
return;
593+
}
594+
572595
if (! isConsoleApp && audioEditor->isAudioConfigurationWindowVisible())
573596
{
574597
audioEditor->disable();

0 commit comments

Comments
 (0)