Re: MusicPlayerPreroll takes time - every time!
Re: MusicPlayerPreroll takes time - every time!
- Subject: Re: MusicPlayerPreroll takes time - every time!
- From: Bill Stewart <email@hidden>
- Date: Mon, 4 Nov 2002 15:24:33 -0800
Firstly,
You can't expect anything to be disposed for you...
So, when you add a track, add events, add a sequence, you go through a
series of steps each time...
You'd be better to:
Have a sequence that you keep targetted to a graph - keep both the
graph and sequence and player around (you can let the sequence create
the default graph for you if you're happy with that)
In that sequence, create a track that you keep using.
Make sure you initialize the graph (after you've set it up) and that it
has what you need in it, is connected and ready to go... (the first
time you preroll the player it will do this for you if you haven't
explicitly done it)
Now, when you add notes that you want to play - add them to the track
you're using, preroll the player and start it.
When you're finished with those notes remove these events from the
track (after stopping the player of course) - but that is all that you
do... (Remember the player DOES NOT reset its time automatically, so
you'd probably also want to set the time of the player back to zero.
At the moment you're going through ALOT of setup and tear down code (if
you were disposing of things:)
Bill
On Monday, November 4, 2002, at 02:31 PM, Daniel Jalkut wrote:
I am trying to update my application to use CoreAudio's MusicPlayer
APIs instead of the QuickTime TunePlayer functionality.
I have got a basic "working case," but the solution is currently not
acceptible because of the LONG (sometimes 1 second) delay I see in
MusicPlayerPreroll().
What I'm doing is basically keeping a "MusicPlayer" allocated and
on-hand, then I'm allocating a 1-track sequence, adding some notes,
setting that as the sequence for the player, pre-rolling and playing
it. This code gets reached hundreds of times, and the response time
needs to be quick each time.
Is the delay because of the amount of "hooking up the wires" I'm
leaving to CoreAudio defaults? What should I be sure to configure by
hand if I want to make sure my MusicPlayer is "primed" for delivering
an arbitrary sequence of notes at any given time?
My sample code below is typical of the kind of "workout" I need to put
the MusicPlayer through. This code just creates a 1-track
MusicSequence, adds 5 semi-random notes to it, and plays it.
Any help appreciated! I'm also curious whether I need to be
responsible for manually disposing the sequence and track or whether
"replacing" the sequence in the musicplayer will automatically dispose
any prior sequence and associated structures.
Thanks,
Daniel
*** TEST CODE ***
- (OSStatus) playTestNotes
{
OSStatus anyError = noErr;
MusicSequence testSequence;
// Instantiate our music player if it's not already created
if (musicPlayer == nil)
{
anyError = NewMusicPlayer(&musicPlayer);
if (anyError != noErr)
{
NSLog(@"Failed to create music player!");
return anyError;
}
}
// Make a MusicSequence for the notes we are playing...
anyError = NewMusicSequence(&testSequence);
if (anyError == noErr)
{
MusicTrack testTrack;
// Add a single track
anyError = MusicSequenceNewTrack(testSequence, &testTrack);
if (anyError == noErr)
{
MIDINoteMessage thisNote;
short iterator;
// fill in the invariable fields
thisNote.channel = 1;
thisNote.velocity = 100.00;
thisNote.reserved = 0;
thisNote.duration = 1.0;
// Add some notes!
for (iterator = 0; iterator < 5; iterator++)
{
// Random note within octave above middle C
thisNote.note = 60 + (((unsigned short)random()) % 13);
// Add the note N seconds into the track...
anyError = MusicTrackNewMIDINoteEvent(testTrack, (iterator * 1.0),
&thisNote);
if (anyError != noErr)
{
NSLog(@"Failed to add MIDI note event to interval playback
track!");
}
}
// Stop any active playing
(void) MusicPlayerStop(musicPlayer);
// Prepare the new sequence
anyError = MusicPlayerSetSequence(musicPlayer, testSequence);
if (anyError == noErr)
{
MusicPlayerSetTime(musicPlayer, 0.0);
MusicPlayerPreroll(musicPlayer); // takes a long time - every
time!
anyError = MusicPlayerStart(musicPlayer);
if (anyError != noErr)
{
NSLog(@"MusicPlayerStart returned an error!\n");
}
}
// MusicSequenceDisposeTrack(testSequence, testTrack);
}
// DisposeMusicSequence(testSequence);
}
return anyError;
}
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.
--
mailto:email@hidden
tel: +1 408 974 4056
________________________________________________________________________
__
"Much human ingenuity has gone into finding the ultimate Before.
The current state of knowledge can be summarized thus:
In the beginning, there was nothing, which exploded" - Terry Pratchett
________________________________________________________________________
__
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.