[sdiy] math question - somewhat OT

Magnus Danielson cfmd at bredband.net
Tue Sep 21 15:06:52 CEST 2004


From: jbv <jbv.silences at Club-Internet.fr>
Subject: Re: [sdiy] math question - somewhat OT
Date: Tue, 21 Sep 2004 22:17:06 +0200
Message-ID: <41508C40.9BD7BF2A at Club-Internet.fr>

> Magnus,

JB,

> thanks for the reply.
> yes, that's what I'm looking for.

OK, that's a good start!

> But I actually need to know the mathematical way
> to compute that for a software routine that will
> draw any freq on a log scale.
> 
> for instance, if I have 3 freqs (190Hz, 445Hz, 895Hz),
> I want that routine to draw each freq at their exact position
> on a scale in which perfect partials (220, 440, 880) would
> have equal distance of 100 pixels.

OK. This little C-line would do it for you:

x = ceil(100 * log(f/110) / log(2));

Where 220 Hz is the first mark. 110 Hz is the 0th mark at origo.

> so the distance between 190 and 445 would be 107 pixels,

190 Hz => x = 79 pixels
445 Hz => x = 202 pixels

Diff => 123 pixels

ceil(100 * log(202/79) / log(2)) => 123

Check!

> and the distance between 445 and 895 would be 109 pixels
> (these aren't the right values, I'm just throwing in these
> figures for the example).

OK. Try the above one-liner in a compiler near you and enjoy the results!

It's verified on a HP48SX, so it can't be wrong, now can it? ;O)

Cheers,
Magnus



More information about the Synth-diy mailing list