SoundpipeAudioKit icon indicating copy to clipboard operation
SoundpipeAudioKit copied to clipboard

PitchTap doesn't work on a real device

Open ja-bravo opened this issue 10 months ago • 0 comments

macOS Version(s) Used to Build

macOS 13 Ventura

Xcode Version(s)

Xcode 14

Description

Using MacOS 14.1 and Xcode 15.0.1.

I have a basic setup for using PitchTap on an app but while everything works as expected on simulators, on a real device (iPhone 14 pro max running iOS 18.1.1) it returns fixed values of Pitch: 100.0 and Amp: 2.4266092e-05.

The setup I'm using.

let session = AVAudioSession.sharedInstance()
try session.setCategory(.playAndRecord)
try session.setPreferredIOBufferDuration(0.01)
try session.setPreferredSampleRate(48000)
try session.setActive(true)

let engine = AudioEngine()
guard let input = engine.input else {
    print("Could not create input")
    return
}

let silence = Fader(input, gain: 0)
engine.output = silence

print("Input format:", input.outputFormat)
print("Default sample rate:", session.sampleRate)

tracker = PitchTap(input) { [self] pitch, amp in
    print("Pitch: \(pitch[0]), Amp: \(amp[0])")
}

try engine.start()
tracker.start()
isSetupComplete = true

The result of the logs on a real device

Setting up AudioKit...
Input format: <AVAudioFormat 0x3016dc7d0:  2 ch,  44100 Hz, Float32, deinterleaved>
Default sample rate: 48000.0
"Start monitoring..."
Pitch: 100.0, Amp: 6.309573e-08
Pitch: 100.0, Amp: 2.4266092e-05
Pitch: 100.0, Amp: 6.309573e-08

The same logs for from a simulator

Setting up AudioKit...
Input format: <AVAudioFormat 0x600002142170:  2 ch,  44100 Hz, Float32, deinterleaved>
Default sample rate: 48000.0
"Start monitoring..."
Pitch: 100.0, Amp: 6.309573e-08
Pitch: 100.0, Amp: 6.309573e-08
Pitch: 223.35707, Amp: 0.016687963
Pitch: 105.962296, Amp: 0.022452937
Pitch: 210.46704, Amp: 0.061113775
Pitch: 102.177284, Amp: 0.052259564

I'm not entirely sure if I've done something wrong or if there's a problem with the library itself, any help would be greatly appreciated 😄

Crash Logs, Screenshots or Other Attachments (if applicable)

No response

ja-bravo avatar Feb 21 '25 10:02 ja-bravo