简易重采样resampler的实现

本文介绍如何利用开源库speexdsp在CentOS和Windows环境下实现音频文件的重采样。通过示例代码展示了如何读取输入音频文件,调整采样率,并将处理后的音频写入新的输出文件。

基于开源库speexdsp, 可以简单实现重采样。

 

简单实现的代码如下:

需要的三方库: speexdsp ,libsndfile

#include <stdlib.h>
#include <sndfile.h>
#include <speex_resampler.h>

#define BUFFER_SIZE 2048

int main(int argv, const char *args[]) {
    if (argv != 4) {
        printf("usage: %s <input file path> <to samplerate> <output file path> \n", args[0]);
        return 1;
    }

    const char *in_path = args[1];

    int output_sr = atoi(args[2]);
    const char *out_path = args[3];

    SF_INFO info;
    SNDFILE *in = sf_open(in_path, SFM_READ, &info);
    if (!in) {
        fprintf(stderr, "cannot open file %s\n", in_path);
        return 2;
    }
    SF_INFO onfo;
    onfo.channels = 1;
    onfo.samplerate = output_sr;
    onfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16 ;
    onfo.sections = 0;
    onfo.seekable = 1;
    SNDFILE *out = sf_open(out_path, SFM_WRITE, &onfo);
    if (!out) {
        fprintf(std
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值