Skip to content

Commit

Permalink
Report tuning analysis progress #1
Browse files Browse the repository at this point in the history
  • Loading branch information
jurihock committed Mar 31, 2024
1 parent 13eebc5 commit 9b56b3d
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/remucs/tuning.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import numpy
import resampy
import soundfile
import tqdm

from qdft import QDFT
from qdft.fafe import QFAFE
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand All @@ -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


Expand Down

0 comments on commit 9b56b3d

Please sign in to comment.