Sonic and Sega Retro Message Board: Sonic 1 DAC drum samples unleashed! - Sonic and Sega Retro Message Board

Jump to content

Hey there, Guest!  (Log In · Register) Help
Page 1 of 1
    Locked
    Locked Forum

Sonic 1 DAC drum samples unleashed!

#1 User is offline jman2050 

Posted 25 April 2006 - 01:38 PM

  • Teh Sonik Haker
  • Posts: 625
  • Joined: 10-December 05
  • Wiki edits:4
For the record, the S1 sound driver in a proper S1 rom beings at offset $72E7C and is $1760 bytes long. You'll notice in Hivebrain's disassembly that the z80 driver is split into two parts, with 5 bytes defined in between them (look at label Kos_Z80). This is because the Sega sound's location and length is stored in the sound driver, so this allows the Sega sound to be easily relocated without having to mess with the sound driver itself. I digress, but I do bring out that if you plan on changing the sound driver and reinputting it into the rom, you'll either have to put it in as one piece, or split it up again, remove the 5 bytes defining the sega sound's attributes, and arrange it the same way as Hivebrain did. This isn't about that, so I'll leave that aspect up to your own devices.

Anyway, this is about the DAC drum samples in Sonic 1. The reason I told you about extracting the S1 sound driver is simply because the PCM samples used for the drums is actually located in the sound driver itself! however, it isn't raw PCM data. The z80 ram area wouldn't have enough space to do that properly. Instead, they are in a lossy (I believe) compressed form, and are actually decompressed in real-time by the z80. How does this work?

First, open a decompressed sound driver (I'll provide one here http://www.cgi101.co...hole_decomp.bin , but if you were able to get the compressed data from the S1 rom, you could easily decompress it using the Koszinski format). You'll notice lots of hex values and crap. What's interesting is that the actual code is actually very small. Less than $100 bytes small actually. The rest of the sound driver is the compressed data. Look at byte $D6. What we have here is a table that's $18 (24) bytes long. Each entry is 8 bytes long, so this table describes exactly 3 DAC drum samples as used by Sonic 1. The format is:

bytes 1/2 - The location in Z80 memory of the DAC compressed data (little endian)
bytes 3/4 - The size in bytes of the compressed data (little endian)
bytes 5 - pitch/sample size
bytes 6-8 - unused

As for how the data is compressed, lemme explain that real quick: First, it is a lossy compression. So if you recompress a PCM sample this way, you will lose precision in data. Anyway, what happens is that each compressed data is seperated into nybbles (1 4-bit section of a byte). This first nybble of data is read, and used as an index to a table containing the following data: 0,1,2,4,8,$10,$20,$40,$80,$FF,$FE,$FC,$F8,$F0,$E0,$C0. So if the nybble were equal to F, it'd extract $C0 from the tale. If it were 8, it would extract $80 from the table. Etc. etc. Anyway, there is also another byte of data that we'll call 'd'. At the start of decompression, d is $80. What happens is that d is then added to the data extracted from the table using the nybble. So if the nybble were 4, the 8 would be extracted from the table, then added to d, which is $80, resulting in $88. This result is then put bank into d, then fed into the YM2612 for processing. Then the next nybble is read, the data is extracted from the table, then is added to d (remember, d is now changed because of the previous operation), then is put bank into d, then is fed into the YM2612. This process is repeated until the number of bytes as defined in the table above are read and decompressed.

So basically, to add your own samples, you'd have to decompress the sound driver, find the table, input your own compressed PCM samples into the driver (you can't use the last few bytes of memory, but you do have about 1KB worth of extra space to use), change the tables to reflect the locations, length, and pitch of the new samples, then somehow recompress the driver and input it back into the rom. And remember, you can change the tables in the z80 using the 68k. in fact, Sonic 1 does this quite a bit when it plays the third drum sample, in order to change the sample/rate pitch.

For reference, I've uploaded the decompressed raw PCM samples, as well as three wav files of the drum files that are closely approximated in sound to the real thing

http://www.cgi101.co...n2050/dac1d.bin
http://www.cgi101.co...n2050/dac1d.wav
http://www.cgi101.co...n2050/dac2d.bin
http://www.cgi101.co...n2050/dac2d.wav
http://www.cgi101.co...n2050/dac3d.bin
http://www.cgi101.co...n2050/dac3d.wav

I hope this information will help fellow S1 music hackers in their quest to make awesome sounding music :rolleyes:

EDIT - And for the record, I'm working on a decompressor and compressor for this, but if anyone else can do it faster than me, be my guest :)
This post has been edited by jman2050: 25 April 2006 - 01:40 PM

#2 User is offline Tweaker 

Posted 25 April 2006 - 01:41 PM

  • Posts: 12389
  • Joined: 27-June 04
  • Gender:Male
You have no fucking clue, sir, what you just did.

Compressor pls. =O

#3 User is offline jman2050 

Posted 25 April 2006 - 03:06 PM

  • Teh Sonik Haker
  • Posts: 625
  • Joined: 10-December 05
  • Wiki edits:4
http://www.cgi101.co...0/s1sndcomp.exe

Decompressor/Compressor for the S1 sample format. arguments are:

(-d/-c) <input file> <num of bytes> <output file>

-d to decompress, -c to compress. Num of bytes refers to the number in the INPUT file. Also note that the num of bytes is IN DECIMAL NOT HEX BECAUSE I WAS TOO LAZY TO DO IT IN HEX. That is all

#4 User is offline Hivebrain 

Posted 27 April 2006 - 05:06 PM

  • Posts: 2660
  • Joined: 15-January 03
  • Gender:Male
  • Location:53.4N, 1.5W
  • Project:HivePal 2.0
  • Wiki edits:6,176
Interesting stuff. I gather this will be useful for porting music more accurately.

It will probably be necessary to leave the sound driver uncompressed, in order to actually replace the DAC samples with new ones. You can easily load the driver from the ROM to the Z80 as you would any other piece of uncompressed data.

#5 User is offline GregBFM 

Posted 27 April 2006 - 10:47 PM

  • Posts: 42
  • Joined: 07-November 05
  • Gender:Male
  • Wiki edits:1
I wonder if eventually we'll be able to use SoundFonts with Sonic ROMs.

A man can dream.

#6 User is offline MarkeyJester 

Posted 22 August 2008 - 09:52 PM

  • The architect of the universe, didn't build a stairway, leading nowhere.
  • Posts: 1785
  • Joined: 22-July 08
  • Gender:Male
  • Location:Japan
  • Wiki edits:16
hmm...

O.K. I know this guide was posted 2 years ago, but I have to say, Thank you man!!

I've just understood what you ment, and I've managed to add in the "GO" DAC from Sonic 3 without destroying the other samples.

Although I don't understand how to use your compressor, but I'm just a beginner at this DAC business, so again Thanks, is there anything new I should know about the DAC's?

#7 User is offline PsychoSk8r 

Posted 21 October 2009 - 06:19 AM

  • HighKnights
  • Posts: 2579
  • Joined: 11-July 07
  • Gender:Male
  • Location:Walsall, UK
  • Project:30 Day Project: Revisited.A New Release!
  • Wiki edits:19
Sorry to bump an old thread, but the download link is broken. The Wiki points to here, so I was wondering if anybody had a mirror?

#8 User is offline Selbi 

Posted 21 October 2009 - 07:35 AM

  • Impaled with Extreme Prejudice
  • Posts: 1480
  • Joined: 12-May 08
  • Gender:Male
  • Location:Northern Germany
  • Project:Sonic ERaZor
  • Wiki edits:320
QUOTE (PsychoSk8r @ Oct 21 2009, 01:19 PM)
Sorry to bump an old thread, but the download link is broken. The Wiki points to here, so I was wondering if anybody had a mirror?

Here: http://selbi.se.funpic.de/s1sndcomp.exe

#9 User is offline MarkeyJester 

Posted 21 October 2009 - 07:44 AM

  • The architect of the universe, didn't build a stairway, leading nowhere.
  • Posts: 1785
  • Joined: 22-July 08
  • Gender:Male
  • Location:Japan
  • Wiki edits:16
you might wanna check this out too:

http://forums.sonicretro.org/index.php?showtopic=6920

Although the download link to that driver's fucked also, I'd upload one but the link'll be dead in a couple of months after (It really needs a perminant place to be uploaded to).

#10 User is offline nineko 

Posted 21 October 2009 - 08:05 AM

  • I am the Holy Cat
  • Posts: 5535
  • Joined: 17-August 06
  • Gender:Male
  • Location:italy
  • Project:I... don't even know anymore :U
  • Wiki edits:5,251
Send me the files you want to be hosted and I'll put them on my unlimited webspace.

#11 User is offline MarkeyJester 

Posted 21 October 2009 - 08:49 AM

  • The architect of the universe, didn't build a stairway, leading nowhere.
  • Posts: 1785
  • Joined: 22-July 08
  • Gender:Male
  • Location:Japan
  • Wiki edits:16
Done:
http://forums.sonicretro.org/index.php?sho...t=0#entry364328

#12 User is offline Master3k 

Posted 21 October 2009 - 03:32 PM

  • Posts: 278
  • Joined: 25-July 07
  • Gender:Male
  • Wiki edits:27
Shouldn't this program be on the Wiki?

If it is, disregard/delete this post, but I couldn't find the program anywhere other than in this topic.
This post has been edited by Master3k: 21 October 2009 - 03:38 PM

Page 1 of 1
    Locked
    Locked Forum

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users