[Stk] Voicer and Release Time

Robert Gründler doobre@gmail.com
Tue, 10 Apr 2007 18:45:28 +0200


Hi Stephen,

thanks for your reply.

I figured out that the there was a serious performance loss when calling 
this isSounding() function from within the tick() function, so i
added a boolean "sounding" variable to my instrument, which i then alter 
from within the envelope class. This way i can check if the voice is
sounding directly from within the tick() function of voicer:

StkFloat VoicerEnv :: tick()
{
  lastOutput_= 0.0;
  for ( unsigned int i=0; i<voices_.size(); i++ ) {
       
      if (voices_[i].instrument->sounding) { // <- the is_sounding check 
now takes place inside the instance of the instrument
          lastOutput_ +=   voices_[i].instrument->tick();
    }
}
    return lastOutput_ / voices_.size();
}

I got another question though concerning Voicer. When using the channel 
argument for adding instruments / calling the noteOn function etc,
i'm unable to set different frequencies for different channels. The 
Instruments get assigned the right channels, but both play at the same 
frequency.

My attempt:

 
    for ( int i=0; i<voices; i++ ) {
      osci[i] = new Oscillators();
      osc2[i] = new Oscillators();
    }
     
    
      for ( int i=0; i<voices; i++ ) {
    voicer.addInstrument( osci[i], 0 );
    voicer.addInstrument( osc2[i], 1);
      }


...
in processMessage() :

case __SK_NoteOn_:
 
      if (value2 == 0.0 ) {  // velocity is zero ... really a NoteOff
        data->voicer.noteOff( value1, 64.0, 0 );
        data->voicer.noteOff( value1, 64.0, 1);
       
    }
    else { // a NoteOn
        data->voicer.noteOn( value1, value2, 0 );
        data->voicer.noteOn( value1-20, value2-3, 1 );



What am i doing wrong ? ;)

thanks again for your time!

-robert

Stephen Sinclair wrote:
> Sounds fine to me, just remember that you can't really check for =0.0 
> when using floating point values.  Always check < 0.0001 or something 
> similar.
>
> Another approach might be to count the number of ticks from the 
> noteOff, and mute the voice when the release time has expired, instead 
> of checking the value of the envelope.
>
> Keep in mind that you can always use the ADSR class for your envelope 
> instead of rolling your own.  If you want an exponential envelope, 
> Asymp is pretty good too.
>
>
> Steve
>
>
> Robert Gründler wrote:
>> Hi fellow list members,
>>
>> as far as i've understood, when voicer receives a noteOff, it 
>> immediately turns off  the corresponding voice:
>>
>> void Voicer :: noteOff( StkFloat noteNumber, StkFloat amplitude, int 
>> channel )
>> {
>>  for ( unsigned int i=0; i<voices_.size(); i++ ) {
>>    if ( voices_[i].noteNumber == noteNumber && voices_[i].channel == 
>> channel ) {
>>      voices_[i].instrument->noteOff( amplitude * ONE_OVER_128 );
>>      voices_[i].sounding = -muteTime_;
>>     }
>>  }
>> }
>>
>> Now i've written an Instrument that implements a flexible envelope, 
>> which can have an arbitrary numbers of breakpoints
>> after the release of a key. The problem was, when noteOff was called, 
>> the voice was turned off regardless of the release time.
>> My attempt was to modify the noteOff method and take out the line: 
>> voices_[i].sounding = -muteTime_;
>>
>> Then i've added a method to my instrument, that returns true if the 
>> last breakpoint of the envelope is reached and the value of
>> that point is 0.0.
>>
>> I call this method in the tick() function of voicer, and then set 
>> "voices_[i]sounding = -muteTime_" if it returns true.
>> Is there a better way to achieve this ?
>>
>> thanks for your help,
>>
>> -robert
>>
>>
>>
>>
>> _______________________________________________
>> Stk mailing list
>> Stk@ccrma.stanford.edu
>> http://ccrma-mail.stanford.edu/mailman/listinfo/stk
>
>