用于上采样的 PCM 算法

发布于 2024-10-25 22:48:08 字数 137 浏览 5 评论 0原文

我有 8k16 位 pcm 音频,我想将其上采样到 16k16 位。我必须手动执行此操作。

有人可以告诉我线性插值的算法吗?我应该在每两个字节之间插入吗?

另外,当我上采样时,我必须对 wav 标头进行更改 - 我应该更改什么?

I have 8k16bit pcm audio and I want to upsample it to 16k16bit. I have to do this manually.

Can someone tell me the algorithm for linear interpolation? Should I interpolate between each two bytes?

Also when I upsample i have to make changes for the wav header - what should I change?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

﹎☆浅夏丿初晴 2024-11-01 22:48:08

正如其他人提到的,线性插值并不能提供最好的音质,但它简单且便宜。

对于您创建的每个新样本,只需将其与下一个样本进行平均,例如,

short[] source = ...;
short[] result = new short[source.length * 2];
for(int i = 0; i < source.length; ++i) {
  result[i * 2] = source[i];
  result[i * 2 + 1] = (source[i] + source[i + 1]) / 2;
}

您绝对应该搜索可以帮助您处理 WAV 文件的库。尽管它是一种简单的格式,但如果有可用的代码可以满足您的需要,您就不必自己执行此操作。顺便问一下,你为什么要这样做?也许您可以使用 sox 或类似的工具来完成此操作。

As others have mentioned, linear interpolation doesn't give the best sound quality, but it's simple and cheap.

For each new sample you create, just average it with the next one, e.g.

short[] source = ...;
short[] result = new short[source.length * 2];
for(int i = 0; i < source.length; ++i) {
  result[i * 2] = source[i];
  result[i * 2 + 1] = (source[i] + source[i + 1]) / 2;
}

You should definitely search for a library that helps you with working with WAV files. Even though it's a simple format, you shouldn't have to do that yourself if there's code available that will do what you need. By the way, why are you doing this in the first place? Perhaps you could just use sox or a similar tool to do this.

胡大本事 2024-11-01 22:48:08

有人可以告诉我线性插值的算法吗?我应该在每两个字节之间插入吗?

当然:

double interpolate_linear(double a, double b, double x) {
    assert(0.0 <= x);
    assert(1.0 >= x);

    if (0.0 >= x)
        return a;
    else if (1.0 <= x)
        return b;
    else
        return (1.0 - x) * a + x * b;
}

线性插值虽然总比没有好,但误差很大。如果你有足够的CPU时间,最好将零填充和窗口设置为零。

此外,当我进行上采样时,我必须对 wav 标头进行更改 - 我应该更改什么?

不确定java。

Can someone tell me the algorithm for linear interpolation? Should I interpolate between each two bytes?

sure:

double interpolate_linear(double a, double b, double x) {
    assert(0.0 <= x);
    assert(1.0 >= x);

    if (0.0 >= x)
        return a;
    else if (1.0 <= x)
        return b;
    else
        return (1.0 - x) * a + x * b;
}

linear interpolation, while better than nothing, has a high amount of error. it's better to zero fill and window if you have the cpu time.

Also when I upsample i have to make changes for the wav header - what should I change?

not sure for java.

榕城若虚 2024-11-01 22:48:08

这是在 java 中使用 WAV 文件的一个很好的链接:

http://www.labbookpages.co .uk/audio/javaWavFiles.html

Here's a good link to working with WAV files in java:

http://www.labbookpages.co.uk/audio/javaWavFiles.html

走过海棠暮 2024-11-01 22:48:08

不确定标题,但我会研究三次样条插值。您可以查看此网站。它有一种非常巧妙的方法来执行三次插值。我不确定如何修改标头,但我很确定 Stack Overflow 上已经有您可以搜索的答案。

Not sure about the header, but I would look into cubic spline interpolation. You could look at this website. It's got a very neat way of performing cubic interpolation. I'm not sure how to modify the header, but I'm pretty sure there have been answers to that on Stack Overflow that you could search for.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文