🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
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.

205 lines
4.2 KiB

  1. #ifndef CORE_EFFECTS_BASE_H
  2. #define CORE_EFFECTS_BASE_H
  3. #include <stddef.h>
  4. #include "albyte.h"
  5. #include "almalloc.h"
  6. #include "alspan.h"
  7. #include "atomic.h"
  8. #include "core/bufferline.h"
  9. #include "intrusive_ptr.h"
  10. struct BufferStorage;
  11. struct ContextBase;
  12. struct DeviceBase;
  13. struct EffectSlot;
  14. struct MixParams;
  15. struct RealMixParams;
  16. /** Target gain for the reverb decay feedback reaching the decay time. */
  17. constexpr float ReverbDecayGain{0.001f}; /* -60 dB */
  18. constexpr float ReverbMaxReflectionsDelay{0.3f};
  19. constexpr float ReverbMaxLateReverbDelay{0.1f};
  20. enum class ChorusWaveform {
  21. Sinusoid,
  22. Triangle
  23. };
  24. constexpr float ChorusMaxDelay{0.016f};
  25. constexpr float FlangerMaxDelay{0.004f};
  26. constexpr float EchoMaxDelay{0.207f};
  27. constexpr float EchoMaxLRDelay{0.404f};
  28. enum class FShifterDirection {
  29. Down,
  30. Up,
  31. Off
  32. };
  33. enum class ModulatorWaveform {
  34. Sinusoid,
  35. Sawtooth,
  36. Square
  37. };
  38. enum class VMorpherPhenome {
  39. A, E, I, O, U,
  40. AA, AE, AH, AO, EH, ER, IH, IY, UH, UW,
  41. B, D, F, G, J, K, L, M, N, P, R, S, T, V, Z
  42. };
  43. enum class VMorpherWaveform {
  44. Sinusoid,
  45. Triangle,
  46. Sawtooth
  47. };
  48. union EffectProps {
  49. struct {
  50. // Shared Reverb Properties
  51. float Density;
  52. float Diffusion;
  53. float Gain;
  54. float GainHF;
  55. float DecayTime;
  56. float DecayHFRatio;
  57. float ReflectionsGain;
  58. float ReflectionsDelay;
  59. float LateReverbGain;
  60. float LateReverbDelay;
  61. float AirAbsorptionGainHF;
  62. float RoomRolloffFactor;
  63. bool DecayHFLimit;
  64. // Additional EAX Reverb Properties
  65. float GainLF;
  66. float DecayLFRatio;
  67. float ReflectionsPan[3];
  68. float LateReverbPan[3];
  69. float EchoTime;
  70. float EchoDepth;
  71. float ModulationTime;
  72. float ModulationDepth;
  73. float HFReference;
  74. float LFReference;
  75. } Reverb;
  76. struct {
  77. float AttackTime;
  78. float ReleaseTime;
  79. float Resonance;
  80. float PeakGain;
  81. } Autowah;
  82. struct {
  83. ChorusWaveform Waveform;
  84. int Phase;
  85. float Rate;
  86. float Depth;
  87. float Feedback;
  88. float Delay;
  89. } Chorus; /* Also Flanger */
  90. struct {
  91. bool OnOff;
  92. } Compressor;
  93. struct {
  94. float Edge;
  95. float Gain;
  96. float LowpassCutoff;
  97. float EQCenter;
  98. float EQBandwidth;
  99. } Distortion;
  100. struct {
  101. float Delay;
  102. float LRDelay;
  103. float Damping;
  104. float Feedback;
  105. float Spread;
  106. } Echo;
  107. struct {
  108. float LowCutoff;
  109. float LowGain;
  110. float Mid1Center;
  111. float Mid1Gain;
  112. float Mid1Width;
  113. float Mid2Center;
  114. float Mid2Gain;
  115. float Mid2Width;
  116. float HighCutoff;
  117. float HighGain;
  118. } Equalizer;
  119. struct {
  120. float Frequency;
  121. FShifterDirection LeftDirection;
  122. FShifterDirection RightDirection;
  123. } Fshifter;
  124. struct {
  125. float Frequency;
  126. float HighPassCutoff;
  127. ModulatorWaveform Waveform;
  128. } Modulator;
  129. struct {
  130. int CoarseTune;
  131. int FineTune;
  132. } Pshifter;
  133. struct {
  134. float Rate;
  135. VMorpherPhenome PhonemeA;
  136. VMorpherPhenome PhonemeB;
  137. int PhonemeACoarseTuning;
  138. int PhonemeBCoarseTuning;
  139. VMorpherWaveform Waveform;
  140. } Vmorpher;
  141. struct {
  142. float Gain;
  143. } Dedicated;
  144. };
  145. struct EffectTarget {
  146. MixParams *Main;
  147. RealMixParams *RealOut;
  148. };
  149. struct EffectState : public al::intrusive_ref<EffectState> {
  150. struct Buffer {
  151. const BufferStorage *storage;
  152. al::span<const al::byte> samples;
  153. };
  154. al::span<FloatBufferLine> mOutTarget;
  155. virtual ~EffectState() = default;
  156. virtual void deviceUpdate(const DeviceBase *device, const Buffer &buffer) = 0;
  157. virtual void update(const ContextBase *context, const EffectSlot *slot,
  158. const EffectProps *props, const EffectTarget target) = 0;
  159. virtual void process(const size_t samplesToDo, const al::span<const FloatBufferLine> samplesIn,
  160. const al::span<FloatBufferLine> samplesOut) = 0;
  161. };
  162. struct EffectStateFactory {
  163. virtual ~EffectStateFactory() = default;
  164. virtual al::intrusive_ptr<EffectState> create() = 0;
  165. };
  166. #endif /* CORE_EFFECTS_BASE_H */