-
Notifications
You must be signed in to change notification settings - Fork 10
Description
Here is my code:
let pitchEngine = PitchEngine { result in
switch result {
case .success(let pitch):
// Handle the reported pitch
print("pitch:\(pitch)")
case .failure(let error):
// Handle the error
switch error {
case PitchEngine.Error.levelBelowThreshold: break
case PitchEngine.Error.recordPermissionDenied: break
case PitchError.invalidFrequency: break
case PitchError.invalidWavelength: break
case PitchError.invalidPeriod: break
case PitchError.invalidPitchIndex: break
case PitchError.invalidOctave: break
default: break
}
}
}
self.engine = pitchEngine
self.engine.start()In my Xcode console, I saw the following print out even there is no audio input at all:
pitch:Pitch(frequency: 33.99433517456055, wave: Tuna.AcousticWave(frequency: 33.99433517456055, wavelength: 10.089916400444329, period: 0.02941666589050825), offsets: Tuna.Pitch.Offsets(lower: (note: C1, frequency: 1.291139511985719, percentage: 66.39501504219396, cents: 67.03528398347567), higher: (note: C#1, frequency: -0.6534936975484626, percentage: -33.604984957806046, cents: -32.96471601652434)))
pitch:Pitch(frequency: 24.2914981842041, wave: Tuna.AcousticWave(frequency: 24.2914981842041, wavelength: 14.120166545472305, period: 0.04116666631333033), offsets: Tuna.Pitch.Offsets(lower: (note: F#0, frequency: 1.1668467647269516, percentage: 84.85767453715917, cents: 85.22382318798803), higher: (note: G0, frequency: -0.2082165646552241, percentage: -15.142325462840832, cents: -14.776176812011498)))
pitch:Pitch(frequency: 49.484535217285156, wave: Tuna.AcousticWave(frequency: 49.484535217285156, wavelength: 6.931458454523155, period: 0.020208333686656428), offsets: Tuna.Pitch.Offsets(lower: (note: G1, frequency: 0.48510571956649073, percentage: 16.64937235434482, cents: 17.055331471965207), higher: (note: G#1, frequency: -2.4285519802079847, percentage: -83.35062764565518, cents: -82.94466852803451)))
Then I tried to filter out the short period pitch like this:
if pitch.wave.period > 0.05Then there is no print out at all. I'm wondering how to detect the pitch?