Bri Bri
Bri Bri

Reputation: 2216

Can someone explain this magic number used in this formula for converting between Amiga periods and frequencies?

I'm working on implementing an old style music tracker for S3M modules. I'm already most of the way through it, and part of what I needed to do was figure out how to convert between periods — the values used to define note pitches in old Amiga music trackers like Protracker and Scream Tracker — and pitch frequencies.

After doing some research, of which this thread on the Music StackExchange was especially helpful, I learned that the formula is ostensibly dividing the clock rate of the old Amiga computers that these trackers were originally written for by the period. So that would be 3546895 / period. (This is the PAL clock rate, btw.) For reasons I don't fully understand, this produced totally wrong frequencies for me.

Eventually I came upon this formula from an open source S3M player implementation:

frequency = 14317056.0 * sample_rate / (8363.0 * 16.0 * period)

which also didn't work for me, but then I massaged it into:

frequency = (SCREAM_TRACKER_CLOCK_RATE * (MAGIC_NUMBER / sample_rate)) / (AMIGA_MIDDLE_C_RATE * 16.0 * period)

...where SCREAM_TRACKER_CLOCK_RATE is four times 3579264 Hz or 14317056, AMIGA_MIDDLE_C_RATE is 8363 Hz, sample_rate is the sample rate of the sample to be played (i.e. its frequency for middle C, often 44100 Hz), period is the Amiga period being converted to frequency, and MAGIC_NUMBER is... 8687700.

All of the other values in this formula other than the magic number more or less make sense. (Actually I'm not sure why 16 is a factor in there, either.) But if I don't put that magic number in there, I get very wrong pitches, and I figured it out just by ear and trial and error. I could simply represent this formula as:

929002505.162523900573614 / (sample_rate * period)

...but I like the formulas in my code to make sense and not just be full of magic numbers, in case someone else (or more likely me some time later) needs to understand it.

Can anyone explain why multiplying by 8687700 works?

I came upon that number by getting the right period to frequency conversion for 44100 Hz samples, but my version of the formula then didn't have the sample rate as a variable, hence that value being 44100 * 197. But even so, I came upon 197 just because it worked and sounded right, not because I understand where it's coming from and deduced it logically some way.

Upvotes: 1

Views: 58

Answers (0)

Related Questions