objective c - Can't set multiple musical instruments in iOS using MusicPlayer and AUGraph -
i have musicplayer holds musicsequence containing 3 musictracks. have set augraph 3 ausampler nodes plugged multichannel mixer, in turn connected output node.
i using soundfont, , 3 different musictracks play on 3 different musical instruments, described here. however, code i've got doesn't work - instead, plays 1 of parts.
i create augraph follows:
newaugraph (&_processinggraph); aunode samplernode, samplernodetwo, samplernodethree, ionode, mixernode; audiocomponentdescription cd = {}; cd.componentmanufacturer = kaudiounitmanufacturer_apple; //---------------------------------------- // add 3 sampler unit nodes graph //---------------------------------------- cd.componenttype = kaudiounittype_musicdevice; cd.componentsubtype = kaudiounitsubtype_sampler; augraphaddnode (self.processinggraph, &cd, &samplernode); augraphaddnode (self.processinggraph, &cd, &samplernodetwo); augraphaddnode (self.processinggraph, &cd, &samplernodethree); //----------------------------------- // 2. add mixer unit node graph //----------------------------------- cd.componenttype = kaudiounittype_mixer; cd.componentsubtype = kaudiounitsubtype_multichannelmixer; augraphaddnode (self.processinggraph, &cd, &mixernode); //-------------------------------------- // 3. add output unit node graph //-------------------------------------- cd.componenttype = kaudiounittype_output; cd.componentsubtype = kaudiounitsubtype_remoteio; // output speakers augraphaddnode (self.processinggraph, &cd, &ionode); //--------------- // open graph //--------------- augraphopen (self.processinggraph); //----------------------------------------------------------- // obtain mixer unit instance corresponding node //----------------------------------------------------------- augraphnodeinfo ( self.processinggraph, mixernode, null, &mixerunit ); //-------------------------------- // set bus count mixer //-------------------------------- uint32 numbuses = 3; audiounitsetproperty(mixerunit, kaudiounitproperty_elementcount, kaudiounitscope_input, 0, &numbuses, sizeof(numbuses)); //------------------ // connect nodes //------------------ augraphconnectnodeinput (self.processinggraph, samplernode, 0, mixernode, 0); augraphconnectnodeinput (self.processinggraph, samplernodetwo, 0, mixernode, 1); augraphconnectnodeinput (self.processinggraph, samplernodethree, 0, mixernode, 2); // connect mixer unit output unit augraphconnectnodeinput (self.processinggraph, mixernode, 0, ionode, 0); // obtain references of audio units nodes augraphnodeinfo (self.processinggraph, samplernode, 0, &_samplerunit); augraphnodeinfo (self.processinggraph, samplernodetwo, 0, &_samplerunittwo); augraphnodeinfo (self.processinggraph, samplernodethree, 0, &_samplerunitthree); augraphnodeinfo (self.processinggraph, ionode, 0, &_iounit);
i load 3 instruments soundfont (ids 0, 1 , 2 in soundfont) follows, passing in 'bankurl' of soundfont:
// load first instrument ausamplerbankpresetdata bpdata; bpdata.bankurl = (__bridge cfurlref) bankurl; bpdata.bankmsb = kausampler_defaultmelodicbankmsb; bpdata.banklsb = kausampler_defaultbanklsb; bpdata.presetid = (uint8) 0; audiounitsetproperty(self.samplerunit, kausamplerproperty_loadpresetfrombank, kaudiounitscope_global, 0, &bpdata, sizeof(bpdata)); // load second instrument ausamplerbankpresetdata bpdatatwo; bpdatatwo.bankurl = (__bridge cfurlref) bankurl; bpdatatwo.bankmsb = kausampler_defaultmelodicbankmsb; bpdatatwo.banklsb = kausampler_defaultbanklsb; bpdatatwo.presetid = (uint8) 1; audiounitsetproperty(self.samplerunittwo, kausamplerproperty_loadpresetfrombank, kaudiounitscope_global, 0, &bpdatatwo, sizeof(bpdatatwo)); // load third instrument ausamplerbankpresetdata bpdatathree; bpdatathree.bankurl = (__bridge cfurlref) bankurl; bpdatathree.bankmsb = kausampler_defaultmelodicbankmsb; bpdatathree.banklsb = kausampler_defaultbanklsb; bpdatathree.presetid = (uint8) 2; audiounitsetproperty(self.samplerunitthree, kausamplerproperty_loadpresetfrombank, kaudiounitscope_global, 0, &bpdatathree, sizeof(bpdatathree));
finally, set ausampler nodes used each musictrack follows:
//------------------------------------------------- // set ausampler nodes used each track //------------------------------------------------- musictrack track, tracktwo, trackthree; musicsequencegetindtrack(testsequence, 0, &track); musicsequencegetindtrack(testsequence, 1, &tracktwo); musicsequencegetindtrack(testsequence, 2, &trackthree); aunode samplernode, samplernodetwo, samplernodethree; augraphgetindnode (self.processinggraph, 0, &samplernode); augraphgetindnode (self.processinggraph, 1, &samplernodetwo); augraphgetindnode (self.processinggraph, 2, &samplernodethree); musictracksetdestnode(track, samplernode); musictracksetdestnode(tracktwo, samplernodetwo); musictracksetdestnode(trackthree, samplernodethree);
however, when play musicplayer, hear single part playing. problem arising in trying use different instruments - when use single instrument standard musicplayer setup (instead of editing augraph above), works fine.
does have idea i'm doing wrong?
i've found solution. before loading instruments soundfont, following line needed:
musicsequencesetaugraph(testsequence, self.processinggraph);
as long point @ line run comes before instruments loaded soundfont , before various musictracks assigned ausampler nodes, seems work - parts played on different instruments, desired. this answer related question helped me figure out.
Comments
Post a Comment