• 4266阅读
  • 0回复

Aplayer怎么用SoundTouch对音频实时变调? [复制链接]

上一主题 下一主题
离线xyc0714
 

只看楼主 倒序阅读 使用道具 楼主  发表于: 2017-05-26
  1. EXPORT_FUNCTION void APlayerPluginAudioFrame(AUDIO_FRAME_INFO * pFrame)
  2. {
  3.     HANDLE mSoundTouch = soundtouch_createInstance();//初始化对象
  4.     soundtouch_setChannels(mSoundTouch,1);//设置声道
  5.     soundtouch_setSampleRate(mSoundTouch, pFrame->bit_per_sample);//设置采样频率
  6.     soundtouch_setPitchSemiTones(mSoundTouch, 10);//设置音调
  7.             auto len = pFrame->sample_count * pFrame->bit_per_sample;
  8.     float *touch_buffer = new float[len];
  9.     for (int i = 0; i < len; i++)
  10.     {
  11.         touch_buffer[i] = (short)((pFrame->frame[i] + 0x80) << 8); //这里不知道怎么写
  12.     }
  13.     soundtouch_putSamples(mSoundTouch, touch_buffer, len);
  14.     int receiveCount = 0;
  15.     int pcm_data_size = 0;
  16.     do
  17.     {
  18.         // 接收处理后的sample
  19.         receiveCount = soundtouch_receiveSamples(mSoundTouch, touch_buffer, len);
  20.         for (int i = 0; i < receiveCount; i++)
  21.         {
  22.             pFrame->frame[pcm_data_size] = (BYTE)(((short)touch_buffer[i] >> 8) - 0x80);//这里不知道怎么写
  23.             pcm_data_size++;
  24.         }
  25.     } while (receiveCount != 0);
  26.     soundtouch_flush(mSoundTouch);
  27.     do
  28.     {
  29.         // 接收处理后的sample
  30.         receiveCount = soundtouch_receiveSamples(mSoundTouch, touch_buffer, len);
  31.         for (int i = 0; i < receiveCount; i++)
  32.         {
  33.             pFrame->frame[pcm_data_size] = (BYTE)(((short)touch_buffer[i] >> 8) - 0x80);//这里不知道怎么写
  34.             pcm_data_size++;
  35.         }
  36.     } while (receiveCount != 0);
  37.     pFrame->sample_count = pcm_data_size / pFrame->bit_per_sample;
  38.     delete[](touch_buffer);
  39. }


Aplayer插件的导出函数输出的数据是一个char型8位数据,而SoundTouch要的是16位的float型的音频数据,两者不兼容,不但调没变,还搞出一堆杂音,不知如何处理。
快速回复
限100 字节
如果您提交过一次失败了,可以用”恢复数据”来恢复帖子内容
 
上一个 下一个