2020-06-06 22:37:48 +02:00
|
|
|
import findLoudness, { SwapPoint } from "./find-loudness";
|
|
|
|
|
|
|
|
const graph_density = 8000;
|
2020-05-15 08:18:52 +02:00
|
|
|
|
|
|
|
const threshold_at_point = 1;
|
|
|
|
|
2020-06-06 22:37:48 +02:00
|
|
|
const inertia_s = 0.3;
|
2020-05-15 08:18:52 +02:00
|
|
|
const inertia_samples = inertia_s * graph_density;
|
|
|
|
|
2020-06-06 22:37:48 +02:00
|
|
|
const s = (n: number) => n / graph_density;
|
2020-05-15 08:18:52 +02:00
|
|
|
|
|
|
|
const minutes = (units: number) => Math.floor(s(units) / 60);
|
|
|
|
|
2020-06-06 22:37:48 +02:00
|
|
|
const hours = (units: number) => Math.floor(units / graph_density / 60 / 60);
|
|
|
|
|
2020-05-15 08:18:52 +02:00
|
|
|
const formatTime = (units: number) =>
|
2020-06-06 22:37:48 +02:00
|
|
|
`${hours(units)}:${minutes(units)}:${Math.floor(s(units) % 60)}`;
|
2020-05-15 08:18:52 +02:00
|
|
|
|
2020-06-06 22:37:48 +02:00
|
|
|
type Mode = { left: boolean; right: boolean };
|
2020-05-15 08:18:52 +02:00
|
|
|
|
2020-06-06 22:37:48 +02:00
|
|
|
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"
|
|
|
|
),
|
|
|
|
]);
|
2020-05-15 08:18:52 +02:00
|
|
|
|
2020-06-06 22:37:48 +02:00
|
|
|
const merged = [...left_breaks, ...right_breaks].sort((a, b) =>
|
|
|
|
a.position_start < b.position_start
|
|
|
|
? -1
|
|
|
|
: a.position_start > b.position_start
|
|
|
|
? 1
|
|
|
|
: 0
|
|
|
|
);
|
2020-05-15 08:18:52 +02:00
|
|
|
|
2020-06-06 22:37:48 +02:00
|
|
|
// 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 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;
|
2020-05-15 08:18:52 +02:00
|
|
|
}
|
|
|
|
}
|
2020-06-06 22:37:48 +02:00
|
|
|
return "none";
|
2020-05-15 08:18:52 +02:00
|
|
|
}
|
2020-05-15 21:48:24 +02:00
|
|
|
|
2020-06-06 22:37:48 +02:00
|
|
|
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();
|