Synthetizer : Selecting waveform

Hi all!

I'm coding a synth with 5 types of waveforms, and I'm kinda confused on how to tell the synth which waveform is selected by the user.

My synth has 5 sounds ( one for each waveforms ) and 25 voices ( 5 per sounds ).

Maybe my approach isn't right?

Any help would be appreciated!





    nbVoices = 5;

    for (int i = 0; i<nbVoices; i++)
        synth.addVoice (new SineWaveVoice());
        synth.addVoice (new SquareWaveVoice());
        synth.addVoice (new TriangleWaveVoice());
        synth.addVoice (new UpSawWaveVoice());
        synth.addVoice (new DownSawWaveVoice());
    synth.addSound (new SineWaveSound());
    synth.addSound (new SquareWaveSound());
    synth.addSound (new TriangleWaveSound());
    synth.addSound (new UpSawWaveSound());
    synth.addSound (new DownSawWaveSound());

Am I supposed to delete all voices and sounds every time the waveform is changed on an oscillator?


I think you should not treat your voices as you source of waveforms.

Your waveforms should be generated by some independent source in your plugin code and _read_ from the the voices instantiated with them.

This way, you can e.g. pool pre-enerated waves and don't have to recompute them for every voice involved.