CSharpSynth.Synthesis.Voice.Start C# (CSharp) Method

Start() public method

public Start ( int channel, int note, int velocity ) : void
channel int
note int
velocity int
return void
        public void Start(int channel, int note, int velocity)
        {
            this.note = note;
            this.velocity = velocity;
            this.channel = channel;
            time = 0.0;
            fadeMultiplier = 1.0f;
            decayCounter = 0;
            fadeCounter = 0;

            //Set note parameters in samples
            attack = inst.getAttack(note);
            release = inst.getRelease(note);
            hold = inst.getHold(note);
            decay = inst.getDecay(note);

            //Set counters and initial state
            decayCounter = decay;
            if (attack == 0)
                state = VoiceState.Sustain;
            else
            {
                state = VoiceState.Attack;
                fadeCounter = attack;
            }
            inUse = true;
        }

Usage Example

Beispiel #1
0
        public void NoteOn(int channel, int note, int velocity, int program)
        {
            // Grab a free voice
            Voice freeVoice = getFreeVoice();

            if (freeVoice == null)
            {
                // If there are no free voices steal an active one.
                freeVoice = getUsedVoice(activeVoices.First.Value.getKey());
                // If there are no voices to steal then leave this method.
                if (freeVoice == null)
                {
                    return;
                }
            }
            // Create a key for this event
            NoteRegistryKey r = new NoteRegistryKey((byte)channel, (byte)note);

            // Get the correct instrument depending if it is a drum or not
            if (channel == 9)
            {
                freeVoice.setInstrument(bank.getInstrument(program, true));
            }
            else
            {
                freeVoice.setInstrument(bank.getInstrument(program, false));
            }
            // Check if key exists
            if (keyRegistry.ContainsKey(r))
            {
                if (keyRegistry[r].Count >= maxnotepoly)
                {
                    keyRegistry[r][0].Stop();
                    keyRegistry[r].RemoveAt(0);
                }
                keyRegistry[r].Add(freeVoice);
            }
            else//The first noteOn of it's own type will create a list for multiple occurences
            {
                List <Voice> Vlist = new List <Voice>(maxnotepoly);
                Vlist.Add(freeVoice);
                keyRegistry.Add(r, Vlist);
            }
            freeVoice.Start(channel, note, velocity);
            activeVoices.AddLast(freeVoice);
        }