Converting Wav file to float array


#1

Hello
I am trying to read a wav file and turn it into a float array for manipulation…
I have searched the forum and tried a few approaches to this, but to no avail.

I have tried using read from AudioFormatReader to at least extract an int** but couldn’t get this to work (resulted in bad_access error in XCode).

I’ve also tried using a FileInputStream and the readFloat function, which seems to almost work, but when I tried to output the resulting array I just got a nasty sound from the speakers…

I’m fairly new to Juce and C++ so any help would be much appreciated!

Cheers
J


As a newbie I just want to load a sample and play it
#2

the method that you missed which conveniently loads audio data into memory is AudioSampleBuffer::readFromAudioReader

This code should get you started:

    File file ("d:/my.wav");
    AudioFormatManager formatManager;
    formatManager.registerBasicFormats();
    ScopedPointer<AudioFormatReader> reader = formatManager.createReaderFor(file);
    if (reader != 0)
    { 
        AudioSampleBuffer buffer(reader->numChannels, reader->lengthInSamples);
        buffer.readFromAudioReader(reader, 0, reader->lengthInSamples, 0, true, true);
        float* firstChannelSamples = buffer.getSampleData(0, 0);
    }

#3

Yes!
Thanks for the help, much appreciated!

J


#4

AudioSampleBuffer::readFromAudioReader has vanished, but ...

http://www.juce.com/doc/tutorial_looping_audio_sample_buffer