25 lines
644 B
JavaScript
25 lines
644 B
JavaScript
class Synth {
|
|
constructor(audioContext, waveType = "sine", frequency = 400) {
|
|
this.audioContext = audioContext;
|
|
this.oscWaveType = waveType;
|
|
this.oscFrequency = frequency;
|
|
this.osc = this.audioContext.createOscillator();
|
|
this.osc.type = this.oscWaveType;
|
|
this.osc.frequency.setValueAtTime(this.oscFrequency, this.audioContext.currentTime);
|
|
}
|
|
|
|
setOscWaveType(type) {
|
|
this.oscWaveType = type;
|
|
this.osc.type = this.oscWaveType;
|
|
}
|
|
}
|
|
|
|
|
|
let globalAudioContext = new AudioContext();
|
|
let synth = new Synth(globalAudioContext);
|
|
|
|
window.onload = function() {
|
|
console.log("hello world!");
|
|
console.log(synth);
|
|
}
|