pouët.net

Sound in small DOS intros ?

category: code [glöplog]
I have been looking for different ways to output sound in DOS intros, using as few bytes as possible.

- General Midi : a classic. Require only a few bytes. Unfortunately there is not that much room for creativity / effects. Also (correct me if I'm wrong) DOSBOX sends this directly to the OS midi mapper (instead of emulating it) so same intro might sounds differently on some computers .

- PC speaker (port 0x61) : pros : easy to setup / use. But it can only have two states : on /off. Because of that it's can only output square wave sound (aka beeps).

I have tried to use PDM (Pulse Density Modulation) and PIT (Programmable Interval Timer) to output something much more interesting (eg : 8 bit resolution). It works, but sound quality is really poor. In DOSBOX, it sound like there is a low pass filter put on the whole thing (I did not tried on real hardware).

- SB16 / GUS / whatever : good sound quality but require too much bytes to get it work. I have found some SB16 code here : http://www.shdon.com/files/wave-c.zip .
Don't know for GUS and the other cards, but I expect code to be as long as SB16.
added on the 2016-11-26 00:23:26 by Tigrou Tigrou
Quote:
- General Midi : a classic. Require only a few bytes. Unfortunately there is not that much room for creativity / effects. Also (correct me if I'm wrong) DOSBOX sends this directly to the OS midi mapper (instead of emulating it) so same intro might sounds differently on some computers .

What exaclty should it emulate?
DOSBox emulates an MPU-401 interface, which itself is just a MIDI adapter. Like "back in the days", the target of this emulation can be any synthesizer you want, no matter if external hardware or internal software synthesizer, but most of the time, on a modern computer, this is of course the GS Wavetable Synth. But you could easily reconfigure your system to choose a different default MIDI device, like an external hardware syntheiszer. Doesn't even have to be compatible with General MIDI, since that is just an instrument and behaviour definition, not a protocol.

You missed an obvious alternative to playing wave files on the SoundBlaster: OPL2 / OPL3 (aka AdLib).
AdLib

Yes, the most interesting sounding one from that list..
added on the 2016-11-26 07:34:54 by 1in10 1in10
AdLib also has the advantage of many mature tools being available from small to big. :)
added on the 2016-11-26 10:02:50 by tomaes tomaes
I believe there are Dosbox builds with Roland MT-32 emulation if you want to explore a somewhat exotic option.
added on the 2016-11-26 14:21:47 by absence absence
About MIDI: did orgs accept DOSBox conf?
added on the 2016-11-26 14:34:12 by g0blinish g0blinish
Since the MT-32 is one of those devices that you can hook up to an MPU-401, you do not need a custom DOSBox build - you can get Munt, install the Windows MIDI driver, set it as the default MIDI device in Windows and then DOSBox will send its MPU-401 commands to the MT-32 (or other emulated synth, there are some more classic options) to Munt.
like others have said.
Adlib, it does have room for alot of experimentation, does a bit plastic-like but alot better than PC-speaker.
added on the 2016-11-26 17:30:14 by rudi rudi
@Tigrou, you might want to check this one http://www.sizecoding.org/wiki/Output#Producing_sound

Regarding the PC speaker, you can modify the "timer2" to change the frequency, that allows for arbitrary FM synthesis, example here -> SpeaCore 128b.

If you (all) find something groundbreaking, it would be awesome to contribute that to the sizecoding wiki =)
added on the 2016-11-26 17:55:15 by HellMood HellMood
Quote:
What exactly should it emulate?

Do you mean that the way midi sounds for a particular card (eg : SB16) is not tight to the hardware ? I tought the opposite.

Quote:
AdLib

I skipped that one because I thought it was not compatible with DOSBOX. Actually it's not totally true : http://www.dosbox.com/wiki/sound#AdLib
added on the 2016-11-26 18:05:34 by Tigrou Tigrou
Hellmood: nice one.
added on the 2016-11-26 18:06:03 by rudi rudi
Yep, thanks Hellmood. I only saw your post after submitting reply.
added on the 2016-11-26 18:34:23 by Tigrou Tigrou
If you set the low two bits of port 0x61 and put value 0x90 (mode 0, LSB only) in port 0x43 then you get pulse width modulation. Each byte that you send to port 0x42 causes a high pulse, the length of which is ~838ns times the byte value (except that value 0 gives a very long pulse). If you send bytes to this port at a very regular rate, you have a pretty decent approximation to a DAC (apart from the carrier frequency). This is how the mod player at the end of 8088MPH works.

In general, the tricky part of getting it to sound good comes down to two factors: getting a high enough sample rate to avoid an annoying carrier whine, and outputting at a very regular rate to avoid jitter noise. With a sufficiently fast machine, you can use an IRQ0 (interrupt 8) handler with the timer channel 0 period changed to correspond to the desired sample rate, and just do your 'OUT 0x42,AL" in the interrupt handler. Enough software does this that DOSBox does a reasonably good job with it (in fact, I think it cheats and directly converts the pulse lengths to levels avoiding a carrier whine instead of the more accurate method of generating a high-rate 1-bit waveform and resampling it to audio rates).

If all you want is a DAC that you can hammer bytes to (and don't mind requiring hardware more sophisticated than a PC speaker) you might do better by using the SoundBlaster DAC in direct mode. It's been a while since I've done this, but I think the procedure is to write byte 0xd1 to port 0x22C to turn the speaker on, and then for each sample write byte 0x10 followed by your 8-bit sample (both to port 0x22C). No need to worry about carrier whine, but you do still need to write bytes at a regular rate to get clean notes. Similarly for a parallel port DAC (Covox Speech Thing or Disney Sound Source).
added on the 2016-11-26 22:07:27 by reenigne reenigne
Quote:
Do you mean that the way midi sounds for a particular card (eg : SB16) is not tight to the hardware ? I tought the opposite.

The SB16 does not have a wavetable synthesizer. It can be connected to an MPU-401 as I said, which is merely a MIDI interface that can be used to connect it to a real MIDI synth. Another option would be the optional MIDI daughterboards, I guess. The first SoundBlaster to feature a built-in wavetable synthesizer that can be accessed via MIDI is the AWE32, and even that does not have a specific sound because you first have to load a soundfont into it.

Quote:
I skipped that one because I thought it was not compatible with DOSBOX. Actually it's not totally true : http://www.dosbox.com/wiki/sound#AdLib

The thing that most people call "AdLib" is in fact just the OPL2 chip, which is part of every SoundBlaster. If DOSBox didn't emulate it, it wouldn't emulate SoundBlaster cards correctly.
Assuming that the MPU-401 MIDI interface means General MIDI or an MT-32 sound module is weird. Well if the platform is Youtube captured from Dosbox, then why not. Why not as well assume that Windows 95 is installed, so you can use all its software and media files in the "DOS" intros.
added on the 2016-11-27 17:50:05 by yzi yzi
The OPL2 (or OPL3 on later Sound Blasters) is also the one used by (old versions of) windows when playing MIDI files, unless you have the MPU401 and some other synth connected to that (not a common setup back in the days). But, from a DOS intro, there is no direct MIDI access to the OPL2/3, so you have to program the chip directly.
Quote:
Assuming that the MPU-401 MIDI interface means General MIDI or an MT-32 sound module is weird.

It's the best assumption you can make though. Assuming that a specific synthesizer that is not GM-compatible is connected via MPU-401 reduces your audience to almost zero. (MT-32 is not GM-compatible but was widespread enough and there are emulators, so it's a valid option.)
Those cards and card+module combinations were really rare and expensive, so making that assumption for "DOS" platform is ridiculous.
added on the 2016-11-27 20:06:07 by yzi yzi
Quote:
If all you want is a DAC that you can hammer bytes to (and don't mind requiring hardware more sophisticated than a PC speaker) you might do better by using the SoundBlaster DAC in direct mode.[...]


True. Disadvantage: Not supported by many SB clones =(
added on the 2016-11-27 22:45:16 by T$ T$
yzi: Okay, then let's assume this: No sound output at all. That doesn't help anyone.
Besides, there was UltraMID for the GUS and of course the AWE32/64 which would allow MPU-401 (and MT-32 emulation to a certain degree). And now please don't argue that noone had an AWE32/64, or noone used the GUS TSRs.
@yzi: DOS was never a fixed platform, that's part of what makes it fun. There was all kinds of bonkers hardware floating around back when it was current. Everything from expensive pro audio synths & 3D accelerators to hacked-together resistor DACs. If you wanna support MT32 or whatever in your DOS prod, you just do it; stick a line in the nfo that says "requires: MT32 on port x." Done.
added on the 2016-11-28 09:20:56 by jmph jmph
Exactly. Just like an Amiga intro can say it requires a MIDI output hooked to a General MIDI module, or that you run it in WinUAE. Done. I think such an intro would be quite weird and/or lame though.

This thread begins with "- General Midi : a classic. Require only a few bytes. Unfortunately there is not that much room for creativity / effects. Also (correct me if I'm wrong) DOSBOX sends this directly to the OS midi mapper (instead of emulating it) so same intro might sounds differently on some computers ."

So, it feels like the platform that's being talked about is actually something like Dosbox in Windows.
added on the 2016-11-28 13:01:33 by yzi yzi
that's just another incarnation of the DOS platform. Yes, however primitive it is, DOS is an hardware abstraction layer and plain DOS apps can run on quite anything that has an x86 CPU (including some high end Casio calculators). There are various implementations of it. Microsoft's one is popular, but there is also IBM PC-DOS and Digital Research/Caldera DR-DOS, and FreeDOS. And Dosbox.

If your platform tag is "DOS", then yes, all of these apply. And this is why there is a DOS+GUS platform on Pouet, which is a little more "fixed hardware".

For the record, some Atari ST games did support (as an option) plugging the MT32 to the machine's MIDI ports and using it for much better sound than the built-in YM chip. Why not? And why wouldn't that be allowed in a demo? As long as you do it with style, and it helps your creativity, I don't see a problem. As usual, make sure people are aware of it when they watch the demo, so they can understand the technical advantage over other prods and judge accordingly.
oh the memories...
BB Image
added on the 2016-11-28 13:31:50 by wysiwtf wysiwtf
Oh the rules and definitions of what is "allowed". It's important to use the Correct Tags so sceners i.e. prod quality measurement devices can produce the correct output.

Quote:
make sure people are aware of it when they make the demo


Fixed that for you.
added on the 2016-11-28 13:34:28 by yzi yzi

login