soundmgr.pp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. {$MACRO ON}
  2. {$define Rsc := }
  3. (******************************************************************************
  4. *
  5. * Copyright (c) 1995-2000 Palm, Inc. or its subsidiaries.
  6. * All rights reserved.
  7. *
  8. * File: SoundMgr.h
  9. *
  10. * Release: Palm OS SDK 4.0 (63220)
  11. *
  12. * Description:
  13. * Include file for Sound Manager
  14. *
  15. * History:
  16. * 4/11/95 VMK - Created by Vitaly Kruglikov
  17. *
  18. *****************************************************************************)
  19. unit soundmgr;
  20. interface
  21. uses palmos, coretraps, errorbase, preferences;
  22. (************************************************************
  23. * Sound Manager constants
  24. *
  25. *************************************************************)
  26. const
  27. // Sound Manager max and default volume levels
  28. sndMaxAmp = 64;
  29. //sndVolumeMask = $ff;
  30. sndDefaultAmp = sndMaxAmp;
  31. sndMidiNameLength = 32; // MIDI track name length *including* NULL terminator
  32. (************************************************************
  33. * Sound Manager data structures
  34. *
  35. *************************************************************)
  36. //
  37. // Command numbers for SndCommandType's cmd field
  38. //
  39. type
  40. SndCmdIDType = Enum;
  41. const
  42. sndCmdFreqDurationAmp = 1; // play a sound, blocking for the entire duration (except for zero amplitude)
  43. // param1 = frequency in Hz
  44. // param2 = duration in milliseconds
  45. // param3 = amplitude (0 - sndMaxAmp); if 0, will return immediately
  46. // Commands added in PilotOS v3.0
  47. // ***IMPORTANT***
  48. // Please note that SndDoCmd() in PilotOS before v3.0 will Fatal Error on unknown
  49. // commands (anything other than sndCmdFreqDurationAmp). For this reason,
  50. // applications wishing to take advantage of these new commands while staying
  51. // compatible with the earlier version of the OS, _must_ avoid using these commands
  52. // when running on OS versions less thatn v3.0 (see sysFtrNumROMVersion in SystemMgr.h).
  53. // Beginning with v3.0, SndDoCmd has been fixed to return sndErrBadParam when an
  54. // unknown command is passed.
  55. sndCmdNoteOn = Succ(sndCmdFreqDurationAmp); // start a sound given its MIDI key index, max duration and velocity;
  56. // the call will not wait for the sound to complete, returning imeediately;
  57. // any other sound play request made before this one completes will interrupt it.
  58. // param1 = MIDI key index (0-127)
  59. // param2 = maximum duration in milliseconds
  60. // param3 = velocity (0 - 127) (will be interpolated as amplitude)
  61. sndCmdFrqOn = Succ(sndCmdNoteOn); // start a sound given its frequency in Hz, max duration and amplitude;
  62. // the call will not wait for the sound to complete, returning imeediately;
  63. // any other sound play request made before this one completes will interrupt it.
  64. // param1 = frequency in Hz
  65. // param2 = maximum duration in milliseconds
  66. // param3 = amplitude (0 - sndMaxAmp)
  67. sndCmdQuiet = Succ(sndCmdFrqOn); // stop current sound
  68. // param1 = 0
  69. // param2 = 0
  70. // param3 = 0
  71. //
  72. // SndCommandType: used by SndDoCmd()
  73. //
  74. type
  75. SndCommandType = record
  76. cmd: SndCmdIDType; // command id
  77. reserved: UInt8;
  78. param1: Int32; // first parameter
  79. param2: UInt16; // second parameter
  80. param3: UInt16; // third parameter
  81. end;
  82. SndCommandPtr = ^SndCommandType;
  83. //
  84. // Beep numbers used by SndSysBeep()
  85. //
  86. type
  87. SndSysBeepType = Enum;
  88. const
  89. sndInfo = 1;
  90. sndWarning = Succ(sndInfo);
  91. sndError = Succ(sndWarning);
  92. sndStartUp = Succ(sndError);
  93. sndAlarm = Succ(sndStartUp);
  94. sndConfirmation = Succ(sndAlarm);
  95. sndClick = Succ(sndConfirmation);
  96. (************************************************************
  97. * Standard MIDI File (SMF) support structures
  98. *************************************************************)
  99. // Structure of records in the MIDI sound database:
  100. //
  101. // Each MIDI record consists of a record header followed immediately by the
  102. // Standard MIDI File (SMF) data stream. Only SMF format #0 is presently supported.
  103. // The first byte of the record header is the byte offset from the beginning of the record
  104. // to the SMF data stream. The name of the record follows the byte offset
  105. // field. sndMidiNameLength is the limit on name size (including NULL).
  106. const
  107. sndMidiRecSignature = Rsc('PMrc');
  108. type
  109. SndMidiRecHdrType = record
  110. signature: UInt32; // set to sndMidiRecSignature
  111. bDataOffset: UInt8; // offset from the beginning of the record
  112. // to the Standard Midi File data stream
  113. reserved: UInt8; // set to zero
  114. end;
  115. SndMidiRecType = record
  116. hdr: SndMidiRecHdrType; // offset from the beginning of the record
  117. // to the Standard Midi File data stream
  118. name: array [0..2-1] of Char; // Track name: 1 or more chars including NULL terminator.
  119. // If a track has no name, the NULL character must still
  120. // be provided.
  121. // Set to 2 to pad the structure out to a word boundary.
  122. end;
  123. // Midi records found by SndCreateMidiList.
  124. SndMidiListItemType = record
  125. name: array [0..sndMidiNameLength-1] of Char; // including NULL terminator
  126. uniqueRecID: UInt32;
  127. dbID: LocalID;
  128. cardNo: UInt16;
  129. end;
  130. // Commands for SndPlaySmf
  131. SndSmfCmdEnum = Enum;
  132. const
  133. sndSmfCmdPlay = 1; // play the selection
  134. sndSmfCmdDuration = Succ(sndSmfCmdPlay); // get the duration in milliseconds of the entire track
  135. type
  136. SndComplFuncType = procedure(chanP: Pointer; dwUserData: UInt32);
  137. SndComplFuncPtr = SndComplFuncType;
  138. // Return true to continue, false to abort
  139. SndBlockingFuncType = function(chanP: Pointer; dwUserData: UInt32; sysTicksAvailable: Int32): Boolean;
  140. SndBlockingFuncPtr = SndBlockingFuncType;
  141. type
  142. SndCallbackInfoType = record
  143. funcP: MemPtr; // pointer to the callback function (NULL = no function)
  144. dwUserData: UInt32; // value to be passed in the dwUserData parameter of the callback function
  145. end;
  146. SndSmfCallbacksType = record
  147. completion: SndCallbackInfoType; // completion callback function (see SndComplFuncType)
  148. blocking: SndCallbackInfoType; // blocking hook callback function (see SndBlockingFuncType)
  149. reserved: SndCallbackInfoType; // RESERVED -- SET ALL FIELDS TO ZERO BEFORE PASSING
  150. end;
  151. SndSmfCallbacksPtr = ^SndSmfCallbacksType;
  152. const
  153. sndSmfPlayAllMilliSec = $FFFFFFFF;
  154. type
  155. SndSmfOptionsType = record
  156. // dwStartMilliSec and dwEndMilliSec are used as inputs to the function for sndSmfCmdPlay and as
  157. // outputs for sndSmfCmdDuration
  158. dwStartMilliSec: UInt32; // 0 = "start from the beginning"
  159. dwEndMilliSec: UInt32; // sndSmfPlayAllMilliSec = "play the entire track";
  160. // the default is "play entire track" if this structure
  161. // is not passed in
  162. // The amplitude and interruptible fields are used only for sndSmfCmdPlay
  163. amplitude: UInt16; // relative volume: 0 - sndMaxAmp, inclusively; the default is
  164. // sndMaxAmp if this structure is not passed in; if 0, the play will
  165. // be skipped and the call will return immediately
  166. interruptible: Boolean; // if true, sound play will be interrupted if
  167. // user interacts with the controls (digitizer, buttons, etc.);
  168. // if false, the paly will not be interrupted; the default behavior
  169. // is "interruptible" if this structure is not passed in
  170. reserved1: UInt8;
  171. reserved: UInt32; // RESERVED! -- MUST SET TO ZERO BEFORE PASSING
  172. end;
  173. SndSmfOptionsPtr = ^SndSmfOptionsType;
  174. SndSmfChanRangeType = record
  175. bFirstChan: UInt8; // first MIDI channel (0-15 decimal)
  176. bLastChan: UInt8; // last MIDI channel (0-15 decimal)
  177. end;
  178. SndSmfChanRangePtr = ^SndSmfChanRangeType;
  179. (************************************************************
  180. * Sound Manager result codes
  181. * (sndErrorClass is defined in SystemMgr.h)
  182. *************************************************************)
  183. const
  184. sndErrBadParam = sndErrorClass or 1;
  185. sndErrBadChannel = sndErrorClass or 2;
  186. sndErrMemory = sndErrorClass or 3;
  187. sndErrOpen = sndErrorClass or 4;
  188. sndErrQFull = sndErrorClass or 5;
  189. sndErrQEmpty = sndErrorClass or 6; // internal
  190. sndErrFormat = sndErrorClass or 7; // unsupported data format
  191. sndErrBadStream = sndErrorClass or 8; // invalid data stream
  192. sndErrInterrupted = sndErrorClass or 9; // play was interrupted
  193. (********************************************************************
  194. * Sound Manager Routines
  195. * These are define as syscall calls only under emulation mode or
  196. * under native mode from the module that actually installs the trap
  197. * vectors
  198. ********************************************************************)
  199. //-------------------------------------------------------------------
  200. // Initialization
  201. //-------------------------------------------------------------------
  202. // Initializes the Sound Manager. Should only be called by
  203. // Pilot initialization code.
  204. function SndInit: Err; syscall sysTrapSndInit;
  205. // Frees the Sound Manager.
  206. //procedure SndFree; syscall sysTrapSndFree;
  207. //-------------------------------------------------------------------
  208. // API
  209. //-------------------------------------------------------------------
  210. // Sets default sound volume levels
  211. //
  212. // Any parameter may be passed as NULL
  213. procedure SndSetDefaultVolume(var alarmAmpP, sysAmpP, defAmpP: UInt16); syscall sysTrapSndSetDefaultVolume;
  214. // Gets default sound volume levels
  215. //
  216. // Any parameter may be passed as NULL
  217. procedure SndGetDefaultVolume(var alarmAmpP, sysAmpP, masterAmpP: UInt16); syscall sysTrapSndGetDefaultVolume;
  218. // Executes a sound command on the given sound channel (pass
  219. // channelP = 0 to use the shared channel).
  220. function SndDoCmd({SndChanPtr} channelP: Pointer; cmdP: SndCommandPtr; noWait: Boolean): Err; syscall sysTrapSndDoCmd;
  221. // Plays one of several defined system beeps/sounds (see sndSysBeep...
  222. // constants).
  223. procedure SndPlaySystemSound(beepID: SndSysBeepType); syscall sysTrapSndPlaySystemSound;
  224. // NEW FOR v3.0
  225. // Performs an operation on a Standard MIDI File (SMF) Format #0
  226. function SndPlaySmf(chanP: Pointer; cmd: SndSmfCmdEnum; var smfP: UInt8; selP: SndSmfOptionsPtr;
  227. chanRangeP: SndSmfChanRangePtr; callbacksP: SndSmfCallbacksPtr;
  228. bNoWait: Boolean): Err; syscall sysTrapSndPlaySmf;
  229. // NEW FOR v3.0
  230. // Creates a list of all midi records. Useful for displaying in lists.
  231. // For creator wildcard, pass creator=0;
  232. function SndCreateMidiList(creator: UInt32; multipleDBs: Boolean; var wCountP: UInt16; var entHP: MemHandle): Boolean; syscall sysTrapSndCreateMidiList;
  233. // NEW FOR v3.2
  234. // Plays a MIDI sound which is read out of an open resource database
  235. function SndPlaySmfResource(resType: UInt32; resID: Int16; volumeSelector: SystemPreferencesChoice): Err; syscall sysTrapSndPlaySmfResource;
  236. // NEW FOR v4.0
  237. // Plays MIDI sounds regardless of the how the interruptible flag is set
  238. function SndPlaySmfIrregardless(chanP: Pointer; cmd: SndSmfCmdEnum; var smfP: UInt8;
  239. var selP: SndSmfOptionsType; var chanRangeP: SndSmfChanRangeType;
  240. var callbacksP: SndSmfCallbacksType; bNoWait: Boolean): Err; syscall sysTrapSndPlaySmfIrregardless;
  241. function SndPlaySmfResourceIrregardless(resType: UInt32; resID: Int16; volumeSelector: SystemPreferencesChoice): Err; syscall sysTrapSndPlaySmfResourceIrregardless;
  242. function SndInterruptSmfIrregardless: Err; syscall sysTrapSndInterruptSmfIrregardless;
  243. (************************************************************
  244. * Sound Manager Macros
  245. *
  246. *************************************************************)
  247. implementation
  248. end.