syedhali / EZAudio

An iOS and macOS audio visualization framework built upon Core Audio useful for anyone doing real-time, low-latency audio processing and visualizations.
Other
4.96k stars 823 forks source link

Small Microphone Gain After "applicationDidEnterBackground" #259

Open shuyangsun opened 8 years ago

shuyangsun commented 8 years ago

I am using EZAudio for some realtime audio analysis and waveform drawing, it works great!

One of the problem I have is that when my app enters background and become active again, the gain for microphone is very small. I checked calculated RMS, those number are significantly smaller.

PS: A new instance of microphone and plot is created every time I do the analysis. I also have no code at all in "applicationDidEnterBackground" callback.

Any ideas?

hailucmg commented 8 years ago

I have the same issue. To fix this issue, I add the following code before playing and it works normally. I don't know the reason, but hope it help.

let session: AVAudioSession = AVAudioSession.sharedInstance()
do {
    try session.setCategory(AVAudioSessionCategoryPlayback)
    try session.setActive(true)
    try session.overrideOutputAudioPort(AVAudioSessionPortOverride.Speaker)
} catch {
}
shuyangsun commented 8 years ago

Thank you. I haven't tried it but I assume this code would fix the output volume issue, do you know if this would also fix input volume issue?