2012-07-28 01:30:20 +02:00
|
|
|
COOLDOWN_FACTOR = 0.9998
|
2012-07-29 23:45:14 +02:00
|
|
|
FACTOR = 0.033
|
2012-07-28 01:30:20 +02:00
|
|
|
|
|
|
|
num_modules = 20
|
|
|
|
center_module = 10
|
|
|
|
|
|
|
|
-- maximum energy values for each band
|
|
|
|
maxRedEnergy = 1
|
|
|
|
maxGreenEnergy = 1
|
|
|
|
maxBlueEnergy = 1
|
|
|
|
maxRMS = 1
|
|
|
|
|
|
|
|
-- output color buffers
|
|
|
|
red = {}
|
|
|
|
green = {}
|
|
|
|
blue = {}
|
|
|
|
|
|
|
|
function periodic()
|
|
|
|
local redEnergy = get_energy_in_band(0, 400);
|
|
|
|
local greenEnergy = get_energy_in_band(400, 4000);
|
|
|
|
local blueEnergy = get_energy_in_band(4000, 22000);
|
|
|
|
local rms = get_rms();
|
|
|
|
|
|
|
|
maxRedEnergy = maxRedEnergy * COOLDOWN_FACTOR
|
|
|
|
if redEnergy > maxRedEnergy then
|
|
|
|
maxRedEnergy = redEnergy
|
|
|
|
end
|
|
|
|
|
|
|
|
maxGreenEnergy = maxGreenEnergy * COOLDOWN_FACTOR
|
|
|
|
if greenEnergy > maxGreenEnergy then
|
|
|
|
maxGreenEnergy = greenEnergy
|
|
|
|
end
|
|
|
|
|
|
|
|
maxBlueEnergy = maxBlueEnergy * COOLDOWN_FACTOR
|
|
|
|
if blueEnergy > maxBlueEnergy then
|
|
|
|
maxBlueEnergy = blueEnergy
|
|
|
|
end
|
|
|
|
|
|
|
|
maxRMS = maxRMS * COOLDOWN_FACTOR
|
|
|
|
if rms > maxRMS then
|
|
|
|
maxRMS = rms
|
|
|
|
end
|
|
|
|
|
|
|
|
local brightness = rms / maxRMS
|
|
|
|
|
|
|
|
for i = 1,num_modules do
|
2012-07-29 23:45:14 +02:00
|
|
|
if i <= center_module and
|
|
|
|
center_module - i < center_module * redEnergy / maxRedEnergy or
|
|
|
|
i > center_module and
|
|
|
|
i - (center_module + 1) < (num_modules-center_module) * redEnergy / maxRedEnergy
|
|
|
|
then
|
2012-07-28 01:30:20 +02:00
|
|
|
redTarget = brightness
|
|
|
|
else
|
|
|
|
redTarget = 0
|
|
|
|
end
|
|
|
|
red[i] = (1 - FACTOR) * red[i] + FACTOR * redTarget;
|
|
|
|
|
2012-07-29 23:45:14 +02:00
|
|
|
if i <= center_module and
|
|
|
|
center_module - i < center_module * greenEnergy / maxGreenEnergy or
|
|
|
|
i > center_module and
|
|
|
|
i - (center_module + 1) < (num_modules-center_module) * greenEnergy / maxGreenEnergy
|
|
|
|
then
|
2012-07-28 01:30:20 +02:00
|
|
|
greenTarget = brightness
|
|
|
|
else
|
|
|
|
greenTarget = 0
|
|
|
|
end
|
|
|
|
green[i] = (1 - FACTOR) * green[i] + FACTOR * greenTarget;
|
|
|
|
|
2012-07-29 23:45:14 +02:00
|
|
|
if i <= center_module and
|
|
|
|
center_module - i < center_module * blueEnergy / maxBlueEnergy or
|
|
|
|
i > center_module and
|
|
|
|
i - (center_module + 1) < (num_modules-center_module) * blueEnergy / maxBlueEnergy
|
|
|
|
then
|
2012-07-28 01:30:20 +02:00
|
|
|
blueTarget = brightness
|
|
|
|
else
|
|
|
|
blueTarget = 0
|
|
|
|
end
|
|
|
|
blue[i] = (1 - FACTOR) * blue[i] + FACTOR * blueTarget;
|
|
|
|
end
|
|
|
|
|
|
|
|
-- return the 3 color arrays
|
|
|
|
return red, green, blue
|
|
|
|
end
|
|
|
|
|
|
|
|
function init(nmod, cmod)
|
|
|
|
num_modules = nmod
|
|
|
|
center_module = cmod
|
|
|
|
|
|
|
|
for i = 1,nmod do
|
|
|
|
red[i] = 0
|
|
|
|
green[i] = 0
|
|
|
|
blue[i] = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
-- fadestep (0 = no fading)
|
|
|
|
return 0
|
|
|
|
end
|