@@ -187,21 +187,25 @@ def _time_slice_indices(self, time_slice, strict_slicing=True):
187
187
assert self .t_start <= t_start <= self .t_stop , 't_start is outside'
188
188
else :
189
189
t_start = max (t_start , self .t_start )
190
- # the i_start is necessary ceil
191
- i_start = int ( np .ceil ((t_start - self .t_start ).magnitude * sr .magnitude ))
192
- # this needed to get the real t_start of the first sample
193
- # because do not necessary match what is demanded
190
+ # the i_start is rounded to the nearest sample
191
+ i_start = np .rint ((t_start - self .t_start ).magnitude * sr .magnitude ). astype ( np . int64 )
192
+ # this is needed to get the real t_start of the first sample
193
+ # because it does not necessary match what is demanded
194
194
sig_t_start = self .t_start + i_start / sr
195
195
196
196
if t_stop is None :
197
197
i_stop = None
198
198
else :
199
199
t_stop = ensure_second (t_stop )
200
200
if strict_slicing :
201
- assert self .t_start <= t_stop <= self .t_stop , 't_stop is outside'
201
+ assert self .t_start <= t_stop <= self .t_stop , 't_stop is outside possible time range '
202
202
else :
203
203
t_stop = min (t_stop , self .t_stop )
204
- i_stop = int ((t_stop - self .t_start ).magnitude * sr .magnitude )
204
+ # calculate duration demanded then round it to nearest sample number
205
+ # add this to i_start to get i_stop
206
+ delta = (t_stop - t_start ) * sr
207
+ i_stop = i_start + int (np .rint (delta .simplified .magnitude ))
208
+
205
209
return i_start , i_stop , sig_t_start
206
210
207
211
def load (self , time_slice = None , strict_slicing = True ,
0 commit comments