summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/index.js18
-rw-r--r--client/lib/output.js5
-rw-r--r--client/lib/sampler.js50
-rw-r--r--client/lib/util.js3
4 files changed, 61 insertions, 15 deletions
diff --git a/client/index.js b/client/index.js
index 75dc612..ca6b3d9 100644
--- a/client/index.js
+++ b/client/index.js
@@ -25,7 +25,7 @@ requestAudioContext( () => {
})
samplers['smash'] = new Sampler('samples/smash/g{}.mp3', 12)
-samplers['glass'] = new Sampler('samples/glass/0{}Particle.mp3', 90)
+// samplers['glass'] = new Sampler('samples/glass/0{}Particle.mp3', 90)
let last_index = 0
keys.listen(index => {
@@ -46,10 +46,10 @@ keys.listen(index => {
for (i = 0; i < count; i++) {
// kalimba.play(freq * (i+1)/4, now + Math.random()/(i+1))
when = Math.random()/2000 + (i + Math.random()/10)/randrange(2,5)
- samplers['glass'].play(
- 100 + index*(Math.random() * 10),
- now + when
- )
+ // samplers['glass'].play(
+ // 100 + index*(Math.random() * 10),
+ // now + when
+ // )
setTimeout( () => {
draw.triangle(randint(window.innerWidth), randint(window.innerHeight), randrange(10, 100))
}, when * 1000)
@@ -75,10 +75,10 @@ mouse.register({
let when, i, player
for (i = 0; i < count; i++) {
when = Math.random()/2000 + (i+ Math.random()/10)/randrange(2,5)
- player = samplers['glass'].play(
- 100 * randrange(2,5) / randrange(2,5) * randrange(0.5,1.5),
- now + when
- )
+ // player = samplers['glass'].play(
+ // 100 * randrange(2,5) / randrange(2,5) * randrange(0.5,1.5),
+ // now + when
+ // )
player.volume.value = isMobile ? -(1+i/2) : -i*i
}
setTimeout( () => {
diff --git a/client/lib/output.js b/client/lib/output.js
new file mode 100644
index 0000000..2155009
--- /dev/null
+++ b/client/lib/output.js
@@ -0,0 +1,5 @@
+import Tone from 'tone'
+
+const compressor = new Tone.Compressor(-30, 3).toMaster()
+
+export default compressor
diff --git a/client/lib/sampler.js b/client/lib/sampler.js
index c1faa7e..b392caf 100644
--- a/client/lib/sampler.js
+++ b/client/lib/sampler.js
@@ -1,17 +1,22 @@
import Tone from 'tone'
-import { choice } from './util'
+import { lerp, choice } from './util'
+import output from './output'
const player_count = 2
+const filter_count = 3
+
+const notes = [299, 336, 374, 399, 449, 498, 561, 598].map(i => i/2)
-const compressor = new Tone.Compressor(-30, 3).toMaster()
const reverb = new Tone.Freeverb({
roomSize: 0.2,
dampening: 12000,
-}).connect(compressor)
+}).connect(output)
+
+const crossfaders = []
export default class Sampler {
constructor(path, count){
- this.samples = (()=>{
+ this.samples = (() => {
let s = '', a = []
for (let i = 1; i < count; i++) {
const s = i < 10 ? '0' + i : i;
@@ -22,6 +27,8 @@ export default class Sampler {
this.samples.forEach((sample) => {
sample.players = []
+ sample.filters = []
+ sample.crossfaders = []
sample.index = -1
for (let i = 0; i < player_count; i++) {
let fn = sample.fn
@@ -33,8 +40,32 @@ export default class Sampler {
retrigger: true,
playbackRate: 1,
})
- player.connect(reverb)
+
+ let crossFade = new Tone.CrossFade(0.5)
+ sample.crossfaders.push(crossFade)
+
+ let wet = new Tone.Gain(1)
+
+ player.connect(crossFade, 0, 0)
+ wet.connect(crossFade, 0, 1)
+
+ crossFade.connect(output)
+
+ let filter, note
+ let filters = sample.filters = []
+ for (let j = 0; j < filter_count; j++) {
+ note = choice(notes)
+ filter = new Tone.Filter({
+ frequency: filter_count * j * note,
+ Q: 5 * (filter_count-j) + 20,
+ })
+ player.connect(filter)
+ filter.connect(wet)
+ filters.push(filter)
+ }
+ // player.connect(reverb)
sample.players.push(player)
+ sample.filters.push(filters)
}
})
@@ -44,6 +75,7 @@ export default class Sampler {
best.sample.index = (best.sample.index + 1) % player_count
const player = best.sample.players[ best.sample.index ]
+ const crossfader = best.sample.crossfaders[ best.sample.index ]
freq = freq || best.sample.root
time = time || Tone.now()
@@ -54,6 +86,14 @@ export default class Sampler {
} else {
console.log('loading')
}
+
+ crossfader.fade.value = lerp(x_pos, 0.0, 1.0)
+
return player
}
}
+
+let x_pos = 0.5
+document.body.addEventListener('mousemove', (e) => {
+ x_pos = (e.pageX / window.innerWidth)
+}) \ No newline at end of file
diff --git a/client/lib/util.js b/client/lib/util.js
index 48145e0..504c562 100644
--- a/client/lib/util.js
+++ b/client/lib/util.js
@@ -17,6 +17,7 @@ function mod(n,m){ return n-(m * Math.floor(n/m)) }
function randint(n){ return (Math.random()*n)|0 }
function randrange(a,b){ return a + Math.random() * (b-a) }
function randsign(){ return Math.random() >= 0.5 ? -1 : 1 }
+function lerp(n,a,b){ return (b-a)*n+a }
function requestAudioContext (fn) {
if (isMobile) {
@@ -62,7 +63,7 @@ function requestAudioContext (fn) {
}
export {
- choice, mod, clamp,
+ choice, mod, clamp, lerp,
randint, randrange, randsign,
browser, requestAudioContext,
}