Skip to content

Commit

Permalink
Fix qdft latency handling #1
Browse files Browse the repository at this point in the history
  • Loading branch information
jurihock committed Mar 31, 2024
1 parent c716d3d commit 6c74393
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
22 changes: 14 additions & 8 deletions src/remucs/tuning.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,29 @@ def analyze(src: Path, opts: RemucsOptions) -> Tuple[NDArray, NDArray]:
x, sr = soundfile.read(src)
x = numpy.atleast_2d(x).mean(axis=-1)

oldsize = len(x)
newsize = int(numpy.ceil(oldsize / sr) * sr)
x.resize(newsize)

scale = Scale(440)
bandwidth = (scale.frequency('A0'), scale.frequency('C#8'))
resolution = 12*4

qdft = QDFT(samplerate=sr, bandwidth=bandwidth, resolution=resolution)
fafe = QFAFE(qdft)

# use qdft.latencies in the next qdft release
latency = int(numpy.max(qdft.periods[0] - qdft.offsets))

oldsize = len(x)
newsize = int(numpy.ceil((latency + oldsize) / sr) * sr)

assert oldsize > latency
x.resize(newsize)

batches = numpy.arange(len(x)).reshape((-1, sr))
estimates = numpy.full(len(x), 440, float)
weights = numpy.zeros(len(x), float)

numpeaks = 3
kernel = 1 # int(100e-3 * sr)

# use qdft.latencies in the next qdft release
roi = [int(numpy.max(qdft.periods[0] - qdft.offsets)), oldsize - 1]
roi = [latency, oldsize - 1]

for batch in batches:

Expand Down Expand Up @@ -89,4 +92,7 @@ def analyze(src: Path, opts: RemucsOptions) -> Tuple[NDArray, NDArray]:
estimates[batch[n]] = estimate
weights[batch[n]] = numpy.prod(magns[n, m])

return estimates[:oldsize], weights[:oldsize]
estimates = estimates[latency:latency+oldsize]
weights = weights[latency:latency+oldsize]

return estimates, weights
1 change: 0 additions & 1 deletion src/sandbox/tuning.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def main():
sr = soundfile.info(test).samplerate

cp2, weights = analyze(test, RemucsOptions())

weights /= np.max(np.abs(weights))

values = np.round(cp2).astype(int)
Expand Down

0 comments on commit 6c74393

Please sign in to comment.