0

I've been working in a project with "Sounddevice 0.3.6" module and Python for proposing an active noise cancellation system. For this specific application, I needed to precisely output a signal with same frequency of the input signal. That is when I came across some problems with the Stream class of Sounddevice. Here is the problem:

Let's take the simple "wire.py" example given in Sounddevice's documentation.

(http://python-sounddevice.readthedocs.io/en/0.3.6/examples.html)

This routine basically gets the input and passes to the output of the stream.

By doing so, I did generate a fixed sine wave as the input to pass through. However, I get a sine wave of slightly different frequency as output. It is a small difference in frequency (~1 Hz) that I could ensure checking with an oscilloscope.

I wonder what may cause this problem, since it's a simple pass-through routine.

Fernando H'.'
  • 897
  • 1
  • 8
  • 19
  • Hmm, that's odd. Did you try different *block size*, *sample rate* and *device* settings? What OS and host API are you using? What was the original frequency of your test tone? – Matthias Jan 29 '17 at 10:02
  • I did try different block sizes, the sample rate is fixed by the usb sound card at 48 kHz, and I tried different devices. Same result for all of them. I'm using Ubuntu 16.04 and Python 3.5. The input signal is a sine wave of 250 Hz, and the output has a slightly lower frequency. I checked the frequencies with an oscilloscope. – Fernando H'.' Jan 29 '17 at 18:01
  • And you are generating the signal with an external signal generator that you also measured with the oscilloscope? This is really strange, the frequency should not change. Can you try it with JACK? Can you try it with some other software that short-circuits the inputs to the outputs? E.g. [this](http://jackclient-python.readthedocs.io/en/0.4.2/examples.html#pass-through-client) or [this](https://people.csail.mit.edu/hubert/pyaudio/#wire-example)? – Matthias Jan 29 '17 at 21:15
  • Sorry for the late reply, and thanks for the help. I tried many different softwares and got the same result. Finally, I could solve the problem using a better sound device. Of course, the cheap USB sound card was messing up the whole thing. Now I got another little problem. Is there a way I could synchronize two Streams? I need one full-duplex stream, and one input Stream for the project. The problem is that for processing the signal I need that the input of both streams are synchronized. – Fernando H'.' Feb 01 '17 at 18:18
  • OK, good to know that it works now. There is no automatic way to synchronize two streams. You would have to do this manually and take care of the necessary buffering yourself, which isn't an easy problem to solve. This would also definitely add latency. And: multiple streams are not supported for all host APIs, therefore your code wouldn't be fully portable anymore. I think the better solution would be to write your own custom callback function that takes care of all inputs and all outputs that you need. – Matthias Feb 02 '17 at 08:31

0 Answers0