Synthesizer Class - renderNextBlock - App crash

Hi Everyone,

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:



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. wink


Could you use the "Styles" pulldown to format code blocks?

 It would make your question much easier to parse.


Type* getWritePointer (int channelNumber, int sampleIndex) 
    jassert (isPositiveAndBelow (sampleIndex, size));).

 Much nicer!

Have you checked what size is? Maybe it is 0, which would suggest there is some problem with loading your sound WAV into a buffer.


The size of my write buffer ist 512 bytes and starts always from index 0. And the method getWritePointer tries to get the write pointer from startIndex 512. 


Solved the problem.

The startSample for the audio buffer "bufferToFill" has to be 0.
Every "getNextAudioBlock" cycle I send a midi buffer with a message timestamp of 0.
And that was the issue. I have to send the buffer only once.