NAudio 和 DirectX 12

NAudio and DirectX 12

我在使用 NAudio 时收到 DirectX 源错误。我对 DirectX 不是很了解,所以希望得到一些指点。

在安装了 DirectX 12 的 windows 10 PC 上初始化 NAudio 时收到的错误是:

NAudio.Dmo.DmoResampler..ctor System.Runtime.InteropServices.COMException: Retrieving the COM class factory for component with CLSID {F447B69E-1884-4A7E-8055-346F74D6EDB3} failed due to the following error: 80040154 Class not registered (Exception from >HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

NAudio.Dmo.DmoResampler..ctor

NAudio.Wave.ResamplerDmoStream..ctor IWaveProvider inputProvider, WaveFormat outputFormat

NAudio.Wave.WasapiOut.Init IWaveProvider waveProvider

Sound.Support.AudioPlaybackEngine..ctor MMDevice device, Int32 sampleRate, Int32 channelCount

Sound.Manager.PerformInitialization

Analyze.ViewModels.ApplicationViewModel.InitSoundManager

好的,很明显有些 COM 对象没有注册,那怎么办?

这是调用 NAudio 的代码:

    public AudioPlaybackEngine(MMDevice device, int sampleRate = 44100, int channelCount = 2)
    {
        Device = device;

        mOutputDevice = new WasapiOut(device,
                                      AudioClientShareMode.Shared,
                                      true,
                                      200);

        mMixer = new MixingSampleProvider(WaveFormat.CreateIeeeFloatWaveFormat(sampleRate, channelCount))
                {
                    ReadFully = true
                };

        mMixer.MixerInputEnded += OnMixerInputEnded;

        mOutputDevice.Init(mMixer);
        mOutputDevice.Play();
    }

第一次调用就出错

这在 DirectX 11 和任何平台上都可以正常工作

有什么想法吗?

Windows 10 同时支持 DirectX 9.0c 到 DirectX 12。这可能更好地考虑媒体基础问题。

该 GUID ({F447B69E-1884-4A7E-8055-346F74D6EDB3}) 似乎是重采样器 DMO(DirectX 媒体对象)。 DMOs were part of the legacy DirectShow technologies which are primarily used today by the Media Foundation APIs--I won't get into the tortured history of how "DirectShow" originally called "ActiveMovie" ended up being branded DirectX, but needless to say the technology was removed 来自 2005 年的 DirectX SDK。

因此,我的问题是:您使用的是 Windows 10 的 N 版还是 KN 版? 如果是,则默认情况下不包含媒体基础.您必须通过 Restore Pack. See Who moved my Windows Media Cheese?.

安装它

You can try using this sample program to ensure the GUID is present on your machine.

如果您正在开发通用 Windows 平台 (UWP) 应用程序而不是经典的 Win32 桌面应用程序,则可能还会有一些对可用转换的限制可能会影响您。