make vowel work with node

This commit is contained in:
Felix Roos 2022-09-15 20:11:10 +02:00
parent 4406dd88d1
commit 149b2ab9f9

View File

@ -6,32 +6,33 @@ export var vowelFormant = {
o: { freqs: [430, 820, 2700, 3000, 3300], gains: [1, 0.3162, 0.0501, 0.0794, 0.01995], qs: [40, 80, 100, 120, 120] },
u: { freqs: [370, 630, 2750, 3000, 3400], gains: [1, 0.1, 0.0708, 0.0316, 0.01995], qs: [40, 60, 100, 120, 120] },
};
class VowelNode extends GainNode {
constructor(ac, letter) {
super(ac);
if (!vowelFormant[letter]) {
throw new Error('vowel: unknown vowel ' + letter);
if (typeof GainNode !== 'undefined') {
class VowelNode extends GainNode {
constructor(ac, letter) {
super(ac);
if (!vowelFormant[letter]) {
throw new Error('vowel: unknown vowel ' + letter);
}
const { gains, qs, freqs } = vowelFormant[letter];
const makeupGain = ac.createGain();
for (let i = 0; i < 5; i++) {
const gain = ac.createGain();
gain.gain.value = gains[i];
const filter = ac.createBiquadFilter();
filter.type = 'bandpass';
filter.Q.value = qs[i];
filter.frequency.value = freqs[i];
this.connect(filter);
filter.connect(gain);
gain.connect(makeupGain);
}
makeupGain.gain.value = 8; // how much makeup gain to add?
this.connect = (target) => makeupGain.connect(target);
return this;
}
const { gains, qs, freqs } = vowelFormant[letter];
const makeupGain = ac.createGain();
for (let i = 0; i < 5; i++) {
const gain = ac.createGain();
gain.gain.value = gains[i];
const filter = ac.createBiquadFilter();
filter.type = 'bandpass';
filter.Q.value = qs[i];
filter.frequency.value = freqs[i];
this.connect(filter);
filter.connect(gain);
gain.connect(makeupGain);
}
makeupGain.gain.value = 8; // how much makeup gain to add?
this.connect = (target) => makeupGain.connect(target);
return this;
}
}
AudioContext.prototype.createVowelFilter = function (letter) {
return new VowelNode(this, letter);
};
AudioContext.prototype.createVowelFilter = function (letter) {
return new VowelNode(this, letter);
};
}