Audiokit iOS Aksamplermetronome

AudioKit ios AKSamplerMetronome

You could do this easily enough with AKSequencer (I did something similar). I assigned one track of the sequencer to an AKMIDISampler, generating the metronome sound, and a second track that went to an AKCallbackInstrument.

In the track being sent to the AKCallbackInstrument, I encoded the beat information arbitrarily in the MIDI data, so for example, the MIDI data for the first beat has a MIDINote of 1, the second, MIDINote 2 (you could do this with the velocity). Then the callback function could would just look at all of the noteOn messages and get the current beat from the MIDI Note number, and respond accordingly. It's a little indirect, but it works.

// create the sequencer before hand (e.g., at init); calling play() immediately after creating it causes some odd behaviour
let sequencer = AKSequencer()

// set up the sampler and callbackInst
let sampler = AKSynthSnare()
// or for your own sample:
// let sampler = AKMIDISampler()
// sampler.loadWav("myMetronomeSound)
let callbackInst = AKCallbackInstrument()
AudioKit.output = sampler
AudioKit.start()

// create two tracks for the sequencer
let metronomeTrack = sequencer.newTrack()
metronomeTrack?.setMIDIOutput(sampler.midiIn)
let callbackTrack = sequencer.newTrack()
callbackTrack?.setMIDIOutput(callbackInst.midiIn)

// create the MIDI data
for i in 0 ..< 4 {
// this will trigger the sampler on the four down beats
metronomeTrack?.add(noteNumber: 60, velocity: 100, position: AKDuration(beats: Double(i)), duration: AKDuration(beats: 0.5))

// set the midiNote number to the current beat number
callbackTrack?.add(noteNumber: MIDINoteNumber(i), velocity: 100, position: AKDuration(beats: Double(i)), duration: AKDuration(beats: 0.5))
}

// set the callback
callbackInst.callback = {status, noteNumber, velocity in
guard status == .noteOn else { return }
print("beat number: \(noteNumber + 1)")
// e.g., resondToBeat(beatNum: noteNumber)
}

// get the sequencer ready
sequencer.enableLooping(AKDuration(beats: 4))
sequencer.setTempo(60)
sequencer.play()

AudioKit ios AKSamplerMetronome

You could do this easily enough with AKSequencer (I did something similar). I assigned one track of the sequencer to an AKMIDISampler, generating the metronome sound, and a second track that went to an AKCallbackInstrument.

In the track being sent to the AKCallbackInstrument, I encoded the beat information arbitrarily in the MIDI data, so for example, the MIDI data for the first beat has a MIDINote of 1, the second, MIDINote 2 (you could do this with the velocity). Then the callback function could would just look at all of the noteOn messages and get the current beat from the MIDI Note number, and respond accordingly. It's a little indirect, but it works.

// create the sequencer before hand (e.g., at init); calling play() immediately after creating it causes some odd behaviour
let sequencer = AKSequencer()

// set up the sampler and callbackInst
let sampler = AKSynthSnare()
// or for your own sample:
// let sampler = AKMIDISampler()
// sampler.loadWav("myMetronomeSound)
let callbackInst = AKCallbackInstrument()
AudioKit.output = sampler
AudioKit.start()

// create two tracks for the sequencer
let metronomeTrack = sequencer.newTrack()
metronomeTrack?.setMIDIOutput(sampler.midiIn)
let callbackTrack = sequencer.newTrack()
callbackTrack?.setMIDIOutput(callbackInst.midiIn)

// create the MIDI data
for i in 0 ..< 4 {
// this will trigger the sampler on the four down beats
metronomeTrack?.add(noteNumber: 60, velocity: 100, position: AKDuration(beats: Double(i)), duration: AKDuration(beats: 0.5))

// set the midiNote number to the current beat number
callbackTrack?.add(noteNumber: MIDINoteNumber(i), velocity: 100, position: AKDuration(beats: Double(i)), duration: AKDuration(beats: 0.5))
}

// set the callback
callbackInst.callback = {status, noteNumber, velocity in
guard status == .noteOn else { return }
print("beat number: \(noteNumber + 1)")
// e.g., resondToBeat(beatNum: noteNumber)
}

// get the sequencer ready
sequencer.enableLooping(AKDuration(beats: 4))
sequencer.setTempo(60)
sequencer.play()

Sync playing AKSamplerMetronome and AKAppleSequencer

Lots of ways to do this but I would make one of the tracks in the sequencer a metronome track and send that midi signal to a midiSampler.

How to visualize current AKSequencer position with Audiokit?

I do this with the AKCallbackInstrument. For each sequence track that I write MIDI events to, I have a sister sequencer track sending to AKCallbackInstrument. When I write a MIDI event for the audio track, I also write a GUI event to the sister callback track.

Because you can only send MIDIStatus, MIDINote, and MIDIVelocity data to the callback instrument, you have to arbitrarily encode information into these formats. For example, a MIDINote of 0 might signify one type of GUI event, MIDINote 1 something else. Creating some enums makes this easy.

Of course the callback functions are called on a background thread, so don't forget to specify that your GUI updates should happen on the main thread.

This approach has worked quite well for me.

edit: I suspect you've already seen this sample code that illustrates something very similar, but this link might be useful for anyone else coming across this question.

AudioKit stop and start produce weird sounds

i was having the weird sound issue. and i fixed the issue by assigning the audio files again to metronome. there was no weird sound anymore and no more volume cut down. hope it will help all.

iOS AudioKit AKAmplitudeTracker

The main problem here is that Frequency Tracker node is not part of the signal chain. AudioKit (and Apple's underlying AVAudioEngine) works on a pull model in that audio will not be pulled through a node unless it is requested by a downstream node. This basically means everything up from the AudioKit.output node will get bytes pulled through them.

However, here, the reverb is made to be the output, so the tracker itself doesn't get any data coming through it. Changing it to AudioKit.output = amplitudeTracker will get the data going through the node.

The amplitudeTracker acts as a passthrough so the audio comes through as well. If you would not want the audio, you'd then stick the output of the tracker through a booster which would lower the volume down to zero.

AudioKit ios AKSequencer Not Restarting Playback Accurately

There are a few confusing things in your code, so I'm not sure if this is your only issue, but minimally, every time you change the length of your sequence, you will need to call setLength() followed by enableLooping. Basically, by default (i.e., unless you explicitly set the length) the length of the sequence will be the length of the longest track in the sequence. In your 'playback' method you are adding track on top of track without removing the old ones so it has no way of knowing how long you intend the sequence to be.

Your 'playback' method is doing two distinct things (neither of which involves playback). You might want to break it up. You could have a setup() to do the things that only ever need to be done once (create the tracks, set their outputs, set up the callback) and a rewriteSequence() methods that gets called when you want to re-write the tracks. This way you can reuse your existing tracks rather than continuously creating new ones.

var metronomeTrack: AKMusicTrack!
var callbackTrack: AKMusicTrack!

// call this just once at the start
func setup() {
metronomeTrack = sequencer.newTrack()
metronomeTrack?.setMIDIOutput(click.midiIn)
callbackTrack = sequencer.newTrack()
callbackTrack?.setMIDIOutput(callbackInst.midiIn)

callbackInst.callback = {status, noteNumber, velocity in
guard status == .noteOn else { return }
print("beat number: \(noteNumber + 1)")

}
}

// call this each time you want to change the sequence
func rewriteSequence() {
metronomeTrack?.clear()
callbackTrack?.clear()
for steps in 0 ... Int(measuresRowOneValue) {
metronomeTrack?.add(noteNumber: 60, velocity: 100, position: AKDuration(beats: Double(steps)), duration: AKDuration(beats: 0.5))
callbackTrack?.add(noteNumber: MIDINoteNumber(steps), velocity: 100, position: AKDuration(beats: Double(steps)), duration: AKDuration(beats: 0.5))
}

// This will make sure it loops correctly:
sequencer.setLength(AKDuration(beats: Double(measuresRowOneValue)))
sequencer.enableLooping()
}

I hope this helps.



Related Topics



Leave a reply



Submit