100
This commit is contained in:
parent
c2df8aa6b9
commit
1e3a23e017
3 changed files with 49 additions and 26 deletions
|
|
@ -891,17 +891,37 @@ export const { delaytime, delayt, dt } = registerControl('delaytime', 'delayt',
|
||||||
*/
|
*/
|
||||||
export const { lock } = registerControl('lock');
|
export const { lock } = registerControl('lock');
|
||||||
/**
|
/**
|
||||||
* Set detune of oscillators. Works only with some synths, see <a target="_blank" href="https://tidalcycles.org/docs/patternlib/tutorials/synthesizers">tidal doc</a>
|
* Set detune for stacked voices of supported oscillators
|
||||||
*
|
*
|
||||||
* @name detune
|
* @name detune
|
||||||
* @param {number | Pattern} amount between 0 and 1
|
* @param {number | Pattern} amount
|
||||||
* @synonyms det
|
* @synonyms det
|
||||||
* @superdirtOnly
|
|
||||||
* @example
|
* @example
|
||||||
* n("0 3 7").s('superzow').octave(3).detune("<0 .25 .5 1 2>").osc()
|
* note("d f a a# a d3").fast(2).s("supersaw").detune("<.4 1 3 200>")
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export const { detune, det } = registerControl('detune', 'det');
|
export const { detune, det } = registerControl('detune', 'det');
|
||||||
|
/**
|
||||||
|
* Set number of stacked voices for supported oscillators
|
||||||
|
*
|
||||||
|
* @name unison
|
||||||
|
* @param {number | Pattern} numvoices
|
||||||
|
* @example
|
||||||
|
* note("d f a a# a d3").fast(2).s("supersaw").unison("<1 2 7>")
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
export const { unison } = registerControl('unison');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the stereo pan spread for supported oscillators
|
||||||
|
*
|
||||||
|
* @name spread
|
||||||
|
* @param {number | Pattern} spread between 0 and 1
|
||||||
|
* @example
|
||||||
|
* note("d f a a# a d3").fast(2).s("supersaw").spread("<0 .3 1>")
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
export const { spread } = registerControl('spread');
|
||||||
/**
|
/**
|
||||||
* Set dryness of reverb. See `room` and `size` for more information about reverb.
|
* Set dryness of reverb. See `room` and `size` for more information about reverb.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { midiToFreq, noteToMidi } from './util.mjs';
|
import { clamp, midiToFreq, noteToMidi } from './util.mjs';
|
||||||
import { registerSound, getAudioContext, getWorklet } from './superdough.mjs';
|
import { registerSound, getAudioContext, getWorklet } from './superdough.mjs';
|
||||||
import { gainNode, getADSRValues, getParamADSR, getPitchEnvelope, getVibratoOscillator } from './helpers.mjs';
|
import { gainNode, getADSRValues, getParamADSR, getPitchEnvelope, getVibratoOscillator } from './helpers.mjs';
|
||||||
import { getNoiseMix, getNoiseOscillator } from './noise.mjs';
|
import { getNoiseMix, getNoiseOscillator } from './noise.mjs';
|
||||||
|
|
@ -24,6 +24,20 @@ const fm = (osc, harmonicityRatio, modulationIndex, wave = 'sine') => {
|
||||||
const waveforms = ['triangle', 'square', 'sawtooth', 'sine'];
|
const waveforms = ['triangle', 'square', 'sawtooth', 'sine'];
|
||||||
const noises = ['pink', 'white', 'brown', 'crackle'];
|
const noises = ['pink', 'white', 'brown', 'crackle'];
|
||||||
|
|
||||||
|
const getFrequencyFromValue = (value) => {
|
||||||
|
let { note, freq } = value;
|
||||||
|
note = note || 36;
|
||||||
|
if (typeof note === 'string') {
|
||||||
|
note = noteToMidi(note); // e.g. c3 => 48
|
||||||
|
}
|
||||||
|
// get frequency
|
||||||
|
if (!freq && typeof note === 'number') {
|
||||||
|
freq = midiToFreq(note); // + 48);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Number(freq);
|
||||||
|
};
|
||||||
|
|
||||||
export function registerSynthSounds() {
|
export function registerSynthSounds() {
|
||||||
[...waveforms].forEach((s) => {
|
[...waveforms].forEach((s) => {
|
||||||
registerSound(
|
registerSound(
|
||||||
|
|
@ -35,8 +49,7 @@ export function registerSynthSounds() {
|
||||||
[0.001, 0.05, 0.6, 0.01],
|
[0.001, 0.05, 0.6, 0.01],
|
||||||
);
|
);
|
||||||
|
|
||||||
let sound;
|
let sound = getOscillator(s, t, value);
|
||||||
sound = getOscillator(s, t, value);
|
|
||||||
let { node: o, stop, triggerRelease } = sound;
|
let { node: o, stop, triggerRelease } = sound;
|
||||||
|
|
||||||
// turn down
|
// turn down
|
||||||
|
|
@ -69,18 +82,9 @@ export function registerSynthSounds() {
|
||||||
'supersaw',
|
'supersaw',
|
||||||
(begin, value, onended) => {
|
(begin, value, onended) => {
|
||||||
const ac = getAudioContext();
|
const ac = getAudioContext();
|
||||||
let { note, freq, duration, n = 2 } = value;
|
let { duration, n, unison = 6, spread = 0.3, detune } = value;
|
||||||
note = note || 36;
|
detune = detune ?? n ?? 2;
|
||||||
if (typeof note === 'string') {
|
const frequency = getFrequencyFromValue(value);
|
||||||
note = noteToMidi(note); // e.g. c3 => 48
|
|
||||||
}
|
|
||||||
// get frequency
|
|
||||||
if (!freq && typeof note === 'number') {
|
|
||||||
freq = midiToFreq(note); // + 48);
|
|
||||||
}
|
|
||||||
|
|
||||||
// set frequency
|
|
||||||
freq = Number(freq);
|
|
||||||
|
|
||||||
const [attack, decay, sustain, release] = getADSRValues(
|
const [attack, decay, sustain, release] = getADSRValues(
|
||||||
[value.attack, value.decay, value.sustain, value.release],
|
[value.attack, value.decay, value.sustain, value.release],
|
||||||
|
|
@ -95,12 +99,12 @@ export function registerSynthSounds() {
|
||||||
ac,
|
ac,
|
||||||
'supersaw-oscillator',
|
'supersaw-oscillator',
|
||||||
{
|
{
|
||||||
frequency: freq,
|
frequency,
|
||||||
begin,
|
begin,
|
||||||
end,
|
end,
|
||||||
detune: Math.min(200, Math.max(0, n * 0.1)),
|
detune: detune * 0.1,
|
||||||
// voices: n,
|
voices: clamp(unison, 0, 100),
|
||||||
// spread: 0,
|
spread: clamp(spread, 0, 1),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
outputChannelCount: [2],
|
outputChannelCount: [2],
|
||||||
|
|
|
||||||
|
|
@ -184,7 +184,6 @@ class SuperSawOscillatorProcessor extends AudioWorkletProcessor {
|
||||||
name: 'voices',
|
name: 'voices',
|
||||||
defaultValue: 6,
|
defaultValue: 6,
|
||||||
min: 1,
|
min: 1,
|
||||||
max: 10,
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
@ -202,7 +201,7 @@ class SuperSawOscillatorProcessor extends AudioWorkletProcessor {
|
||||||
const detune = params.detune[0];
|
const detune = params.detune[0];
|
||||||
let spread = params.spread[0];
|
let spread = params.spread[0];
|
||||||
spread = spread * 0.5 + 0.5;
|
spread = spread * 0.5 + 0.5;
|
||||||
const gainAdjustment = Math.max(0.75, 1 - (voices - 1) * 0.05);
|
const gainAdjustment = 1;
|
||||||
|
|
||||||
for (let n = 0; n < voices; n++) {
|
for (let n = 0; n < voices; n++) {
|
||||||
let adj = 0;
|
let adj = 0;
|
||||||
|
|
@ -210,7 +209,7 @@ class SuperSawOscillatorProcessor extends AudioWorkletProcessor {
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
adj = isOdd ? n * detune : -((n - 1) * detune);
|
adj = isOdd ? n * detune : -((n - 1) * detune);
|
||||||
}
|
}
|
||||||
const freq = frequency + adj * 0.01 * frequency;
|
const freq = Math.min(16744, Math.max(1, frequency + adj * 0.01 * frequency));
|
||||||
const balance = isOdd ? 1 - spread : spread;
|
const balance = isOdd ? 1 - spread : spread;
|
||||||
const dt = freq / sampleRate;
|
const dt = freq / sampleRate;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue