基于开源库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

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

3193

被折叠的 条评论
为什么被折叠?



