Reputation: 31
I'm faced with simple problem, on which not trivial to find an answer in google (at least for me). Working with AudioKit 4.4
, I'm trying to make a microphone, output from which I can hear in both channels of my stereo headphones. I'm trying to set audioformat to AudioKit.format
and AKSettings.channelCount
manually, but in headphones I hear microphone only in left channel. What I'm missing?
Here simplified code with my current settings:
AKSettings.bufferLength = .long
AKSettings.fixTruncatedRecordings = true
AKSettings.defaultToSpeaker = true
AKSettings.ioBufferDuration = 0.002
AKSettings.channelCount = 2
AKSettings.enableRouteChangeHandling = false
let format = AVAudioFormat(standardFormatWithSampleRate: 44100, channels: 2)
AudioKit.format = format ?? AudioKit.format
let mic = AKMicrophone()
AudioKit.output = mic
try? AudioKit.start()
As you can see, I'm just initialising AKSettings
properties for audio session and create a microphone, that connects to AudioKit
engine output. I suspect that AKSettings
before AKSettings.channelCount = 2
doesn't play any role in this problem. But I don't understand at all, what I'm doing wrong? I'm sure, it would be a simple solution.
Upvotes: 1
Views: 188
Reputation: 31
So, I have found the answer - it is class AKStereoFieldLimiter
:
let mic = AKMicrophone()
let monoToStereo = AKStereoFieldLimiter(mic, amount: 1)
let micMixer = AKMixer(monoToStereo)
AudioKit.output = micMixer
Also, there may be a more simple solution in AudioKit 4.7.1
- initialisation AKMicrophone(with format: AVAudioFormat?)
, but I can't check it, because I'm working with AudioKit 4.4
. If someone can try this method, please, leave a feedback in comment to this answer.
Upvotes: 1