Sonic and Sega Retro Message Board: New Sonic 1 PCM sound driver - Sonic and Sega Retro Message Board

Jump to content

Hey there, Guest!  (Log In · Register) Help
Loading News Feed...
 
Page 1 of 1

New Sonic 1 PCM sound driver

#1 User is offline jman2050 

Posted 27 April 2006 - 09:18 PM

  • Teh Sonik Haker
  • Posts: 614
  • Joined: 10-December 05
  • Wiki edits:4
I thought this deserved it's own topic.

Take this driver and compress it in the S1 ROM anywhere you like (Kosinski), and make sure to read the notes below. It's much smaller than the other driver because the PCm samples formerly found in the z80 ram are no longer there

http://www.cgi101.co...050/z80_new.bin

New S1 Music Driver notes:

PCM playing is controlled by a table located at offset $200 of the uncompressed sound driver. The table's format is as follows.

Bytes 1/2 - The location of the PCM sample in the bank of the ROM pointed to by bytes 6/7. $8000-based, little-endian
Bytes 3/4 - The size of the PCM sample in words (bytes/2)
Byte 5 - Sample rate/Pitch
Bytes 6/7 - Rom Bank. Format is upper 9-bits of a 16-bit word, little endian (for easy conversion, take the start of the bank in ROM for example, offset $88000, and divide it by $100).
Byte 8 - unused

There are 14 slots of 8 bytes each for PCM definitions. To play them, just write $81 + the slot number (0-based) to $1FFF of the Z80 RAM area.

Writing $90 to $1FFFwill play the sega sound. The bank location of this is still hardcoded, so instead, make a new definition for the Sega sound in an open PCM definition slot. This method of playing the Sega sound is depreciated.

Writing $8F to $1FFF will play the multi-bank PCM (since we're playing slot $E, and $E + $81 is $8F). This is controlled by the 15th and final slot of the PCM table (slot $E). The format for the multi-bank PCM is a bit different.

Bytes 1/2 - Same
Bytes 3/4 - Size of the FIRST SECTION of the PCM sample in BYTES. Not WORDS.
Byte 5 - Same
Byte 6/7 - Same, with one note: The lower 7 bits MUST be zero for the bank switching to work properly
byte 8 - Number of banks to span when playing the file.

The rom bank is the starting bank of the PCM. The size refers to the number of bytes the PCm takes up in the FIRST bank. NOT the total size of the sample. This is because after this initial size when used as a counter is exhausted, it switches to the ROm bank and assumes a start position of $8000 and a size of $8000. Because of this, the routine will always end playing at the end of a bank. For this reason, make sure to position your PCM samples so that the very end of it coincides with the very end of a ROM bank.

NOTE ON CHANGING THE NUMBER OF PCM SLOTS.

The default behavior of the driver is 14 PCM slots and 1 multi-bank PCM slot for a total of 15 slots. However, this can easily be changed. First, you have to change when the sega sound is played. To do that, go to offset $3D of the uncompressed file. The default is $0F. Change this to the number of slots you want (so if you want 18 slots, change it to $12). Do note that this will change the value you need to put into $1FFF in your game code in order to play the sega sound. This is the value of offset $3D + $81 (so in the previous example, you'd need to play $93 ($12+$81) into $1FFF). Then just apped the extra PCM data to the end of the table. There's plenty of RAM in the z80, so you can have an endless amount of PCM samples.

You can also change the number of multi-bank PCM slots. Note that these will always be at te end of the PCM table, no matter how long it is. To do this, go to offset $96. The default is $E. This desribes which slot number to begin defining multi-bank PCM samples. So if you, for example, change it to $C, then every slot in the table from $C onward will be a multi-bank PCM definition. Combined with the change of the number of slots above, this would give you 12 normal PCM slots and 6 multi-bank PCm slots (lots 0-$B and slots $C-$11 respectively.

And now, finally, the default behavior of this sound driver. These are my settings to test the driver with the uncompressed drum DAC samples from S1, as well as a custom PCM sample I played across multiple banks. Change them to whatever you need. Note that not every slot need be filled. As long as you don't attempt to play a slot with bad data, nothing bad should happen.

Also, don't ask how to make these samples work in music files. You'll have to write your own game code for that, and I don't know the music format for S1. Ask Tweaker

Slot 0
Location: $9000
Size: $352
Sample rate: $19
Bank: $800

Slot 1
Location: $A000
Size: $770
Sample rate: 1
Bank $800

Slots 2-D
Location: $B000
Size: $1016
Sample rate: $1B
Bank $800

Slot E (multi-bank)
Location: $A250
Initial Size: $5DB0
Sample rate: $B
Bank: $880
Banks to span: 8
If you have any questions or comments please post them

#2 User is offline Tweaker 

Posted 27 April 2006 - 09:27 PM

  • Posts: 12389
  • Joined: 27-June 04
  • Gender:Male
All samples are uncompressed now, then?

What are the PCM limitations for the new uncompressed samples?

#3 User is offline jman2050 

Posted 27 April 2006 - 09:28 PM

  • Teh Sonik Haker
  • Posts: 614
  • Joined: 10-December 05
  • Wiki edits:4
Nothing except that normal samples can only be played within a bank. Attempting to go out of bounds could result in undefined behavior.

#4 User is offline Tweaker 

Posted 27 April 2006 - 09:32 PM

  • Posts: 12389
  • Joined: 27-June 04
  • Gender:Male
So with this, I could make normal DAC samples with the quality of, say, the sega sound or better (max hardware limit AKA)? That kicks major ass. Once Jim releases his program, I'll get right to work. :)

#5 User is offline Qjimbo 

Posted 27 April 2006 - 09:51 PM

  • Your friendly neighbourhood lemming.
  • Posts: 4333
  • Joined: 17-February 03
  • Gender:Male
  • Location:Vancouver, BC
  • Wiki edits:69
Posted Image
It's coming...

Awesome stuff Jman :) I'll get to work on implamenting this for the Sonic 1 part of UnlimiDAC.

As for the hardware limit, technically it's as fast as you can write to the DAC, the Z80 is limited to 16khz though, but writing to it with the M68K could probably get faster rates.
This post has been edited by QJimbo: 27 April 2006 - 09:52 PM

#6 User is offline LocalH 

Posted 27 April 2006 - 10:29 PM

  • roxoring your soxors
  • Posts: 3120
  • Joined: 11-January 03
  • Gender:Male
  • Location:wouldn't you like to know
  • Project:MDEM - Genesis programming stufz
  • Wiki edits:3
To write with the 68k you have to effectively disable the Z80 by giving it a bus request. Also, some of the docs I've read state that you can't set the Z80 bank from the 68k side but only the Z80. If that's true, then you'd be limited to 32KB of sample data without using some Z80 code to swap banks.

#7 User is offline ddrmaxromance 

Posted 29 April 2006 - 11:18 AM

  • Posts: 477
  • Joined: 06-January 06
  • Wiki edits:40

QJimbo, on Apr 27 2006, 09:51 PM, said:

http://qjimbo.projec...dacscreenie.png
It's coming...

Awesome stuff Jman :) I'll get to work on implamenting this for the Sonic 1 part of UnlimiDAC.

As for the hardware limit, technically it's as fast as you can write to the DAC, the Z80 is limited to 16khz though, but writing to it with the M68K could probably get faster rates.

WOW! That looks great! :)

Could you tell us the major features of this program? Such as you can import MIDI files, other Sonic game music easily, etc.

.....Will this work with Windows 95?..... or 2000 at least?

#8 User is offline LocalH 

Posted 20 May 2006 - 02:43 PM

  • roxoring your soxors
  • Posts: 3120
  • Joined: 11-January 03
  • Gender:Male
  • Location:wouldn't you like to know
  • Project:MDEM - Genesis programming stufz
  • Wiki edits:3
Huge ass bump, because I can, and I have a question.

Is there any problem with just doing away with the Sega sound completely and ignoring that part of the driver? I plan on using your PCM driver with the normal FM driver for my PYL game (with full credit of course), and I don't need the Sega sound at all. I would primarily be using multi-bank samples, as I seriously doubt many of these sounds would fit in 32KB. Is there any requirement for having at least one normal PCM slot or can they all be multi-bank? Also, do you (or anyone else) know the correlation between byte 5 and sample rates in terms of Hz? The particuar sounds I have (recordings from the actual show) are 8-bit/mono/11KHz, which I figure is playable by your routine with the right sample rates.
This post has been edited by LocalH: 20 May 2006 - 02:44 PM

#9 User is offline Dracula 

Posted 20 May 2006 - 04:04 PM

  • Posts: 587
  • Joined: 03-March 03
  • Gender:Male
  • Location:I'm watching you!
  • Project:Ripping Tim Follin's SPC Samples
  • Wiki edits:12
Cool! I'll try it.

#10 User is offline LocalH 

Posted 21 May 2006 - 01:28 AM

  • roxoring your soxors
  • Posts: 3120
  • Joined: 11-January 03
  • Gender:Male
  • Location:wouldn't you like to know
  • Project:MDEM - Genesis programming stufz
  • Wiki edits:3
Also, another question - does the DAC take signed or unsigned PCM data? I need to know so I can begin converting WAVs to raw PCM.

Edit: NM (unless I'm wrong), I think it uses signed PCM.

Edit 2: Hm, I had to use unsigned samples to make it work. And I can't get it to work anywhere but Kega as of right now, in a standalone test ROM (which I can provide). I think it's got something to do with my Z80 handshaking, as some of the source code I have seems to differ from what the Sega documentation says.

<s>Also, there seems to be a glitch in the output when playing multi-bank samples, at what seems to be the point where the initial bank setup is exhausted. It has done this with three different samples, so it's not a problem in my PCM data.</s> My fuckup here, I'd miscalculated the first bank's length.
This post has been edited by LocalH: 21 May 2006 - 09:49 PM

#11 User is offline kram1024 

Posted 10 January 2009 - 06:13 AM

  • Researcher / Hacker
  • Posts: 55
  • Joined: 02-March 04
  • Gender:Male
  • Location:at home, duh
  • Project:Part of the new Team Revamped; Kraminator Special Series disassemblies; Sonic 3 Sound Driver porting guides; KENS 1.5; smps studio; various non-sonic related things
  • Wiki edits:542
Sorry for the bump, but the link seems dead and I wish to make a s3 engine clone with this.
---
Updated due to the fact that Tweaker just provided me with the file and I have uploaded it here: <a href="http://info.sonicretro.org/Category:Code_Sniplets">Retro Code Sniplets</a>
This post has been edited by kram1024: 13 January 2009 - 12:37 AM

#12 User is offline MarkeyJester 

Posted 21 October 2009 - 08:47 AM

  • We're all mad here
  • Posts: 1511
  • Joined: 22-July 08
  • Gender:Male
  • Location:Japan
  • Wiki edits:16
Sorry to bump (God knows how many times this thread has/will be bumbed lol), nineko has hosted this for us so it should be a parminant host (or at least a longtime host)

http://digilander.iol.it/projectchaos/NEW_KOSZ80.bin

now this isn't exactly the same as original one that was posted above by Jman [that one I don't have], this one has been modded slightly to fit my needs, the only real difference being is that the table doesn't start from offset 00000200, it starts from offset 00000150 insted, but that's the only minor change you need to be aware of.
This post has been edited by MarkeyJester: 21 October 2009 - 08:48 AM

Page 1 of 1
    Locked
    Locked Forum

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