I am about a week into learning JUCE and I am having a great time!
Today, I encountered something that I am having trouble figuring out. I am going through the “Add distortion through waveshaping and convolution” tutorial and I don’t hear anything different when implementing the convolution processor chain. The signal just gets quieter. I have commented out the dsp reverb within the AudioEngine class to hear the signal more clearly, and when I try the cassette_recorder.wav the same thing happens - no effect on the audio except for the signal getting quieter. I have even tried loading in some reverb wav IRs, but the same result. I haven’t really changed the code from the tutorial, so I am stuck on how I can load impulse responses.
This is a function inspired by @daniel I used for loading a bunch of impulse responses loaded in as binaries to an array of AudioSampleBuffers. If you’re just loading 1 impulse response obviously you won’t need any of the for() loop and indexing business. Let me know if you have any issues!
// Relevant declarations
#define HRIR_FILE_SIZE 1068
// Iterate through the list of binary resources (i.e. the impulse responses)
for (int i = 0; i < BinaryData::namedResourceListSize; ++i)
const char* binaryData = 0;
int binaryDataSize = 0;
// Extract impulse response from binary resource list
binaryDataSize = HRIR_FILE_SIZE;
binaryData = BinaryData::getNamedResource(BinaryData::namedResourceList[i], binaryDataSize);
// Create a memory stream for the impulse response
auto* inputStream = new MemoryInputStream (binaryData, binaryDataSize, false);
// Create WAV format reader for this stream
reader = format.createReaderFor (inputStream, true); // takes ownership
// If reader was successfully created, read stream into corresponding index of AudioSampleBuffer array
int streamNumChannels = reader->numChannels;
int streamNumSamples = (int)reader->lengthInSamples;
bufferArray[i] = juce::AudioBuffer<float>(streamNumChannels, streamNumSamples);
reader->read(&bufferArray[i], 0, streamNumSamples, 0, true, true);
To get the size of a binary if you don’t know it, invoke the BinaryData namespace and follow it with the name of the binary file followed immediately by “Size” like so (in this case file is called IR.wav):
In my case HRIR_FILE_SIZE was 1068 as all of my impulse responses I was using were 1068 bytes. If you want to load a bunch of impulse responses of differing sizes that will be a bit trickier, because as far as I can tell the BinaryData namespace allows you return individual items from a list of loaded binaries and and the number of items in the list (amongst other things: https://github.com/juce-framework/JUCE/blob/master/extras/AudioPluginHost/JuceLibraryCode/BinaryData.h), but you can’t return the size of individual items from the binary list. Aside from working out the size of each binary item and hardcoding them into a separate list, the only other way I can think of would be some kind of use of the “Size” thing I mentioned in my previous post.
If this for() loop structure came across an image you would invariably be thrown an error. If you want to load both audio and image binaries your best bet would be to drag all your binaries into the Projucer first (say for argument’s sake you have 10), then your images. Then you’d have this for() loop iterate from 0 to 9. I’ve loaded and drawn binary images like so: