• 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
how to integrate Core Audio code into the run loop
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

how to integrate Core Audio code into the run loop


  • Subject: how to integrate Core Audio code into the run loop
  • From: John Michael Zorko <email@hidden>
  • Date: Sun, 07 Sep 2008 08:04:29 -0700


... what i've tried hasn't worked :-(

Hello, all ...

I have what is likely a very easy question. I'm new to Core Audio, and i'm working with AudioFileStreamExample. I was quite happy to find this, and i've learned a lot about Core Audio by seeing it work, but the problem is that this example doesn't illustrate how to integrate into the run loop. Basically, my app plays the audio streamed from the server fine, but the user can't do anything else while it's going on.

What i've done is:

1. replace the example's main() function with my own, NSURLConnection- based code, like this:

- (void)playStream:(Song *)streamToPlay
{
	NSLog(@"playing mp3 stream %s", [streamToPlay.mp3 UTF8String]);

// initialize a mutex and condition so that we can block on buffers in use.

pthread_mutex_init(&myData.mutex, NULL);
pthread_cond_init(&myData.cond, NULL);

OSStatus err = AudioFileStreamOpen(&myData, MyPropertyListenerProc, MyPacketsProc,
kAudioFileAAC_ADTSType, &myData.audioFileStream);
if (err)
{
NSLog(@"AudioFileOStreamOpen error %d", err);
}

NSString *url = @"http://he3.magnatune.com/all/";;
url = [url stringByAppendingString:streamToPlay.mp3];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[url stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];

if (connection)
{
receivedData = [[NSMutableData data] retain];
}
else
{
NSLog(@"can't connect to server");
}
}


... and inside my NSURLConnection's received-data method, I tried to integrate into the run loop thusly:

- (void)connection:(NSURLConnection *)connection didReceiveData: (NSData *)data
{
unsigned int length = [data length];

NSLog(@"recv'd %d bytes", length);

OSStatus status = AudioFileStreamParseBytes(myData.audioFileStream, length, [data bytes], 0);


	CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.25, false);

    [receivedData appendData:data];
}

... but alas, it doesn't work -- my app is still unresponsive while the stream is playing. I'm also not so sure that didReceiveData is the best place to do this, but I don't know of a better place yet. Any pointers?

Regards,

John

Falling You - exploring the beauty of voice and sound
http://www.fallingyou.com



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: how to integrate Core Audio code into the run loop
      • From: Jeff Moore <email@hidden>
  • Prev by Date: Re: Test report iTunes SRC
  • Next by Date: Re: how to integrate Core Audio code into the run loop
  • Previous by thread: Regarding Equalizer
  • Next by thread: Re: how to integrate Core Audio code into the run loop
  • Index(es):
    • Date
    • Thread