Easier way to configure volume threshold (an exported variable in generate.sh)

This commit is contained in:
Kuba Orlik 2023-12-28 13:07:15 +01:00
parent d96d4373f4
commit a6e89ee5ad
2 changed files with 56 additions and 65 deletions

View File

@ -2,7 +2,7 @@ import findLoudness, { SwapPoint } from "./find-loudness";
const graph_density = 8000;
const threshold_at_point = 1;
const threshold_at_point = parseInt(process.env.demuxer_volume_threshold) || 1;
const inertia_s = 0.3;
const inertia_samples = inertia_s * graph_density;
@ -14,75 +14,65 @@ const minutes = (units: number) => Math.floor(s(units) / 60);
const hours = (units: number) => Math.floor(units / graph_density / 60 / 60);
const formatTime = (units: number) =>
`${hours(units)}:${minutes(units)}:${Math.floor(s(units) % 60)}`;
`${hours(units)}:${minutes(units)}:${Math.floor(s(units) % 60)}`;
type Mode = { left: boolean; right: boolean };
async function run() {
const [left_breaks, right_breaks] = await Promise.all([
findLoudness(
"/tmp/leftraw",
threshold_at_point,
inertia_samples,
"left"
),
findLoudness(
"/tmp/rightraw",
threshold_at_point,
inertia_samples,
"right"
),
]);
const [left_breaks, right_breaks] = await Promise.all([
findLoudness("/tmp/leftraw", threshold_at_point, inertia_samples, "left"),
findLoudness("/tmp/rightraw", threshold_at_point, inertia_samples, "right"),
]);
const merged = [...left_breaks, ...right_breaks].sort((a, b) =>
a.position_start < b.position_start
? -1
: a.position_start > b.position_start
? 1
: 0
);
const merged = [...left_breaks, ...right_breaks].sort((a, b) =>
a.position_start < b.position_start
? -1
: a.position_start > b.position_start
? 1
: 0
);
// console.log("left breaks:", left_breaks);
// console.log(`right_breaks`, right_breaks);
// console.log(`merged`, merged);
// console.log("left breaks:", left_breaks);
// console.log(`right_breaks`, right_breaks);
// console.log(`merged`, merged);
function new_mode(m: Mode, s: SwapPoint): Mode {
return { ...m, [s.label]: s.loud };
}
function new_mode(m: Mode, s: SwapPoint): Mode {
return { ...m, [s.label]: s.loud };
}
function mode_to_string(mode: Mode) {
if (mode.left && mode.right) {
return "both";
}
for (const side of ["left", "right"]) {
if (mode[side as keyof Mode]) {
return side;
}
}
return "none";
}
function mode_to_string(mode: Mode) {
if (mode.left && mode.right) {
return "both";
}
for (const side of ["left", "right"]) {
if (mode[side as keyof Mode]) {
return side;
}
}
return "none";
}
console.log("file", `${process.cwd()}/pics/none.png`);
let last_point = 0;
let mode: Mode = { left: false, right: false };
let last_file;
let total = 0;
for (let i = 2; i < merged.length; i++) {
const point = merged[i];
mode = new_mode(mode, point);
const file = `${process.cwd()}/pics/${mode_to_string(mode)}.png`;
const duration = (point.position_start - last_point) / graph_density;
console.log(
"duration",
(point.position_start - last_point) / graph_density
);
console.log("file", file);
last_point = point.position_start;
last_file = file;
total += duration * graph_density;
}
console.log("duration", merged[merged.length - 1].duration / graph_density);
console.log("file", last_file);
console.error(total, formatTime(total));
console.log("file", `${process.cwd()}/pics/none.png`);
let last_point = 0;
let mode: Mode = { left: false, right: false };
let last_file;
let total = 0;
for (let i = 2; i < merged.length; i++) {
const point = merged[i];
mode = new_mode(mode, point);
const file = `${process.cwd()}/pics/${mode_to_string(mode)}.png`;
const duration = (point.position_start - last_point) / graph_density;
console.log(
"duration",
(point.position_start - last_point) / graph_density
);
console.log("file", file);
last_point = point.position_start;
last_file = file;
total += duration * graph_density;
}
console.log("duration", merged[merged.length - 1].duration / graph_density);
console.log("file", last_file);
console.error(total, formatTime(total));
}
run();

View File

@ -6,13 +6,14 @@
# W katalogu z tym skryptem musisz mieć katalog "pics", w którym są pliki "left.png", "right.png", "none.png" i "both.png"
#
export input=~/Downloads/icdw3/stereo-processed.wav # tutaj dajemy ścieżkę do pliku mp3 z Arkiem w jednym kanale i Kubą w drugim
export input_mono=~/Downloads/icdw3/mono-processed.wav # tutaj dajemy ścieżkę do pliku mp3 z Arkiem w jednym kanale i Kubą w drugim
export input=~/Downloads/icdw5/icdw5-stereo.wav # tutaj dajemy ścieżkę do pliku mp3 z Arkiem w jednym kanale i Kubą w drugim
export input_mono=~/Downloads/icdw5/icdw5-stereo.wav # tutaj dajemy ścieżkę do pliku mp3 z Arkiem w jednym kanale i Kubą w drugim
export intro=~/projects/midline/podcast-visualizer/out/intro.mp4 # glitch
export outro=~/projects/midline/podcast-visualizer/out/intro.mp4 # to samo na końcu, co na początku
export final_output=~/Downloads/icdw3-viz.mp4
export final_output=~/Downloads/icdw5-viz.mp4
export framerate=25
export timescale=25000
export demuxer_volume_threshold=30 #od 0 do 128
aresample=8000 # to bez zmian
mkdir -p out