Just playing around with ChatGPT. I asked it to write an Ardour script to normalize an audio region, this is what it came up with.
-- Get a reference to the audio region that we want to normalize
local region = ARDOUR.LuaAPI.selected_region(0)
-- Check if a region is selected
if region:isnil() then
-- If no region is selected, display an error message
print("Error: No region selected")
return
end
-- Get the audio data for the region
local audio = region:to_readable():array()
-- Find the maximum sample value in the audio data
local max_sample = -math.huge
for i=1,#audio do
max_sample = math.max(max_sample, math.abs(audio[i]))
end
-- Calculate the normalization factor
local factor = 1 / max_sample
-- Normalize the audio data
for i=1,#audio do
audio[i] = audio[i] * factor
end
-- Update the region with the normalized audio data
region:from_array(audio, region:length())
-- Display a message to confirm that the normalization was successful
print("Volume normalized for region '" .. region:name() .. "'")
It also gave this explanation:
This script first gets a reference to the audio region that is currently selected in the editor. It then reads the audio data for the region and finds the maximum sample value. It calculates a normalization factor based on this maximum value, and applies it to the audio data. Finally, it updates the region with the normalized audio data and displays a message to confirm that the normalization was successful.
You can execute this script in Ardour by using the “Lua Console” window, or by saving it as a “.luax” file and running it using the “Run Lua Script” command in the “Transport” menu. This script will only work on the audio region that is currently selected in the editor, so make sure to select the region that you want to normalize before running the script.
The script doesn’t work btw