Juce Synthesizer Class, Looping Sounds?


#1

I’m trying to implement the Synthesizer class and giving it some sounds like below (This is straight out of the juce demo)

[code]WavAudioFormat wavFormat;
AudioFormatReader* audioReader
= wavFormat.createReaderFor (new MemoryInputStream (ResourceSynth::tek3,ResourceSynth::tek3_size,
false),
true);

    synth.addSound (new SamplerSound (T("demo sound"),
                                      *audioReader,
                                      samplerNotes,
                                      74,   // root midi note
                                      0.1,  // attack time
                                      0.1,  // release time
                                      16.0  // maximum sample length
                                      ));[/code]

This works good, however how can set this sound to loop mode when a key is pressed? with the above implementation when you press a key it only triggers it once and fades out based on the release time.I have a beat sample that I want it to loop when a key is held down…Cheers!


#2

I think you’d have to write your own SynthesiserSound and SythesiserVoice that support looping. You can probably use the standard Synthesiser class, though.


#3

Thanks martin, was going to do that but checking to see if there was perhaps a different way. Since we are talking about the synth class, does any one have any code examples of implementing the pitch wheel or modulation wheel support?


#4

For my sampler classes I wanted ADSR envelope support. I decided to implement a synth voice class with the ADSR support then subclassed that to make my sampler voice. I ending up copy/pasting much of SamplerVoice’s renderNextBlock method. For my purposes this ended up being more elegant than subclassing SamplerVoice.

I don’t have any code but I assume implementing pitchwheel is just a matter of implementing the

pitchWheelMoved (const int newValue)

in your voice class and storing newValue to use in your voice class’s renderNextBlock method. Same with controllers implementing

controllerMoved (const int controllerNumber, const int newValue)

just that controllerNumber will be 1 for mod wheel.