|
| 1 | +# Vibrato |
| 2 | +### A simple vibrato effect |
| 3 | + |
| 4 | +The `ML_Vibrato` class implements a vibrato effect using a circular buffer and modulation input. |
| 5 | +It supports standard and high-quality processing modes. |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## Constants |
| 10 | + |
| 11 | +```c |
| 12 | +#define VIBRATO_BUFFER_SIZE 1024 |
| 13 | +``` |
| 14 | + |
| 15 | +- Size of the internal circular buffer used for delay modulation. |
| 16 | +- Determines maximum vibrato depth (in samples). |
| 17 | + |
| 18 | +--- |
| 19 | + |
| 20 | +## Class Interface |
| 21 | + |
| 22 | +```c++ |
| 23 | +class ML_Vibrato |
| 24 | +{ |
| 25 | +public: |
| 26 | + ML_Vibrato(float sample_rate); |
| 27 | + ~ML_Vibrato() {}; |
| 28 | + |
| 29 | + void Process(const float *in, const float *mod_in, float *out, uint32_t count); |
| 30 | + void ProcessHQ(const float *in, const float *mod_in, float *out, uint32_t count); |
| 31 | + |
| 32 | + void setDepth(float depth); |
| 33 | + void setIntensity(float intensity); |
| 34 | + |
| 35 | +private: |
| 36 | + void ModMultiplierUpdate(); |
| 37 | + |
| 38 | + float sample_rate; |
| 39 | + float depth; |
| 40 | + float depthInv; |
| 41 | + float buffer[VIBRATO_BUFFER_SIZE]; |
| 42 | + float mod_multiplier; |
| 43 | + float mod_multiplier_curr; |
| 44 | + int32_t inCnt; |
| 45 | +}; |
| 46 | +``` |
| 47 | + |
| 48 | +--- |
| 49 | + |
| 50 | +## Constructor & Destructor |
| 51 | + |
| 52 | +```c++ |
| 53 | +ML_Vibrato(float sample_rate); |
| 54 | +~ML_Vibrato(); |
| 55 | +``` |
| 56 | +
|
| 57 | +- `sample_rate`: system sampling rate in Hz. |
| 58 | +- Destructor does nothing special. |
| 59 | +
|
| 60 | +--- |
| 61 | +
|
| 62 | +## Processing |
| 63 | +
|
| 64 | +### Standard Processing |
| 65 | +```c++ |
| 66 | +void Process(const float *in, const float *mod_in, float *out, uint32_t count); |
| 67 | +``` |
| 68 | + |
| 69 | +- `in`: pointer to input buffer. |
| 70 | +- `mod_in`: pointer to modulation buffer (typically LFO). |
| 71 | +- `out`: pointer to output buffer. |
| 72 | +- `count`: number of samples to process. |
| 73 | + |
| 74 | +### High-Quality Processing |
| 75 | +```c++ |
| 76 | +void ProcessHQ(const float *in, const float *mod_in, float *out, uint32_t count); |
| 77 | +``` |
| 78 | +
|
| 79 | +- Similar to `Process()` but uses a higher-quality interpolation method for smoother vibrato. |
| 80 | +
|
| 81 | +--- |
| 82 | +
|
| 83 | +## Parameters |
| 84 | +
|
| 85 | +### Depth |
| 86 | +```c++ |
| 87 | +void setDepth(float depth); |
| 88 | +``` |
| 89 | +- Sets vibrato depth in **samples**. |
| 90 | +- Maximum is limited by `VIBRATO_BUFFER_SIZE`. |
| 91 | + |
| 92 | +### Intensity |
| 93 | +```c++ |
| 94 | +void setIntensity(float intensity); |
| 95 | +``` |
| 96 | +- Controls modulation intensity (scaling applied to `mod_in`). |
| 97 | +
|
| 98 | +--- |
| 99 | +
|
| 100 | +## Private Helper |
| 101 | +
|
| 102 | +```c++ |
| 103 | +void ModMultiplierUpdate(); |
| 104 | +``` |
| 105 | +- Updates modulation multiplier values internally. |
| 106 | + |
| 107 | +--- |
| 108 | + |
| 109 | +## Example Usage |
| 110 | + |
| 111 | +```c++ |
| 112 | +#include "ML_Vibrato.h" |
| 113 | + |
| 114 | +#define BLOCK_SIZE 256 |
| 115 | + |
| 116 | +ML_Vibrato vibrato(48000.0f); |
| 117 | + |
| 118 | +float in[BLOCK_SIZE]; |
| 119 | +float mod[BLOCK_SIZE]; // typically filled with LFO samples |
| 120 | +float out[BLOCK_SIZE]; |
| 121 | + |
| 122 | +void audioCallback() |
| 123 | +{ |
| 124 | + // set parameters |
| 125 | + vibrato.setDepth(64.0f); // depth in samples |
| 126 | + vibrato.setIntensity(0.8f); // modulation intensity |
| 127 | + |
| 128 | + // process audio |
| 129 | + vibrato.Process(in, mod, out, BLOCK_SIZE); |
| 130 | +} |
| 131 | +``` |
0 commit comments