bastibe / SoundCard

A Pure-Python Real-Time Audio Library
https://soundcard.readthedocs.io
BSD 3-Clause "New" or "Revised" License
689 stars 70 forks source link

Assertion error when opening specific mic #93

Closed Bob-Thomas closed 3 years ago

Bob-Thomas commented 4 years ago

Just noticed when I try to open the "chat" channel on my headphones through loopback I get greeted with a big assertion error

assert pPropVariantBlob[0].blob.cbSize == 40

Don't really have a clue what it means or how to properly handle this.

@bastibe have you seen this before? it works perfect on all my other speakers but when I use this one it raises an error

bastibe commented 4 years ago

I have never seen this before. Could you check the actual value of cbSize? It should be fine as long as it is at least 40. As far as I can tell, >= 40 might actually be a better implementation. But I am not at all experienced with this API.

shawnc722 commented 3 years ago

I'm having the same error when I print the output of all_microphones(). The cbSize is 18, and the pBlobData's repr is <cdata 'unsigned char *' 0x000001AE8E9CC890>. The error only occurs when I try to interact with this mic, my other inputs work fine. Please let me know if there's any other data I can find or anything that'd be helpful.

bastibe commented 3 years ago

Does it work if you uncomment the assert line?

shawnc722 commented 3 years ago

I won’t be able to check on this for a few days, but as soon as I do I’ll post the results

shawnc722 commented 3 years ago

When I run it without the assert line, I get this traceback:

Traceback (most recent call last):
  File "<pyshell#6>", line 1, in <module>
    with si.recorder(48000) as mic:
  File "C:\Users\shawn\AppData\Local\Programs\Python\Python38\lib\site-packages\soundcard\mediafoundation.py", line 467, in recorder
    return _Recorder(self._audio_client(), samplerate, channels, blocksize, self.isloopback, exclusive_mode)
  File "C:\Users\shawn\AppData\Local\Programs\Python\Python38\lib\site-packages\soundcard\mediafoundation.py", line 505, in __init__
    assert ppMixFormat[0][0].Format.wFormatTag == 0xFFFE
AssertionError

The only value of ppMixFormat I can get is <cdata 'WAVEFORMATEXTENSIBLE * *' owning 8 bytes>, which doesn't seem particularly useful to me at least. Edit: I forgot to mention, uncommenting the assert fixed the original problem and all_microphones() works perfectly now. I got this problem while testing if the newly usable mic would work with this fix.

bastibe commented 3 years ago

The error message seems to indicate that your sound card does not return float values for whatever reason. I have heard stories of audio driver issues on Windows that sound vaguely like this one. What sort of microphone is this?

shawnc722 commented 3 years ago

It’s the microphone array of intel’s realsense RGBD camera. It connects via USB, if that’s relevant at all.

bastibe commented 3 years ago

Without more information on the behavior of this soundcard and its interaction with WASAPI, I'm afraid I won't be of much help. In theory, it would certainly be possible to add the relevant casts in soundcard to deal with non-float audio data. But being that this is the very first time I have ever heard of such a thing, I am doubtful it is worth the effort.

But, pull requests are welcome... Sorry to not be able to help.

shawnc722 commented 3 years ago

I did a quick check on Linux, and the same mic works fine and records float values. Since this looks like a windows specific problem, probably caused by Microsoft and hopefully fixed by them, I agree it’s likely not worth the time. Thanks for your suggestions!

bastibe commented 3 years ago

I've heard a lot of bad things about third-party audio drivers on Windows. So it's probably not Microsoft's fault directly, but some third party. Sadness.