Flushing the Secondary Buffer in DSound

Started by
1 comment, last by CrushingHellHammer 19 years, 10 months ago
How do I get rid of those annoying pops in DirectSound? I have a very simple app that opens a sound file and plays it. I have a "Play" and a "Stop" button. The "pops" manifest themselves when I either (a) Press "Play" again, once the file has finished playing (b) Press "Stop" and then press "Play" again. Am I correct in intuitively assuming that if I flushed the buffer these pops would disappear? If so, how can I do that. I don''t see a "Flush" method. If this approach is wrong, could somebody advise me on how to get rid of these? This is critical for my app, as I''m feeding the contents of the buffer to some functions that perform some DSP. Thanks a lot, in advance!
Advertisement
actually, the pop is most likely coming from a sample that varies too much with the previous value, giving a near-vertical slope (just think about how the speaker would try to move from rest position to the position indicated by the sample and you''ll get an idea).

Flushing the buffer with zeros won''t fix this, but what you can do is make sure that the transition isn''t as dramatic. One easy way of doing this is to fade the volume down gradually when stopping and up gradually when resuming playback.

This is more complicated when mixing different sounds into the same output buffer since you don''t want to affect the volume of the entire sound channel when playing a second sample over it, so you''ll have to do volume interpolation for each sound you''re mixing in. There may be a way in DirectSound to give volume levels to each waveform (IIRC there is).

It''s been a while since I''ve done DirectSound programming so I don''t know the specifics but this should give you a good idea.
Greenspun's Tenth Rule of Programming: "Any sufficiently complicated C or Fortran program contains an ad-hoc, informally-specified bug-ridden slow implementation of half of Common Lisp."
Void pointer is correct but you don''t want to dampen the signal if you are doing DSP work on it. You don''t say what kind of analysis you intend to do, so it''s tough to really know.

On the other hand, to get rid of the pops on the speaker youare going to have to stop and start the sound signal when is crosses a zero value. If you are sending a pure sign wave (digitized) the DAC generates an analog signal by "filling" in the values between to digitzed inputs. If you stop at the peak value of the digitized sound wave the DAC creats this bizzare signal which goes from your max value to 0 in one sample time. That sudden drop will most likely introduce more garbage when the speaker responds to the spike than the actual analog signal itself.

In the generation of music for listening, you will have to fade in or fade out as void* states. But for DSP stuff you might not want to do that. Just be sure that the sample you use for analysis starts after the signal gets going and ceases before it stops. Clearly, a sudden spike up (or down) is going to mess up your analysis. Think of what a job those spikes will do on a frequency spectrum!

Brian
Brian Reinhold

This topic is closed to new replies.

Advertisement