Ejemplo n.º 1
0
    def run(self):
        self.done = False
        while not self.done:
            data = self.queue.get()
            data = np.fromstring(data, dtype='int16')
            offsets = [0] * self.channels
            for i in range(1, self.channels):
                offsets[i], _ = gcc_phat(data[i::self.channels],
                                         data[0::self.channels],
                                         max_tau=self.max_offset,
                                         interp=1)

            self.sum.fill(0)
            half = int(self.frames_size / 2)
            for i in range(self.channels):
                offset = int(offsets[i])
                self.sum[:half -
                         offset] += (self.last[i::self.channels])[half +
                                                                  offset:]
                self.sum[half - offset:] += (data[i::self.channels])[:half +
                                                                     offset]

            self.last = data

            out = np.array(self.sum / self.channels, dtype='int16')
            super(DelaySum, self).put(out.tostring())
    def get_direction(self):
        buf = b''.join(self.queue)
        buf = np.fromstring(buf, dtype='int16')
        tau, _ = gcc_phat(buf[0::8],
                          buf[3::8],
                          fs=self.sample_rate,
                          max_tau=MAX_TDOA,
                          interp=4)
        theta = np.arcsin(tau / MAX_TDOA) * 180 / np.pi

        return theta
    def get_direction(self):
        tau = [0, 0, 0]
        theta = [0, 0, 0]

        buf = b''.join(self.queue)
        buf = np.fromstring(buf, dtype='int16')
        for i, v in enumerate(self.pair):
            tau[i], _ = gcc_phat(buf[v[0]::8], buf[v[1]::8], fs=self.sample_rate, max_tau=MAX_TDOA_6,
                                 interp=1)
            theta[i] = np.arcsin(tau[i] / MAX_TDOA_6) * 180 / np.pi

        min_index = np.argmin(np.abs(tau))
        if (min_index != 0 and theta[min_index - 1] >= 0) or (min_index == 0 and theta[len(self.pair) - 1] < 0):
            best_guess = (theta[min_index] + 360) % 360
        else:
            best_guess = (180 - theta[min_index])

        best_guess = (best_guess + 30 + min_index * 60) % 360

        return best_guess