I’ve set up an AudioEngine
with the below code.
It can play notes with the MIDISampler
. However, the PitchTap
doesn’t seem to get any sample data. It always prints Frequency 100.0 – Amplitude 2.4266092e-05
.
<code>final class AudioGraph {
let engine = AudioEngine()
let sampler = MIDISampler(name: "sampler")
let pitchTracker: PitchTap
init(file: SamplerFile? = nil) throws {
let mic = engine.input!
engine.output = Mixer(
sampler,
Fader(mic, gain: 0.000)
)
/// Hooking ``PitchTap`` to ``sampler`` works. Yay. Why not the ``mic`` input?
pitchTracker = PitchTap(mic) { f, a in
guard let f = f.first, let a = a.first else { return }
print("Frequency (f) – Amplitude (a)")
}
if let file {
try setFile(file)
}
}
func setFile(_ file: SamplerFile) throws {
try sampler.loadInstrument(url: file.url)
}
}
// MARK: -
extension AudioGraph: NotePlayer {
func startAudioEngine() throws {
print("### Start engine")
try engine.start()
pitchTracker.start()
}
}
</code>
<code>final class AudioGraph {
let engine = AudioEngine()
let sampler = MIDISampler(name: "sampler")
let pitchTracker: PitchTap
init(file: SamplerFile? = nil) throws {
let mic = engine.input!
engine.output = Mixer(
sampler,
Fader(mic, gain: 0.000)
)
/// Hooking ``PitchTap`` to ``sampler`` works. Yay. Why not the ``mic`` input?
pitchTracker = PitchTap(mic) { f, a in
guard let f = f.first, let a = a.first else { return }
print("Frequency (f) – Amplitude (a)")
}
if let file {
try setFile(file)
}
}
func setFile(_ file: SamplerFile) throws {
try sampler.loadInstrument(url: file.url)
}
}
// MARK: -
extension AudioGraph: NotePlayer {
func startAudioEngine() throws {
print("### Start engine")
try engine.start()
pitchTracker.start()
}
}
</code>
final class AudioGraph {
let engine = AudioEngine()
let sampler = MIDISampler(name: "sampler")
let pitchTracker: PitchTap
init(file: SamplerFile? = nil) throws {
let mic = engine.input!
engine.output = Mixer(
sampler,
Fader(mic, gain: 0.000)
)
/// Hooking ``PitchTap`` to ``sampler`` works. Yay. Why not the ``mic`` input?
pitchTracker = PitchTap(mic) { f, a in
guard let f = f.first, let a = a.first else { return }
print("Frequency (f) – Amplitude (a)")
}
if let file {
try setFile(file)
}
}
func setFile(_ file: SamplerFile) throws {
try sampler.loadInstrument(url: file.url)
}
}
// MARK: -
extension AudioGraph: NotePlayer {
func startAudioEngine() throws {
print("### Start engine")
try engine.start()
pitchTracker.start()
}
}