Date: Wed, 5 Mar 1997 11:23:55 -0600 (CST) From: Ethan Brodsky Subject: Re: sound routines On Wed, 5 Mar 1997, somebody wrote: > I hope you don't mind me mailing you about this. I was very > interested by your web page and am glad to have found someone who has > put some effort into sound routines. I have been working on a sound > routine in Assembly for some time now and i have what i beleive to > be, a very fast mixer routine. I used to have a problem with the > soundcard creating a click (as it says in your info) when i restarted > the sample after a DMA interrupt had occured. (this was with my > Soundblaster 16 card). I eventually used the other playback call (i > can't remember the number offhand). But it's the one which CAN use > stereo and choose between 16 and 8 bit output. So the routine works > ok now. I am however concerned because i don't think my routine will > work on soundblaster 8 bit cards as i suspect that they only support > one playback call. If you have the time i would greatfully appreciate > it if you could elaborate on why the click occurs and how to prevent > it. I have written a few sound routines and would like to discuss > them in the future. I hope you don't mind me mailing, if your too > busy then that's that. I'm fairly busy, but I have enough time to give you advice. I don't have time to look at your code though. (I used to debug sound code for people, but I stopped doing that last year) The new commands Bx/Cx are, as you believe, only supported on the SB16. In order for your code to work on earlier sound cards, you must use the older commands. I'd recommend getting the official hardware reference manual, which Creative Labs has now made available on the www (I had to pay $100 to get it). I don't remember the URL, but there is a link to it at the bottom of the WWW version of my SB16DOC. Now, on to your problem with clicks. There are a number of causes of clicks, including some that I don't understand. The first one is the interval between blocks of a transfer. When you program for playback, the DSP plays one block, triggers and interrupt to tell you to start the next, and stops. Although your interrupt handler immediately starts another block, there is a small delay (at 44100 HZ, the samples must come 20 microseconds apart), and this results in a click. You can minimize the click by reordering your interrupt handler so that it copies in the new data and restarts the transfer first, then performs any other functions like mixing, etc... You'll end up with an extra delay between when you send the sound and when it is heard, but the click is eliminated. If you really want to work at it, you might be able to eliminate the delay of most of the copy by copying in the first few bytes, starting the transfer, then copying the rest before it catches up. If you are playing directly out of the sound buffer rather than double-buffering, then all my discussion about copying is irrelevant, and you simply have to speed up your transfer. A better solution is to use auto-initialized DMA. With AI DMA, the sound card sends you the interrupt at the end of each block, but automatically resets and plays the next block, without a delay. To do this, you typically program the DMA controller to do autoinitialized DMA with a buffer, then program the sound card to do autoinitialized playback with a buffer half that size. Thus, the sound card will play a block, interrupt, play the next block, interrupt, then the DMA controller will wrap around to the begining, and the sound card will play a block, etc... This is often described as a "ping-pong scheme", since the sound card bounces back and forth, playing buffer 0, then buffer 1, then buffer 0, then buffer 1, etc... Your interrupt handler fills the buffer just finished with the new data, while the card is playing the other one. That way the card never runs out of data and never clicks. Unfortunately, AI DMA is not supported by all cards. There are a few _old_ SB 1.xx cards out there that don't support it. For these, there is still hope. You can still program the DMA controller for auto-initialized DMA. You then program the DSP for single-cycle output with half the buffer size. When it finishes, you still must reprogram the DSP, but it takes a lot less time than programming the DSP and the interrupt controller. The other cause of clicks is buffer mismanagement. This comes from a variety of causes, but usually results in your program not keeping the buffers correctly updated. You might copy data over the point where the sound card is currently playing, or you might misalign the buffers so it plays one byte or so of uninitialized data. Good luck in tracking your click. If you have any furthur questions, feel free to ask, Ethan Brodsky ----