Skip to content

Other Processors

David Braun edited this page Jun 30, 2022 · 4 revisions

Playback and Add Processor

add_processor = engine.make_add_processor("added")
# or start with gain values
add_processor = engine.make_add_processor("added", [0.25, 0.42, 0.30])
add_processor.gain_levels = [0.26, 0.41, 0.31] # Adjust gain levels whenever you want.

import librosa

def load_audio_file(file_path, duration=None):
  sig, rate = librosa.load(file_path, duration=duration, mono=False, sr=SAMPLE_RATE)
  assert(rate == SAMPLE_RATE)
  return sig

# load stereo wav files into playback
vocals = engine.make_playback_processor("vocals", load_audio_file("vocals.wav"))
piano = engine.make_playback_processor("piano", load_audio_file("piano.wav"))
guitar = engine.make_playback_processor("guitar", load_audio_file("guitar.wav"))

faust_effect = engine.make_faust_processor("faust")
faust_effect.set_dsp_string("process = sp.stereoize( fi.lowpass(2, 5000.) );")
faust_effect.record = True

# A graph is a meaningfully ordered list of tuples.
# In each tuple, the first item is an audio processor.
# The second item is this audio processor's list of input processors by their unique names.
# Note that you can use either hard-coded strings or `get_name()` to make this list.
# The audio from the last tuple's processor will be accessed automatically later by engine.get_audio()
graph = [
  (vocals, []), # Playback has no inputs.
  (piano, []), # Playback has no inputs.
  (guitar, []),  # Playback has no inputs
  (faust_effect, ["guitar"])
  (add_processor, ["vocals", "piano", "faust"])
]

engine.load_graph(graph)
engine.render(5.)

# You can get the audio of any processor whose recording was enabled.
filtered_guitar = faust_effect.get_audio()
# Or get audio according to the processor's unique name
filtered_guitar = engine.get_audio("faust")

# You can set playback data in between rendering.
vocals.set_data(load_audio_file("other_vocals.wav"))

Filter Processor

# Basic filter processor from JUCE.
filter_mode = "high" # "low", "high", "band", "low_shelf", "high_shelf", "notch"
freq = 1000.0  # cutoff frequency in Hz.
q = 0.707107 # safe choice is 1./rad(2)=0.707107.
gain = 1. # gain values only matter when the mode is low_shelf or high_shelf.

filter_processor = engine.make_filter_processor("my_filter", filter_mode, freq, q, gain)
# FilterProcessor has getters/setters
filter_processor.mode = filter_mode
filter_processor.freq = freq
filter_processor.q = q
filter_processor.gain = gain

freq_automation = make_sine(.5, DURATION)*5000. + 7000. # 0.5 Hz sine wave centered at 7000 w/ amp 5000
filter_processor.set_automation("freq", freq_automation) # Argument is single channel numpy array

Compressor Processor

threshold = 0. # dB level of threshold
ratio = 2. # greater than or equal to 1.
attack = 2. # attack of compressor in milliseconds
release = 50. # release of compressor in milliseconds

compressor_processor = engine.make_compressor_processor("my_compressor", threshold, ratio, attack, release)
# CompressorProcessor has getters/setters
compressor_processor.threshold = threshold
compressor_processor.ratio = ratio
compressor_processor.attack = attack
compressor_processor.release = release

Reverb (JUCE)

# Basic reverb processor from JUCE.
room_size = 0.5
damping = 0.5
wet_level = 0.33
dry_level = 0.4
width = 1.
reverb_processor = engine.make_reverb_processor("my_reverb", room_size, damping, wet_level, dry_level, width)
# ReverbProcessor has getters/setters
reverb_processor.room_size = room_size
reverb_processor.damping = damping
reverb_processor.wet_level = wet_level
reverb_processor.dry_level = dry_level
reverb_processor.width = width

Panner (JUCE)

panner_processor = engine.make_panner_processor("my_panner", "linear", 0.)
# the rules: "linear", "balanced", "sin3dB", "sin4p5dB", "sin6dB", "squareRoot3dB", "squareRoot4p5dB"
panner_processor.rule = "balanced" 
panner_processor.pan = -.5 # -1. is fully left and 1. is fully right

Delay (JUCE)

delay_rule = "linear" # only linear is supported right now
delay_ms = 200. # delay in milliseconds
delay_wet = .3 # 0 means use all of original signal and none of the "wet" delayed signal. 1. is the opposite.
delay_processor = engine.make_delay_processor("my_delay", delay_rule, delay_ms, delay_wet)
# delay_processor.rule = "linear" # modifying the rule is not supported yet.
delay_processor.delay = delay_ms
delay_processor.wet = delay_wet