Welcome Guest ( Log In | Register )


Help | Search | Members | Calendar
IRC Chat: irc.badnik.net | CGI:IRC
IPB
home | info | forums | svn | irc | podcast | about
 
Reply to this topicStart new topic
> Sonic 1 DAC drum samples unleashed!
 jman2050
post Apr 25 2006, 01:38 PM
Post #1


Teh Sonik Haker

Group Icon

Group: Tech Members
Posts: 484
Edits: 4
Joined: 10-December 05




5th Annual Hacking Contest - HPZ Winner4th Annual Hacking Contest - Trophy Winner6th Annual Hacking Contest - Trophy Winner

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.com/~jman2050/z80_whole_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.com/~jman2050/dac1d.bin
http://www.cgi101.com/~jman2050/dac1d.wav
http://www.cgi101.com/~jman2050/dac2d.bin
http://www.cgi101.com/~jman2050/dac2d.wav
http://www.cgi101.com/~jman2050/dac3d.bin
http://www.cgi101.com/~jman2050/dac3d.wav

I hope this information will help fellow S1 music hackers in their quest to make awesome sounding music smile.png

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 smile.png

This post has been edited by jman2050: Apr 25 2006, 01:40 PM
Go to the top of the page
+Quote Post
 Tweaker
post Apr 25 2006, 01:41 PM
Post #2


A thrilling mystery!

Group Icon

Group: Admins
Posts: 10,937
Edits: 3,205
Joined: 27-June 04
From: Pinellas Park, FL

Current Project:
Sonic Retro, Sonic Megamix, Sonic Boom



4th Annual Hacking Contest - HPZ Winner5th Annual Hacking Contest - HPZ Winner3rd Annual Hacking Contest - Trophy Winner6th Annual Hacking Contest - Trophy WinnerSonic 2 HD Contributor

You have no fucking clue, sir, what you just did.

Compressor pls. =O
Go to the top of the page
+Quote Post
 jman2050
post Apr 25 2006, 03:06 PM
Post #3


Teh Sonik Haker

Group Icon

Group: Tech Members
Posts: 484
Edits: 4
Joined: 10-December 05




5th Annual Hacking Contest - HPZ Winner4th Annual Hacking Contest - Trophy Winner6th Annual Hacking Contest - Trophy Winner

http://www.cgi101.com/~jman2050/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
Go to the top of the page
+Quote Post
 Hivebrain
post Apr 27 2006, 05:06 PM
Post #4




Group Icon

Group: Admins
Posts: 1,829
Edits: 11,173
Joined: 15-January 03
From: 53.3N, 1.2W

Current Project:
Sonic 1 Disassembly



Hacking Utility Programmer2nd Annual Hacking Contest - Grand Prize Winner4th Annual Hacking Contest - Trophy WinnerWiki Restoration Contributor

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.
Go to the top of the page
+Quote Post
 GregBFM
post Apr 27 2006, 10:47 PM
Post #5




Group Icon

Group: Oldbies
Posts: 18
Edits: 1
Joined: 7-November 05




I wonder if eventually we'll be able to use SoundFonts with Sonic ROMs.

A man can dream.
Go to the top of the page
+Quote Post
 MarkeyJester
post Aug 22 2008, 09:52 PM
Post #6


Jack of all trades... ...Master of fuck all.

Group Icon

Group: Tech Members
Posts: 315
Edits: 1
Joined: 22-July 08




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?
Go to the top of the page
+Quote Post
 PsychoSk8r
post Oct 21 2009, 06:19 AM
Post #7


Random Avatar. Now with more Psy.

Group Icon

Group: Oldbies
Posts: 1,305
Edits: 12
Joined: 11-July 07
From: Brummyland, UK




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?
Go to the top of the page
+Quote Post
 Selbi
post Oct 21 2009, 07:35 AM
Post #8


Scourge for president!

Group Icon

Group: Members
Posts: 215
Edits: 174
Joined: 12-May 08
From: Germany

Current Project:
S.C.H.ERZ and S1TCG



Hacking Utility ProgrammerWiki Restoration Contributor

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
Go to the top of the page
+Quote Post
 MarkeyJester
post Oct 21 2009, 07:44 AM
Post #9


Jack of all trades... ...Master of fuck all.

Group Icon

Group: Tech Members
Posts: 315
Edits: 1
Joined: 22-July 08




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).
Go to the top of the page
+Quote Post
 nineko
post Oct 21 2009, 08:05 AM
Post #10


I am the Holy Cat

Group Icon

Group: Wiki Sysops
Posts: 3,130
Edits: 3,276
Joined: 17-August 06
From: italy

Current Project:
trying to become a better person



Hacking Utility ProgrammerBest Member EverHidden Palace Donator6th Annual Hacking Contest - Trophy WinnerWiki Restoration Contributor

Send me the files you want to be hosted and I'll put them on my unlimited webspace.
Go to the top of the page
+Quote Post
 MarkeyJester
post Oct 21 2009, 08:49 AM
Post #11


Jack of all trades... ...Master of fuck all.

Group Icon

Group: Tech Members
Posts: 315
Edits: 1
Joined: 22-July 08




Done:
http://forums.sonicretro.org/index.php?sho...t=0#entry364328
Go to the top of the page
+Quote Post
 Master3k
post Oct 21 2009, 03:32 PM
Post #12


私はこれを翻訳しているあなたの時間を失った

Group Icon

Group: Members
Posts: 221
Edits: 26
Joined: 25-July 07
From: Brasilia, Brazil.

Current Project:
SECA, beta testing for some awesome hack.



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: Oct 21 2009, 03:38 PM
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 22nd November 2009 - 03:09 AM
Bridged By IpbWiki: Integration Of Invision Power Board and MediaWiki © GlobalSoft