From 9b56b3d89e04b413ce90c7f37856ee39513d0c2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ju=CC=88rgen=20Hock?= Date: Sun, 31 Mar 2024 20:52:41 +0200 Subject: [PATCH] Report tuning analysis progress #1 --- src/remucs/tuning.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/remucs/tuning.py b/src/remucs/tuning.py index 4a33b19..a2eda0b 100644 --- a/src/remucs/tuning.py +++ b/src/remucs/tuning.py @@ -6,6 +6,7 @@ import numpy import resampy import soundfile +import tqdm from qdft import QDFT from qdft.fafe import QFAFE @@ -57,6 +58,9 @@ def analyze(src: Path, opts: RemucsOptions) -> Tuple[NDArray, NDArray]: if not opts.quiet: click.echo(f'Analyzing {src.resolve()}') + progress = tqdm.tqdm(total=100) \ + if not opts.quiet else None + samplerate = 8000 x, samplerate = resample(src, samplerate) @@ -91,7 +95,7 @@ def analyze(src: Path, opts: RemucsOptions) -> Tuple[NDArray, NDArray]: estimates = numpy.zeros(len(x), float) weights = numpy.zeros(len(x), float) - for batch in batches: + for index, batch in enumerate(batches): dfts = qdft.qdft(x[batch]) magns = numpy.abs(dfts) @@ -110,12 +114,24 @@ def analyze(src: Path, opts: RemucsOptions) -> Tuple[NDArray, NDArray]: estimates[batch] = numpy.sum(freqs * b, axis=-1) / numpy.sum(c, axis=-1) weights[batch] = numpy.prod(magns, axis=-1) + if progress is not None: + + q = index / len(batches) + n = numpy.clip(numpy.ceil(100 * q), 0, 100) + m = numpy.clip(n - progress.n, 0, 100 - progress.n) + + progress.update(m) + estimates = estimates[latency:latency+oldsize] weights = weights[latency:latency+oldsize] assert numpy.all(numpy.isfinite(estimates)) assert numpy.all(numpy.isfinite(weights)) + if progress is not None: + progress.update(numpy.clip(100 - progress.n, 0, 100)) + progress.close() + return estimates, weights