/*
 * encode.c
 *
 * CCITT ADPCM encoder
 *
 * Usage : encode [-3|4|5] [-a|u|l] < infile > outfile
 */
#include <stdio.h>
#include "g72x.h"
/*
 * Pack output codes into bytes and write them to stdout.
 * Returns 1 if there is residual output, else returns 0.
 */
FILE *fpin,*fpOut ;
int
pack_output(
unsigned code,
int bits)
{
static unsigned int out_buffer = 0;
static int out_bits = 0;
unsigned char out_byte; out_buffer |= (code << out_bits);
out_bits += bits;
if (out_bits >= 8) {
out_byte = out_buffer & 0xff;
out_bits -= 8;
out_buffer >>= 8;
fwrite(&out_byte, sizeof (char), 1, fpOut);
}
return (out_bits > 0);
}main(
int argc,
char **argv)
{
struct g72x_state state;
unsigned char sample_char;
short sample_short;
unsigned char code;
int resid;
int in_coding;
int in_size;
unsigned *in_buf;
int (*enc_routine)();
int enc_bits; g72x_init_state(&state); /* Set defaults to u-law input, G.721 output */
in_coding = AUDIO_ENCODING_ULAW;
in_size = sizeof (char);
in_buf = (unsigned *)&sample_char;
enc_routine = g721_encoder;
enc_bits = 4;
fpin= fopen("YourInputFile,"rb");
fpOut= fopen("YouOutFile","arw+"); while (fread(in_buf, in_size, 1, fpin) == 1) {
code = (*enc_routine)(in_size == 2 ? sample_short : sample_char,
    in_coding, &state);
resid = pack_output(code, enc_bits);
} /* Write zero codes until all residual codes are written out */
while (resid) {
resid = pack_output(0, enc_bits);
}
fclose(stdout);
}

解决方案 »

  1.   

    DealWolf(死狼)
    你还在呀
    不是说你要到现场吗?你上面的还不是一样跟那个demo一样吗
    你收到我的信没有?我如下录音////////////////参数初始化 m_BufferIndex=0;
    m_BufferLength=960;
    for (i=0;i<5;i++)
    {
    m_lpAudioData[i]=(LPSTR)GlobalAllocPtr(GMEM_MOVEABLE|GMEM_SHARE|GMEM_ZEROINIT,m_BufferLength);
    m_lpAudioHdr[i]=(LPWAVEHDR)GlobalAllocPtr(GMEM_MOVEABLE|GMEM_SHARE|GMEM_ZEROINIT,sizeof(WAVEHDR));
    }
    m_pwfx=(LPWAVEFORMATEX)GlobalAllocPtr(GHND,sizeof(WAVEFORMATEX));
    memset(m_pwfx,0,sizeof(WAVEFORMATEX));
    m_pwfx->cbSize=0;
    m_pwfx->wFormatTag=WAVE_FORMAT_PCM;
    m_pwfx->nChannels=1;
    m_pwfx->nSamplesPerSec=8000;
    m_pwfx->wBitsPerSample=8;
    m_pwfx->nBlockAlign=1;
    m_pwfx->nAvgBytesPerSec=8000;
    ////////////////录音
     
    waveInOpen((LPHWAVEIN)&m_hWaveIn,(WORD)WAVE_MAPPER,m_pwfx,(LONG)m_hWnd,0L,CALLBACK_WINDOW);
    for (i=0;i<5;i++)
    {
    m_lpAudioHdr[i]->lpData=(LPSTR)m_lpAudioData[i];
    m_lpAudioHdr[i]->dwBufferLength=(DWORD)m_BufferLength;
    m_lpAudioHdr[i]->dwFlags=0L;
    m_lpAudioHdr[i]->dwLoops=0L;
    waveInPrepareHeader(m_hWaveIn,m_lpAudioHdr[i],sizeof(WAVEHDR));
    }
    waveInAddBuffer(m_hWaveIn,m_lpAudioHdr[m_BufferIndex],sizeof(WAVEHDR));
    waveInStart(m_hWaveIn);  
    ////////////接下来我要压缩我该怎么做或
      

  2.   

    Wave系列函数我不熟  问一句  
      怎样直到现在已经录音了多少数据
      

  3.   

    while(recodeing==true)  //仍在录音
    {
    code = g721_encoder(m_lpAudioHdr[Processed/*已处理数据*/]->lpData,AUDIO_ENCODING_ALAW,&state);

    resid = pack_output(code, enc_bits);
    while (resid) {
    resid = pack_output(0, enc_bits);

    }char OutData[MAX_BUFFER]; //压缩后数据区 int pack_output(unsigned code,int bits)
    {
    static unsigned int out_buffer = 0;
    static int out_bits = 0;
    unsigned char out_byte; out_buffer |= (code << out_bits);
    out_bits += bits;
    if (out_bits >= 8) {
    out_byte = out_buffer & 0xff;
    out_bits -= 8;
    out_buffer >>= 8;
    OutData[Process++]=out_byte; //这里换成写内存
    //OutData(&out_byte, sizeof (char), 1, fpOut);
    }

    return (out_bits > 0);
    }
      

  4.   

    //录音部分
    while(recodeing==true)  //仍在录音
    {
    code = g721_encoder(m_lpAudioHdr[Processed++/*已处理数据  更正上面的*/]->lpData,AUDIO_ENCODING_ALAW,&state);

    resid = pack_output(code, enc_bits);
    while (resid) {
    resid = pack_output(0, enc_bits);

    }
    //输出部分
    char OutData[MAX_BUFFER]; //压缩后数据区 int pack_output(unsigned code,int bits)
    {
    static unsigned int out_buffer = 0;
    static int  Writed = 0; //已写入的数据量  新增
    static int out_bits = 0;
    unsigned char out_byte; out_buffer |= (code << out_bits);
    out_bits += bits;
    if (out_bits >= 8) {
    out_byte = out_buffer & 0xff;
    out_bits -= 8;
    out_buffer >>= 8;
    OutData[Writed++]=out_byte; //这里换成写内存[还要判断越界等处理]
    //OutData(&out_byte, sizeof (char), 1, fpOut);
    }

    return (out_bits > 0);
    }
      

  5.   

    DealWolf(死狼):
    在吗
    我给你的信收到了吗
      

  6.   

    好的我的程序我试过了
    在10M局域网上没问题
    当然你可以在本机上试
    注意思改好个IP
      

  7.   

    你可以改一下 让它有回音 就是接收到后先Sleep(10)再放不改的话也有明显的不同(比如杂音等,断续等因为程序只用了两个内存区 相互换着录、放)
      

  8.   

    能将程序给我来一份,吗?   
                          我也在做这方面的实验。
                          [email protected]
      

  9.   

    最好是在局域网上的两台机子上试 杂音有点大 不过跟那个netmeeting差不多
      

  10.   

    DeadWolf(死狼)
     要下班了吗
    晚上抽点时帮我
    明天见