Triggering multiple samples simultaneously


#1

I am working on an audio plugin project where I would like to start (and stop) a large number of audio loops with some level of accuracy. Iterating through and array using a for loop (even unchecked) feels wrong. Is there a recommended approach I should be researching or am I waiting for the wrong bus in Jules speak smiley?

 

Thanks in advance

Tone


#2

hi!

when you look at the [Synthesiser] : noteOn method you will notice that traversing through an arrays of [SythesiserSound/Voice] is the only way to track them down. If you want to be super efficient then you have to make your Voice tracking yourself, with use of an array (by the way). Storing indexes of currently playing voices to shut them down on your will is the way i can imagine for now. 


#3

If you want to avoid O(n) complexity you could always create a custom data structure that contains an array of sounds for every note / velocity information (or whatever data layout you need):

/* This code is just a ugly sketch to show what I mean. There a tons of missing safe checks and stuff. Also this takes only velocity / note number into account. If you use stuff like round robins and so on, it gets more complicated. */

struct VoiceMap
{

    void addSound(SynthesiserSound *sound)
    {
        for(int note = 0; note < 128; note++)
        {
            for(int velocity = 0; velocity < 128; velocity++)
            {
                if(sound->appliesToNote(note) && sound->appliesToVelocity(velocity))
                    map[note][velocity].add(s);
            }
        }
    } 


    SynthesiserSound *getSoundsFor(int noteNumber, int velocity)
    {
        return map[noteNumber][velocity].getRawDataPointer();
    }

    Array<SynthesiserSound> map[128][128];
}

// Usage
noteOn(const MidiMessage &m)
{
    SynthesiserSound *soundsToStart = voiceMap.getSoundsFor(m.getNoteNumber(), m.getVelocity());
    for(int i = 0; i < soundsToStart.size(); i++)
    {
        START_THE_SOUND(soundsToStart[i]);
    }
}


I thought about implementing something like this too but actually, iterating over an array is not a problem at voice start (I am doing this with ~40k samples without being bottlenecked there), so I would suggest you start with the basic array, profile and tweak until you satisfied...


#4

Thanks all for the info. Makes things a bit clearer.