VOGONS


First post, by Malvineous

User metadata
Rank Oldbie
Rank
Oldbie

Hi all,

I'd like to take the new OPL synth used by DOSBox and incorporate it in some other license-compatible programs, however I'm a little unsure about the format of the samples that the synth produces.

The samples come out in 32-bit unsigned integers, however as best as I can tell they are only 16-bit values. However if I output these samples as 16-bit audio they are very quiet (much quieter than in DOSBox), which makes me think the full dynamic range available in a 16-bit sample is not used.

I don't really want to assume the samples are smaller (e.g. 14-bit) because then I will get clipping if a sample ever arrives that it outside this range, and unfortunately looking at the mixer code it's not immediately obvious what's going on.

Can anyone shed some light on what type of samples are produced by the OPL synth, and how DOSBox is able to amplify it to normal levels?

Reply 1 of 5, by wd

User metadata
Rank DOSBox Author
Rank
DOSBox Author

Which is the last (outmost) dosbox-contained function you are using?

Reply 2 of 5, by Malvineous

User metadata
Rank Oldbie
Rank
Oldbie

At the end of dbopl.cpp, in Handler::Generate, it calls MixerChannel::AddSamples_m32(). I have implemented my own version of this function (so that I didn't have to modify dbopl.cpp), which means I receive the buffer that was ultimately filled by DBOPL::Chip::GenerateBlock2().

Reply 3 of 5, by Harekiet

User metadata
Rank DOSBox Author
Rank
DOSBox Author

That's pretty much the final output in mono samples or when it's using generateblock3 it's creating stereo output. It's just the 16bit values of all the different opl channels added up and it depends on the mixer to the final clipping although i don't think the volume is very loud that it even needs clipping.

Reply 4 of 5, by Malvineous

User metadata
Rank Oldbie
Rank
Oldbie

Ok then, so the mixer must be doing some amplification of its own? The DOSBox OPL output is at least 3-4 times as loud as the output I'm getting, when I treat the samples as 16-bit values.

Any idea what sort of amplification the mixer does? The reason I ask is that I've never heard the DOSBox output clip, but (in the past with other synths) amplifying it myself has always resulted in loud clicks on certain songs when clipping has occurred.

Also as a side note, how are the samples internally generated? Having recently connected an OPL2 chip to an Arduino I discovered the chip outputs digital samples in a weird kind of encoded 8-bit, which the DAC chip then converts to analogue. Does the emulator generate the encoded 8-bit samples internally, or the final 16-bit sample?

Reply 5 of 5, by wd

User metadata
Rank DOSBox Author
Rank
DOSBox Author

adlib.cpp does a mixerChan->SetScale( 2.0 ); (think that's to rebase opl synth with SB digital output)

but (in the past with other synths) amplifying it myself has always resulted in loud clicks on certain songs when clipping has occurred.

How are you clipping? In dosbox the mixer buffer is Bit32s work and it is fed to SDL through
MIXER_CallBack which is also where the Bit32s is clipped down to a Bit16s (SDL target format).

Harekiet may (or may not hehe) remember if all the mixer shifting introduces some amplification.