bool CCoreAudioUnit::Open(AUGraph audioGraph, ComponentDescription desc) { if (m_audioUnit) Close(); OSStatus ret; m_Initialized = false; ret = AUGraphNewNode(audioGraph, &desc, 0, NULL, &m_audioNode); if (ret) { CLog::Log(LOGERROR, "CCoreAudioGraph::Open: " "Error add m_outputNode. Error = %s", GetError(ret).c_str()); return false; } ret = AUGraphGetNodeInfo(audioGraph, m_audioNode, 0, 0, 0, &m_audioUnit); if (ret) { CLog::Log(LOGERROR, "CCoreAudioGraph::Open: " "Error getting m_outputNode. Error = %s", GetError(ret).c_str()); return false; } m_audioGraph = audioGraph; m_Initialized = true; return true; }
/* This call creates the Graph and the Synth unit... */ static OSStatus CreateAUGraph(void) { OSStatus result; /* Create the nodes of the graph */ AUNode synthNode, limiterNode, outNode; ComponentDescription cd; cd.componentManufacturer = kAudioUnitManufacturer_Apple; cd.componentFlags = 0; cd.componentFlagsMask = 0; result = NewAUGraph(&s_graph); if (result != 0) return result; cd.componentType = kAudioUnitType_MusicDevice; cd.componentSubType = kAudioUnitSubType_DLSSynth; result = AUGraphNewNode(s_graph, &cd, 0, NULL, &synthNode); if (result != 0) return result; cd.componentType = kAudioUnitType_Effect; cd.componentSubType = kAudioUnitSubType_PeakLimiter; result = AUGraphNewNode(s_graph, &cd, 0, NULL, &limiterNode); if (result != 0) return result; cd.componentType = kAudioUnitType_Output; cd.componentSubType = kAudioUnitSubType_DefaultOutput; result = AUGraphNewNode(s_graph, &cd, 0, NULL, &outNode); if (result != 0) return result; result = AUGraphOpen(s_graph); if (result != 0) return result; result = AUGraphConnectNodeInput(s_graph, synthNode, 0, limiterNode, 0); if (result != 0) return result; result = AUGraphConnectNodeInput(s_graph, limiterNode, 0, outNode, 0); if (result != 0) return result; /* Ok we're good to go - get the Synth Unit... */ result = AUGraphGetNodeInfo(s_graph, synthNode, 0, 0, 0, &s_synthUnit); return result; }
OSStatus CAPlayThrough::MakeGraph() { OSStatus err = noErr; ComponentDescription varispeedDesc,outDesc; //Q:Why do we need a varispeed unit? //A:If the input device and the output device are running at different sample rates //we will need to move the data coming to the graph slower/faster to avoid a pitch change. varispeedDesc.componentType = kAudioUnitType_FormatConverter; varispeedDesc.componentSubType = kAudioUnitSubType_Varispeed; varispeedDesc.componentManufacturer = kAudioUnitManufacturer_Apple; varispeedDesc.componentFlags = 0; varispeedDesc.componentFlagsMask = 0; outDesc.componentType = kAudioUnitType_Output; outDesc.componentSubType = kAudioUnitSubType_DefaultOutput; outDesc.componentManufacturer = kAudioUnitManufacturer_Apple; outDesc.componentFlags = 0; outDesc.componentFlagsMask = 0; ////////////////////////// ///MAKE NODES //This creates a node in the graph that is an AudioUnit, using //the supplied ComponentDescription to find and open that unit err = AUGraphNewNode(mGraph, &varispeedDesc, 0, NULL, &mVarispeedNode); checkErr(err); err = AUGraphNewNode(mGraph, &outDesc, 0, NULL, &mOutputNode); checkErr(err); //Get Audio Units from AUGraph node err = AUGraphGetNodeInfo(mGraph, mVarispeedNode, NULL, NULL, NULL, &mVarispeedUnit); checkErr(err); err = AUGraphGetNodeInfo(mGraph, mOutputNode, NULL, NULL, NULL, &mOutputUnit); checkErr(err); // don't connect nodes until the varispeed unit has input and output formats set return err; }
// This call creates the Graph and the Synth unit... OSStatus CreateAUGraph (AUGraph &outGraph, AudioUnit &outSynth) { OSStatus result; //create the nodes of the graph AUNode synthNode, limiterNode, outNode; ComponentDescription cd; cd.componentManufacturer = kAudioUnitManufacturer_Apple; cd.componentFlags = 0; cd.componentFlagsMask = 0; require_noerr (result = NewAUGraph (&outGraph), home); cd.componentType = kAudioUnitType_MusicDevice; cd.componentSubType = kAudioUnitSubType_DLSSynth; require_noerr (result = AUGraphNewNode (outGraph, &cd, 0, NULL, &synthNode), home); cd.componentType = kAudioUnitType_Effect; cd.componentSubType = kAudioUnitSubType_PeakLimiter; require_noerr (result = AUGraphNewNode (outGraph, &cd, 0, NULL, &limiterNode), home); cd.componentType = kAudioUnitType_Output; cd.componentSubType = kAudioUnitSubType_DefaultOutput; require_noerr (result = AUGraphNewNode (outGraph, &cd, 0, NULL, &outNode), home); require_noerr (result = AUGraphOpen (outGraph), home); require_noerr (result = AUGraphConnectNodeInput (outGraph, synthNode, 0, limiterNode, 0), home); require_noerr (result = AUGraphConnectNodeInput (outGraph, limiterNode, 0, outNode, 0), home); // ok we're good to go - get the Synth Unit... require_noerr (result = AUGraphGetNodeInfo(outGraph, synthNode, 0, 0, 0, &outSynth), home); home: return result; }
MidiDevice * openMidiDevice (int errorLevel, const char *device) { MidiDevice *midi; int result; AUNode synthNode, outNode; ComponentDescription cd; UInt32 propVal; if (!(midi = malloc(sizeof(*midi)))) { logMallocError(); return NULL; } /* Create a graph with a software synth and a default output unit. */ cd.componentManufacturer = kAudioUnitManufacturer_Apple; cd.componentFlags = 0; cd.componentFlagsMask = 0; if ((result = NewAUGraph(&midi->graph)) != noErr) { logMessage(errorLevel, "Can't create audio graph component: %d", result); goto err; } cd.componentType = kAudioUnitType_MusicDevice; cd.componentSubType = kAudioUnitSubType_DLSSynth; if ((result = AUGraphNewNode(midi->graph, &cd, 0, NULL, &synthNode)) != noErr) { logMessage(errorLevel, "Can't create software synthersizer component: %d", result); goto err; } cd.componentType = kAudioUnitType_Output; cd.componentSubType = kAudioUnitSubType_DefaultOutput; if ((result = AUGraphNewNode(midi->graph, &cd, 0, NULL, &outNode)) != noErr) { logMessage(errorLevel, "Can't create default output audio component: %d", result); goto err; } if ((result = AUGraphOpen(midi->graph)) != noErr) { logMessage(errorLevel, "Can't open audio graph component: %d", result); goto err; } if ((result = AUGraphConnectNodeInput(midi->graph, synthNode, 0, outNode, 0)) != noErr) { logMessage(errorLevel, "Can't connect synth audio component to output: %d", result); goto err; } if ((result = AUGraphGetNodeInfo(midi->graph, synthNode, 0, 0, 0, &midi->synth)) != noErr) { logMessage(errorLevel, "Can't get audio component for software synth: %d", result); goto err; } if ((result = AUGraphInitialize(midi->graph)) != noErr) { logMessage(errorLevel, "Can't initialize audio graph: %d", result); goto err; } /* Turn off the reverb. The value range is -120 to 40 dB. */ propVal = false; if ((result = AudioUnitSetProperty(midi->synth, kMusicDeviceProperty_UsesInternalReverb, kAudioUnitScope_Global, 0, &propVal, sizeof(propVal))) != noErr) { /* So, having reverb isn't that critical, is it? */ logMessage(LOG_DEBUG, "Can't turn of software synth reverb: %d", result); } /* TODO: Maybe just start the graph when we are going to use it? */ if ((result = AUGraphStart(midi->graph)) != noErr) { logMessage(errorLevel, "Can't start audio graph component: %d", result); goto err; } return midi; err: if (midi->graph) DisposeAUGraph(midi->graph); free(midi); return NULL; }
int main(int argc, char *argv[]) { WindowRef window; HIViewRef content; HIViewRef combo; HIViewRef group; HIViewRef check; HIViewRef text; HIViewRef slider; HIViewRef quit; MenuRef menu; HIRect rect; // Window bounds Rect bounds = {0, 0, 436, 590}; // Create window CreateNewWindow(kDocumentWindowClass, kWindowStandardFloatingAttributes | kWindowStandardHandlerAttribute | kWindowInWindowMenuAttribute | kWindowCompositingAttribute, &bounds, &window); // Set the title SetWindowTitleWithCFString(window, CFSTR("Accordion")); // Create an application menu CreateNewMenu(0, 0, &menu); // Set menu title SetMenuTitleWithCFString(menu, CFStringCreateWithPascalString(kCFAllocatorDefault, "\p\024", kCFStringEncodingMacRoman)); // Create an about item InsertMenuItemTextWithCFString(menu, CFSTR("About Accordion"), 0, 0, kHICommandAbout); // Insert the menu InsertMenu(menu, 0); // Create a standard window menu CreateStandardWindowMenu(0, &menu); // Insert the menu InsertMenu(menu, 0); // Show and position the window ShowWindow(window); RepositionWindow(window, NULL, kWindowCascadeOnMainScreen); // Find the window content HIViewFindByID(HIViewGetRoot(window), kHIViewWindowContentID, &content); // Set bounds for group box bounds.bottom = 92; bounds.right = 550; // Create group box CreateGroupBoxControl(window, &bounds, NULL, true, &group); // Place in the window HIViewAddSubview(content, group); HIViewPlaceInSuperviewAt(group, 20, 20); // Bounds of text bounds.bottom = 16; bounds.right = 74; // Create static text CreateStaticTextControl(window, &bounds, CFSTR("Instrument:"), NULL, &text); // Place in the group box HIViewAddSubview(group, text); HIViewPlaceInSuperviewAt(text, 16, 18); // Bounds of combo box rect.size.height = 20; rect.size.width = 168; // Create combo box HIComboBoxCreate(&rect, CFSTR(" Accordion"), NULL, NULL, kHIComboBoxStandardAttributes, &combo); // Set visible and set command ID HIViewSetVisible(combo, true); HIViewSetCommandID(combo, kCommandInst); // Add the instruments for (int i = 0; i < Length(instruments); i++) { HIComboBoxAppendTextItem(combo, CFStringCreateWithCString(kCFAllocatorDefault, instruments[i], kCFStringEncodingMacRoman), NULL); // Set the current instrument if (strcmp(instruments[i], " Accordion") == 0) instrument = i; } // Place in the group box HIViewAddSubview(group, combo); HIViewPlaceInSuperviewAt(combo, 102, 16); // Bounds of check box bounds.bottom = 18; bounds.right = 121; // Create check box CreateCheckBoxControl(window, &bounds, CFSTR("Reverse"), false, true, &check); // Set the control ID and the command ID HIViewSetID(check, kHIViewIDReverse); HIViewSetCommandID(check, kCommandReverse); // Place in the group box HIViewAddSubview(group, check); HIViewPlaceInSuperviewAt(check, 286, 17); // Bounds of text bounds.bottom = 16; bounds.right = 32; // Create static text CreateStaticTextControl(window, &bounds, CFSTR("Key:"), NULL, &text); // Place in the group box HIViewAddSubview(group, text); HIViewPlaceInSuperviewAt(text, 400, 18); // Bounds of combo box rect.size.width = 90; // Create combo box HIComboBoxCreate(&rect, CFSTR(" A/D/G"), NULL, NULL, kHIComboBoxStandardAttributes, &combo); // Set visible and set command ID HIViewSetVisible(combo, true); HIViewSetID(combo, kHIViewIDKey); HIViewSetCommandID(combo, kCommandKey); // Add keys for (int i = 0; i < Length(keys); i++) { HIComboBoxAppendTextItem(combo, CFStringCreateWithCString(kCFAllocatorDefault, keys[i], kCFStringEncodingMacRoman), NULL); // Set current key if (strcmp(keys[i], " A/D/G") == 0) key = i; } // Place in the group box HIViewAddSubview(group, combo); HIViewPlaceInSuperviewAt(combo, 440, 16); // Bounds of text bounds.bottom = 16; bounds.right = 54; // Create static text CreateStaticTextControl(window, &bounds, CFSTR("Volume:"), NULL, &text); // Place in the group box HIViewAddSubview(group, text); HIViewPlaceInSuperviewAt(text, 16, 56); // Bounds of slider bounds.bottom = 16; bounds.right = 168; // Create slider CreateSliderControl(window, &bounds, MAXVOL, 0, MAXVOL, kControlSliderDoesNotPoint, 0, false, NULL, &slider); // Set command ID HIViewSetCommandID(slider, kCommandVolume); // Place in the group box HIViewAddSubview(group, slider); HIViewPlaceInSuperviewAt(slider, 100, 58); // Bounds of check box bounds.bottom = 18; bounds.right = 121; // Create check box CreateCheckBoxControl(window, &bounds, CFSTR("Notes"), false, true, &check); // Set the control ID and the command ID HIViewSetID(check, kHIViewIDNote); HIViewSetCommandID(check, kCommandNote); // Place in the group box HIViewAddSubview(group, check); HIViewPlaceInSuperviewAt(check, 286, 56); // Bounds of push button bounds.bottom = 20; bounds.right = 90; // Create push button CreatePushButtonControl(window, &bounds, CFSTR("Quit"), &quit); // Set command ID HIViewSetCommandID(quit, kHICommandQuit); // Place in the group box HIViewAddSubview(group, quit); HIViewPlaceInSuperviewAt(quit, 440, 54); // Group box bounds bounds.bottom = 48; bounds.right = 550; // Create group box CreateGroupBoxControl(window, &bounds, NULL, true, &group); // Place in the window HIViewAddSubview(content, group); HIViewPlaceInSuperviewAt(group, 20, 132); // Font style ControlFontStyleRec style; style.flags = kControlUseFontMask|kControlUseJustMask; style.font = kControlFontBigSystemFont; style.just = teCenter; // Bounds of text bounds.bottom = 16; bounds.right = 550; // Create static text CreateStaticTextControl(window, &bounds, CFSTR("Accordion"), &style, &text); // Place in the group box HIViewAddSubview(group, text); HIViewPlaceInSuperviewAt(text, 0, 8); // Bounds of text bounds.bottom = 16; bounds.right = 550; // Create static text CreateStaticTextControl(window, &bounds, CFSTR("Play accordion on your keyboard"), &style, &text); // Place in the group box HIViewAddSubview(group, text); HIViewPlaceInSuperviewAt(text, 0, 24); // Group box bounds bounds.bottom = 196; bounds.right = 550; // Create group box CreateGroupBoxControl(window, &bounds, NULL, true, &group); // Place in the window HIViewAddSubview(content, group); HIViewPlaceInSuperviewAt(group, 20, 200); // Button bounds bounds.bottom = SIZE; bounds.right = SIZE; // Create row of bass buttons for (int i = 0; i < Length(bassdisplay); i++) { int x = 15 + 44 * i; int y = 15; // Create button CreateBevelButtonControl(window, &bounds, NULL, kControlBevelButtonNormalBevel, kControlBehaviorPushbutton, NULL, 0, 0, 0, &bassdisplay[i]); // Place in the group box HIViewAddSubview(group, bassdisplay[i]); HIViewPlaceInSuperviewAt(bassdisplay[i], x, y); } // Create three rows of buttons for (int i = 0; i < Length(display); i++) { for (int j = 0; j < ((i == 1)? Length(display[i]): Length(display[i]) - 1); j++) { int x = (i == 1)? 37 + 44 * j: 59 + 44 * j; int y = 59 + 44 * i; // Create button CreateBevelButtonControl(window, &bounds, NULL, kControlBevelButtonNormalBevel, kControlBehaviorPushbutton, NULL, 0, 0, 0, &display[i][j]); // Place in the group box HIViewAddSubview(group, display[i][j]); HIViewPlaceInSuperviewAt(display[i][j], x, y); } } // Create spacebar button CreateBevelButtonControl(window, &bounds, NULL, kControlBevelButtonNormalBevel, kControlBehaviorPushbutton, NULL, 0, 0, 0, &spacebar); // Place in the group box HIViewAddSubview(group, spacebar); HIViewPlaceInSuperviewAt(spacebar, 16, 147); // Group box bounds, wider than the window to hide rounded corners bounds.bottom = 20; bounds.right = 598; // Create group box for fake status bar CreateGroupBoxControl(window, &bounds, NULL, false, &group); // Place in window at negative offset to hide rounded corners HIViewAddSubview(content, group); HIViewPlaceInSuperviewAt(group, -4, 416); // Text bounds bounds.bottom = 16; bounds.right = 590; // Font style style.flags = kControlUseFontMask|kControlUseJustMask; style.font = kControlFontSmallSystemFont; style.just = teCenter; // Create static text CreateStaticTextControl(window, &bounds, CFSTR("Press the keyboard keys as accordion buttons " "and the space bar as the bellows. 3rd button start."), &style, &text); // Place in group box HIViewAddSubview(group, text); HIViewPlaceInSuperviewAt(text, 0, 2); // Application events type spec EventTypeSpec applicationEvents[] = {{kEventClassApplication, kEventAppFrontSwitched}}; // Install event handler InstallApplicationEventHandler(NewEventHandlerUPP(ApplicationHandler), Length(applicationEvents), applicationEvents, NULL, NULL); // Mouse events type spec EventTypeSpec mouseEvents[] = {{kEventClassMouse, kEventMouseDown}}; // Install event handler on the event dispatcher, so that we can // see mouse events before the default handler gets them InstallEventHandler(GetEventDispatcherTarget(), NewEventHandlerUPP(MouseHandler), Length(mouseEvents), mouseEvents, NULL, NULL); // Window events type spec EventTypeSpec windowEvents[] = {{kEventClassWindow, kEventWindowClose}}; // Install event handler InstallWindowEventHandler(window, NewEventHandlerUPP(WindowHandler), Length(windowEvents), windowEvents, NULL, NULL); // Combo box events type spec EventTypeSpec comboBoxEvents[] = {{kEventClassHIComboBox, kEventComboBoxListItemSelected}}; // Install event handler InstallApplicationEventHandler(NewEventHandlerUPP(ComboBoxHandler), Length(comboBoxEvents), comboBoxEvents, NULL, NULL); // Command events type spec EventTypeSpec commandEvents[] = {{kEventClassCommand, kEventCommandProcess}}; // Install event handler InstallApplicationEventHandler(NewEventHandlerUPP(CommandHandler), Length(commandEvents), commandEvents, NULL, NULL); // Keyboard events type spec EventTypeSpec keyboardEvents[] = {{kEventClassKeyboard, kEventRawKeyDown}, {kEventClassKeyboard, kEventRawKeyUp}, {kEventClassKeyboard, kEventRawKeyModifiersChanged}}; // Install event handler on the event dispatcher InstallEventHandler(GetEventDispatcherTarget(), NewEventHandlerUPP(KeyboardHandler), Length(keyboardEvents), keyboardEvents, NULL, NULL); // Audio Unit graph AUGraph graph; // Audio Unit synthesizer and output node AUNode synthNode; AUNode outNode; // Component description ComponentDescription cd; cd.componentManufacturer = kAudioUnitManufacturer_Apple; cd.componentFlags = 0; cd.componentFlagsMask = 0; do { // New AU graph OSStatus status = NewAUGraph(&graph); if (status != noErr) { DisplayAlert(CFSTR("NewAUGraph"), CFSTR("Can't create a new AUGraph"), status); break; } // Synthesizer cd.componentType = kAudioUnitType_MusicDevice; cd.componentSubType = kAudioUnitSubType_DLSSynth; // New synthesizer node status = AUGraphNewNode(graph, &cd, 0, NULL, &synthNode); if (status != noErr) { DisplayAlert(CFSTR("AUGraphNewNode"), CFSTR("Can't create a new AUGraph node"), status); break; } // Output cd.componentType = kAudioUnitType_Output; cd.componentSubType = kAudioUnitSubType_DefaultOutput; // New output node status = AUGraphNewNode(graph, &cd, 0, NULL, &outNode); if (status != noErr) { DisplayAlert(CFSTR("AUGraphNewNode"), CFSTR("Can't create a new AUGraph node"), status); break; } // Open graph status = AUGraphOpen(graph); if (status != noErr) { DisplayAlert(CFSTR("AUGraphOpen"), CFSTR("Can't open AUGraph"), status); break; } // Connect synthesizer node to output node status = AUGraphConnectNodeInput(graph, synthNode, 0, outNode, 0); if (status != noErr) { DisplayAlert(CFSTR("AUGraphConnectNodeInput"), CFSTR("Can't connect AUGraph input node"), status); break; } // Get a synthesizer unit status = AUGraphGetNodeInfo(graph, synthNode, NULL, 0, NULL, &synthUnit); if (status != noErr) { DisplayAlert(CFSTR("AUGraphGetNodeInfo"), CFSTR("Can't get AUGraph node info"), status); break; } // Initialise status = AUGraphInitialize(graph); if (status != noErr) { DisplayAlert(CFSTR("AUGraphInitialize"), CFSTR("Can't initialize AUGraph"), status); break; } // Start status = AUGraphStart(graph); if (status != noErr) { DisplayAlert(CFSTR("AUGraphStart"), CFSTR("Can't start AUGraph"), status); break; } // Show the graph // CAShow(graph); } while (false); // Change instrument ChangeInstrument(instrument); // Run the application event loop RunApplicationEventLoop(); // Stop the graph AUGraphStop(graph); // Dispose of the graph DisposeAUGraph(graph); // Exit return 0; }
int MidiDriver_CORE::open() { OSStatus err = 0; if (isOpen()) return MERR_ALREADY_OPEN; // Open the Music Device. RequireNoErr(NewAUGraph(&_auGraph)); AUNode outputNode, synthNode; #if USE_DEPRECATED_COREAUDIO_API ComponentDescription desc; #else AudioComponentDescription desc; #endif // The default output device desc.componentType = kAudioUnitType_Output; desc.componentSubType = kAudioUnitSubType_DefaultOutput; desc.componentManufacturer = kAudioUnitManufacturer_Apple; desc.componentFlags = 0; desc.componentFlagsMask = 0; #if USE_DEPRECATED_COREAUDIO_API RequireNoErr(AUGraphNewNode(_auGraph, &desc, 0, NULL, &outputNode)); #else RequireNoErr(AUGraphAddNode(_auGraph, &desc, &outputNode)); #endif // The built-in default (softsynth) music device desc.componentType = kAudioUnitType_MusicDevice; desc.componentSubType = kAudioUnitSubType_DLSSynth; desc.componentManufacturer = kAudioUnitManufacturer_Apple; #if USE_DEPRECATED_COREAUDIO_API RequireNoErr(AUGraphNewNode(_auGraph, &desc, 0, NULL, &synthNode)); #else RequireNoErr(AUGraphAddNode(_auGraph, &desc, &synthNode)); #endif // Connect the softsynth to the default output RequireNoErr(AUGraphConnectNodeInput(_auGraph, synthNode, 0, outputNode, 0)); // Open and initialize the whole graph RequireNoErr(AUGraphOpen(_auGraph)); RequireNoErr(AUGraphInitialize(_auGraph)); // Get the music device from the graph. #if USE_DEPRECATED_COREAUDIO_API RequireNoErr(AUGraphGetNodeInfo(_auGraph, synthNode, NULL, NULL, NULL, &_synth)); #else RequireNoErr(AUGraphNodeInfo(_auGraph, synthNode, NULL, &_synth)); #endif // Load custom soundfont, if specified if (ConfMan.hasKey("soundfont")) { FSRef fsref; FSSpec fsSpec; const char *soundfont = ConfMan.get("soundfont").c_str(); err = FSPathMakeRef ((const byte *)soundfont, &fsref, NULL); if (err == noErr) { err = FSGetCatalogInfo (&fsref, kFSCatInfoNone, NULL, NULL, &fsSpec, NULL); } if (err == noErr) { // TODO: We should really check here whether the file contains an // actual soundfont... err = AudioUnitSetProperty ( _synth, kMusicDeviceProperty_SoundBankFSSpec, kAudioUnitScope_Global, 0, &fsSpec, sizeof(fsSpec) ); } if (err != noErr) warning("Failed loading custom sound font '%s' (error %ld)\n", soundfont, (long)err); } #ifdef COREAUDIO_DISABLE_REVERB // Disable reverb mode, as that sucks up a lot of CPU power, which can // be painful on low end machines. // TODO: Make this customizable via a config key? UInt32 usesReverb = 0; AudioUnitSetProperty (_synth, kMusicDeviceProperty_UsesInternalReverb, kAudioUnitScope_Global, 0, &usesReverb, sizeof (usesReverb)); #endif // Finally: Start the graph! RequireNoErr(AUGraphStart(_auGraph)); return 0; bail: if (_auGraph) { AUGraphStop(_auGraph); DisposeAUGraph(_auGraph); _auGraph = 0; } return MERR_CANNOT_CONNECT; }
void I_InitMusic (void) { #ifdef UNIX struct stat buf; if(stat("/etc/timidity.cfg", &buf) && stat("/etc/timidity/timidity.cfg", &buf)) Args.AppendArg("-nomusic"); #endif if(Args.CheckParm("-nomusic")) { Printf (PRINT_HIGH, "I_InitMusic: Music playback disabled\n"); return; } #ifdef OSX NewAUGraph(&graph); ComponentDescription d; d.componentType = kAudioUnitType_MusicDevice; d.componentSubType = kAudioUnitSubType_DLSSynth; d.componentManufacturer = kAudioUnitManufacturer_Apple; d.componentFlags = 0; d.componentFlagsMask = 0; AUGraphNewNode(graph, &d, 0, NULL, &synth); d.componentType = kAudioUnitType_Output; d.componentSubType = kAudioUnitSubType_DefaultOutput; d.componentManufacturer = kAudioUnitManufacturer_Apple; d.componentFlags = 0; d.componentFlagsMask = 0; AUGraphNewNode(graph, &d, 0, NULL, &output); if(AUGraphConnectNodeInput(graph, synth, 0, output, 0) != noErr) { Printf (PRINT_HIGH, "I_InitMusic: AUGraphConnectNodeInput failed\n"); return; } if(AUGraphOpen(graph) != noErr) { Printf (PRINT_HIGH, "I_InitMusic: AUGraphOpen failed\n"); return; } if(AUGraphInitialize(graph) != noErr) { Printf (PRINT_HIGH, "I_InitMusic: AUGraphInitialize failed\n"); return; } if(AUGraphGetNodeInfo(graph, output, NULL, NULL, NULL, &unit) != noErr) { Printf (PRINT_HIGH, "I_InitMusic: AUGraphGetNodeInfo failed\n"); return; } if(NewMusicPlayer(&player) != noErr) { Printf (PRINT_HIGH, "I_InitMusic: Music player creation failed using AudioToolbox\n"); return; } Printf (PRINT_HIGH, "I_InitMusic: Music playback enabled using AudioToolbox\n"); #else Printf (PRINT_HIGH, "I_InitMusic: Music playback enabled\n"); #endif music_initialized = true; }
JNIEXPORT jint JNICALL Java_com_apple_audio_toolbox_AUGraph_AUGraphNewNode (JNIEnv *, jclass, jint inGraph, jint inDescription, jint inClassDataLength, jint inClassData, jint outNode) { return (jint)AUGraphNewNode((AUGraph)inGraph, (ComponentDescription *)inDescription, (UInt32)inClassDataLength, (const void *)inClassData, (AUNode *)outNode); }
int QBSoundMac::initGraph() { OSStatus err; mAudioFormat.mSampleRate = 44100.000000; mAudioFormat.mFormatID = kAudioFormatLinearPCM; #ifdef __FLOAT_BUFFER__ mAudioFormat.mFormatFlags = 0 | kLinearPCMFormatFlagIsPacked | kLinearPCMFormatFlagIsFloat #if __BIG_ENDIAN__ | kLinearPCMFormatFlagIsBigEndian #endif ; mAudioFormat.mBytesPerPacket = 8; mAudioFormat.mFramesPerPacket = 1; mAudioFormat.mBytesPerFrame = 8; mAudioFormat.mChannelsPerFrame = 2; mAudioFormat.mBitsPerChannel = 32; mAudioFormat.mReserved = 0; #else mAudioFormat.mFormatFlags = 0 | kLinearPCMFormatFlagIsPacked | kLinearPCMFormatFlagIsSignedInteger #if __BIG_ENDIAN__ | kLinearPCMFormatFlagIsBigEndian #endif ; mAudioFormat.mBytesPerPacket = 4; mAudioFormat.mFramesPerPacket = 1; mAudioFormat.mBytesPerFrame = 4; mAudioFormat.mChannelsPerFrame = 2; mAudioFormat.mBitsPerChannel = 16; mAudioFormat.mReserved = 0; #endif err = NewAUGraph(&mGraph); #if !TARGET_OS_IPHONE AudioComponentDescription description; description.componentSubType = kAudioUnitSubType_DefaultOutput; #else AudioComponentDescription description; description.componentSubType = kAudioUnitSubType_RemoteIO; #endif description.componentType = kAudioUnitType_Output; description.componentManufacturer = kAudioUnitManufacturer_Apple; description.componentFlags = 0; description.componentFlagsMask = 0; #if 1 err = AUGraphAddNode(mGraph,&description,&mOutputNode); #else err = AUGraphNewNode(mGraph,&description, 0, NULL, &mOutputNode); #endif err = AUGraphOpen(mGraph); #if 1 err = AUGraphNodeInfo(mGraph,mOutputNode,NULL,&mAudioUnit); #else err = AUGraphGetNodeInfo(mGraph,mOutputNode,NULL,NULL,NULL,&mAudioUnit); #endif err = AudioUnitSetProperty(mAudioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &mAudioFormat, sizeof(AudioStreamBasicDescription)); { AURenderCallbackStruct input; input.inputProc = callback; input.inputProcRefCon = this; err = AudioUnitSetProperty(mAudioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &input, sizeof(input)); } // { // AudioUnitSetParameter (mAudioUnit, // kHALOutputParam_Volume, // kAudioUnitScope_Global,0,1,0); // } err = AUGraphInitialize(mGraph); //err = AUGraphStart(mGraph); //pthread_mutex_init(&mLoaderThreadMutex,NULL); #ifdef __USE_OGG_VORBIS__ mThreadEnd = false; pthread_create(&mLoaderThread,NULL,LoaderThreadProc,this); #endif // mOpenGraph = false; // mInitGraph = false; // startAUGraph(); //printf("openAUGraph\n"); return err; }