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 - Sampled Audio in Lemmings and Mortal Kombat II

Reply to topic
Author Message
  • Joined: 08 Dec 2005
  • Posts: 488
  • Location: Melbourne, Australia
Reply with quote
Sampled Audio in Lemmings and Mortal Kombat II
Post Posted: Mon Jan 09, 2012 10:26 pm
Lemmings and Mortal Kombat II, both developed by Probe, use exactly the same code to play their audio samples.

The code works on 8-bit signed sample data, converting a sample to 4-bit unsigned and outputting it to the PSG once every 467 Z80 cycles. This works out as a sample rate of approximately 7600Hz on PAL systems.

I have extracted the sample data from the ROMs and attach it here both in raw binary form and converted to WAV format - allowing the samples to be heard in their full 8-bit quality. (All of the attached files have been zipped due to the forum's restrictions on file extensions.)

Interestingly, the samples in Lemmings are almost identical to those used in the original Amiga version. For the Master System they have been slightly shortened, and a 62-byte header and 4-byte footer ("AMII") have been added. The SMS games treat the header and footer as part of the sample data - this is the reason for the clicks at the beginning and end of the attached WAV files.

On the Amiga the Lemmings voices are played at a rate of one sample every 480 cycles of the "Paula" chip. Since this chip runs at the same clock rate as the Master System's Z80, the Amiga plays the samples more slowly: at approximately 7400Hz.

  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14740
  • Location: London
Reply with quote
Post Posted: Tue Jan 10, 2012 10:57 am
Here's some MP3 versions...
Lemmings - OhNo.mp3 (3.87 KB)


  View user's profile Send private message Visit poster's website
  • Joined: 31 Oct 2007
  • Posts: 853
  • Location: Estonia, Rapla city
Reply with quote
Post Posted: Tue Jan 10, 2012 11:02 am
Do the games convert the samples to PSG log curve or they just chop off bottom 4 bits and go with top 4 ?
  View user's profile Send private message Visit poster's website
  • Joined: 08 Dec 2005
  • Posts: 488
  • Location: Melbourne, Australia
Reply with quote
Post Posted: Thu Jan 12, 2012 10:27 am
Last edited by RetroSpark on Sat Sep 10, 2016 10:59 am; edited 1 time in total
TmEE wrote
Do the games convert the samples to PSG log curve or they just chop off bottom 4 bits and go with top 4 ?

They just use the top 4 bits:

    ld      a, (hl)
    inc     hl
    sub     $80
    srl     a
    srl     a
    srl     a
    srl     a


RetroSpark wrote
once every 467 Z80 cycles
[...]
On the Amiga the Lemmings voices [...] one sample every 480 cycles

Immediately after the above code comes a delay loop which consumes the majority of the 467 cycles:

    ld      b, $19
-:  djnz    -

DJNZ takes 13 cycles when b is non-zero. So, simply increasing the loop count from $19 to $1a will make the sample rate exactly match the Amiga.
  View user's profile Send private message Visit poster's website
  • Joined: 31 Oct 2007
  • Posts: 853
  • Location: Estonia, Rapla city
Reply with quote
Post Posted: Thu Jan 12, 2012 11:05 am
You get slightly less noisy output when you convert samples to log. It is still noisy though, but in a different way...
  View user's profile Send private message Visit poster's website
Reply to topic



Back to the top of this page

Back to SMS Power!