summaryrefslogtreecommitdiff
path: root/client/lib
diff options
context:
space:
mode:
Diffstat (limited to 'client/lib')
-rw-r--r--client/lib/kalimba.js9
1 files changed, 6 insertions, 3 deletions
diff --git a/client/lib/kalimba.js b/client/lib/kalimba.js
index 0354f69..1401dc4 100644
--- a/client/lib/kalimba.js
+++ b/client/lib/kalimba.js
@@ -2,6 +2,7 @@ import Tone from 'tone'
import { choice } from './util'
const player_count = 2
+let sample_index = 0
const compressor = new Tone.Compressor(-30, 3).toMaster()
@@ -33,14 +34,16 @@ samples.forEach((sample) => {
}
})
-function play (freq) {
- const best = { sample: choice(samples) }
+function play (freq, volume = 0.0) {
+ const best = { sample: samples[sample_index] }
+ sample_index = (sample_index + 1) % samples.length
best.sample.index = (best.sample.index + 1) % player_count
const player = best.sample.players[ best.sample.index ]
player.playbackRate = freq / best.sample.root
// console.log(player)
- player.start()
+ player.volume.value = volume
+ setTimeout(() => { player.start() }, 0)
}
export default { play }