Module:MOS intervals: Difference between revisions

Ganaram inukshuk (talk | contribs)
mNo edit summary
R-4981 (talk | contribs)
No edit summary
Line 31: Line 31:
local bright_gen_step_count = mos.bright_gen_step_count(input_mos)
local bright_gen_step_count = mos.bright_gen_step_count(input_mos)
local dark_gen_step_count = mos.dark_gen_step_count(input_mos)
local dark_gen_step_count = mos.dark_gen_step_count(input_mos)
-- Setup for harmonic entropy
local step_ratios = {
{ 4, 3 },
{ 3, 2 },
{ 5, 3 },
{ 2, 1 },
{ 5, 2 },
{ 3, 1 },
{ 4, 1 },
}
-- Create the table, starting with the headers
-- Create the table, starting with the headers
Line 38: Line 49:
result = result .. '! rowspan="2" | Steps subtended\n'
result = result .. '! rowspan="2" | Steps subtended\n'
result = result .. '! rowspan="2" | Range in cents\n'
result = result .. '! rowspan="2" | Range in cents\n'
result = result .. '! rowspan="2" | [[Harmonic entropy]]<br/>(Shannon, <math>\\sqrt{n\\cdot d}</math>)\n'
result = result .. '|-\n'
result = result .. '|-\n'
result = result .. '! Generic<sup>[[#mosstep-1|[1]]]</sup>\n'
result = result .. '! Generic<sup>[[#mosstep-1|[1]]]</sup>\n'
Line 63: Line 75:
result = result .. string.format("| %s\n" , mos.interval_as_string(current_bright_interval))
result = result .. string.format("| %s\n" , mos.interval_as_string(current_bright_interval))
result = result .. string.format("| %.1f¢\n", cents)
result = result .. string.format("| %.1f¢\n", cents)
result = result .. string.format("| %.6f bits\n", inverval.harmonic_entropy(cents))
else
else
-- Calculate the best and average harmonic entropies
local he_dark_average = 0
local he_bright_average = 0
local he_dark_best = 1000
local he_bright_best = 1000
for i = 1, #step_ratios do
local step_ratio = step_ratios[i]
local he_dark = mos.interval_to_cents(current_dark_interval, input_mos, step_ratio)
local he_bright = mos.interval_to_cents(current_bright_interval, input_mos, step_ratio)
he_dark_average = he_dark_average + he_dark / #step_ratios
he_bright_average = he_bright_average + he_bright / #step_ratios
if he_dark_best > he_dark then
he_dark_best = he_dark
end
if he_bright_best > he_bright then
he_bright_best = he_bright
end
end
-- Calculate the cent values min and max for the current intervals
-- Calculate the cent values min and max for the current intervals
local sm_min_cents = mos.interval_to_cents(current_dark_interval, input_mos, {1,1})
local sm_min_cents = mos.interval_to_cents(current_dark_interval, input_mos, {1,1})
Line 81: Line 113:
result = result .. string.format("| %s\n" , mos.interval_as_string(current_dark_interval))
result = result .. string.format("| %s\n" , mos.interval_as_string(current_dark_interval))
result = result .. string.format("| %s\n" , dark_interval_range)
result = result .. string.format("| %s\n" , dark_interval_range)
result = result .. string.format("| %.6f¢ bits (average), %.6f¢ bits (best)\n" , he_dark_average, he_dark_best)
result = result .. "|-\n"
result = result .. "|-\n"
Line 87: Line 120:
result = result .. string.format("| %s\n" , mos.interval_as_string(current_bright_interval))
result = result .. string.format("| %s\n" , mos.interval_as_string(current_bright_interval))
result = result .. string.format("| %s\n" , bright_interval_range)
result = result .. string.format("| %s\n" , bright_interval_range)
result = result .. string.format("| %.6f¢ bits (average), %.6f¢ bits (best)\n" , he_bright_average, he_bright_best)
end
end