vibrato working
This commit is contained in:
parent
c7ee90922f
commit
8a502e886e
2 changed files with 26 additions and 13 deletions
|
|
@ -135,10 +135,10 @@ export function registerSynthSounds() {
|
||||||
|
|
||||||
|
|
||||||
registerSound(
|
registerSound(
|
||||||
'pwm',
|
'pulse',
|
||||||
(begin, value, onended) => {
|
(begin, value, onended) => {
|
||||||
const ac = getAudioContext();
|
const ac = getAudioContext();
|
||||||
let { duration, n } = value;
|
let { duration, n: pulsewidth = 0.5 } = value;
|
||||||
const frequency = getFrequencyFromValue(value);
|
const frequency = getFrequencyFromValue(value);
|
||||||
|
|
||||||
const [attack, decay, sustain, release] = getADSRValues(
|
const [attack, decay, sustain, release] = getADSRValues(
|
||||||
|
|
@ -152,12 +152,12 @@ export function registerSynthSounds() {
|
||||||
|
|
||||||
let o = getWorklet(
|
let o = getWorklet(
|
||||||
ac,
|
ac,
|
||||||
'pwm-oscillator',
|
'pulse-oscillator',
|
||||||
{
|
{
|
||||||
frequency,
|
frequency,
|
||||||
begin,
|
begin,
|
||||||
end,
|
end,
|
||||||
pulsewidth: 1
|
pulsewidth,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
outputChannelCount: [2],
|
outputChannelCount: [2],
|
||||||
|
|
@ -165,7 +165,7 @@ export function registerSynthSounds() {
|
||||||
);
|
);
|
||||||
|
|
||||||
getPitchEnvelope(o.parameters.get('detune'), value, begin, holdend);
|
getPitchEnvelope(o.parameters.get('detune'), value, begin, holdend);
|
||||||
// const vibratoOscillator = getVibratoOscillator(o.parameters.get('detune'), value, begin);
|
const vibratoOscillator = getVibratoOscillator(o.parameters.get('detune'), value, begin);
|
||||||
const fm = applyFM(o.parameters.get('frequency'), value, begin);
|
const fm = applyFM(o.parameters.get('frequency'), value, begin);
|
||||||
let envGain = gainNode(1);
|
let envGain = gainNode(1);
|
||||||
envGain = o.connect(envGain);
|
envGain = o.connect(envGain);
|
||||||
|
|
@ -177,7 +177,7 @@ export function registerSynthSounds() {
|
||||||
envGain.disconnect();
|
envGain.disconnect();
|
||||||
onended();
|
onended();
|
||||||
fm?.stop();
|
fm?.stop();
|
||||||
// vibratoOscillator?.stop();
|
vibratoOscillator?.stop();
|
||||||
},
|
},
|
||||||
begin,
|
begin,
|
||||||
end,
|
end,
|
||||||
|
|
|
||||||
|
|
@ -362,6 +362,11 @@ function getUnisonDetune(unison, detune, voiceIndex) {
|
||||||
}
|
}
|
||||||
return lerp(-detune * 0.5, detune * 0.5, voiceIndex / (unison - 1));
|
return lerp(-detune * 0.5, detune * 0.5, voiceIndex / (unison - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function applySemitoneDetuneToFrequency(frequency, detune) {
|
||||||
|
return frequency * Math.pow(2, detune / 12)
|
||||||
|
}
|
||||||
|
|
||||||
class SuperSawOscillatorProcessor extends AudioWorkletProcessor {
|
class SuperSawOscillatorProcessor extends AudioWorkletProcessor {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
@ -438,7 +443,8 @@ class SuperSawOscillatorProcessor extends AudioWorkletProcessor {
|
||||||
const isOdd = (n & 1) == 1;
|
const isOdd = (n & 1) == 1;
|
||||||
|
|
||||||
//applies unison "spread" detune in semitones
|
//applies unison "spread" detune in semitones
|
||||||
const freq = frequency * Math.pow(2, getUnisonDetune(voices, freqspread, n) / 12);
|
const freq = applySemitoneDetuneToFrequency(frequency, getUnisonDetune(voices, freqspread, n))
|
||||||
|
// const freq = frequency * Math.pow(2, getUnisonDetune(voices, freqspread, n) / 12);
|
||||||
let gainL = gain1;
|
let gainL = gain1;
|
||||||
let gainR = gain2;
|
let gainR = gain2;
|
||||||
// invert right and left gain
|
// invert right and left gain
|
||||||
|
|
@ -649,9 +655,8 @@ class PhaseVocoderProcessor extends OLAProcessor {
|
||||||
|
|
||||||
registerProcessor('phase-vocoder-processor', PhaseVocoderProcessor);
|
registerProcessor('phase-vocoder-processor', PhaseVocoderProcessor);
|
||||||
|
|
||||||
// SelfPMpwmWorklet.js
|
|
||||||
|
|
||||||
class PwmOscillatorProcessor extends AudioWorkletProcessor {
|
class PulseOscillatorProcessor extends AudioWorkletProcessor {
|
||||||
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
@ -688,6 +693,11 @@ class PwmOscillatorProcessor extends AudioWorkletProcessor {
|
||||||
defaultValue: 440,
|
defaultValue: 440,
|
||||||
min: Number.EPSILON,
|
min: Number.EPSILON,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'detune',
|
||||||
|
defaultValue: 0,
|
||||||
|
min: Number.NEGATIVE_INFINITY,
|
||||||
|
max: Number.POSITIVE_INFINITY},
|
||||||
{
|
{
|
||||||
name: 'pulsewidth',
|
name: 'pulsewidth',
|
||||||
defaultValue: 1,
|
defaultValue: 1,
|
||||||
|
|
@ -705,11 +715,14 @@ class PwmOscillatorProcessor extends AudioWorkletProcessor {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const output = outputs[0];
|
const output = outputs[0];
|
||||||
let env = 1, dphi;
|
let env = 1, dphi;
|
||||||
let freq = params.frequency[0]
|
let pw = clamp(params.pulsewidth[0], 0.01, 0.99) * _PI * 2
|
||||||
let pw = params.pulsewidth[0] * _PI
|
let detune = params.detune[0];
|
||||||
|
let freq = applySemitoneDetuneToFrequency(params.frequency[0], detune /100)
|
||||||
|
|
||||||
for (let i = 0; i < (output[0].length ?? 0); i++) {
|
for (let i = 0; i < (output[0].length ?? 0); i++) {
|
||||||
|
|
||||||
|
|
||||||
dphi = freq * (this.pi / (sampleRate * .5)); // phase increment
|
dphi = freq * (this.pi / (sampleRate * .5)); // phase increment
|
||||||
this.dphif += 0.1 * (dphi - this.dphif);
|
this.dphif += 0.1 * (dphi - this.dphif);
|
||||||
|
|
||||||
|
|
@ -743,4 +756,4 @@ class PwmOscillatorProcessor extends AudioWorkletProcessor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
registerProcessor('pwm-oscillator', PwmOscillatorProcessor);
|
registerProcessor('pulse-oscillator', PulseOscillatorProcessor);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue