Forums

Sega Master System / Mark III / Game Gear
SG-1000 / SC-3000 / SF-7000 / OMV
Home - Forums - Games - Scans - Maps - Cheats - Credits
Music - Videos - Development - Hacks - Translations - Homebrew

View topic - SMS VGM timing

Reply to topic
Author Message
  • Joined: 24 Jan 2022
  • Posts: 4
  • Location: Quebec
Reply with quote
SMS VGM timing
Post Posted: Mon Jan 24, 2022 3:38 am
Hi! I'm coding a VGM player that work using the SN76489 from the Tandy (seen in many homebrew ISA cards now). For now I want to only support VGM from the Sega Master System' PSG.

It seem that the SMS .VGM file I checked mainly use 4 commands : 0x50 to send data and 0x63,0x62,0x61 for some timing. 0x63 and 0x62 would be shortcut to 0x61 for 735 and 882 samples and 0x61 specify amount of samples to wait. Are those sample related to the PSG 3,579,545 hz clock rate ?

I dont understand how 735 or 882 sample should represent 1/60 and 1/50 seconds at a 3579545 frequency.

So far working good with delay estimation of 0x63 and 0x62 instruction but I cannot cheat 0x61 instruction and I would like to use precise value.

Any help understanding the VGM timing for that precise case would be grealty appreciated !
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14741
  • Location: London
Reply with quote
Post Posted: Mon Jan 24, 2022 5:46 am
The timing counts are based on a 44100Hz clock, independent of the chip timings.
  View user's profile Send private message Visit poster's website
  • Joined: 24 Jan 2022
  • Posts: 4
  • Location: Quebec
Reply with quote
Post Posted: Tue Jan 25, 2022 3:59 am
I remember noticing 44100 while reading the Paul's SonicPlayer source code but I did not knew what to make of it.

With what you told me in mind, I reviewed my timing functions and just coded a rough estimate 1/44100 pulse based on idling CPU, but the music sound much more faithful already!

Of course now I would like to use something really precise and constant. I think that the intel 825x PIT is a good candidate for my project target system. The mode 2 (rate generator) might be just what I need. But I think this might be more on topic in another forum.

I'm so glad you answered my question Maxim, since I also appreciate very much all what you bring to the SMS community.
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14741
  • Location: London
Reply with quote
Post Posted: Tue Jan 25, 2022 8:53 am
VGM is quite tolerant of jitter, you could poll a time counter if you have one. Else you might set a timer for a 60Hz interrupt (or 50Hz if appropriate), even with some inaccuracy in that timer, and move the “VGM time” forward by the relevant number of samples each time. This would not work with sampled audio in VGMs but it would be easy to support on a slow CPU.
  View user's profile Send private message Visit poster's website
  • Joined: 24 Jan 2022
  • Posts: 4
  • Location: Quebec
Reply with quote
Post Posted: Wed Jan 26, 2022 6:02 am
Maxim wrote
you could poll a time counter if you have one.


This is what I did! I was able to use the intel 8253/8254 PIT chip for the 8086/8088 CPU. To make thing easy for me I set frequency to 44100hz so the PIT would do only 27 cycles before generating an interrupt that I use to time the wait requested by 0x61,0x62 and 0x63 instructions. I think 44.1khz is a bit of a stretch as an PIT frequency since my understanding is that it loose precision the higher you divide its 1.19Mhz operation clock. But it's working well enough and is very consistent so I will leave it that way unless I know better.

I really made rapid progression in my project since you help me understand the timing. And now the fun part can begin, my goal behind that player is to try to play NES APU VGM music using the SN76489 chip. Based on the /Development/SN76489 page from this site I could make a small interface to the PSG functions. I think it will be interesting to hear what we can get after the interpretation of APU register!
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14741
  • Location: London
Reply with quote
Post Posted: Wed Jan 26, 2022 8:56 am
Converting NES APU to SN76489 is more a matter of adapting the data values, and you could do that in the realm of VGM files on a PC before moving to a hardware solution. Some conversions might require a lot more work on SMS, for example changing a triangle wave into rapid volume adjustments.
  View user's profile Send private message Visit poster's website
  • Joined: 24 Mar 2021
  • Posts: 120
Reply with quote
Post Posted: Wed Jan 26, 2022 8:04 pm
You don't need to reproduce the less-than-1/60th-second delays - those are almost always artifacts of the recording process instead of musically important.

There's a program that gets rid of the them called "vgm_facc" - unfortunately it occasionally causes quantization errors. I've written my own replacement which is tolerant of those, but I wrote it in perl which makes it useless to many other people.
  View user's profile Send private message
Reply to topic



Back to the top of this page

Back to SMS Power!