Kunal Verma
Kunal Verma

Reputation: 33

Disconnecting headphones with audiokit running gives malloc error with AKOperationEffect specifically

// My code is below

do{
    file = try AKAudioFile(readFileName: "Sound1.mp3", baseDir: .resources)
    //    file =  try AKAudioFile(forReading: SingletonClass.sharedInstance.recordedURLs[SingletonClass.sharedInstance.recordedURL]!)

    //     AKSettings.defaultToSpeaker = true
}
catch {

}

do {
    player = try AKAudioPlayer(file : file)

}
catch {

}

let lfoAmplitude = 1_000
let lfoRate = 1.0 / 3.428

_ = 0.9

//filter section effect below
filterSectionEffect = AKOperationEffect(tracker) { input, _ in
    let lfo = AKOperation.sineWave(frequency: lfoRate, amplitude: lfoAmplitude)
    return input.moogLadderFilter(cutoffFrequency: lfo + cutoffFrequency,
                                  resonance: resonance)
}
Audiokit.output = filterSectionEffect
Audiokit.start()

And whenever I play the audio using a button with code player.play , the audio gets played properly. And if I connect the headphones, it gets played properly as well but as soon as I disconnect the headphones, I see the error:

Image showing the error

It happens in same way for both wired as well as bluetooth headphones. My app with stuck because of this issue only that too happens only with AKOperationEffect. Any help would be appreciated.

Upvotes: 2

Views: 223

Answers (1)

Aurelius Prochazka
Aurelius Prochazka

Reputation: 4573

The comment from Kunal Verma that this is fixed is correct, but just for completeness here is the commit that fixed it.

https://github.com/AudioKit/AudioKit/commit/ffac4acbe93553764f6095011e9bf5d71fdc88c2

Upvotes: 1

Related Questions