naudio / NAudio

Audio and MIDI library for .NET
MIT License
5.48k stars 1.1k forks source link

Can we get OPUS Support anytime soon? #674

Open PlastMan420 opened 4 years ago

markheath commented 4 years ago

If you want opus support in .NET the only managed port I'm aware of is concentus which sadly hasn't been updated in a while. Otherwise the best option is probably to create PInvoke wrappers for a native Opus library

prajaybasu commented 4 years ago

FYI, modern Windows 10 installs ship with an Opus decoder MFT (CLSID 63E17C10-2D43-4C42-8FE3-8D8B63E46A6A)

rampaa commented 1 year ago

Windows 10 does come with an Opus decoder but when I try to read an Opus file with StreamMediaFoundationReader I get the following exception: System.Runtime.InteropServices.COMException: The byte stream type of the given URL is unsupported. (0xC00D36C4)'.

Here's the code that gives me the aforementioned exception: IWaveProvider waveProvider = new StreamMediaFoundationReader(new MemoryStream(audio)).

@markheath do you have any idea as to why I get the aforementioned exception? And do you have any tips to resolve it?

markheath commented 1 year ago

Do you need to use StreamMediaFoundationReader? Can you provide the path or a URL instead - that tends to work better. I think the file extension is useful information to know which container format the audio is in.

rampaa commented 1 year ago

Do you need to use StreamMediaFoundationReader?

Yes because I need to check the hash of the audio before playing it so I read it into a byte array first.

Nonetheless, I've tried it with MediaFoundationReader as well just to see if it works but unfortunately I still get the The byte stream type of the given URL is unsupported. (0xC00D36C4)' exception.

I think the file extension is useful information to know which container format the audio is in.

The file extension is .opus. Here's a sample audio file: https://gofile.io/d/6lkHcL

markheath commented 1 year ago

Yes, doesn't seem that MFCreateSourceReaderFromURL works with the .opus extension. If I had to guess I think maybe using MFCreateSourceResolverFromURL and experimenting with flags like MF_RESOLUTION_CONTENT_DOES_NOT_HAVE_TO_MATCH_EXTENSION_OR_MIME_TYPE might create an IMFSource, and then perhaps passing that into MFCreateSourceReaderFromMediaSource would work. Afraid I don't really have the time to work through all that at the moment though