filoe / cscore

An advanced audio library, written in C#. Provides tons of features. From playing/recording audio to decoding/encoding audio streams/files to processing audio data in realtime (e.g. applying custom effects during playback, create visualizations,...). The possibilities are nearly unlimited.
Other
2.22k stars 458 forks source link

Implement pure c# resampler #330

Open digimezzo opened 6 years ago

digimezzo commented 6 years ago

I'm using CSCore.FFMpeg (CSCore version 1.2.1.2) to play audio in Dopamine. A user notified inability to playback mp3's on Windows 10 Enterprise N 2016 LTSB (which is a Windows 10 edition without Media Foundation). I expected CSCore.FFMpeg to play mp3's fine, as it is not using MediaFoundation decoder. Please correct me if I'm wrong. Is CSCore.FFMpeg supposed to be able to play audio without Media Foundation or not? (This is more a question than a bug report)

This is the stack trace when trying to play a mp3 file, using FFMpegDecoder on Windows 10 Enterprise N 2016 LTSB:

Shuffle=False. Exception: 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)).. StackTrace: at CSCore.DMO.WMResampler..ctor() at CSCore.DSP.DmoResampler.Initialize(WaveFormat inputformat, WaveFormat outputformat) at CSCore.DSP.DmoResampler..ctor(IWaveSource source, WaveFormat outputFormat, Boolean ignoreBaseStreamPosition) at CSCore.SoundOut.WasapiOut.SetupWaveFormat(IWaveSource source, AudioClient audioClient) at CSCore.SoundOut.WasapiOut.InitializeInternal() at CSCore.SoundOut.WasapiOut.Initialize(IWaveSource source) at Dopamine.Core.Audio.CSCorePlayer.InitializeSoundOut(IWaveSource soundSource) in C:\Users\rapha\Source\Repos\Dopamine\Dopamine.Core\Audio\CSCorePlayer.cs:line 360 at Dopamine.Core.Audio.CSCorePlayer.Play(String filename) in C:\Users\rapha\Source\Repos\Dopamine\Dopamine.Core\Audio\CSCorePlayer.cs:line 235 at Dopamine.Core.Audio.CSCorePlayer.Play(String filename, MMDevice outputDevice) in C:\Users\rapha\Source\Repos\Dopamine\Dopamine.Core\Audio\CSCorePlayer.cs:line 243 at Dopamine.Services.Playback.PlaybackService.<>c__DisplayClass190_0.b__0() in C:\Users\rapha\Source\Repos\Dopamine\Dopamine.Services\Playback\PlaybackService.cs:line 1115 at System.Threading.Tasks.Task.Execute()

digimezzo commented 6 years ago

Ok, this is obviously caused because I'm using WasapiOut, which calls the DmoResampler(...) constructor in SetupWaveFormat(...). The DmoResampler constructor in turn calls WMResampler constructor which tries to access a COM interface which is not available on that edition of Windows.

Apparently, DirectsoundOut plays sound fine on such crippled edition of Windows.

filoe commented 6 years ago

Sorry for the late response. Was injured ... Yes, you're right. The DmoResampler is used the resample the audio stream to the target samplerate. It would be an option to use a native c# resampler which is currently not supported. Do you have any troubles with it?

digimezzo commented 6 years ago

Hi @filoe, no problem. I hope you are well now. I was trying to make my audio player compatible with Windows editions which don't have the Media Feature Pack installed, the so called N Editions (mostly because users don't know they have such edition, and assume that my player is broken). I assumed that FFmpegDecoder would allow audio playback on such editions. However, when combined with WasapiOut, I bump into the DmoResampler usage. When combined with DirectSoundOut, it works on Windows N Editions. So that's a nice workaround. I use DIrectSoundOut as fallback mechanism when Media Foundation is not found.