Wav assets compiling along with the plugin


I’m relatively new to JUCE and C++ I was struggling for a little while loading in a file for use as a SamplerSound in a synth that I am creating until I realised I had to use an absolute path. This is a little bit of a pain as I can’t really predict where people will install my plugins and will have to change the path for every operating system I support.

So I was wondering if there was a way for me to load in all the wavs I will be using as assets and compile them into the plugin itself to bypass all of these issues?


Of course - just add them to the file list in the projucer, and they’ll be embedded as binary literals in the BinaryData class.


Ah that’s great, thank you. So can that BinaryData be cast as a file and passed into the audio format manager ?

This is the code I have at the moment, I’,m just wondering how dramatically this will need to change and if so what it might need to change to:

File* file = new File(“path/to/file.wav”);

ScopedPointer reader = audioFormatManager.createReaderFor(*file);


The AudioFormatManager also takes an InputStream as well: AudioFormatManager::createReaderFor (InputStream* audioFileStream), and the memory can be turned into a MemoryInputStream.


MemoryInputStream* input = new MemoryInputStream (BinaryData::fille_wav, BinaryData::file_wav_size, false);
auto reader = audioFormatManager.createReaderFor (input);


EDIT: Fixed code after @jules reply…


oh, careful there - createReaderFor takes ownership of the pointer you give it.


Ah cool, I was wondering, but couldn’t figure out immediately…
(Reading it again now, it’s said in the docs… sorry)


Thanks guys, works perfectly, exactly what I was trying to achieve!