Dune "HERAD" Ad Lib Music Hacking

Getting old DOS games working. (DOSBox topics belong in DOSBox areas below, not here).

Re: Dune "HERAD" Ad Lib Music Hacking

Postby binarymaster » 2017-8-22 @ 07:34

Jepael wrote:So what's the preferred workflow, as the libadplug is now installed into system library dir, and I want to develop that, using stock adplay-unix to test?
Compile and reinstall libadplug into system dirs again and again?

I usually compile with Cygwin, and since toolchain is set up and build is working (let the current directory be /adplay-unix), I use these commands to rebuild:

Code: Select all
// first build and install libadplug
// then build player
cd ../adplug/&&make&&make install&&cd ../adplay-unix/&&make

The directory structure is:
/adplay-unix
/adplug
/libbinio

And I use this command to test output:

Code: Select all
src/adplay.exe -o -r -e nuked --stereo ../GORBI2.SQX
by Stas'M
User avatar
binarymaster
Newbie
 
Posts: 54
Joined: 2010-3-07 @ 19:03

Re: Dune "HERAD" Ad Lib Music Hacking

Postby synamax » 2017-9-04 @ 20:05

binarymaster wrote:
opl2 wrote:I've disassembled all of the drivers (dune/kgb/megarace) and have the bend code working in my (almost perfect?) converter.

Hope this helps!

This helps indeed, I just translated the code into C and whoosh... It works pretty good! No more dissonant notes! :D

The commit:
https://github.com/adplug/adplug/commit ... 2ba62c8756

However this introduced some regressions (tested with Winamp plugin via Nuked OPL3):
1. Strange hiss sound at the beginning of "NewSan"


I isolated the weird intro sound at the beginning of NewSan. The instrument is located at 0x955E in the SDB file (MIDI instrument number 46). The transpose byte was set to F4, but when I changed it to 00, the intro sounds a lot better. Another instrument that was weird in NewSan is the chorus drums on track 8 (MIDI Instrument 44 / SDB offset 0x950E) The transpose byte is DC but while changing it to zero made it sound better, it's still not accurate.

So first, I started looking at the HERAD internals in MegaRace. It looks like this drum should be playing at MIDI note 3, which is weird because that note is technically not playable in HERAD. HERAD uses MIDI Notes C1 to B8 (0x18 to 0x77). If any MIDI notes are out of range, the sequencer will play note C1. I made a test HA2 file where I made MegaRace play all possible MIDI pitches and then compared it with AdPlug. Sure enough, AdPlug doesn't limit the pitch range (at least the lower notes anyway). Here's how that work:

HERAD pulls up the MIDI pitch. Let's say in this case it's 0x17. In between grabbing the MIDI pitch from the song data and writing the OPL FNUM, HERAD is also transposing the pitch, checking if there's a drum map involved, as well as grabbing and resetting values for the pitch slides. When it's done doing that, it'll take the transposed pitch (if there is transposing), and subtract it by 48.

17 - 48 = FFCF

Then HERAD takes that value and adds 30 to it.

FFCF + 30 = FFFF

HERAD then compares that value with 60. If the value is greater than or equals to 60, it is zeroed out. HERAD then grabs the FNUM from it's frequency table and adds it to the MIDI pitch. Since the MIDI pitch is now zero, it grabs the first value from the FNUM table, which is 0x157, aka FNUM 343, aka a C note.

Now let's do this with a valid note, like the drum from NewSan.

44 - 48 = FFFC
FFFC + 30 = 2C
2C < 60


Since 2C is less than 60, it's a valid note, so HERAD proceeds to grab the FNUM. It starts this by taking our modified MIDI pitch and dividing it by C.

2C / 0C = 0803

Then HERAD takes the high byte and adds it with itself.

08 + 08 = 10

HERAD then uses this value to look up the frequency table and grab the corresponding value.

0x10 bytes into frequency table = 0x222

0x222 equates to FNUM 546, which is the note G#.

Now, we take the low byte from our divided value (0803) and shift bits to the left twice.

03 -> 0C

Take C and perform an OR with the high byte of the FNUM value, 222.

C OR 2 = E22

Finally, perform an OR on the high byte with 20 (the 20 turns on the Key On Bit for the OPL register) and this is now the new register FNUM to be written to the OPL chip.

20 OR E22 = 2E22

I'm gonna dig into this a bit further, but this should be a good start for fixing this issue.
User avatar
synamax
Newbie
 
Posts: 69
Joined: 2016-9-07 @ 04:57

Re: Dune "HERAD" Ad Lib Music Hacking

Postby binarymaster » 2017-10-27 @ 19:56

Shame on me, only today I figured out that % modulo operator in C is sign aware. :blah:

Today I fixed that thing, and Travis build passed! :lol:

https://travis-ci.org/adplug/adplug/bui ... tification

synamax wrote:When it's done doing that, it'll take the transposed pitch (if there is transposing), and subtract it by 48.

17 - 48 = FFCF

Then HERAD takes that value and adds 30 to it.

FFCF + 30 = FFFF

Yep, resulting in operation (note - 0x18), that's how it already implemented, see:

https://github.com/adplug/adplug/blob/e ... d.cpp#L883

synamax wrote:HERAD then compares that value with 60. If the value is greater than or equals to 60, it is zeroed out.

And yes! YES!!! :-D That fixed strange high-pitched sounds!

https://github.com/adplug/adplug/blob/e ... d.cpp#L884

Some comments on your research:

synamax wrote:Since 2C is less than 60, it's a valid note, so HERAD proceeds to grab the FNUM. It starts this by taking our modified MIDI pitch and dividing it by C.

At this stage, it calculates an octave (note / 12).

https://github.com/adplug/adplug/blob/e ... d.cpp#L885

synamax wrote:Then HERAD takes the high byte and adds it with itself.

HERAD then uses this value to look up the frequency table and grab the corresponding value.

Since FNum array consists of 16-bit values, it multiplies note key value by 2 to make proper address to the table. In my C port the table is indexed, so it doesn't require multiplication. ;)
by Stas'M
User avatar
binarymaster
Newbie
 
Posts: 54
Joined: 2010-3-07 @ 19:03

Re: Dune "HERAD" Ad Lib Music Hacking

Postby synamax » 2017-10-28 @ 20:03

That's awesome news, binarymaster!! I cant wait to try out the new build! :D

I've been itching to write some more HERAD music lately so I'm going to be making some more songs in the near future.

binarymaster wrote:Some comments on your research:

synamax wrote:Since 2C is less than 60, it's a valid note, so HERAD proceeds to grab the FNUM. It starts this by taking our modified MIDI pitch and dividing it by C.

At this stage, it calculates an octave (note / 12).


Oh, of course! I can't believe I didn't make the connection between 0xC and an octave, haha.
User avatar
synamax
Newbie
 
Posts: 69
Joined: 2016-9-07 @ 04:57

Re: Dune "HERAD" Ad Lib Music Hacking

Postby binarymaster » 2017-10-29 @ 11:05

Here you go. ;)

Now I'm thinking about creating a program which will compare raw OPL2/3 logs, all possible chip parameters + ability to select which channels to play.
Attachments
in_adlib.7z
AdPlug Winamp test plugin with HERAD
(188.64 KiB) Downloaded 13 times
by Stas'M
User avatar
binarymaster
Newbie
 
Posts: 54
Joined: 2010-3-07 @ 19:03

Re: Dune "HERAD" Ad Lib Music Hacking

Postby synamax » 2017-11-02 @ 06:39

Awesome work, binarymaster! The intro to NewSan sounds excellent!

I did noticed that the bass drum on channel 8 in NewSan is still incorrect. I made a video with imfplay showing the difference between the two drums.

https://youtu.be/FGvZvTTnXgA

This instrument is very confusing. It's MIDI pitch is 27 and the transpose byte is DC, so that makes it's MIDI pitch 03, which is below the HERAD keyboard clip. From going through the debugger it looks like on the first cycle, this is the case and nothing happens. For a microsecond, the note plays at HERAD's default FNUM (0x157), but when the routine goes through a second time, it treats the pitch slide like a pitch bend and grabs the invalid MIDI pitch of 03, the pitch bend subroutine subtracts that MIDI pitch by 18 to get EB (03 - 18 = EB) and then modifies that value to get the new pitch bent FNUM value. The first FNUM value you should get when the pitch slide starts is 0x4DF1. With the Note On bit on, it'll be 0x6DF1 in the OPL register map. So, if I'm understanding this correctly, it looks like pitch bends/pitch slides ignore the MIDI keyboard clipping. Hope this helps!
User avatar
synamax
Newbie
 
Posts: 69
Joined: 2016-9-07 @ 04:57

Re: Dune "HERAD" Ad Lib Music Hacking

Postby binarymaster » 2017-11-02 @ 11:48

synamax wrote:I did noticed that the bass drum on channel 8 in NewSan is still incorrect.

So, if I'm understanding this correctly, it looks like pitch bends/pitch slides ignore the MIDI keyboard clipping. Hope this helps!

Yeah, that was easy. :lol:

https://github.com/adplug/adplug/commit ... 88da6651cd
Attachments
in_adlib.7z
AdPlug Winamp test plugin with HERAD
(188.45 KiB) Downloaded 14 times
by Stas'M
User avatar
binarymaster
Newbie
 
Posts: 54
Joined: 2010-3-07 @ 19:03

Re: Dune "HERAD" Ad Lib Music Hacking

Postby Malvineous » 2017-11-02 @ 22:06

binarymaster wrote:Now I'm thinking about creating a program which will compare raw OPL2/3 logs, all possible chip parameters + ability to select which channels to play.

If it helps, I had the same idea and created dro2txt for this purpose. It converts DRO files into plain text so you can use standard text file comparison tools (like 'diff') to see if there's any difference between two DRO files.

It does a few nice things like only comparing the OPL registers when notes are playing, so even if the two files program the OPL registers in a different order, you'll get the same text output so long as the two songs sound exactly the same. Since pretty much every program sends the OPL data in a different order (especially when programming the instruments) it makes it much easier to see whether your code is correct or not if you ignore the order during those times when it doesn't affect the audio.
User avatar
Malvineous
Member
 
Posts: 475
Joined: 2006-6-11 @ 02:24
Location: Brisbane, Australia

Re: Dune "HERAD" Ad Lib Music Hacking

Postby synamax » 2017-11-03 @ 06:24

Excellent work again, binarymaster! I love how we're getting closer and closer to perfection!

I did noticed a weird glitch with Skyholder (PAGA.HSQ). For some reason, the first note on one of the instruments for the solo is an octave higher than it should be. Once again, I isolated the instruments and recorded them in imfplay. I have no idea what would be causing this. =\

https://www.youtube.com/watch?v=epRKRNvsOag

Also, some of the output levels and or feedback sounded off in Fractalian Space (LENNY.HSQ), but I'm not sure, I'll confirm this tomorrow.
User avatar
synamax
Newbie
 
Posts: 69
Joined: 2016-9-07 @ 04:57

Previous

Return to DOS

Who is online

Users browsing this forum: No registered users and 1 guest