Skip to content

Commit

Permalink
Replace wind noise with attackDetune/Noise
Browse files Browse the repository at this point in the history
  • Loading branch information
jonikorpi committed Feb 14, 2025
1 parent 2130139 commit 0271c84
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 41 deletions.
57 changes: 25 additions & 32 deletions instrument-presets.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,6 @@ import { InstrumentPreset, OscillatorPreset } from "./instruments";
import { getPianoPitch, getPluckedStringPitch } from "./stretched-pitches";
import { addSympatheticStringsToImag, getSympatheticStringPitch } from "./sympathetic-strings";

const getWindNoiseOscillator = ({
attackDetune = 200,
attack = 0.021,
decay = 0.056,
noiseQ = 32,
gain = 0.236,
} = {}) =>
new OscillatorPreset({
type: "noise",
noiseQ,
noiseType: "highpass",
gain: gain / noiseQ,
attack,
decay,
sustain: 0.0,
release: attack * 0.618,
attackDetune,
attackDetuneDuration: attack + decay,
velocityImpactOnGain: 0.618,
});

// https://northwoodsoboe.com/the-oboes-overtones-why-does-the-oboe-sound-so-unique/
// https://musiccrashcourses.com/lessons/harmonic_series.html
// https://www.youtube.com/watch?v=hfS7mDvrZ7g
Expand Down Expand Up @@ -53,10 +32,9 @@ export const flute = new InstrumentPreset({
decay: 0.146,
release: 0.021,
velocitySensitivity: -1,
vibratoEffectOnVolume: 0.382,
vibratoEffectOnVolume: 1,
velocityImpactOnGain: 0.764,
},
getWindNoiseOscillator(),
],

attack: 0.056,
Expand All @@ -67,6 +45,13 @@ export const flute = new InstrumentPreset({
highPassFrequency: 261.624,
lowPassFrequency: 4185.984,

attackDetune: -30,
attackDetuneDuration: 0.034,
attackNoise: 100,
attackNoiseDuration: 0.034,

vibratoEffectOnVolume: -0.382,

formants: [{ frequency: 880 }],
});

Expand All @@ -82,12 +67,10 @@ export const ocarina = new InstrumentPreset({
...flute.oscillators[1],
imag: Float32Array.of(0.0, 0.0, 0.0, 0.034, 0.0, 0.021, 0.0, 0.013, 0.0, 0.008),
},
getWindNoiseOscillator(),
],

highPassFrequency: 261.6,
lowPassFrequency: 2793.826,
vibratoEffectOnPitch: 30,
});

// // https://northwoodsoboe.com/the-oboes-overtones-why-does-the-oboe-sound-so-unique/
Expand Down Expand Up @@ -123,7 +106,6 @@ export const oboe = new InstrumentPreset({
velocitySensitivity: -1,
velocityImpactOnGain: 0.764,
},
getWindNoiseOscillator({ attackDetune: 100 }),
],

attack: 0.056,
Expand All @@ -134,6 +116,11 @@ export const oboe = new InstrumentPreset({
highPassFrequency: 233.08,
lowPassFrequency: 2793.83,

attackDetune: -30,
attackDetuneDuration: 0.034,
attackNoise: 30,
attackNoiseDuration: 0.034,

vibratoEffectOnPitch: 30,
formants: [{ frequency: 1396.91 }, { frequency: 2793.83 }],
});
Expand Down Expand Up @@ -167,7 +154,6 @@ export const bassoon = new InstrumentPreset({
0.005,
),
},
getWindNoiseOscillator({ attackDetune: 100 }),
],
highPassFrequency: 58.27,
lowPassFrequency: 1108.73,
Expand Down Expand Up @@ -221,14 +207,18 @@ export const clarinet = new InstrumentPreset({
velocitySensitivity: -1,
velocityImpactOnGain: 0.764,
},
getWindNoiseOscillator({ attackDetune: 0 }),
],

attack: 0.056,
decay: 0.236,
sustain: 0.91,
release: 0.034,

attackDetune: -30,
attackDetuneDuration: 0.034,
attackNoise: 30,
attackNoiseDuration: 0.034,

highPassFrequency: 164.812,
lowPassFrequency: 2349.32,
vibratoEffectOnPitch: 30,
Expand Down Expand Up @@ -281,14 +271,14 @@ export const saxophone = new InstrumentPreset({
},
],

attackDetune: 30, // FIXME: is this a thing?
attackDetuneDuration: 0.382,

attack: 0.056,
attack: 0.09,
decay: 0.236,
sustain: 0.764,
release: 0.056,

attackDetune: -30,
attackDetuneDuration: 0.056,

highPassFrequency: 69.3,
lowPassFrequency: 1975.53,
vibratoEffectOnPitch: 30,
Expand Down Expand Up @@ -342,6 +332,9 @@ export const trumpet = new InstrumentPreset({
sustain: 0.854,
release: 0.09,

attackDetune: -30,
attackDetuneDuration: 0.034,

highPassFrequency: 184.996,
lowPassFrequency: 2349.32,

Expand Down
17 changes: 9 additions & 8 deletions instruments.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getNoiseOscillator } from "./sources.js";
import { getConstantMinusSource, getNoiseOscillator } from "./sources.js";

export class InstrumentPreset {
group = "Miscellaneous";
Expand Down Expand Up @@ -273,30 +273,31 @@ export const createInstrument = (

// Percussion-style attack noise
let attackNoiseGain = null;
if (attackNoise > 0.0) {
if (attackNoise) {
attackNoiseGain = new GainNode(audioContext, { gain: 0.0 });
getNoiseOscillator(audioContext).connect(attackNoiseGain).connect(oscillatorNode.detune);
}

// Brass-style attack instability
let attackInstabilityGain = null;
if (attackInstability > 0.0) {
if (attackInstability) {
canVibrato = true;
attackInstabilityGain = new GainNode(audioContext, { gain: 0.0 });
vibratoMain.connect(attackInstabilityGain).connect(gainNode.gain);
}

// Tremolo and/or brightness vibrato
let vibratoVolumeGain = null;
if (vibratoEffectOnVolume > 0.0) {
if (vibratoEffectOnVolume) {
canVibrato = true;
vibratoVolumeGain = new GainNode(audioContext, { gain: 0.0 });
vibratoMain.connect(vibratoVolumeGain).connect(gainNode.gain);
getConstantMinusSource(audioContext).connect(vibratoVolumeGain);
}

// Regular pitch vibrato
let vibratoPitchGain = null;
if (vibratoEffectOnPitch > 0.0) {
if (vibratoEffectOnPitch) {
canVibrato = true;
vibratoPitchGain = new GainNode(audioContext, { gain: 0.0 });
vibratoMain.connect(vibratoPitchGain).connect(oscillatorNode.detune);
Expand Down Expand Up @@ -469,7 +470,7 @@ export const attackInstrument = (
}

// Brass-style attack instability
if (attackInstability > 0.0) {
if (attackInstability) {
attackInstabilityStopsAt = Math.max(
attackInstabilityStopsAt,
attackInstabilityStopsAt + dynamicAttack * 5.0,
Expand Down Expand Up @@ -517,7 +518,7 @@ export const attackInstrument = (
}

// Fire up vibrato
if (canVibrato && vibratoAmount > 0.0) {
if (canVibrato && vibratoAmount) {
const attack = firstAttack * 0.013;
const gainAttack = firstAttack * 0.056;
const vibratoAt = attackInstabilityStopsAt + attack;
Expand All @@ -536,7 +537,7 @@ export const attackInstrument = (
gainAttack,
);
vibratoVolumeGain?.gain.setTargetAtTime(
vibratoAmount * -vibratoEffectOnVolume * volume,
vibratoAmount * -vibratoEffectOnVolume * volume * 0.5, // halved because it should range from -2 to 0
vibratoAt,
gainAttack,
);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vuoro/pelimanni",
"version": "0.17.0",
"version": "0.17.1",
"type": "module",
"main": "./instruments.js",
"exports": {
Expand Down

0 comments on commit 0271c84

Please sign in to comment.