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 - Playing Sound Samples

Reply to topic
Author Message
  • Joined: 13 Apr 2014
  • Posts: 21
  • Location: London, UK
Reply with quote
Playing Sound Samples
Post Posted: Mon Apr 14, 2014 12:52 am
Hi everyone,

Below is the code used to play the "Let's Go" sound sample at the start of each level in the Game Gear version of Lemmings 2. I've attached the output table (1024 bytes) and the sound sample as a RAR file. The code was written for KASM (written by Krysalis Software, in 1992!) so you may need to edit it to work in the assembler of your choice.


SMPRTE   DB 0

INSREG:   LD C,#80      ;Initialise sound registers
   LD B,3
ISR10:   LD A,C
   OUT (PSG),A
   XOR A
   OUT (PSG),A   
   LD A,C
   ADD #20
   LD C,A
   DJNZ ISR10
   RET
   
PSGSAMP:   DI
   CALL INSREG
   LD HL,LETSGO   ;Sample data
   LD BC,6346      ;Length
   LD A,16      ;Rate
   LD (SMPRTE),A
PSGS10:   LD A,(HL)
   SUB 127
   PUSH HL
   LD L,A
   LD H,0
   ADD HL,HL
   ADD HL,HL
   LD A,(SMPRTE)
   LD E,A
PSGS20:   DEC E
   JR NZ,PSGS20   
   LD A,L
   ADD 255&SAMPTB
   LD E,A
   LD A,H
   ADC SAMPTB/256
   LD D,A
   PUSH BC
   LD A,(DE)
   LD B,A
   INC DE
   LD A,(DE)
   LD C,A
   INC DE
   LD A,(DE)
   LD D,A
   LD E,C
   LD C,PSG
   OUT (C),B
   OUT (C),E   
   OUT (C),D   
   POP BC
   POP HL
   DEC BC
   INC HL
   LD A,B
   OR C
   JP NZ,PSGS10
   EI
   RET

SAMPTB:   INCBIN L2SGSMTB.BIN   ; 1024
LETSGO:   INCBIN L2LETSGO.SMP   ; 6346


Code from twenty years ago, so no guarantees, your mileage may vary, etc. :-)
L2 Sample Data.rar (4.66 KB)
L2 Sample Data

  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 12985
  • Location: London
Reply with quote
Post Posted: Mon Apr 14, 2014 1:12 am
Interesting, it seems somewhat different from how many games do it, possibly for cross platform reasons. The sample data seems to be raw signed 8 bit data, and the lookup table is trying to get some extra resolution out of the 16 volume levels of the PSG by mixing the three channels. This comes at the cost of ROM space, but by the early 90s this was much less of an issue than in the early years of the Master System.
  View user's profile Send private message Visit poster's website
  • Joined: 31 Oct 2007
  • Posts: 847
  • Location: Estonia, Rapla city
Reply with quote
Post Posted: Mon Apr 14, 2014 8:13 am
That's an interesting approach and sounds quite decent :)

I experimented with sample playback on the PSG a while ago and went to a different route :
I took the logarithmic curve of the PSG volume register into account and with some DC offset shifting I could create 4bit streams that sound pretty naiss.
http://www.tmeeco.eu/BitShit/SMSPCM.SMS
  View user's profile Send private message Visit poster's website
  • Joined: 13 Apr 2014
  • Posts: 21
  • Location: London, UK
Reply with quote
Post Posted: Mon Apr 14, 2014 8:32 am
The lookup table was reverse engineered by hooking up a voltmeter to the headphone output and measuring the DC level for each combination of channel outputs. While this gave the highest resolution, my lack of sample processing software meant that I couldn't take advantage of it.

Cutting back this back to two channels (with two channels combined at the same level) would have yielded results that saved ROM space and might have been good enough for an 8-bit sample - but that required more time that I had.
  View user's profile Send private message
  • Joined: 31 Oct 2007
  • Posts: 847
  • Location: Estonia, Rapla city
Reply with quote
Post Posted: Mon Apr 14, 2014 8:52 am
Do you remember if there were any non-linearities like say highest peaks being flattened ?

From my tests that happened in SMS2 and only because of "wrong" choice of a resistor on the audio out pin. MD1/2 and SMS1 has no such issues, GG I have not touched.
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 12985
  • Location: London
Reply with quote
Post Posted: Mon Apr 14, 2014 12:55 pm
The lookup table seems a bit odd when I graph it. I guess the voltmeter approach may have taken into account real-system effects which you don't get with pure emulation. It is broadly dealing with the non-linearity, but has resolution issues at the high end.
lookup.png (19.7 KB)
lookup.png

  View user's profile Send private message Visit poster's website
  • Joined: 13 Apr 2014
  • Posts: 21
  • Location: London, UK
Reply with quote
Post Posted: Mon Apr 14, 2014 4:31 pm
Interesting to see it graphed. :-) Certainly the sample playback sounded much better through the speaker and headphones than in an emulator such as Fusion, but it seems at least comparable with the playback on something like Ecco the Dolphin.

Maxim wrote
The lookup table seems a bit odd when I graph it. I guess the voltmeter approach may have taken into account real-system effects which you don't get with pure emulation. It is broadly dealing with the non-linearity, but has resolution issues at the high end.
  View user's profile Send private message
Reply to topic



Back to the top of this page

Back to SMS Power!