女儿:爸爸,最近我在练英语听力,可是学校发的听力课文说的太快了,我听不懂,能让听力语音说慢点吗?
爸爸:嗯… 这个容易,马上给你做一个。
<思路>
- 调节节拍(tempo)可实现减速或加速播放,同时声音不变调。
- 先做一个实时播放的路由,实时调节节拍(tempo),当女儿觉得节拍速度OK了,把这个节拍的参数记住,再做一个文件到文件的转换路由,并应用此节拍参数。
- 因为soudtouch只吃float数据,听力材料是signed 16bit integer格式,所以在其前加一个格式转换器。
<代码实现>
在MyEngineerDaddy_3.cpp
的基础上做简单修改,变成MyEngineerDaddy_4-1.cpp
:
#include <lark/lark.h>
#include <klogging.h>
#if defined(__APPLE__)
#define SUFIX ".dylib"
#elif defined(_WIN32)
#define SUFIX ".dll"
#else
#define SUFIX ".so"
#endif
int main()
{
const unsigned int rate = 44100;
const lark::SampleFormat format = lark::SampleFormat::S16_LE;
const unsigned int chNum = 1;
const unsigned int frameDuration_ms = 20;
const lark::samples_t frameSizeInSamples = frameDuration_ms * rate / 1000;
// Create the playback route named RouteA
lark::Route *playbackRoute = lark::Lark::Instance().NewRoute("RouteA");
if (!playbackRoute) {
KLOGE("Failed to create playbackRoute");
return -1;
}
// Create RouteA's blocks
const char *soFileName = "libblkfilereader" SUFIX;
lark::Parameters args;
args.push_back("./english_listening_material-44100Hz-S16_LE-1ch.pcm");
lark::Block *blkFileReader = playbackRoute->NewBlock(soFileName, true, false, args);
if (!blkFileReader) {
KLOGE("Failed to new a block from %s", soFileName);
return -1;
}
soFileName = "libblkformatadapter" SUFIX;
lark::Block *blkFormatAdapter0 = playbackRoute->NewBlock(soFileName, false, false);
if (!blkFormatAdapter0) {
KLOGE("Failed to new a block from %s", soFileName);
return -1;
}
soFileName = "libblksoundtouch" SUFIX;
lark::Block *blkSoundTouch = playbackRoute->NewBlock(soFileName, false, false);
if (!blkSoundTouch) {
KLOGE("Failed to new a block from %s", soFileName);