add compressor + postgain
This commit is contained in:
parent
daf965f119
commit
130ad4451b
3 changed files with 30 additions and 2 deletions
|
|
@ -86,6 +86,7 @@ const generic_params = [
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
['gain'],
|
['gain'],
|
||||||
|
['postgain'],
|
||||||
/**
|
/**
|
||||||
* Like {@link gain}, but linear.
|
* Like {@link gain}, but linear.
|
||||||
*
|
*
|
||||||
|
|
@ -1051,6 +1052,11 @@ const generic_params = [
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
['shape'],
|
['shape'],
|
||||||
|
[['compressor', 'compressorRatio', 'compressorKnee', 'compressorAttack', 'compressorRelease']],
|
||||||
|
['compressorKnee'],
|
||||||
|
['compressorRatio'],
|
||||||
|
['compressorAttack'],
|
||||||
|
['compressorRelease'],
|
||||||
/**
|
/**
|
||||||
* Changes the speed of sample playback, i.e. a cheap way of changing pitch.
|
* Changes the speed of sample playback, i.e. a cheap way of changing pitch.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,17 @@ export const getParamADSR = (param, attack, decay, sustain, release, min, max, b
|
||||||
param.linearRampToValueAtTime(min, end + Math.max(release, 0.1));
|
param.linearRampToValueAtTime(min, end + Math.max(release, 0.1));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function getCompressor(ac, threshold, ratio, knee, attack, release) {
|
||||||
|
const options = {
|
||||||
|
threshold: threshold ?? -3,
|
||||||
|
ratio: ratio ?? 10,
|
||||||
|
knee: knee ?? 10,
|
||||||
|
attack: attack ?? 0.005,
|
||||||
|
release: release ?? 0.05,
|
||||||
|
};
|
||||||
|
return new DynamicsCompressorNode(ac, options);
|
||||||
|
}
|
||||||
|
|
||||||
export function createFilter(
|
export function createFilter(
|
||||||
context,
|
context,
|
||||||
type,
|
type,
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import './reverb.mjs';
|
||||||
import './vowel.mjs';
|
import './vowel.mjs';
|
||||||
import { clamp } from './util.mjs';
|
import { clamp } from './util.mjs';
|
||||||
import workletsUrl from './worklets.mjs?url';
|
import workletsUrl from './worklets.mjs?url';
|
||||||
import { createFilter, gainNode } from './helpers.mjs';
|
import { createFilter, gainNode, getCompressor } from './helpers.mjs';
|
||||||
import { map } from 'nanostores';
|
import { map } from 'nanostores';
|
||||||
import { logger } from './logger.mjs';
|
import { logger } from './logger.mjs';
|
||||||
|
|
||||||
|
|
@ -192,6 +192,7 @@ export const superdough = async (value, deadline, hapDuration) => {
|
||||||
bank,
|
bank,
|
||||||
source,
|
source,
|
||||||
gain = 0.8,
|
gain = 0.8,
|
||||||
|
postgain = 1,
|
||||||
// filters
|
// filters
|
||||||
ftype = '12db',
|
ftype = '12db',
|
||||||
fanchor = 0.5,
|
fanchor = 0.5,
|
||||||
|
|
@ -237,6 +238,11 @@ export const superdough = async (value, deadline, hapDuration) => {
|
||||||
velocity = 1,
|
velocity = 1,
|
||||||
analyze, // analyser wet
|
analyze, // analyser wet
|
||||||
fft = 8, // fftSize 0 - 10
|
fft = 8, // fftSize 0 - 10
|
||||||
|
compressor: compressorThreshold,
|
||||||
|
compressorRatio,
|
||||||
|
compressorKnee,
|
||||||
|
compressorAttack,
|
||||||
|
compressorRelease,
|
||||||
} = value;
|
} = value;
|
||||||
gain *= velocity; // legacy fix for velocity
|
gain *= velocity; // legacy fix for velocity
|
||||||
let toDisconnect = []; // audio nodes that will be disconnected when the source has ended
|
let toDisconnect = []; // audio nodes that will be disconnected when the source has ended
|
||||||
|
|
@ -351,6 +357,11 @@ export const superdough = async (value, deadline, hapDuration) => {
|
||||||
crush !== undefined && chain.push(getWorklet(ac, 'crush-processor', { crush }));
|
crush !== undefined && chain.push(getWorklet(ac, 'crush-processor', { crush }));
|
||||||
shape !== undefined && chain.push(getWorklet(ac, 'shape-processor', { shape }));
|
shape !== undefined && chain.push(getWorklet(ac, 'shape-processor', { shape }));
|
||||||
|
|
||||||
|
compressorThreshold !== undefined &&
|
||||||
|
chain.push(
|
||||||
|
getCompressor(ac, compressorThreshold, compressorRatio, compressorKnee, compressorAttack, compressorRelease),
|
||||||
|
);
|
||||||
|
|
||||||
// panning
|
// panning
|
||||||
if (pan !== undefined) {
|
if (pan !== undefined) {
|
||||||
const panner = ac.createStereoPanner();
|
const panner = ac.createStereoPanner();
|
||||||
|
|
@ -359,7 +370,7 @@ export const superdough = async (value, deadline, hapDuration) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// last gain
|
// last gain
|
||||||
const post = gainNode(1);
|
const post = gainNode(postgain);
|
||||||
chain.push(post);
|
chain.push(post);
|
||||||
post.connect(getDestination());
|
post.connect(getDestination());
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue