kcat / openal-soft

OpenAL Soft is a software implementation of the OpenAL 3D audio API.
Other
2.2k stars 532 forks source link

Failed to open capture using example code. #300

Open antithing opened 5 years ago

antithing commented 5 years ago

Hi, and thank you for making this code available. I am trying to record from the Line in or Mic port and am failing. I build the libs and examples. I run the openal-info.exe application. It prints:

Microsoft Windows [Version 10.0.16299.15]
(c) 2017 Microsoft Corporation. All rights reserved.

X:\dev\sandbox_bsharp\timecode\2019\openal-soft-master\build\Release>openal-info.exe
Available playback devices:
    OpenAL Soft on Speakers / Headphones (Realtek Audio)
    OpenAL Soft on DELL U2414H (NVIDIA High Definition Audio)
    OpenAL Soft on DELL U2414H (NVIDIA High Definition Audio) #2
Available capture devices:
    OpenAL Soft on Line In (Realtek Audio)
Default playback device: OpenAL Soft on Speakers / Headphones (Realtek Audio)
Default capture device: OpenAL Soft on Line In (Realtek Audio)
ALC version: 1.1

** Info for device "OpenAL Soft on Speakers / Headphones (Realtek Audio)" **
ALC version: 1.1
ALC extensions:
    ALC_ENUMERATE_ALL_EXT, ALC_ENUMERATION_EXT, ALC_EXT_CAPTURE,
    ALC_EXT_DEDICATED, ALC_EXT_disconnect, ALC_EXT_EFX,
    ALC_EXT_thread_local_context, ALC_SOFT_device_clock, ALC_SOFT_HRTF,
    ALC_SOFT_loopback, ALC_SOFT_output_limiter, ALC_SOFT_pause_device
Available HRTFs:
    Built-In 44100hz
    Built-In 48000hz
OpenAL vendor string: OpenAL Community
OpenAL renderer string: OpenAL Soft
OpenAL version string: 1.1 ALSOFT 1.19.1
OpenAL extensions:
    AL_EXT_ALAW, AL_EXT_BFORMAT, AL_EXT_DOUBLE, AL_EXT_EXPONENT_DISTANCE,
    AL_EXT_FLOAT32, AL_EXT_IMA4, AL_EXT_LINEAR_DISTANCE, AL_EXT_MCFORMATS,
    AL_EXT_MULAW, AL_EXT_MULAW_BFORMAT, AL_EXT_MULAW_MCFORMATS, AL_EXT_OFFSET,
    AL_EXT_source_distance_model, AL_EXT_SOURCE_RADIUS, AL_EXT_STEREO_ANGLES,
    AL_LOKI_quadriphonic, AL_SOFT_block_alignment, AL_SOFT_deferred_updates,
    AL_SOFT_direct_channels, AL_SOFTX_effect_chain, AL_SOFTX_events,
    AL_SOFTX_filter_gain_ex, AL_SOFT_gain_clamp_ex, AL_SOFT_loop_points,
    AL_SOFTX_map_buffer, AL_SOFT_MSADPCM, AL_SOFT_source_latency,
    AL_SOFT_source_length, AL_SOFT_source_resampler, AL_SOFT_source_spatialize
Available resamplers:
    Nearest
    Linear *
    Cubic
    11th order Sinc
    23rd order Sinc
EFX version: 1.0
Max auxiliary sends: 2
Supported filters:
    Low-pass, High-pass, Band-pass
Supported effects:
    EAX Reverb, Reverb, Chorus, Distortion, Echo, Flanger, Frequency Shifter,
    Pitch Shifter, Ring Modulator, Autowah, Compressor, Equalizer,
    Dedicated Dialog, Dedicated LFE

I then want to run alrecord.exe, so i launch a cmd and run:

alrecord.exe -device "OpenAL Soft on Line In (Realtek Audio)"

and i see:

AL lib: (EE) Failed to initialize audio client: 0x80070057 Failed to open OpenAL Soft on Line In (Realtek Audio), Signed 16-bit, Mono, 44100hz (32768 samples)

I am able to listen to this device in another application, so the audio input is fine. What can i look at to get this working?

Thank you.

kcat commented 5 years ago

Which commit is this built from? 0x80070057 is E_INVALIDARG, and according to MSDN that error is returned when:

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.

Neither AUDCLNT_STREAMFLAGS_LOOPBACK or AUDCLNT_STREAMFLAGS_CROSSPROCESS are set, so it's not that, leaving only pFormat. There used to be an issue where certain audio devices don't like the WAVE_FORMAT_EXTENSIBLE tag even when it described an otherwise supported format, but that was fixed with commit 657978c732d3ed379ff4e65891fe21140433a248. It's returning exactly what IAudioClient::IsFormatSupported gave back. Can you provide a full trace log? Set the ALSOFT_LOGLEVEL env var to 3 to have the lib print more information.

antithing commented 5 years ago

Hi, thanks for getting back to me. This is using the current code, downloaded from git this morning.

I have added `ALSOFT_LOGLEVEL=3`` to the preprocessor args, but i see the same error msg:

AL lib: (EE) Failed to initialize audio client: 0x80070057
Failed to open OpenAL Soft on Microphone (Realtek Audio), Signed 16-bit, Mono, 44100hz (32768 samples)

Thank you for your time!

kcat commented 5 years ago

I have added `ALSOFT_LOGLEVEL=3`` to the preprocessor args

It's an environment variable, not a build option. Run:

set ALSOFT_LOGLEVEL=3 alrecord.exe -device "OpenAL Soft on Line In (Realtek Audio)"

antithing commented 5 years ago

Okay! That gives me:

alrecord.exe -device "OpenAL Soft on Line In (Realtek Audio)"
AL lib: (II) Initializing library v1.19.1-unknown UNKNOWN
AL lib: (II) Supported backends: wasapi, dsound, winmm, null, wave
AL lib: (II) Loading config C:\Users\bsh\AppData\Roaming\alsoft.ini...
AL lib: (II) Got binary: X:\dev\bsh\timecode\2019\openal-soft-master\build\Release, alrecord.exe
AL lib: (II) Loading config X:\dev\bsh\timecode\2019\openal-soft-master\build\Release\alsoft.ini...
AL lib: (II) Key disable-cpu-exts not found
AL lib: (II) Detected max CPUID function: 0xf (ext. 0x80000008)
AL lib: (II) Vendor ID: ""
AL lib: (II) Name: "Intel(R) Xeon(R) CPU E5-2667 v3 @ 3.20GHz"
AL lib: (II) Extensions: +SSE +SSE2 +SSE3 +SSE4.1
AL lib: (II) Key rt-prio not found
AL lib: (II) Key resampler not found
AL lib: (II) Key trap-al-error not found
AL lib: (II) Key trap-alc-error not found
AL lib: (II) Key reverb/boost not found
AL lib: (II) Key drivers not found
AL lib: (II) Starting message thread
AL lib: (II) Message thread initialization complete
AL lib: (II) Starting message loop
AL lib: (II) Initialized backend "wasapi"
AL lib: (II) Added "wasapi" for playback
AL lib: (II) Added "wasapi" for capture
AL lib: (II) Key excludefx not found
AL lib: (II) Key default-reverb not found
AL lib: (II) Capture format: Mono, Signed Short, 44100hz, 32768 / 32768 buffer
AL lib: (II) Got message "Enumerate Capture" (0x0006, this=000002264777C068)
AL lib: (II) Got device "OpenAL Soft on Line In (Realtek Audio)", "{70F58939-F82E-4155-AEE3-A7598D3278B0}", "{0.0.1.00000000}.{70f58939-f82e-4155-aee3-a7598d3278b0}"
AL lib: (II) Got message "Open Device" (0x0000, this=000002264777C068)
AL lib: (II) Got message "Reset Device" (0x0001, this=000002264777C068)
AL lib: (II) Created Float stereo-to-mono converter
AL lib: (II) Created converter for Mono format, dst: Signed Short 44100hz, src: Float 48000hz
AL lib: (EE) Failed to initialize audio client: 0x80070057
AL lib: (WW) Error generated on device 0000000000000000, code 0xa004
AL lib: (II) Freeing device 0000022647771FB0
AL lib: (II) Got message "Close Device" (0x0004, this=000002264777C068)
Failed to open OpenAL Soft on Line In (Realtek Audio), Signed 16-bit, Mono, 44100hz (32768 samples)
kcat commented 5 years ago

That's certainly odd, I'm not seeing anything really abnormal. Can you try with the latest master? It probably won't fix the issue, but I added some additional traces that may help give a bit more insight into what it's complaining about.

antithing commented 5 years ago

Thank you! Pulling down the latest master just now and building gives me:

alrecord.exe -device "OpenAL Soft on Line In (Realtek Audio)"
AL lib: (II) Initializing library v1.19.1-unknown UNKNOWN
AL lib: (II) Supported backends: wasapi, dsound, winmm, null, wave
AL lib: (II) Loading config C:\Users\bsh\AppData\Roaming\alsoft.ini...
AL lib: (II) Got binary: X:\dev\bsh\timecode\2019\openal-soft-master2\openal-soft-master\build\Release, alrecord.exe
AL lib: (II) Loading config X:\dev\bsh\timecode\2019\openal-soft-master2\openal-soft-master\build\Release\alsoft.ini...
AL lib: (II) Key disable-cpu-exts not found
AL lib: (II) Detected max CPUID function: 0xf (ext. 0x80000008)
AL lib: (II) Vendor ID: ""
AL lib: (II) Name: "Intel(R) Xeon(R) CPU E5-2667 v3 @ 3.20GHz"
AL lib: (II) Extensions: +SSE +SSE2 +SSE3 +SSE4.1
AL lib: (II) Key rt-prio not found
AL lib: (II) Key resampler not found
AL lib: (II) Key trap-al-error not found
AL lib: (II) Key trap-alc-error not found
AL lib: (II) Key reverb/boost not found
AL lib: (II) Key drivers not found
AL lib: (II) Starting message thread
AL lib: (II) Message thread initialization complete
AL lib: (II) Starting message loop
AL lib: (II) Initialized backend "wasapi"
AL lib: (II) Added "wasapi" for playback
AL lib: (II) Added "wasapi" for capture
AL lib: (II) Key excludefx not found
AL lib: (II) Key default-reverb not found
AL lib: (II) Capture format: Mono, Signed Short, 44100hz, 32768 / 32768 buffer
AL lib: (II) Got message "Enumerate Capture" (0x0006, this=00000193271330F8)
AL lib: (II) Got device "OpenAL Soft on Line In (Realtek Audio)", "{70F58939-F82E-4155-AEE3-A7598D3278B0}", "{0.0.1.00000000}.{70f58939-f82e-4155-aee3-a7598d3278b0}"
AL lib: (II) Got message "Open Device" (0x0000, this=00000193271330F8)
AL lib: (II) Got message "Reset Device" (0x0001, this=00000193271330F8)
AL lib: (II) Requesting capture format:
    FormatTag      = 0xfffe
    Channels       = 1
    SamplesPerSec  = 44100
    AvgBytesPerSec = 88200
    BlockAlign     = 2
    BitsPerSample  = 16
    Size           = 22
    Samples        = 16
    ChannelMask    = 0x4
    SubFormat      = {00000001-0000-0010-8000-00aa00389b71}
AL lib: (II) Got capture format:
    FormatTag      = 0xfffe
    Channels       = 2
    SamplesPerSec  = 48000
    AvgBytesPerSec = 384000
    BlockAlign     = 8
    BitsPerSample  = 32
    Size           = 22
    Samples        = 32
    ChannelMask    = 0x3
    SubFormat      = {00000003-0000-0010-8000-00aa00389b71}
AL lib: (II) Created Float stereo-to-mono converter
AL lib: (II) Created converter for Mono format, dst: Signed Short 44100hz, src: Float 48000hz
AL lib: (EE) Failed to initialize audio client: 0x80070057
AL lib: (WW) Error generated on device 0000000000000000, code 0xa004
AL lib: (II) Freeing device 0000019327143A40
AL lib: (II) Got message "Close Device" (0x0004, this=00000193271330F8)
Failed to open OpenAL Soft on Line In (Realtek Audio), Signed 16-bit, Mono, 44100hz (32768 samples)
kcat commented 5 years ago

I'm pretty stumped. The format looks fine, but it won't accept the format it just said is supported. I don't suppose there's debug mmdevapi/wasapi libs that can provide more information about why that call is failing? What if you try different parameters (just for testing purposes, e.g. try using the device's real format, 48khz AL_FORMAT_STEREO_FLOAT32)?

antithing commented 5 years ago

I tried:

alrecord.exe -device "OpenAL Soft on Microphone (Realtek Audio)" -r 48000 -b 32

and i get:

AL lib: (II) Initializing library v1.19.1-unknown UNKNOWN
AL lib: (II) Supported backends: wasapi, dsound, winmm, null, wave
AL lib: (II) Loading config C:\Users\bsh\AppData\Roaming\alsoft.ini...
AL lib: (II) Got binary: X:\dev\bsh\timecode\2019\openal-soft-master2\openal-soft-master\build\Release, alrecord.exe
AL lib: (II) Loading config X:\dev\bsh\timecode\2019\openal-soft-master2\openal-soft-master\build\Release\alsoft.ini...
AL lib: (II) Key disable-cpu-exts not found
AL lib: (II) Detected max CPUID function: 0xf (ext. 0x80000008)
AL lib: (II) Vendor ID: ""
AL lib: (II) Name: "Intel(R) Xeon(R) CPU E5-2667 v3 @ 3.20GHz"
AL lib: (II) Extensions: +SSE +SSE2 +SSE3 +SSE4.1
AL lib: (II) Key rt-prio not found
AL lib: (II) Key resampler not found
AL lib: (II) Key trap-al-error not found
AL lib: (II) Key trap-alc-error not found
AL lib: (II) Key reverb/boost not found
AL lib: (II) Key drivers not found
AL lib: (II) Starting message thread
AL lib: (II) Message thread initialization complete
AL lib: (II) Starting message loop
AL lib: (II) Initialized backend "wasapi"
AL lib: (II) Added "wasapi" for playback
AL lib: (II) Added "wasapi" for capture
AL lib: (II) Key excludefx not found
AL lib: (II) Key default-reverb not found
AL lib: (II) Capture format: Mono, Float, 48000hz, 32768 / 32768 buffer
AL lib: (II) Got message "Enumerate Capture" (0x0006, this=000001BE289E1288)
AL lib: (II) Got device "OpenAL Soft on Microphone (Realtek Audio)", "{9D8F7A57-81C4-411F-ABD2-E8B81D765710}", "{0.0.1.00000000}.{9d8f7a57-81c4-411f-abd2-e8b81d765710}"
AL lib: (II) Got message "Open Device" (0x0000, this=000001BE289E1288)
AL lib: (II) Got message "Reset Device" (0x0001, this=000001BE289E1288)
AL lib: (II) Requesting capture format:
    FormatTag      = 0xfffe
    Channels       = 1
    SamplesPerSec  = 48000
    AvgBytesPerSec = 192000
    BlockAlign     = 4
    BitsPerSample  = 32
    Size           = 22
    Samples        = 32
    ChannelMask    = 0x4
    SubFormat      = {00000003-0000-0010-8000-00aa00389b71}
AL lib: (EE) Failed to initialize audio client: 0x80070057
AL lib: (WW) Error generated on device 0000000000000000, code 0xa004
AL lib: (II) Freeing device 000001BE28A0BFB0
AL lib: (II) Got message "Close Device" (0x0004, this=000001BE289E1288)
Failed to open OpenAL Soft on Microphone (Realtek Audio), Float 32-bit, Mono, 48000hz (32768 samples)

I have also tried stereo, and I get the same. Can you think of anything else that I can try? It's weird. Thanks!

antithing commented 5 years ago

... Using, for example, the inbuilt windows voice recorder app, it works fine.

kcat commented 5 years ago

Unfortunately I'm out of ideas. The only reason it should be getting this error is due to an unsupported format, but the format given is one it said is supported. Any other reason would have to be undocumented, but nothing looks out of the ordinary so I wouldn't know where to begin. All I can suggest to try at this point is using smaller or larger buffer sizes.

Shempp commented 1 year ago

Hello! Just for information, suddenly it will help someone: the error above was caused by an antivirus in the system in my case (Kaspersky Endpoint Security). https://stackoverflow.com/questions/46281593/iaudioclientinitialize-returns-e-invalidarg-0x80070057-2147024809