@@ -133,15 +133,23 @@ def time_frequency(
133
133
f"frequencies.shape={ frequencies .shape } is incompatible with gram.shape={ gram .shape } "
134
134
)
135
135
136
+ padding = [0 , 0 ]
137
+ stacking = []
138
+
136
139
if times .min () > 0 :
137
140
# We need to pad a silence column on to gram at the beginning
138
- gram = np .pad (gram , ((0 , 0 ), (1 , 0 )), mode = "constant" )
139
- times = np .vstack (([0 , times .min ()], times ))
141
+ padding [0 ] = 1
142
+ stacking .append ([0 , times .min ()])
143
+
144
+ stacking .append (times )
140
145
141
146
if times .max () < last_time_in_secs :
142
147
# We need to pad a silence column onto gram at the end
143
- gram = np .pad (gram , ((0 , 0 ), (0 , 1 )), mode = "constant" )
144
- times = np .vstack ((times , [times .max (), last_time_in_secs ]))
148
+ padding [1 ] = 1
149
+ stacking .append ([times .max (), last_time_in_secs ])
150
+
151
+ gram = np .pad (gram , ((0 , 0 ), padding ), mode = "constant" )
152
+ times = np .vstack (stacking )
145
153
146
154
# Identify the time intervals that have some overlap with the duration
147
155
idx = np .logical_and (times [:, 1 ] >= 0 , times [:, 0 ] <= last_time_in_secs )
@@ -150,10 +158,6 @@ def time_frequency(
150
158
151
159
n_times = times .shape [0 ]
152
160
153
- # Round up to ensure that the adjusted interval last time does not diverge from length
154
- # due to a loss of precision and truncation to ints.
155
- sample_intervals = np .round (times * fs ).astype (int )
156
-
157
161
# Threshold the tfgram to remove negative values
158
162
gram = np .maximum (gram , 0 )
159
163
@@ -164,7 +168,11 @@ def time_frequency(
164
168
# the empty signal.
165
169
return output
166
170
167
- time_centers = np .mean (times , axis = 1 ) * float (fs )
171
+ # Discard frequencies below threshold
172
+ freq_keep = np .max (gram , axis = 1 ) >= threshold
173
+
174
+ gram = gram [freq_keep , :]
175
+ frequencies = frequencies [freq_keep ]
168
176
169
177
# Interpolate the values in gram over the time grid.
170
178
if n_times > 1 :
@@ -185,13 +193,7 @@ def time_frequency(
185
193
186
194
signal = interpolator (np .arange (length ))
187
195
188
- # Check if there is at least one element on each frequency that has a value above the threshold
189
- # to justify processing, for optimisation.
190
- spectral_max_magnitudes = np .max (gram , axis = 1 )
191
196
for n , frequency in enumerate (frequencies ):
192
- if spectral_max_magnitudes [n ] < threshold :
193
- continue
194
-
195
197
# Get a waveform of length samples at this frequency
196
198
wave = _fast_synthesize (frequency , n_dec , fs , function , length )
197
199
0 commit comments