Playing AudioSampleBuffer content with midi input like a SamplerSound

Hey. how would you guys go about “playing” with midi input whats stored on an AudioSampleBuffer? Im familiar with the Synthesiser class, so I thought about using a SamplerSound but it only seems to read from a file stream.
I can just output the AudioSampleBuffer into a .wav file and read it, but it seems like a lazy solution. Im fairly new to JUCE so I might be overlooking something that can make this easier! Thanks

The Juce SamplerSound is constructed with an AudioFormatReader but it internally uses an AudioBuffer<float> aka AudioSampleBuffer. (It just reads the file into the buffer in the constructor.) You could probably copy and modify the SamplerSound code to be able to initialize it directly from a buffer. Inheriting from SamplerSound probably isn’t going to work too nicely, unfortunately. (The Juce Sampler classes are pretty limited and difficult to extend/customize…)

If you just need to be able to play your buffer with a single voice, you could likely also skip using the Juce Synthesizer/Sampler stuff entirely.

1 Like