I'm trying to get a synthesiser (sampler) to play a sampled piano note.
I seems that all works except the "renderNextBlock"-Method. The method throws following error:
Type* getWritePointer (int channelNumber, int sampleIndex) jassert (isPositiveAndBelow (sampleIndex, size));
My first step is to create a component which is a subclass of " AudioAppComponent". I specify the number of input and output channels, initialize my synth with SamplerVoice and SamplerSound and set the current playback rate for the synth.
My next step was to create a MidiBuffer:
MidiMessage note = MidiMessage::noteOn(1, 64, (uint8)127); midiBuffer = new MidiBuffer(); midiBuffer->addEvent(note, 0);
The error is thrown in the "getNextAudioBlock"-Method. Here I do the following:
bufferToFill.clearActiveBufferRegion(); bufferToFill.buffer->clear(); synth->renderNextBlock(*bufferToFill.buffer, *midiBuffer, counter, bufferToFill.numSamples); counter += bufferToFill.numSamples;
I use the "counter"-Member to track the offset for the synth-rendering.
All I get is a very short sound (I think the first 512 bytes from the first block) and then the error is thrown. If I replace the counter with "0" then my app doesn't crash but I'm hearing a shuttering sound (again the 512 bytes in a loop?).
I have read the synthesizer class reference again and again but I can't figure out where the problem is.
I think the solution is very obvious but I don't get it. Would be nice if somebody can push me in the right direction.