Important: Inside Macintosh: Sound is deprecated as of Mac OS X v10.5. For new audio development in Mac OS X, use Core Audio. See the Audio page in the ADC Reference Library.
Dispatching to Audio Component-Defined Routines
As explained in the previous section, the code stored in the audio component should be contained in a resource of typekAudioCodeType
. The Component Manager expects the entry point in this resource to be a function with this format:
pascal ComponentResult MyAudioDispatch (ComponentParameters *params, AudioGlobalsPtr globals);The Component Manager calls your sound component by passingMyAudioDispatch
a selector in theparams->what
field;MyAudioDispatch
must interpret the selector and possibly dispatch to some other routine in the resource. Your audio component must be able to handle the required selectors, defined by these constants:
#define kComponentOpenSelect -1 #define kComponentCloseSelect -2 #define kComponentCanDoSelect -3 #define kComponentVersionSelect -4 #define kComponentRegisterSelect -5 #define kComponentTargetSelect -6 #define kComponentUnregisterSelect -7In addition, your audio component must be able to respond to component-specific selectors. The Sound Manager can pass these selectors to your audio component:
- Note
- For complete details on required component selectors, see the chapter "Component Manager" in Inside Macintosh: More Macintosh Toolbox.
enum { kAudioGetVolumeSelect = 0, kAudioSetVolumeSelect, kAudioGetMuteSelect, kAudioSetMuteSelect, kAudioSetToDefaultsSelect, kAudioGetInfoSelect };You can respond to these selectors by calling the Component Manager routineCallComponentFunctionWithStorage
. See the section "Audio Component-Defined Routines" beginning on page 6-9 for information on how to handle these selectors.In all likelihood, your component is loaded into the system heap, although it might be loaded into an application heap if memory is low in the system heap. You can call the Component Manager function GetComponentInstanceA5 to determine the A5 value of the current application. If this function returns 0, your component is in the system heap; otherwise, your component is in an application's heap. Its location might affect how you allocate memory. For example, calling the MoveHHi routine on handles in the system heap has no result. Thus, you should either call the ReserveMemSys routine before calling NewHandleSys (so that the handle is allocated as low in the system heap as possible) or else just allocate a nonrelocatable block by calling the
NewPtrSys
routine.If you need to access resources that are stored in your audio component, you can use
OpenComponentResFile
andCloseComponentResFile
.OpenComponentResFile
requires theComponentInstance
parameter supplied to your routine. You should not call Resource Manager routines such asOpenResFile
orCloseResFile
.
- WARNING
- Do not leave any resource files open when your audio component is closed. Their maps will be left in the subheap when the subheap is freed, causing the Resource Manager to crash.