diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2024-09-08 23:21:02 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-09-08 23:21:02 +0200 |
commit | 73a0f6e90f9703a5eaee5bda25fd1affc0d9cd53 (patch) | |
tree | ab70ef7135c8b537803a2e917a322e5b98d68c21 | |
parent | 5675c76461e197d3929a1142cfb84ab1a76ac9dd (diff) | |
parent | 94b31c1db7176d7e37ec836747e50a7d89a06c65 (diff) | |
download | redot-engine-73a0f6e90f9703a5eaee5bda25fd1affc0d9cd53.tar.gz |
Merge pull request #83536 from wareya/new_cubic
Optimize cubic hermite algorithm in AudioStreamPlaybackResampled
-rw-r--r-- | servers/audio/audio_stream.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/servers/audio/audio_stream.cpp b/servers/audio/audio_stream.cpp index e2c8686911..ece088a694 100644 --- a/servers/audio/audio_stream.cpp +++ b/servers/audio/audio_stream.cpp @@ -173,12 +173,12 @@ int AudioStreamPlaybackResampled::mix(AudioFrame *p_buffer, float p_rate_scale, } float mu2 = mu * mu; - AudioFrame a0 = 3 * y1 - 3 * y2 + y3 - y0; - AudioFrame a1 = 2 * y0 - 5 * y1 + 4 * y2 - y3; - AudioFrame a2 = y2 - y0; - AudioFrame a3 = 2 * y1; + float h11 = mu2 * (mu - 1); + float z = mu2 - h11; + float h01 = z - h11; + float h10 = mu - z; - p_buffer[i] = (a0 * mu * mu2 + a1 * mu2 + a2 * mu + a3) / 2; + p_buffer[i] = y1 + (y2 - y1) * h01 + ((y2 - y0) * h10 + (y3 - y1) * h11) * 0.5; mix_offset += mix_increment; |