Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Poor sound quality under DOS

This thread is locked; no one can reply to it. rss feed Print
 1   2 
Poor sound quality under DOS
Ulrich Peters
Member #3,933
October 2003
avatar

Hello,

I am developing a program using Allegro 4.1.11. The code is written to allow me to compile it for DOS (using DJGPP) and Win32 (using MSVC6). Both versions use the same DAT files where the sound samples are stored.

When running the program on DOS (I use OpenDOS 7.01), I get a bad sound quality with a lot of background noise. The Win32 running on the same hardware and using XP has the clear and loud sound, originally expected for both versions.

The hardware I am using is a VIA EPIA board, which has a VT1612A sound processor. This device can emulate a Sound Blaster on IRQ5/7, 0x220, DMA 1. To have this emulation work under DOS, it is required to load a small TSR.

One could think that the TSR is not well written, and that the emulation isn't working well. However, I installed my DooM II (yes, I am that old) on the same DOS partition, and the sound is perfect: DooM has loud, clear and scary sound effects. So the problem is not the TSR, as I told DooM during install the same I said to Allegro: Sound Blaster, IRQ5, etc.

I already tried all Sound Blaster types available in the Allegro setup program, and all produce terrible sound. Why does DooM work fine, and the Allegro-based program sounds so low and distorted (under DOS)? Any ideas to solve this?

Thanks,
Ulrich

Marcello
Member #1,860
January 2002
avatar

I got a really good idea. don't use dos.

Marcello

Ulrich Peters
Member #3,933
October 2003
avatar

Yes, if there weren't no power outages, and people could be teached about the need to shut down the Windows file system (or Linux, or whatever) before turning off the equipment, I could agree. Unfortunately some people don't have the time or the will to wait for long boot times, file system recoveries, and shutdown delays.
In short, it probably has to be done on DOS.

Michael Jensen
Member #2,870
October 2002
avatar

So if it's not the tsr, then it's allegro's dos sound support that is written "poorly", actually in theory it could still be the tsr -- I don't know much about sound implimentation but I do know there's usually more than one answer to a problem -- your problem -- "we need sound in dos" solved by doom via method 1, solved by allegro via method 2, your tsr may have great support for method 1 and horrible support for method 2,--you could just look at the doom 2 source code (which I belive is freely avilable) and write your own sound code...

Edit:
Here's a question, without the TSR loaded does allegro autodetect your sound?

Bruce Perry
Member #270
April 2000

Quote:

This device can emulate a Sound Blaster on IRQ5/7, 0x220, DMA 1.

There's your problem (well, part of it). The first four DMA channels (0 to 3) are for transferring 8-bit words between memory and hardware. The other four (4 to 7) are for 16-bit data. The Sound Blasters (and probably all other cards with PCM audio support) use DMA to get the sample data from memory (or write to memory when recording). If you can only specify a low DMA channel, that means your emulation only supports 8-bit sound. (To understand why this results in noise, you have to understand the way sound is stored and have a certain feel for what various waveforms sound like; if this is new to you, play with a sample editor such as Cool Edit.)

You can, however, do something to help the situation. Read the docs for set_volume_per_voice(); that should help to some extent.

--
Bruce "entheh" Perry [ Web site | DUMB | Set Up Us The Bomb !!! | Balls ]
Programming should be fun. That's why I hate C and C++.
The brxybrytl has you.

Chris Katko
Member #1,881
January 2002
avatar

Is it possible to set the DMA higher on your TSR/soundcard?

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Bruce Perry
Member #270
April 2000

8-bit sound and 16-bit sound are quite separate on a Sound Blaster. If the emulation supports 16-bit sound, it should* be quite obvious to the software that wants to use it (Allegro included). If not, then there is no way you will get 16-bit sound. Sorry.

*Sound Blaster emulation is (apparently) tricky to do well. You may find that some software fails to detect the emulation. Allegro 4.x is usually OK though in my experience (Allegro 3.12 wasn't).

--
Bruce "entheh" Perry [ Web site | DUMB | Set Up Us The Bomb !!! | Balls ]
Programming should be fun. That's why I hate C and C++.
The brxybrytl has you.

Chris Katko
Member #1,881
January 2002
avatar

Yeah, I know that all too well. Sometimes setting it manually will work a lot better. I used a Pro Audio Spectrum 16 for years. That thing was a beast, but some programs didn't fully support it's sb16 emulation.

p.s. Never knew that DMA lines where different lengths. Thanks for mentioning that.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Ulrich Peters
Member #3,933
October 2003
avatar

Hi,
thanks for the input. The hardware offers DMA settings from channel 0 to 3. I converted the 16 bit sound sample to 8 bit, but the quality of the output is still the same. On true Sound Blaster hardware (I tested a SB16 AWE) with same DOS and the same software, the sound quality is perfect.
Seems that there is no easy solution for this, after all. Somehow Allegro doesn't like the emulation, while other progams perform just fine, as if a true SB card is present. :(

Ulrich

Kitty Cat
Member #2,815
October 2002
avatar

Make sure you're setting a respectable frequency. IIRC, the default Sound Blaster driver uses 11khz, SB 2.0 and SB Pro use 22khz, and SB16 driver uses 44khz. Also, the default SB driver won't let you use a higher frequency than what the Allegro driver supports, whether or not your card can properly emulate it, and as well doesn't use auto-initialized DMA which can probably cause some static.

Try forcing the SB 2.0/Pro/16 driver, and see if you get better output. And use the High DMA channel (usually 5 or 7) in allegro.cfg if you have one available.

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Bruce Perry
Member #270
April 2000

Also, have you tried set_volume_per_voice() as I suggested? It'll allow you to make the whole thing louder, and then it should be more on a par with Doom in terms of sound quality.

(Note: you have to use the high DMA channel for 16-bit sound, and you can't use the high DMA channel for 8-bit sound. That's just the way it works.)

--
Bruce "entheh" Perry [ Web site | DUMB | Set Up Us The Bomb !!! | Balls ]
Programming should be fun. That's why I hate C and C++.
The brxybrytl has you.

Kitty Cat
Member #2,815
October 2002
avatar

Quote:

(Note: you have to use the high DMA channel for 16-bit sound, and you can't use the high DMA channel for 8-bit sound. That's just the way it works.)

If he has a high DMA channel, he must supply that instead. At least with my SB16, when I had it, if I used the low DMA channel I wouldn't get any sound at all. Probably because it forced the SB16 into 16 bit mode, so the low DMA was inadequite, but I'm not sure of that.

Though I do kind of wish Allegro supported both high and low DMA and just used whichever it needed to for the bit depth and card/driver. Especially when I started out with Allegro, it just said to supply the DMA, but since my SB16 had two DMA channels I didn't know which to give it. And of course, playing it safe I used the low DMA.. ::)

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Sirocco
Member #88
April 2000
avatar

For the SB cards at least Awe32 or later (and I'm assuming SB16 since the AWE series is based on that design) DMA 5 will work, but your output volume will be significantly decreased. You can compensate through volume controls, or boosting the samples.

-->
Graphic file formats used to fascinate me, but now I find them rather satanic.

ImLeftFooted
Member #3,935
October 2003
avatar

hmm, i might be way off, but if you havent u should call reserve_voices() and reserve 1 voice (or how every many u need). the more voices u have the worse the quality.

EDIT: this ofcourse is using allegros method of doing things. as Michael Jensen said. But if you havent tried it yet, u should.

Sirocco
Member #88
April 2000
avatar

The number of voices has more of an impact on volume than anything else.

-->
Graphic file formats used to fascinate me, but now I find them rather satanic.

ImLeftFooted
Member #3,935
October 2003
avatar

It seemed to improve the quality of sound in games ive made dramaticaly. But that was MIDI music, so i guess that might have been differnt.

EDIT:
reserve_voices();

"You should be aware that the sound quality is usually inversely related to how many voices you use, so don't reserve any more than you really need."

Marcello
Member #1,860
January 2002
avatar

I still think my solution is the best. If you're making a freaking GAME, people can wait for a DECENT operating system to START so that they can PLAY it.

Marcello

Oscar Giner
Member #2,207
April 2002
avatar

I own a SBAWE32 and sounds great under DOS, even in 8bit mode, so it's like your sound card doesn't emulate SB 100% correctly.

I don't know how TSR work, but maybe, just maybe, they install themselves in the timer interrupt. Allegro touches this, probably breaking the TSR...

Chris Katko
Member #1,881
January 2002
avatar

That could be it. Allegro is killing it. Before everyone flames me, remember, Allegro constantly reprograms the DOS timer. If the TSR needed to do the same, it'd all go to heck, wouldn't it?

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Zaphos
Member #1,468
August 2001

Quote:

Yes, if there weren't no power outages, and people could be teached about the need to shut down the Windows file system (or Linux, or whatever) before turning off the equipment, I could agree. Unfortunately some people don't have the time or the will to wait for long boot times, file system recoveries, and shutdown delays.
In short, it probably has to be done on DOS.

Actually, a journaling file system like that provided by NTFS and ext3 would solve much of your problem there while still giving you access to good, supported drivers and such. Windows NT or XP, could provide you NTFS; I believe any linux distribution could be set up with ext3. These systems change scanning the hard-disk to a task that only takes a few seconds.

ImLeftFooted
Member #3,935
October 2003
avatar

Marcello has a good point. The original cell phones were like 5 pounds and huge, we dont use them anymore. The first airplanes were immensely cheaper, we dont use them anymore. The first TVs had tiny screens and were really crappy, we dont use them anymore. Music from the 50s is crap and no listens to it. So... why should our programs have to backwards compatible to one of the very first operating systems if nothing else does?

Thomas Fjellstrom
Member #476
June 2000
avatar

NTFS isn't journaled (AFAIK). Wish it was :(

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Bruce Perry
Member #270
April 2000

Everyone who recommended reserve_voices(), please read the docs for:

Also note that reserve_voices() alone will not give you louder sound than you get by default; it can only give you quieter. And it will only affect the volume if you don't call set_volume_per_voice(). If volume is what you care about, use set_volume_per_voice(), not reserve_voices().

--
Bruce "entheh" Perry [ Web site | DUMB | Set Up Us The Bomb !!! | Balls ]
Programming should be fun. That's why I hate C and C++.
The brxybrytl has you.

Zaphos
Member #1,468
August 2001

Tobias Dammers
Member #2,604
August 2002
avatar

Here's my 2p:
Allegro's mixer sucks. It uses a clipping table which is fast, but adds distortion. Also, dos allegro uses quite strange sample rates, so they need to be converted. The best sound I got out of allegro was using DirectX and the DX mixer (not the AL mixer).
Of course, if you refuse to use a "real os" (no offence), you can't do that. Your best bet then, I think, would be to make your own mixer (maybe 16 or 32 bits internally, or even floats), and use only 1 or 2 voices (mono / stereo) from allegro. Doing so, you can avoid allegro's clipping and handle it by yourself. Either do a simple range limiting (mid(minval, sample, maxval)), or something more sophisticated like a compressor or limiter. This will typically eat more cpu time than the dx mixer though.
Anyway, dos... I don't know, but using linux should really solve the boot time problem... longer boot time than dos, but you can get by without rebooting for months... and it unleashes quite some cpu and ram power for you...

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

 1   2 


Go to: