How to use the sounddevice.playrec function in sounddevice

To help you get started, we’ve selected a few sounddevice examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github LCAV / FRIDA / experiment / play_sweeps.py View on Github external
# Create multichannel signal
    signal = np.zeros((sd.default.channels[0]*sweep.shape[0], sd.default.channels[0]))

    compactsix_server = AudioGetter("192.168.2.11:8888", sd.default.channels[0]*T+1, fs=fs, channels=6)
    compactsix_server.start()

    # Play the sweep on each channel
    for ch in range(sd.default.channels[0]):
        s = ch*sweep.shape[0]
        e = (ch+1)*sweep.shape[0]

        signal[s:e,ch] = sweep


    data_in = sd.playrec(signal, fs, blocking=True)

    compactsix_server.join()
github LCAV / pyroomacoustics / pyroomacoustics / experimental / measure_ir.py View on Github external
channels_input_mapping = [1]
    if channels_output_mapping is None:
        channels_output_mapping = [1]
    if dev_in is not None:
        sd.default.device[0] = dev_in
    if dev_out is not None:
        sd.default.device[1] = dev_out

    # repeat if we need to play in multiple channels
    if len(channels_output_mapping) > 1:
        play_signal = np.tile(test_signal[:, np.newaxis], 
                              (1, len(channels_output_mapping)))
    else:
        play_signal = test_signal

    recorded_signal = sd.playrec(
            test_signal, samplerate=fs, 
            input_mapping=channels_input_mapping,
            output_mapping=channels_output_mapping,
            blocking=True
            )

    h = None
    if deconvolution:
        h = np.array(
                [wiener_deconvolve(recorded_signal[:,c], sweep) 
                for c in range(len(channels_input_mapping))]
                ).T

    if plot:
        import matplotlib.pyplot as plt
github LCAV / pyroomacoustics / pyroomacoustics / experimental / delay_calibration.py View on Github external
s = np.zeros((mls.shape[0] + int(self.pad_time*self.fs), sd.default.channels[1]), dtype=np.float32)

        # placeholder for delays
        delays = np.zeros((sd.default.channels[0], len(ch_out)))

        try:
            import matplotlib.pyplot as plt
        except ImportError:
            import warnings
            warnings.warn('Matplotlib is required for plotting')
            return

        for och in ch_out:
            # play and record the signal simultaneously
            s[:mls.shape[0], och] = 0.1 * mls
            rec_sig = sd.playrec(s, self.fs, channels=sd.default.channels[0], blocking=True)
            s[:,och] = 0

            for ich in range(rec_sig.shape[1]):
                xcorr = signal.correlate(rec_sig[:,ich], mls, mode='valid')
                delays[ich,och] = np.argmax(xcorr)
                plt.plot(xcorr)
                plt.show()

        # subtract distance
        delays -= int(distance / self.c * self.fs)

        return delays