JUCE
JUCE copied to clipboard
[Bug]: Reading one channel of a WindowsAudioFormat file crashes
Detailed steps on how to reproduce the bug
Create an audio format reader for a WindowsAudioFormat file, like *.wma
. Then call read()
on it, supplying true
to useReaderLeftChan
and false
to useReaderRightChan
.
Sample code:
AudioFormatManager formatManager{};
formatManager.registerBasicFormats();
if (auto reader = std::unique_ptr<AudioFormatReader>(formatManager.createReaderFor(File("C:\\My File.wma"))))
{
auto readLength = reader->lengthInSamples;
std::unique_ptr<AudioBuffer<float>> buffer = std::make_unique<AudioBuffer<float>>(1, readLength);
reader->read(buffer.get(), 0, readLength, 0, true, false);
}
What is the expected behaviour?
Only one channel of the audio file should be read.
Operating systems
Windows
What versions of the operating systems?
Windows 11 Pro 21H2
Architectures
64-bit
Stacktrace
juce::WindowsMediaCodec::WMAudioReader::readSamples(int * * destSamples, int numDestChannels, int startOffsetInDestBuffer, __int64 startSampleInFile, int numSamples) Line 235
juce::AudioFormatReader::read(int * const * destChannels, int numDestChannels, __int64 startSampleInSource, int numSamplesToRead, bool fillLeftoverChannelsWithCopies) Line 89
juce::AudioFormatReader::read(juce::AudioBuffer<float> * buffer, int startSample, int numSamples, __int64 readerStartSample, bool useReaderLeftChan, bool useReaderRightChan) Line 180
Plug-in formats (if applicable)
No response
Plug-in host applications (DAWs) (if applicable)
No response
Testing on the develop
branch
The bug is present on the develop
branch
Code of Conduct
- [X] I agree to follow the Code of Conduct
Just want to mention, I'm noticing line 175 of juce_AudioFormatReader.cpp
assumes that 2 channels are to be read, which may be part of the issue. I'm able to fix the bug by changing the line to read (chans, chans[1] == nullptr ? 1 : 2, readerStartSample, numSamples, true);
.