0

I am currently making a music app where you can add new instruments as tracks to the music sequnce.

Here's what I have for when a new track has been added:

MusicPlayerStop(_musicPlayer);

status = MusicSequenceNewTrack(sequence, &tracks[tracksCount]);

timeDiff = 32.f/_tempo;

[self setLoopDuration:currentLoopDuration forPattern:tracks[tracksCount]];

AudioComponentDescription samplerNodeDesc;
samplerNodeDesc.componentManufacturer = (OSType)kAudioUnitManufacturer_Apple;
samplerNodeDesc.componentType = (OSType)kAudioUnitType_MusicDevice;
samplerNodeDesc.componentSubType = (OSType)kAudioUnitSubType_Sampler;
samplerNodeDesc.componentFlags = 0;
samplerNodeDesc.componentFlagsMask = 0;


status = AUGraphAddNode(graph, &samplerNodeDesc, &auNodes[tracksCount]);
status = AUGraphNodeInfo(graph, auNodes[tracksCount], 0, &audioUnits[tracksCount]);


status = AUGraphConnectNodeInput(graph, auNodes[tracksCount], 0, filterNode, 0);
status = MusicTrackSetDestNode(tracks[tracksCount], auNodes[tracksCount]);

int trackId = tracksCount;

tracksCount++;

MusicPlayerStart(_musicPlayer);


return trackId;

The following doesn't produce audio at all, what can I Do here please.

Thanks so much !

ipalibowhyte
  • 1,553
  • 2
  • 22
  • 34
  • Are you able to get a music player working at all? – dave234 Jun 21 '15 at 02:03
  • @dave I have added that to my code and still cant get it to work! :( – ipalibowhyte Jun 21 '15 at 04:04
  • @dave should we move on to a chat and when i get it working i post the answer ? – ipalibowhyte Jun 21 '15 at 04:04
  • I'm just not sure I understand your question. Are you having trouble getting a music sequence to play at all? Or are you just needing help adding tracks? – dave234 Jun 21 '15 at 04:34
  • @Dave, I have a problems getting newly added tracks to play! I have a conductor which is the first track added during initialisation of the augraph and if I use that sample node added during initialisation as the dest node for the newly added track, it plays ie `MusicTrackSetDestNode(tracks[tracksCount], sampleNode)` . However I cant get `MusicTrackSetDestNode(tracks[tracksCount], auNodes[tracksCount])` to work. Hope you understand now ? – ipalibowhyte Jun 21 '15 at 04:46
  • @Dave, any ideas why it may not be working ? thanks! – ipalibowhyte Jun 21 '15 at 05:48

1 Answers1

0

You need to call AUGraphUpdate(graph, nil); Or if you want the graph to block until it has ben added you supply it with a pointer to a Boolean and the calling thread will wait for the audio thread to add the audio unit.

Boolean updated;
AUGraphUpdate(graph, &updated); //will block until end of next audio cycle

if (updated){
    printf("hooray\n");
} 
dave234
  • 4,793
  • 1
  • 14
  • 29