Pointers to left and right channel of a stereo file

Hi,

I have an application that will process an audio wav file through an algorithm. I want my application to load a file and then run the process.
When Loading a stereo wav file to later process, is there a way I can get get a pointer to the left channel and a pointer to the right channel of the wav file before the processing? What function do I use for that if its possible?

Thanks!

You will probably use “WavAudioFormat” and “AudioFormatReader” to read your file. In “AudioFormatReader::read”, you have to provide an array of buffers which will be filled with the chanel data. If you read the whole file at once, your array of buffer will be an array of pointers to the chanel data

HTH

Yeah I am using AudioFormatReader to read and play the file, I’m not understanding how the AudioFormatReader::read function works though, I don’t know how to get an array of buffers filled with the channel data. Do I get that through the AudioFormatReader to then provide that to AudioFormatReader::read to get the for example destSamples[0] as my left channel?

Do you need the entire WAV file in memory at once or can your algorithm work by receiving small pieces of the file in sequence?

Yes, the algorithm works receiving small pieces of the file, I can set a window size parameter for it to process each window sequentially, so I don’t need the whole file loaded in memory.

I don’t have my compiler at hand, but a very primitive dand dirty implementation for this would be something like :

juce::File sampleFile;
int *const * samples;

// initialize your file

if(!sampleFile.existsAsFile())
{
 //error management
}
else			
{
 juce::AudioFormatReader* reader = juce::FormatManager::getInstance()->createReaderFor(sampleFile);


int * const *samples = new int*[buffer->numChanels];
for ( int i = 0; i < buffer->numChanels; ++i )
{
    samples[i] = new int*[buffer->lengthInSamples];
}


if (reader != 0)
{  reader.read(samples,reader->numChanels,0,reader->lengthInSamples,0,false);
}
}

/* cleanup*/

This code assumes you read all your audio file in memory at once. Further more, the samples allocation is very dirty, and the cleanup code is absent, so don’t use it as is !!! (I’m not even sure it compiles anyway)
That’s just to give you an idea of how it works.

HTH

I don’t have my compiler at hand, but a very primitive dand dirty implementation for this would be something like :
This code assumes you read all your audio file in memory at once. Further more, the samples allocation is very dirty, and the cleanup code is absent, so don’t use it as is !!! (I’m not even sure it compiles anyway)
That’s just to give you an idea of how it works.

HTH[/quote]

Thanks! That is very helpful to get a good idea how things are working. To try it out I implemented that with a few changes and with cleanup code and it does compile.
To see if I’m actually getting what I want I would like to hear just the left (or right) channel and see if I’m pointing to the correct data. I would like to pass in the ‘samples[0]’ (left channel) as input to some function that will let me play the audio data and hear it, assuming that I got the pointers to each channel correctly…
how could I playback each channel once at a time?? Thanks again for the info!

Is there a good example for AudioFormatReader->read() anywhere? I can’t find one and the code outlined above doesn’t work. I’m having trouble figuring out how Juce is trying to load the file into memory (and how to allocate memory correctly for that).