python-sounddevice icon indicating copy to clipboard operation
python-sounddevice copied to clipboard

Playing through loopback adapter bad distortion

Open StuartIanNaylor opened this issue 4 years ago • 4 comments

Hi,

I grabbed your wire.py example and made a small change where during the callback I am running some code.

def callback(indata, outdata, frames, time, status):
    if status:
        print(status)
    global tail
    rear = np.hstack((tail, indata[:frames - 3, 1] *-1))
    tail = indata[frames -3:, 1] *-1
    outdata[:] = np.stack((indata[:,0], rear), axis = 1)

If I output the above to my headphones from what I can hear seems normal, but what I want to do is output to a loopback adapter to record. When I record from the loopback the distortion is terrible and can tell straight away as soon as I started I get system messages about the buffers. I am confused why playing out to a loopback should make any difference to what seems to be working headphones.

I can use a loopback that way with the wire.py example?

StuartIanNaylor avatar Dec 12 '20 11:12 StuartIanNaylor

... but what I want to do is output to a loopback adapter to record.

Why do you need a loopback adapter for recording? Why not just record the data you already have? See examples/rec_unlimited.py for how to record some data.

When I record from the loopback the distortion is terrible and can tell straight away as soon as I started I get system messages about the buffers.

What messages?

I am confused why playing out to a loopback should make any difference to what seems to be working headphones.

What loopback device are you using?

What are the max/min values of the signals you are handling?

I can use a loopback that way with the wire.py example?

I don't know, you would have to provide a bit more information about what you are using and how.

mgeier avatar Dec 13 '20 14:12 mgeier

I am grabbing the mic processing and passing through with wire.py but have a simple alg to inverse and delay the right channel by 3 samples. It plays back to a loopback so it can be used as a alsa-source once more but with the alg audio modifications.

Messages are the usual buffer ones from and strange as only when connected on a loopback.

    if status:
        print(status)

snd_aloop standard kernel module

I just don't understand why there is any difference playing to any sink but from my usb soundcard to loopback there is? Sounds perfect on the usb soundcard sink but from the source side of the loopback much distortion and not sure why as loopback is just a loopback !?!

StuartIanNaylor avatar Dec 14 '20 09:12 StuartIanNaylor

Messages are the usual buffer ones from and strange as only when connected on a loopback.

This is indeed strange. But as long as those messages appear, you should expect audible artifacts. Did you try larger block sizes and latencies?

What are the max/min values of the signals you are handling?

mgeier avatar Dec 15 '20 18:12 mgeier

No but I will and see if I can get max/min values but it may be something weird with the Pi I2S mic driver. https://github.com/opencardev/snd-i2s_rpi

As I know its MSB/LSB the wrong way round so the samples are quiet.

Thanks will get back to you.

StuartIanNaylor avatar Dec 16 '20 06:12 StuartIanNaylor