How to make a synth voice play back a wav file on a sample-by-sample basis?

I want to try to trigger a WAV file to play back in sample-by-sample processing within my MPESynthVoice under renderNextBlock. I am okay with the file location being hardcoded for simple testing.

eg. file is C:\testwav.wav

I would like a simple way of having it do something like this:

//To trigger playback:
playWav = true;
sampleIndex = 0;

//Playback:
if (playWav == true) {
double wavSampleOutput = wavSample[sampleIndex];
sampleIndex = sampleIndex +1;
}

I don’t want to manually put it all the wav file’s values into an array/vector or anything though. I just mean I want to step through the wav file sample-by-sample on command/trigger and get the values so I can use them elsewhere in my synth voice.

The tutorial I see on playing back audio samples is all about block/buffer based processing:

https://docs.juce.com/master/tutorial_playing_sound_files.html

Is there any simple way to do what I’m talking about? Could you share a bit of example code for how it would work? Thanks.

If the only way to do this is to iterate through the samples of the wav file and add them to a vector to create a wave table on initialization of the voice/synth, I’m okay with that too. I just don’t want to have to manually create the vector of all the per sample wav values myself. Is it possible to make JUCE do that?

You need to load the whole WAV file into memory. You can stream, but takes a bit more work. If I recall JUCE does have a code for that, but I don’t remember what it was.