webrtc框架下得isac语音译码问题 2C

看了了webrtc源代码的isac编译码程序,自己写了一个控制台程序,读取一个pcm int16的话音文件,然后用isac编码,最后译码,译码后语音明显有破音和过载,与原语音比较差异很明显,始终找不到原因,忘高手指教。以下是我写的源代码。

#include "stdafx.h"
#include "isac.h"
#include "utility.h"
#include "math.h"
#include "windows.h";
int _tmain(int argc, _TCHAR* argv[])
{
ISACStruct* ISAC_main_inst;
WebRtc_Word16 stream_len = 0;
IsacSamplingRate sampFreqKHz = kIsacWideband;
WebRtc_Word16 declen;
WebRtc_Word16 speechType[1];
*speechType = 1;
WebRtc_UWord16 payload[600];
WebRtc_Word16 decoded[1920];
WebRtc_Word16 decodeout[1920];
WebRtc_UWord16 payloadRCU[600];
WebRtc_Word16 rcuStreamLen = 0;
int samplesIn10Ms = 160, cur_framesmpls = 0;
const char Infilename[] = "D:\matlab code\fileout.pcm";
const char Outfilename[] = "D:\matlab code\fileout_decode.pcm";
FILE *filein, *fileout;
short shortdata[160];
memset(shortdata, 0, 160);
memset(decoded, 0, 1920);
filein = fopen(Infilename, "r");
fileout = fopen(Outfilename, "w");
fclose(fileout);
fileout = fopen(Outfilename, "a+");
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
int err = WebRtcIsac_Create(&ISAC_main_inst);
WebRtcIsac_SetEncSampRate(ISAC_main_inst, (sampFreqKHz == 16) ? kIsacWideband : kIsacSuperWideband);
WebRtcIsac_SetDecSampRate(ISAC_main_inst, (sampFreqKHz == 16) ? kIsacWideband : kIsacSuperWideband);
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
fseek(filein, 0, SEEK_END);
int fsize = ftell(filein);
int samplenum = floor((double)fsize / 2);
int blocknum = floor((double)samplenum / samplesIn10Ms/3);
fseek(filein, 0, SEEK_SET);
if (WebRtcIsac_DecoderInit(ISAC_main_inst) < 0)
{
printf("cannot initialize decoder\n");
return -1;
} if (WebRtcIsac_EncoderInit(ISAC_main_inst, 0) < 0)
{
printf("cannot initialize encoder\n");
return -1;
}
if (WebRtcIsac_ControlBwe(ISAC_main_inst, 36000, 30, 1) < 0)
{
printf("cannot configure BWE\n");
return -1;
}
BottleNeckModel packetData;
packetData.arrival_time = 0;
packetData.sample_count = 0;
packetData.rtp_number = 0;
stream_len = 0;
for (int i = 0; i < blocknum; i++)
{
cur_framesmpls = 0;
stream_len = 0;
fseek(filein, i*samplesIn10Ms * 3 * 2, SEEK_SET);
//+++++++++++read file and encode
while (stream_len == 0)
{
int k = 0;
int size = fread(shortdata, sizeof(short), samplesIn10Ms, filein);

k++;
fseek(filein, i*samplesIn10Ms * 3 * 2 + samplesIn10Ms*2*k, SEEK_SET);
cur_framesmpls += samplesIn10Ms;

        //-------- iSAC encoding ---------
        stream_len = WebRtcIsac_Encode(ISAC_main_inst, shortdata,
            (WebRtc_Word16*)payload);           
        if (stream_len < 0)
        {
            // exit if returned with error
            //errType=WebRtcIsac_GetErrorCode(ISAC_main_inst);
            fprintf(stderr, "\nError in encoder\n");
            getchar();
            exit(EXIT_FAILURE);
        }
    }

    rcuStreamLen = WebRtcIsac_GetRedPayload(ISAC_main_inst, (WebRtc_Word16*)payloadRCU);
    //++++++++++++++test parameters++++++++
    //WebRtc_Word32 sendbottleneck;
    //WebRtcIsac_GetUplinkBw(ISAC_main_inst, &sendbottleneck);
    //WebRtcIsac_UpdateUplinkBw(ISAC_main_inst, 9);
    WebRtc_Word16 bweindex, framelen;
    WebRtcIsac_ReadBwIndex((WebRtc_Word16*)payload, &bweindex);
    WebRtcIsac_UpdateUplinkBw(ISAC_main_inst, bweindex);
    WebRtcIsac_ReadFrameLen(ISAC_main_inst, (WebRtc_Word16*)payload, &framelen);
    //=========================updata bw========================================
    //get_arrival_time(cur_framesmpls, 10000, 16000, &packetData,
        //sampFreqKHz * 1000, sampFreqKHz * 1000);
    /*
    /*
    if (WebRtcIsac_UpdateBwEstimate(ISAC_main_inst,
        payload, stream_len, 1,
        0,
        480) < 0)
    {
        printf(" BWE Error at client\n");
        return -1;
    }*/
    //======================= iSAC decoding ===========================

    declen = WebRtcIsac_Decode(ISAC_main_inst, payload,
        stream_len, decoded, speechType);
    if (declen <= 0)
    {
        //errType=WebRtcIsac_GetErrorCode(ISAC_main_inst);
        fprintf(stderr, "\nError in decoder.\n");
        getchar();
        exit(1);
    }
    //+++++++++++++++++++++write file to the out file
    /*for (int i = 0; i < declen; i++)
    {
        WebRtc_Word16 bit1 = (int16_t)decoded[i] >> 15 & 0x0001;
        WebRtc_Word16 bit2 = (int16_t)decoded[i] >> 13 & 0x0002;
        WebRtc_Word16 bit3 = (int16_t)decoded[i] >> 11 & 0x0004;
        WebRtc_Word16 bit4 = (int16_t)decoded[i] >> 9 & 0x0008;
        WebRtc_Word16 bit5 = (int16_t)decoded[i] >> 7 & 0x0010;
        WebRtc_Word16 bit6 = (int16_t)decoded[i] >> 5 & 0x0020;
        WebRtc_Word16 bit7 = (int16_t)decoded[i] >> 3 & 0x0040;
        WebRtc_Word16 bit8 = (int16_t)decoded[i] >> 1 & 0x0080;
        WebRtc_Word16 bit9 = (int16_t)decoded[i] <<1 & 0x0100;
        WebRtc_Word16 bit10 = (int16_t)decoded[i] <<3 & 0x0200;
        WebRtc_Word16 bit11 = (int16_t)decoded[i] << 5 & 0x0400;
        WebRtc_Word16 bit12 = (int16_t)decoded[i] << 7 & 0x0800;
        WebRtc_Word16 bit13 = (int16_t)decoded[i] << 9 & 0x1000;
        WebRtc_Word16 bit14 = (int16_t)decoded[i] << 11 & 0x2000;
        WebRtc_Word16 bit15 = (int16_t)decoded[i] << 13 & 0x4000;
        WebRtc_Word16 bit16 = (int16_t)decoded[i] << 15 & 0x8000;
        decodeout[i] = bit1 | bit2 | bit3 | bit4 | bit5 | bit6| bit7 | bit8 | bit9 | bit10 | bit11 | bit12| bit13 | bit14 | bit15 | bit16;

    }*/
    fwrite(decoded, sizeof(WebRtc_Word16), declen, fileout);

}
fclose(filein);
fclose(fileout);
return 0;

}

1个回答

图片说明这是原始的语音波形图。图片说明,这是译码后的波形图。对比明显结果是有问题的。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐