开发者

Playback "clicking" noise

I am trying to write a program to play a small .wav file in C++. I have programmed it following the DirectX SDK documents to write and play on a secondary static buffer. It runs correctly except that at the end of the playback for 开发者_JAVA技巧any .wav file, there is a very noticeable "clicking" noise. I am certain that it's not a defect on my audio hardware's part because any other game that I know uses DirectSound doesn't have it.

I've tried polling GetCurrentPosition for it every cycle and stopping it right before it ends but was unreliable. I can't play it on a primary buffer because .wav's played on primary buffers must be looped, which I don't want.

Does anybody know a fix to this problem? Thanks in advance.


We'd need to see both the WAV file in question and the code to load the WAV file into the sound buffer. But's here's a few guesses.

My first guess is that if we were to load the WAV file you have into an a visual audio editor we'd see the sound coming to an abrupt end instead of tapering off into silence. This would result in an abrubt "popping" noise with almost any audio player.

My second guess is that you are copying garbage data into the sound buffer at the end. Some WAV files have extra metadata at the end of the file past the end of the DATA chunk. Not sure how you determined the positions in the sound file to copy samples from, but its easy to mess this up. Did you inspect the WAV file with a hex editor (like Visual Studio) to confirm the length of the DATA chunk is as big as it claims to be? When you debug the ReadFile call to copy data from file into the buffer, did you inspect the last several bytes of your buffer match what you saw in the hex editor?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜