Extract/Convert Adlib Instruments

General chat related to ScummVM, adventure gaming, and so on.

Moderator: ScummVM Team

tashiy
Posts: 9
Joined: Tue Jun 19, 2012 9:17 am

Extract/Convert Adlib Instruments

Post by tashiy »

Hi all

I really like the Adlib sound from the old Lucas Arts Adventures Games (specially Monkey1/2).

Is there a possible way to convert single instruments to wave samples from the games? I know Adlib have a Yamaha 2OP FM chip. Therefor the instruments have to be emulated.

Would be great to create some music with these old games.

Great fun would also to load a game and play instruments with a midi keyboard ;)
User avatar
DrMcCoy
ScummVM Developer
Posts: 595
Joined: Sat Dec 17, 2005 1:33 pm
Location: Braunschweig, Germany
Contact:

Re: Extract/Convert Adlib Instruments

Post by DrMcCoy »

tashiy wrote:Is there a possible way to convert single instruments to wave samples from the games? I know Adlib have a Yamaha 2OP FM chip. Therefor the instruments have to be emulated.
The OPL2 is a synthesizer chip, meaning the instruments are not stored as finished wave samples, but created from scratch. Basically, it takes a pure sine wave and manipulates it in multiple ways. The various parameters for this manipulation is provided by the games.

Therefore, there's no easy way to "extract" the instruments.

There's also, as far as I know, nothing in ScummVM that would already do something like this. You would need to write it yourself. Unless you have programming experience or can find someone else to do this for you, you're out of luck.
tashiy
Posts: 9
Joined: Tue Jun 19, 2012 9:17 am

Post by tashiy »

I read there is adlib support in scumm vm. Because of that I think the OPL FM Synthesizer chip must be emulated.

http://wiki.scummvm.org/index.php/User_ ... _and_sound

This is also an interesing tread about the opl emulation:

Source: http://forums.scummvm.org/viewtopic.php ... d85d92f56b
User avatar
DrMcCoy
ScummVM Developer
Posts: 595
Joined: Sat Dec 17, 2005 1:33 pm
Location: Braunschweig, Germany
Contact:

Post by DrMcCoy »

tashiy wrote:I read there is adlib support in scumm vm. Because of that I think the OPL FM Synthesizer chip must be emulated.
Sure, we have an OPL emulator in ScummVM (courtesy of DOSBox, based, partially on MAME's emulator by Tatsuyuki Satoh).
However, so that it's easy to plug in, from the engine's perspective, it behaves just like an actual AdLib card.

Meaning:
1) It still synthesizes the instruments. Only this time, it does so per software, instead of per hardware. Take a look at the source, you'll see math and small waveform tables there, no PCM data.
2) You still program it by writing control data into registers, just like DOS programs used to do it in the olden days. See this document for the interface works: http://www.shipbrook.net/jeff/sb.html.

Of course, the AdLib output is now easier to capture; you have get the generated digital PCM data directly at the emulator, instead of having to read the analog output of a real AdLib card back into your soundcard's input.

However, telling the emulator which operator parameters you want it to take, and generate one clear note is exactly as if you had a real AdLib card.
Again, ScummVM does not provide such a capability for you. You still have to write that yourself.
tashiy
Posts: 9
Joined: Tue Jun 19, 2012 9:17 am

Post by tashiy »

Thank you for your detailed answer!

Then I try to sample some sounds from the games. Maybe I find some parts of the game where instruments are played only one note at a time.

I wish I can programm some midi controlled scummvm synth. But I can`t programm. I know thats a common excuse.
robertmo
Posts: 15
Joined: Sun Jun 17, 2012 11:41 am

Post by robertmo »

you can install windows in dosbox and choose fm in midi mapper.
or if you have any old pc with isa slots you can place any opl card install its windows drivers and do the same.
jepael
Posts: 32
Joined: Sat Oct 25, 2008 8:16 pm

Post by jepael »

DrMcCoy wrote: Of course, the AdLib output is now easier to capture; you have get the generated digital PCM data directly at the emulator, instead of having to read the analog output of a real AdLib card back into your soundcard's input.
I read the digital audio bus on OPL2 and OPL3 chips with USB logic analyzer just fine before the DAC converts it to analog. Helps a lot to record and analyse the output.

Here are some more discussion about the subject:
http://forums.submarine.org.uk/phpBB/viewforum.php?f=9
http://yehar.com/blog/?p=665
DrMcCoy wrote: However, telling the emulator which operator parameters you want it to take, and generate one clear note is exactly as if you had a real AdLib card.
Again, ScummVM does not provide such a capability for you. You still have to write that yourself.
Well, ScummVM emulator knows how to play the music, so it takes in the stored music data from the game files and converts this to OPL chip register writes for the OPL chip emulator. So it is already done. For example Lucasarts Adlib Audio (.laa) files contain MIDI data with custom header that contains parameters for the OPL chip instruments.

I have also written some sort of OPL chip emulator for myself, but it is still in the works. And because I also needed some material to play with my chip emulator, I have written a simple player for .laa files. It is very similar to LordHoto's player but I wrote it before I knew about LordHoto's player here: http://lordhoto.blogspot.com. I even know my player writes the exact same bytes to OPL chip than original Monkey Island playing the title theme.

You could even take the Monkey Island .laa files, and take a look at their header for instrument data. There is a DOS program called SBTimbre that you can enter instrument parameters and use MIDI interface to play the sounds with MIDI keyboard.
User avatar
LordHoto
ScummVM Developer
Posts: 1029
Joined: Sun Oct 30, 2005 3:58 pm
Location: Germany

Post by LordHoto »

jepael wrote:
DrMcCoy wrote: However, telling the emulator which operator parameters you want it to take, and generate one clear note is exactly as if you had a real AdLib card.
Again, ScummVM does not provide such a capability for you. You still have to write that yourself.
Well, ScummVM emulator knows how to play the music, so it takes in the stored music data from the game files and converts this to OPL chip register writes for the OPL chip emulator. So it is already done. For example Lucasarts Adlib Audio (.laa) files contain MIDI data with custom header that contains parameters for the OPL chip instruments.
That "laa" is just some abitrary name ADPlug uses for the audio files btw. it's not really the original name, at least there's no indication for that in the original game executable. The original SCUMM engine used either "AD" or "ADL" (for later games) as resource tags.

While it's true that ScummVM sets up the instrument data, it doesn't mean ScummVM can abitrarily play a single note for the instruments without adapting the code. So if tashiy wants to record instrument samples, he will need to write that himself.
jepael wrote:I have also written some sort of OPL chip emulator for myself, but it is still in the works. And because I also needed some material to play with my chip emulator, I have written a simple player for .laa files. It is very similar to LordHoto's player but I wrote it before I knew about LordHoto's player here: http://lordhoto.blogspot.com. I even know my player writes the exact same bytes to OPL chip than original Monkey Island playing the title theme.
SCUMM's AD/ADL music files are a really simple format, so it should be pretty easy to write some program, which fits tashiy's needs. ADPlug also does have some implementation for them, but I don't know whether it's accurate, but the frequency table it uses is definitly different to what Monkey Island 1 uses (which in turn is different to what ADL ,Monkey Island 2, etc.) uses IIRC), so it might be a bit off.
User avatar
DrMcCoy
ScummVM Developer
Posts: 595
Joined: Sat Dec 17, 2005 1:33 pm
Location: Braunschweig, Germany
Contact:

Post by DrMcCoy »

jepael wrote:I read the digital audio bus on OPL2 and OPL3 chips with USB logic analyzer just fine before the DAC converts it to analog.
Oh, neat. :)

Of course not something a normal non-programmer/-engineer (like I guess tashiy is) could do. I like this a lot, though. :)
jepael wrote:Well, ScummVM emulator knows how to play the music. [...] MIDI data with custom header that contains parameters for the OPL chip instruments.
Sure. I never said it's impossible or incredible hard to figure out. Just that ScummVM can't do exactly what tashiy wants yet, and that they'd need someone (TM) with programming experience to do it.
jepael wrote:There is a DOS program called SBTimbre that you can enter instrument parameters and use MIDI interface to play the sounds with MIDI keyboard.
Nice, didn't know something like this existed.

However, tashiy would of course still need to look up the parameters, or find someone to do it for them. But this program (or a similar one) is probably a step in the right direction.
tashiy
Posts: 9
Joined: Tue Jun 19, 2012 9:17 am

Post by tashiy »

DrMcCoy wrote:
jepael wrote:There is a DOS program called SBTimbre that you can enter instrument parameters and use MIDI interface to play the sounds with MIDI keyboard.
Nice, didn't know something like this existed.

However, tashiy would of course still need to look up the parameters, or find someone to do it for them. But this program (or a similar one) is probably a step in the right direction.
The possibility with SBTimbre sounds interesting.
Jepael you wrote there are .laa files that contains the music and instrument data from Monkey Island 1 and these Files can imported in SBTimbre. As I understand it right.
jepael
Posts: 32
Joined: Sat Oct 25, 2008 8:16 pm

Post by jepael »

tashiy wrote: The possibility with SBTimbre sounds interesting.
Jepael you wrote there are .laa files that contains the music and instrument data from Monkey Island 1 and these Files can imported in SBTimbre. As I understand it right.
No, they cannot be directly imported.

The .laa files are extracted adlib audio resource data from Monkey Island. You need to look inside the .laa file yourself somehow (hex editor, C code) and see the exact OPL register settings for all the 8 instruments. That is about ten bytes per instrument, much less than 16 bytes anyway. ScummVM or AdPlug (can play .laa and other adlib files) source code will tell you where to find the instrument definition bytes contain values for the parameters, and then you can type in these parameters into SBTimbre.

SBTimbre can load/import some types of instruments or instrument banks, so in fact, it might be just easier to write some software or script that reads .laa files and exports .ibk instrument bank files.
tashiy
Posts: 9
Joined: Tue Jun 19, 2012 9:17 am

Post by tashiy »

jepael wrote: No, they cannot be directly imported.

The .laa files are extracted adlib audio resource data from Monkey Island. You need to look inside the .laa file yourself somehow (hex editor, C code) and see the exact OPL register settings for all the 8 instruments. That is about ten bytes per instrument, much less than 16 bytes anyway. ScummVM or AdPlug (can play .laa and other adlib files) source code will tell you where to find the instrument definition bytes contain values for the parameters, and then you can type in these parameters into SBTimbre.

SBTimbre can load/import some types of instruments or instrument banks, so in fact, it might be just easier to write some software or script that reads .laa files and exports .ibk instrument bank files.
I had a quick look inside different laa files from Monkey Island 1 with a hex editor. I hoped to find some plaintext to understand the function. But I only see the the raw binary data. I know thats a bit over my head. But I really like to understand where these variables are saved.

I f I understand it right I have to look at the Scummvm OPL Emulator sourcecode (Mame/Dosbox) where the FM Parameters are processed?
jepael
Posts: 32
Joined: Sat Oct 25, 2008 8:16 pm

Post by jepael »

tashiy wrote: I f I understand it right I have to look at the Scummvm OPL Emulator sourcecode (Mame/Dosbox) where the FM Parameters are processed?
No, an OPL emulator is responsible generating sound with those parameters when they are written to it, just like a real OPL chip.

You would have to take a look at some music playing code that can play .laa files to know what bytes in the .laa file are the instrument data for which OPL register.

Basically for each instrument in the .laa file, you take 11 bytes, reorder them, and write these 11 bytes into another file along with header information, to create either instrument or instrument bank file compatible with SBTimbre.

Moddingwiki has a lot of formats explained.
http://www.shikadi.net/moddingwiki/SBTimbre

You can also find OPL chip register information in Moddingwiki, so you only need .laa file player source code (like AdPlug or LordHoto's player), pen and paper to write down instrument parameters in human readable form, and then type in channel/operator parameters like volumes, multipliers, ADSR envelope parameters etc separately into SBTimbre.
tashiy
Posts: 9
Joined: Tue Jun 19, 2012 9:17 am

Post by tashiy »

I see much info regarding noteFrequencies and things like uint8_t instruments in lordhoto`s sourcecode.

In the following link i found the register information from the OPL Chip in the moddingwiki.

Sadly that all over my head. I can`t really see any connection and dependencies in the specification and the sourcecode.

Till now I like to thank you all to explaining these things to me.
jepael
Posts: 32
Joined: Sat Oct 25, 2008 8:16 pm

Post by jepael »

You can see yourself the original .laa file instrument byteorder from LordHoto's setupChannel and setupOperator functions in adplayer.cpp line 219 onwards. It tells you in which order the 11 instrument bytes get written into certain OPL chip register addresses.

Then taking a look at .sbi file format documentation shows you in what order the OPL chip register bytes should be. Apparently they are the same bytes but in different order:
http://www.shikadi.net/moddingwiki/SBI_Format

Take pen and paper and compare laa and sbi formats, which data bytes goes to which OPL chip register address.

After you have drawn on pen and paper how to reorder the 11 bytes, you can take a look at Adplug source code.

Adplug mid.c is also used to load in .laa files among other types. Lines 983-1006 show where to read instrument definition bytes, and the bytes order is changed somewhat before storing for later use.

My guess is the internal order in myinsbank (array of instrument bytes) is same as in .sbi instrument file, so your pen and paper method should match Adplug source code. If it does not match, trust your paper and pen.

I hope this helps.
Post Reply