Retired Document
Important: This sample code may not represent best practices for current development. The project may use deprecated symbols and illustrate technologies and techniques that are no longer recommended.
ComponentDispatch.h
/* |
File: ComponentDispatch.h |
Contains: Header for common routines for dispatching for a sound component |
Written by: Mark Cookson |
Copyright: Copyright © 1996-1999 by Apple Computer, Inc., All Rights Reserved. |
You may incorporate this Apple sample source code into your program(s) without |
restriction. This Apple sample source code has been provided "AS IS" and the |
responsibility for its operation is yours. You are not permitted to redistribute |
this Apple sample source code as "Apple sample source code" after having made |
changes. If you're going to re-distribute the source, we require that you make |
it clear in the source that the code was descended from Apple sample source |
code, but that you've made changes. |
Change History (most recent first): |
8/13/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1 |
*/ |
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
// Sound Component Function Prototypes |
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
// component stuff |
#pragma once |
#include <SoundComponents.h> |
#ifdef COMPRESSION |
#define kOutputSampleFormat 'ALAW' // output sample format |
#endif |
#ifdef DECOMPRESSION |
#define kOutputSampleFormat 'twos' // output sample format |
#endif |
#define kMaxOutputSamples 1024 // max no. samples in output buffer |
#define SoundComponentEntryPoint ALAWCompressor |
#define kSoundComponentVersion 0x00010000 // version for this sound component |
#define kRequiredSndMgrMajorRev 3 // Sound Manager version required to run this component |
#define kOutputSampleSize 16 // output sample size |
typedef struct { |
// these are general purpose variables that every sound component will need |
ComponentInstance sourceComponent; // component to call when we need more data |
SoundComponentDataPtr sourceDataPtr; // pointer to source data structure |
SoundComponentData thisComponent; // description of this component's output |
Handle globalsHandle; // handle to component globals |
short outputFrames; // max no. frames in output buffer |
short outputSamples; // max no. samples in output buffer |
CompressionInfo compInfo; // info about compressor |
CompressionInfo destCompInfo; // info about destination |
Boolean reverse; // true if data should be played back in reverse |
Boolean pad1; |
Byte buffer[kMaxOutputSamples * 2]; // room for 8-bit, stereo samples |
} SoundComponentGlobals, *SoundComponentGlobalsPtr; |
#ifdef COMPRESSION |
void InitializeCompressor (SoundComponentGlobalsPtr globals); |
void CompressALaw (short *inbuf, Byte *outbuf, unsigned long framesToConvert, unsigned long numChannels); |
#endif |
#ifdef DECOMPRESSION |
void InitializeDecompressor (SoundComponentGlobalsPtr globals); |
void DecompressALaw (Byte *inbuf, short *outbuf, unsigned long framesToConvert, unsigned long numChannels); |
#endif |
ComponentResult PrimeSource (SoundComponentGlobalsPtr globals); |
void GetCompressorInfo (CompressionInfoPtr cp); |
pascal ComponentResult __SoundComponentOpen(void *unused1, ComponentInstance self); |
pascal ComponentResult __SoundComponentClose(SoundComponentGlobalsPtr globals, ComponentInstance self); |
pascal ComponentResult __SoundComponentRegister(SoundComponentGlobalsPtr globals); |
pascal ComponentResult __SoundComponentCanDo(void *unused1, short selector); |
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
// basic stuff |
pascal ComponentResult __SoundComponentSetSource(SoundComponentGlobalsPtr globals, SoundSource sourceID, ComponentInstance source); |
pascal ComponentResult __SoundComponentGetSourceData(SoundComponentGlobalsPtr globals, SoundComponentDataPtr *sourceData); |
pascal ComponentResult __SoundComponentSetOutput(SoundComponentGlobalsPtr globals, SoundComponentDataPtr requested, SoundComponentDataPtr *actual); |
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
// info methods |
pascal ComponentResult __SoundComponentGetInfo(SoundComponentGlobalsPtr globals, SoundSource sourceID, OSType selector, void *infoPtr); |
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
// control methods |
pascal ComponentResult __SoundComponentStopSource(SoundComponentGlobalsPtr globals, short count, SoundSource *sources); |
pascal ComponentResult __SoundComponentPlaySourceBuffer(SoundComponentGlobalsPtr globals, SoundSource sourceID, SoundParamBlockPtr pb, long actions); |
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
// types |
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
#if GENERATINGPOWERPC |
// These structs are use in PowerMac builds to cast the |
// ComponentParameters passed into our component's entry point. |
enum { |
uppSoundComponentEntryPointProcInfo = kPascalStackBased |
| RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult))) |
| STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ComponentParameters *))) |
| STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(void *))) |
}; |
// These are used to create the routine descriptor to call each function. |
enum { |
upp__SoundComponentOpenProcInfo = kPascalStackBased |
| RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult))) |
| STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(void *))) |
| STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(ComponentInstance))) |
}; |
enum { |
upp__SoundComponentCloseProcInfo = kPascalStackBased |
| RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult))) |
| STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(SoundComponentGlobalsPtr))) |
| STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(ComponentInstance))) |
}; |
enum { |
upp__SoundComponentRegisterProcInfo = kPascalStackBased |
| RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult))) |
| STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(SoundComponentGlobalsPtr))) |
}; |
enum { |
upp__SoundComponentSetSourceProcInfo = kPascalStackBased |
| RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult))) |
| STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(SoundComponentGlobalsPtr))) |
| STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(SoundSource))) |
| STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(ComponentInstance))) |
}; |
enum { |
upp__SoundComponentGetSourceDataProcInfo = kPascalStackBased |
| RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult))) |
| STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(SoundComponentGlobalsPtr))) |
| STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(SoundComponentDataPtr))) |
}; |
enum { |
upp__SoundComponentSetOutputProcInfo = kPascalStackBased |
| RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult))) |
| STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(SoundComponentGlobalsPtr))) |
| STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(SoundComponentDataPtr))) |
| STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(SoundComponentDataPtr))) |
}; |
enum { |
upp__SoundComponentGetInfoProcInfo = kPascalStackBased |
| RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult))) |
| STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(SoundComponentGlobalsPtr))) |
| STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(SoundSource))) |
| STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(OSType))) |
| STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(void *))) |
}; |
enum { |
upp__SoundComponentStopSourceProcInfo = kPascalStackBased |
| RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult))) |
| STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(SoundComponentGlobalsPtr))) |
| STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(short))) |
| STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(SoundSource))) |
}; |
enum { |
upp__SoundComponentPlaySourceBufferProcInfo = kPascalStackBased |
| RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult))) |
| STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(SoundComponentGlobalsPtr))) |
| STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(SoundSource))) |
| STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(SoundParamBlockPtr))) |
| STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(long))) |
}; |
#define CallComponentFunctionWithStorageUniv(storage, params, funcName) \ |
CallComponentFunctionWithStorage(storage, params, &funcName##RD) |
#define CallComponentFunctionUniv(params, funcName) \ |
CallComponentFunction(params, &funcName##RD) |
#define INSTANTIATE_ROUTINE_DESCRIPTOR(funcName) RoutineDescriptor funcName##RD = \ |
BUILD_ROUTINE_DESCRIPTOR (upp##funcName##ProcInfo, funcName) |
INSTANTIATE_ROUTINE_DESCRIPTOR(__SoundComponentRegister); |
INSTANTIATE_ROUTINE_DESCRIPTOR(__SoundComponentClose); |
INSTANTIATE_ROUTINE_DESCRIPTOR(__SoundComponentOpen); |
INSTANTIATE_ROUTINE_DESCRIPTOR(__SoundComponentSetSource); |
INSTANTIATE_ROUTINE_DESCRIPTOR(__SoundComponentGetSourceData); |
INSTANTIATE_ROUTINE_DESCRIPTOR(__SoundComponentSetOutput); |
INSTANTIATE_ROUTINE_DESCRIPTOR(__SoundComponentGetInfo); |
INSTANTIATE_ROUTINE_DESCRIPTOR(__SoundComponentStopSource); |
INSTANTIATE_ROUTINE_DESCRIPTOR(__SoundComponentPlaySourceBuffer); |
#else //GENERATING68K |
#define CallComponentFunctionWithStorageUniv(storage, params, funcName) \ |
CallComponentFunctionWithStorage(storage, params, (ComponentFunctionUPP)funcName) |
#define CallComponentFunctionUniv(params, funcName) \ |
CallComponentFunction(params, (ComponentFunctionUPP)funcName) |
#endif |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-03-14