Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to connect a MusicPlayer using MusicSequence to AVAudioUnitSampler?

I'm using Audiokit for the audio needs of my iOS app, where I need to use a sequencer to programmatically control a sequence of notes and I want to drive a sampler with it. Audiokit seems to be designed to use MIDI internally, but I'd like to avoid this and go directly from sequencer to sampler, because using MIDI seems to make all the internal connections appear in virtual MIDI lists in other apps.

My question is this: Is it possible to connect a sequencer using MusicPlayer, MusicSequence and MusicTrack (from AudioToolbox) to an AVAudioUnitSampler (from AVFoundation)?

The other option would apparently be to construct the sampler using an AudioComponentDescription and building an AUGraph, but I'd like to use the Audiokit helpers as far as possible.

EDIT: The critical step seems to be using MusicTrackSetDestNode that takes an AUNode. AVAudioUnitSampler is an AVAudioNode that has the auAudioUnit property, of type AUAudioUnit. Essential APIs like AUGraphNodeInfo give you the audio unit from the audio node. How do you get the audio node from the audio unit?

like image 821
whistler Avatar asked Nov 20 '17 06:11

whistler


1 Answers

You can use AVAudioSequencer easily with AVAudioUnitSampler. This works for many cases.

It doesn't work for MIDI sequences that are built "on the fly" because there is no API to create sequences besides the AudioToolbox right now. File a Radar asking for this. (They're tired of hear from me about this). Otherwise, one clunky way is to create a MusicSequence, convert that to a Data instance, then hand that to AVAudioSequencer.

like image 56
Gene De Lisa Avatar answered Nov 14 '22 23:11

Gene De Lisa