@@ -166,6 +166,16 @@ def time_frequency(
166
166
167
167
time_centers = np .mean (times , axis = 1 ) * float (fs )
168
168
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
+
169
179
# Check if there is at least one element on each frequency that has a value above the threshold
170
180
# to justify processing, for optimisation.
171
181
spectral_max_magnitudes = np .max (gram , axis = 1 )
@@ -176,26 +186,13 @@ def time_frequency(
176
186
# Get a waveform of length samples at this frequency
177
187
wave = _fast_synthesize (frequency , n_dec , fs , function , length )
178
188
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
-
192
189
# Use a two-cycle ramp to smooth over transients
193
190
period = 2 * int (fs / frequency )
194
191
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" )
196
193
197
194
# Mix the signal into the output
198
- output [:] += wave [: len (signal )] * signal
195
+ output [:] += wave [:len (signal_n )] * signal_n
199
196
200
197
# Normalize, but only if there's non-zero values
201
198
norm = np .abs (output ).max ()
0 commit comments