Basic DirectSound problem

Started by
8 comments, last by Raeburn 21 years, 11 months ago
I'm having trouble playing a sound with DirectSound8. Everything works fine (the initialization, loading etc) except for the actual playing of the sound. The sound plays well, until the end, where some static noise suddenly pops up. Kind of like the sound you hear when unplugging the speaker cable while the power is still on. It's extremely annoying, and I have no clue why it happens, as I am a total n0n-l337 n00b at DirectX programming. The code (in short) is as follows... it is in Visual Basic, as I have been forced to work with it. --[theCode]------------- 'Globals Public dx As DirectX8 Public ds As DirectSound8 Public dsSecondaryBuffer As DirectSoundSecondaryBuffer8 Public DSBuffDesc As DSBUFFERDESC Public Sub InitSound() Set dx = New DirectX8 Set ds = dx.DirectSoundCreate(vbNullString) ds.SetCooperativeLevel frmMain.hWnd, DSSCL_PRIORITY Set dsSecondaryBuffer = ds.CreateSoundBufferFromFile(App.Path & "\Sounds\Snare.wav", DSBuffDesc) dsSecondaryBuffer.Play 0 Exit Sub --[/theCode]------------- Really need some help! Thank you, Daniel Lindros [edited by - Raeburn on May 4, 2002 11:26:04 AM] [edited by - Raeburn on May 4, 2002 11:26:41 AM] [edited by - Raeburn on May 4, 2002 11:27:21 AM]
Advertisement
I had the same problem, I tried everything manually reseting the play point before each play, making sure I''d stopped each buffer before playing. It turned out to be the microphone I had sitting on a shelf, I''d forgotten to turn it off in the windows mixer and I was getting feedback .

,Jay
Wish it could have been the same problem on my machine, but it wasn''t =). Muted everything but the Wave output in the mixer, and the noise was still there.
A few ideas:

Use the WAVEFORMATX bits when setting up buffers. I think its done by default anyway but it can''t hurt (I always use it).

Check the sample rate of your sound and up it to 44k and see if the noise is still there.

Try it on another machine.

And lastly check the sound plays ok using media player.

,Jay
I suspected that the format of the snare-wav which I use for testing purposes had something to do with it, so I checked it out. Turns out that it had some strange format, 4Bit 33 KHz or something. When I play a "normal" formated wav, e.g. 16bit, 44kHz, it plays fine... so it seems that although the LoadSoundFromFile sets up the buffer automatically, it doesn''t like certain formats(?).

Thanks for the help Jason!
Also, you may be using the debug version of DX, which purposely clears all buffers to contain a static sound when created.

Jim Adams


Jim Adams
home.att.net/~rpgbook
Author, Programming Role-Playing Games with DirectX
Yes, I became aware of that when checking MSDN. I know that I have installed the debug version before, but a while ago I installed the retail one on top of it. That should have wiped out all the debug versions of the files, but when I start up DXDiag I can see there are still about 10 dx-related files that are still debug versions. Another thing I don''t know how to fix =)

Daniel
Provided you have the debug version installed (SDK), if you go into control panel and open up the directx icon you can switch between retail and debug dll's by a mouse click.

,Jay

Edit: Also when you run directx install, it first checks the existing version and only installs if its a later number. Retail/debug may be the same, I'm not sure, but it would explain your symptons.

[edited by - Jason Zelos on May 5, 2002 12:42:13 PM]
The option to switch between debug-retail versions are available to most of the DirectX components, but not DirectSound... and the "Debug Output Level" slider is there, which would mean that DirectSound is running with debug dlls, right? Looks like something I will have to remedy =).
Well, figured out what the problem really was. The files that produced the static noise sounds where saved in Microsoft ADPCM (whatever that is) and DirectSound obviously doesn''t like it very much. Switching to regular PCM format removes the noise and it plays perfectly.

Thanks for all the help!

Daniel

This topic is closed to new replies.

Advertisement