ACE Amplifier Stereo with One Control per Channel

Hi there!

I have a simple suggestion… now I have this stereo track, and it turns out I had set the gain of the left channel too low during recording. How simple would it be to fix this if there was an ACE Amplifier version that just had two volume sliders, one for left and one for right.

Well, of course, because Ardour’s mixer is one of the greatest DAW mixers out there, I can go to the pin connections window and bypass the plugin for the right channel of the stereo track, but not for the left one. But having two sliders would be more convenient in everyday use.

As always, thanks for making Arodur.

Best
Niels

You could try to use the paning in any plugin or the mixer strip. You could for example also use x42 stereo balance tool.
But I’d also like to see your suggestion actually. The Utility plugin in Ableton has so many simple features inside and it would be cool to have on go to plugin for all of these usecases.

1 Like

save as ~/.config/ardour8/scripts/stereo_gain.lua

EDIT: direct download: https://paste.debian.net/download/1348589

ardour {
  ["type"]    = "dsp",
  name        = "ACE Stereo Gain",
  category    = "Utility",
  license     = "MIT",
  author      = "Ardour Community",
  description = [[DrNi asked for it]]
}

function dsp_ioconfig ()
  return { { audio_in = 2, audio_out = 2} }
end

function dsp_params ()
  return {
    { ["type"] = "input", name = "Gain Left", min = -20, max = 20, default = 0, unit="dB"},
    { ["type"] = "input", name = "Gain Right", min = -20, max = 20, default = 0, unit="dB"},
  }
end
  
local current_gain_l = 1.0
local current_gain_r = 1.0
local sample_rate = 48000

function dsp_init (rate)
  sample_rate = rate
end

function dsp_configure (ins, outs)
  n_out = outs
end

function dsp_runmap (bufs, in_map, out_map, n_samples, offset)
  ARDOUR.DSP.process_map (bufs, n_out, in_map, out_map, n_samples, offset) -- apply pin connections
  local id_l = out_map:get (ARDOUR.DataType ("audio"), 0); -- get id of mapped left output buffer
  local id_r = out_map:get (ARDOUR.DataType ("audio"), 1); -- get id of mapped right output buffer

  local ctrl = CtrlPorts:array() -- get parameters
  local target_gain_l = ARDOUR.DSP.dB_to_coefficient (ctrl[1]) -- 10 ^ (0.05 * ctrl[1])
  local target_gain_r = ARDOUR.DSP.dB_to_coefficient (ctrl[2]) -- 10 ^ (0.05 * ctrl[2])

  if (id_l ~= ARDOUR.ChanMapping.Invalid) then
    current_gain_l = ARDOUR.Amp.apply_gain (bufs:get_audio(id_l), sample_rate, n_samples, current_gain_l, target_gain_l, offset)
  end

  if (id_r ~= ARDOUR.ChanMapping.Invalid) then
    current_gain_r = ARDOUR.Amp.apply_gain (bufs:get_audio(id_r), sample_rate, n_samples, current_gain_r, target_gain_r, offset)
  end
end
6 Likes

Hi
I copied the script above, pasted into gedit and saved into ~/.config/ardour8/scripts/stereo_gain.lua
Then I went to Edit>Lua scripts>Script manager and tried to add it by right clicking an unset action, but it was not in the list, even after I restarted Ardour. The scripts folder did not seem to exist before I saved Robin’s script, yet there are other Lua scripts listed in script manager.
here is the contents of my .config folder:

ls .config/ardour8/
config plugin_metadata recent sfdb ui_scripts
instant.xml presets scripts ui_config

Have i misunderstood something?
Many thanks

Did you copy the entire script or just the visible part in Robin’s post ?

Thanks baptiste. Now i can see i left some of it out. I will copy it all now and see if things improve.

No luck so far.
The script strart with

ardour {
and ends:
if (id_r ~= ARDOUR.ChanMapping.Invalid) then
current_gain_r = ARDOUR.Amp.apply_gain (bufs:get_audio(id_r), sample_rate, n_samples, current_gain_r, target_gain_r, offset)
end
end

Is that right?
Many thanks

@mel-g
The final lines of @x42’s script are:

function dsp_runmap (bufs, in_map, out_map, n_samples, offset)
  ARDOUR.DSP.process_map (bufs, n_out, in_map, out_map, n_samples, offset) -- apply pin connections
  local id_l = out_map:get (ARDOUR.DataType ("audio"), 0); -- get id of mapped left output buffer
  local id_r = out_map:get (ARDOUR.DataType ("audio"), 1); -- get id of mapped right output buffer

  local ctrl = CtrlPorts:array() -- get parameters
  local target_gain_l = ARDOUR.DSP.dB_to_coefficient (ctrl[1]) -- 10 ^ (0.05 * ctrl[1])
  local target_gain_r = ARDOUR.DSP.dB_to_coefficient (ctrl[2]) -- 10 ^ (0.05 * ctrl[2])

  if (id_l ~= ARDOUR.ChanMapping.Invalid) then
    current_gain_l = ARDOUR.Amp.apply_gain (bufs:get_audio(id_l), sample_rate, n_samples, current_gain_l, target_gain_l, offset)
  end

  if (id_r ~= ARDOUR.ChanMapping.Invalid) then
    current_gain_r = ARDOUR.Amp.apply_gain (bufs:get_audio(id_r), sample_rate, n_samples, current_gain_r, target_gain_r, offset)
  end
end

(Note that I am using the “code” tags, labeled </> in the editor toolbar, to quote the code section).

It’s a Lua plugin, not a ‘script’ as such. It should show up in your plugin list.

Thank you both.
Its showing up now. In the plugin dialog the Filter defaults to Show Effects Only and it did not appear. when I changed that option to Show All, its in the list. Lovely :grinning:

Robin, I’m close to speechless. This is exactly it and it solves my problem. Thank you so very much!

I wasn’t aware that one could do audio processing with LUA in Ardour.

Side remark to other suggestions: Yes, panning. But: It’s much less straightforward since there are different panning laws in different plugins and DAWs. When you see your left channel of a stereo track showing some decibels less than the right one, the most simply and also straightforward idea is that simple plugin that Robin provided.

Btw., as people may guess, this also works right away in Mixbus.

Best
Niels

Yeah it’s pretty neat to use Lua as glue to call Ardour’s DSP functions. It’s also handy for quick prototyping.

The code above could be more generic and a for loop reduce the number of lines.
You could also directly add maths for your favorite pan law.

Perhaps take some inspiration from DAW v DAW - Part 6: Pan Laws and Pan Curves

Some of the example scripts (ardour/share/scripts at master · Ardour/ardour · GitHub) may come in handy if you want head down the road of tweaking the Lua DSP script.