I need to read a .wav file into an array of samples. I’ve searched for examples of this, but I’m surprisingly not finding anything current. I’ve read through the documentation for the AudioFormatReader class and I’m in a bit over my head with the use of int** and float**. I get that these are 2d arrays, but I’m still new to this kind of syntax.
calling the read function triggers an error in audioDataConverter on this line:
inline void setAsInt32LE (int32 newValue) noexcept { *data = ByteOrder::swapIfBigEndian ((uint32) newValue); }
error: Exception thrown: read access violation.
this->data was 0xFFFFFFFFFFFFFFFF.
Here’s my code so far. I was trying out both read and readSamples. They triggered the same error. I also took a guess at how to access these samples in the lines below but haven’t made it there yet due to the error. Any assistance with my syntax would be awesome. Thanks!
if (myChooser.browseForFileToOpen())
{
File audioFile(myChooser.getResult());
AudioFormatManager formatManager;
formatManager.registerBasicFormats();
ScopedPointer<AudioFormatReader> reader = formatManager.createReaderFor(audioFile);
if (reader != 0)
{
uint64 zero = 0;
int** destChannels;
float** destBuffer;
reader->read(destBuffer, 1, zero, (int)reader->lengthInSamples);//<<<<< Error triggered here
//reader->readSamples(destChannels, 1, 0, 0, (int)reader->lengthInSamples);
float testSamp1 = **(destBuffer + 1);
float testSamp2 = **(destBuffer + 10);
float testSamp3 = **(destBuffer + 100);
}
}
I’m also open to any better ways of reading a wav file. I just need the array of samples, don’t really care how I get there.