VOGONS

Common searches


Dune "HERAD" Ad Lib Music Hacking

Topic actions

Reply 140 of 155, by binarymaster

User metadata
Rank Newbie
Rank
Newbie
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:

// 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:

src/adplay.exe -o -r -e nuked --stereo ../GORBI2.SQX

by Stas'M

Reply 141 of 155, by synamax

User metadata
Rank Newbie
Rank
Newbie
binarymaster wrote:
This helps indeed, I just translated the code into C and whoosh... It works pretty good! No more dissonant notes! :D […]
Show full quote
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! 😁

The commit:
https://github.com/adplug/adplug/commit/284af … 876082ba62c8756

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.

Reply 142 of 155, by binarymaster

User metadata
Rank Newbie
Rank
Newbie

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

Today I fixed that thing, and Travis build passed! 🤣

https://travis-ci.org/adplug/adplug/builds/29 … um=notification

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

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/eb2a752 … /herad.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!!! 😁 That fixed strange high-pitched sounds!

https://github.com/adplug/adplug/blob/eb2a752 … /herad.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/eb2a752 … /herad.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

Reply 143 of 155, by synamax

User metadata
Rank Newbie
Rank
Newbie

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

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.

Reply 144 of 155, by binarymaster

User metadata
Rank Newbie
Rank
Newbie

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

  • Filename
    in_adlib.7z
    File size
    188.64 KiB
    Downloads
    46 downloads
    File comment
    AdPlug Winamp test plugin with HERAD
    File license
    Fair use/fair dealing exception

by Stas'M

Reply 145 of 155, by synamax

User metadata
Rank Newbie
Rank
Newbie

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!

Reply 146 of 155, by binarymaster

User metadata
Rank Newbie
Rank
Newbie
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. 🤣

https://github.com/adplug/adplug/commit/fb44f … cd7cf88da6651cd

Attachments

  • Filename
    in_adlib.7z
    File size
    188.45 KiB
    Downloads
    55 downloads
    File comment
    AdPlug Winamp test plugin with HERAD
    File license
    Fair use/fair dealing exception

by Stas'M

Reply 147 of 155, by Malvineous

User metadata
Rank Oldbie
Rank
Oldbie
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.

Reply 148 of 155, by synamax

User metadata
Rank Newbie
Rank
Newbie

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.

Reply 150 of 155, by binarymaster

User metadata
Rank Newbie
Rank
Newbie
psy_ wrote on 2020-01-11, 22:54:

hello, very nice project 😀 i want to ask how to inject files into dune.dat (dat) file? thank you!

Hello. I think your question is out of this topic, because music in Dune is not packed into a resource file like dune.dat.

by Stas'M

Reply 151 of 155, by psy_

User metadata
Rank Newbie
Rank
Newbie

hi, in the cd version it is inside the big dat file dune.dat , i have a program that can extract it (DuneCDExtractor.exe) but i don't know how to compress the files again to the dat format

Reply 152 of 155, by carlostex

User metadata
Rank l33t
Rank
l33t
psy_ wrote on 2020-01-12, 19:53:

hi, in the cd version it is inside the big dat file dune.dat , i have a program that can extract it (DuneCDExtractor.exe) but i don't know how to compress the files again to the dat format

Does the game crash if you remove the compressed .DAT and just use the uncompressed files?

Reply 153 of 155, by psy_

User metadata
Rank Newbie
Rank
Newbie
carlostex wrote on 2020-02-15, 22:28:
psy_ wrote on 2020-01-12, 19:53:

hi, in the cd version it is inside the big dat file dune.dat , i have a program that can extract it (DuneCDExtractor.exe) but i don't know how to compress the files again to the dat format

Does the game crash if you remove the compressed .DAT and just use the uncompressed files?

It doesnt work like that from what i remember i tried it but @Tgames from this forum : https://www.abandonware-forums.org/forum/foru … 4135#post804135
made some tools for that purpose ,so when he release the tools would be easy to change files 😀

Reply 154 of 155, by carlostex

User metadata
Rank l33t
Rank
l33t
psy_ wrote on 2020-08-15, 12:11:

It doesnt work like that from what i remember i tried it but @Tgames from this forum : https://www.abandonware-forums.org/forum/foru … 4135#post804135
made some tools for that purpose ,so when he release the tools would be easy to change files 😀

Nice! I hope he releases them soon!