Skip to content

Commit 29a8736

Browse files
committed
optimizations on tf sonification again
1 parent 249c783 commit 29a8736

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

mir_eval/sonify.py

+12-15
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,16 @@ def time_frequency(
166166

167167
time_centers = np.mean(times, axis=1) * float(fs)
168168

169+
# Interpolate the values in gram over the time grid.
170+
gram_interpolator = interp1d(
171+
times[:, 0] * fs,
172+
gram[:, :n_times],
173+
kind="previous",
174+
bounds_error=False,
175+
fill_value=(gram[:, 0], gram[:, -1]),
176+
)
177+
signal = gram_interpolator(np.arange(length))
178+
169179
# Check if there is at least one element on each frequency that has a value above the threshold
170180
# to justify processing, for optimisation.
171181
spectral_max_magnitudes = np.max(gram, axis=1)
@@ -176,26 +186,13 @@ def time_frequency(
176186
# Get a waveform of length samples at this frequency
177187
wave = _fast_synthesize(frequency, n_dec, fs, function, length)
178188

179-
# Interpolate the values in gram over the time grid.
180-
gram_interpolator = interp1d(
181-
times[:, 0] * fs,
182-
gram[n, :n_times],
183-
kind="previous",
184-
bounds_error=False,
185-
fill_value=(gram[n, 0], gram[n, -1]),
186-
)
187-
188-
# Create the time-varying scaling for the entire time interval by the piano roll
189-
# magnitude and add to the accumulating waveform.
190-
signal = gram_interpolator(np.arange(0, length))
191-
192189
# Use a two-cycle ramp to smooth over transients
193190
period = 2 * int(fs / frequency)
194191
filter = np.ones(period) / period
195-
signal = scipy.signal.convolve(signal, filter, mode="same")
192+
signal_n = scipy.signal.convolve(signal[n], filter, mode="same")
196193

197194
# Mix the signal into the output
198-
output[:] += wave[: len(signal)] * signal
195+
output[:] += wave[:len(signal_n)] * signal_n
199196

200197
# Normalize, but only if there's non-zero values
201198
norm = np.abs(output).max()

0 commit comments

Comments
 (0)