diff options
| author | julian laplace <julescarbon@gmail.com> | 2025-07-07 12:13:51 +0200 |
|---|---|---|
| committer | julian laplace <julescarbon@gmail.com> | 2025-07-07 12:13:51 +0200 |
| commit | 966e3b080f039fa1c62113e75e1e1481d7e19439 (patch) | |
| tree | d9b2145cf07ba64101be9ec62c83a947fdb3e720 /client | |
| parent | 784bf3ff435f5236c8d32e90cedd1a1e488c9159 (diff) | |
trigger index
Diffstat (limited to 'client')
| -rw-r--r-- | client/index.js | 13 | ||||
| -rw-r--r-- | client/lib/util.js | 10 |
2 files changed, 18 insertions, 5 deletions
diff --git a/client/index.js b/client/index.js index 19cae7b..3c56825 100644 --- a/client/index.js +++ b/client/index.js @@ -17,6 +17,7 @@ import { requestAudioContext, choice, roundFreq, + frequencyInRange, mod, } from "./lib/util"; import { PRIMES } from "./lib/primes"; @@ -73,10 +74,12 @@ function rebuild() { } function log() { const seen = {}; + console.log(notes); for (let i = 0; i < 8; i++) { for (let j = 0; j < 8; j++) { - const rounded = roundFreq(notes[i][j].frequency); - if (!seen[rounded] && 20 < rounded && rounded < 12000) { + const frequency = notes[i][j].frequency; + const rounded = roundFreq(frequency); + if (!seen[rounded] && frequencyInRange(frequency)) { seen[rounded] = notes[i][j].frequency; } } @@ -104,13 +107,15 @@ function play(freq) { } } function trigger(freq) { - if (20 && freq.frequency && freq.frequency < 15000) { + if (frequencyInRange(freq.frequency)) { instrument.play(freq.frequency); } } function trigger_index(index) { const frequency = frequencies[index]; - instrument.play(frequency); + if (frequency) { + instrument.play(frequency); + } } function pause(freq) { organ.pause(freq.frequency); diff --git a/client/lib/util.js b/client/lib/util.js index 8696a50..5bf93dc 100644 --- a/client/lib/util.js +++ b/client/lib/util.js @@ -26,6 +26,7 @@ function mod(n, m) { function roundFreq(freq) { return Math.round(freq * 100); } +const frequencyInRange = (freq) => 20 < freq && freq < 15000; function requestAudioContext(fn) { if (window.location.protocol !== "https:") { @@ -70,4 +71,11 @@ function requestAudioContext(fn) { } } -export { choice, mod, browser, roundFreq, requestAudioContext }; +export { + choice, + mod, + browser, + roundFreq, + frequencyInRange, + requestAudioContext, +}; |
