|
1 | | -<h1 align="center">Delay</h1> |
2 | | -<h3 align="center">A very simple delay</h3> |
| 1 | +# Delay |
| 2 | +### A very simple delay module |
3 | 3 |
|
4 | | -This module provides a delay effect. |
5 | | -It supports two delay lines for a stereo delay. |
6 | | -The Delay_Init function needs a buffer and the length for a mono delay. |
7 | | -For stereo please use Delay_Init2 which needs two buffers. |
| 4 | +This module provides a **mono** or **stereo delay effect**. |
| 5 | +It supports different audio formats (`int16_t` and `float`) and multiple input/output modes. |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## Initialization |
| 10 | + |
| 11 | +The delay module requires a buffer (or two for stereo). The buffer length determines the **maximum delay length**. |
| 12 | + |
| 13 | +- For **mono**: `void Delay_Init(int16_t *buffer, uint32_t len);` |
| 14 | + |
| 15 | +- For **stereo**: `void Delay_Init2(int16_t *left, int16_t *right, uint32_t len);` |
| 16 | + |
| 17 | +- `buffer`, `left`, `right`: pointers to delay line buffers. |
| 18 | +- `len`: number of samples per buffer. This defines the maximum delay length. |
| 19 | +- Maximum delay in time = `len / SAMPLE_RATE` seconds. |
| 20 | + |
| 21 | +To reset the delay state: |
| 22 | +```c |
| 23 | +void Delay_Reset(void); |
| 24 | +``` |
| 25 | +
|
| 26 | +--- |
| 27 | +
|
| 28 | +## Processing |
| 29 | +
|
| 30 | +The delay supports multiple processing functions depending on the input/output format and mode. |
| 31 | +
|
| 32 | +### Mono |
| 33 | +```c |
| 34 | +// Mono in/out |
| 35 | +void Delay_Process_Buff(float *signal_l, int buffLen); |
| 36 | +void Delay_Process_Buff(int16_t *signal_l, int buffLen); |
| 37 | +``` |
| 38 | + |
| 39 | +### Mono → Stereo |
| 40 | +```c |
| 41 | +// Mono input, stereo output |
| 42 | +void Delay_Process_Buff(float *in, float *left, float *right, int buffLen); |
| 43 | +void Delay_Process_Buff(int16_t *in, int16_t *left, int16_t *right, int buffLen); |
| 44 | +``` |
| 45 | +
|
| 46 | +### Stereo |
| 47 | +```c |
| 48 | +// Stereo input/output |
| 49 | +void Delay_Process_Buff(float *in_l, float *in_r, float *out_l, float *out_r, int buffLen); |
| 50 | +void Delay_Process_Buff(int16_t *in_l, int16_t *in_r, int16_t *out_l, int16_t *out_r, int buffLen); |
| 51 | +void Delay_Process_Buff2(float *signal_l, float *signal_r, int buffLen); // in/out inplace |
| 52 | +``` |
| 53 | + |
| 54 | +- `buffLen`: number of samples to process per call. |
| 55 | +- Use the function variant matching your signal format (`float` or `int16_t`). |
| 56 | + |
| 57 | +--- |
| 58 | + |
| 59 | +## Parameters |
| 60 | + |
| 61 | +The module provides several parameter setters. |
| 62 | + |
| 63 | +### Input Level |
| 64 | +```c |
| 65 | +void Delay_SetInputLevel(uint8_t unused, float value); |
| 66 | +void Delay_SetInputLevel(uint8_t unused, uint8_t value); |
| 67 | +``` |
| 68 | +
|
| 69 | +- `float`: range **0.0 … 1.0** (linear gain). |
| 70 | +- `uint8_t`: range **0 … 127** (MIDI-style scaling). |
| 71 | +
|
| 72 | +### Feedback |
| 73 | +```c |
| 74 | +void Delay_SetFeedback(uint8_t unused, float value); |
| 75 | +void Delay_SetFeedback(uint8_t unused, uint8_t value); |
| 76 | +``` |
| 77 | + |
| 78 | +- Controls how much delayed signal is fed back into the input. |
| 79 | +- Same ranges as above. |
| 80 | + |
| 81 | +### Output Level |
| 82 | +```c |
| 83 | +void Delay_SetOutputLevel(uint8_t unused, float value); |
| 84 | +void Delay_SetOutputLevel(uint8_t unused, uint8_t value); |
| 85 | +``` |
| 86 | +
|
| 87 | +### Delay Length |
| 88 | +```c |
| 89 | +void Delay_SetLength(uint8_t unused, float value); |
| 90 | +void Delay_SetLength(uint8_t unused, uint32_t value); |
| 91 | +``` |
| 92 | + |
| 93 | +- `float`: **0.0 … 1.0** → percentage of max delay (`len`). |
| 94 | +- `uint32_t`: absolute delay length in samples. |
| 95 | + |
| 96 | +### Stereo Shift |
| 97 | +```c |
| 98 | +void Delay_SetShift(uint8_t unused, float value); |
| 99 | +``` |
| 100 | +
|
| 101 | +- Used only in **stereo mode**. |
| 102 | +- Shifts one channel relative to the other. |
| 103 | +- Range: **0.0 … 1.0**. |
| 104 | +
|
| 105 | +--- |
| 106 | +
|
| 107 | +## Examples |
| 108 | +
|
| 109 | +### Mono Delay |
| 110 | +```c |
| 111 | +#define BUFFER_LEN 48000 |
| 112 | +static int16_t delayBuffer[BUFFER_LEN]; |
| 113 | +
|
| 114 | +Delay_Init(delayBuffer, BUFFER_LEN); |
| 115 | +Delay_SetFeedback(0, 0.5f); // 50% feedback |
| 116 | +Delay_SetLength(0, 0.25f); // 25% of buffer length |
| 117 | +Delay_SetOutputLevel(0, 1.0f); // full output |
| 118 | +
|
| 119 | +Delay_Process_Buff(inputBuffer, 256); |
| 120 | +``` |
| 121 | + |
| 122 | +### Stereo Delay |
| 123 | +```c |
| 124 | +#define BUFFER_LEN 48000 |
| 125 | +static int16_t delayBufferL[BUFFER_LEN]; |
| 126 | +static int16_t delayBufferR[BUFFER_LEN]; |
| 127 | + |
| 128 | +Delay_Init2(delayBufferL, delayBufferR, BUFFER_LEN); |
| 129 | +Delay_SetFeedback(0, 64); // MIDI style (64/127 ~ 0.5) |
| 130 | +Delay_SetLength(0, 24000); // 24000 samples delay |
| 131 | +Delay_SetShift(0, 0.1f); // slight stereo shift |
| 132 | + |
| 133 | +Delay_Process_Buff(inputL, inputR, outputL, outputR, 256); |
| 134 | +``` |
0 commit comments