• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
MusicPlayerPreroll takes time - every time!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

MusicPlayerPreroll takes time - every time!


  • Subject: MusicPlayerPreroll takes time - every time!
  • From: Daniel Jalkut <email@hidden>
  • Date: Mon, 04 Nov 2002 14:31:57 -0800

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.

  • Follow-Ups:
    • Re: MusicPlayerPreroll takes time - every time!
      • From: Bill Stewart <email@hidden>
  • Prev by Date: Re: audio kext plugin
  • Next by Date: Re: audio kext plugin
  • Previous by thread: Re: audio kext plugin
  • Next by thread: Re: MusicPlayerPreroll takes time - every time!
  • Index(es):
    • Date
    • Thread