AudioHardwareService.pas 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. {!
  2. @file AudioHardwareService.h
  3. @framework AudioToolbox.framework
  4. @copyright (c) 2006-2015 by Apple, Inc., all rights reserved.
  5. @abstract API's for general high level audio services.
  6. @discussion
  7. The Audio Hardware Service (AHS) provides a way for applications to query and manipulate the
  8. aspects of an audio hardware device without incurring the overhead of loading the full audio
  9. HAL. AHS provides access to all the AudioObjects and their properties on the system. However,
  10. access is limited to only those properties that do not directly impact IO. For example, you can
  11. query the device's format but you can't query its IO buffer size. As such, the AHS API directly
  12. incorporates the various structures and constants in HAL's API, with the caveat that the
  13. AudioObjectIDs used in AHS cannot be used with the HAL.
  14. }
  15. { Pascal Translation: Jonas Maebe <[email protected]>, July 2019 }
  16. {
  17. Modified for use with Free Pascal
  18. Version 308
  19. Please report any bugs to <[email protected]>
  20. }
  21. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  22. {$mode macpas}
  23. {$modeswitch cblocks}
  24. {$packenum 1}
  25. {$macro on}
  26. {$inline on}
  27. {$calling mwpascal}
  28. unit AudioHardwareService;
  29. interface
  30. {$setc UNIVERSAL_INTERFACES_VERSION := $0400}
  31. {$setc GAP_INTERFACES_VERSION := $0308}
  32. {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
  33. {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
  34. {$endc}
  35. {$ifc defined CPUPOWERPC and defined CPUI386}
  36. {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
  37. {$endc}
  38. {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
  39. {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
  40. {$endc}
  41. {$ifc not defined __ppc__ and defined CPUPOWERPC32}
  42. {$setc __ppc__ := 1}
  43. {$elsec}
  44. {$setc __ppc__ := 0}
  45. {$endc}
  46. {$ifc not defined __ppc64__ and defined CPUPOWERPC64}
  47. {$setc __ppc64__ := 1}
  48. {$elsec}
  49. {$setc __ppc64__ := 0}
  50. {$endc}
  51. {$ifc not defined __i386__ and defined CPUI386}
  52. {$setc __i386__ := 1}
  53. {$elsec}
  54. {$setc __i386__ := 0}
  55. {$endc}
  56. {$ifc not defined __x86_64__ and defined CPUX86_64}
  57. {$setc __x86_64__ := 1}
  58. {$elsec}
  59. {$setc __x86_64__ := 0}
  60. {$endc}
  61. {$ifc not defined __arm__ and defined CPUARM}
  62. {$setc __arm__ := 1}
  63. {$elsec}
  64. {$setc __arm__ := 0}
  65. {$endc}
  66. {$ifc not defined __arm64__ and defined CPUAARCH64}
  67. {$setc __arm64__ := 1}
  68. {$elsec}
  69. {$setc __arm64__ := 0}
  70. {$endc}
  71. {$ifc defined cpu64}
  72. {$setc __LP64__ := 1}
  73. {$elsec}
  74. {$setc __LP64__ := 0}
  75. {$endc}
  76. {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
  77. {$error Conflicting definitions for __ppc__ and __i386__}
  78. {$endc}
  79. {$ifc defined __ppc__ and __ppc__}
  80. {$setc TARGET_CPU_PPC := TRUE}
  81. {$setc TARGET_CPU_PPC64 := FALSE}
  82. {$setc TARGET_CPU_X86 := FALSE}
  83. {$setc TARGET_CPU_X86_64 := FALSE}
  84. {$setc TARGET_CPU_ARM := FALSE}
  85. {$setc TARGET_CPU_ARM64 := FALSE}
  86. {$setc TARGET_OS_MAC := TRUE}
  87. {$setc TARGET_OS_IPHONE := FALSE}
  88. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  89. {$setc TARGET_OS_EMBEDDED := FALSE}
  90. {$elifc defined __ppc64__ and __ppc64__}
  91. {$setc TARGET_CPU_PPC := FALSE}
  92. {$setc TARGET_CPU_PPC64 := TRUE}
  93. {$setc TARGET_CPU_X86 := FALSE}
  94. {$setc TARGET_CPU_X86_64 := FALSE}
  95. {$setc TARGET_CPU_ARM := FALSE}
  96. {$setc TARGET_CPU_ARM64 := FALSE}
  97. {$setc TARGET_OS_MAC := TRUE}
  98. {$setc TARGET_OS_IPHONE := FALSE}
  99. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  100. {$setc TARGET_OS_EMBEDDED := FALSE}
  101. {$elifc defined __i386__ and __i386__}
  102. {$setc TARGET_CPU_PPC := FALSE}
  103. {$setc TARGET_CPU_PPC64 := FALSE}
  104. {$setc TARGET_CPU_X86 := TRUE}
  105. {$setc TARGET_CPU_X86_64 := FALSE}
  106. {$setc TARGET_CPU_ARM := FALSE}
  107. {$setc TARGET_CPU_ARM64 := FALSE}
  108. {$ifc defined(iphonesim)}
  109. {$setc TARGET_OS_MAC := FALSE}
  110. {$setc TARGET_OS_IPHONE := TRUE}
  111. {$setc TARGET_IPHONE_SIMULATOR := TRUE}
  112. {$elsec}
  113. {$setc TARGET_OS_MAC := TRUE}
  114. {$setc TARGET_OS_IPHONE := FALSE}
  115. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  116. {$endc}
  117. {$setc TARGET_OS_EMBEDDED := FALSE}
  118. {$elifc defined __x86_64__ and __x86_64__}
  119. {$setc TARGET_CPU_PPC := FALSE}
  120. {$setc TARGET_CPU_PPC64 := FALSE}
  121. {$setc TARGET_CPU_X86 := FALSE}
  122. {$setc TARGET_CPU_X86_64 := TRUE}
  123. {$setc TARGET_CPU_ARM := FALSE}
  124. {$setc TARGET_CPU_ARM64 := FALSE}
  125. {$ifc defined(iphonesim)}
  126. {$setc TARGET_OS_MAC := FALSE}
  127. {$setc TARGET_OS_IPHONE := TRUE}
  128. {$setc TARGET_IPHONE_SIMULATOR := TRUE}
  129. {$elsec}
  130. {$setc TARGET_OS_MAC := TRUE}
  131. {$setc TARGET_OS_IPHONE := FALSE}
  132. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  133. {$endc}
  134. {$setc TARGET_OS_EMBEDDED := FALSE}
  135. {$elifc defined __arm__ and __arm__}
  136. {$setc TARGET_CPU_PPC := FALSE}
  137. {$setc TARGET_CPU_PPC64 := FALSE}
  138. {$setc TARGET_CPU_X86 := FALSE}
  139. {$setc TARGET_CPU_X86_64 := FALSE}
  140. {$setc TARGET_CPU_ARM := TRUE}
  141. {$setc TARGET_CPU_ARM64 := FALSE}
  142. { will require compiler define when/if other Apple devices with ARM cpus ship }
  143. {$setc TARGET_OS_MAC := FALSE}
  144. {$setc TARGET_OS_IPHONE := TRUE}
  145. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  146. {$setc TARGET_OS_EMBEDDED := TRUE}
  147. {$elifc defined __arm64__ and __arm64__}
  148. {$setc TARGET_CPU_PPC := FALSE}
  149. {$setc TARGET_CPU_PPC64 := FALSE}
  150. {$setc TARGET_CPU_X86 := FALSE}
  151. {$setc TARGET_CPU_X86_64 := FALSE}
  152. {$setc TARGET_CPU_ARM := FALSE}
  153. {$setc TARGET_CPU_ARM64 := TRUE}
  154. { will require compiler define when/if other Apple devices with ARM cpus ship }
  155. {$setc TARGET_OS_MAC := FALSE}
  156. {$setc TARGET_OS_IPHONE := TRUE}
  157. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  158. {$setc TARGET_OS_EMBEDDED := TRUE}
  159. {$elsec}
  160. {$error __ppc__ nor __ppc64__ nor __i386__ nor __x86_64__ nor __arm__ nor __arm64__ is defined.}
  161. {$endc}
  162. {$ifc defined __LP64__ and __LP64__ }
  163. {$setc TARGET_CPU_64 := TRUE}
  164. {$elsec}
  165. {$setc TARGET_CPU_64 := FALSE}
  166. {$endc}
  167. {$ifc defined FPC_BIG_ENDIAN}
  168. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  169. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  170. {$elifc defined FPC_LITTLE_ENDIAN}
  171. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  172. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  173. {$elsec}
  174. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  175. {$endc}
  176. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  177. {$setc CALL_NOT_IN_CARBON := FALSE}
  178. {$setc OLDROUTINENAMES := FALSE}
  179. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  180. {$setc OPAQUE_UPP_TYPES := TRUE}
  181. {$setc OTCARBONAPPLICATION := TRUE}
  182. {$setc OTKERNEL := FALSE}
  183. {$setc PM_USE_SESSION_APIS := TRUE}
  184. {$setc TARGET_API_MAC_CARBON := TRUE}
  185. {$setc TARGET_API_MAC_OS8 := FALSE}
  186. {$setc TARGET_API_MAC_OSX := TRUE}
  187. {$setc TARGET_CARBON := TRUE}
  188. {$setc TARGET_CPU_68K := FALSE}
  189. {$setc TARGET_CPU_MIPS := FALSE}
  190. {$setc TARGET_CPU_SPARC := FALSE}
  191. {$setc TARGET_OS_UNIX := FALSE}
  192. {$setc TARGET_OS_WIN32 := FALSE}
  193. {$setc TARGET_RT_MAC_68881 := FALSE}
  194. {$setc TARGET_RT_MAC_CFM := FALSE}
  195. {$setc TARGET_RT_MAC_MACHO := TRUE}
  196. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  197. {$setc TYPE_BOOL := FALSE}
  198. {$setc TYPE_EXTENDED := FALSE}
  199. {$setc TYPE_LONGLONG := TRUE}
  200. uses MacTypes,AudioHardwareBase,AudioHardware;
  201. {$endc} {not MACOSALLINCLUDE}
  202. {$ALIGN POWER}
  203. //==================================================================================================
  204. //#pragma mark Audio Hardware Service Properties
  205. {!
  206. @enum Audio Hardware Service Properties
  207. @abstract AudioObjectPropertySelector values that apply to various kinds of AudioObjects
  208. only when accessed via the Audio Hardware Service API.
  209. @constant kAudioHardwareServiceProperty_ServiceRestarted
  210. A Float32 whose value has no meaning. Rather, this property exists so that
  211. clients can be informed when the service has been reset for some reason.
  212. When a reset happens, any state the client has with AHS, such as cached data
  213. or added listeners, must be re-established by the client.
  214. @constant kAudioHardwareServiceDeviceProperty_VirtualMasterVolume
  215. A Float32 that represents the value of the volume control. The range is
  216. between 0.0 and 1.0 (inclusive). This actual volume controls this property
  217. manipulates depends on what the device provides. If the device has a true
  218. master volume control, this property directly controls that. If the device
  219. has individual channel volume controls, this property will apply to those
  220. identified by the device's preferred multi-channel layout (or preferred
  221. stereo pair if the device is stereo only). Note that this control maintains
  222. the relative balance between all the channels it affects.
  223. @constant kAudioHardwareServiceDeviceProperty_VirtualMasterBalance
  224. A Float32 that represents the value of the stereo balance control. The range
  225. is from 0.0 (all power to the left) to 1.0 (all power to the right) with
  226. the value of 0.5 signifying that the channels have equal power. This control
  227. is only present for devices that have individual channel volume controls. It
  228. manipulates the relative balance between the volume controls on the channels
  229. identified as the device's default stereo pair.
  230. }
  231. const
  232. kAudioHardwareServiceProperty_ServiceRestarted = FourCharCode('srst');
  233. kAudioHardwareServiceDeviceProperty_VirtualMasterVolume = FourCharCode('vmvc');
  234. kAudioHardwareServiceDeviceProperty_VirtualMasterBalance = FourCharCode('vmbc');
  235. //==================================================================================================
  236. //#pragma mark Audio Hardware Service Functions
  237. {$ifc TARGET_OS_MAC}
  238. {!
  239. @functiongroup Audio Hardware Service
  240. }
  241. {!
  242. @function AudioHardwareServiceHasProperty
  243. @abstract Queries an AudioObject about whether or not it has the given property.
  244. @param inObjectID
  245. The AudioObject to query.
  246. @param inAddress
  247. An AudioObjectPropertyAddress indicating which property is being queried.
  248. @result A Boolean indicating whether or not the AudioObject has the given property.
  249. }
  250. function AudioHardwareServiceHasProperty( inObjectID: AudioObjectID; const (*var*) inAddress: AudioObjectPropertyAddress ): Boolean; external name '_AudioHardwareServiceHasProperty';
  251. (* API_DEPRECATED("no longer supported", macos(10.5, 10.11)) API_UNAVAILABLE(ios, watchos, tvos) *)
  252. {!
  253. @function AudioHardwareServiceIsPropertySettable
  254. @abstract Queries an AudioObject about whether or not the given property can be set using
  255. AudioHardwareServiceSetPropertyData.
  256. @param inObjectID
  257. The AudioObject to query.
  258. @param inAddress
  259. An AudioObjectPropertyAddress indicating which property is being queried.
  260. @param outIsSettable
  261. A Boolean indicating whether or not the property can be set.
  262. @result An OSStatus indicating success or failure.
  263. }
  264. function AudioHardwareServiceIsPropertySettable( inObjectID: AudioObjectID; const (*var*) inAddress: AudioObjectPropertyAddress; var outIsSettable: Boolean ): OSStatus; external name '_AudioHardwareServiceIsPropertySettable';
  265. (* API_DEPRECATED("no longer supported", macos(10.5, 10.11)) API_UNAVAILABLE(ios, watchos, tvos) *)
  266. {!
  267. @function AudioHardwareServiceGetPropertyDataSize
  268. @abstract Queries an AudioObject to find the size of the data for the given property.
  269. @param inObjectID
  270. The AudioObject to query.
  271. @param inAddress
  272. An AudioObjectPropertyAddress indicating which property is being queried.
  273. @param inQualifierDataSize
  274. A UInt32 indicating the size of the buffer pointed to by inQualifierData.
  275. Note that not all properties require qualification, in which case this
  276. value will be 0.
  277. @param inQualifierData
  278. A buffer of data to be used in determining the data of the property being
  279. queried. Note that not all properties require qualification, in which case
  280. this value will be NULL.
  281. @param outDataSize
  282. A UInt32 indicating how many bytes the data for the given property occupies.
  283. @result An OSStatus indicating success or failure.
  284. }
  285. function AudioHardwareServiceGetPropertyDataSize( inObjectID: AudioObjectID; const (*var*) inAddress: AudioObjectPropertyAddress; inQualifierDataSize: UInt32; inQualifierData: {const} UnivPtr; var outDataSize: UInt32 ): OSStatus; external name '_AudioHardwareServiceGetPropertyDataSize';
  286. (* API_DEPRECATED("no longer supported", macos(10.5, 10.11)) API_UNAVAILABLE(ios, watchos, tvos) *)
  287. {!
  288. @function AudioHardwareServiceGetPropertyData
  289. @abstract Queries an AudioObject to get the data of the given property and places it in
  290. the provided buffer.
  291. @param inObjectID
  292. The AudioObject to query.
  293. @param inAddress
  294. An AudioObjectPropertyAddress indicating which property is being queried.
  295. @param inQualifierDataSize
  296. A UInt32 indicating the size of the buffer pointed to by inQualifierData.
  297. Note that not all properties require qualification, in which case this
  298. value will be 0.
  299. @param inQualifierData
  300. A buffer of data to be used in determining the data of the property being
  301. queried. Note that not all properties require qualification, in which case
  302. this value will be NULL.
  303. @param ioDataSize
  304. A UInt32 which on entry indicates the size of the buffer pointed to by
  305. outData and on exit indicates how much of the buffer was used.
  306. @param outData
  307. The buffer into which the AudioObject will put the data for the given
  308. property.
  309. @result An OSStatus indicating success or failure.
  310. }
  311. function AudioHardwareServiceGetPropertyData( inObjectID: AudioObjectID; const (*var*) inAddress: AudioObjectPropertyAddress; inQualifierDataSize: UInt32; inQualifierData: {const} UnivPtr; var ioDataSize: UInt32; outData: UnivPtr ): OSStatus; external name '_AudioHardwareServiceGetPropertyData';
  312. (* API_DEPRECATED("no longer supported", macos(10.5, 10.11)) API_UNAVAILABLE(ios, watchos, tvos) *)
  313. {!
  314. @function AudioHardwareServiceSetPropertyData
  315. @abstract Tells an AudioObject to change the value of the given property using the
  316. provided data.
  317. @discussion Note that the value of the property should not be considered changed until the
  318. HAL has called the listeners as many properties values are changed
  319. asynchronously.
  320. @param inObjectID
  321. The AudioObject to change.
  322. @param inAddress
  323. An AudioObjectPropertyAddress indicating which property is being changed.
  324. @param inQualifierDataSize
  325. A UInt32 indicating the size of the buffer pointed to by inQualifierData.
  326. Note that not all properties require qualification, in which case this
  327. value will be 0.
  328. @param inQualifierData
  329. A buffer of data to be used in determining the data of the property being
  330. queried. Note that not all properties require qualification, in which case
  331. this value will be NULL.
  332. @param inDataSize
  333. A UInt32 indicating the size of the buffer pointed to by inData.
  334. @param inData
  335. The buffer containing the data to be used to change the property's value.
  336. @result An OSStatus indicating success or failure.
  337. }
  338. function AudioHardwareServiceSetPropertyData( inObjectID: AudioObjectID; const (*var*) inAddress: AudioObjectPropertyAddress; inQualifierDataSize: UInt32; inQualifierData: {const} UnivPtr; inDataSize: UInt32; inData: {const} UnivPtr ): OSStatus; external name '_AudioHardwareServiceSetPropertyData';
  339. (* API_DEPRECATED("no longer supported", macos(10.5, 10.11)) API_UNAVAILABLE(ios, watchos, tvos) *)
  340. {!
  341. @function AudioHardwareServiceAddPropertyListener
  342. @abstract Registers the given AudioObjectPropertyListenerProc to receive notifications
  343. when the given properties change.
  344. @param inObjectID
  345. The AudioObject to register the listener with.
  346. @param inAddress
  347. The AudioObjectPropertyAddresses indicating which property the listener
  348. should be notified about.
  349. @param inListener
  350. The AudioObjectPropertyListenerProc to call.
  351. @param inClientData
  352. A pointer to client data that is passed to the listener when it is called.
  353. @result An OSStatus indicating success or failure.
  354. }
  355. function AudioHardwareServiceAddPropertyListener( inObjectID: AudioObjectID; const (*var*) inAddress: AudioObjectPropertyAddress; inListener: AudioObjectPropertyListenerProc; inClientData: UnivPtr ): OSStatus; external name '_AudioHardwareServiceAddPropertyListener';
  356. (* API_DEPRECATED("no longer supported", macos(10.5, 10.11)) API_UNAVAILABLE(ios, watchos, tvos) *)
  357. {!
  358. @function AudioHardwareServiceRemovePropertyListener
  359. @abstract Unregisters the given AudioObjectPropertyListenerProc from receiving
  360. notifications when the given properties change.
  361. @param inObjectID
  362. The AudioObject to unregister the listener from.
  363. @param inAddress
  364. The AudioObjectPropertyAddresses indicating which property the listener
  365. will stop being notified about.
  366. @param inListener
  367. The AudioObjectPropertyListenerProc being removed.
  368. @param inClientData
  369. A pointer to client data that is passed to the listener when it is called.
  370. @result An OSStatus indicating success or failure.
  371. }
  372. function AudioHardwareServiceRemovePropertyListener( inObjectID: AudioObjectID; const (*var*) inAddress: AudioObjectPropertyAddress; inListener: AudioObjectPropertyListenerProc; inClientData: UnivPtr ): OSStatus; external name '_AudioHardwareServiceRemovePropertyListener';
  373. (* API_DEPRECATED("no longer supported", macos(10.5, 10.11)) API_UNAVAILABLE(ios, watchos, tvos) *)
  374. {$endc}
  375. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  376. end.
  377. {$endc} {not MACOSALLINCLUDE}