You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

498 lines
22KB

  1. /* ladspa.h
  2. Version 1. Copyright 2000 Richard W.E. Furse, Paul Barton-Davis,
  3. Stefan Westerfeld. */
  4. #ifndef LADSPA_INCLUDED
  5. #define LADSPA_INCLUDED
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. /*****************************************************************************/
  10. /* Overview:
  11. There is a large number of synthesis packages in use or development
  12. on the Linux platform at this time. This API (`The Linux Audio
  13. Developer's Simple Plugin API') attempts to give programmers the
  14. ability to write simple `plugin' audio processors in C/C++ and link
  15. them dynamically (`plug') into a range of these packages (`hosts').
  16. It should be possible for any host and any plugin to communicate
  17. completely through this interface. The LADSPA plugin API is free to
  18. use.
  19. This API is deliberately short and simple. To achieve compatibility
  20. with a range of promising Linux sound synthesis packages it
  21. attempts to find the `greatest common divisor' in their logical
  22. behaviour. Having said this, certain limiting decisions are
  23. implicit, notably the use of a fixed type (LADSPA_Data) for all
  24. data transfer and absence of a parameterised `initialisation'
  25. phase. See below for the LADSPA_Data typedef.
  26. Plugins are expected to distinguish between control and audio
  27. data. Plugins have `ports' that are inputs or outputs for audio or
  28. control data and each plugin is `run' for a `block' corresponding
  29. to a short time interval measured in samples. Audio data is
  30. communicated using arrays of LADSPA_Data, allowing a block of audio
  31. to be processed by the plugin in a single pass. Control data is
  32. communicated using single LADSPA_Data values. Control data has a
  33. single value at the start of a call to the `run()' or `run_adding()'
  34. function, and may be considered to remain this value for its
  35. duration. The plugin may assume that all its input and output ports
  36. have been connected to the relevant data location (see the
  37. `connect_port()' function below) before it is asked to run.
  38. Plugins will reside in shared object files suitable for dynamic
  39. linking by dlopen() and family. The file will provide a number of
  40. `plugin types' that can be used to instantiate actual plugins
  41. (sometimes known as `plugin instances') that can be connected
  42. together to perform tasks.
  43. This API contains very limited error-handling. */
  44. /*****************************************************************************/
  45. /* Fundamental data type passed in and out of plugin. This data type
  46. is used to communicate audio samples and control values. It is
  47. assumed that the plugin will work sensibly given any numeric input
  48. value although it may have a preferred range (see hints below). */
  49. typedef float LADSPA_Data;
  50. /*****************************************************************************/
  51. /* Special Plugin Properties:
  52. Optional features of the plugin type are encapsulated in the
  53. LADSPA_Properties type. This is assembled by ORing individual
  54. properties together. */
  55. typedef int LADSPA_Properties;
  56. /* Property LADSPA_PROPERTY_REALTIME indicates that the plugin has a
  57. real-time dependency (e.g. listens to a MIDI device) and so its
  58. output must not be cached or subject to significant latency. */
  59. #define LADSPA_PROPERTY_REALTIME 0x1
  60. /* Property LADSPA_PROPERTY_INPLACE_BROKEN indicates that the plugin
  61. may cease to work correctly if the host elects to use the same data
  62. location for both input and output (see connect_port()). This
  63. should be avoided as enabling this flag makes it impossible for
  64. hosts to use the plugin to process audio `in-place.' */
  65. #define LADSPA_PROPERTY_INPLACE_BROKEN 0x2
  66. /* Property LADSPA_PROPERTY_HARD_RT_CAPABLE indicates that the plugin
  67. is capable of running not only in a conventional host but also in a
  68. `hard real-time' environment. To qualify for this the plugin must
  69. satisfy all of the following:
  70. (1) The plugin must not use malloc(), free() or other heap memory
  71. management within its run() or run_adding() functions. All new
  72. memory used in run() must be managed via the stack. These
  73. restrictions only apply to the run() function.
  74. (2) The plugin will not attempt to make use of any library
  75. functions with the exceptions of functions in the ANSI standard C
  76. and C maths libraries, which the host is expected to provide.
  77. (3) The plugin will not access files, devices, pipes, sockets, IPC
  78. or any other mechanism that might result in process or thread
  79. blocking.
  80. (4) The plugin will take an amount of time to execute a run() or
  81. run_adding() call approximately of form (A+B*SampleCount) where A
  82. and B depend on the machine and host in use. This amount of time
  83. may not depend on input signals or plugin state. The host is left
  84. the responsibility to perform timings to estimate upper bounds for
  85. A and B. */
  86. #define LADSPA_PROPERTY_HARD_RT_CAPABLE 0x4
  87. #define LADSPA_IS_REALTIME(x) ((x) & LADSPA_PROPERTY_REALTIME)
  88. #define LADSPA_IS_INPLACE_BROKEN(x) ((x) & LADSPA_PROPERTY_INPLACE_BROKEN)
  89. #define LADSPA_IS_HARD_RT_CAPABLE(x) ((x) & LADSPA_PROPERTY_HARD_RT_CAPABLE)
  90. /*****************************************************************************/
  91. /* Plugin Ports:
  92. Plugins have `ports' that are inputs or outputs for audio or
  93. data. Ports can communicate arrays of LADSPA_Data (for audio
  94. inputs/outputs) or single LADSPA_Data values (for control
  95. input/outputs). This information is encapsulated in the
  96. LADSPA_PortDescriptor type which is assembled by ORing individual
  97. properties together.
  98. Note that a port must be an input or an output port but not both
  99. and that a port must be a control or audio port but not both. */
  100. typedef int LADSPA_PortDescriptor;
  101. /* Property LADSPA_PORT_INPUT indicates that the port is an input. */
  102. #define LADSPA_PORT_INPUT 0x1
  103. /* Property LADSPA_PORT_OUTPUT indicates that the port is an output. */
  104. #define LADSPA_PORT_OUTPUT 0x2
  105. /* Property LADSPA_PORT_CONTROL indicates that the port is a control
  106. port. */
  107. #define LADSPA_PORT_CONTROL 0x4
  108. /* Property LADSPA_PORT_AUDIO indicates that the port is a audio
  109. port. */
  110. #define LADSPA_PORT_AUDIO 0x8
  111. #define LADSPA_IS_PORT_INPUT(x) ((x) & LADSPA_PORT_INPUT)
  112. #define LADSPA_IS_PORT_OUTPUT(x) ((x) & LADSPA_PORT_OUTPUT)
  113. #define LADSPA_IS_PORT_CONTROL(x) ((x) & LADSPA_PORT_CONTROL)
  114. #define LADSPA_IS_PORT_AUDIO(x) ((x) & LADSPA_PORT_AUDIO)
  115. /*****************************************************************************/
  116. /* Plugin Port Range Hints:
  117. The host may wish to provide a representation of data entering or
  118. leaving a plugin (e.g. to generate a GUI automatically). To make
  119. this more meaningful, the plugin should provide `hints' to the host
  120. describing the usual values taken by the data.
  121. Note that these are only hints. The host may ignore them and the
  122. plugin must not assume that data supplied to it is meaningful. If
  123. the plugin receives invalid input data it is expected to continue
  124. to run without failure and, where possible, produce a sensible
  125. output (e.g. a high-pass filter given a negative cutoff frequency
  126. might switch to an all-pass mode).
  127. Hints are meaningful for all input and output ports but hints for
  128. input control ports are expected to be particularly useful.
  129. More hint information is encapsulated in the
  130. LADSPA_PortRangeHintDescriptor type which is assembled by ORing
  131. individual hint types together. Hints may require further
  132. LowerBound and UpperBound information.
  133. All the hint information for a particular port is aggregated in the
  134. LADSPA_PortRangeHint structure. */
  135. typedef int LADSPA_PortRangeHintDescriptor;
  136. /* Hint LADSPA_HINT_BOUNDED_BELOW indicates that the LowerBound field
  137. of the LADSPA_PortRangeHint should be considered meaningful. The
  138. value in this field should be considered the (inclusive) lower
  139. bound of the valid range. If LADSPA_HINT_SAMPLE_RATE is also
  140. specified then the value of LowerBound should be multiplied by the
  141. sample rate. */
  142. #define LADSPA_HINT_BOUNDED_BELOW 0x1
  143. /* Hint LADSPA_HINT_BOUNDED_ABOVE indicates that the UpperBound field
  144. of the LADSPA_PortRangeHint should be considered meaningful. The
  145. value in this field should be considered the (inclusive) upper
  146. bound of the valid range. If LADSPA_HINT_SAMPLE_RATE is also
  147. specified then the value of UpperBound should be multiplied by the
  148. sample rate. */
  149. #define LADSPA_HINT_BOUNDED_ABOVE 0x2
  150. /* Hint LADSPA_HINT_TOGGLED indicates that the data item should be
  151. considered a Boolean toggle. Data less than or equal to zero should
  152. be considered `off' or `false,' and data above zero should be
  153. considered `on' or `true.' LADSPA_HINT_TOGGLED may not be used in
  154. conjunction with any other hint. */
  155. #define LADSPA_HINT_TOGGLED 0x4
  156. /* Hint LADSPA_HINT_SAMPLE_RATE indicates that any bounds specified
  157. should be interpreted as multiples of the sample rate. For
  158. instance, a frequency range from 0Hz to the Nyquist frequency (half
  159. the sample rate) could be requested by this hint in conjunction
  160. with LowerBound = 0 and UpperBound = 0.5. Hosts that support bounds
  161. at all must support this hint to retain meaning. */
  162. #define LADSPA_HINT_SAMPLE_RATE 0x8
  163. /* Hint LADSPA_HINT_LOGARITHMIC indicates that it is likely that the
  164. user will find it more intuitive to view values using a logarithmic
  165. scale. This is particularly useful for frequencies and gains. */
  166. #define LADSPA_HINT_LOGARITHMIC 0x10
  167. /* Hint LADSPA_HINT_INTEGER indicates that a user interface would
  168. probably wish to provide a stepped control taking only integer
  169. values. Any bounds set should be slightly wider than the actual
  170. integer range required to avoid floating point rounding errors. For
  171. instance, the integer set {0,1,2,3} might be described as [-0.1,
  172. 3.1]. */
  173. #define LADSPA_HINT_INTEGER 0x20
  174. #define LADSPA_IS_HINT_BOUNDED_BELOW(x) ((x) & LADSPA_HINT_BOUNDED_BELOW)
  175. #define LADSPA_IS_HINT_BOUNDED_ABOVE(x) ((x) & LADSPA_HINT_BOUNDED_ABOVE)
  176. #define LADSPA_IS_HINT_TOGGLED(x) ((x) & LADSPA_HINT_TOGGLED)
  177. #define LADSPA_IS_HINT_SAMPLE_RATE(x) ((x) & LADSPA_HINT_SAMPLE_RATE)
  178. #define LADSPA_IS_HINT_LOGARITHMIC(x) ((x) & LADSPA_HINT_LOGARITHMIC)
  179. #define LADSPA_IS_HINT_INTEGER(x) ((x) & LADSPA_HINT_INTEGER)
  180. typedef struct _LADSPA_PortRangeHint {
  181. /* Hints about the port. */
  182. LADSPA_PortRangeHintDescriptor HintDescriptor;
  183. /* Meaningful when hint LADSPA_HINT_BOUNDED_BELOW is active. When
  184. LADSPA_HINT_SAMPLE_RATE is also active then this value should be
  185. multiplied by the relevant sample rate. */
  186. LADSPA_Data LowerBound;
  187. /* Meaningful when hint LADSPA_HINT_BOUNDED_ABOVE is active. When
  188. LADSPA_HINT_SAMPLE_RATE is also active then this value should be
  189. multiplied by the relevant sample rate. */
  190. LADSPA_Data UpperBound;
  191. } LADSPA_PortRangeHint;
  192. /*****************************************************************************/
  193. /* Plugin Handles:
  194. This plugin handle indicates a particular instance of the plugin
  195. concerned. It is valid to compare this to NULL (0 for C++) but
  196. otherwise the host should not attempt to interpret it. The plugin
  197. may use it to reference internal instance data. */
  198. typedef void * LADSPA_Handle;
  199. /*****************************************************************************/
  200. /* Descriptor for a Type of Plugin:
  201. This structure is used to describe a plugin type. It provides a
  202. number of functions to examine the type, instantiate it, link it to
  203. buffers and workspaces and to run it. */
  204. typedef struct _LADSPA_Descriptor {
  205. /* This numeric identifier indicates the plugin type
  206. uniquely. Plugin programmers may reserve ranges of IDs from a
  207. central body to avoid clashes. Hosts may assume that IDs are
  208. below 0x1000000. */
  209. unsigned long UniqueID;
  210. /* This identifier can be used as a unique, case-sensitive
  211. identifier for the plugin type within the plugin file. Plugin
  212. types should be identified by file and label rather than by index
  213. or plugin name, which may be changed in new plugin
  214. versions. Labels must not contain white-space characters. */
  215. const char * Label;
  216. /* This indicates a number of properties of the plugin. */
  217. LADSPA_Properties Properties;
  218. /* This member points to the null-terminated name of the plugin
  219. (e.g. "Sine Oscillator"). */
  220. const char * Name;
  221. /* This member points to the null-terminated string indicating the
  222. maker of the plugin. This can be an empty string but not NULL. */
  223. const char * Maker;
  224. /* This member points to the null-terminated string indicating any
  225. copyright applying to the plugin. If no Copyright applies the
  226. string "None" should be used. */
  227. const char * Copyright;
  228. /* This indicates the number of ports (input AND output) present on
  229. the plugin. */
  230. unsigned long PortCount;
  231. /* This member indicates an array of port descriptors. Valid indices
  232. vary from 0 to PortCount-1. */
  233. const LADSPA_PortDescriptor * PortDescriptors;
  234. /* This member indicates an array of null-terminated strings
  235. describing ports (e.g. "Frequency (Hz)"). Valid indices vary from
  236. 0 to PortCount-1. */
  237. const char * const * PortNames;
  238. /* This member indicates an array of range hints for each port (see
  239. above). Valid indices vary from 0 to PortCount-1. */
  240. const LADSPA_PortRangeHint * PortRangeHints;
  241. /* This may be used by the plugin developer to pass any custom
  242. implementation data into an instantiate call. It must not be used
  243. or interpreted by the host. It is expected that most plugin
  244. writers will not use this facility as LADSPA_Handle should be
  245. used to hold instance data. */
  246. void * ImplementationData;
  247. /* This member is a function pointer that instantiates a plugin. A
  248. handle is returned indicating the new plugin instance. The
  249. instantiation function accepts a sample rate as a parameter. The
  250. plugin descriptor from which this instantiate function was found
  251. must also be passed. This function must return NULL if
  252. instantiation fails.
  253. Note that instance initialisation should generally occur in
  254. activate() rather than here. */
  255. LADSPA_Handle (*instantiate)(const struct _LADSPA_Descriptor * Descriptor,
  256. unsigned long SampleRate);
  257. /* This member is a function pointer that connects a port on an
  258. instantiated plugin to a memory location at which a block of data
  259. for the port will be read/written. The data location is expected
  260. to be an array of LADSPA_Data for audio ports or a single
  261. LADSPA_Data value for control ports. Memory issues will be
  262. managed by the host. The plugin must read/write the data at these
  263. locations every time run() or run_adding() is called and the data
  264. present at the time of this connection call should not be
  265. considered meaningful.
  266. connect_port() may be called more than once for a plugin instance
  267. to allow the host to change the buffers that the plugin is
  268. reading or writing. These calls may be made before or after
  269. activate() or deactivate() calls.
  270. connect_port() must be called at least once for each port before
  271. run() or run_adding() is called. When working with blocks of
  272. LADSPA_Data the plugin should pay careful attention to the block
  273. size passed to the run function as the block allocated may only
  274. just be large enough to contain the block of samples.
  275. Plugin writers should be aware that the host may elect to use the
  276. same buffer for more than one port and even use the same buffer
  277. for both input and output (see LADSPA_PROPERTY_INPLACE_BROKEN).
  278. However, overlapped buffers or use of a single buffer for both
  279. audio and control data may result in unexpected behaviour. */
  280. void (*connect_port)(LADSPA_Handle Instance,
  281. unsigned long Port,
  282. LADSPA_Data * DataLocation);
  283. /* This member is a function pointer that initialises a plugin
  284. instance and activates it for use. This is separated from
  285. instantiate() to aid real-time support and so that hosts can
  286. reinitialise a plugin instance by calling deactivate() and then
  287. activate(). In this case the plugin instance must reset all state
  288. information dependent on the history of the plugin instance
  289. except for any data locations provided by connect_port() and any
  290. gain set by set_run_adding_gain(). If there is nothing for
  291. activate() to do then the plugin writer may provide a NULL rather
  292. than an empty function.
  293. When present, hosts must call this function once before run() (or
  294. run_adding()) is called for the first time. This call should be
  295. made as close to the run() call as possible and indicates to
  296. real-time plugins that they are now live. Plugins should not rely
  297. on a prompt call to run() after activate(). activate() may not be
  298. called again unless deactivate() is called first. Note that
  299. connect_port() may be called before or after a call to
  300. activate(). */
  301. void (*activate)(LADSPA_Handle Instance);
  302. /* This method is a function pointer that runs an instance of a
  303. plugin for a block. Two parameters are required: the first is a
  304. handle to the particular instance to be run and the second
  305. indicates the block size (in samples) for which the plugin
  306. instance may run.
  307. Note that if an activate() function exists then it must be called
  308. before run() or run_adding(). If deactivate() is called for a
  309. plugin instance then the plugin instance may not be reused until
  310. activate() has been called again.
  311. If the plugin has the property LADSPA_PROPERTY_HARD_RT_CAPABLE
  312. then there are various things that the plugin should not do
  313. within the run() or run_adding() functions (see above). */
  314. void (*run)(LADSPA_Handle Instance,
  315. unsigned long SampleCount);
  316. /* This method is a function pointer that runs an instance of a
  317. plugin for a block. This has identical behaviour to run() except
  318. in the way data is output from the plugin. When run() is used,
  319. values are written directly to the memory areas associated with
  320. the output ports. However when run_adding() is called, values
  321. must be added to the values already present in the memory
  322. areas. Furthermore, output values written must be scaled by the
  323. current gain set by set_run_adding_gain() (see below) before
  324. addition.
  325. run_adding() is optional. When it is not provided by a plugin,
  326. this function pointer must be set to NULL. When it is provided,
  327. the function set_run_adding_gain() must be provided also. */
  328. void (*run_adding)(LADSPA_Handle Instance,
  329. unsigned long SampleCount);
  330. /* This method is a function pointer that sets the output gain for
  331. use when run_adding() is called (see above). If this function is
  332. never called the gain is assumed to default to 1. Gain
  333. information should be retained when activate() or deactivate()
  334. are called.
  335. This function should be provided by the plugin if and only if the
  336. run_adding() function is provided. When it is absent this
  337. function pointer must be set to NULL. */
  338. void (*set_run_adding_gain)(LADSPA_Handle Instance,
  339. LADSPA_Data Gain);
  340. /* This is the counterpart to activate() (see above). If there is
  341. nothing for deactivate() to do then the plugin writer may provide
  342. a NULL rather than an empty function.
  343. Hosts must deactivate all activated units after they have been
  344. run() (or run_adding()) for the last time. This call should be
  345. made as close to the last run() call as possible and indicates to
  346. real-time plugins that they are no longer live. Plugins should
  347. not rely on prompt deactivation. Note that connect_port() may be
  348. called before or after a call to deactivate().
  349. Deactivation is not similar to pausing as the plugin instance
  350. will be reinitialised when activate() is called to reuse it. */
  351. void (*deactivate)(LADSPA_Handle Instance);
  352. /* Once an instance of a plugin has been finished with it can be
  353. deleted using the following function. The instance handle passed
  354. ceases to be valid after this call.
  355. If activate() was called for a plugin instance then a
  356. corresponding call to deactivate() must be made before cleanup()
  357. is called. */
  358. void (*cleanup)(LADSPA_Handle Instance);
  359. } LADSPA_Descriptor;
  360. /**********************************************************************/
  361. /* Accessing a Plugin: */
  362. /* The exact mechanism by which plugins are loaded is host-dependent,
  363. however all most hosts will need to know is the name of shared
  364. object file containing the plugin types. To allow multiple hosts to
  365. share plugin types, hosts may wish to check for environment
  366. variable LADSPA_PATH. If present, this should contain a
  367. colon-separated path indicating directories that should be searched
  368. (in order) when loading plugin types.
  369. A plugin programmer must include a function called
  370. "ladspa_descriptor" with the following function prototype within
  371. the shared object file. This function will have C-style linkage (if
  372. you are using C++ this is taken care of by the `extern "C"' clause
  373. at the top of the file).
  374. A host will find the plugin shared object file by one means or
  375. another, find the ladspa_descriptor() function, call it, and
  376. proceed from there.
  377. Plugin types are accessed by index (not ID) using values from 0
  378. upwards. Out of range indexes must result in this function
  379. returning NULL, so the plugin count can be determined by checking
  380. for the least index that results in NULL being returned. */
  381. const LADSPA_Descriptor * ladspa_descriptor(unsigned long Index);
  382. /* Datatype corresponding to the ladspa_descriptor() function. */
  383. typedef const LADSPA_Descriptor *
  384. (*LADSPA_Descriptor_Function)(unsigned long Index);
  385. /**********************************************************************/
  386. #ifdef __cplusplus
  387. };
  388. #endif
  389. #endif /* LADSPA_INCLUDED */
  390. /* EOF */