⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 codectest.c

📁 由HawK提供的语音压缩软件
💻 C
📖 第 1 页 / 共 2 页
字号:

    lpc14file = _topen(TEXT("lpc14.au"), O_BINARY|O_CREAT|O_TRUNC|O_RDWR, S_IREAD|S_IWRITE);
    writeHeader(lpc14file);
    lpc14encode = create_openlpc_encoder_state();
    init_openlpc_encoder_state(lpc14encode, OPENLPC_FRAMESIZE_1_4);
    lpc14decode = create_openlpc_decoder_state();
    init_openlpc_decoder_state(lpc14decode, OPENLPC_FRAMESIZE_1_4);

    vbrlpc10file = _topen(TEXT("vbrlpc10.au"), O_BINARY|O_CREAT|O_TRUNC|O_RDWR, S_IREAD|S_IWRITE);
    writeHeader(vbrlpc10file);
    vbrlpc10encode = create_lpc10_encoder_state();
    init_lpc10_encoder_state(vbrlpc10encode);
    vbrlpc10decode = create_lpc10_decoder_state();
    init_lpc10_decoder_state(vbrlpc10decode);

    ulawe = adpcme = gsme = lpce = lpc10e = lpc18e = lpc14e = celpe = vbrlpc10e = count = 0;
    ulawd = adpcmd = gsmd = lpcd = lpc10d = lpc18d = lpc14d = celpd = vbrlpc10d = 0;
#if 1
    while(len == NUM_SAMPLES)
    {
        int             encodedlen;
        short           samples[NUM_SAMPLES];
        short           decoded[NUM_SAMPLES];
        unsigned char   encoded[NUM_SAMPLES];
        unsigned long   c;

        len = readSamples(infile, type, samples, NUM_SAMPLES);
        count++;
        /* u-law */
        c = getcycles();
        encodedlen = ulawEncode(samples, encoded, len);
        ulawe += countcycles(c);
        c = getcycles();
        (void)ulawDecode(encoded, decoded, encodedlen);
        ulawd += countcycles(c);
        writeSamples(ulawfile, decoded, len);

        /* ADPCM */
        c = getcycles();
        encodedlen = adpcm_coder(samples, encoded, len, &adpcmencode);
        adpcme += countcycles(c);
        c = getcycles();
        (void)adpcm_decoder(encoded, decoded, encodedlen, &adpcmdecode);
        adpcmd += countcycles(c);
        writeSamples(adpcmfile, decoded, len);

        /* GSM */
        c = getcycles();
        encodedlen = gsm_encode(gsmencode, samples, encoded);
        gsme += countcycles(c);
        c = getcycles();
        (void)gsm_decode(gsmdecode, encoded, decoded);
        gsmd += countcycles(c);
        writeSamples(gsmfile, decoded, len);

        /* LPC */
        c = getcycles();
        encodedlen = lpc_encode(samples, encoded, lpcencode);
        lpce += countcycles(c);
        c = getcycles();
        (void)lpc_decode(encoded, decoded, lpcdecode);
        lpcd += countcycles(c);
        writeSamples(lpcfile, decoded, len);
    }
    count /= 8000/NUM_SAMPLES;
    _tprintf(TEXT("u-law cycles per second: encode = %lu, decode = %lu\n"), ulawe / count, ulawd / count);
    _tprintf(TEXT("ADPCM cycles per second: encode = %lu, decode = %lu\n"), adpcme / count, adpcmd / count);
    _tprintf(TEXT("GSM cycles per second: encode = %lu, decode = %lu\n"), gsme / count, gsmd / count);
    _tprintf(TEXT("LPC cycles per second: encode = %lu, decode = %lu\n"), lpce / count, lpcd / count);
#endif
#if 1
    /* reset the input file for the LPC-10 codec */
    lseek(infile, 0, SEEK_SET);
    type = readHeader(infile);
    len = LPC10_SAMPLES;
    count = 0;

    while(len == LPC10_SAMPLES)
    {
        int             encodedlen, p;
        short           samples[LPC10_SAMPLES];
        short           decoded[LPC10_SAMPLES];
        unsigned char   encoded[LPC10_SAMPLES];
        unsigned long   c;

        len = readSamples(infile, type, samples, LPC10_SAMPLES);
        count++;

        /* LPC-10 */
        c = getcycles();
        encodedlen = lpc10_encode(samples, encoded, lpc10encode);
        lpc10e += countcycles(c);
        c = getcycles();
        (void)lpc10_decode(encoded, decoded, lpc10decode);
        lpc10d += countcycles(c);
        writeSamples(lpc10file, decoded, len);

        /* VBR-LPC-10 */
        c = getcycles();
        encodedlen = vbr_lpc10_encode(samples, encoded, vbrlpc10encode);
        vbrlpc10e += countcycles(c);
        c = getcycles();
        (void)vbr_lpc10_decode(encoded, decoded, vbrlpc10decode, &p);
        vbrlpc10d += countcycles(c);
        writeSamples(vbrlpc10file, decoded, len);
    }
    count /= 8000/LPC10_SAMPLES;

    _tprintf(TEXT("LPC-10 cycles per second: encode = %lu, decode = %lu\n"), lpc10e / count, lpc10d / count);
    _tprintf(TEXT("VBR-LPC-10 cycles per second: encode = %lu, decode = %lu\n"), vbrlpc10e / count, vbrlpc10d / count);
#endif
#if 1
    /* reset the input file for the OpenLPC 1.8 Kbps codec */
    lseek(infile, 0, SEEK_SET);
    type = readHeader(infile);
    len = OPENLPC_FRAMESIZE_1_8;
    count = 0;

    while(len == OPENLPC_FRAMESIZE_1_8)
    {
        int             encodedlen;
        short           samples[OPENLPC_FRAMESIZE_1_8];
        short           decoded[OPENLPC_FRAMESIZE_1_8];
        unsigned char   encoded[OPENLPC_FRAMESIZE_1_8];
        unsigned long   c;

        len = readSamples(infile, type, samples, OPENLPC_FRAMESIZE_1_8);
        count++;

        /* OpenLPC 1.8 Kbps */
        c = getcycles();
        encodedlen = openlpc_encode(samples, encoded, lpc18encode);
        lpc18e += countcycles(c);
        c = getcycles();
        (void)openlpc_decode(encoded, decoded, lpc18decode);
        lpc18d += countcycles(c);
        writeSamples(lpc18file, decoded, len);
    }
    count /= 8000/OPENLPC_FRAMESIZE_1_8;

    _tprintf(TEXT("OpenLPC 1.8 Kbps cycles per second: encode = %lu, decode = %lu\n"), lpc18e / count, lpc18d / count);

    /* reset the input file for the OpenLPC 1.4 Kbps codec */
    lseek(infile, 0, SEEK_SET);
    type = readHeader(infile);
    len = OPENLPC_FRAMESIZE_1_4;
    count = 0;

    while(len == OPENLPC_FRAMESIZE_1_4)
    {
        int             encodedlen;
        short           samples[OPENLPC_FRAMESIZE_1_4];
        short           decoded[OPENLPC_FRAMESIZE_1_4];
        unsigned char   encoded[OPENLPC_FRAMESIZE_1_4];
        unsigned long   c;

        len = readSamples(infile, type, samples, OPENLPC_FRAMESIZE_1_4);
        count++;

        /* OpenLPC 1.4 Kbps */
        c = getcycles();
        encodedlen = openlpc_encode(samples, encoded, lpc14encode);
        lpc14e += countcycles(c);
        c = getcycles();
        (void)openlpc_decode(encoded, decoded, lpc14decode);
        lpc14d += countcycles(c);
        writeSamples(lpc14file, decoded, len);
    }
    count /= 8000/OPENLPC_FRAMESIZE_1_4;

    _tprintf(TEXT("OpenLPC 1.4 Kbps cycles per second: encode = %lu, decode = %lu\n"), lpc14e / count, lpc14d / count);
#endif
#if 1
    /* reset the input file for the CELP 4.5 Kbps codec */
    celp45file = _topen(TEXT("celp45.au"), O_BINARY|O_CREAT|O_TRUNC|O_RDWR, S_IREAD|S_IWRITE);
    writeHeader(celp45file);
    celpencode = create_celp_encoder_state();
    init_celp_encoder_state(celpencode, CELP_4_5_FRAMESIZE);
    celp_set_encoder_option(celpencode, CELP_CODEBOOK_LEN, CELP_CODEBOOK);
    celp_set_encoder_option(celpencode, CELP_FAST_GAIN, CELP_FAST);
    celpdecode = create_celp_decoder_state();
    init_celp_decoder_state(celpdecode, CELP_4_5_FRAMESIZE);

    lseek(infile, 0, SEEK_SET);
    type = readHeader(infile);
    len = CELP_4_5_FRAMESIZE;
    count = 0;

    while(len == CELP_4_5_FRAMESIZE)
    {
        int             encodedlen;
        short           samples[CELP_4_5_FRAMESIZE];
        short           decoded[CELP_4_5_FRAMESIZE];
        unsigned char   encoded[CELP_4_5_FRAMESIZE];
        unsigned long   c;

        len = readSamples(infile, type, samples, CELP_4_5_FRAMESIZE);
        count++;

        /* CELP */
        c = getcycles();
        encodedlen = celp_encode(samples, encoded, celpencode);
        celpe += countcycles(c);
        c = getcycles();
        (void)celp_decode(encoded, decoded, celpdecode);
        celpd += countcycles(c);
        writeSamples(celp45file, decoded, len);
    }
    count /= 8000/CELP_4_5_FRAMESIZE;

    _tprintf(TEXT("CELP 4.5 Kbps cycles per second: encode = %lu, decode = %lu\n"), celpe / count, celpd / count);
    close(celp45file);

    destroy_celp_encoder_state(celpencode);
    destroy_celp_decoder_state(celpdecode);

    /* reset the input file for the CELP 3.0 Kbps codec */
    celp30file = _topen(TEXT("celp30.au"), O_BINARY|O_CREAT|O_TRUNC|O_RDWR, S_IREAD|S_IWRITE);
    writeHeader(celp30file);
    celpencode = create_celp_encoder_state();
    init_celp_encoder_state(celpencode, CELP_3_0_FRAMESIZE);
    celp_set_codebook_len(celpencode, CELP_CODEBOOK);
    celpdecode = create_celp_decoder_state();
    init_celp_decoder_state(celpdecode, CELP_3_0_FRAMESIZE);

    lseek(infile, 0, SEEK_SET);
    type = readHeader(infile);
    len = CELP_3_0_FRAMESIZE;
    celpe = celpd = count = 0;

    while(len == CELP_3_0_FRAMESIZE)
    {
        int             encodedlen;
        short           samples[CELP_3_0_FRAMESIZE];
        short           decoded[CELP_3_0_FRAMESIZE];
        unsigned char   encoded[CELP_3_0_FRAMESIZE];
        unsigned long   c;

        len = readSamples(infile, type, samples, CELP_3_0_FRAMESIZE);
        count++;

        /* CELP */
        c = getcycles();
        encodedlen = celp_encode(samples, encoded, celpencode);
        celpe += countcycles(c);
        c = getcycles();
        (void)celp_decode(encoded, decoded, celpdecode);
        celpd += countcycles(c);
        writeSamples(celp30file, decoded, len);
    }
    count /= 8000/CELP_3_0_FRAMESIZE;

    _tprintf(TEXT("CELP 3.0 Kbps cycles per second: encode = %lu, decode = %lu\n"), celpe / count, celpd / count);
    close(celp30file);

    destroy_celp_encoder_state(celpencode);
    destroy_celp_decoder_state(celpdecode);

    /* reset the input file for the CELP 2.3 Kbps codec */
    celp23file = _topen(TEXT("celp23.au"), O_BINARY|O_CREAT|O_TRUNC|O_RDWR, S_IREAD|S_IWRITE);
    writeHeader(celp30file);
    celpencode = create_celp_encoder_state();
    init_celp_encoder_state(celpencode, CELP_2_3_FRAMESIZE);
    celp_set_codebook_len(celpencode, CELP_CODEBOOK);
    celpdecode = create_celp_decoder_state();
    init_celp_decoder_state(celpdecode, CELP_2_3_FRAMESIZE);

    lseek(infile, 0, SEEK_SET);
    type = readHeader(infile);
    len = CELP_2_3_FRAMESIZE;
    celpe = celpd = count = 0;

    while(len == CELP_2_3_FRAMESIZE)
    {
        int             encodedlen;
        short           samples[CELP_2_3_FRAMESIZE];
        short           decoded[CELP_2_3_FRAMESIZE];
        unsigned char   encoded[CELP_2_3_FRAMESIZE];
        unsigned long   c;

        len = readSamples(infile, type, samples, CELP_2_3_FRAMESIZE);
        count++;

        /* CELP */
        c = getcycles();
        encodedlen = celp_encode(samples, encoded, celpencode);
        celpe += countcycles(c);
        c = getcycles();
        (void)celp_decode(encoded, decoded, celpdecode);
        celpd += countcycles(c);
        writeSamples(celp23file, decoded, len);
    }
    count /= 8000/CELP_2_3_FRAMESIZE;

    _tprintf(TEXT("CELP 2.3 Kbps cycles per second: encode = %lu, decode = %lu\n"), celpe / count, celpd / count);
    close(celp23file);

    destroy_celp_encoder_state(celpencode);
    destroy_celp_decoder_state(celpdecode);
#endif
    destroy_openlpc_encoder_state(lpc14encode);
    destroy_openlpc_decoder_state(lpc14decode);

    destroy_openlpc_encoder_state(lpc18encode);
    destroy_openlpc_decoder_state(lpc18decode);

    destroy_lpc10_encoder_state(lpc10encode);
    destroy_lpc10_decoder_state(lpc10decode);

    destroy_lpc_encoder_state(lpcencode);
    destroy_lpc_decoder_state(lpcdecode);

    gsm_destroy(gsmencode);
    gsm_destroy(gsmdecode);

    close(lpc14file);
    close(lpc18file);
    close(lpc10file);
    close(lpcfile);
    close(gsmfile);
    close(adpcmfile);
    close(ulawfile);
    close(infile);
    return 0;
}

#if defined (_WIN32_WCE)
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
				   LPWSTR lpCmdLine, int nShowCmd )
{
	TCHAR	*argv[64], *tok; /* assume 64 max tokens */
	int		argc = 1, rval;
	TCHAR	namebuf[132];

	GetModuleFileName(NULL, namebuf, 132);

	argv[0] = namebuf;
	/* tokenize the command line */
	for (tok = _tcstok(lpCmdLine, TEXT(" \t")); tok; tok = _tcstok(NULL, TEXT(" \t")))
	{
		if (argc >= 64) break;
		argv[argc] = malloc(_tcslen(tok)+sizeof(TCHAR));
		_tcscpy(argv[argc], tok);
		argc++;
	}

	rval = _tmain(argc, argv);

	while(--argc)
	{
		free(argv[argc]);
	}
	return rval;
}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -