Using the default AudioOutputUnit on a separate thread
Using the default AudioOutputUnit on a separate thread
- Subject: Using the default AudioOutputUnit on a separate thread
- From: Dalzhim Dalzhim <email@hidden>
- Date: Tue, 5 May 2009 17:51:12 -0400
Hello,
I am trying to use the default AudioOutputUnit on a separate thread in order to prevent my GUI from hanging while I play a sound. For some weird reason, it only works once and stops working afterwards.
I have made my code using the example /Developer/Examples/CoreAudio/SimpleSDK/DefaultOutputUnit.
My code follows the same pattern as the example:
==============================
Component comp = FindNextComponent(NULL, &desc);
err = OpenAComponent(comp, &outputUnit);
err = AudioUnitSetProperty (outputUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &input, sizeof(input));
err = AudioUnitSetProperty (outputUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &streamFormat, sizeof(AudioStreamBasicDescription));
err = AudioUnitInitialize(outputUnit);
err = AudioUnitGetProperty (outputUnit, kAudioUnitProperty_SampleRate, kAudioUnitScope_Output, 0, &outSampleRate, &size);
err = AudioOutputUnitStart (outputUnit);
CFRunLoopRunInMode(kCFRunLoopDefaultMode, duree, false);
verify_noerr (AudioOutputUnitStop(outputUnit));
err = AudioUnitUninitialize (outputUnit);
CloseComponent (outputUnit);
==============================
And this code is all bundled in a method that is called by one of these 2 lines:
==============================
// This is the method that works, I can play the sound, and when it is done playing and that the GUI starts responding again, I can play it again without any problem
[self performSelector:@selector(playAudio:)
withObject:[[[PlayerWrapper alloc] initWithPlayer:leLecteur]
autorelease]];
// This is the method that I would like to get to work. Right now it works during the first invocation, but it never works again until I restart the application. The run loop exits with code 1 during the failed attempts.
[NSThread detachNewThreadSelector:@selector(playAudio:) toTarget:self withObject:[[[PlayerWrapper alloc] initWithPlayer:thePlayer] autorelease]];
==============================
Here is the playAudio selector:
==============================
- (nul) playAudio:(id)parametre
{
[(LecteurOggWrapper*)parametre jouerSurSortieParDefaut];
}
==============================
And here is my wrapper which I use in the Multi-threaded approach:
==============================
@interface PlayerWrapper : NSObject {
Player* myPlayer;
}
- (id) initWithPlayer:(Player*)thePlayer;
- (void) playOnDefaultOutput;
@end
@implementation PlayerWrapper
- (id) initWithPlayer:(Player*)thePlayer
{
self = [super init];
si (self) {
myPlayer = thePlayer;
}
retourne self;
}
- (void) playOnDefaultOutput
{
myPlayer->playOnDefaultOutput();
}
@end
==============================
So basically, I need to get the multi-threaded approach working, but I cannot seem to make it work more than once during the life of the application.
Thanks for your help!
-Dalzhim
_______________________________________________
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