迅雷Aplayer集成soundtouch做变调,爆音

早知今日何必当猪 2017-05-26 12:33:19
本来想用迅雷Aplayer(http://aplayer.open.xunlei.com/)的插件系统写一个变调插件,结果在转换位数哪里怎么也弄不对,主要原因是一个是char类型的,一个是float类型的,也不知道哪里还有错误,改了两天,结果不是爆音就是无声,反正调没变。

struct AUDIO_FRAME_INFO //这个是调用时传入的结构体,里面有些东西不知道什么意思,
//这些英文表述不是很清楚,官方又没说明
{
int channel; //声道?
int bit_per_sample; //比特率?
BOOL is_float; //?
int sample_count; //?
BYTE * frame; //这个是单声道数据还是所有声道数据?
__int64 time_stamp; //?
};
float *Convert16BitToFloat(BYTE *input, int *inputSamples)
{
*inputSamples = *inputSamples / 2; // 16 bit input, so 2 bytes per sample
float *output = new float[*inputSamples];
int outputIndex = 0;
for (int n = 0; n < *inputSamples; n++)
{
short sample = input[n * 2] | (input[n * 2 + 1] << 8);
output[outputIndex++] = sample / 32768.0f;
}
return output;
}
float *Convert24BitToFloat(BYTE *input, int *inputSamples)
{
*inputSamples = *inputSamples / 3; // 24 bit input
float *output = new float[*inputSamples];
int outputIndex = 0;
for (int n = 0; n < *inputSamples; n++)
{
// copy 3 bytes in
int sample = input[n * 3] | (input[n * 3 + 1] << 8) | (input[n * 3 + 2] << 16 | 0x0 << 24);
output[outputIndex++] = sample / 16777216.0f;
}
return output;
}
EXPORT_FUNCTION void APlayerPluginAudioFrame(AUDIO_FRAME_INFO * pFrame)
{
//g_nAudioFrameCount++;
//UpdateUI();

HANDLE mSoundTouch = soundtouch_createInstance();//初始化对象
soundtouch_setChannels(mSoundTouch,1);//设置声道
soundtouch_setSampleRate(mSoundTouch, pFrame->bit_per_sample);//设置采样频率
soundtouch_setPitchSemiTones(mSoundTouch, 10);//设置音调


// 将解码后的buffer(uint8*)转换为soundtouch::SAMPLETYPE,也就是singed int 16
auto len = pFrame->sample_count * pFrame->bit_per_sample;
float *touch_buffer = Convert24BitToFloat(pFrame->frame, &len);//这里不知道是24位
// 还是16位
soundtouch_putSamples(mSoundTouch, touch_buffer, len);
int receiveCount = 0;
int pcm_data_size = 0;
do
{
// 接收处理后的sample
receiveCount = soundtouch_receiveSamples(mSoundTouch, touch_buffer, len);
for (int i = 0; i < receiveCount; i++)//网上找到,不知道写对没有,原来是*2的结果转
//完还原时这样就少了一半,很奇怪
{
// adjust volume
float sample32 = touch_buffer[receiveCount] * 1;
// clip
if (sample32 > 1.0f)
sample32 = 1.0f;
if (sample32 < -1.0f)
sample32 = -1.0f;
pFrame->frame[pcm_data_size] = (short)(sample32 * 32767);
pcm_data_size++;
}
} while (receiveCount != 0);
soundtouch_flush(mSoundTouch);
do
{
// 接收处理后的sample
receiveCount = soundtouch_receiveSamples(mSoundTouch, touch_buffer, len);
for (int i = 0; i < receiveCount; i++)//和上面一样少了一半
{
// adjust volume
float sample32 = touch_buffer[receiveCount] * 1;
// clip
if (sample32 > 1.0f)
sample32 = 1.0f;
if (sample32 < -1.0f)
sample32 = -1.0f;
pFrame->frame[pcm_data_size] = (short)(sample32 * 32767);
pcm_data_size++;
}
} while (receiveCount != 0);
pFrame->sample_count = pcm_data_size / pFrame->bit_per_sample;
delete[](touch_buffer);
}
...全文
412 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

2,543

社区成员

发帖
与我相关
我的任务
社区描述
专题开发/技术/项目 多媒体/流媒体开发
社区管理员
  • 多媒体/流媒体开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧