due to result of wrong sample rate unable to merge audio with my cmsamplebuffer
Can you supply a sample project and/or make the necessary fixes to the open source microphone code?
@aure
My app is also having the same problem that causing recordings have crackling sound.
After poking around for a while, I found temporary solution, hope this will help you to fix the root problem:
var inputFormat = AudioKit.engine.inputNode.outputFormat(forBus: 0)
DDLogDebug("wrong rate---> session rate: \(AVAudioSession.sharedInstance().sampleRate) input rate: \(inputFormat.sampleRate)")
manager.mic = AKMicrophone()
inputFormat = AudioKit.engine.inputNode.outputFormat(forBus: 0)
AKSettings.sampleRate = inputFormat.sampleRate
AKSettings.channelCount = inputFormat.channelCount
DDLogDebug("correct rate---> session rate: \(AVAudioSession.sharedInstance().sampleRate) input rate: \(inputFormat.sampleRate) aksettings rate:\(AKSettings.sampleRate)")
output:
2019-01-29 18:54:50:695 session rate: 44100.0 input rate: 44100.0
2019-01-29 18:54:50:783 session rate: 48000.0 input rate: 48000.0 aksettings rate:48000.0
So far, I have tested this code on iPhoneX(48K hz native), iPhone 6s plus(48K hz native), iPhone 6(44.1K hz native).
It looks like AudioKit isn't using correct input device sample rate before the AKMicrophone is being initialized.
@apprithm Thanks ! its work for me !
Glad you got it fixed. If it comes up again, some sample code demonstrating the problem would really help. Thank yall.
Related to this issue AKmicrophone() is not working in ios 11 devices !
any solutions ?
I don't know if that's a fair addition to this issue. All iOS 11 devices have 48K microphones now? More info or a new issue please. Thanks.
@aure On my iPhone 7+, when you're creating AKMicrophone and headphones with mic are connected to the device - AVAudioSession.sharedInstance().sampleRate returns 44800 - and, because of deviceSampleRate from AudioKit class is static let - AudioKit uses everywhere deviceSampleRate as 44800. The magic is - when you're disconnecting headphones - after that AVAudioSession.sharedInstance().sampleRate returns 44100, while deviceSampleRate is still 44800 and I think that's why it crashes with exception 'required condition is false: format.sampleRate == hwFormat.sampleRate'
Been testing with zero issues on iOS 12 devices, my partner has a 7th gen iPad running iOS 11.4, app has worked for him in the past, now it's hard crashing no matter what on AKMicrohpone(). Tried the above fixes, interestingly enough the device is returning 44100 for sample rate form AVAudioSession. Cannot reproduce on any iOS 12 devices, I'll look to see if I have any other iOS 11 devices but so far have no idea how to fix this issue for iOS 11. Crash is coming from AKMicrophone.getInputFromDevice()
This is a weird one... Code below:
internal func setupMicrophone()
{
var inputFormat = AudioKit.engine.inputNode.outputFormat(forBus: 0)
AKLog("wrong rate---> session rate: \(AVAudioSession.sharedInstance().sampleRate) input rate: \(inputFormat.sampleRate)")
inputFormat = AudioKit.engine.inputNode.outputFormat(forBus: 0)
AKSettings.sampleRate = inputFormat.sampleRate
AKSettings.channelCount = inputFormat.channelCount
AKLog("correct rate---> session rate: \(AVAudioSession.sharedInstance().sampleRate) input rate: \(inputFormat.sampleRate) aksettings rate:\(AKSettings.sampleRate)")
mic = AKMicrophone()
}
Most helpful comment
@aure On my iPhone 7+, when you're creating AKMicrophone and headphones with mic are connected to the device -
AVAudioSession.sharedInstance().sampleRatereturns 44800 - and, because ofdeviceSampleRatefromAudioKitclass isstatic let- AudioKit uses everywhere deviceSampleRate as 44800. The magic is - when you're disconnecting headphones - after thatAVAudioSession.sharedInstance().sampleRatereturns 44100, whiledeviceSampleRateis still 44800 and I think that's why it crashes with exception'required condition is false: format.sampleRate == hwFormat.sampleRate'