http://yarin.blog.51cto.com/1130898/640398
首先下载soundtouch开源库,可以到官方网站去找了,http://www.surina.net/soundtouch/。
下面我们要修改音频文件主要调整的几个函数如下了:
- mSoundTouch.setSampleRate(sampleRate);//设置声音的采样频率
- mSoundTouch.setChannels(channels);//设置声音的声道
- m_SoundTouch.setTempoChange(tempoDelta); //这个就是传说中的变速不变调
- m_SoundTouch.setPitchSemiTones(pitchDelta);//设置声音的pitch
- mSoundTouch.setRateChange(rateDelta);//设置声音的速率
- // quick是一个bool变量,USE_QUICKSEEK具体有什么用我暂时也不太清楚。
- mSoundTouch.setSetting(SETTING_USE_QUICKSEEK, quick);
- // noAntiAlias是一个bool变量,USE_AA_FILTER具体有什么用我暂时也不太清楚。
- mSoundTouch.setSetting(SETTING_USE_AA_FILTER, !(noAntiAlias));
最后需要注意的两个问题:
已开始我编译出来,声音很奇怪也有噪音很大,还是花了很多时间来找原因,但是都无果,突然想起前面我们说过,它同时支持32位浮点和16位定点,默
认时采用32位浮点的,我将其改为16位定点数的,哈哈,对了,效果很好,更改方式在STTypes.h文件中找到FLOAT_SAMPLES宏,注释
掉,并打开INTEGER_SAMPLES宏,如下:
- #if !(INTEGER_SAMPLES || 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 INTEGER_SAMPLES 1 //< 16bit integer samples
- //#define FLOAT_SAMPLES 1 //< 32bit float samples
- #endif
另外一个问题就是在模拟器上测试都完全无误了,这个时候放到真机设备上,直接报错,退出程序,又一个花了我不少时间的问题,最终发现,在真机上需要将声道改变为单声道,如下,在自己设置的时候使用:
- mSoundTouch.setChannels(2);//1则为单声道
大功告成,当然了如果你要继续了解soundtouch库,那么这里(http://blog.csdn.net/leilu2008/article/details/6540575)又一系列的参考资料。
转:在ios中使用soundtouch库实现变声,布布扣,bubuko.com
时间: 2024-10-05 05:07:17