...and if you are wanting to write a DOS sound engine look up the following topics.

  • DMA transfer modes
  • How to program the DMA
  • Writing interrupt service routines
  • SoundBlaster DSP programming - available on Creative's website - Legacy programming - you can download the entire SDK from the old days
  • Sound mixing algorithms - for mixing mutiple sounds into one main mix - easiest way is add byte/word from each sound sample and divide by number of samples - called additive mixing - some drawbacks (too many sounds= very distorted final mix)
  • Assembly language programming - go to Randall Hyde's art of assembly language site - enough to get you started.


The basic idea is that the DMA will scan a portion of memory continually (auto initialized DMA mode). This portion of memory contains the sound data which is then sent to the sound card's DSP via the DMA so the CPU does not have to worry about it. From the DSP it is then converted from digital to analog, amplified, and then sent to the speakers. This is a very simple description as there is much more taking place. In order to produce clickless sound you must always load the portion of the DMA buffer that you just played. This way the DMA offset will never be in the section of sound data that is being loaded which is what causes that annoying clicking.

Split the DMA buffer in half.
Code:
............................................   256 bytes

......................|.....................
       128                 128
    Loading          Playing
  • Play the second half - load the first as you play the second.
  • Play the first half - load the second.
  • Repeat for length of sound


If you want more information then go to www.creative.com - There is a lot of information still available and the best part is that it is free. I programmed a sound system that theoretically could mix an unlimited number of sounds using a 256 byte buffer and it did not click. You really need to be in protected mode to do this correctly because you cannot, repeat cannot, load sound data from disk in the middle of a real-mode interrupt. Try it and watch the whole system crash. Salem helped me out on this issue some time ago - the solution is to move to protected mode and pre-load all the sound data into buffers before they are played - not to mention that loading from the disk during the playback degrades the quality of the sound.

You don't have to load every sound - just when it is about to be played - hence the slowdown in games on some systems when sounds must be loaded from the CD or the hard drive.

I'm probably above your head and if I am I'm sorry, but I spent considerable time last year figuring all this stuff out and it's really not that hard, just tedious which is why DirectSound is a life saver and a good one at that. If you are truly committed to programming this then do some research and don't let the stuff scare you - it's really pretty simple once you get your code up and running and producing sound.