Closed xloc closed 1 year ago
Thanks for bringing this up.
In order to find the source of this issue, can you describe your noise in more detail? I.e., is it white noise on top of the normal audio, or do you get completely distorted values? You can also send me some raw audio data from each microphone.
Aso, for reference, can you please compare the audio from your built-in vs. your AirPods microphones through a different recording tool?
That responds was fast. Thank you so much!
The noise is more of a white noise, and it doesn't seem to relate to the input in any way. No matter how loud I go, the waveform doesn't seem to related to my input pattern.
Let me first share a few snapshots of the demo app. I will record some raw audio and do the comparison later.
This is the noise, from the built-in mic:
This is normal audio, from the AirPods:
yes, it looks like white noise.
On another note, when you start recording, the app should print the audio configuration it is recording with; can you check whether this config looks sane? The MacOS part should be able to handle the default example config but since I didn't write that part I cannot be sure.
One more question: how many microphones does your MacBook have built in? It may be possible that the app tries to record in mono while MacOS supplies stereo audio.
Thanks for the suggestion! Yes, the config looks the same
AirPods mic
[Optional(0), Optional(44100), Optional(16), Optional(2)]
flutter: Start Listening to the microphone, sample rate is 24000.0, bit depth is 32, bufferSize: 4096
Built-in mic
Optional(0), Optional(44100), Optional(16), Optional(2)]
flutter: Start Listening to the microphone, sample rate is 24000.0, bit depth is 32, bufferSize: 4096
I noticed the sample rate and bit depth are different from what I set. Is that wrong?
I also recorded the stream and made some plots: Archive.zip
The files without extension are the raw binary files. I recorded with sample rate 44100
and ENCODING_PCM_16BIT
. The wav files are parsed audio.
In the AirPods audio (which I was thinking is good), although can hear what I said, the sound is also overlapped with a strong white noise. Please see the following spectrogram and wave plots
From AirPods:
From built-in mic:
I'm not too sure about the config parts. I'm not a mac developer, I only merged the mac-native implementation into the repo. From what I can tell, MacOS does not always respect the user-provided configuration and uses its own preferred settings instead. As such, assume that the config that was printed by the example application, i.e., the latter config, to be the real one that the audio was recorded with.
I suggest you look at different configurations for sample rate and bit depth, see how this changes the actual used config, and whether this affects the white noise in any way.
Additionally, examine the audio data as if recorded from 24 kHz and 32 bit depth, or 24 kHz and float bit depth, and see if that makes more sense to you.
Also, I won't be able to analyse the audio data in depth until in about two weeks, sorry for that.
No worry. The knowledge you provided is already very helpful to me. I appreciated it.
I still can't figure out why the noise is here. But, you are right. The sample rate and bit depth indeed differ from what I set them to be. I read through the native swift code. In fact, the bit depth and sample rate are never used. AVCaptureAudioDataOutputSampleBufferDelegate
doesn't allow the user to config these settings.
However, that doesn't explain why I got white noise when I use the built-in mic. I tested with all possible ways to parse the data. None of them worked.
Instead, I found a different native API AVAudioEngine
and it worked. Now I can get valid audio from both built-in and wireless earphones. It looks like this:
Do you want me to submit a PR for it?
Looks great! Please open a PR; I'll merge and publish it once I'm back to office. I highly appreciate your patience and efforts; this is what keeps such voluntary open source projects alive!
PR created. I'm also happy to contribute to an open source project to make it better. Thank you for your kind support these days!
Thanks for bringing us a microphone library that works across multiple platforms!
I got a strange problem:
I used the demo recorder app for all the testing. So, there shouldn't be any int16 conversion mistakes.