Import Audio: Plug-in

Hi there,

I am fairly new to Juce. I am trying to make a plug-in in which I import an audio file.

I followed the audioplayer tutorial but this is done using the Audio App mode not Plug-in.

I’ve accessed the file like so:

std::unique_ptr<AudioFormatReader> reader (formatManager.createReaderFor (filepath));

And read it to a AudioSampleBuffer object:

fileBuffer.setSize(reader->numChannels, (int) reader->lengthInSamples);
reader->read(&fileBuffer, 0, (int) reader->lengthInSamples, 0, true, true);

I’m not sure what to do next to grab that audio file data in the processBlock method so I can manipulate it (I will be processing it together with audio incoming from my DAW).

Would I say something like:

auto samplesToProcess = fileBuffer.getNumSamples() // my wav file
auto* channelData = buffer.getWritePointer (channel) + sampleToProcess; // DAW audio + wav file

(This didn’t work, but shows my thinking).

Thank you to anyone who points me in the right direction, I am learning how all the components in Juce come together structurally, so am appreciative of corrections of my current misconceptions :slight_smile:

What you do is to iterate over the samples. There are several options to achieve that:

  1. manipulate the whole buffer at once, using -> AudioBuffer::addFrom()
  2. iterate over the samples and add them, e.g. *channelData += waveData[i]; (with auto* waveData = fileBuffer.getReadPointer (channel);)

Make sure you keep the index to the next sample in your fileBuffer as a member, since each buffer is so small, each time you will only process a fraction of your wav file.

HTH

1 Like

Hi Daniel, thank you very much - it works!

I chose the second option, with a separate variable to store the index of the wav sample as you suggested. Very happy, I can move on to the next step now.