I use portaudio in a Cpp work. My signal model treats the only 16000Hz audio input and
When the First released my work, I don't need to use 44100 sample rate. It was just about 48000Hz microphone. So I resampled my signal like 48000 -> 16000 -> 48000 with a simple decimation algorithm and linear interpolation.
But now I want to use a 44100 microphone. In real-time processing, My buffer is 256 points in 16000 Hz. So it is hard to find the input buffer size in 44100 Hz and downsample from 44100 to 16000.
When I used just decimation or average filter(https://github.com/mattdiamond/Recorderjs/issues/186), the output speech is higher then input and windowed sinc function interpolation makes a distortion.
is there any method to make 44100->16000 downsampling for realtime processing? please let me know...
thank you.
I had to implement a similar problem in the past, not for audio, but to simulate an asynchronism between a transmitte signal sampling frequency and a receiver sampling frequency.
This is how I will proceed:
Let us call
T1
the sampling time duration of the incoming signalx
:T1=1/44100
and let us callT2
the sampling time duration of the signal to be generatedy
.To calculate the value of the signal
y[n*T2]
, select the two input valuesx[k*T1]
andx[(k+1)*T2]
that surround the value to be calculated:Then perform a linear interpolation from these two values. The interpolation factor must be recalculated for each sample.
If
t = n*T2
,a = k*T1
andb = (k+1)*T2
, thenWith a 44.1kHz frequency,
x|a]
andx[a+T1]
should be rather well correlated, and the linear interpolation could be goood enough.With the obtained quality is not good enough, you can interpolate the incoming signal with a fixed interpolation ratio, for example 2, with a classical well defined good interpolation filter.
Then you can apply the previous procedure, with the help of the new calculated signal, the sampling duration of which is
T1/2
.If the incoming signal has some high frequencies, then, in order to avoid aliasing, you need to apply a low-pas filter to the incoming signal prior to the downsampling. Note that this is necessary even in your previous case 48kHz -> 16kHz