basComponentInsance, are my structures falling of the stack?
basComponentInsance, are my structures falling of the stack?
- Subject: basComponentInsance, are my structures falling of the stack?
- From: Darren Minifie <email@hidden>
- Date: Mon, 5 Oct 2009 14:53:00 -0700
Hi everyone.
I'm beginning a fun little core audio app for myself and I'm having, what I think is a Core Audio beginners problem, with my code thus far. I'm working from the sample code that plays a softSynth via midi and an AUGraph. What i'm trying to do is set up my graph in the appDidFinishLaunching method, then tell my synth unit to play notes later on (based on usr events). With this approach, i get a "badComponentInstance" after my graph initialization method exits. The part im confused about is that if I append some note playing code within this method, everything works as expected. From these results I"m guessing that when my initialize method ends, something i've created in there loses scope and becomes unreachable. Starting out, I'm finding it difficult to determine what types are really opaque pointers, and what types are being put on the stack. anyways here is my code so far. Any advice would be very helpful.
static NAInstrument* anInstrument;
static AUGraph graph;
@implementation JamAppDelegate
@synthesize window;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[self createNewAUGraph];
// The following section causes the error, but if its moved within the
// createNewAUGraph method, things work properly.
CAShow (graph);
UInt32 noteNum = 60;
UInt32 > // anInstrument holds a pointer to the synth Audio Unit.
[anInstrument playNote:noteNum withVolume:onVelocity];
// sleep for a second
usleep (1 * 1000 * 1000);
[anInstrument playNote:noteNum withVolume:0];
}
-(void)createNewAUGraph{
graph = 0;
AudioUnit synthUnit = nil;
// START AUDIO GRAPH
AUNode synthNode, limiterNode, outNode;
AudioComponentDescription cd;
cd.componentManufacturer = kAudioUnitManufacturer_Apple;
cd.componentFlags = 0;
cd.componentFlagsMask = 0;
if(noErr != NewAUGraph(&graph)){
NSLog(@"Could not create a new AUGraph (%@ - %@)", self, NSStringFromSelector(_cmd));
return;
}
cd.componentType = kAudioUnitType_MusicDevice;
cd.componentSubType = kAudioUnitSubType_DLSSynth;
if(noErr != AUGraphAddNode(graph, &cd, &synthNode)){
NSLog(@"Could not add node to graph (%@ - %@)", self, NSStringFromSelector(_cmd));
return;
}
cd.componentType = kAudioUnitType_Effect;
cd.componentSubType = kAudioUnitSubType_PeakLimiter;
if(noErr != AUGraphAddNode (graph, &cd, &limiterNode)){
NSLog(@"Could not add node to graph (%@ - %@)", self, NSStringFromSelector(_cmd));
return;
}
cd.componentType = kAudioUnitType_Output;
cd.componentSubType = kAudioUnitSubType_DefaultOutput;
if(noErr != AUGraphAddNode(graph, &cd, &outNode)){
NSLog(@"Could not add node to graph (%@ - %@)", self, NSStringFromSelector(_cmd));
return;
}
if(noErr != AUGraphOpen(graph)){
NSLog(@"Could not open the AUGraph (%@ - %@)", self, NSStringFromSelector(_cmd));
return;
}
if(noErr != AUGraphConnectNodeInput(graph, synthNode, 0, limiterNode, 0)){
NSLog(@"Could not connect an input node in the graph (%@ - %@)", self, NSStringFromSelector(_cmd));
return;
}
if(noErr != AUGraphConnectNodeInput(graph, limiterNode, 0, outNode, 0)){
NSLog(@"Could not connect an input node in the graph (%@ - %@)", self, NSStringFromSelector(_cmd));
return;
}
// ok we're good to go - get the Synth Unit...
if(noErr != AUGraphNodeInfo(graph, synthNode, 0, &synthUnit)){
NSLog(@"Could not grab node info AUGraphNodeInfo (%@ - %@)", self, NSStringFromSelector(_cmd));
return;
}
// END AUDIO GRAPH
// create an instrument from the new audio unit:
anInstrument = [NAInstrument intrumentWithAudioUnit:&synthUnit];
if(noErr != AUGraphInitialize(graph)){
NSLog(@"Could not initialize the AUGraph (%@ - %@)", self, NSStringFromSelector(_cmd));
return;
}
if(noErr != AUGraphStart(graph)){
NSLog(@"Could not start the AUGraph (%@ - %@)", self, NSStringFromSelector(_cmd));
return;
}
}
--
Darren Minifie
Computer Science Masters Candidate
University of Victoria, BC. Canada
My Rants:
www.noisyair.com
My Band:
www.ohsnapmusic.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