diff options
Diffstat (limited to 'player.mjs')
| -rw-r--r-- | player.mjs | 20 |
1 files changed, 11 insertions, 9 deletions
@@ -12,8 +12,6 @@ const tromboneWave = new PeriodicWave(audioCtx, { imag: Trombone.imag }); -const globalGain = new GainNode(audioCtx, { gain: 0.06 }) - export default class extends HTMLElement { static name = 'x-player' static register() { @@ -21,10 +19,12 @@ export default class extends HTMLElement { customElements.define(this.name, this); } + // A4 + aFreq = 440; + // oscillatornodes notes = []; getOffsets = () => []; - detuneParams = []; constructor() { super(); @@ -32,14 +32,18 @@ export default class extends HTMLElement { } connectedCallback() { + this.globalGain = audioCtx.createGain(); + this.globalGain.connect(audioCtx.destination); + this.globalGain.gain.setValueAtTime(this.volume, audioCtx.currentTime); + this.querySelector('.volume').onchange = e => { console.debug('vol changed', e, this.volume); - globalGain.setValueAtTime(0.1, audioCtx.currentTime); - globalGain.value = this.volume; + this.globalGain.gain.setValueAtTime(this.volume, audioCtx.currentTime); } } get volume() { + console.debug('Player#volume', this.querySelector('.volume').value) return Number(this.querySelector('.volume').value); } @@ -74,13 +78,11 @@ export default class extends HTMLElement { for (let i = 0; i < this.offsets.length; i++) { if (!this.notes[i]) { const note = new OscillatorNode(audioCtx, { - frequency: 440, // a above middle c (c4) - // detune: o, - // type: 'sine', + frequency: this.aFreq, type: 'custom', periodicWave: tromboneWave, }); - note.connect(globalGain).connect(audioCtx.destination); + note.connect(this.globalGain); note.start(); this.notes[i] = note; } |
