Skip to content

Instantly share code, notes, and snippets.

@simondotm
Last active January 14, 2021 02:25
Show Gist options
  • Save simondotm/84a08066469866d7f2e6aad875e598be to your computer and use it in GitHub Desktop.
Save simondotm/84a08066469866d7f2e6aad875e598be to your computer and use it in GitHub Desktop.
Retuning SN76489 chip tune music written for Sega Master System on a BBC Micro

We use Deflemask to author SN76489 chip music, for which support is aimed mainly at NTSC Sega Master System. We export these tunes as VGMs from Deflemask and then to get them working on a BBC Micro we have to do some shenanigans because the BBC version of the SN76489 has two key differences from the SMS:

  1. It is clocked at 4Mhz not 3.58Mhz
  2. It has a 15-bit linear-feedback shift register (LFSR) for noise channel generation (the SMS version has 16-bits).

Because the squarewave output of the sound chip is driven by its clockspeed, to transpose frequencies from NTSC to 4Mhz we have to adjust every pitch value sent to the chip registers. This is done mathematically by converting the NTSC pitch register value to Hz and then calculating the equivalent pitch register value on a 4Mhz clocked chip to deliver the same Hz frequency.

That bit is easy (ish).

The tricky bit is when musicians use the tuned periodic noise function on the chip to create basslines. In this scenario channel 2 pitch controls the pitch of the periodic noise channel.

Periodic noise works by emitting a pulse at a fraction of the main clock speed. On Sega, this is 1/16. However on the Beeb, it is 1/15. (more on this later).

This means that, on the BBC at least, an additional frequency adjustment to channel 2 pitch values is necessary to maintain correct periodic noise tuning when transposing from 3.54Mhz to 4Mhz. So far, my conversion script could detect this and correct for it.

Now typically, musicians will mute channel 2 when playing PN on channel 3.

However, our smart musician, Inverse Phase, figured out that in Deflemask we can effectively get 4 channels of audio (3 tones + 1 bass) playing at the same time by NOT muting channel 2.

This is entirely correct, and a neat trick indeed. And works well on Sega because it turns out that PN being generated at 1/16 of the channel 2 frequency is harmonious.

However on the Beeb, 1/15 PN frequencies are discordant.

For example: On Sega, a pitch of 440Hz on channel 2 will play 27.5Hz on PN channel3 (exactly 4 octaves lower). With the BBC, 440Hz on channel2 will deliver 29.33Hz on PN channel3 (almost 4 octaves lower - but out of tune).

The conclusion is that, on BBC Micros, unlike Sega Master Systems, it is not possible to play 3 tone channels as well as a tuned periodic noise on channel 3 in harmony.

The solution is, that during conversion, we now detect this scenario, and force-mute channel 2 whenever a tuned PN is playing on channel 3. It does mean the music is slightly compromised because it doesnt sound as "rich" as the "Sega" version since we can only have 3 audible channels on BBC rather than 4. Of course, this only applies to "tuned" noises - if channel 3 is playing regular white noise (drums etc.) then 4 audible channels is perfectly fine.

@inversephase
Copy link

Giving away my trade secrets 😅
Also I believe 3.54 -> 3.58 (NTSC burst)?

@simondotm
Copy link
Author

Corrected, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment