Loading into my plugin a sample wav file from my hard drive - do I load it into an AudioBuffer<float> area?

I’ve got a sample on my hard drive that I’d like my plugin to load up during initialization.

Can I store this in a AudioBuffer type area? I.e. the same type that appears in the processBlock()? I will have to setSize of this AudioBuffer of course, in relation to the sample being loaded.

And does it matter if the sample being loaded is 48,000, 32 bit, or will my Juce plugin just convert it to 44,100 32 bit?

I stumbled on this tutorial from the Audio Programmer, made things clearer re: loading a sample in and putting it into a buffer.
# Build a Sampler VST Plug-in with JUCE Part 1 - Loading and Playing

However, I am still wondering about this question:

If I recall correctly, you will need to consider sample rate, but the internal audio data will be stored in floating point, so that is a non-issue. You can either do the sample rate conversion on the read, or at playback. JUCE has a usable SRC with JUCE: ResamplingAudioSource Class Reference

1 Like

Would it make sense to do it on the Read rather than the playback as that could slow things down?
So if I am importing a 48000 wav file, I can convert it to a 44100 – is 44100 32bit what Juce operates in best?

None of the Juce provided resampling solutions is particularly heavy on the CPU, so you could just do the resampling during playback in real time, especially if you are just playing back a single file.

But if you opt for the resampling when reading the file from disk, you need to resample to the current sample rate chosen by the user/system in your application/plugin. (There’s no “native” sample rate in Juce.)

1 Like