Hi,
I’ve got some code that reads from an audio file and puts it into a buffer.
std::unique_ptr<juce::AudioFormatReader> formatReader(formatManager.createReaderFor(file));
if(formatReader == nullptr) return false;
This works perfectly for macos, but I’ve been running into an issue on windows.
the program gets to the creation of the “format reader” object and enters “createReaderFor”.
AudioFormatReader* AudioFormatManager::createReaderFor (const File& file)
{
// you need to actually register some formats before the manager can
// use them to open a file!
jassert (getNumKnownFormats() > 0);
for (auto* af : knownFormats)
if (af->canHandleFile (file))
if (auto in = file.createInputStream())
//manages to create the input stream
if (auto* r = af->createReaderFor (in.release(), true))
return r; //but fails to arrive here
//so it returns a nullptr
return nullptr;
}
inside “af->createReaderFor()”
//im testing with aiff format
AudioFormatReader* AiffAudioFormat::createReaderFor (InputStream* sourceStream, bool deleteStreamIfOpeningFails)
{
std::unique_ptr<AiffAudioFormatReader> w (new AiffAudioFormatReader (sourceStream));
if (w->sampleRate > 0 && w->numChannels > 0)
return w.release(); // does not reach this point. So the sample rate of input stream is 0 and so is num channels
if (! deleteStreamIfOpeningFails)
w->input = nullptr;
return nullptr;
}
It looks like it is not reading the file properly, namely the samplerate and num channels. But the num of samples seems to loading fine.
This works perfectly for WAV on windows, but not any other file type. MP3 causes a crash everytime.
Not sure whats going on here. Any Windows weirdness i need to look out for?
UPDATE: I have found out that it is only when i build with CMake that I have these problems. If I build the project directly with visual studio then it works fine. not sure what to make of this.
