Extract/Convert Adlib Instruments
Moderator: ScummVM Team
Extract/Convert Adlib Instruments
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
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
- DrMcCoy
- ScummVM Developer
- Posts: 595
- Joined: Sat Dec 17, 2005 1:33 pm
- Location: Braunschweig, Germany
- Contact:
Re: Extract/Convert Adlib Instruments
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.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.
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.
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
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
- DrMcCoy
- ScummVM Developer
- Posts: 595
- Joined: Sat Dec 17, 2005 1:33 pm
- Location: Braunschweig, Germany
- Contact:
Sure, we have an OPL emulator in ScummVM (courtesy of DOSBox, based, partially on MAME's emulator by Tatsuyuki Satoh).tashiy wrote:I read there is adlib support in scumm vm. Because of that I think the OPL FM Synthesizer chip must be emulated.
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.
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.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.
Here are some more discussion about the subject:
http://forums.submarine.org.uk/phpBB/viewforum.php?f=9
http://yehar.com/blog/?p=665
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.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.
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.
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.jepael wrote: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.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.
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.
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.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.
- DrMcCoy
- ScummVM Developer
- Posts: 595
- Joined: Sat Dec 17, 2005 1:33 pm
- Location: Braunschweig, Germany
- Contact:
Oh, neat.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.
Of course not something a normal non-programmer/-engineer (like I guess tashiy is) could do. I like this a lot, though.
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:Well, ScummVM emulator knows how to play the music. [...] MIDI data with custom header that contains parameters for the OPL chip instruments.
Nice, didn't know something like this existed.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.
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.DrMcCoy wrote:Nice, didn't know something like this existed.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.
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.
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.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.
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.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 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.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?
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.
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.
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.
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.
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.