import { Note, toCents } from './scale.mjs'; import GuitarFuzz from './vend/guitar-fuzz.mjs'; import Trombone from './vend/trombone.mjs'; const audioCtx = new AudioContext(); const fuzzWave = new PeriodicWave(audioCtx, { real: GuitarFuzz.real, imag: GuitarFuzz.imag }); const tromboneWave = new PeriodicWave(audioCtx, { real: Trombone.real, imag: Trombone.imag }); const globalGain = new GainNode(audioCtx, { gain: 0.06 }) export default class { // oscillatornodes notes = []; // offsets is an array of offsets in cents from A4. constructor(offsets) { console.debug('Player#constructor', this, offsets); this.offsets = offsets; this.notes = offsets.map(o => new OscillatorNode(audioCtx, { frequency: 440, // a above middle c (c4) detune: o, // type: 'sine', type: 'custom', periodicWave: tromboneWave, })); this.notes.forEach(n => n.connect(globalGain).connect(audioCtx.destination)); } start() { console.debug('Player#start', this); this.notes.forEach(n => n.start()); } stop() { console.debug('Player#stop', this); this.notes.forEach(n => n.stop()); } }