AMR - 如何上采样

发布于 2024-10-20 13:20:54 字数 181 浏览 0 评论 0原文

如何对 AMR 音频数据进行上采样。 amr 文件由 6 字节标头组成 - "!#AMR".getBytes(),之后有 32 字节的帧,每个帧有 1 字节标头和 31 字节音频。我应该如何对其进行上采样?我读过有关线性插值的内容,但我不确定如何在这里应用它。 我应该在不同的帧之间或帧中的字节之间或其他内容之间进行插值吗? 任何帮助将不胜感激:)

How can I upsample AMR audio data. The amr file consists of 6 bytes header - "!#AMR".getBytes() and after that there are frames 32bytes each with 1 byte header and 31bytes audio. How am I supposed to upsample it? I read about linear interpolation but I am not sure how to apply it here.
Should I interpolate between different frames or between bytes in a frame or something else?
Any help will be highly appreciated :)

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

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

发布评论

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

评论(2

撩起发的微风 2024-10-27 13:20:54

您需要将 AMR 数据转换为原始 PCM 缓冲区,对 PCM 缓冲区进行重采样,然后可以选择转换回 AMR。

You need to convert your AMR data to a raw PCM buffer, do the resampling on the PCM buffer, and then optionally convert back to AMR.

ぃ弥猫深巷。 2024-10-27 13:20:54

将 AMR 解码为线性 PCM。然后,您可以使用 https://github.com/dataandsignal/libhdsp 对其进行上采样

hdsp_status_t hdsp_upsample_int16(int16_t *x, size_t x_len, int upsample_factor, int16_t *y, size_t y_len);

:完整的代码片段可能看起来像这个

#include "hdsp.h"

int main(int argc, char **argv) {

    #define Fs_x 8000
    #define f_x 200
    #define Fs_y 48000
    #define FRAME_LEN_MS 20
    #define X_LEN_SAMPLES (FRAME_LEN_MS * Fs_x / 1000)
    #define Y_LEN_SAMPLES (FRAME_LEN_MS * Fs_y / 1000)
    #define UPSAMPLE_FACTOR (Fs_y / Fs_x)

    int16_t x[X_LEN_SAMPLES] = {0};
    int16_t y[Y_LEN_SAMPLES] = {0};

    int i = 0;
    while (i < X_LEN_SAMPLES) {
        x[i] = 100 * sin((double)i * 2 * M_PI * f_x / Fs_x);
        printf("%d\n",x[i]);
        i = i + 1;
    }

    hdsp_test(HDSP_STATUS_OK == hdsp_upsample_int16(x, X_LEN_SAMPLES, UPSAMPLE_FACTOR, y, Y_LEN_SAMPLES), "It did not work\n");

    i = 0;
    while (i < X_LEN_SAMPLES)
    {
        int j = 0;
        while (j < UPSAMPLE_FACTOR) {
            if (j == 0) {
                hdsp_test(y[UPSAMPLE_FACTOR * i + j] == x[i], "Wrong sample");
            } else {
                hdsp_test(y[UPSAMPLE_FACTOR * i + j] == 0, "Wrong zero");
            }
            j = j + 1;
        }
        i = i + 1;
    }
    return 0;
}

这是我的一篇文章写了有关使用 libhdsp 进行上采样/下采样和过滤的文章(我是该库的作者):

https://dataandsignal .com/blog/static/audio_upsampling_downsampling_and_filtering_with_libhdsp/

Decode AMR to linear PCM. Then you can upsample it with https://github.com/dataandsignal/libhdsp this way:

hdsp_status_t hdsp_upsample_int16(int16_t *x, size_t x_len, int upsample_factor, int16_t *y, size_t y_len);

A more complete snippet may look like this:

#include "hdsp.h"

int main(int argc, char **argv) {

    #define Fs_x 8000
    #define f_x 200
    #define Fs_y 48000
    #define FRAME_LEN_MS 20
    #define X_LEN_SAMPLES (FRAME_LEN_MS * Fs_x / 1000)
    #define Y_LEN_SAMPLES (FRAME_LEN_MS * Fs_y / 1000)
    #define UPSAMPLE_FACTOR (Fs_y / Fs_x)

    int16_t x[X_LEN_SAMPLES] = {0};
    int16_t y[Y_LEN_SAMPLES] = {0};

    int i = 0;
    while (i < X_LEN_SAMPLES) {
        x[i] = 100 * sin((double)i * 2 * M_PI * f_x / Fs_x);
        printf("%d\n",x[i]);
        i = i + 1;
    }

    hdsp_test(HDSP_STATUS_OK == hdsp_upsample_int16(x, X_LEN_SAMPLES, UPSAMPLE_FACTOR, y, Y_LEN_SAMPLES), "It did not work\n");

    i = 0;
    while (i < X_LEN_SAMPLES)
    {
        int j = 0;
        while (j < UPSAMPLE_FACTOR) {
            if (j == 0) {
                hdsp_test(y[UPSAMPLE_FACTOR * i + j] == x[i], "Wrong sample");
            } else {
                hdsp_test(y[UPSAMPLE_FACTOR * i + j] == 0, "Wrong zero");
            }
            j = j + 1;
        }
        i = i + 1;
    }
    return 0;
}

Here is an article I wrote about upsampling / downsampling and filtering using libhdsp (I am author of this lib):

https://dataandsignal.com/blog/static/audio_upsampling_downsampling_and_filtering_with_libhdsp/

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