Esempio n. 1
0
 def _get_itd(self, max_lag):
     max_lag = Sound.in_samples(max_lag, self.samplerate)
     xcorr = numpy.correlate(self.data[:, 0], self.data[:, 1], 'full')
     lags = numpy.arange(-max_lag, max_lag + 1)
     xcorr = xcorr[self.n_samples - 1 - max_lag:self.n_samples + max_lag]
     idx = numpy.argmax(xcorr)
     return lags[idx]
Esempio n. 2
0
    def itd(self, duration=600e-6):
        '''
        Returns a binaural sound object with one channel delayed with respect to the other channel by duration (*600 microseconds*), which can be the number of samples or a length of time in seconds.
        Negative dB values delay the right channel (virtual sound source moves to the left). itd requires a sound with two channels.
        >>> sig = Binaural.whitenoise()
        >>> _ = sig.itd(1)
        >>> _ = sig.itd(-0.001)

        '''
        duration = Sound.in_samples(duration, self.samplerate)
        new = copy.deepcopy(self)  # so that we can return a new signal
        if duration == 0:
            return new  # nothing needs to be shifted
        if duration < 0:  # negative itds by convention shift to the left (i.e. delay right channel)
            channel = 1  # right
        else:
            channel = 0  # left
        new.delay(duration=abs(duration), chan=channel)
        return new