mirror of
https://codeberg.org/uzu/strudel
synced 2026-09-05 06:57:35 -04:00
frequency control (bad)
This commit is contained in:
Binary file not shown.
@@ -1,5 +1,5 @@
|
||||
const std = @import("std");
|
||||
|
||||
export fn saw(t: f64) f64 {
|
||||
return ((@mod(110.0 * t, 1.0)) - 0.5) * 2.0;
|
||||
export fn saw(t: f64, f: f64) f64 {
|
||||
return ((@mod(f * t, 1.0)) - 0.5) * 2.0;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
</head>
|
||||
<body>
|
||||
<button id="play">play</button>
|
||||
<input type="range" min="55" max="880" id="freq" />
|
||||
</body>
|
||||
<script src="./main.js"></script>
|
||||
</html>
|
||||
|
||||
@@ -14,4 +14,8 @@ document.getElementById('play').addEventListener('click', async () => {
|
||||
};
|
||||
node.port.postMessage({ webassembly: buffer });
|
||||
node.connect(ac.destination);
|
||||
|
||||
document.getElementById('freq').addEventListener('input', async (e) => {
|
||||
node.port.postMessage({ frequency: e.target.value });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,6 +2,7 @@ class SawProcessor extends AudioWorkletProcessor {
|
||||
constructor() {
|
||||
super();
|
||||
this.t = 0; // samples passed
|
||||
this.f = 110;
|
||||
this.port.onmessage = (e) => {
|
||||
const key = Object.keys(e.data)[0];
|
||||
const value = e.data[key];
|
||||
@@ -12,6 +13,8 @@ class SawProcessor extends AudioWorkletProcessor {
|
||||
this.port.postMessage('OK');
|
||||
});
|
||||
break;
|
||||
case 'frequency':
|
||||
this.f = value;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -22,7 +25,7 @@ class SawProcessor extends AudioWorkletProcessor {
|
||||
for (let i = 0; i < output[0].length; i++) {
|
||||
let t = this.t;
|
||||
let out = 0;
|
||||
out = this.api.saw(t / 44100, 220);
|
||||
out = this.api.saw(t / 44100, this.f);
|
||||
output.forEach((channel) => {
|
||||
channel[i] = out;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user