views:

482

answers:

4

For some reason, when a WAV file is played back using the snippet below, it randomly plays back screwy, like a high pitch noise. It doesn't happen all the time, just randomly. It seems to happen more often when it is played back more frequently. The WAV properties are below along with the code snippet I am using.

WAV Properties:

Bit Rate - 750kbps
Audio Sample Size - 16 bit
Channels - 1 (mono)
Audio Sample Rate - 44kHz
Audio Format - PCM

Snippet:

System.Media.SoundPlayer myPlayer = new System.Media.SoundPlayer(Captcha.Properties.Resources.sound1);
myPlayer.Play();

Is this because of the way I am playing the file or the file itself? Thank you.

A: 

Do you get this noise on vista?

I've encounter this problem using the WaveOut WIN32 API. PlaySound uses the same library (Winmm) internally to play the sound.

This noise appears only on certain wave files, and on windows vista (and I think windows 7 too). It works fine on XP. I believe it's a bug in the new implementation of those APIs. If you use windows media player to play those WAV files they play fine (on vista) because I think it uses DirectSound APIs.

I've got no solution for this right now and I am thinking of changing my implementation to use DirectSound in the future.

dtroy
This is currently on Windows XP 32-bit.
Nate Shoffner
A: 

So the reason for this either seems to be a problem with the WAV file itself or a bug in .NET. Most likely it is a problem with the file and I'll either try working with the file to see if that helps or just use another file altogether. Thank you for your help everyone.

Nate Shoffner
yeah. try to play it with external players to see if you still get the noise
dtroy
I just played it for about 8 minutes straight in Windows Media Player 11 and in Songbird and there were no problems.
Nate Shoffner
You can check out this project: http://naudio.codeplex.com/the sample let's you play the audio with different APIs. it might help you pin point the API you're having a problem with. A work around might be using DirectSound for example.
dtroy
+1  A: 

Seems to be a audio problem. Try another WAV file.

A: 

I had similar problems in the past and I solved it by replacing the audio drivers of the offending machine.

Try reproducing the problem in identical conditions but in a different machine.

Padu Merloti