3
(******************************************************************************
5
* Copyright (c) 1995-2000 Palm, Inc. or its subsidiaries.
10
* Release: Palm OS SDK 4.0 (63220)
13
* Include file for Sound Manager
16
* 4/11/95 VMK - Created by Vitaly Kruglikov
18
*****************************************************************************)
24
uses palmos, coretraps, errorbase, preferences;
26
(************************************************************
27
* Sound Manager constants
29
*************************************************************)
32
// Sound Manager max and default volume levels
34
//sndVolumeMask = $ff;
35
sndDefaultAmp = sndMaxAmp;
37
sndMidiNameLength = 32; // MIDI track name length *including* NULL terminator
39
(************************************************************
40
* Sound Manager data structures
42
*************************************************************)
45
// Command numbers for SndCommandType's cmd field
51
sndCmdFreqDurationAmp = 1; // play a sound, blocking for the entire duration (except for zero amplitude)
52
// param1 = frequency in Hz
53
// param2 = duration in milliseconds
54
// param3 = amplitude (0 - sndMaxAmp); if 0, will return immediately
56
// Commands added in PilotOS v3.0
58
// Please note that SndDoCmd() in PilotOS before v3.0 will Fatal Error on unknown
59
// commands (anything other than sndCmdFreqDurationAmp). For this reason,
60
// applications wishing to take advantage of these new commands while staying
61
// compatible with the earlier version of the OS, _must_ avoid using these commands
62
// when running on OS versions less thatn v3.0 (see sysFtrNumROMVersion in SystemMgr.h).
63
// Beginning with v3.0, SndDoCmd has been fixed to return sndErrBadParam when an
64
// unknown command is passed.
66
sndCmdNoteOn = Succ(sndCmdFreqDurationAmp); // start a sound given its MIDI key index, max duration and velocity;
67
// the call will not wait for the sound to complete, returning imeediately;
68
// any other sound play request made before this one completes will interrupt it.
69
// param1 = MIDI key index (0-127)
70
// param2 = maximum duration in milliseconds
71
// param3 = velocity (0 - 127) (will be interpolated as amplitude)
73
sndCmdFrqOn = Succ(sndCmdNoteOn); // start a sound given its frequency in Hz, max duration and amplitude;
74
// the call will not wait for the sound to complete, returning imeediately;
75
// any other sound play request made before this one completes will interrupt it.
76
// param1 = frequency in Hz
77
// param2 = maximum duration in milliseconds
78
// param3 = amplitude (0 - sndMaxAmp)
80
sndCmdQuiet = Succ(sndCmdFrqOn); // stop current sound
86
// SndCommandType: used by SndDoCmd()
90
SndCommandType = record
91
cmd: SndCmdIDType; // command id
93
param1: Int32; // first parameter
94
param2: UInt16; // second parameter
95
param3: UInt16; // third parameter
98
SndCommandPtr = ^SndCommandType;
101
// Beep numbers used by SndSysBeep()
105
SndSysBeepType = Enum;
109
sndWarning = Succ(sndInfo);
110
sndError = Succ(sndWarning);
111
sndStartUp = Succ(sndError);
112
sndAlarm = Succ(sndStartUp);
113
sndConfirmation = Succ(sndAlarm);
114
sndClick = Succ(sndConfirmation);
116
(************************************************************
117
* Standard MIDI File (SMF) support structures
118
*************************************************************)
120
// Structure of records in the MIDI sound database:
122
// Each MIDI record consists of a record header followed immediately by the
123
// Standard MIDI File (SMF) data stream. Only SMF format #0 is presently supported.
124
// The first byte of the record header is the byte offset from the beginning of the record
125
// to the SMF data stream. The name of the record follows the byte offset
126
// field. sndMidiNameLength is the limit on name size (including NULL).
129
sndMidiRecSignature = Rsc('PMrc');
132
SndMidiRecHdrType = record
133
signature: UInt32; // set to sndMidiRecSignature
134
bDataOffset: UInt8; // offset from the beginning of the record
135
// to the Standard Midi File data stream
136
reserved: UInt8; // set to zero
139
SndMidiRecType = record
140
hdr: SndMidiRecHdrType; // offset from the beginning of the record
141
// to the Standard Midi File data stream
142
name: array [0..2-1] of Char; // Track name: 1 or more chars including NULL terminator.
143
// If a track has no name, the NULL character must still
145
// Set to 2 to pad the structure out to a word boundary.
148
// Midi records found by SndCreateMidiList.
149
SndMidiListItemType = record
150
name: array [0..sndMidiNameLength-1] of Char; // including NULL terminator
156
// Commands for SndPlaySmf
157
SndSmfCmdEnum = Enum;
160
sndSmfCmdPlay = 1; // play the selection
161
sndSmfCmdDuration = Succ(sndSmfCmdPlay); // get the duration in milliseconds of the entire track
164
SndComplFuncType = procedure(chanP: Pointer; dwUserData: UInt32);
165
SndComplFuncPtr = SndComplFuncType;
167
// Return true to continue, false to abort
168
SndBlockingFuncType = function(chanP: Pointer; dwUserData: UInt32; sysTicksAvailable: Int32): Boolean;
169
SndBlockingFuncPtr = SndBlockingFuncType;
172
SndCallbackInfoType = record
173
funcP: MemPtr; // pointer to the callback function (NULL = no function)
174
dwUserData: UInt32; // value to be passed in the dwUserData parameter of the callback function
177
SndSmfCallbacksType = record
178
completion: SndCallbackInfoType; // completion callback function (see SndComplFuncType)
179
blocking: SndCallbackInfoType; // blocking hook callback function (see SndBlockingFuncType)
180
reserved: SndCallbackInfoType; // RESERVED -- SET ALL FIELDS TO ZERO BEFORE PASSING
182
SndSmfCallbacksPtr = ^SndSmfCallbacksType;
185
sndSmfPlayAllMilliSec = $FFFFFFFF;
188
SndSmfOptionsType = record
189
// dwStartMilliSec and dwEndMilliSec are used as inputs to the function for sndSmfCmdPlay and as
190
// outputs for sndSmfCmdDuration
191
dwStartMilliSec: UInt32; // 0 = "start from the beginning"
192
dwEndMilliSec: UInt32; // sndSmfPlayAllMilliSec = "play the entire track";
193
// the default is "play entire track" if this structure
196
// The amplitude and interruptible fields are used only for sndSmfCmdPlay
197
amplitude: UInt16; // relative volume: 0 - sndMaxAmp, inclusively; the default is
198
// sndMaxAmp if this structure is not passed in; if 0, the play will
199
// be skipped and the call will return immediately
201
interruptible: Boolean; // if true, sound play will be interrupted if
202
// user interacts with the controls (digitizer, buttons, etc.);
203
// if false, the paly will not be interrupted; the default behavior
204
// is "interruptible" if this structure is not passed in
207
reserved: UInt32; // RESERVED! -- MUST SET TO ZERO BEFORE PASSING
209
SndSmfOptionsPtr = ^SndSmfOptionsType;
211
SndSmfChanRangeType = record
212
bFirstChan: UInt8; // first MIDI channel (0-15 decimal)
213
bLastChan: UInt8; // last MIDI channel (0-15 decimal)
215
SndSmfChanRangePtr = ^SndSmfChanRangeType;
217
(************************************************************
218
* Sound Manager result codes
219
* (sndErrorClass is defined in SystemMgr.h)
220
*************************************************************)
223
sndErrBadParam = sndErrorClass or 1;
224
sndErrBadChannel = sndErrorClass or 2;
225
sndErrMemory = sndErrorClass or 3;
226
sndErrOpen = sndErrorClass or 4;
227
sndErrQFull = sndErrorClass or 5;
228
sndErrQEmpty = sndErrorClass or 6; // internal
229
sndErrFormat = sndErrorClass or 7; // unsupported data format
230
sndErrBadStream = sndErrorClass or 8; // invalid data stream
231
sndErrInterrupted = sndErrorClass or 9; // play was interrupted
233
(********************************************************************
234
* Sound Manager Routines
235
* These are define as syscall calls only under emulation mode or
236
* under native mode from the module that actually installs the trap
238
********************************************************************)
240
//-------------------------------------------------------------------
242
//-------------------------------------------------------------------
244
// Initializes the Sound Manager. Should only be called by
245
// Pilot initialization code.
246
function SndInit: Err; syscall sysTrapSndInit;
248
// Frees the Sound Manager.
249
//procedure SndFree; syscall sysTrapSndFree;
251
//-------------------------------------------------------------------
253
//-------------------------------------------------------------------
255
// Sets default sound volume levels
257
// Any parameter may be passed as NULL
258
procedure SndSetDefaultVolume(var alarmAmpP, sysAmpP, defAmpP: UInt16); syscall sysTrapSndSetDefaultVolume;
260
// Gets default sound volume levels
262
// Any parameter may be passed as NULL
263
procedure SndGetDefaultVolume(var alarmAmpP, sysAmpP, masterAmpP: UInt16); syscall sysTrapSndGetDefaultVolume;
265
// Executes a sound command on the given sound channel (pass
266
// channelP = 0 to use the shared channel).
267
function SndDoCmd({SndChanPtr} channelP: Pointer; cmdP: SndCommandPtr; noWait: Boolean): Err; syscall sysTrapSndDoCmd;
269
// Plays one of several defined system beeps/sounds (see sndSysBeep...
271
procedure SndPlaySystemSound(beepID: SndSysBeepType); syscall sysTrapSndPlaySystemSound;
274
// Performs an operation on a Standard MIDI File (SMF) Format #0
275
function SndPlaySmf(chanP: Pointer; cmd: SndSmfCmdEnum; var smfP: UInt8; selP: SndSmfOptionsPtr;
276
chanRangeP: SndSmfChanRangePtr; callbacksP: SndSmfCallbacksPtr;
277
bNoWait: Boolean): Err; syscall sysTrapSndPlaySmf;
280
// Creates a list of all midi records. Useful for displaying in lists.
281
// For creator wildcard, pass creator=0;
282
function SndCreateMidiList(creator: UInt32; multipleDBs: Boolean; var wCountP: UInt16; var entHP: MemHandle): Boolean; syscall sysTrapSndCreateMidiList;
285
// Plays a MIDI sound which is read out of an open resource database
286
function SndPlaySmfResource(resType: UInt32; resID: Int16; volumeSelector: SystemPreferencesChoice): Err; syscall sysTrapSndPlaySmfResource;
290
// Plays MIDI sounds regardless of the how the interruptible flag is set
291
function SndPlaySmfIrregardless(chanP: Pointer; cmd: SndSmfCmdEnum; var smfP: UInt8;
292
var selP: SndSmfOptionsType; var chanRangeP: SndSmfChanRangeType;
293
var callbacksP: SndSmfCallbacksType; bNoWait: Boolean): Err; syscall sysTrapSndPlaySmfIrregardless;
295
function SndPlaySmfResourceIrregardless(resType: UInt32; resID: Int16; volumeSelector: SystemPreferencesChoice): Err; syscall sysTrapSndPlaySmfResourceIrregardless;
297
function SndInterruptSmfIrregardless: Err; syscall sysTrapSndInterruptSmfIrregardless;
299
(************************************************************
300
* Sound Manager Macros
302
*************************************************************)