diff options
| author | 2021-02-14 20:09:15 -0800 | |
|---|---|---|
| committer | 2021-02-14 20:09:15 -0800 | |
| commit | 8378b8a61feb971fc4b8af8468938e4691c2cfb7 (patch) | |
| tree | 6df36c0a553a72ad4ec5dca2a5134b44d0f31849 /src/audio_core/delay_line.cpp | |
| parent | Merge pull request #5920 from bunnei/am-ldn-fix (diff) | |
| parent | revert to std::sin and std::cos (diff) | |
| download | yuzu-8378b8a61feb971fc4b8af8468938e4691c2cfb7.tar.gz yuzu-8378b8a61feb971fc4b8af8468938e4691c2cfb7.tar.xz yuzu-8378b8a61feb971fc4b8af8468938e4691c2cfb7.zip | |
Merge pull request #5909 from ogniK5377/I3dl2Reverb
audren: Implement I3dl2Reverb
Diffstat (limited to 'src/audio_core/delay_line.cpp')
| -rw-r--r-- | src/audio_core/delay_line.cpp | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/src/audio_core/delay_line.cpp b/src/audio_core/delay_line.cpp new file mode 100644 index 000000000..f4e4dd8d2 --- /dev/null +++ b/src/audio_core/delay_line.cpp | |||
| @@ -0,0 +1,104 @@ | |||
| 1 | #include <cstring> | ||
| 2 | #include "audio_core/delay_line.h" | ||
| 3 | |||
| 4 | namespace AudioCore { | ||
| 5 | DelayLineBase::DelayLineBase() = default; | ||
| 6 | DelayLineBase::~DelayLineBase() = default; | ||
| 7 | |||
| 8 | void DelayLineBase::Initialize(s32 max_delay_, float* src_buffer) { | ||
| 9 | buffer = src_buffer; | ||
| 10 | buffer_end = buffer + max_delay_; | ||
| 11 | max_delay = max_delay_; | ||
| 12 | output = buffer; | ||
| 13 | SetDelay(max_delay_); | ||
| 14 | Clear(); | ||
| 15 | } | ||
| 16 | |||
| 17 | void DelayLineBase::SetDelay(s32 new_delay) { | ||
| 18 | if (max_delay < new_delay) { | ||
| 19 | return; | ||
| 20 | } | ||
| 21 | delay = new_delay; | ||
| 22 | input = (buffer + ((output - buffer) + new_delay) % (max_delay + 1)); | ||
| 23 | } | ||
| 24 | |||
| 25 | s32 DelayLineBase::GetDelay() const { | ||
| 26 | return delay; | ||
| 27 | } | ||
| 28 | |||
| 29 | s32 DelayLineBase::GetMaxDelay() const { | ||
| 30 | return max_delay; | ||
| 31 | } | ||
| 32 | |||
| 33 | f32 DelayLineBase::TapOut(s32 last_sample) { | ||
| 34 | const float* ptr = input - (last_sample + 1); | ||
| 35 | if (ptr < buffer) { | ||
| 36 | ptr += (max_delay + 1); | ||
| 37 | } | ||
| 38 | |||
| 39 | return *ptr; | ||
| 40 | } | ||
| 41 | |||
| 42 | f32 DelayLineBase::Tick(f32 sample) { | ||
| 43 | *(input++) = sample; | ||
| 44 | const auto out_sample = *(output++); | ||
| 45 | |||
| 46 | if (buffer_end < input) { | ||
| 47 | input = buffer; | ||
| 48 | } | ||
| 49 | |||
| 50 | if (buffer_end < output) { | ||
| 51 | output = buffer; | ||
| 52 | } | ||
| 53 | |||
| 54 | return out_sample; | ||
| 55 | } | ||
| 56 | |||
| 57 | float* DelayLineBase::GetInput() { | ||
| 58 | return input; | ||
| 59 | } | ||
| 60 | |||
| 61 | const float* DelayLineBase::GetInput() const { | ||
| 62 | return input; | ||
| 63 | } | ||
| 64 | |||
| 65 | f32 DelayLineBase::GetOutputSample() const { | ||
| 66 | return *output; | ||
| 67 | } | ||
| 68 | |||
| 69 | void DelayLineBase::Clear() { | ||
| 70 | std::memset(buffer, 0, sizeof(float) * max_delay); | ||
| 71 | } | ||
| 72 | |||
| 73 | void DelayLineBase::Reset() { | ||
| 74 | buffer = nullptr; | ||
| 75 | buffer_end = nullptr; | ||
| 76 | max_delay = 0; | ||
| 77 | input = nullptr; | ||
| 78 | output = nullptr; | ||
| 79 | delay = 0; | ||
| 80 | } | ||
| 81 | |||
| 82 | DelayLineAllPass::DelayLineAllPass() = default; | ||
| 83 | DelayLineAllPass::~DelayLineAllPass() = default; | ||
| 84 | |||
| 85 | void DelayLineAllPass::Initialize(u32 delay_, float coeffcient_, f32* src_buffer) { | ||
| 86 | DelayLineBase::Initialize(delay_, src_buffer); | ||
| 87 | SetCoefficient(coeffcient_); | ||
| 88 | } | ||
| 89 | |||
| 90 | void DelayLineAllPass::SetCoefficient(float coeffcient_) { | ||
| 91 | coefficient = coeffcient_; | ||
| 92 | } | ||
| 93 | |||
| 94 | f32 DelayLineAllPass::Tick(f32 sample) { | ||
| 95 | const auto temp = sample - coefficient * *output; | ||
| 96 | return coefficient * temp + DelayLineBase::Tick(temp); | ||
| 97 | } | ||
| 98 | |||
| 99 | void DelayLineAllPass::Reset() { | ||
| 100 | coefficient = 0.0f; | ||
| 101 | DelayLineBase::Reset(); | ||
| 102 | } | ||
| 103 | |||
| 104 | } // namespace AudioCore | ||