int put_wav_header(ByteIOContext *pb, AVCodecContext *enc)

{

    int bps, blkalign, bytespersec;

    int hdrsize = 18;



    if(!enc->codec_tag || enc->codec_tag > 0xffff)

       enc->codec_tag = codec_get_tag(codec_wav_tags, enc->codec_id);

    if(!enc->codec_tag)

        return -1;



    put_le16(pb, enc->codec_tag);

    put_le16(pb, enc->channels);

    put_le32(pb, enc->sample_rate);

    if (enc->codec_id == CODEC_ID_PCM_U8 ||

        enc->codec_id == CODEC_ID_PCM_ALAW ||

        enc->codec_id == CODEC_ID_PCM_MULAW) {

        bps = 8;

    } else if (enc->codec_id == CODEC_ID_MP2 || enc->codec_id == CODEC_ID_MP3) {

        bps = 0;

    } else if (enc->codec_id == CODEC_ID_ADPCM_IMA_WAV || enc->codec_id == CODEC_ID_ADPCM_MS || enc->codec_id == CODEC_ID_ADPCM_G726 || enc->codec_id == CODEC_ID_ADPCM_YAMAHA) { //

        bps = 4;

    } else if (enc->codec_id == CODEC_ID_PCM_S24LE) {

        bps = 24;

    } else if (enc->codec_id == CODEC_ID_PCM_S32LE) {

        bps = 32;

    } else {

        bps = 16;

    }



    if (enc->codec_id == CODEC_ID_MP2 || enc->codec_id == CODEC_ID_MP3) {

        blkalign = enc->frame_size; //this is wrong, but seems many demuxers dont work if this is set correctly

        //blkalign = 144 * enc->bit_rate/enc->sample_rate;

    } else if (enc->codec_id == CODEC_ID_ADPCM_G726) { //

        blkalign = 1;

    } else if (enc->block_align != 0) { /* specified by the codec */

        blkalign = enc->block_align;

    } else

        blkalign = enc->channels*bps >> 3;

    if (enc->codec_id == CODEC_ID_PCM_U8 ||

        enc->codec_id == CODEC_ID_PCM_S24LE ||

        enc->codec_id == CODEC_ID_PCM_S32LE ||

        enc->codec_id == CODEC_ID_PCM_S16LE) {

        bytespersec = enc->sample_rate * blkalign;

    } else {

        bytespersec = enc->bit_rate / 8;

    }

    put_le32(pb, bytespersec); /* bytes per second */

    put_le16(pb, blkalign); /* block align */

    put_le16(pb, bps); /* bits per sample */

    if (enc->codec_id == CODEC_ID_MP3) {

        put_le16(pb, 12); /* wav_extra_size */

        hdrsize += 12;

        put_le16(pb, 1); /* wID */

        put_le32(pb, 2); /* fdwFlags */

        put_le16(pb, 1152); /* nBlockSize */

        put_le16(pb, 1); /* nFramesPerBlock */

        put_le16(pb, 1393); /* nCodecDelay */

    } else if (enc->codec_id == CODEC_ID_MP2) {

        put_le16(pb, 22); /* wav_extra_size */

        hdrsize += 22;

        put_le16(pb, 2);  /* fwHeadLayer */

        put_le32(pb, enc->bit_rate); /* dwHeadBitrate */

        put_le16(pb, enc->channels == 2 ? 1 : 8); /* fwHeadMode */

        put_le16(pb, 0);  /* fwHeadModeExt */

        put_le16(pb, 1);  /* wHeadEmphasis */

        put_le16(pb, 16); /* fwHeadFlags */

        put_le32(pb, 0);  /* dwPTSLow */

        put_le32(pb, 0);  /* dwPTSHigh */

    } else if (enc->codec_id == CODEC_ID_ADPCM_IMA_WAV) {

        put_le16(pb, 2); /* wav_extra_size */

        hdrsize += 2;

        put_le16(pb, ((enc->block_align - 4 * enc->channels) / (4 * enc->channels)) * 8 + 1); /* wSamplesPerBlock */

    } else if(enc->extradata_size){

        put_le16(pb, enc->extradata_size);

        put_buffer(pb, enc->extradata, enc->extradata_size);

        hdrsize += enc->extradata_size;

        if(hdrsize&1){

            hdrsize++;

            put_byte(pb, 0);

        }

    } else {

        hdrsize -= 2;

    }



    return hdrsize;

}

int put_wav_header(ByteIOContext *pb, AVCodecContext *enc)

{

    int bps, blkalign, bytespersec;

    int hdrsize = 18;



    if(!enc->codec_tag || enc->codec_tag > 0xffff)

       enc->codec_tag = codec_get_tag(codec_wav_tags, enc->codec_id);

    if(!enc->codec_tag)

        return -1;



    put_le16(pb, enc->codec_tag);

    put_le16(pb, enc->channels);

    put_le32(pb, enc->sample_rate);

    if (enc->codec_id == CODEC_ID_PCM_U8 ||

        enc->codec_id == CODEC_ID_PCM_ALAW ||

        enc->codec_id == CODEC_ID_PCM_MULAW) {

        bps = 8;

    } else if (enc->codec_id == CODEC_ID_MP2 || enc->codec_id == CODEC_ID_MP3) {

        bps = 0;

    } else if (enc->codec_id == CODEC_ID_ADPCM_IMA_WAV || enc->codec_id == CODEC_ID_ADPCM_MS || enc->codec_id == CODEC_ID_ADPCM_G726 || enc->codec_id == CODEC_ID_ADPCM_YAMAHA) { 

        bps = 4;

    } else if (enc->codec_id == CODEC_ID_PCM_S24LE) {

        bps = 24;

    } else if (enc->codec_id == CODEC_ID_PCM_S32LE) {

        bps = 32;

    } else {

        bps = 16;

    }



    if (enc->codec_id == CODEC_ID_MP2 || enc->codec_id == CODEC_ID_MP3) {

        blkalign = enc->frame_size; this is wrong, but seems many demuxers dont work if this is set correctly

        blkalign = 144 * enc->bit_rate/enc->sample_rate;

    } else if (enc->codec_id == CODEC_ID_ADPCM_G726) { 

        blkalign = 1;

    } else if (enc->block_align != 0) { 

        blkalign = enc->block_align;

    } else

        blkalign = enc->channels*bps >> 3;

    if (enc->codec_id == CODEC_ID_PCM_U8 ||

        enc->codec_id == CODEC_ID_PCM_S24LE ||

        enc->codec_id == CODEC_ID_PCM_S32LE ||

        enc->codec_id == CODEC_ID_PCM_S16LE) {

        bytespersec = enc->sample_rate * blkalign;

    } else {

        bytespersec = enc->bit_rate / 8;

    }

    put_le32(pb, bytespersec); 

    put_le16(pb, blkalign); 

    put_le16(pb, bps); 

    if (enc->codec_id == CODEC_ID_MP3) {

        put_le16(pb, 12); 

        hdrsize += 12;

        put_le16(pb, 1); 

        put_le32(pb, 2); 

        put_le16(pb, 1152); 

        put_le16(pb, 1); 

        put_le16(pb, 1393); 

    } else if (enc->codec_id == CODEC_ID_MP2) {

        put_le16(pb, 22); 

        hdrsize += 22;

        put_le16(pb, 2);  

        put_le32(pb, enc->bit_rate); 

        put_le16(pb, enc->channels == 2 ? 1 : 8); 

        put_le16(pb, 0);  

        put_le16(pb, 1);  

        put_le16(pb, 16); 

        put_le32(pb, 0);  

        put_le32(pb, 0);  

    } else if (enc->codec_id == CODEC_ID_ADPCM_IMA_WAV) {

        put_le16(pb, 2); 

        hdrsize += 2;

        put_le16(pb, ((enc->block_align - 4 * enc->channels) / (4 * enc->channels)) * 8 + 1); 

    } else if(enc->extradata_size){

        put_le16(pb, enc->extradata_size);

        put_buffer(pb, enc->extradata, enc->extradata_size);

        hdrsize += enc->extradata_size;

        if(hdrsize&1){

            hdrsize++;

            put_byte(pb, 0);

        }

    } else {

        hdrsize -= 2;

    }



    return hdrsize;

}

int FUNC_0(ByteIOContext *VAR_0, AVCodecContext *VAR_1)

{

    int VAR_2, VAR_3, VAR_4;

    int VAR_5 = 18;



    if(!VAR_1->codec_tag || VAR_1->codec_tag > 0xffff)

       VAR_1->codec_tag = codec_get_tag(codec_wav_tags, VAR_1->codec_id);

    if(!VAR_1->codec_tag)

        return -1;



    put_le16(VAR_0, VAR_1->codec_tag);

    put_le16(VAR_0, VAR_1->channels);

    put_le32(VAR_0, VAR_1->sample_rate);

    if (VAR_1->codec_id == CODEC_ID_PCM_U8 ||

        VAR_1->codec_id == CODEC_ID_PCM_ALAW ||

        VAR_1->codec_id == CODEC_ID_PCM_MULAW) {

        VAR_2 = 8;

    } else if (VAR_1->codec_id == CODEC_ID_MP2 || VAR_1->codec_id == CODEC_ID_MP3) {

        VAR_2 = 0;

    } else if (VAR_1->codec_id == CODEC_ID_ADPCM_IMA_WAV || VAR_1->codec_id == CODEC_ID_ADPCM_MS || VAR_1->codec_id == CODEC_ID_ADPCM_G726 || VAR_1->codec_id == CODEC_ID_ADPCM_YAMAHA) { 

        VAR_2 = 4;

    } else if (VAR_1->codec_id == CODEC_ID_PCM_S24LE) {

        VAR_2 = 24;

    } else if (VAR_1->codec_id == CODEC_ID_PCM_S32LE) {

        VAR_2 = 32;

    } else {

        VAR_2 = 16;

    }



    if (VAR_1->codec_id == CODEC_ID_MP2 || VAR_1->codec_id == CODEC_ID_MP3) {

        VAR_3 = VAR_1->frame_size; this is wrong, but seems many demuxers dont work if this is set correctly

        VAR_3 = 144 * VAR_1->bit_rate/VAR_1->sample_rate;

    } else if (VAR_1->codec_id == CODEC_ID_ADPCM_G726) { 

        VAR_3 = 1;

    } else if (VAR_1->block_align != 0) { 

        VAR_3 = VAR_1->block_align;

    } else

        VAR_3 = VAR_1->channels*VAR_2 >> 3;

    if (VAR_1->codec_id == CODEC_ID_PCM_U8 ||

        VAR_1->codec_id == CODEC_ID_PCM_S24LE ||

        VAR_1->codec_id == CODEC_ID_PCM_S32LE ||

        VAR_1->codec_id == CODEC_ID_PCM_S16LE) {

        VAR_4 = VAR_1->sample_rate * VAR_3;

    } else {

        VAR_4 = VAR_1->bit_rate / 8;

    }

    put_le32(VAR_0, VAR_4); 

    put_le16(VAR_0, VAR_3); 

    put_le16(VAR_0, VAR_2); 

    if (VAR_1->codec_id == CODEC_ID_MP3) {

        put_le16(VAR_0, 12); 

        VAR_5 += 12;

        put_le16(VAR_0, 1); 

        put_le32(VAR_0, 2); 

        put_le16(VAR_0, 1152); 

        put_le16(VAR_0, 1); 

        put_le16(VAR_0, 1393); 

    } else if (VAR_1->codec_id == CODEC_ID_MP2) {

        put_le16(VAR_0, 22); 

        VAR_5 += 22;

        put_le16(VAR_0, 2);  

        put_le32(VAR_0, VAR_1->bit_rate); 

        put_le16(VAR_0, VAR_1->channels == 2 ? 1 : 8); 

        put_le16(VAR_0, 0);  

        put_le16(VAR_0, 1);  

        put_le16(VAR_0, 16); 

        put_le32(VAR_0, 0);  

        put_le32(VAR_0, 0);  

    } else if (VAR_1->codec_id == CODEC_ID_ADPCM_IMA_WAV) {

        put_le16(VAR_0, 2); 

        VAR_5 += 2;

        put_le16(VAR_0, ((VAR_1->block_align - 4 * VAR_1->channels) / (4 * VAR_1->channels)) * 8 + 1); 

    } else if(VAR_1->extradata_size){

        put_le16(VAR_0, VAR_1->extradata_size);

        put_buffer(VAR_0, VAR_1->extradata, VAR_1->extradata_size);

        VAR_5 += VAR_1->extradata_size;

        if(VAR_5&1){

            VAR_5++;

            put_byte(VAR_0, 0);

        }

    } else {

        VAR_5 -= 2;

    }



    return VAR_5;

}

int FUNC_0(ByteIOContext *VAR_0, AVCodecContext *VAR_1)
{ int VAR_2, VAR_3, VAR_4; int VAR_5 = 18; if(!VAR_1->codec_tag || VAR_1->codec_tag > 0xffff)
VAR_1->codec_tag = codec_get_tag(codec_wav_tags, VAR_1->codec_id); if(!VAR_1->codec_tag)
return -1; put_le16(VAR_0, VAR_1->codec_tag); put_le16(VAR_0, VAR_1->channels); put_le32(VAR_0, VAR_1->sample_rate); if (VAR_1->codec_id == CODEC_ID_PCM_U8 ||
VAR_1->codec_id == CODEC_ID_PCM_ALAW ||
VAR_1->codec_id == CODEC_ID_PCM_MULAW) { VAR_2 = 8; } else if (VAR_1->codec_id == CODEC_ID_MP2 || VAR_1->codec_id == CODEC_ID_MP3) { VAR_2 = 0; } else if (VAR_1->codec_id == CODEC_ID_ADPCM_IMA_WAV || VAR_1->codec_id == CODEC_ID_ADPCM_MS || VAR_1->codec_id == CODEC_ID_ADPCM_G726 || VAR_1->codec_id == CODEC_ID_ADPCM_YAMAHA) { VAR_2 = 4; } else if (VAR_1->codec_id == CODEC_ID_PCM_S24LE) { VAR_2 = 24; } else if (VAR_1->codec_id == CODEC_ID_PCM_S32LE) { VAR_2 = 32; } else { VAR_2 = 16; } if (VAR_1->codec_id == CODEC_ID_MP2 || VAR_1->codec_id == CODEC_ID_MP3) { VAR_3 = VAR_1->frame_size; this is wrong, but seems many demuxers dont work if this is set correctly VAR_3 = 144 * VAR_1->bit_rate/VAR_1->sample_rate; } else if (VAR_1->codec_id == CODEC_ID_ADPCM_G726) { VAR_3 = 1; } else if (VAR_1->block_align != 0) { VAR_3 = VAR_1->block_align; } else VAR_3 = VAR_1->channels*VAR_2 >> 3; if (VAR_1->codec_id == CODEC_ID_PCM_U8 ||
VAR_1->codec_id == CODEC_ID_PCM_S24LE ||
VAR_1->codec_id == CODEC_ID_PCM_S32LE ||
VAR_1->codec_id == CODEC_ID_PCM_S16LE) { VAR_4 = VAR_1->sample_rate * VAR_3; } else { VAR_4 = VAR_1->bit_rate / 8; } put_le32(VAR_0, VAR_4); put_le16(VAR_0, VAR_3); put_le16(VAR_0, VAR_2); if (VAR_1->codec_id == CODEC_ID_MP3) { put_le16(VAR_0, 12); VAR_5 += 12; put_le16(VAR_0, 1); put_le32(VAR_0, 2); put_le16(VAR_0, 1152); put_le16(VAR_0, 1); put_le16(VAR_0, 1393); } else if (VAR_1->codec_id == CODEC_ID_MP2) { put_le16(VAR_0, 22); VAR_5 += 22; put_le16(VAR_0, 2); put_le32(VAR_0, VAR_1->bit_rate); put_le16(VAR_0, VAR_1->channels == 2 ? 1 : 8); put_le16(VAR_0, 0); put_le16(VAR_0, 1); put_le16(VAR_0, 16); put_le32(VAR_0, 0); put_le32(VAR_0, 0); } else if (VAR_1->codec_id == CODEC_ID_ADPCM_IMA_WAV) { put_le16(VAR_0, 2); VAR_5 += 2; put_le16(VAR_0, ((VAR_1->block_align - 4 * VAR_1->channels) / (4 * VAR_1->channels)) * 8 + 1); } else if(VAR_1->extradata_size){ put_le16(VAR_0, VAR_1->extradata_size); put_buffer(VAR_0, VAR_1->extradata, VAR_1->extradata_size); VAR_5 += VAR_1->extradata_size; if(VAR_5&1){ VAR_5++; put_byte(VAR_0, 0); } } else { VAR_5 -= 2; } return VAR_5; }