Previous Book Contents Book Index Next

Inside Macintosh: Sound /
Chapter 6 - Audio Components / Writing an Audio Component


Legacy Documentclose button

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.

Creating an Audio Component

An audio component is a component. It contains a number of resources, including icons, strings, and the standard component resource (a resource of type 'thng') required of any Component Manager component. In addition, an audio component must contain code to handle required selectors passed to it by the Component Manager as well as selectors specific to the audio component.

Note
For complete details on components and their structure, see the chapter "Component Manager" in Inside Macintosh: More Macintosh Toolbox. This section provides specific information about audio components.
The component resource binds together all the relevant resources contained in a component; its structure is defined by the ComponentResource data type.

struct ComponentResource {
   ComponentDescription    cd;
   ResourceSpec            component;
   ResourceSpec            componentName
   ResourceSpec            componentInfo;
   ResourceSpec            componentIcon;
};
The component field specifies the resource type and resource ID of the component's executable code. By convention, this field should be set to the value kAudioCodeType.

#define kAudioCodeType     'adio'   /*audio component code type*/
(You can, however, specify some other resource type if you wish.) The resource ID can be any integer greater than or equal to 128. See the following section for further information about this code resource.

The componentName field specifies the resource type and resource ID of the resource that contains the component's name. Usually the name is contained in a resource of type 'STR '. This string should be as short as possible.

The componentInfo field specifies the resource type and resource ID of the resource that contains a description of the component. Usually the description is contained in a resource of type 'STR '.

The componentIcon field specifies the resource type and resource ID of the resource that contains an icon for the component. Usually the icon is contained in a resource of type 'ICON'.

The cd field of the ComponentResource structure is a component description record, which contains additional information about the component. A component description record is defined by the ComponentDescription data type.

typedef struct {
   OSType                  componentType;
   OSType                  componentSubType;
   OSType                  componentManufacturer;
   unsigned long           componentFlags;
   unsigned long           componentFlagsMask;
} ComponentDescription;
For audio components, the componentType field must be set to a value recognized by the Sound Manager.

#define kAudioComponentType      'adio'   /*audio component*/
In addition, the componentSubType field must be set to a value that indicates the type of audio services your component provides. For example, the Apple-supplied audio components have these subtypes:

#define kAwacsPhoneSubType             'hphn'   /*AWACS phone*/
#define kAudioVisionSpeakerSubType     'telc'   /*AudioVision speaker*/
#define kAudioVisionHeadphoneSubType   'telh'   /*AudioVision headphones*/
If you write an audio component, you should define some other subtype.

Note
Apple Computer, Inc., reserves for its own use all types and subtypes composed solely of lowercase letters.
You can assign any value you like to the componentManufacturer field; typically you put the signature of your audio component in this field.

The componentFlags field of the component description for an audio component contains bit flags that encode information about the component. You can use this field to specify that the Component Manager should send your component the kComponentRegisterSelect selector.

enum {
   cmpWantsRegisterMessage    = 1L<<31 /*send register request*/
};
This bit is useful for audio components, which might need to test for the presence of the appropriate hardware to determine whether to register with the Component Manager. When your component gets the kComponentRegisterSelect selector at system startup time, it should make sure that all the necessary hardware is available. If it isn't available, your component shouldn't register.

You should set the componentFlagsMask field to 0.

Your audio component is contained in a resource file. You can assign any type you wish to be the file creator, but the type of the file must be 'thng'. If the audio component contains a 'BNDL' resource, then the file's bundle bit must be set.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
2 JUL 1996