Skip to content

Instantly share code, notes, and snippets.

@xavriley
Created February 5, 2016 21:09
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save xavriley/1b9063ea2ce645c016c8 to your computer and use it in GitHub Desktop.
Getting LADSPA plugins working on Sonic Pi

Getting LADSPA plugins working on Sonic Pi

This is an evil experiment at the moment but it works

  • Download and install LMMS from http://lmms.io
  • Run the attached SuperCollider file to create the synthdef locally (Overtone doesn't have ladspa yet)
  • patch the named ruby files as per the other attachments
  • start Sonic Pi
live_loop :lands, auto_cue: false do
  with_fx :reverb, room: 0.2 do
    with_fx :tube_warmth, tape_blend: 1, drive: 0.99 do
      use_synth :dsaw
      use_random_seed 310003
      ns = (scale :e1, :minor_pentatonic, num_octaves: 4).take(4)
      16.times do
        play ns.choose, detune: 12, release: 0.1, amp: 2, amp: rand + 0.5, cutoff: rrand(70, 120), amp: 2
        sleep 0.125
      end
    end
  end
end
diff --git a/app/server/sonicpi/lib/sonicpi/scsynthexternal.rb b/app/server/sonicpi/lib/sonicpi/scsynthexternal.rb
index f3e3247..30b2895 100644
--- a/app/server/sonicpi/lib/sonicpi/scsynthexternal.rb
+++ b/app/server/sonicpi/lib/sonicpi/scsynthexternal.rb
@@ -313,7 +313,7 @@ module SonicPi
rescue Exception => e
raise "Unable to boot sound synthesis engine: the input and output rates of your audio card are not the same. Got in: #{audio_in_rate}, out: #{audio_out_rate}."
end
- boot_and_wait(scsynth_path, "-u", @port.to_s, "-a", num_audio_busses_for_current_os.to_s, "-m", "131072", "-D", "0", "-R", "0", "-l", "1")
+ boot_and_wait({"LADSPA_PATH" => "/Applications/LMMS.app/Contents/lib/lmms/ladspa"}, scsynth_path, "-u", @port.to_s, "-a", num_audio_busses_for_current_os.to_s, "-m", "131072", "-D", "0", "-R", "0", "-l", "1")
end
diff --git a/app/server/sonicpi/lib/sonicpi/synths/synthinfo.rb b/app/server/sonicpi/lib/sonicpi/synths/synthinfo.rb
index 8ecf9ce..6867f75 100644
--- a/app/server/sonicpi/lib/sonicpi/synths/synthinfo.rb
+++ b/app/server/sonicpi/lib/sonicpi/synths/synthinfo.rb
@@ -4775,6 +4775,139 @@ module SonicPi
end
end
+ class FXTubeWarmth < FXInfo
+ def name
+ "TubeWarmth"
+ end
+
+ def introduced
+ Version.new(2,10,0)
+ end
+
+ def synth_name
+ "fx_tube-warmth"
+ end
+
+ def doc
+ "TAP TubeWarmth adds the character of vacuum tube amplification to your audio tracks by emulating the sonically desirable nonlinear characteristics of triodes. In addition, this plugin also supports emulating analog tape satura
tion."
+ end
+
+ def arg_defaults
+ {
+ :amp => 1,
+ :amp_slide => 0,
+ :amp_slide_shape => 1,
+ :amp_slide_curve => 0,
+ :mix => 1,
+ :mix_slide => 0,
+ :mix_slide_shape => 1,
+ :mix_slide_curve => 0,
+ :pre_amp => 1,
+ :pre_amp_slide => 0,
+ :pre_amp_slide_shape => 1,
+ :pre_amp_slide_curve => 0,
+ :drive => 0.2575,
+ :drive_slide => 0,
+ :drive_slide_shape => 1,
+ :drive_slide_curve => 0,
+ :tape_blend => 1,
+ :tape_blend_slide => 0,
+ :tape_blend_slide_shape => 1,
+ :tape_blend_slide_curve => 0,
+ }
+ end
+
+ def specific_arg_info
+ {
+ :drive =>
+ {
+ :doc => "Amount of drive to be applied (as a value between 0 and 1). Values between 0.2 and 0.5 are a good starting point for a variety of source materials. Since audio tracks can vary quite a bit in average and peak levels
, experiment with this setting and use your ears to get the sound you want. (It's quite easy if you know how real tube amps sound like...) If the drive level is set too high, the signal will most likely sound distorted. If it's too low,
you may not hear the effect working.",
+ :validations => [v_greater_than_oet(:drive, 0), v_less_than_oet(:drive, 1)],
+ :modulatable => true
+ },
+
+ :drive_slide =>
+ {
+ :doc => generic_slide_doc(:drive),
+ :validations => [v_positive(:drive_slide)],
+ :modulatable => true,
+ :bpm_scale => true
+ },
+
+ :tape_blend =>
+ {
+ :doc => "Blend of tape vs tube colour (as a value between -1 and 1, -1 being fully tape, 1 being fully tube). When set all the way to the right (+1 or default position), the plugin emulates the sound of triode tube distorti
on. The result is asymmetrical, producing mostly second harmonics and some third. When set all the way to the left (-1), the plugin emulates the sound of analog tape. The result is symmetrical and produces mostly third harmonics and som
e second. With high drive settings, moving the blend control to the left increases the apparent loudness of low-level signals dramatically. This is because the zero-attack, zero-release compression effect is increased under these condit
ions. Use the blend control to set the sound of the plugin anywhere between Tape and Tube sound.",
+ :validations => [v_greater_than_oet(:tape_blend, -1), v_less_than_oet(:tape_blend, 1)],
+ :modulatable => true
+ },
+
+ :tape_blend_slide =>
+ {
+ :doc => generic_slide_doc(:tape_blend),
+ :validations => [v_positive(:tape_blend_slide)],
+ :modulatable => true,
+ :bpm_scale => true
+ }
+ }
+ end
+ end
+
+
:fx_replace_normaliser => FXNormaliser.new,
:fx_distortion => FXDistortion.new,
+ :fx_tube_warmth => FXTubeWarmth.new,
"LADSPA_PATH".setenv("/Applications/LMMS.app/Contents/lib/lmms/ladspa");
s.boot;
s.quit;
(
SynthDef('sonic-pi-fx_tube-warmth', {
arg drive = 0.2572, tape_blend = 1, out_bus=0, in_bus=0;
var source, result;
source = In.ar(in_bus,2);
result = LADSPA.ar(1, 2158, drive*10, tape_blend*10, source);
Out.ar(out_bus, result.dup);
}).writeDefFile("/Users/xriley/Projects/sonic-pi/etc/synthdefs/compiled/");
%%%
%%% REMEMBER TO CHANGE THIS ^^^ TO MATCH YOUR SONIC PI PATH
%%%
)
def boot_server_osx
log_boot_msg
log "Boot - Booting on OS X"
log "Boot - Checkout audio rates on OSX:"
# Force sample rate for both input and output to 44k
# If these are not identical, then scsynth will refuse
# to boot.
begin
audio_in_rate = :unknown_in_rate
audio_out_rate = :unknown_out_rate
require 'coreaudio'
audio_in_rate = CoreAudio.default_input_device.nominal_rate
audio_out_rate = CoreAudio.default_output_device.nominal_rate
log "Boot - Input audio rate: #{audio_in_rate}"
log "Boot - Output audio rate: #{audio_out_rate}"
if audio_in_rate != audio_out_rate
log "Attempting to set both in and out sample rates to 44100.0..."
CoreAudio.default_output_device(nominal_rate: 44100.0)
CoreAudio.default_input_device(nominal_rate: 44100.0)
# now check again...
audio_in_rate = CoreAudio.default_input_device.nominal_rate
audio_out_rate = CoreAudio.default_output_device.nominal_rate
log "Boot - Input audio rate now: #{audio_in_rate}"
log "Boot - Output audio rate now: #{audio_out_rate}"
if audio_in_rate != :unknown_in_rate && audio_out_rate != :unknown_out_rate && audio_in.nominal_rate != audio_out.nominal_rate
log "Boot - Sample rates do not match, exiting"
raise
end
else
log "Boot - Sample rates match, we may continue to boot..."
end
rescue Exception => e
raise "Unable to boot sound synthesis engine: the input and output rates of your audio card are not the same. Got in: #{audio_in_rate}, out: #{audio_out_rate}."
end
boot_and_wait({"LADSPA_PATH" => "/Applications/LMMS.app/Contents/lib/lmms/ladspa"}, scsynth_path, "-u", @port.to_s, "-a", num_audio_busses_for_current_os.to_s, "-m", "131072", "-D", "0", "-R", "0", "-l", "1")
end
class FXTubeWarmth < FXInfo
def name
"TubeWarmth"
end
def introduced
Version.new(2,10,0)
end
def synth_name
"fx_tube-warmth"
end
def doc
"TAP TubeWarmth adds the character of vacuum tube amplification to your audio tracks by emulating the sonically desirable nonlinear characteristics of triodes. In addition, this plugin also supports emulating analog tape saturation."
end
def arg_defaults
{
:amp => 1,
:amp_slide => 0,
:amp_slide_shape => 1,
:amp_slide_curve => 0,
:mix => 1,
:mix_slide => 0,
:mix_slide_shape => 1,
:mix_slide_curve => 0,
:pre_amp => 1,
:pre_amp_slide => 0,
:pre_amp_slide_shape => 1,
:pre_amp_slide_curve => 0,
:drive => 0.2575,
:drive_slide => 0,
:drive_slide_shape => 1,
:drive_slide_curve => 0,
:tape_blend => 1,
:tape_blend_slide => 0,
:tape_blend_slide_shape => 1,
:tape_blend_slide_curve => 0,
}
end
def specific_arg_info
{
:drive =>
{
:doc => "Amount of drive to be applied (as a value between 0 and 1). Values between 0.2 and 0.5 are a good starting point for a variety of source materials. Since audio tracks can vary quite a bit in average and peak levels, experiment with this setting and use your ears to get the sound you want. (It's quite easy if you know how real tube amps sound like...) If the drive level is set too high, the signal will most likely sound distorted. If it's too low, you may not hear the effect working.",
:validations => [v_greater_than_oet(:drive, 0), v_less_than_oet(:drive, 1)],
:modulatable => true
},
:drive_slide =>
{
:doc => generic_slide_doc(:drive),
:validations => [v_positive(:drive_slide)],
:modulatable => true,
:bpm_scale => true
},
:tape_blend =>
{
:doc => "Blend of tape vs tube colour (as a value between -1 and 1, -1 being fully tape, 1 being fully tube). When set all the way to the right (+1 or default position), the plugin emulates the sound of triode tube distortion. The result is asymmetrical, producing mostly second harmonics and some third. When set all the way to the left (-1), the plugin emulates the sound of analog tape. The result is symmetrical and produces mostly third harmonics and some second. With high drive settings, moving the blend control to the left increases the apparent loudness of low-level signals dramatically. This is because the zero-attack, zero-release compression effect is increased under these conditions. Use the blend control to set the sound of the plugin anywhere between Tape and Tube sound.",
:validations => [v_greater_than_oet(:tape_blend, -1), v_less_than_oet(:tape_blend, 1)],
:modulatable => true
},
:tape_blend_slide =>
{
:doc => generic_slide_doc(:tape_blend),
:validations => [v_positive(:tape_blend_slide)],
:modulatable => true,
:bpm_scale => true
}
}
end
end
# ...
:fx_tube_warmth => FXTubeWarmth.new,
@b08x
Copy link

b08x commented Jun 28, 2022

This is fantastic, thank you. My only question is this line:

result = LADSPA.ar(1, 2158, drive*10, tape_blend*10, source);

What made you multiply these values by 10? I was trying to apply this to Steve Harris' revdelay plugin but seem to get stuck here.

I guess it could be a limit of the plugin, so I think I'll try the compressor plugin to further test.

Thanks again for doing this, really helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment