Synthesiser Example

Is there a simple example of how to use the Synthesiser class with the SamplerSound and SamplerVoice classes?

I wrote a fairly minimal one a few months back:

π

1 Like

Hi π

One suggestion in Piano/Source/Synth.h in PiSynthPlayer::getNextAudioBlock(). You should be using the start sample from the AudioSourceChannelInfo struct:

void getNextAudioBlock(const AudioSourceChannelInfo& bufferToFill) override 
{
    bufferToFill.clearActiveBufferRegion();

    MidiBuffer incomingMidi;
    midiCollector.removeNextBlockOfMessages(incomingMidi, bufferToFill.numSamples);

    // pass these messages to the keyboard state so that it can update the component
    // to show on-screen which keys are being pressed on the physical midi keyboard.
    const bool injectIndirectEvents = true; // add midi messages generated by clicking on the on-screen keyboard.
    keyboardState.processNextMidiBuffer(incomingMidi, bufferToFill.startSample, bufferToFill.numSamples, injectIndirectEvents);
    synth.renderNextBlock(*bufferToFill.buffer, incomingMidi, bufferToFill.startSample, bufferToFill.numSamples);
}

Is there a reason you were using zero?

Thanks for the referece. I’ve been looking it over.

However, I am having a bigger issue, perhaps. Is there an obvious reason that this shouldn’t produce any audio? It’s going to the right audio device (verified by cout and getName().

int main (int argc, char* argv[])
{
	ScopedJuceInitialiser_GUI application;
    	AudioDeviceManager devman;
    	devman.initialise(2, 2, 0, true);
    	std::cout << devman.getCurrentAudioDevice()->getName();
    	devman.playTestSound();
    	Thread::sleep(10000);

    	return 0;
}

You’re not running an event loop, so any event-based stuff in e.g. the AudioDeviceManager) can’t run. Try it as a normal app rather than writing your own main()

Ah, that makes sense. It worked from a standard, GUI application.

Going back to the idea of a synthesiser example, I think it’s clear how the samples and voices work - you add them to the synthesiser. It would be nice to expand that information for new users, so that the subsequent steps are more clear.

Here is my test for a synthesiser, in the simplest way I could devise: code listing

If you have time, please have a look and let me know if I’m doing anything incorrectly or where I might improve on it. It’s a console app but I expect the AudioAppComponent must be running an event loop. Is that right?

Thanks!

Thanks, no that was my oversight – it didn’t occur to me it might be nonzero!

π