文章目录
一、SoundTouch音频处理库的编译
soundtouch项目官网 https://www.surina.net/soundtouch/
SoundTouch git repository: https://codeberg.org/soundtouch/soundtouch.git
windows版本编译步骤
克隆项目代码
工具:git visiual studio 2019
// 下载源码 当前版本 2.3.1
git clone https://codeberg.org/soundtouch/soundtouch.git
修改soundtouch\include\STTypes.h下的宏定义
注意:默认是使用32bit float samples,需要更改成使用16bit integer samples
#if !(SOUNDTOUCH_INTEGER_SAMPLES || SOUNDTOUCH_FLOAT_SAMPLES)
/// Choose either 32bit floating point or 16bit integer sampletype
/// by choosing one of the following defines, unless this selection
/// has already been done in some other file.
////
/// Notes:
/// - In Windows environment, choose the sample format with the
/// following defines.
/// - In GNU environment, the floating point samples are used by
/// default, but integer samples can be chosen by giving the
/// following switch to the configure script:
/// ./configure --enable-integer-samples
/// However, if you still prefer to select the sample format here
/// also in GNU environment, then please #undef the INTEGER_SAMPLE
/// and FLOAT_SAMPLE defines first as in comments above.
#define SOUNDTOUCH_INTEGER_SAMPLES 1 //< 16bit integer samples
//#define SOUNDTOUCH_FLOAT_SAMPLES 1 //< 32bit float samples
#endif
vs2019编译soundtouch静态库和动态库
打开vs命令行工具 Developer Command Prompt for VS 2019
切换到源码路径执行命令 make-win.bat
生成的静态库动态库在 lib文件夹下面
vs解决方案在: soundtouch\source\SoundTouch\SoundTouch.sln
二、封装soundtouch库变速接口
对soundtouch库进行c风格api封装,提供变速接口给ffplay调用
头文件:soundtouch_wrap.h
#ifndef IJKSOUNDTOUCHWRAP_H
#define IJKSOUNDTOUCHWRAP_H
#include <stdint.h>
void* soundtouch_create();
int soundtouch_translate(void *handle, short* data, float speed, float pitch,
int len, int bytes_per_sample, int n_channel, int n_sampleRate);
void soundtouch_destroy(void *handle);
#endif /* IJKSOUNDTOUCHWRAP_H */
实现文件:soundtouch_wrap.cpp
#include "SoundTouch.h"
using namespace std;
using namespace soundtouch;
void* soundtouch_create()
{
SoundTouch *handle_ptr = new SoundTouch();
const char *version = handle_ptr->getVersionString();
return handle_ptr;
}
int soundtouch_translate(void *handle, short* data, float speed, float pitch,
int len, int bytes_per_sample, int n_channel, int n_sampleRate)
{
SoundTouch *handle_ptr = (SoundTouch*)handle;
int put_n_sample = len / n_channel;
int nb = 0;
int pcm_data_size = 0;
if (handle_ptr == NULL)
return 0;
handle_ptr->setPitch(pitch);
handle_ptr->setRate(speed);
handle_ptr->setSampleRate(n_sampleRate);
handle_ptr->setChannels(n_channel);
handle_ptr->putSamples((SAMPLETYPE*)data, put_n_sample);
do {
nb = handle_ptr->receiveSamples((SAMPLETYPE*)data, n_sampleRate / n_channel);
pcm_data_size += nb * n_channel * bytes_per_sample

本文介绍如何使用SoundTouch音频处理库为FFmpeg项目中的ffplay添加倍速播放功能,包括SoundTouch库的编译、C风格API封装及ffplay中的集成应用。
最低0.47元/天 解锁文章
2581

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



