Last active
September 5, 2024 16:14
-
-
Save SpotlightKid/9e3b14d5cda5c763c9db7e5e24cfe352 to your computer and use it in GitHub Desktop.
A FAUST-based drum and percussion synth with three components: band-limited noise through a feedback delay, noise and FM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NOTE: as-is, this does NOT work correctly with faust2lv2, since it does not support MIDI input via the "key" parameter. | |
// It does work with the FAUST web IDE and Faust Live, though. | |
declare name "FB / Noise / FM Drum Voice"; | |
declare version "0.1"; | |
declare author "Christopher Arndt"; | |
declare license "MIT License"; | |
declare description "A drum and percussion synth with three components: band-limited noise through a feedback delay, noise and FM"; | |
import("stdfaust.lib"); | |
declare options "[midi:on][nvoices:4]"; | |
key = hslider("key", 440, 20, 7040, 0.01); | |
gain = hslider("gain", 1, 0, 1, 0.001); | |
gate = button("gate"); | |
max_fc = ma.SR / 2; | |
// velocity_gain implements adjustable velocity sensitivity. | |
// At maximum amount and maximum velocity, the value is 1. | |
velocity_gain(amount, velocity) = (1 - amount) + amount * velocity; | |
delay(max_delay, samples, x) = x@(int(samples)&(max_delay-1)); | |
fb_synth(gain, gate) = | |
noise | |
* env : | |
bandpass : | |
+~delay(1000, delay_samples) * feedback : | |
* (velocity_gain(gain_vel_amount, gain) * level) | |
with { | |
delay_samples = hslider("[1] Delay (samples)", 100, 0, 1000, 1); | |
feedback = hslider("[2] Feedback", 99, 90, 99.9, 0.001) / 100; | |
decay = hslider("[3] Decay [unit:s]", 0.5, 0.001, 5.0, 0.001); | |
fc = hslider("[4] BP Center Freq [scale:log]", 5000, 20, 12000, 0.1); | |
fq = hslider("[5] BP Q", 1.0, 0.5, 30, 0.1); | |
gain_vel_amount = hslider("[6] Vel. > Gain", 100, 0, 100, 1) / 100; | |
level = hslider("[7] Level [unit:dB]", -6, -90.0, 0.0, 0.1) : ba.db2linear; | |
noise = no.noise; | |
env = en.adsre(0.001, decay, 0.0, decay, gate); | |
bandpass = fi.resonbp(fc, fq, 1.0); | |
}; | |
noise_synth(gain, gate) = | |
no.noise | |
* env : | |
bandpass : | |
* (velocity_gain(gain_vel_amount, gain) * level) | |
with { | |
attack = hslider("[1] Attack [unit:s]", 0.001, 0.001, 3.0, 0.001); | |
hold = hslider("[2] Hold [unit:s]", 0.0, 0.0, 3.0, 0.001); | |
decay = hslider("[3] Decay [unit:s]", 0.5, 0.001, 5.0, 0.001); | |
fc = hslider("[4] BP Center Freq [scale:log]", 5000, 20, 12000, 0.1); | |
fq = hslider("[5] BP Q", 1.0, 0.1, 30, 0.1); | |
f_env_amount = hslider("[6] Env > Freq [unit:ct]", 0.0, -4800.0, 4800.0, 1); | |
gain_vel_amount = hslider("[7] Vel. > Gain", 100, 0, 100, 1) / 100; | |
level = hslider("[8] Level [unit:dB]", -6, -90.0, 0.0, 0.1) : ba.db2linear; | |
env = en.ahdsre(attack, hold, decay, 0.0, decay, gate); | |
bandpass = fi.resonbp(min(max_fc, fc * ba.cent2ratio(f_env_amount * env)), fq, 1.0); | |
}; | |
fm_synth(key, gain, gate) = | |
os.osc(freq + os.osc(mod_freq) | |
* mod_index * freq) | |
* env | |
* velocity_gain(gain_vel_amount, gain) | |
* level | |
with { | |
tuning = hslider("[0] Tuning [unit:Hz]", 440.0, 20.0, 10000.0, 0.01); | |
keytrack = hslider("[1] Key tracking", 0, -200, 200, 1) / 100; | |
mod_ratio = hslider("[2] Mod ratio", 1, 0.5, 20, .01); | |
mod_index = hslider("[3] FM index", 0.0, 0.0, 50.0, 0.01); | |
attack = hslider("[4] Attack [unit:s]", 0.002, 0.001, 3.0, 0.001); | |
hold = hslider("[5] Hold [unit:s]", 0.0, 0.0, 3.0, 0.001); | |
decay = hslider("[6] Decay [unit:s]", 1.5, 0.001, 5.0, 0.001); | |
pitch_env_amount = hslider("[7] Env > Pitch [unit:ct]", 0.0, -4800.0, 4800.0, 1); | |
gain_vel_amount = hslider("[8] Vel. > Gain", 100, 0, 100, 1) / 100; | |
level = hslider("[9] Level [unit:dB]", -6, -90.0, 0.0, 0.1) : ba.db2linear; | |
env = en.ahdsre(attack, hold, decay, 0.0, decay, gate); | |
car_freq = tuning * pow(2.0, (key - 69.0) / 12.0 * keytrack); | |
freq = car_freq * ba.cent2ratio(pitch_env_amount * env); | |
mod_freq = freq * mod_ratio; | |
}; | |
vol = hslider("[0] Volume", -6.0, -90.0, 0.0, 0.1) : ba.db2linear; | |
drumvoice = hgroup("Drum Voice", | |
fb_group(fb_synth)(gain, gate) | |
+ noise_group(noise_synth)(gain, gate) | |
+ fm_group(fm_synth)(key, gain, gate) | |
) * vol | |
with { | |
fb_group(x) = vgroup("FB", x); | |
noise_group(x) = vgroup("Noise", x); | |
fm_group(x) = vgroup("Sine/FM", x); | |
}; | |
process = drumvoice <: _,_; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment