I
am trying to use the MusicPlayer to play a MIDI file containing a few
notes through a simple AUGraph consisting of a file player connected
to the output. When I set the Boolean useAUGraph to false in the code below, the file
plays 7 notes in succession, as I intended. However, if I set
useAUGraph to true, the MusicPlayer plays the first 2 notes
immediately in the first iteration of my loop, without waiting for
the scheduled time, and fails to play the notes in subsequent loop
iterations. What am I missing?
Mark
Brophy
void
TestPlaySequence()
{
MusicSequence
mSequence;
AUGraph
mGraph;
Boolean
useAUGraph = true;
AudioFileID
audioFile;
MusicPlayer
mPlayer;
Boolean
isPlaying;
MusicTimeStamp
currentTime;
CreateSequence
(&mSequence);
CreateSignalProcessingNetwork
(&mGraph, &audioFile);
if
(useAUGraph)
MusicSequenceSetAUGraph
(mSequence, mGraph);
NewMusicPlayer(&mPlayer);
MusicPlayerSetSequence(mPlayer,
mSequence);
MusicPlayerSetTime(mPlayer,
0.0);
MusicPlayerPreroll(mPlayer);
MusicPlayerStart(mPlayer);
while
(MusicPlayerIsPlaying(mPlayer,
&isPlaying) == noErr &&
isPlaying) {
[NSThread
sleepUntilDate:[NSDate
dateWithTimeIntervalSinceNow:1.0]];
if
(MusicPlayerGetTime(mPlayer,
¤tTime) != noErr ||
currentTime > 9.0)
break;
}
DisposeNetwork
(mGraph, audioFile);
}
|