重新采样数字声音信号

信息处理 重采样 数字滤波器
2022-02-03 20:33:31

作为非数学专业人士,我正在寻找一些指示。

我正在我的模拟器中重写音频核心以提高准确性,并且有点卡在技术的细节上。

我正在尝试以 223,807.5 Hz 的采样率(来自模拟的 Yamaha SN76489)重新采样 4,466 个样本的样本缓冲区,以 44,100 Hz 的采样率重新采样 880 个样本的样本缓冲区,然后可以输出到声音卡片。

现在据我了解,由于 44,100 和 223,807.5 Hz 之间的比率为 5.075,我需要将其转换为分数,计算结果为 203/40,然后按分母进行插值(中间保留 0 个样本),运行低-通过滤波器,然后按分子抽取,给我 880 个 44,100 Hz 输出的样本。

(1)我在这里走对了吗?在我只是直接 5 下采样(即每 5 个样本中漏掉 4 个)之前,虽然它工作得很好,但在某些游戏中,一些音符略微失调,并且存在混叠。这种新方法正确吗?

(2) 另外,我不确定在低通滤波器方面会有什么作用。我在 wikipedia 上发现了以下伪代码,似乎符合要求:

    // Return RC low-pass filter output samples, given input samples,
    // time interval dt, and time constant RC
    function lowpass(real[0..n] x, real dt, real RC)
       var real[0..n] y
       var real α := dt / (RC + dt)
       y[0] := x[0]
       for i from 1 to n
           y[i] := α * x[i] + (1-α) * y[i-1]
       return y

但我不知道如何获得 RC 和 dt - 这些与我希望实现的过滤器有什么关系?由于我不知道如何在这里选择合适的值,所以目前输出信号严重乱码。如果有更好/更容易理解的公式可用,那么一定要建议它。抱歉这个新手问题,我希望这是适合它的地方。谢谢 :-)

2个回答

您可以使用这种方法,前提是它不会产生效率负担。

% Note that matlab arrays start from index 1, not 0.
F1 = 223807.5;     % Sampling rate of Yamaha chip
F2 = 44100;        % New sampling rate of standard Audio-CD
M = 203;           % Necessary Decimation ratio
N = 40;            % necessary Expansion ratio
Lx = 4466;         % Length of Audio Input Buffer at F1 rate
Ly = Lx*N/M;       % Length of Resampled Output Buffer at F2 rate


x = sin(2*pi*1234*[0:Lx-1]/F1);  % Just a test sine wave
y = zeros(1,Ly);                 % allocate output signal memory

for i=0:Ly-1              % run per each output sample
   n = i*(M/N);          % compute exact sampling position inside the long buffer 
   ind = floor(n);       % convert it into largest integer smaller than itself for array indexing
   d = n-ind;            % take the difference for proportional weighting
   y(i+1) = (1-d)*x(ind+1) + d*x(ind+2); % sum the weighted mixture.
end

figure,plot(x);            %plot each waveforms...
figure,plot(y);

对于如此大的整数的比率,您最好使用高质量的插值器直接在采样点处插值以获得新的采样率,而不是先上采样然后再下采样。合适宽度的窗口化 Sinc 插值内核可以包括它自己的 anti-alas 低通滤波器。