summaryrefslogtreecommitdiff
path: root/fpcsrc/packages/palmunits/src/soundmgr.pp
blob: c4b9ecf3fc62f0b4de458d6c6ab9ef1dfd570034 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
{$MACRO ON}
{$define Rsc := }
(******************************************************************************
 *
 * Copyright (c) 1995-2000 Palm, Inc. or its subsidiaries.
 * All rights reserved.
 *
 * File: SoundMgr.h
 *
 * Release: Palm OS SDK 4.0 (63220)
 *
 * Description:
 *    Include file for Sound Manager
 *
 * History:
 *    4/11/95  VMK - Created by Vitaly Kruglikov
 *
 *****************************************************************************)

unit soundmgr;

interface

uses palmos, coretraps, errorbase, preferences;

(************************************************************
 * Sound Manager constants
 *
 *************************************************************)

const
// Sound Manager max and default volume levels
  sndMaxAmp         = 64;
//sndVolumeMask     = $ff;
  sndDefaultAmp     = sndMaxAmp;

  sndMidiNameLength = 32; // MIDI track name length *including* NULL terminator

(************************************************************
 * Sound Manager data structures
 *
 *************************************************************)

//
// Command numbers for SndCommandType's cmd field
//
type
  SndCmdIDType = Enum;

const
  sndCmdFreqDurationAmp = 1;                // play a sound, blocking for the entire duration (except for zero amplitude)
                                            // param1 = frequency in Hz
                                            // param2 = duration in milliseconds
                                            // param3 = amplitude (0 - sndMaxAmp); if 0, will return immediately

    // Commands added in PilotOS v3.0
    // ***IMPORTANT***
    // Please note that SndDoCmd() in PilotOS before v3.0 will Fatal Error on unknown
    // commands (anything other than sndCmdFreqDurationAmp).  For this reason,
    // applications wishing to take advantage of these new commands while staying
    // compatible with the earlier version of the OS, _must_ avoid using these commands
    // when running on OS versions less thatn v3.0 (see sysFtrNumROMVersion in SystemMgr.h).
    // Beginning with v3.0, SndDoCmd has been fixed to return sndErrBadParam when an
    // unknown command is passed.

  sndCmdNoteOn = Succ(sndCmdFreqDurationAmp); // start a sound given its MIDI key index, max duration and velocity;
                                            // the call will not wait for the sound to complete, returning imeediately;
                                            // any other sound play request made before this one completes will interrupt it.
                                            // param1 = MIDI key index (0-127)
                                            // param2 = maximum duration in milliseconds
                                            // param3 = velocity (0 - 127) (will be interpolated as amplitude)

  sndCmdFrqOn = Succ(sndCmdNoteOn);         // start a sound given its frequency in Hz, max duration and amplitude;
                                            // the call will not wait for the sound to complete, returning imeediately;
                                            // any other sound play request made before this one completes will interrupt it.
                                            // param1 = frequency in Hz
                                            // param2 = maximum duration in milliseconds
                                            // param3 = amplitude (0 - sndMaxAmp)

  sndCmdQuiet = Succ(sndCmdFrqOn);          // stop current sound
                                            // param1 = 0
                                            // param2 = 0
                                            // param3 = 0

//
// SndCommandType: used by SndDoCmd()
//

type
  SndCommandType = record
    cmd: SndCmdIDType;             // command id
    reserved: UInt8;
    param1: Int32;                 // first parameter
    param2: UInt16;                // second parameter
    param3: UInt16;                // third parameter
  end;

  SndCommandPtr = ^SndCommandType;

//
// Beep numbers used by SndSysBeep()
//

type
  SndSysBeepType = Enum;

const
  sndInfo = 1;
  sndWarning = Succ(sndInfo);
  sndError = Succ(sndWarning);
  sndStartUp = Succ(sndError);
  sndAlarm = Succ(sndStartUp);
  sndConfirmation = Succ(sndAlarm);
  sndClick = Succ(sndConfirmation);

(************************************************************
 * Standard MIDI File (SMF) support structures
 *************************************************************)

// Structure of records in the MIDI sound database:
//
// Each MIDI record consists of a record header followed immediately by the
// Standard MIDI File (SMF) data stream.  Only SMF format #0 is presently supported.
// The first byte of the record header is the byte offset from the beginning of the record
// to the SMF data stream.  The name of the record follows the byte offset
// field.  sndMidiNameLength is the limit on name size (including NULL).

const
  sndMidiRecSignature = Rsc('PMrc');

type
  SndMidiRecHdrType = record
    signature: UInt32;             // set to sndMidiRecSignature
    bDataOffset: UInt8;            // offset from the beginning of the record
                                   // to the Standard Midi File data stream
    reserved: UInt8;               // set to zero
  end;

  SndMidiRecType = record
    hdr: SndMidiRecHdrType;            // offset from the beginning of the record
                                       // to the Standard Midi File data stream
    name: array [0..2-1] of Char;      // Track name: 1 or more chars including NULL terminator.
                                       // If a track has no name, the NULL character must still
                                       // be provided.
                                       // Set to 2 to pad the structure out to a word boundary.
  end;

// Midi records found by SndCreateMidiList.
  SndMidiListItemType = record
    name: array [0..sndMidiNameLength-1] of Char; // including NULL terminator
    uniqueRecID: UInt32;
    dbID: LocalID;
    cardNo: UInt16;
  end;

// Commands for SndPlaySmf
  SndSmfCmdEnum = Enum;

const
  sndSmfCmdPlay = 1;                       // play the selection
  sndSmfCmdDuration = Succ(sndSmfCmdPlay); // get the duration in milliseconds of the entire track

type
  SndComplFuncType = procedure(chanP: Pointer; dwUserData: UInt32);
  SndComplFuncPtr = SndComplFuncType;

// Return true to continue, false to abort
  SndBlockingFuncType = function(chanP: Pointer; dwUserData: UInt32; sysTicksAvailable: Int32): Boolean;
  SndBlockingFuncPtr = SndBlockingFuncType;

type
  SndCallbackInfoType = record
    funcP: MemPtr;          // pointer to the callback function (NULL = no function)
    dwUserData: UInt32;     // value to be passed in the dwUserData parameter of the callback function
  end;

  SndSmfCallbacksType = record
    completion: SndCallbackInfoType;     // completion callback function (see SndComplFuncType)
    blocking: SndCallbackInfoType;       // blocking hook callback function (see SndBlockingFuncType)
    reserved: SndCallbackInfoType;       // RESERVED -- SET ALL FIELDS TO ZERO BEFORE PASSING
  end;
  SndSmfCallbacksPtr = ^SndSmfCallbacksType;

const
  sndSmfPlayAllMilliSec = $FFFFFFFF;

type
  SndSmfOptionsType = record
    // dwStartMilliSec and dwEndMilliSec are used as inputs to the function for sndSmfCmdPlay and as
    // outputs for sndSmfCmdDuration
    dwStartMilliSec: UInt32;                // 0 = "start from the beginning"
    dwEndMilliSec: UInt32;                  // sndSmfPlayAllMilliSec = "play the entire track";
                                            // the default is "play entire track" if this structure
                                            // is not passed in

    // The amplitude and interruptible fields are used only for sndSmfCmdPlay
    amplitude: UInt16;                      // relative volume: 0 - sndMaxAmp, inclusively;  the default is
                                            // sndMaxAmp if this structure is not passed in; if 0, the play will
                                            // be skipped and the call will return immediately

    interruptible: Boolean;                 // if true, sound play will be interrupted if
                                            // user interacts with the controls (digitizer, buttons, etc.);
                                            // if false, the paly will not be interrupted; the default behavior
                                            // is "interruptible" if this structure is not passed in

    reserved1: UInt8;
    reserved: UInt32;                       // RESERVED! -- MUST SET TO ZERO BEFORE PASSING
  end;
  SndSmfOptionsPtr = ^SndSmfOptionsType;

  SndSmfChanRangeType = record
    bFirstChan: UInt8;                         // first MIDI channel (0-15 decimal)
    bLastChan: UInt8;                          // last MIDI channel (0-15 decimal)
  end;
  SndSmfChanRangePtr = ^SndSmfChanRangeType;

(************************************************************
 * Sound Manager result codes
 * (sndErrorClass is defined in SystemMgr.h)
 *************************************************************)

const
  sndErrBadParam    = sndErrorClass or 1;
  sndErrBadChannel  = sndErrorClass or 2;
  sndErrMemory      = sndErrorClass or 3;
  sndErrOpen        = sndErrorClass or 4;
  sndErrQFull       = sndErrorClass or 5;
  sndErrQEmpty      = sndErrorClass or 6; // internal
  sndErrFormat      = sndErrorClass or 7; // unsupported data format
  sndErrBadStream   = sndErrorClass or 8; // invalid data stream
  sndErrInterrupted = sndErrorClass or 9; // play was interrupted

(********************************************************************
 * Sound Manager Routines
 * These are define as syscall calls only under emulation mode or
 *  under native mode from the module that actually installs the trap
 *  vectors
 ********************************************************************)

//-------------------------------------------------------------------
// Initialization
//-------------------------------------------------------------------

// Initializes the Sound Manager.  Should only be called by
// Pilot initialization code.
function SndInit: Err; syscall sysTrapSndInit;

// Frees the Sound Manager.
//procedure SndFree; syscall sysTrapSndFree;

//-------------------------------------------------------------------
// API
//-------------------------------------------------------------------

// Sets default sound volume levels
//
// Any parameter may be passed as NULL
procedure SndSetDefaultVolume(var alarmAmpP, sysAmpP, defAmpP: UInt16); syscall sysTrapSndSetDefaultVolume;

// Gets default sound volume levels
//
// Any parameter may be passed as NULL
procedure SndGetDefaultVolume(var alarmAmpP, sysAmpP, masterAmpP: UInt16); syscall sysTrapSndGetDefaultVolume;

// Executes a sound command on the given sound channel (pass
// channelP = 0 to use the shared channel).
function SndDoCmd({SndChanPtr} channelP: Pointer; cmdP: SndCommandPtr; noWait: Boolean): Err; syscall sysTrapSndDoCmd;

// Plays one of several defined system beeps/sounds (see sndSysBeep...
// constants).
procedure SndPlaySystemSound(beepID: SndSysBeepType); syscall sysTrapSndPlaySystemSound;

// NEW FOR v3.0
// Performs an operation on a Standard MIDI File (SMF) Format #0
function SndPlaySmf(chanP: Pointer; cmd: SndSmfCmdEnum; var smfP: UInt8; selP: SndSmfOptionsPtr;
                    chanRangeP: SndSmfChanRangePtr; callbacksP: SndSmfCallbacksPtr;
                    bNoWait: Boolean): Err; syscall sysTrapSndPlaySmf;

// NEW FOR v3.0
// Creates a list of all midi records.  Useful for displaying in lists.
// For creator wildcard, pass creator=0;
function SndCreateMidiList(creator: UInt32; multipleDBs: Boolean; var wCountP: UInt16; var entHP: MemHandle): Boolean; syscall sysTrapSndCreateMidiList;

// NEW FOR v3.2
// Plays a MIDI sound which is read out of an open resource database
function SndPlaySmfResource(resType: UInt32; resID: Int16; volumeSelector: SystemPreferencesChoice): Err; syscall sysTrapSndPlaySmfResource;


// NEW FOR v4.0
// Plays MIDI sounds regardless of the how the interruptible flag is set
function SndPlaySmfIrregardless(chanP: Pointer; cmd: SndSmfCmdEnum; var smfP: UInt8;
                                var selP: SndSmfOptionsType; var chanRangeP: SndSmfChanRangeType;
                                var callbacksP: SndSmfCallbacksType; bNoWait: Boolean): Err; syscall sysTrapSndPlaySmfIrregardless;

function SndPlaySmfResourceIrregardless(resType: UInt32; resID: Int16; volumeSelector: SystemPreferencesChoice): Err; syscall sysTrapSndPlaySmfResourceIrregardless;

function SndInterruptSmfIrregardless: Err; syscall sysTrapSndInterruptSmfIrregardless;

(************************************************************
 * Sound Manager Macros
 *
 *************************************************************)

implementation

end.