vadymmarkov / Beethoven

:guitar: A maestro of pitch detection.
https://github.com/vadymmarkov
Other
824 stars 146 forks source link

Question: why is the AudioSession category 'playAndRecord', instead of just 'record' ? #76

Open HectorRicardo opened 3 years ago

HectorRicardo commented 3 years ago

Hello. First of all I want to thank you for developing such an amazing library.

I was going through the source code (inside the Source folder) to learn how the library is implemented. I understand all the source code and what's going one, except for two questions I've got:

  1. Check here. Why is the AudioSession category playAndRecord ? I mean, this library doesn't do playback at all. However, if I change the category to record only, an error is thrown at runtime.

  2. Check here. What is going on? The comment says //Check input type .... but it's clearly referencing currentRoute.outputs.... so is it input or output? I checked Apple documentation. It says this about overrideOutputAudioPort:

If your app uses the playAndRecord category, calling this method with the AVAudioSession.PortOverride.speaker option causes the system to route audio to the built-in speaker and microphone regardless of other settings. This change remains in effect only until the current route changes or you call this method again with the AVAudioSession.PortOverride.none option.

I understand the intent of the code. If we don't have any headphones (with microphone) plugged in, force the system to use the built-in mic. However, I think this falls back to these questions: 1. isn't this the default behaviour? and 2. why use category playAndRecord ?

Thanks!