summaryrefslogtreecommitdiff
path: root/tools/editor/dct.js
diff options
context:
space:
mode:
Diffstat (limited to 'tools/editor/dct.js')
-rw-r--r--tools/editor/dct.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/tools/editor/dct.js b/tools/editor/dct.js
new file mode 100644
index 0000000..f60f27e
--- /dev/null
+++ b/tools/editor/dct.js
@@ -0,0 +1,29 @@
+// --- Utility Functions for Audio Processing ---
+// JavaScript equivalent of C++ idct_512
+function javascript_idct_512(input) {
+ const output = new Float32Array(dctSize);
+ const PI = Math.PI;
+ const N = dctSize;
+
+ for (let n = 0; n < N; ++n) {
+ let sum = input[0] / 2.0;
+ for (let k = 1; k < N; ++k) {
+ sum += input[k] * Math.cos((PI / N) * k * (n + 0.5));
+ }
+ output[n] = sum * (2.0 / N);
+ }
+ return output;
+}
+
+// Hanning window for smooth audio transitions (JavaScript equivalent)
+function hanningWindow(size) {
+ const window = new Float32Array(size);
+ const PI = Math.PI;
+ for (let i = 0; i < size; i++) {
+ window[i] = 0.5 * (1 - Math.cos((2 * PI * i) / (size - 1)));
+ }
+ return window;
+}
+
+const hanningWindowArray = hanningWindow(dctSize); // Pre-calculate window
+