AudioUnitUtilities.pas 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. {!
  2. @file AudioUnitUtilities.h
  3. @framework AudioToolbox.framework
  4. @copyright (c) 2002-2015 by Apple, Inc., all rights reserved.
  5. @abstract Higher-level utility functions for the use of AudioUnit clients.
  6. @discussion
  7. The AU Parameter Listener is designed to provide notifications when an Audio Unit's parameters
  8. or other state changes. It makes it unnecessary for UI components to continually poll an Audio
  9. Unit to determine if a parameter value has been changed. In order for this notification
  10. mechanism to work properly, parameter values should be changed using the AUParameterSet call
  11. (discussed below). This also makes it unnecessary for an Audio Unit to provide and support a
  12. notification mechanism, particularly as AudioUnitSetParameter may be received by an Audio Unit
  13. during the render process.
  14. The AUEventListener API's extend the AUParameterListener API's by supporting event types
  15. other than parameter changes. Events, including parameter changes are delivered serially to the
  16. listener, preserving the time order of the events and parameter changes.
  17. There are also some utilities for converting between non-linear and linear value ranges. These
  18. are useful for displaying a non-linear parameter (such as one whose units are in Hertz or
  19. decibels) using a linear control mechanism, such as a slider, to ensure that the user has a
  20. wider perceived range of control over the parameter value.
  21. }
  22. { Pascal Translation: Jonas Maebe <[email protected]>, July 2019 }
  23. {
  24. Modified for use with Free Pascal
  25. Version 308
  26. Please report any bugs to <[email protected]>
  27. }
  28. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  29. {$mode macpas}
  30. {$modeswitch cblocks}
  31. {$packenum 1}
  32. {$macro on}
  33. {$inline on}
  34. {$calling mwpascal}
  35. unit AudioUnitUtilities;
  36. interface
  37. {$setc UNIVERSAL_INTERFACES_VERSION := $0400}
  38. {$setc GAP_INTERFACES_VERSION := $0308}
  39. {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
  40. {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
  41. {$endc}
  42. {$ifc defined CPUPOWERPC and defined CPUI386}
  43. {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
  44. {$endc}
  45. {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
  46. {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
  47. {$endc}
  48. {$ifc not defined __ppc__ and defined CPUPOWERPC32}
  49. {$setc __ppc__ := 1}
  50. {$elsec}
  51. {$setc __ppc__ := 0}
  52. {$endc}
  53. {$ifc not defined __ppc64__ and defined CPUPOWERPC64}
  54. {$setc __ppc64__ := 1}
  55. {$elsec}
  56. {$setc __ppc64__ := 0}
  57. {$endc}
  58. {$ifc not defined __i386__ and defined CPUI386}
  59. {$setc __i386__ := 1}
  60. {$elsec}
  61. {$setc __i386__ := 0}
  62. {$endc}
  63. {$ifc not defined __x86_64__ and defined CPUX86_64}
  64. {$setc __x86_64__ := 1}
  65. {$elsec}
  66. {$setc __x86_64__ := 0}
  67. {$endc}
  68. {$ifc not defined __arm__ and defined CPUARM}
  69. {$setc __arm__ := 1}
  70. {$elsec}
  71. {$setc __arm__ := 0}
  72. {$endc}
  73. {$ifc not defined __arm64__ and defined CPUAARCH64}
  74. {$setc __arm64__ := 1}
  75. {$elsec}
  76. {$setc __arm64__ := 0}
  77. {$endc}
  78. {$ifc defined cpu64}
  79. {$setc __LP64__ := 1}
  80. {$elsec}
  81. {$setc __LP64__ := 0}
  82. {$endc}
  83. {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
  84. {$error Conflicting definitions for __ppc__ and __i386__}
  85. {$endc}
  86. {$ifc defined __ppc__ and __ppc__}
  87. {$setc TARGET_CPU_PPC := TRUE}
  88. {$setc TARGET_CPU_PPC64 := FALSE}
  89. {$setc TARGET_CPU_X86 := FALSE}
  90. {$setc TARGET_CPU_X86_64 := FALSE}
  91. {$setc TARGET_CPU_ARM := FALSE}
  92. {$setc TARGET_CPU_ARM64 := FALSE}
  93. {$setc TARGET_OS_MAC := TRUE}
  94. {$setc TARGET_OS_IPHONE := FALSE}
  95. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  96. {$setc TARGET_OS_EMBEDDED := FALSE}
  97. {$elifc defined __ppc64__ and __ppc64__}
  98. {$setc TARGET_CPU_PPC := FALSE}
  99. {$setc TARGET_CPU_PPC64 := TRUE}
  100. {$setc TARGET_CPU_X86 := FALSE}
  101. {$setc TARGET_CPU_X86_64 := FALSE}
  102. {$setc TARGET_CPU_ARM := FALSE}
  103. {$setc TARGET_CPU_ARM64 := FALSE}
  104. {$setc TARGET_OS_MAC := TRUE}
  105. {$setc TARGET_OS_IPHONE := FALSE}
  106. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  107. {$setc TARGET_OS_EMBEDDED := FALSE}
  108. {$elifc defined __i386__ and __i386__}
  109. {$setc TARGET_CPU_PPC := FALSE}
  110. {$setc TARGET_CPU_PPC64 := FALSE}
  111. {$setc TARGET_CPU_X86 := TRUE}
  112. {$setc TARGET_CPU_X86_64 := FALSE}
  113. {$setc TARGET_CPU_ARM := FALSE}
  114. {$setc TARGET_CPU_ARM64 := FALSE}
  115. {$ifc defined iphonesim}
  116. {$setc TARGET_OS_MAC := FALSE}
  117. {$setc TARGET_OS_IPHONE := TRUE}
  118. {$setc TARGET_IPHONE_SIMULATOR := TRUE}
  119. {$elsec}
  120. {$setc TARGET_OS_MAC := TRUE}
  121. {$setc TARGET_OS_IPHONE := FALSE}
  122. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  123. {$endc}
  124. {$setc TARGET_OS_EMBEDDED := FALSE}
  125. {$elifc defined __x86_64__ and __x86_64__}
  126. {$setc TARGET_CPU_PPC := FALSE}
  127. {$setc TARGET_CPU_PPC64 := FALSE}
  128. {$setc TARGET_CPU_X86 := FALSE}
  129. {$setc TARGET_CPU_X86_64 := TRUE}
  130. {$setc TARGET_CPU_ARM := FALSE}
  131. {$setc TARGET_CPU_ARM64 := FALSE}
  132. {$ifc defined iphonesim}
  133. {$setc TARGET_OS_MAC := FALSE}
  134. {$setc TARGET_OS_IPHONE := TRUE}
  135. {$setc TARGET_IPHONE_SIMULATOR := TRUE}
  136. {$elsec}
  137. {$setc TARGET_OS_MAC := TRUE}
  138. {$setc TARGET_OS_IPHONE := FALSE}
  139. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  140. {$endc}
  141. {$setc TARGET_OS_EMBEDDED := FALSE}
  142. {$elifc defined __arm__ and __arm__}
  143. {$setc TARGET_CPU_PPC := FALSE}
  144. {$setc TARGET_CPU_PPC64 := FALSE}
  145. {$setc TARGET_CPU_X86 := FALSE}
  146. {$setc TARGET_CPU_X86_64 := FALSE}
  147. {$setc TARGET_CPU_ARM := TRUE}
  148. {$setc TARGET_CPU_ARM64 := FALSE}
  149. {$setc TARGET_OS_MAC := FALSE}
  150. {$setc TARGET_OS_IPHONE := TRUE}
  151. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  152. {$setc TARGET_OS_EMBEDDED := TRUE}
  153. {$elifc defined __arm64__ and __arm64__}
  154. {$setc TARGET_CPU_PPC := FALSE}
  155. {$setc TARGET_CPU_PPC64 := FALSE}
  156. {$setc TARGET_CPU_X86 := FALSE}
  157. {$setc TARGET_CPU_X86_64 := FALSE}
  158. {$setc TARGET_CPU_ARM := FALSE}
  159. {$setc TARGET_CPU_ARM64 := TRUE}
  160. {$ifc defined ios}
  161. {$setc TARGET_OS_MAC := FALSE}
  162. {$setc TARGET_OS_IPHONE := TRUE}
  163. {$setc TARGET_OS_EMBEDDED := TRUE}
  164. {$elsec}
  165. {$setc TARGET_OS_MAC := TRUE}
  166. {$setc TARGET_OS_IPHONE := FALSE}
  167. {$setc TARGET_OS_EMBEDDED := FALSE}
  168. {$endc}
  169. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  170. {$elsec}
  171. {$error __ppc__ nor __ppc64__ nor __i386__ nor __x86_64__ nor __arm__ nor __arm64__ is defined.}
  172. {$endc}
  173. {$ifc defined __LP64__ and __LP64__ }
  174. {$setc TARGET_CPU_64 := TRUE}
  175. {$elsec}
  176. {$setc TARGET_CPU_64 := FALSE}
  177. {$endc}
  178. {$ifc defined FPC_BIG_ENDIAN}
  179. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  180. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  181. {$elifc defined FPC_LITTLE_ENDIAN}
  182. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  183. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  184. {$elsec}
  185. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  186. {$endc}
  187. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  188. {$setc CALL_NOT_IN_CARBON := FALSE}
  189. {$setc OLDROUTINENAMES := FALSE}
  190. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  191. {$setc OPAQUE_UPP_TYPES := TRUE}
  192. {$setc OTCARBONAPPLICATION := TRUE}
  193. {$setc OTKERNEL := FALSE}
  194. {$setc PM_USE_SESSION_APIS := TRUE}
  195. {$setc TARGET_API_MAC_CARBON := TRUE}
  196. {$setc TARGET_API_MAC_OS8 := FALSE}
  197. {$setc TARGET_API_MAC_OSX := TRUE}
  198. {$setc TARGET_CARBON := TRUE}
  199. {$setc TARGET_CPU_68K := FALSE}
  200. {$setc TARGET_CPU_MIPS := FALSE}
  201. {$setc TARGET_CPU_SPARC := FALSE}
  202. {$setc TARGET_OS_UNIX := FALSE}
  203. {$setc TARGET_OS_WIN32 := FALSE}
  204. {$setc TARGET_RT_MAC_68881 := FALSE}
  205. {$setc TARGET_RT_MAC_CFM := FALSE}
  206. {$setc TARGET_RT_MAC_MACHO := TRUE}
  207. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  208. {$setc TYPE_BOOL := FALSE}
  209. {$setc TYPE_EXTENDED := FALSE}
  210. {$setc TYPE_LONGLONG := TRUE}
  211. uses MacTypes,CFBase,CFRunLoop,AUComponent;
  212. {$endc} {not MACOSALLINCLUDE}
  213. {$ALIGN POWER}
  214. //CF_ASSUME_NONNULL_BEGIN
  215. { ============================================================================= }
  216. {!
  217. @enum
  218. @constant kAUParameterListener_AnyParameter
  219. A wildcard value for an AudioUnitParameterID. Note that this is
  220. only valid when sending a notification (with AUParameterListenerNotify),
  221. not when registering to receive one.
  222. }
  223. const
  224. kAUParameterListener_AnyParameter = $FFFFFFFF;
  225. {!
  226. @enum AudioUnitEventType
  227. @abstract Types of Audio Unit Events.
  228. @constant kAudioUnitEvent_ParameterValueChange
  229. The event is a change to a parameter value
  230. @constant kAudioUnitEvent_BeginParameterChangeGesture
  231. The event signifies a gesture (e.g. mouse-down) beginning a potential series of
  232. related parameter value change events.
  233. @constant kAudioUnitEvent_EndParameterChangeGesture
  234. The event signifies a gesture (e.g. mouse-up) ending a series of related
  235. parameter value change events.
  236. @constant kAudioUnitEvent_PropertyChange
  237. The event is a change to a property value.
  238. }
  239. type
  240. AudioUnitEventType = UInt32;
  241. AudioUnitEventTypePtr = ^AudioUnitEventType;
  242. const
  243. kAudioUnitEvent_ParameterValueChange = 0;
  244. kAudioUnitEvent_BeginParameterChangeGesture = 1;
  245. kAudioUnitEvent_EndParameterChangeGesture = 2;
  246. kAudioUnitEvent_PropertyChange = 3;
  247. { ============================================================================= }
  248. {!
  249. @typedef AUParameterListenerRef
  250. @abstract An object which receives notifications of Audio Unit parameter value changes.
  251. @discussion
  252. }
  253. type
  254. AUListenerBase = record end;
  255. AUParameterListenerRef = ^AUListenerBase;
  256. // opaque
  257. // old-style listener, may not be passed to new functions
  258. {!
  259. @typedef AUEventListenerRef
  260. @abstract An object which receives Audio Unit events.
  261. @discussion An AUEventListenerRef may be passed to API's taking an AUEventListenerRef
  262. as an argument.
  263. }
  264. type
  265. AUEventListenerRef = AUParameterListenerRef;
  266. // new-style listener, can be passed to both old and new functions
  267. {!
  268. @struct AudioUnitEvent
  269. @abstract Describes a change to an Audio Unit's state.
  270. @field mEventType
  271. The type of event.
  272. @field mArgument
  273. Specifies the parameter or property which has changed.
  274. }
  275. type
  276. AudioUnitEvent = record
  277. mEventType: AudioUnitEventType;
  278. mArgument: record
  279. case byte of
  280. 0: (mParameter: AudioUnitParameter); // for parameter value change, begin and end gesture
  281. 1: (mProperty: AudioUnitProperty); // for kAudioUnitEvent_PropertyChange
  282. end
  283. end;
  284. AudioUnitEventPtr = ^AudioUnitEvent;
  285. {!
  286. @typedef AUParameterListenerProc
  287. @abstract A function called when a parameter value changes.
  288. @param inUserData
  289. The value passed to AUListenerCreate when the callback function was installed.
  290. @param inObject
  291. The object which generated the parameter change.
  292. @param inParameter
  293. Signifies the parameter whose value changed.
  294. @param inValue
  295. The parameter's new value.
  296. }
  297. type
  298. AUParameterListenerProc = procedure( inUserData: UnivPtr {__nullable}; inObject: UnivPtr {__nullable}; const (*var*) inParameter: AudioUnitParameter; inValue: AudioUnitParameterValue );
  299. {!
  300. @typedef AUEventListenerProc
  301. @abstract A function called when an Audio Unit event occurs.
  302. @param inUserData
  303. The value passed to AUListenerCreate when the callback function was installed.
  304. @param inObject
  305. The object which generated the parameter change.
  306. @param inEvent
  307. The event which occurred.
  308. @param inEventHostTime
  309. The host time at which the event occurred.
  310. @param inParameterValue
  311. If the event is parameter change, the parameter's new value (otherwise, undefined).
  312. }
  313. type
  314. AUEventListenerProc = procedure( inUserData: UnivPtr {__nullable}; inObject: UnivPtr {__nullable}; const (*var*) inEvent: AudioUnitEvent; inEventHostTime: UInt64; inParameterValue: AudioUnitParameterValue );
  315. { ============================================================================= }
  316. {!
  317. @functiongroup AUListener
  318. }
  319. {!
  320. @function AUListenerCreate
  321. @abstract Create an object for fielding notifications when AudioUnit parameter values change.
  322. @param inProc
  323. Function called when the parameter's value changes.
  324. @param inUserData
  325. A reference value for the use of the callback function.
  326. @param inRunLoop
  327. The run loop on which the callback is called. If NULL,
  328. CFRunLoopGetCurrent() is used.
  329. @param inRunLoopMode
  330. The run loop mode in which the callback's underlying run loop source will be
  331. attached. If NULL, kCFRunLoopDefaultMode is used.
  332. @param inNotificationInterval
  333. The minimum time interval, in seconds, at which the callback will be called.
  334. If multiple parameter value changes occur within this time interval, the
  335. listener will only receive a notification for the last value change that
  336. occurred before the callback. If inNotificationInterval is 0, the inRunLoop
  337. and inRunLoopMode arguments are ignored, and the callback will be issued
  338. immediately, on the thread on which the parameter was changed.
  339. @param outListener
  340. On successful return, an AUParameterListenerRef.
  341. @discussion
  342. Note that only parameter changes issued through AUParameterSet will generate
  343. notifications to listeners; thus, in most cases, AudioUnit clients should use
  344. AUParameterSet in preference to AudioUnitSetParameter.
  345. }
  346. function AUListenerCreate( inProc: AUParameterListenerProc; inUserData: UnivPtr; inRunLoop: CFRunLoopRef {__nullable}; inRunLoopMode: CFStringRef {__nullable}; inNotificationInterval: Float32; var outListener: AUParameterListenerRef {__nullable * __nonnull} ): OSStatus; external name '_AUListenerCreate';
  347. (* API_AVAILABLE(macos(10.2), ios(6.0), watchos(2.0), tvos(9.0)) *)
  348. {!
  349. @function AUListenerDispose
  350. @abstract Dispose a parameter listener object.
  351. @param inListener
  352. The parameter listener to dispose.
  353. @discussion
  354. }
  355. function AUListenerDispose( inListener: AUParameterListenerRef ): OSStatus; external name '_AUListenerDispose';
  356. (* API_AVAILABLE(macos(10.2), ios(6.0), watchos(2.0), tvos(9.0)) *)
  357. {!
  358. @function AUListenerAddParameter
  359. @abstract Connect a parameter to a listener.
  360. @param inListener
  361. The parameter listener which will receive the callback.
  362. @param inObject
  363. The object which is interested in the value of the parameter. This will be
  364. passed as the inObject parameter to the listener callback function when the
  365. parameter changes.
  366. @param inParameter
  367. The parameter whose value changes are to generate callbacks.
  368. @discussion
  369. Associates an arbitrary object (often a user interface widget) with an
  370. AudioUnitParameter, and delivers notifications to the specified listener, telling it
  371. that the object needs to be informed of the parameter's value change.
  372. }
  373. function AUListenerAddParameter( inListener: AUParameterListenerRef; inObject: UnivPtr {__nullable}; const (*var*) inParameter: AudioUnitParameter ): OSStatus; external name '_AUListenerAddParameter';
  374. (* API_AVAILABLE(macos(10.2), ios(6.0), watchos(2.0), tvos(9.0)) *)
  375. {!
  376. @function AUListenerRemoveParameter
  377. @abstract Remove a parameter/listener connection.
  378. @param inListener
  379. The parameter listener to stop receiving callbacks.
  380. @param inObject
  381. The object which is no longer interested in the value of the parameter.
  382. @param inParameter
  383. The parameter whose value changes are to stop generating callbacks.
  384. @discussion
  385. }
  386. function AUListenerRemoveParameter( inListener: AUParameterListenerRef; inObject: UnivPtr {__nullable}; const (*var*) inParameter: AudioUnitParameter ): OSStatus; external name '_AUListenerRemoveParameter';
  387. (* API_AVAILABLE(macos(10.2), ios(6.0), watchos(2.0), tvos(9.0)) *)
  388. {!
  389. @function AUParameterSet
  390. @abstract Set an AudioUnit parameter value and notify listeners.
  391. @param inSendingListener
  392. A parameter listener generating the change and which does not want to
  393. receive a callback as a result of it. May be NULL.
  394. @param inSendingObject
  395. The object generating the change and which does not want to receive a
  396. callback as a result of it. NULL is treated specially when inListener is
  397. non-null; it signifies that none of the specified listener's objects will
  398. receive notifications.
  399. @param inParameter
  400. The parameter being changed.
  401. @param inValue
  402. The new value of the parameter.
  403. @param inBufferOffsetInFrames
  404. The offset into the next rendered buffer at which the parameter change will take
  405. effect.
  406. @discussion
  407. Calls AudioUnitSetParameter, and performs/schedules notification callbacks to all
  408. parameter listeners, for that parameter -- except that no callback will be generated to
  409. the inListener/inObject pair.
  410. }
  411. function AUParameterSet( inSendingListener: AUParameterListenerRef {__nullable}; inSendingObject: UnivPtr {__nullable}; const (*var*) inParameter: AudioUnitParameter; inValue: AudioUnitParameterValue; inBufferOffsetInFrames: UInt32 ): OSStatus; external name '_AUParameterSet';
  412. (* API_AVAILABLE(macos(10.2), ios(6.0), watchos(2.0), tvos(9.0)) *)
  413. {!
  414. @function AUParameterListenerNotify
  415. @abstract Notify listeners of a past parameter change.
  416. @param inSendingListener
  417. A parameter listener generating the change and which does not want to
  418. receive a callback as a result of it. May be NULL.
  419. @param inSendingObject
  420. The object generating the change and which does not want to receive a
  421. callback as a result of it. NULL is treated specially when inListener is
  422. non-null; it signifies that none of the specified listener's objects will
  423. receive notifications.
  424. @param inParameter
  425. The parameter which was changed.
  426. @discussion
  427. Performs and schedules the notification callbacks of AUParameterSet, without
  428. actually setting an AudioUnit parameter value.
  429. Clients scheduling ramped parameter changes to AudioUnits must make this call
  430. dynamically during playback in order for AudioUnitViews to be updated. When the view's
  431. listener receives a notification, it will be passed the current value of the parameter.
  432. A special meaning is applied if the mParameterID value of inParameter is equal to
  433. kAUParameterListener_AnyParameter. In this case, ANY listener for ANY parameter value
  434. changes on the specified AudioUnit will be notified of the current value of that
  435. parameter.
  436. }
  437. function AUParameterListenerNotify( inSendingListener: AUParameterListenerRef {__nullable}; inSendingObject: UnivPtr {__nullable}; const (*var*) inParameter: AudioUnitParameter ): OSStatus; external name '_AUParameterListenerNotify';
  438. (* API_AVAILABLE(macos(10.2), ios(6.0), watchos(2.0), tvos(9.0)) *)
  439. { ============================================================================= }
  440. {!
  441. @functiongroup AUEventListener
  442. }
  443. {!
  444. @function AUEventListenerCreate
  445. @abstract Creates an Audio Unit event listener.
  446. @param inProc
  447. Function called when an event occurs.
  448. @param inUserData
  449. A reference value for the use of the callback function.
  450. @param inRunLoop
  451. The run loop on which the callback is called. If NULL,
  452. CFRunLoopGetCurrent() is used.
  453. @param inRunLoopMode
  454. The run loop mode in which the callback's underlying run loop source will be
  455. attached. If NULL, kCFRunLoopDefaultMode is used.
  456. @param inNotificationInterval
  457. The minimum time interval, in seconds, at which the callback will be called.
  458. @param inValueChangeGranularity
  459. Determines how parameter value changes occurring within this interval are
  460. queued; when an event follows a previous one by a smaller time interval than
  461. the granularity, then the listener will only be notified for the second
  462. parameter change.
  463. @param outListener
  464. On successful return, an AUEventListenerRef.
  465. @discussion
  466. See the discussion of AUEventListenerCreateWithDispatchQueue.
  467. }
  468. function AUEventListenerCreate( inProc: AUEventListenerProc; inUserData: UnivPtr {__nullable}; inRunLoop: CFRunLoopRef {__nullable}; inRunLoopMode: CFStringRef {__nullable}; inNotificationInterval: Float32 { seconds }; inValueChangeGranularity: Float32 { seconds }; var outListener: AUEventListenerRef {__nullable * __nonnull} ): OSStatus; external name '_AUEventListenerCreate';
  469. (* API_AVAILABLE(macos(10.3), ios(6.0), watchos(2.0), tvos(9.0)) *)
  470. {!
  471. @function AUEventListenerAddEventType
  472. @abstract Begin delivering a particular type of events to a listener.
  473. @param inListener
  474. The parameter listener which will receive the events.
  475. @param inObject
  476. The object which is interested in the value of the parameter. This will be
  477. passed as the inObject parameter to the listener callback function when the
  478. parameter changes.
  479. @param inEvent
  480. The type of event to listen for.
  481. @result An OSStatus error code.
  482. }
  483. function AUEventListenerAddEventType( inListener: AUEventListenerRef; inObject: UnivPtr {__nullable}; const (*var*) inEvent: AudioUnitEvent ): OSStatus; external name '_AUEventListenerAddEventType';
  484. (* API_AVAILABLE(macos(10.3), ios(6.0), watchos(2.0), tvos(9.0)) *)
  485. {!
  486. @function AUEventListenerRemoveEventType
  487. @abstract Stop delivering a particular type of events to a listener.
  488. @param inListener
  489. The parameter listener to stop receiving events.
  490. @param inObject
  491. The object which is no longer interested in the value of the parameter.
  492. @param inEvent
  493. The type of event to stop listening for.
  494. @result An OSStatus error code.
  495. }
  496. function AUEventListenerRemoveEventType( inListener: AUEventListenerRef; inObject: UnivPtr {__nullable}; const (*var*) inEvent: AudioUnitEvent ): OSStatus; external name '_AUEventListenerRemoveEventType';
  497. (* API_AVAILABLE(macos(10.3), ios(6.0), watchos(2.0), tvos(9.0)) *)
  498. {!
  499. @function AUEventListenerNotify
  500. @abstract Deliver an AudioUnitEvent to all listeners registered to receive it.
  501. @discussion This is only to be used for notifications about parameter changes (and gestures).
  502. It can not be used for notifying changes to property values as these are
  503. internal to an audio unit and should not be issued outside of the audio unit itself.
  504. @param inSendingListener
  505. A parameter listener generating the change and which does not want to
  506. receive a callback as a result of it. May be NULL.
  507. @param inSendingObject
  508. The object generating the change and which does not want to receive a
  509. callback as a result of it. NULL is treated specially when inListener is
  510. non-null; it signifies that none of the specified listener's objects will
  511. receive notifications.
  512. @param inEvent
  513. The event to be delivered.
  514. @result An OSStatus error code.
  515. }
  516. function AUEventListenerNotify( inSendingListener: AUEventListenerRef {__nullable}; inSendingObject: UnivPtr {__nullable}; const (*var*) inEvent: AudioUnitEvent ): OSStatus; external name '_AUEventListenerNotify';
  517. (* API_AVAILABLE(macos(10.3), ios(6.0), watchos(2.0), tvos(9.0)) *)
  518. { ============================================================================= }
  519. {!
  520. @functiongroup Parameter value utilities
  521. }
  522. {!
  523. @function AUParameterValueFromLinear
  524. @abstract Converts a linear value to a parameter value according to the parameter's units.
  525. @param inLinearValue
  526. The linear value (0.0-1.0) to convert.
  527. @param inParameter
  528. The parameter, including its Audio Unit, that will define the conversion of
  529. the supplied linear value to a value that is natural to that parameter.
  530. @result
  531. The converted parameter value, in the parameter's natural units.
  532. @discussion
  533. }
  534. function AUParameterValueFromLinear( inLinearValue: Float32 { // 0-1 }; const (*var*) inParameter: AudioUnitParameter ): AudioUnitParameterValue; external name '_AUParameterValueFromLinear';
  535. (* API_AVAILABLE(macos(10.2), ios(6.0), watchos(2.0), tvos(9.0)) *)
  536. {!
  537. @function AUParameterValueToLinear
  538. @abstract Converts a parameter value to a linear value according to the parameter's units.
  539. @param inParameterValue
  540. The value in the natural units of the specified parameter.
  541. @param inParameter
  542. The parameter, including its Audio Unit, that will define the conversion of
  543. the supplied parameter value to a corresponding linear value.
  544. @result
  545. A number 0.0-1.0.
  546. @discussion
  547. }
  548. function AUParameterValueToLinear( inParameterValue: AudioUnitParameterValue; const (*var*) inParameter: AudioUnitParameter ): Float32; external name '_AUParameterValueToLinear';
  549. (* API_AVAILABLE(macos(10.2), ios(6.0), watchos(2.0), tvos(9.0)) *)
  550. // returns 0-1
  551. {!
  552. @function AUParameterFormatValue
  553. @abstract Format a parameter value into a string.
  554. @param inParameterValue
  555. The parameter value to be formatted.
  556. @param inParameter
  557. The Audio Unit, scope, element, and parameter whose value this is.
  558. @param inTextBuffer
  559. The character array to receive the formatted text. Should be at least 32
  560. characters.
  561. @param inDigits
  562. The resolution of the string (see example above).
  563. @result
  564. <tt>inTextBuffer</tt>
  565. @discussion
  566. Formats a floating point value into a string. Computes a power of 10 to which the value
  567. will be rounded and displayed as follows: if the the parameter is logarithmic (Hertz),
  568. the number of significant digits is inDigits - pow10(inParameterValue) + 1. Otherwise,
  569. it is inDigits - pow10(maxValue - minValue) + 1.
  570. Example for inDigits=3:
  571. <pre>
  572. pow10 range digits after decimal place display
  573. -2 .0100-.0999 4
  574. -1 .100-.999 3
  575. 0 1.00-9.99 2
  576. 1 10.0-99.9 1
  577. 2 100-999 0
  578. 3 1000-9990 -1
  579. 4 10000-99900 -2</pre>
  580. }
  581. function AUParameterFormatValue( inParameterValue: Float64; const (*var*) inParameter: AudioUnitParameter; var inTextBuffer: char; inDigits: UInt32 ): CStringPtr; external name '_AUParameterFormatValue';
  582. (* API_AVAILABLE(macos(10.2), ios(6.0), watchos(2.0), tvos(9.0)) *)
  583. //CF_ASSUME_NONNULL_END
  584. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  585. end.
  586. {$endc} {not MACOSALLINCLUDE}