- Group:
- Tech Member: Tech Members
- Active Posts:
- 147 (0.14 per day)
- Most Active In:
- Technical Discussion (60 posts)
- Joined:
- 08-September 10
- Profile Views:
- 107
- Last Active:
Yesterday, 05:12 PM- Currently:
- Offline
My Information
- Age:
- 22 years old
- Birthday:
- May 29, 1991
- Gender:
-
Male
Contact Information
- E-mail:
- Private
- Website:
-
http://
Previous Fields
- Project:
- vgm tools and vgm packs, other random projects
- National Flag:
- de
- Wiki edits:
- 10
Latest Visitors
-
ShadowsofYest... 
13 Jun 2013 - 12:18 -
TmEE 
13 Jun 2013 - 04:12 -
vladikcomper 
08 Jun 2013 - 12:36 -
Steelrush 
02 Jun 2013 - 17:13 -
Caverns 4 
28 May 2013 - 16:25
Topics I've Started
-
DAC Rate to Frequency Conversion
21 January 2012 - 10:45 AM
When working on SMPSPlay and DEPlay there was always one thing that bothered me: the DAC frequency
It's something I couldn't just get right, so I decided to do some research.
I startet with Oerg866's SMPS Player, which uses jman2050's DAC driver:
At first I made an SMPS file that plays a few DAC sounds and made each sound play the same sample, but with different DAC rates.
Then I used MESS to make a VGM of it. (MESS because MAME's timing system is extremely accurate.)
After that I wrote a small tool in VB that reads that VGM and calculated the frequency of each sound.
Finally I made another small VB tool that recalculated the formula FreqHz = BaseVal / (RateBase + DACRate) for the DAC rates I logged. With this tool I tested values for RateBase until I found a perfect one. (I made it recalculate BaseVal with the tested frequency of rate 01 and RateBase.)
Then I did the same with plain Sonic 1, Sonic 2, and Barver Battle Saga (because I already had its pointers) for the Data East driver.
And here are my results:
(The columns are DACRate, logged DAC samples, length of the DAC sound in VGM ticks (44100 Hz), DAC samples per VGM sample, DAC frequency.)
jman2050's DAC driver --------------------- 01 8,238 11,940 1.45 30,426.784 02 8,238 13,275 1.61 27,366.915 03 8,238 14,600 1.77 24,883.274 04 8,238 15,937 1.93 22,795.746 05 8,238 17,268 2.10 21,038.673 06 8,238 18,602 2.26 19,529.932 07 8,238 19,938 2.42 18,221.276 08 8,238 21,265 2.58 17,084.213 0C 8,238 26,598 3.23 13,658.764 10 8,238 31,926 3.88 11,379.308 20 8,238 53,243 6.46 6,823.353 30 8,238 74,561 9.05 4,872.464 40 8,082 94,060 11.64 3,789.243 80 4,278 94,054 21.99 2,005.867 C0 2,908 94,020 32.33 1,363.995 FF 2,212 94,038 42.51 1,037.338 00 8,238 352,309 42.77 1,031.185 -> FreqHz = 272624 / (7.96 + DACRate) Calculating with (8 + prim) is still a good approximation. (DACSmpl/VGMSmpl variance is <0.2 for rates <= 80) Sonic 1 DAC driver ------------------ 01 8,236 15,517 1.88 23,407.076 02 8,236 16,846 2.05 21,560.465 03 8,236 18,190 2.21 19,967.433 04 8,236 19,530 2.37 18,597.419 05 8,236 20,866 2.53 17,406.671 06 8,236 22,209 2.70 16,354.073 07 8,236 23,550 2.86 15,422.828 08 8,236 24,882 3.02 14,597.203 0C 8,236 30,252 3.67 12,006.069 10 8,236 35,602 4.32 10,201.888 20 8,236 57,041 6.93 6,367.483 40 8,236 99,906 12.13 3,635.493 80 8,236 185,658 22.54 1,956.326 C0 5,710 188,159 32.95 1,338.288 FF 4,354 188,077 43.20 1,020.919 00 8,236 357,141 43.36 1,016.987 -> FreqHz = 271053 / (10.58 + DACRate) Sonic 2 DAC driver ------------------ [without gaps] 01 5,994 10,634 1.77 24,857.570 02 5,994 11,593 1.93 22,801.294 03 5,994 12,550 2.09 21,062.582 04 5,994 13,505 2.25 19,573.151 05 5,994 14,464 2.41 18,275.401 06 5,994 15,442 2.58 17,117.951 07 5,994 16,400 2.74 16,118.012 08 5,994 17,349 2.89 15,236.348 0C 5,994 21,209 3.54 12,463.360 10 5,994 25,016 4.17 10,566.653 20 5,994 40,424 6.74 6,539.071 40 5,994 71,112 11.86 3,717.170 80 4,384 96,853 22.09 1,996.163 C0 3,014 97,425 32.32 1,364.305 FF 2,312 98,042 42.41 1,039.954 00 5,994 255,585 42.64 1,034.237 -> FreqHz = 275173 / (10.07 + DACRate) [with gaps] 01 5,994 11,152 1.86 23,702.959 02 5,994 12,146 2.03 21,763.165 03 5,994 13,140 2.19 20,116.849 04 5,994 14,163 2.36 18,663.800 05 5,994 15,155 2.53 17,442.125 06 5,994 16,181 2.70 16,336.160 07 5,994 17,175 2.87 15,390.707 08 5,994 18,178 3.03 14,541.501 0C 5,994 22,193 3.70 11,910.756 10 5,994 26,203 4.37 10,087.982 20 5,994 42,327 7.06 6,245.078 40 5,994 74,027 12.35 3,570.797 80 4,384 100,639 22.96 1,921.068 C0 3,014 100,638 33.39 1,320.748 FF 2,312 99,898 43.21 1,020.633 00 5,994 259,097 43.23 1,020.218 -> FreqHz = 265473 / (10.20 + DACRate) Data East DAC driver -------------------- 01 5,309 14,714 2.77 15,911.846 02 5,309 15,768 2.97 14,848.231 03 5,309 16,817 3.17 13,922.037 04 5,309 17,866 3.37 13,104.607 05 5,309 18,906 3.56 12,383.735 06 5,309 19,951 3.76 11,735.096 07 5,309 21,006 3.96 11,145.716 08 5,309 22,077 4.16 10,605.014 0C 5,309 26,261 4.95 8,915.384 10 5,309 30,457 5.74 7,687.129 20 5,309 47,284 8.91 4,951.504 40 5,309 80,941 15.25 2,892.562 80 5,309 148,154 27.91 1,580.294 C0 5,309 215,537 40.60 1,086.249 FF 5,309 281,543 53.03 831.585 00 5,309 282,774 53.26 827.965 -> FreqHz = 222766 / (13 + prim)
All formulas are accurate enough that the difference between tested and recauculated (DAC samples per VGM sample) is <= 0.2 for all rates. (except for Sonic 2 with gaps)
The Sonic 2 driver does all work on the Z80, so it needs to interrupt the DAC stream every frame to do update the music engine. [without gaps] means, that I removed the small delays that occur because of this, [with gaps] means that I just took the approximate frequency including these delays.
The next update of SMPSPlay and DEPlay with feature perfect DAC rates. (For SMPSPlay they're adjustable via ini-files.) -
C-based SMPS Playback Engine - updated
23 December 2011 - 06:12 AM
Do you rememer this SMPS player?
Well, I worked a little on it. And although I didn't improve the actual smps playback a lot (aside from a few small bugfixes), I made a lot of other changes.
At first, it can log v1.60 VGMs. (press V to enable/disable logging)
Also all DACs sounds and PSG envelopes are dynamically loaded and are easy to change. (I included a small editor for the PSG envelope files.)
And I removed Allegro (and made it a console app), so it continues playing if the program doesn't have the focus.
Finally, there is a 32-bit version (compiled with MSVC6 for compatibility) and a 64-bit versions (compiled with MSVC2010, so you need .NET 4.0).
Download
Enjoy!
EDIT: File updated, see this post -
S3K to S1 SMPS Converter
07 December 2011 - 03:20 AM
Crosspost from RetroHack and SSRG:
Valley Bell, on 06 December 2011 - 05:22 PM, said:
During the last week I worked on a tool to convert S3K/S3D/... SMPS files to the Sonic 1 format.
There was a need for it, because MFP doesn't do its job very well. (It converts only a few coordination flags and sometimes changes pointers at places with no pointers at all.)
You can get the tool here. (Source is included.)
The tool does not only convert S3K songs to S1 fully automatically (that includes the missing-note fix), but it also allows you to change all DAC sounds and PSG instruments by simply editing two ini-files. That should make porting songs a piece of cake.
(If you want to find matching PSG envelopes, you can use my PSG Envelope Editor. I used it to make the current PSGMap file.)
Notes and bugs:
- Just change the Z80 ROM bank offset if you're sure that the tool detects it wrong. Don't mess with it or you'll get bad conversions.
- The tool prints a message for every ignored command. (Some of the commands may cause it to stop processing the current track. But I don't know any songs that have such ones.)
- The conversion of the modulation/vibrato effect (F0) is still wrong. S3K seems to do that completely different to S1. (very noticable in the S&K spheres bonus stage)
- I know that S3's LBZ1/2 don't really work. That's because LBZ1 has some data of LBZ2 and vice versa.
If there are other bugs (or even crashes), please report it and I'll try to fix it.
Thanks go to redhotsonic for beta-testing the tool.
Enjoy! -
Data East / Side Pocket Sound Driver
08 September 2011 - 03:01 PM
I was always a fan of this sound driver.
It doesn't just use the LFO to make a nice vibrato and has lots of great PCM drums, but it's the only driver used in chinese pirates which actually sounds good. (if not great sometimes)
Recently I startet ripping another pirate with this sound driver and got the idea of reverse engineering the sound format.
Now, here are my results:
Data East music format:
Header ------ Size Description 4 Absolute ROM-Pointer to Track 1 4 Absolute ROM-Pointer to Track 2 4 Absolute ROM-Pointer to Track 3 4 Absolute ROM-Pointer to Track 4 4 Absolute ROM-Pointer to Track 5 4 Absolute ROM-Pointer to Track 6 (DAC) 6 Channel Assignment for tracks 1-6 (default: 00 01 02 04 05 06, later version only) -> these values specify the 4 lower bits of the Key On/Off command (028) changing these shuffles doesn't change the track's channel (only the key on/off channel), so you better don't change it -> a value of FF causes the driver to ignore the channel Track Data ---------- The early sound driver used in Side Pocket has to additional bytes at the beginning of each track: Size Description 1 unknown 1 Channel Assignment of current track ... Commands In later versions the track starts directly with the commands. Command Description 00-7F aa Note (7F = rest) -> aa = length 80 aa Tempo (track 1 only) -> aa = Tempo Value (00 = slow, FF = fast) 82 aa Instrument Change -> aa = Instrument No. in Instrument Lib 83 aa Volume Change -> aa = Volume (TL value) 86 aa Note Stop value (default 08) -> when a note is started, a length-counter is set to the note's length and counts down when this counter reaches a stop value that's adjusted by aa, the note is stopped when the counter reaches 0, the next note is processed -> aa = 08 makes stop value = 01 (always) aa > 08 can make the stop value negative or 00, resulting in bending notes aa < 08 make the stop value higher stop_value = 1 + round(note_len * (08 - aa) / 8) table from driver: 07 -> 07 of 30, 04 of 18, 03 of 0C, 06 of 24 06 -> 0D of 30, 07 of 18, 04 of 0C, 0A of 24 05 -> 13 of 30, 0A of 18, 06 of 0C, 0F of 24 04 -> 19 of 30, 0D of 18, 07 of 0C, 13 of 24 03 -> 1F of 30, 10 of 18, 09 of 0C, 18 of 24 87 ?? 88 aa Loop Start (nested loops are possible) -> aa = loop count (00 = infinite) 89 Loop End 8D aa ?? 8E aa set LFO register (022) (track 1 only) -> aa = LFO value (ored with 08) 8F ?? 90 aa bb ?? 91 ?? 92 aa Panorama -> aa = L/R mask 93 aa ?? 94 aa ?? 95 Track End 96 aa DAC Volume (track 6 only) -> aa = Volume (00=loud, 03=low)
de2mid (with source, writing the tool took longer than reverse engineering the format, btw)
I didn't work on the unknown coordination flags yet, as I found them when testing de2mid.
Example call for de2mid:
de2mid BarverBattleSaga.bin l 0019868A 0x16
(extracts call songs from Barver Battle Saga, works only with the v1.00 translation patch)
Feedback and comments are welcome.
Update: updated tool to add full support for Side Pocket and added some more unknown flags
another example call: de2mid "Side Pocket (JU) [!].bin" le 30DDE -
mid2smps
22 May 2011 - 03:41 PM
Today I present you the opposite tool of smps2mid: mid2smps.
You can download the tool with some example files here.
Demo songs are: FF4 Boss Theme, The Final Countdown, Tales Of Phantasia: Boss Theme
Features:
- full support for Pan, PitchBend and Tempo changes
- support for volume changes via note velocity and Main Volume controller (no Expression-Controller)
- support for ymx instrument files
- per-channel looping (with Controller 111, value 0 is loop start, 1-127 is loop end)
- force E7 flag between notes (Portatemento Controller 65, Off <=63, On >=64)
- export to binary smps-file or directly into a ROM
How to use:
1. [optional] load a ROM (recommended for quick testing) and select the song you want to overwrite from the list
2. load YMX Instrument file (must only be done once)
3. set Tick/Qrtr and TempoDiv values, if wanted
4. click MID2SMPS
Notes:
- The tool will NOT ask you if you want to save the ROM. It will just silently overwrite the data.
- Instruments are assinged in order they are used.
- You can convert files without loading any instruments. It just won't attach any instrument data to the smps file.
- Currently the channel mapping is hardcoded. See table below:
CODEMIDI SMPS-Drum mapping:
1-5 FM 1-5 (no 6th FM channel)
10 DAC and PSG Noise
11-13 PSG 1-3 (3rd channel used for noise)
14 PSG Noise (for additional controllers)
DAC Drums: 2x Bass Drum, 2x Snare Drum, Clap, 2x Cymbal, all Toms
Noise Drums: all Hi-Hats, 2xRide Cymbal, Ride Bell
- PSG instrument selection is done with Bank Select LSB. An (ignored) patch change message must follow the Bank Select message to confirm it.
- Modulation isn't yet implemented
- only Sonic 1 support (will care about the others later)
- The conversions are quite unoptimized. I'll write an optimized sometime in the future.
Thanks to:
- all the people who contributed to the Music Hacking Guide
- nineko for the tempo calcuation algorithm
- Oerg866 for the SMPS Player and info about the PSG envelopes (that helped me to make the example files)
- Rob Jinnai for notes on SMPS flags
- Tamkis for making a terrible FF4 Boss conversion that convinced me that I had to make a better one (that's why I wrote mid2smps)
The Music Hacking Guide has quite some misinformation that caused me trouble.
I took some notes and will correct these things.
Now listen to the demo files, try the tool and comment! (tool and demo files)
EDIT: Added notes about demo songs, volume change support and thanks to Tamkis
EDIT2: Updated the tool with instrument editor.

Find My Content