back to list

cents to freq ratio

🔗Rick McGowan <rick@...>

3/7/2003 11:36:16 AM

Does anyone have a snippet of code, or a formula, to take a number in cents and return a frequency ratio, expressed as "1:n"?

I have various other conversion functions, but I'm hoping not to have to hit the books and derive an answer...

Thanks,
Rick

🔗Carl Lumma <ekin@...>

3/7/2003 12:31:06 PM

>Does anyone have a snippet of code, or a formula, to take a number in
>cents and return a frequency ratio, expressed as "1:n"?
>
>I have various other conversion functions, but I'm hoping not to have
>to hit the books and derive an answer...

You can't mean to insist on a numerator of 1... but one does need some
sort of restriction, since there are as many ratios as close to a given
irrational as one can churn out. An interesting restriction for tuning
is finding the _simplest_ ratio that comes within some tolerance of the
irrational target. There are many ways to define simple here, n*d being
a favorite. I could easily brute-force the problem for all n*d of musical
importance, but there are surly more elegant solutions for arbitrarily
high n*d cutoffs. I'm curios what those might be myself. But this is a
question for the tuning-math list. Are you a member?

-Carl

🔗Michael McGonagle <fndsnd@...>

3/7/2003 12:46:57 PM

Rick McGowan wrote:
> Does anyone have a snippet of code, or a formula, to take a number in > cents and return a frequency ratio, expressed as "1:n"?
> > I have various other conversion functions, but I'm hoping not to have to > hit the books and derive an answer...

/*
* ref - the reference frequency (ie A-440, etc).
* cents - the cent value (or distance) from ref
*
* returns - value in Hertz (or CPS) of the desire pitch
*/
#define centsToHertz(ref, cents) ref * pow(2.0, cents / 1200)

Hope this helps...

Mike

🔗James Nagy <jnagy2002@...>

3/7/2003 12:51:43 PM

cents are exponential so im guessing freq = tonic freq
* 2 raised to the target note (e.g. 800)/1200
--- Rick McGowan <rick@...> wrote:
> Does anyone have a snippet of code, or a formula, to
> take a number in
> cents and return a frequency ratio, expressed as
> "1:n"?
>
> I have various other conversion functions, but I'm
> hoping not to have to
> hit the books and derive an answer...
>
> Thanks,
> Rick
>
>
>

__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/

🔗Rick McGowan <rick@...>

3/7/2003 1:00:07 PM

Hi Carl --

Yes, I actually do insist on a numerator of "1". The purpose is to calculate frequency ratios for an FM application where the fundamental is "1" and I need a ratio with respect to taht. I'm looking for a floating point number, not "simplest" ratio.

Rick

Carl Lumma wrote:

>>Does anyone have a snippet of code, or a formula, to take a number in >>cents and return a frequency ratio, expressed as "1:n"?
>>
>>I have various other conversion functions, but I'm hoping not to have
>>to hit the books and derive an answer...
>>
> > You can't mean to insist on a numerator of 1... but one does need some
> sort of restriction, since there are as many ratios as close to a given
> irrational as one can churn out. An interesting restriction for tuning
> is finding the _simplest_ ratio that comes within some tolerance of the
> irrational target. There are many ways to define simple here, n*d being
> a favorite. I could easily brute-force the problem for all n*d of musical
> importance, but there are surly more elegant solutions for arbitrarily
> high n*d cutoffs. I'm curios what those might be myself. But this is a
> question for the tuning-math list. Are you a member?
> > -Carl
> > > [MMM info]------------------------------------------------------
> More MMM music files are at http://www.microtonal.org/music.html
> ------------------------------------------------------[MMM info] > > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ > > > >

🔗Ronald Pieket <rpieket@...>

3/7/2003 1:04:23 PM

--- In MakeMicroMusic@yahoogroups.com, Rick McGowan <rick@u...> wrote:
> Does anyone have a snippet of code, or a formula, to take a number in
> cents and return a frequency ratio, expressed as "1:n"?

The one-cent ratio is

1 : 2 ^ 1/1200

which is approximately

1 : 1.00057779

To get the ration of N cents, raise the value to the power of N. Like
this:

1 : ( 2 ^ 1/1200 ) ^ N

You can easily see that if N = 1200 (the number of cents in an
octave), you get

1 : 2

...which is indeed the frequency ratio of an octave.

- Ronald.

🔗Carl Lumma <ekin@...>

3/7/2003 1:34:12 PM

>Yes, I actually do insist on a numerator of "1". The purpose is to
>calculate frequency ratios for an FM application where the fundamental
>is "1" and I need a ratio with respect to taht. I'm looking for a
>floating point number, not "simplest" ratio.

You want a float? -- I thought you wanted a rational... Anyway, all
ratios smaller than 1 are undefined for cents, since 0c = 1/1.
Maybe you want a denominator of 1?

-Carl

🔗Rick McGowan <rick@...>

3/7/2003 1:42:55 PM

Hi Carl --

Actually I got precisely what I wanted from several people, thank them all; most useful was from Michael McMonagle. Thanks!

#define centsToHertz(ref, cents) ref * pow(2.0, cents / 1200)

When "ref" is 1, I get "1:n" answer.

Oh, I didn't mean an "FM" application, I meant actually additive synth application... I wanted to be able to make one oscillator beat a n-times another; where 'n' is a float.
Rick