这是关键的摘抄代码
void CWave1Dlg::OnWimClose(WPARAM wParam,LPARAM lParam)
{
//压缩
int Loop,G729aLen; //循环变量,压缩后的缓冲长度
for(Loop=0;Loop<100;Loop++)
{
mG729a.Encode(WaveBuf+Loop*960,960,G729aBuf+Loop*60,&G729aLen);
}
...
void CWave1Dlg::OnWomOpen(WPARAM wParam,LPARAM lParam)
{
//解压缩
int Loop,TestLen; //循环变量,解压后的缓冲长度
for(Loop=0;Loop<100;Loop++)
{
mG729a.Decode(G729aBuf+Loop*60,60,TestBuf+Loop*960,&TestLen);
}
...我没压缩的时候是可以正常录放音的,缓冲区为96K,可以录约9秒时间,加上就成了噪音
如果在这里不好解决,在QQ上帮我解决下,644960747,50分相赠,谢谢了

解决方案 »

  1.   

    是下载的一个lib文件
    再补充一下吧,这是我自己封装的G729A类:.h文件#define SIZE_AUDIO_FRAME 960
    #define SIZE_AUDIO_PACKED 60
    //#pragma comment(lib,"va_G729a.lib")
    extern "C" void va_g729a_init_encoder();
    extern "C" void va_g729a_encoder(short *speech, unsigned char *bitstream);
    extern "C" void va_g729a_init_decoder();
    extern "C" void va_g729a_decoder(unsigned char *bitstream, short *synth_short, int bfi);class CG729A
    {
    public:
    CG729A();
    bool Encode(char *pin,int len,char *pout,int *lenr);
    bool Decode(char *pin,int len,char *pout,int *lenr);
    };
    // G729A.cpp: implementation of the CG729A class.
    //
    //////////////////////////////////////////////////////////////////////
    cpp文件:#include "stdafx.h"
    #include "Wave1.h"
    #include "G729A.h"#ifdef _DEBUG
    #undef THIS_FILE
    static char THIS_FILE[]=__FILE__;
    #define new DEBUG_NEW
    #endif//////////////////////////////////////////////////////////////////////
    // Construction/Destruction
    //////////////////////////////////////////////////////////////////////CG729A::CG729A()
    {
    va_g729a_init_encoder();
    va_g729a_init_decoder();
    }bool CG729A::Encode(char *pin,int len,char *pout,int *lenr) 

    bool bRet=FALSE;
    if(!pin ||len!=SIZE_AUDIO_FRAME ||!pout) 
    goto RET; 

    va_g729a_encoder((short*)pin,(BYTE*)pout); 
    va_g729a_encoder((short*)(pin+160),(BYTE*)pout+10); 
    va_g729a_encoder((short*)(pin+320),(BYTE*)pout+20); 
    va_g729a_encoder((short*)(pin+480),(BYTE*)pout+30); 
    va_g729a_encoder((short*)(pin+640),(BYTE*)pout+40); 
    va_g729a_encoder((short*)(pin+800),(BYTE*)pout+50); 

    if(lenr) 
    *lenr=SIZE_AUDIO_PACKED; 

    bRet=TRUE; 
    RET: 
    return bRet; 
    } bool CG729A::Decode(char *pin,int len,char *pout,int *lenr) 

    bool bRet=FALSE; 
    if(!pin ||len!=SIZE_AUDIO_PACKED ||!pout) 
    goto RET; 

    va_g729a_decoder((BYTE*)pin,(short*)(pout),0); 
    va_g729a_decoder((BYTE*)pin+10,(short*)(pout+160),0); 
    va_g729a_decoder((BYTE*)pin+20,(short*)(pout+320),0); 
    va_g729a_decoder((BYTE*)pin+30,(short*)(pout+480),0); 
    va_g729a_decoder((BYTE*)pin+40,(short*)(pout+640),0); 
    va_g729a_decoder((BYTE*)pin+50,(short*)(pout+800),0); 

    if(lenr) 
    *lenr=SIZE_AUDIO_FRAME; 

    bRet=TRUE; 
    RET: 
    return bRet; 
    }
      

  2.   

    我的音频格式是这样设置的,有个高手在QQ上说我音频格式设置不对 //初始化音频格式
    mWaveFmt.wFormatTag=WAVE_FORMAT_PCM;
    mWaveFmt.nChannels=1;
    mWaveFmt.nSamplesPerSec=11025;
    mWaveFmt.wBitsPerSample=8;
    mWaveFmt.nBlockAlign=mWaveFmt.nChannels*mWaveFmt.wBitsPerSample/8;
    //nBlockAlign刚好为1
    mWaveFmt.nAvgBytesPerSec=mWaveFmt.nBlockAlign*mWaveFmt.nSamplesPerSec;
    //nAvgBytesPerSec刚好为11025,也就是说录音时每秒会占用11K字节
    mWaveFmt.cbSize=0;
    所以也贴出来看看
      

  3.   

    我自己解决了,将音频格式改成
    mWaveFmt.wFormatTag=WAVE_FORMAT_PCM;
    mWaveFmt.nChannels=1;
    mWaveFmt.nSamplesPerSec=8000;
    mWaveFmt.wBitsPerSample=16;
    mWaveFmt.nAvgBytesPerSec=16000;
    mWaveFmt.nBlockAlign=2;
    mWaveFmt.cbSize=0;
    就搞定了,可惜没人顶,这分就给vcPlayer算了
      

  4.   


    难道我是CSDN的马拉多纳?:)。多谢LZ的慷慨!不过你也可以“无满意答案结贴”。