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.17k stars 450 forks source link

Changing Position causes Exception #10

Closed DeadSix27 closed 9 years ago

DeadSix27 commented 9 years ago

I get a "from must not equal to." Argument exception when trying to set Position of a IWaveSource and then initializing it. I assume that mean's the position is greater than the length of the audio file, but that is impossible if I can trust my console output using this:

Console.WriteLine(startTime + "/" + soundSource.Length); soundSource.Position = startTime; soundOut.Initialize(soundSource);

Tells me: 30293491/45365376

So the position should be fine and below the max, and is definitely not equal to current position.

Any information on that?

Edit: Further research brought me to the exception source: public static ChannelMatrix GetMatrix(ChannelMask from, ChannelMask to) { if (from == to) throw new ArgumentException("from must not equal to.");

But I can't really do anything with that information, "Channel matrix" is beyond my skills.

EDIT2: Ironically, using the newest cscore from github, compiling that and in Extensions.cs adding a try/catch to the code below, catches a new issue of github-version and makes skipping work.

(ORIGINAL:

internal static byte[] ReadBytes(this IWaveSource waveSource, int count)
        {
                if (waveSource == null)
                    throw new ArgumentNullException("waveSource");
                if (count <= 0 || (count % waveSource.WaveFormat.BlockAlign) != 0)
                    throw new ArgumentOutOfRangeException("count");

                byte[] buffer = new byte[count];
                int read = waveSource.Read(buffer, 0, buffer.Length);
                if (read < count)
                    Array.Resize(ref buffer, read);
                return buffer;
}

) (NEW:

internal static byte[] ReadBytes(this IWaveSource waveSource, int count)
        {
            try
            {
                if (waveSource == null)
                    throw new ArgumentNullException("waveSource");
                if (count <= 0 || (count % waveSource.WaveFormat.BlockAlign) != 0)
                    throw new ArgumentOutOfRangeException("count");

                byte[] buffer = new byte[count];
                int read = waveSource.Read(buffer, 0, buffer.Length);
                if (read < count)
                    Array.Resize(ref buffer, read);
                return buffer;
            }
            catch(Exception e)
            {
                byte[] buffer = new byte[1];
                int read = waveSource.Read(buffer, 0, buffer.Length);
                if (read < count)
                    Array.Resize(ref buffer, read);
                return buffer;
            }
        }

)

filoe commented 9 years ago

Thanks for reporting, but I would need the stacktrace to reproduce the issue.

DeadSix27 commented 9 years ago

EDIT: CSCore was built from newest commit: https://github.com/filoe/cscore/commit/18ba6ea1da78633326f546c889b493c9e5a615e3

Here is the stacktrace:

System.ArgumentOutOfRangeException wurde nicht behandelt.
  HResult=-2146233086
  Message=Specified argument was out of the range of valid values.
Parameter name: count
  Source=CSCore
  ParamName=count
  StackTrace:
       at CSCore.Extensions.ReadBytes(IWaveSource waveSource, Int32 count) in *cscore-master\CSCore\Extensions.cs:line 295
       at CSCore.Codecs.FLAC.FlacFile.set_Position(Int64 value) in *cscore-master\CSCore\Codecs\FLAC\FlacFile.cs:line 338
       at *.MainWindow.Slider_DragCompleted(Object sender, DragCompletedEventArgs e) in **\MainWindow.xaml.cs:line 84
       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
       at System.Windows.Controls.Primitives.Thumb.OnMouseLeftButtonUp(MouseButtonEventArgs e)
       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
       at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
       at System.Windows.Input.InputManager.ProcessStagingArea()
       at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
       at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
       at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
       at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
       at System.Windows.Application.RunInternal(Window window)
       at System.Windows.Application.Run()
       at *.App.Main() in **\obj\x64\Debug\App.g.cs:line 0
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

Need anything else?

filoe commented 9 years ago

Should work fine now. Could you please test it and give me a short feedback?

DeadSix27 commented 9 years ago

EDIT: Guess the new issue is the Windows 10 64bit Issue reported by that other person. I will test it on Win7 Later and add a new edit to this post.

But for your information about the new(win10 issue) its caused by WasapiOut on my System running Windows 10 Enterprise 64bit

Original Message:

After compiling your fix @ https://github.com/filoe/cscore/commit/3c74f393ab13efb65f9005f2f2c0852dece039f2

I get the following exception, (but read edit @ top of comment):

System.ArgumentOutOfRangeException was unhandled by user code
  HResult=-2146233086
  Message=Specified argument was out of the range of valid values.
Parameter name: value
  Source=CSCore
  ParamName=value
  StackTrace:
       at CSCore.SoundOut.WasapiOut.set_Latency(Int32 value) in *\cscore-master\CSCore\SoundOut\WasapiOut.cs:line 176
       at CSCore.SoundOut.WasapiOut.InitializeInternal() in *\cscore-master\CSCore\SoundOut\WasapiOut.cs:line 570
       at CSCore.SoundOut.WasapiOut.Initialize(IWaveSource source) in *\cscore-master\CSCore\SoundOut\WasapiOut.cs:line 215
       at *.MainWindow.player_DoWork(Object sender, DoWorkEventArgs e) in *\MainWindow.xaml.cs:line 179
       at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)
       at System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)
  InnerException: 
filoe commented 9 years ago

This is a known issue on windows 10 caused by completely different behaviour of wasapi. Going to release a fix for windows 10 soon. But would still like to know why wasapi got this new, weird behaviour.

Please give me some feedback regarding the flac issue.

DeadSix27 commented 9 years ago

Ok, I tested it on Windows 8.1 64bit (N + with media pack installed) works fine now after your fix.

filoe commented 9 years ago

Thanks. Issue #11 should also be fixed.