Audio plugin host https://kx.studio/carla
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.

356 lines
19KB

  1. //------------------------------------------------------------------------
  2. // Project : VST SDK
  3. //
  4. // Category : Interfaces
  5. // Filename : pluginterfaces/vst/ivstaudioprocessor.h
  6. // Created by : Steinberg, 10/2005
  7. // Description : VST Audio Processing Interfaces
  8. //
  9. //-----------------------------------------------------------------------------
  10. // This file is part of a Steinberg SDK. It is subject to the license terms
  11. // in the LICENSE file found in the top-level directory of this distribution
  12. // and at www.steinberg.net/sdklicenses.
  13. // No part of the SDK, including this file, may be copied, modified, propagated,
  14. // or distributed except according to the terms contained in the LICENSE file.
  15. //-----------------------------------------------------------------------------
  16. #pragma once
  17. #include "ivstcomponent.h"
  18. #include "vstspeaker.h"
  19. //------------------------------------------------------------------------
  20. #include "pluginterfaces/base/falignpush.h"
  21. //------------------------------------------------------------------------
  22. //------------------------------------------------------------------------
  23. /** Class Category Name for Audio Processor Component */
  24. //------------------------------------------------------------------------
  25. #ifndef kVstAudioEffectClass
  26. #define kVstAudioEffectClass "Audio Module Class"
  27. #endif
  28. //------------------------------------------------------------------------
  29. namespace Steinberg {
  30. namespace Vst {
  31. class IEventList;
  32. class IParameterChanges;
  33. struct ProcessContext;
  34. //------------------------------------------------------------------------
  35. /** Component Types used as subCategories in PClassInfo2 */
  36. //------------------------------------------------------------------------
  37. namespace PlugType
  38. {
  39. /**
  40. \defgroup plugType Plug-in Type used for subCategories */
  41. /*@{*/
  42. //------------------------------------------------------------------------
  43. const CString kFxAnalyzer = "Fx|Analyzer"; ///< Scope, FFT-Display, Loudness Processing...
  44. const CString kFxDelay = "Fx|Delay"; ///< Delay, Multi-tap Delay, Ping-Pong Delay...
  45. const CString kFxDistortion = "Fx|Distortion"; ///< Amp Simulator, Sub-Harmonic, SoftClipper...
  46. const CString kFxDynamics = "Fx|Dynamics"; ///< Compressor, Expander, Gate, Limiter, Maximizer, Tape Simulator, EnvelopeShaper...
  47. const CString kFxEQ = "Fx|EQ"; ///< Equalization, Graphical EQ...
  48. const CString kFxFilter = "Fx|Filter"; ///< WahWah, ToneBooster, Specific Filter,...
  49. const CString kFx = "Fx"; ///< others type (not categorized)
  50. const CString kFxInstrument = "Fx|Instrument"; ///< Fx which could be loaded as Instrument too
  51. const CString kFxInstrumentExternal = "Fx|Instrument|External"; ///< Fx which could be loaded as Instrument too and is external (wrapped Hardware)
  52. const CString kFxSpatial = "Fx|Spatial"; ///< MonoToStereo, StereoEnhancer,...
  53. const CString kFxGenerator = "Fx|Generator"; ///< Tone Generator, Noise Generator...
  54. const CString kFxMastering = "Fx|Mastering"; ///< Dither, Noise Shaping,...
  55. const CString kFxModulation = "Fx|Modulation"; ///< Phaser, Flanger, Chorus, Tremolo, Vibrato, AutoPan, Rotary, Cloner...
  56. const CString kFxPitchShift = "Fx|Pitch Shift"; ///< Pitch Processing, Pitch Correction, Vocal Tuning...
  57. const CString kFxRestoration = "Fx|Restoration"; ///< Denoiser, Declicker,...
  58. const CString kFxReverb = "Fx|Reverb"; ///< Reverberation, Room Simulation, Convolution Reverb...
  59. const CString kFxSurround = "Fx|Surround"; ///< dedicated to surround processing: LFE Splitter, Bass Manager...
  60. const CString kFxTools = "Fx|Tools"; ///< Volume, Mixer, Tuner...
  61. const CString kFxNetwork = "Fx|Network"; ///< using Network
  62. const CString kInstrument = "Instrument"; ///< Effect used as instrument (sound generator), not as insert
  63. const CString kInstrumentDrum = "Instrument|Drum"; ///< Instrument for Drum sounds
  64. const CString kInstrumentExternal = "Instrument|External";///< External Instrument (wrapped Hardware)
  65. const CString kInstrumentPiano = "Instrument|Piano"; ///< Instrument for Piano sounds
  66. const CString kInstrumentSampler = "Instrument|Sampler"; ///< Instrument based on Samples
  67. const CString kInstrumentSynth = "Instrument|Synth"; ///< Instrument based on Synthesis
  68. const CString kInstrumentSynthSampler = "Instrument|Synth|Sampler"; ///< Instrument based on Synthesis and Samples
  69. const CString kSpatial = "Spatial"; ///< used for SurroundPanner
  70. const CString kSpatialFx = "Spatial|Fx"; ///< used for SurroundPanner and as insert effect
  71. const CString kOnlyRealTime = "OnlyRT"; ///< indicates that it supports only realtime process call, no processing faster than realtime
  72. const CString kOnlyOfflineProcess = "OnlyOfflineProcess"; ///< used for Plug-in offline processing (will not work as normal insert Plug-in)
  73. const CString kNoOfflineProcess = "NoOfflineProcess"; ///< will be NOT used for Plug-in offline processing (will work as normal insert Plug-in)
  74. const CString kUpDownMix = "Up-Downmix"; ///< used for Mixconverter/Up-Mixer/Down-Mixer
  75. const CString kAnalyzer = "Analyzer"; ///< Meter, Scope, FFT-Display, not selectable as insert plugin
  76. const CString kAmbisonics = "Ambisonics"; ///< used for Ambisonics channel (FX or Panner/Mixconverter/Up-Mixer/Down-Mixer when combined with other category)
  77. const CString kMono = "Mono"; ///< used for Mono only Plug-in [optional]
  78. const CString kStereo = "Stereo"; ///< used for Stereo only Plug-in [optional]
  79. const CString kSurround = "Surround"; ///< used for Surround only Plug-in [optional]
  80. //------------------------------------------------------------------------
  81. /*@}*/
  82. }
  83. //------------------------------------------------------------------------
  84. /** Component Flags used as classFlags in PClassInfo2 */
  85. //------------------------------------------------------------------------
  86. enum ComponentFlags
  87. {
  88. //------------------------------------------------------------------------
  89. kDistributable = 1 << 0, ///< Component can be run on remote computer
  90. kSimpleModeSupported = 1 << 1 ///< Component supports simple IO mode (or works in simple mode anyway) see \ref vst3IoMode
  91. //------------------------------------------------------------------------
  92. };
  93. //------------------------------------------------------------------------
  94. /** Symbolic sample size.
  95. \see ProcessSetup, ProcessData */
  96. //------------------------------------------------------------------------
  97. enum SymbolicSampleSizes
  98. {
  99. kSample32, ///< 32-bit precision
  100. kSample64 ///< 64-bit precision
  101. };
  102. //------------------------------------------------------------------------
  103. /** Processing mode informs the Plug-in about the context and at which frequency the process call is called.
  104. VST3 defines 3 modes:
  105. - kRealtime: each process call is called at a realtime frequency (defined by [numSamples of ProcessData] / samplerate).
  106. The Plug-in should always try to process as fast as possible in order to let enough time slice to other Plug-ins.
  107. - kPrefetch: each process call could be called at a variable frequency (jitter, slower / faster than realtime),
  108. the Plug-in should process at the same quality level than realtime, Plug-in must not slow down to realtime
  109. (e.g. disk streaming)!
  110. The host should avoid to process in kPrefetch mode such sampler based Plug-in.
  111. - kOffline: each process call could be faster than realtime or slower, higher quality than realtime could be used.
  112. Plug-ins using disk streaming should be sure that they have enough time in the process call for streaming,
  113. if needed by slowing down to realtime or slower.
  114. .
  115. Note about Process Modes switching:
  116. -Switching between kRealtime and kPrefetch process modes are done in realtime thread without need of calling
  117. IAudioProcessor::setupProcessing, the Plug-in should check in process call the member processMode of ProcessData
  118. in order to know in which mode it is processed.
  119. -Switching between kRealtime (or kPrefetch) and kOffline requires that the host calls IAudioProcessor::setupProcessing
  120. in order to inform the Plug-in about this mode change.
  121. .
  122. \see ProcessSetup, ProcessData */
  123. //------------------------------------------------------------------------
  124. enum ProcessModes
  125. {
  126. kRealtime, ///< realtime processing
  127. kPrefetch, ///< prefetch processing
  128. kOffline ///< offline processing
  129. };
  130. //------------------------------------------------------------------------
  131. /** kNoTail
  132. *
  133. * to be returned by getTailSamples when no tail is wanted
  134. \see IAudioProcessor::getTailSamples */
  135. //------------------------------------------------------------------------
  136. static const uint32 kNoTail = 0;
  137. //------------------------------------------------------------------------
  138. /** kInfiniteTail
  139. *
  140. * to be returned by getTailSamples when infinite tail is wanted
  141. \see IAudioProcessor::getTailSamples */
  142. //------------------------------------------------------------------------
  143. static const uint32 kInfiniteTail = kMaxInt32u;
  144. //------------------------------------------------------------------------
  145. /** Audio processing setup.
  146. \see IAudioProcessor::setupProcessing */
  147. //------------------------------------------------------------------------
  148. struct ProcessSetup
  149. {
  150. //------------------------------------------------------------------------
  151. int32 processMode; ///< \ref ProcessModes
  152. int32 symbolicSampleSize; ///< \ref SymbolicSampleSizes
  153. int32 maxSamplesPerBlock; ///< maximum number of samples per audio block
  154. SampleRate sampleRate; ///< sample rate
  155. //------------------------------------------------------------------------
  156. };
  157. //------------------------------------------------------------------------
  158. /** Processing buffers of an audio bus.
  159. This structure contains the processing buffer for each channel of an audio bus.
  160. - The number of channels (numChannels) must always match the current bus arrangement.
  161. It could be set to value '0' when the host wants to flush the parameters (when the Plug-in is not processed).
  162. - The size of the channel buffer array must always match the number of channels. So the host
  163. must always supply an array for the channel buffers, regardless if the
  164. bus is active or not. However, if an audio bus is currently inactive, the actual sample
  165. buffer addresses are safe to be null.
  166. - The silence flag is set when every sample of the according buffer has the value '0'. It is
  167. intended to be used as help for optimizations allowing a Plug-in to reduce processing activities.
  168. But even if this flag is set for a channel, the channel buffers must still point to valid memory!
  169. This flag is optional. A host is free to support it or not.
  170. .
  171. \see ProcessData */
  172. //------------------------------------------------------------------------
  173. struct AudioBusBuffers
  174. {
  175. AudioBusBuffers () : numChannels (0), silenceFlags (0), channelBuffers64 (0) {}
  176. //------------------------------------------------------------------------
  177. int32 numChannels; ///< number of audio channels in bus
  178. uint64 silenceFlags; ///< Bitset of silence state per channel
  179. union
  180. {
  181. Sample32** channelBuffers32; ///< sample buffers to process with 32-bit precision
  182. Sample64** channelBuffers64; ///< sample buffers to process with 64-bit precision
  183. };
  184. //------------------------------------------------------------------------
  185. };
  186. //------------------------------------------------------------------------
  187. /** Any data needed in audio processing.
  188. The host prepares AudioBusBuffers for each input/output bus,
  189. regardless of the bus activation state. Bus buffer indices always match
  190. with bus indices used in IComponent::getBusInfo of media type kAudio.
  191. \see AudioBusBuffers, IParameterChanges, IEventList, ProcessContext */
  192. //------------------------------------------------------------------------
  193. struct ProcessData
  194. {
  195. ProcessData ()
  196. : processMode (0), symbolicSampleSize (kSample32), numSamples (0), numInputs (0)
  197. , numOutputs (0), inputs (0), outputs (0), inputParameterChanges (0), outputParameterChanges (0)
  198. , inputEvents (0), outputEvents (0), processContext (0) {}
  199. //------------------------------------------------------------------------
  200. int32 processMode; ///< processing mode - value of \ref ProcessModes
  201. int32 symbolicSampleSize; ///< sample size - value of \ref SymbolicSampleSizes
  202. int32 numSamples; ///< number of samples to process
  203. int32 numInputs; ///< number of audio input buses
  204. int32 numOutputs; ///< number of audio output buses
  205. AudioBusBuffers* inputs; ///< buffers of input buses
  206. AudioBusBuffers* outputs; ///< buffers of output buses
  207. IParameterChanges* inputParameterChanges; ///< incoming parameter changes for this block
  208. IParameterChanges* outputParameterChanges; ///< outgoing parameter changes for this block (optional)
  209. IEventList* inputEvents; ///< incoming events for this block (optional)
  210. IEventList* outputEvents; ///< outgoing events for this block (optional)
  211. ProcessContext* processContext; ///< processing context (optional, but most welcome)
  212. //------------------------------------------------------------------------
  213. };
  214. //------------------------------------------------------------------------
  215. /** Audio Processing Interface.
  216. \ingroup vstIPlug vst300
  217. - [plug imp]
  218. - [extends IComponent]
  219. - [released: 3.0.0]
  220. - [mandatory]
  221. This interface must always be supported by audio processing Plug-ins. */
  222. //------------------------------------------------------------------------
  223. class IAudioProcessor: public FUnknown
  224. {
  225. public:
  226. //------------------------------------------------------------------------
  227. /** Try to set (from host) a predefined arrangement for inputs and outputs.
  228. The host should always deliver the same number of input and output buses than the Plug-in needs
  229. (see \ref IComponent::getBusCount).
  230. The Plug-in returns kResultFalse if wanted arrangements are not supported.
  231. If the Plug-in accepts these arrangements, it should modify its buses to match the new arrangements
  232. (asked by the host with IComponent::getInfo () or IAudioProcessor::getBusArrangement ()) and then return kResultTrue.
  233. If the Plug-in does not accept these arrangements, but can adapt its current arrangements (according to the wanted ones),
  234. it should modify its buses arrangements and return kResultFalse. */
  235. virtual tresult PLUGIN_API setBusArrangements (SpeakerArrangement* inputs, int32 numIns,
  236. SpeakerArrangement* outputs, int32 numOuts) = 0;
  237. /** Gets the bus arrangement for a given direction (input/output) and index.
  238. Note: IComponent::getInfo () and IAudioProcessor::getBusArrangement () should be always return the same
  239. information about the buses arrangements. */
  240. virtual tresult PLUGIN_API getBusArrangement (BusDirection dir, int32 index, SpeakerArrangement& arr) = 0;
  241. /** Asks if a given sample size is supported see \ref SymbolicSampleSizes. */
  242. virtual tresult PLUGIN_API canProcessSampleSize (int32 symbolicSampleSize) = 0;
  243. /** Gets the current Latency in samples.
  244. The returned value defines the group delay or the latency of the Plug-in. For example, if the Plug-in internally needs
  245. to look in advance (like compressors) 512 samples then this Plug-in should report 512 as latency.
  246. If during the use of the Plug-in this latency change, the Plug-in has to inform the host by
  247. using IComponentHandler::restartComponent (kLatencyChanged), this could lead to audio playback interruption
  248. because the host has to recompute its internal mixer delay compensation.
  249. Note that for player live recording this latency should be zero or small. */
  250. virtual uint32 PLUGIN_API getLatencySamples () = 0;
  251. /** Called in disable state (not active) before processing will begin. */
  252. virtual tresult PLUGIN_API setupProcessing (ProcessSetup& setup) = 0;
  253. /** Informs the Plug-in about the processing state. This will be called before any process calls start with true and after with false.
  254. Note that setProcessing (false) may be called after setProcessing (true) without any process calls.
  255. In this call the Plug-in should do only light operation (no memory allocation or big setup reconfiguration),
  256. this could be used to reset some buffers (like Delay line or Reverb). */
  257. virtual tresult PLUGIN_API setProcessing (TBool state) = 0;
  258. /** The Process call, where all information (parameter changes, event, audio buffer) are passed. */
  259. virtual tresult PLUGIN_API process (ProcessData& data) = 0;
  260. /** Gets tail size in samples. For example, if the Plug-in is a Reverb Plug-in and it knows that
  261. the maximum length of the Reverb is 2sec, then it has to return in getTailSamples()
  262. (in VST2 it was getGetTailSize ()): 2*sampleRate.
  263. This information could be used by host for offline processing, process optimization and
  264. downmix (avoiding signal cut (clicks)).
  265. It should return:
  266. - kNoTail when no tail
  267. - x * sampleRate when x Sec tail.
  268. - kInfiniteTail when infinite tail. */
  269. virtual uint32 PLUGIN_API getTailSamples () = 0;
  270. //------------------------------------------------------------------------
  271. static const FUID iid;
  272. };
  273. DECLARE_CLASS_IID (IAudioProcessor, 0x42043F99, 0xB7DA453C, 0xA569E79D, 0x9AAEC33D)
  274. //------------------------------------------------------------------------
  275. /** Extended IAudioProcessor interface for a component.
  276. \ingroup vstIPlug vst310
  277. - [plug imp]
  278. - [extends IAudioProcessor]
  279. - [released: 3.1.0]
  280. - [optional]
  281. Inform the Plug-in about how long from the moment of generation/acquiring (from file or from Input)
  282. it will take for its input to arrive, and how long it will take for its output to be presented (to output or to Speaker).
  283. Note for Input Presentation Latency: when reading from file, the first Plug-in will have an input presentation latency set to zero.
  284. When monitoring audio input from a Audio Device, then this initial input latency will be the input latency of the Audio Device itself.
  285. Note for Output Presentation Latency: when writing to a file, the last Plug-in will have an output presentation latency set to zero.
  286. When the output of this Plug-in is connected to a Audio Device then this initial output latency will be the output
  287. latency of the Audio Device itself.
  288. A value of zero means either no latency or an unknown latency.
  289. Each Plug-in adding a latency (returning a none zero value for IAudioProcessor::getLatencySamples) will modify the input
  290. presentation latency of the next Plug-ins in the mixer routing graph and will modify the output presentation latency
  291. of the previous Plug-ins.
  292. \n
  293. \image html "iaudiopresentationlatency_usage.png"
  294. \n
  295. \see IAudioProcessor
  296. \see IComponent*/
  297. //------------------------------------------------------------------------
  298. class IAudioPresentationLatency: public FUnknown
  299. {
  300. public:
  301. //------------------------------------------------------------------------
  302. /** Informs the Plug-in about the Audio Presentation Latency in samples for a given direction (kInput/kOutput) and bus index. */
  303. virtual tresult PLUGIN_API setAudioPresentationLatencySamples (BusDirection dir, int32 busIndex, uint32 latencyInSamples) = 0;
  304. //------------------------------------------------------------------------
  305. static const FUID iid;
  306. };
  307. DECLARE_CLASS_IID (IAudioPresentationLatency, 0x309ECE78, 0xEB7D4fae, 0x8B2225D9, 0x09FD08B6)
  308. //------------------------------------------------------------------------
  309. } // namespace Vst
  310. } // namespace Steinberg
  311. //------------------------------------------------------------------------
  312. #include "pluginterfaces/base/falignpop.h"
  313. //------------------------------------------------------------------------