From 7b4d0677a1c1aa95a68d59d0c4286a92beb1be11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Bourdeauducq?= Date: Sat, 28 Dec 2024 19:04:35 +0800 Subject: [PATCH] average input channels --- sndlock.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/sndlock.cpp b/sndlock.cpp index 4b01291..d7983b4 100644 --- a/sndlock.cpp +++ b/sndlock.cpp @@ -14,6 +14,7 @@ #define SND_BITS 16 #define SND_PCHAN 2 +#define SND_RCHAN 2 #define SND_RATE 44100 #define SND_BUFLEN 4096 @@ -38,7 +39,7 @@ static void dsp_thread() par.sig = 1; par.bits = SND_BITS; par.pchan = SND_PCHAN; - par.rchan = 1; + par.rchan = SND_RCHAN; par.rate = SND_RATE; par.le = SIO_LE_NATIVE; par.xrun = SIO_ERROR; @@ -96,13 +97,17 @@ static void dsp_thread() } if(revents & POLLIN) { - int16_t buf_in[SND_BUFLEN]; + int16_t buf_in[SND_BUFLEN*SND_RCHAN]; size_t read = sio_read(hdl, buf_in, sizeof(buf_in)); - double scale = pow(0.5, SND_BITS-1); + // input channels are averaged together to reduce uncorrelated noise + double scale = pow(0.5, SND_BITS-1)/SND_RCHAN; for(int i=0;i rotated; - rotated = (double)buf_in[j]*std::polar(scale, phase_in[i]*2.0*M_PI/(double)UINT32_MAX); + rotated = sample*std::polar(scale, phase_in[i]*2.0*M_PI/(double)UINT32_MAX); phase_in[i] += ftw[i]; // wraps on underflow lpf_y[i] += (rotated - lpf_y[i])*lpf_k[i];