Subject: freq_to_fnum adlib From: "Leonard, James R \(Jim\)" Date: Mon, 21 Apr 2008 14:49:18 -0500 To: "Jim Leonard" compare this to demo.pas Copyright (C) by Hannu Savolainen 1993-1997 static void freq_to_fnum (int freq, int *block, int *fnum) { int f, octave; /* * Converts the note frequency to block and fnum values for the FM chip */ /* * First try to compute the block -value (octave) where the note belongs */ f = freq; octave = 5; if (f == 0) octave = 0; else if (f < 261) { while (f < 261) { octave--; f <<= 1; } } else if (f > 493) { while (f > 493) { octave++; f >>= 1; } } if (octave > 7) octave = 7; *fnum = freq * (1 << (20 - octave)) / 49716; *block = octave; } -- Jim Leonard, Unix SA, Alcatel-Lucent