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.

430 lines
22KB

  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. namespace PlugType
  37. {
  38. /**
  39. \defgroup plugType Plug-in Type used for subCategories */
  40. /*@{*/
  41. //------------------------------------------------------------------------
  42. const CString kFxAnalyzer = "Fx|Analyzer"; ///< Scope, FFT-Display, Loudness Processing...
  43. const CString kFxDelay = "Fx|Delay"; ///< Delay, Multi-tap Delay, Ping-Pong Delay...
  44. const CString kFxDistortion = "Fx|Distortion"; ///< Amp Simulator, Sub-Harmonic, SoftClipper...
  45. const CString kFxDynamics = "Fx|Dynamics"; ///< Compressor, Expander, Gate, Limiter, Maximizer, Tape Simulator, EnvelopeShaper...
  46. const CString kFxEQ = "Fx|EQ"; ///< Equalization, Graphical EQ...
  47. const CString kFxFilter = "Fx|Filter"; ///< WahWah, ToneBooster, Specific Filter,...
  48. const CString kFx = "Fx"; ///< others type (not categorized)
  49. const CString kFxInstrument = "Fx|Instrument"; ///< Fx which could be loaded as Instrument too
  50. const CString kFxInstrumentExternal = "Fx|Instrument|External"; ///< Fx which could be loaded as Instrument too and is external (wrapped Hardware)
  51. const CString kFxSpatial = "Fx|Spatial"; ///< MonoToStereo, StereoEnhancer,...
  52. const CString kFxGenerator = "Fx|Generator"; ///< Tone Generator, Noise Generator...
  53. const CString kFxMastering = "Fx|Mastering"; ///< Dither, Noise Shaping,...
  54. const CString kFxModulation = "Fx|Modulation"; ///< Phaser, Flanger, Chorus, Tremolo, Vibrato, AutoPan, Rotary, Cloner...
  55. const CString kFxPitchShift = "Fx|Pitch Shift"; ///< Pitch Processing, Pitch Correction, Vocal Tuning...
  56. const CString kFxRestoration = "Fx|Restoration"; ///< Denoiser, Declicker,...
  57. const CString kFxReverb = "Fx|Reverb"; ///< Reverberation, Room Simulation, Convolution Reverb...
  58. const CString kFxSurround = "Fx|Surround"; ///< dedicated to surround processing: LFE Splitter, Bass Manager...
  59. const CString kFxTools = "Fx|Tools"; ///< Volume, Mixer, Tuner...
  60. const CString kFxNetwork = "Fx|Network"; ///< using Network
  61. const CString kInstrument = "Instrument"; ///< Effect used as instrument (sound generator), not as insert
  62. const CString kInstrumentDrum = "Instrument|Drum"; ///< Instrument for Drum sounds
  63. const CString kInstrumentExternal = "Instrument|External";///< External Instrument (wrapped Hardware)
  64. const CString kInstrumentPiano = "Instrument|Piano"; ///< Instrument for Piano sounds
  65. const CString kInstrumentSampler = "Instrument|Sampler"; ///< Instrument based on Samples
  66. const CString kInstrumentSynth = "Instrument|Synth"; ///< Instrument based on Synthesis
  67. const CString kInstrumentSynthSampler = "Instrument|Synth|Sampler"; ///< Instrument based on Synthesis and Samples
  68. const CString kSpatial = "Spatial"; ///< used for SurroundPanner
  69. const CString kSpatialFx = "Spatial|Fx"; ///< used for SurroundPanner and as insert effect
  70. const CString kOnlyRealTime = "OnlyRT"; ///< indicates that it supports only realtime process call, no processing faster than realtime
  71. const CString kOnlyOfflineProcess = "OnlyOfflineProcess"; ///< used for plug-in offline processing (will not work as normal insert plug-in)
  72. const CString kOnlyARA = "OnlyARA"; ///< used for plug-ins that require ARA to operate (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 plug-in
  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. enum ComponentFlags
  86. {
  87. //------------------------------------------------------------------------
  88. kDistributable = 1 << 0, ///< Component can be run on remote computer
  89. kSimpleModeSupported = 1 << 1 ///< Component supports simple IO mode (or works in simple mode anyway) see \ref vst3IoMode
  90. //------------------------------------------------------------------------
  91. };
  92. //------------------------------------------------------------------------
  93. /** Symbolic sample size.
  94. \see ProcessSetup, ProcessData
  95. */
  96. enum SymbolicSampleSizes
  97. {
  98. kSample32, ///< 32-bit precision
  99. kSample64 ///< 64-bit precision
  100. };
  101. //------------------------------------------------------------------------
  102. /** Processing mode informs the plug-in about the context and at which frequency the process call is called.
  103. VST3 defines 3 modes:
  104. - kRealtime: each process call is called at a realtime frequency (defined by [numSamples of ProcessData] / samplerate).
  105. The plug-in should always try to process as fast as possible in order to let enough time slice to other plug-ins.
  106. - kPrefetch: each process call could be called at a variable frequency (jitter, slower / faster than realtime),
  107. the plug-in should process at the same quality level than realtime, plug-in must not slow down to realtime
  108. (e.g. disk streaming)!
  109. The host should avoid to process in kPrefetch mode such sampler based plug-in.
  110. - kOffline: each process call could be faster than realtime or slower, higher quality than realtime could be used.
  111. plug-ins using disk streaming should be sure that they have enough time in the process call for streaming,
  112. if needed by slowing down to realtime or slower.
  113. .
  114. Note about Process Modes switching:
  115. - Switching between kRealtime and kPrefetch process modes are done in realtime thread without need of calling
  116. IAudioProcessor::setupProcessing, the plug-in should check in process call the member processMode of ProcessData
  117. in order to know in which mode it is processed.
  118. - Switching between kRealtime (or kPrefetch) and kOffline requires that the host calls IAudioProcessor::setupProcessing
  119. in order to inform the plug-in about this mode change.
  120. .
  121. \see ProcessSetup, ProcessData
  122. */
  123. enum ProcessModes
  124. {
  125. kRealtime, ///< realtime processing
  126. kPrefetch, ///< prefetch processing
  127. kOffline ///< offline processing
  128. };
  129. //------------------------------------------------------------------------
  130. /** kNoTail
  131. *
  132. * to be returned by getTailSamples when no tail is wanted
  133. \see IAudioProcessor::getTailSamples
  134. */
  135. static const uint32 kNoTail = 0;
  136. //------------------------------------------------------------------------
  137. /** kInfiniteTail
  138. *
  139. * to be returned by getTailSamples when infinite tail is wanted
  140. \see IAudioProcessor::getTailSamples
  141. */
  142. static const uint32 kInfiniteTail = kMaxInt32u;
  143. //------------------------------------------------------------------------
  144. /** Audio processing setup.
  145. \see IAudioProcessor::setupProcessing
  146. */
  147. struct ProcessSetup
  148. {
  149. //------------------------------------------------------------------------
  150. int32 processMode; ///< \ref ProcessModes
  151. int32 symbolicSampleSize; ///< \ref SymbolicSampleSizes
  152. int32 maxSamplesPerBlock; ///< maximum number of samples per audio block
  153. SampleRate sampleRate; ///< sample rate
  154. //------------------------------------------------------------------------
  155. };
  156. //------------------------------------------------------------------------
  157. /** Processing buffers of an audio bus.
  158. This structure contains the processing buffer for each channel of an audio bus.
  159. - The number of channels (numChannels) must always match the current bus arrangement.
  160. It could be set to value '0' when the host wants to flush the parameters (when the plug-in is not processed).
  161. - The size of the channel buffer array must always match the number of channels. So the host
  162. must always supply an array for the channel buffers, regardless if the
  163. bus is active or not. However, if an audio bus is currently inactive, the actual sample
  164. buffer addresses are safe to be null.
  165. - The silence flag is set when every sample of the according buffer has the value '0'. It is
  166. intended to be used as help for optimizations allowing a plug-in to reduce processing activities.
  167. But even if this flag is set for a channel, the channel buffers must still point to valid memory!
  168. This flag is optional. A host is free to support it or not.
  169. .
  170. \see ProcessData
  171. */
  172. struct AudioBusBuffers
  173. {
  174. AudioBusBuffers () : numChannels (0), silenceFlags (0), channelBuffers64 (nullptr) {}
  175. //------------------------------------------------------------------------
  176. int32 numChannels; ///< number of audio channels in bus
  177. uint64 silenceFlags; ///< Bitset of silence state per channel
  178. union
  179. {
  180. Sample32** channelBuffers32; ///< sample buffers to process with 32-bit precision
  181. Sample64** channelBuffers64; ///< sample buffers to process with 64-bit precision
  182. };
  183. //------------------------------------------------------------------------
  184. };
  185. //------------------------------------------------------------------------
  186. /** Any data needed in audio processing.
  187. The host prepares AudioBusBuffers for each input/output bus,
  188. regardless of the bus activation state. Bus buffer indices always match
  189. with bus indices used in IComponent::getBusInfo of media type kAudio.
  190. \see AudioBusBuffers, IParameterChanges, IEventList, ProcessContext, IProcessContextRequirements
  191. */
  192. struct ProcessData
  193. {
  194. ProcessData ()
  195. : processMode (0)
  196. , symbolicSampleSize (kSample32)
  197. , numSamples (0)
  198. , numInputs (0)
  199. , numOutputs (0)
  200. , inputs (nullptr)
  201. , outputs (nullptr)
  202. , inputParameterChanges (nullptr)
  203. , outputParameterChanges (nullptr)
  204. , inputEvents (nullptr)
  205. , outputEvents (nullptr)
  206. , processContext (nullptr)
  207. {
  208. }
  209. //------------------------------------------------------------------------
  210. int32 processMode; ///< processing mode - value of \ref ProcessModes
  211. int32 symbolicSampleSize; ///< sample size - value of \ref SymbolicSampleSizes
  212. int32 numSamples; ///< number of samples to process
  213. int32 numInputs; ///< number of audio input busses
  214. int32 numOutputs; ///< number of audio output busses
  215. AudioBusBuffers* inputs; ///< buffers of input busses
  216. AudioBusBuffers* outputs; ///< buffers of output busses
  217. IParameterChanges* inputParameterChanges; ///< incoming parameter changes for this block
  218. IParameterChanges* outputParameterChanges; ///< outgoing parameter changes for this block (optional)
  219. IEventList* inputEvents; ///< incoming events for this block (optional)
  220. IEventList* outputEvents; ///< outgoing events for this block (optional)
  221. ProcessContext* processContext; ///< processing context (optional, but most welcome)
  222. //------------------------------------------------------------------------
  223. };
  224. //------------------------------------------------------------------------
  225. /** Audio processing interface: Vst::IAudioProcessor
  226. \ingroup vstIPlug vst300
  227. - [plug imp]
  228. - [extends IComponent]
  229. - [released: 3.0.0]
  230. - [mandatory]
  231. This interface must always be supported by audio processing plug-ins.
  232. */
  233. class IAudioProcessor : public FUnknown
  234. {
  235. public:
  236. //------------------------------------------------------------------------
  237. /** Try to set (host => plug-in) a wanted arrangement for inputs and outputs.
  238. The host should always deliver the same number of input and output busses than the plug-in
  239. needs (see \ref IComponent::getBusCount). The plug-in has 3 possibilities to react on this
  240. setBusArrangements call:\n
  241. 1. The plug-in accepts these arrangements, then it should modify, if needed, its busses to match
  242. these new arrangements (later on asked by the host with IComponent::getBusInfo () or
  243. IAudioProcessor::getBusArrangement ()) and then should return kResultTrue.\n
  244. 2. The plug-in does not accept or support these requested arrangements for all
  245. inputs/outputs or just for some or only one bus, but the plug-in can try to adapt its current
  246. arrangements according to the requested ones (requested arrangements for kMain busses should be
  247. handled with more priority than the ones for kAux busses), then it should modify its busses arrangements
  248. and should return kResultFalse.\n
  249. 3. Same than the point 2 above the plug-in does not support these requested arrangements
  250. but the plug-in cannot find corresponding arrangements, the plug-in could keep its current arrangement
  251. or fall back to a default arrangement by modifying its busses arrangements and should return kResultFalse.\n
  252. \param inputs pointer to an array of /ref SpeakerArrangement
  253. \param numIns number of /ref SpeakerArrangement in inputs array
  254. \param outputs pointer to an array of /ref SpeakerArrangement
  255. \param numOuts number of /ref SpeakerArrangement in outputs array
  256. Returns kResultTrue when Arrangements is supported and is the current one, else returns kResultFalse. */
  257. virtual tresult PLUGIN_API setBusArrangements (SpeakerArrangement* inputs, int32 numIns,
  258. SpeakerArrangement* outputs, int32 numOuts) = 0;
  259. /** Gets the bus arrangement for a given direction (input/output) and index.
  260. Note: IComponent::getBusInfo () and IAudioProcessor::getBusArrangement () should be always return the same
  261. information about the busses arrangements. */
  262. virtual tresult PLUGIN_API getBusArrangement (BusDirection dir, int32 index, SpeakerArrangement& arr) = 0;
  263. /** Asks if a given sample size is supported see \ref SymbolicSampleSizes. */
  264. virtual tresult PLUGIN_API canProcessSampleSize (int32 symbolicSampleSize) = 0;
  265. /** Gets the current Latency in samples.
  266. The returned value defines the group delay or the latency of the plug-in. For example, if the plug-in internally needs
  267. to look in advance (like compressors) 512 samples then this plug-in should report 512 as latency.
  268. If during the use of the plug-in this latency change, the plug-in has to inform the host by
  269. using IComponentHandler::restartComponent (kLatencyChanged), this could lead to audio playback interruption
  270. because the host has to recompute its internal mixer delay compensation.
  271. Note that for player live recording this latency should be zero or small. */
  272. virtual uint32 PLUGIN_API getLatencySamples () = 0;
  273. /** Called in disable state (setActive not called with true) before setProcessing is called and processing will begin. */
  274. virtual tresult PLUGIN_API setupProcessing (ProcessSetup& setup) = 0;
  275. /** Informs the plug-in about the processing state. This will be called before any process calls
  276. start with true and after with false.
  277. Note that setProcessing (false) may be called after setProcessing (true) without any process
  278. calls.
  279. Note this function could be called in the UI or in Processing Thread, thats why the plug-in
  280. should only light operation (no memory allocation or big setup reconfiguration),
  281. this could be used to reset some buffers (like Delay line or Reverb).
  282. The host has to be sure that it is called only when the plug-in is enable (setActive (true)
  283. was called). */
  284. virtual tresult PLUGIN_API setProcessing (TBool state) = 0;
  285. /** The Process call, where all information (parameter changes, event, audio buffer) are passed. */
  286. virtual tresult PLUGIN_API process (ProcessData& data) = 0;
  287. /** Gets tail size in samples. For example, if the plug-in is a Reverb plug-in and it knows that
  288. the maximum length of the Reverb is 2sec, then it has to return in getTailSamples()
  289. (in VST2 it was getGetTailSize ()): 2*sampleRate.
  290. This information could be used by host for offline processing, process optimization and
  291. downmix (avoiding signal cut (clicks)).
  292. It should return:
  293. - kNoTail when no tail
  294. - x * sampleRate when x Sec tail.
  295. - kInfiniteTail when infinite tail. */
  296. virtual uint32 PLUGIN_API getTailSamples () = 0;
  297. //------------------------------------------------------------------------
  298. static const FUID iid;
  299. };
  300. DECLARE_CLASS_IID (IAudioProcessor, 0x42043F99, 0xB7DA453C, 0xA569E79D, 0x9AAEC33D)
  301. //------------------------------------------------------------------------
  302. /** Extended IAudioProcessor interface for a component: Vst::IAudioPresentationLatency
  303. \ingroup vstIPlug vst310
  304. - [plug imp]
  305. - [extends IAudioProcessor]
  306. - [released: 3.1.0]
  307. - [optional]
  308. Inform the plug-in about how long from the moment of generation/acquiring (from file or from Input)
  309. 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).
  310. Note for Input Presentation Latency: when reading from file, the first plug-in will have an input presentation latency set to zero.
  311. When monitoring audio input from an audio device, the initial input latency is the input latency of the audio device itself.
  312. Note for Output Presentation Latency: when writing to a file, the last plug-in will have an output presentation latency set to zero.
  313. When the output of this plug-in is connected to an audio device, the initial output latency is the output
  314. latency of the audio device itself.
  315. A value of zero either means no latency or an unknown latency.
  316. Each plug-in adding a latency (returning a none zero value for IAudioProcessor::getLatencySamples) will modify the input
  317. presentation latency of the next plug-ins in the mixer routing graph and will modify the output presentation latency
  318. of the previous plug-ins.
  319. \n
  320. \image html "iaudiopresentationlatency_usage.png"
  321. \n
  322. \see IAudioProcessor
  323. \see IComponent
  324. */
  325. class IAudioPresentationLatency : public FUnknown
  326. {
  327. public:
  328. //------------------------------------------------------------------------
  329. /** Informs the plug-in about the Audio Presentation Latency in samples for a given direction (kInput/kOutput) and bus index. */
  330. virtual tresult PLUGIN_API setAudioPresentationLatencySamples (BusDirection dir, int32 busIndex, uint32 latencyInSamples) = 0;
  331. //------------------------------------------------------------------------
  332. static const FUID iid;
  333. };
  334. DECLARE_CLASS_IID (IAudioPresentationLatency, 0x309ECE78, 0xEB7D4fae, 0x8B2225D9, 0x09FD08B6)
  335. //------------------------------------------------------------------------
  336. /** Extended IAudioProcessor interface for a component: Vst::IProcessContextRequirements
  337. \ingroup vstIPlug vst370
  338. - [plug imp]
  339. - [extends IAudioProcessor]
  340. - [released: 3.7.0]
  341. - [mandatory]
  342. To get accurate process context information (Vst::ProcessContext), it is now required to implement this interface and
  343. return the desired bit mask of flags which your audio effect needs. If you do not implement this
  344. interface, you may not get any information at all of the process function.
  345. The host asks for this information once between initialize and setActive. It cannot be changed afterwards.
  346. This gives the host the opportunity to better optimize the audio process graph when it knows which
  347. plug-ins need which information.
  348. Plug-Ins built with an earlier SDK version (< 3.7) will still get the old information, but the information
  349. may not be as accurate as when using this interface.
  350. */
  351. class IProcessContextRequirements : public FUnknown
  352. {
  353. public:
  354. enum Flags
  355. {
  356. kNeedSystemTime = 1 << 0, // kSystemTimeValid
  357. kNeedContinousTimeSamples = 1 << 1, // kContTimeValid
  358. kNeedProjectTimeMusic = 1 << 2, // kProjectTimeMusicValid
  359. kNeedBarPositionMusic = 1 << 3, // kBarPositionValid
  360. kNeedCycleMusic = 1 << 4, // kCycleValid
  361. kNeedSamplesToNextClock = 1 << 5, // kClockValid
  362. kNeedTempo = 1 << 6, // kTempoValid
  363. kNeedTimeSignature = 1 << 7, // kTimeSigValid
  364. kNeedChord = 1 << 8, // kChordValid
  365. kNeedFrameRate = 1 << 9, // kSmpteValid
  366. kNeedTransportState = 1 << 10, // kPlaying, kCycleActive, kRecording
  367. };
  368. virtual uint32 PLUGIN_API getProcessContextRequirements () = 0;
  369. //------------------------------------------------------------------------
  370. static const FUID iid;
  371. };
  372. DECLARE_CLASS_IID (IProcessContextRequirements, 0x2A654303, 0xEF764E3D, 0x95B5FE83, 0x730EF6D0)
  373. //------------------------------------------------------------------------
  374. } // namespace Vst
  375. } // namespace Steinberg
  376. //------------------------------------------------------------------------
  377. #include "pluginterfaces/base/falignpop.h"
  378. //------------------------------------------------------------------------