iiwusynth-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [iiwusynth-devel] Fw: Re: [linux-audio-dev] more about iiwusynth


From: M. Nentwig
Subject: Re: [iiwusynth-devel] Fw: Re: [linux-audio-dev] more about iiwusynth
Date: Fri, 07 Jun 2002 17:45:36 +0300

...

> Ok thanks!, now I need to know the ranges of amp (what values for max
> and min volume?)

Let's see...
>From iiwu_voice.c:
---------------------------------------------
 /* calculate final amplitude
   * - initial gain
   * - amplitude envelope
   * - dividing by 32768 to scale samples down to [-1, 1] interval
   */

  if (voice->volenv_section == 1) {
    /* the envelop is in the attack section: ramp linearly to max value.
*/
    amp = iiwu_cb2amp(voice->attenuation + voice->modlfo_val *
voice->modlfo_to_vol) * voice->volenv_val;
  } else {
    amp = iiwu_cb2amp(voice->attenuation
                      + 960.0f * (1.0f - voice->volenv_val)
                      + voice->modlfo_val * voice->modlfo_to_vol);
  }

  /* Turn the voice off if the amplitude envelope goes below -100 dB
   * (anywhere except in the attack phase)
   * Using voice->attenuation is a bad idea here, because the
attenuation
   * can be reduced again with a MIDI controller (7, 11).
   * Example: Turn off the volume with a volume pedal, hit a chord
   * with a pad sound, and slowly raise the volume.
  */
  if ((voice->volenv_section != 1) && (voice->volenv_val < 0.01)) {
    iiwu_profile(IIWU_PROF_VOICE_RELEASE, voice->ref);
    voice->status = IIWU_VOICE_OFF;
    goto post_process;
  }

  /* correct the amplitude for the short to float conversion. */
  amp /= 32768.0f;
----------------------------------------------------------------------

The initial iiwu_cb2amp(...) sets amp to a value between 0 and 1. Then
the scaling factor is applied, the maximum is 1/32768 now. But instead
of the scaling factor you'll probably just convert to signed long
instead. Since the amplitude is always below 1, you could << it at this
point all the way to the left.
But:
The filter can add up to 50 dB of volume (the highest resonance peak
allowed is 100 dB, it goes with 50 dB of volume reduction according to
the SF2.01 specs). That would be an amplitude factor of 316 or 9
additional bits.
On the other hand, someone who uses a 100 dB Q factor deserves some
clipping...
It may be wise to leave a couple of bits for headroom in any case.

> > With the limited number of bits, it may well be, that this is the
> > cause of some quantization noise I keep hearing (when notes are
> > fading out)...
>
> Personally I use 32 bits integer buffers. It's just better than float
> buffers (9 bits more of precision, and values dont wrap on add/sub)
> and faster. Also it works great because the only thing you do is to
> take 16 bit ints, multiply for volume, process filter and save back.
> Anyway, so do you mean that the max value PER sample is -1 .. 1?

Yes. The sample from the sound font's sample memory is a signed short,
between -32768 and 32767:

 data = voice->sample->data;

After multiplying with amp, the values fall (roughly) between -1 and 1.

...


> Regards!
>
> Juan Linietsky
>

Regards

Markus





reply via email to

[Prev in Thread] Current Thread [Next in Thread]