您目前如何使用 SoundTouch?您是否在阅读音频样本时将它们传递到 SoundTouch 库?或者您是否生成 soundstretch 实用程序并将音频作为文件或通过管道传递?
我不熟悉 SoundTouch,但它看起来需要 PCM 音频作为输入,所以您可能已经转换为 PCM。如果您想在收到音频样本时将它们传递给 SoundTouch,您可以使用 FAAC 使用类似这样的方式进行解码
#include <stdio.h>
#include <inttypes.h>
#include <faac.h>
#include <neaacdec.h>
#define SAMPLE_SIZE 2 //2 bytes, or 16bits per samle.
int AACDecode(uint8_t *aacData, size_t aacBytes, uint32_t sampleRate, unsigned char channels)
{
NeAACDecHandle decoder = NeAACDecOpen();
NeAACDecConfigurationPtr config = NeAACDecGetCurrentConfiguration(decoder);
NeAACDecFrameInfo info;
uint8_t *decoded = NULL;
uint8_t *readPtr = aacData;
int consumed = 0;
//If the AAC data is wrapped in ADTS, you don't need the next 2 lines
//If it's not wrapped in ADTS, you need to know sampleRate, and object type
//Object type is one of LOW, MAIN, SSR, LTP
config->defObjectType = LOW;
config->defSampleRate = sampleRate;
//If SoundTouch wants it in something other than siged 16bit LE PCM, change this
config->outputFormat = FAAD_FMT_16BIT;
if (!NeAACDecSetConfiguration(decoder, config))
{
printf("unable to set config\n");
return 0;
}
if (NeAACDecInit(decoder, (unsigned char *)aacData, aacBytes, &sampleRate, &channels) < 0)
{
printf("unable to init\n");
return 0;
}
do
{
decoded = (char *)NeAACDecDecode(decoder, &info, readPtr, aacBytes);
if (info.samples > 0)
{
size_t decodedBytes = (size_t)info.samples * SAMPLE_SIZE;
//Pass <decodedBytes> of PCM data, pointed to by <decoded> to soundTouch
}
consumed += info.bytesconsumed;
readPtr += info.bytesconsumed;
} while (info.error == 0 && consumed < aacBytes);
NeAACDecClose(decoder);
return 1;
}
您需要链接到 FAAD 库
或者,如果您要使用命令行路线,可能是这样的:
ffmpeg -i <input_file> raw.wav
然后可以将 raw.wav 传递给 soundstretch