C# - .WAV 随机高音播放
由于某种原因,当使用下面的代码片段播放 WAV 文件时,它会随机播放扭曲的声音,就像高音噪音。它不会一直发生,只是随机发生。回放越频繁,这种情况似乎就越频繁发生。下面是 WAV 属性以及我正在使用的代码片段。
WAV 属性:
比特率 - 750kbps
音频样本大小 - 16 位
通道 - 1(单声道)
音频采样率 - 44kHz
音频格式 - PCM
片段:
System.Media.SoundPlayer myPlayer = new System.Media.SoundPlayer(Captcha.Properties.Resources.sound1);
myPlayer.Play();
这是因为我播放文件的方式还是文件本身?谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
看来是音频问题。尝试另一个 WAV 文件。
Seems to be a audio problem. Try another WAV file.
你在vista上听到这个噪音吗?
我在使用 WaveOut WIN32 API 时遇到了这个问题。 PlaySound 在内部使用相同的库 (Winmm) 来播放声音。
这种噪音仅出现在某些波形文件和 Windows Vista 上(我认为 Windows 7 也是如此)。它在 XP 上运行良好。我相信这是这些 API 的新实现中的一个错误。
如果您使用 Windows Media Player 播放这些 WAV 文件,它们可以正常播放(在 Vista 上),因为我认为它使用 DirectSound API。
我现在没有解决方案,我正在考虑更改我的实现以在将来使用 DirectSound。
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.
因此,造成这种情况的原因要么是 WAV 文件本身的问题,要么是 .NET 中的错误。最有可能的是文件有问题,我将尝试使用该文件来查看是否有帮助,或者干脆使用另一个文件。谢谢大家的帮助。
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.
我过去也遇到过类似的问题,我通过更换有问题的机器的音频驱动程序来解决它。
尝试在相同条件下但在不同机器上重现该问题。
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.