acmStreamConvert

inline BOOL CAudioChannel::ConvertPCMData(unsigned char * Srcdata, unsigned char * Dstdata, WAVEFORMATEX wfSrc, WAVEFORMATEX wfDsc,
            DWORD hadID, DWORD dwSize, long& DestLength)
{
 IVS_LOG(LOG_INFO, "Start conver PCM data.");

 HACMDRIVERID hadid = (HACMDRIVERID)hadID;

 //源音频格式
 wfSrc.cbSize = 0;
 wfSrc.wFormatTag = wfSrc.wFormatTag;
 wfSrc.nChannels = wfSrc.nChannels;
 wfSrc.nSamplesPerSec = wfSrc.nSamplesPerSec;
 wfSrc.wBitsPerSample = wfSrc.wBitsPerSample;
 wfSrc.nBlockAlign = wfSrc.nBlockAlign;
 wfSrc.nAvgBytesPerSec = wfSrc.nAvgBytesPerSec;

 // convert the intermediate PCM format to the final format
 HACMDRIVER had = NULL;
 MMRESULT mmr;
 mmr = acmDriverOpen(&had, hadid, 0);
 if (mmr)
 {
  IVS_LOG(LOG_ERR,"Convert PCM data fail,acmDriverOpen fail.");
  return FALSE;
 }
 
 HACMSTREAM hstr;
 mmr = acmStreamOpen(&hstr,NULL, &wfSrc, &wfDsc, NULL, NULL, 0, ACM_STREAMOPENF_NONREALTIME);
 if (mmr)
 {
  IVS_LOG(LOG_ERR, "acmStreamOpen fail.");
  acmDriverClose(had, 0);
  return FALSE;
 }
 
 ACMSTREAMHEADER strhdr;
 memset(&strhdr, 0, sizeof(strhdr));
 strhdr.cbStruct = sizeof(strhdr);
 strhdr.pbSrc = Srcdata;
 strhdr.cbSrcLength = dwSize;
 strhdr.pbDst = Dstdata;
 strhdr.cbDstLength = dwSize;

 mmr = acmStreamPrepareHeader(hstr, &strhdr, 0);
 if (mmr)
 {
  IVS_LOG(LOG_ERR, "Failed to do PCM to driver format conversion.");
  acmStreamClose(hstr, 0);
     acmDriverClose(had, 0);
  return FALSE;
 }

 mmr = acmStreamConvert(hstr, &strhdr, 0);
 if (mmr)
 {
  IVS_LOG(LOG_ERR,"Failed to do PCM to driver format conversion.");
  acmStreamUnprepareHeader(hstr,&strhdr,0);
  acmStreamClose(hstr, 0);
  acmDriverClose(had, 0);
  return FALSE;
 }

 DestLength = (long)strhdr.cbDstLengthUsed;
 acmStreamUnprepareHeader(hstr,&strhdr,0);
 acmStreamClose(hstr, 0);
 acmDriverClose(had, 0);

 return TRUE;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值