Load BinaryData and play it back

Hi Everybody,
I’ve been trying for a week now to load binary datas to my plugin and play thoose back.
Doing the “usual” way:

AudioFormatManager formatManager;
formatManager.registerBasicFormats();

MemoryInputStream* input = new MemoryInputStream (BinaryData::guitar_wav, BinaryData::guitar_wavSize, false);
AudioFormatReader* reader = formatManager.createReaderFor (input);

wasn’t working here (“new” kept being highlighted and “createReaderFor” wasn’t couldn’t be recognized )

i found that method wich seems to work for me as virtual studio seems to show no errors:

PluginProcessor.h

private:
juce::AudioFormatManager formatManager;
public:
void HelloSamplerAudioProcessor::loadFile();

PluginProcessor.cpp

#endif
{
formatManager.registerBasicFormats();
}

void HelloSamplerAudioProcessor::loadFile()
{
auto input = std::make_uniquejuce::MemoryInputStream(BinaryData::sec1_wav, BinaryData::sec1_wavSize, false);
auto* reader = formatManager.createReaderFor(std::move(input));
if (reader != nullptr);

}

But still doesn’t play the file… would anybody know what i do wrong??
Thanks!

1 Like

The “usual” way didn’t work because createReaderFor() expects either a File or std::unique_ptr<InputStream>. You’re trying to pass in a raw MemoryInputStream pointer, instead of a unique_ptr one.

auto input = std::make_uniquejuce::MemoryInputStream(BinaryData::sec1_wav, BinaryData::sec1_wavSize, false);

In this line it looks like you forgot the <> braces around juce::MemoryInputStream. Or is that a typo? If you add them, that code should load the wav from the BinaryData correctly.

Also, the code you provided has no way to play the audio back, just load it. Where’s your code that does this?

1 Like

Glad I could help!

1 Like