Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSCore.CoreAudioAPI.CoreAudioAPIException (0x80070057): IAudioClient::Initialize caused an error: 0x80070057, "The parameter is incorrect.". #272

Closed
Bahaa-Sobhy opened this issue Sep 8, 2017 · 7 comments
Labels

Comments

@Bahaa-Sobhy
Copy link

I get this error on some Laptops, not all... while the Audio settings (Sound Card options) on all Computers are one the same...
This error doesn't occur On Windows 10 , while on Windows 8.1 it occurs:
This is the thrown Exception:

CSCore.CoreAudioAPI.CoreAudioAPIException (0x80070057): IAudioClient::Initialize caused an error: 0x80070057, "The parameter is incorrect.". at CSCore.CoreAudioAPI.AudioClient.Initialize(AudioClientShareMode shareMode, AudioClientStreamFlags streamFlags, Int64 hnsBufferDuration, Int64 hnsPeriodicity, WaveFormat waveFormat, Guid audioSessionGuid) at CSCore.SoundIn.WasapiCapture.InitializeInternal() at CSCore.SoundIn.WasapiCapture.Initialize() at application.recordForm.ReadyMode() at application.recordForm.recordForm_Shown(Object sender, EventArgs e) at System.Windows.Forms.Form.OnShown(EventArgs e) at System.Windows.Forms.Form.CallShownEvent() at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme) at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj) at System.Threading.ExecutionContext.runTryCode(Object userData) at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme) at System.Windows.Forms.Control.InvokeMarshaledCallbacks()

Any clue about what might be the reason?

@filoe
Copy link
Owner

filoe commented Sep 9, 2017

Please provide at least some code which causes the error.

@Bahaa-Sobhy
Copy link
Author

Hello filoe;
The code was token from the Example "Recorder" attached with CSCore:

private void ReadyMode()
        {
            if (SelectedDevice == null)
                return;
            if(CaptureMode == CaptureMode.Capture)
                _soundIn = new WasapiCapture();
            else
                _soundIn = new WasapiLoopbackCapture();

            _soundIn.Device = SelectedDevice;
            _soundIn.Initialize();

            var soundInSource = new SoundInSource(_soundIn);
            var singleBlockNotificationStream = new SingleBlockNotificationStream(soundInSource.ToSampleSource());
            _finalSource = singleBlockNotificationStream.ToWaveSource();
            _writer = new WaveWriter(fileName, _finalSource.WaveFormat);

            byte[] buffer = new byte[_finalSource.WaveFormat.BytesPerSecond / 2];
            soundInSource.DataAvailable += (s, e) =>
            {
                int read;
                while((read = _finalSource.Read(buffer, 0, buffer.Length)) > 0)
                    _writer.Write(buffer, 0, read);
            };

            singleBlockNotificationStream.SingleBlockRead += SingleBlockNotificationStreamOnSingleBlockRead;

            _soundIn.Start();
        }

private void recordForm_Shown(object sender, EventArgs e)
{
           ReadyMode();
}

As it's shown above in the code, everything is the exact same as in the example "Recorder", except for changing the function name from "StartCapture" to "ReadyMode" and I triggered it on Form Shown instead of button Click...
The form "recordForm" is shown from a main Winform's button.

The program works just fine on Windows 10, but the exception occurs on Windows 8.1 (I didn't try the app on Windows 8 nor 7 as I don't have any PC that works with either of them)

@filoe
Copy link
Owner

filoe commented Sep 9, 2017

Are you using loopback capture? Is it reproduceable with the Recorder Sample?

@Bahaa-Sobhy
Copy link
Author

Bahaa-Sobhy commented Sep 9, 2017

I can't say Yes definitely, but I set the default capture value (property) to loopback, before the User interferes in changing the ComboBox selection (after the form_shown Completed)

internal CaptureMode CaptureMode = CaptureMode.LoopbackCapture;

Everything in the form is the same as in your "Recorder" sample

@filoe filoe added the bug label Sep 10, 2017
@filoe
Copy link
Owner

filoe commented Sep 10, 2017

Well the problem is that I can't reproduce it.
Can you try to reproduce the issue with the original Recorder sample?
Set a breakpoint here:
https://github.com/filoe/cscore/blob/master/CSCore/CoreAudioAPI/AudioClient.cs#L163
Send me as much details as possible. Most important: all details regarding the waveFormat. What type of waveFormat is it (WaveFormat, WaveFormatExtensible,...). All properties of the waveFormat.
Value of shareMode?

The details from msdn regarding your error:

Parameter pFormat points to an invalid format description; or the AUDCLNT_STREAMFLAGS_LOOPBACK flag is set but ShareMode is not equal to AUDCLNT_SHAREMODE_SHARED; or the AUDCLNT_STREAMFLAGS_CROSSPROCESS flag is set but ShareMode is equal to AUDCLNT_SHAREMODE_EXCLUSIVE.

I'm sorry but I really can't help you on this since I've got no idea. You're more or less on your own to determine what causes the error. 😒

@Bahaa-Sobhy
Copy link
Author

Well, I used your sample "Recorder" On Windows 8.1 where the Exception occurs on my application, to check whether the Exception occurs due to something in my app or anything else...

so now I open your sample "Recorder":
When I Click on "Refresh devices" button it shows me the "Stereo Mix" in the list, I select it and I click on "Start recording" button then I write the file name in the "OpenFileDIalog" window
then I get the following error:

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
CSCore.CoreAudioAPI.CoreAudioAPIException (0x80070057): IAudioClient::Initialize caused an error: 0x80070057, "The parameter is incorrect.".
   at CSCore.SoundIn.WasapiCapture.InitializeInternal()
   at CSCore.SoundIn.WasapiCapture.Initialize()
   at Recorder.MainWindow.StartCapture(String fileName)
   at Recorder.MainWindow.btnStart_Click(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.34014 built by: FX45W81RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
Recorder
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Users/administrator/Desktop/Recorder/Recorder.exe
----------------------------------------
System.Windows.Forms
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.33440 built by: FX45W81RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.33440 built by: FX45W81RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.34003 built by: FX45W81RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Core
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.33440 built by: FX45W81RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
CSCore
    Assembly Version: 1.2.1.1
    Win32 Version: 
    CodeBase: file:///C:/Users/administrator/Desktop/Recorder/CSCore.DLL
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.

If there's any other thing I can do to help you in finding the reason please let me know, because sooner or later somebody else will face the same problem on their Windows 8.1 Machine, unless they are lucky.
So I'm eager to help in this process.

@filoe
Copy link
Owner

filoe commented Oct 21, 2017

Set a breakpoint here:
https://github.com/filoe/cscore/blob/master/CSCore/CoreAudioAPI/AudioClient.cs#L163
Send me as much details as possible. Most important: all details regarding the waveFormat. What type of waveFormat is it (WaveFormat, WaveFormatExtensible,...). All properties of the waveFormat.
Value of shareMode?

Would need these information. Maybe we can find a solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants