Page 1 of 1

Sound cards

Posted: Thu Sep 02, 2004 3:12 pm
by confused
How does one programme a sound card? What is a mixer device with a sound card? I think it's just a speaker control, but I'm not sure... what format must sound be in to hear it through the speakers attached to the sound card? I have a SoundBlaster Live! 5.1 which uses the EMU101K chipset, the registers of which are well "documented" in Linux source code...

... but I can't figure out what's happening (the "big picture") by reading the source...

If sound is in some format like MP3 or Ogg Vorbis, it must be translated somehow into some format the sound card understands, right? Would the driver convert it into something (WAV for example), then command the sound card to accept input, then setup a DMA transfer to write the byte stream into the sound card controller or something?

Thanks... I'll try to find a way to pay you all back for answering my questions one day :D

Re:Sound cards

Posted: Thu Sep 02, 2004 3:18 pm
by DennisCGc
confused wrote: If sound is in some format like MP3 or Ogg Vorbis, it must be translated somehow into some format the sound card understands, right? Would the driver convert it into something (WAV for example), then command the sound card to accept input, then setup a DMA transfer to write the byte stream into the sound card controller or something?
Typically the program would convert MP3's, OGG, WAV, ASF etc. to sound card output.
The driver takes care of the input it gets (output from the program) and will send that to the sound card.

Hope this helps a bit

Re:Sound cards

Posted: Thu Sep 02, 2004 3:26 pm
by confused
DennisCGc wrote: Typically the program would convert MP3's, OGG, WAV, ASF etc. to sound card output.
The driver takes care of the input it gets (output from the program) and will send that to the sound card.

Hope this helps a bit
Thanks very much Dennis. That's what I was trying to figure out... now it's becoming clearer. Do you know what sound card format is? Do all sound cards recognise the same format? Do they understand more than one format, if not?

Re:Sound cards

Posted: Fri Sep 03, 2004 8:38 am
by DennisCGc
confused wrote: Do you know what sound card format is? Do all sound cards recognise the same format? Do they understand more than one format, if not?
AFAIK, you send tones to the sound card, read the manuals about some sound cards.
Also, you can find some demo's on several websites (also on www.qbasic.com, and yes, you can easily convert it to C, assembly, or whateveryoulike...

HTH a bit ;)

DennisCGc.

Re:Sound cards

Posted: Fri Sep 03, 2004 9:04 am
by Pype.Clicker
there are several parameters, but typically the soundcard accept (un) signed Pulse-Code-Modulation

That is, your sound consist of regular (44100KHz) samples, each telling the 'position' of the speaker's sheet relatively to a 'central' position

thus encoding '-128 -128 127 127'*N (with signed 8 bits PCM) plays a 'square wave' with a frequency F = sampling rate/4 (usually damn right). '-128 127 -128 127' is one octave even higher and (-128 -128 -128 -128 127 127 127 127) is one octave lower.

.WAV, .VOC are usually directly playable, sometimes skipping some metadata is required, or unsigning/signing samples, swapping bytes (little/big endianness) ...

So most of the time, you tell the Sound card what frequency/encoding you'll feed and then set up a DMA circular buffer in which you'll put samples. When the buffer has been played back, you'll get an interrupt...

Re:Sound cards

Posted: Fri Sep 03, 2004 10:06 am
by mystran
With unsigned .WAV playing it directly is possible if it is encoded with the same format as whatever your soundcard is set to receive. Some soundcards can receive several formats, but you have to tell it what to accept anyway...

Anyway, you normally do want to skip the header, since playing the header as PCM data will give you an ugly "crutzh" sound when you start playing the .WAV.

Finally, you should actually check the .WAV headers to see what format it's in, and convert if necessary. It might be in wrong sample rate (resulting in playing with wrong speed, sounds funny..) or it might be unsigned/signed (wrong format causes really ugly sound) and finally 8/16/24bit (or even higher.. wrong setting result is usually some kind of noise, from which it's sometimes possible to hear the original sound playing with wrong speed, but most of the time it's just sounds like really loud white-noise).

edit: There are also some more "weird" encodings like ?Law which is logarithmic, and such.. Finally, a .WAV file CAN be compressed, in which case in which you obviously need to uncompress it. Compression is quite rare though.

Re:Sound cards

Posted: Fri Sep 03, 2004 10:37 am
by Pype.Clicker
a common compression technique in basic wave files is ADPCM, which encodes *differences* between samples rather than samples themselves. The trick is that if your wave is not "changing" too fast (e.g. has a low-pass filter properly set up), you need less bits to encode such differences than the data.

No need to say that my square wave will encode poorly with ADPCm. Here again, most decent soundchips will be able to play ADPCM stream directly. There may be built-in MP3 decoders on some sound chips, but i don't know about which have and which don't nor about how they're actually programmed...

Re:Sound cards

Posted: Fri Sep 03, 2004 10:49 am
by mystran
Finally there are chips like those find on Creative's Live and Audigy cards, which are really just generic DSP's, to which you can upload any DSP code you've written, provided you know the chip-architecture and have support for that in drivers.

I'd imagine most cards that claim to support EAX or OpenAL or something similar probably have a generic DSP in them. Whether there's other support for normal waves is another thing.

Re:Sound cards

Posted: Fri Sep 03, 2004 3:03 pm
by Candy
PS, the square wave is a very bad example of sound card output. The sound card output might be buffered by condensators and is usually coupled to a speaker set that prefers the neutral setting, iow, outputting a square wave overexhausts it. Try a sine or a combined sine.

The nyquist-sampled square wave is equivalent to the same nyquist-sampled sine wave, so that one would be ok. Don't forget that it should probably be a lot softer because the speaker has to overpower for the sheer speed of it. Try -5 to 4 or something like that.

Re:Sound cards

Posted: Sun Sep 05, 2004 6:21 pm
by srg
hmm According to the SB16 programming docs, 8-bit PCM is unsigned and 16-bit PCM is signed.

srg