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

Re: [sc-users] Re: Resonz x Ringz (gain issues)



At 07:43 AM 12/20/2014, James Harkins wrote:
On December 20, 2014 11:11:27 PM Alexandre Torres Porres <porres@xxxxxxxxx> wrote:

Howdy, if it's unclear why and how Ringz has more gain than Resonz, can
someone please help me out checking the source code? Sorry, I don't even
know how to do that.

Start with line 3383 here:

https://github.com/supercollider/supercollider/blob/master/server/plugins/FilterUGens.cpp

From looking at the code it appears that the filters have the same structure:

    y0 = ZXP(in) + b1 * y1 + b2 * y2;
    ZXP(out) = a0 * (y0 - y2);
    y2 = y1;
    y1 = y0;

where b1 and b2 are determined by resonant frequency and bandwidth in the usual way, and a0 is the gain term.  In Ringz, a0 is fixed at 0.5, while in Resonz it is 0.5 times one minus the poleRadius squared:

    double a0_next = (1.f - R2) * 0.5f;

R2 is determined by decay time, and here they can differ:

Ringz:
    double ffreq = freq * unit->mRate->mRadiansPerSample;
    double R = decayTime == 0.f ? 0.f : exp(log001/(decayTime * SAMPLERATE));
    double R2 = R * R;

where log001 must be ln(0.001).  (The lack of comments in all this code is deplorable.)

Resonz:
    double ffreq = freq * unit->mRate->mRadiansPerSample;
    double B = ffreq * rq;
    double R = 1.f - B * 0.5f;
    double R2 = R * R;

where rq is a parameter defined as bandwidth/centerFreq, so B is bandwidth times the sampling rate in "radians per sample", which probably means pi * BandwidthInHz * SamplingRateInHz.  So, all you should have to do is set the decayTime parameter so that the two R definitions are the same and compensate the different scaling.  A decent approximation (for narrow bandwidths) should be

    decayTime = 2*6.91/(PI * BandwidthInHz)

where 6.91 ~ ln(1000).  Finally, remember that the output of Resonz needs to be be scaled by

    1 / (1 - R2)

using Resonz's definition of R2 above.  That will definitely crank the gain up a lot, hopefully matching Ringz.

(Apologies for any algebra errors, but you get the idea.)

- Julius

Julius O. Smith III <jos@xxxxxxxxxxxxxxxxxx>
Professor of Music and, by courtesy, Electrical Engineering
CCRMA, Stanford University
http://ccrma.stanford.edu/~jos/