我想选择一个特定的样本率为我的音频卡编程在c#与N音频。我的输出是独占模式下的WasapiOut。
我已经尝试了很多东西,但是什么都没成功,我到处搜索,我只找到了这个:How to Change Speaker Configuration in Windows in C#?,但是他们并没有真正找到一个正确的解决方案。
这是我的WasapiOut:
var enumerator = new MMDeviceEnumerator();
MMDevice device = enumerator.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active).FirstOrDefault(d => d.DeviceFriendlyName == name);
outputDevice = new WasapiOut(device, AudioClientShareMode.Exclusive, false,200);
我不明白的是:https://github.com/naudio/NAudio/blob/master/Docs/WasapiOut.md,它说:“如果你选择AudioClientShareMode.Exclusive,那么你就要求对声卡进行独占访问。这种方法的好处是你可以指定你想要的确切采样率”,而我没有找到如何指定采样率的方法。
如果有人知道答案,那就太好了,谢谢!
编辑:
我想我找到了一种方法
var waveFormat5 = WaveFormat.CreateIeeeFloatWaveFormat(Int32.Parse(comboBox1.Text), 2);
var test2 = new MixingSampleProvider(waveFormat5);
var audioFile = new AudioFileReader("test.wav");
var input = audioFile;
test2.ReadFully = true;
test2.AddMixerInput(new AutoDisposeFileReader(input,waveFormat5));
outputDevice.Init(test2);
以"outputDevice“作为我的WasapiOut。因此,我将ouputDevice采样率设置为我与混合样本提供程序选择的一个,然后向该混合器发送一个音频文件,这是正确的方法吗?因为我的音频采样率是44100,所以我选择将我的outputDevice采样率也提高到44100,但是当我制作outputDevice.Play()时,我听到的声音比原来的声音要快。
发布于 2019-05-04 17:02:01
我解决了我的问题,我使用AudioPlaybackEngine (https://markheath.net/post/fire-and-forget-audio-playback-with)和MixingSampleProvider,并使用try/catch来处理“输入不是相同的样本率”的消息错误。
发布于 2019-05-04 09:52:47
一旦创建了WasapiOut
实例,就可以调用传递要播放的音频的Init
。它将尝试直接使用音频的采样率(和WaveFormat
),假设声卡支持它。Usi
https://stackoverflow.com/questions/55969745
复制相似问题