Ejemplo n.º 1
0
static void itu_compliance_tests(void)
{
    g726_state_t enc_state;
    g726_state_t dec_state;
    int len2;
    int len3;
    int i;
    int test;
    int bad_samples;
    int conditioning_samples;
    int samples;
    int conditioning_adpcm;
    int adpcm;

    len2 = 0;
    conditioning_samples = 0;
    for (test = 0;  itu_test_sets[test].rate;  test++)
    {
        printf("Test %2d: '%s' + '%s'\n"
               "      -> '%s' + '%s'\n"
               "      -> '%s' [%d, %d, %d]\n",
               test,
               itu_test_sets[test].conditioning_pcm_file,
               itu_test_sets[test].pcm_file,
               itu_test_sets[test].conditioning_adpcm_file,
               itu_test_sets[test].adpcm_file,
               itu_test_sets[test].output_file,
               itu_test_sets[test].rate,
               itu_test_sets[test].compression_law,
               itu_test_sets[test].decompression_law);
        if (itu_test_sets[test].compression_law != G726_ENCODING_NONE)
        {
            /* Test the encode side */
            g726_init(&enc_state, itu_test_sets[test].rate, itu_test_sets[test].compression_law, G726_PACKING_NONE);
            if (itu_test_sets[test].conditioning_pcm_file[0])
            {
                conditioning_samples = get_test_vector(itu_test_sets[test].conditioning_pcm_file, xlaw, MAX_TEST_VECTOR_LEN);
                printf("Test %d: Homing %d samples at %dbps\n", test, conditioning_samples, itu_test_sets[test].rate);
            }
            else
            {
                conditioning_samples = 0;
            }
            samples = get_test_vector(itu_test_sets[test].pcm_file, xlaw + conditioning_samples, MAX_TEST_VECTOR_LEN);
            memcpy(itudata, xlaw, samples + conditioning_samples);
            printf("Test %d: Compressing %d samples at %dbps\n", test, samples, itu_test_sets[test].rate);
            len2 = g726_encode(&enc_state, adpcmdata, itudata, conditioning_samples + samples);
        }
        /* Test the decode side */
        g726_init(&dec_state, itu_test_sets[test].rate, itu_test_sets[test].decompression_law, G726_PACKING_NONE);
        if (itu_test_sets[test].conditioning_adpcm_file[0])
        {
            conditioning_adpcm = get_test_vector(itu_test_sets[test].conditioning_adpcm_file, unpacked, MAX_TEST_VECTOR_LEN);
            printf("Test %d: Homing %d octets at %dbps\n", test, conditioning_adpcm, itu_test_sets[test].rate);
        }
        else
        {
            conditioning_adpcm = 0;
        }
        adpcm = get_test_vector(itu_test_sets[test].adpcm_file, unpacked + conditioning_adpcm, MAX_TEST_VECTOR_LEN);
        if (itu_test_sets[test].compression_law != G726_ENCODING_NONE)
        {
            /* Test our compressed version against the reference compressed version */
            printf("Test %d: Compressed data check - %d/%d octets\n", test, conditioning_adpcm + adpcm, len2);
            if (conditioning_adpcm + adpcm == len2)
            {
                for (bad_samples = 0, i = conditioning_samples;  i < len2;  i++)
                {
                    if (adpcmdata[i] != unpacked[i])
                    {
                        bad_samples++;
                        printf("Test %d: Compressed mismatch %d %x %x\n", test, i, adpcmdata[i], unpacked[i]);
                    }
                }
                if (bad_samples > 0)
                {
                    printf("Test failed\n");
                    exit(2);
                }
                printf("Test passed\n");
            }
            else
            {
                printf("Test %d: Length mismatch - ref = %d, processed = %d\n", test, conditioning_adpcm + adpcm, len2);
                exit(2);
            }
        }

        len3 = g726_decode(&dec_state, outdata, unpacked, conditioning_adpcm + adpcm);

        /* Get the output reference data */
        samples = get_test_vector(itu_test_sets[test].output_file, xlaw, MAX_TEST_VECTOR_LEN);
        memcpy(itu_ref, xlaw, samples);
        /* Test our decompressed version against the reference decompressed version */
        printf("Test %d: Decompressed data check - %d/%d samples\n", test, samples, len3 - conditioning_adpcm);
        if (samples == len3 - conditioning_adpcm)
        {
            for (bad_samples = 0, i = 0;  i < len3;  i++)
            {
                if (itu_ref[i] != ((uint8_t *) outdata)[i + conditioning_adpcm])
                {
                    bad_samples++;
                    printf("Test %d: Decompressed mismatch %d %x %x\n", test, i, itu_ref[i], ((uint8_t *) outdata)[i + conditioning_adpcm]);
                }
            }
            if (bad_samples > 0)
            {
                printf("Test failed\n");
                exit(2);
            }
            printf("Test passed\n");
        }
        else
        {
            printf("Test %d: Length mismatch - ref = %d, processed = %d\n", test, samples, len3 - conditioning_adpcm);
            exit(2);
        }
    }

    printf("Tests passed.\n");
}
Ejemplo n.º 2
0
static int perform_linear_test(int full, int disk, const char *name)
{
    gsm0610_state_t *gsm0610_enc_state;
    gsm0610_state_t *gsm0610_dec_state;
    int i;
    int xxx;
    int mismatches;

    printf("Performing linear test '%s' from disk %d\n", name, disk);

    get_test_vector(full, disk, name);

    if (full)
    {
        if ((gsm0610_enc_state = gsm0610_init(NULL, GSM0610_PACKING_NONE)) == NULL)
        {
            fprintf(stderr, "    Cannot create encoder\n");
            exit(2);
        }
        xxx = gsm0610_encode(gsm0610_enc_state, code_vector, in_vector, vector_len);

        printf("Check code vector of length %d\n", xxx);
        for (i = 0, mismatches = 0;  i < xxx;  i++)
        {
            if (code_vector[i] != ref_code_vector[i])
            {
                printf("%8d/%3d: %6d %6d\n", i/76, i%76, code_vector[i], ref_code_vector[i]);
                mismatches++;
            }
        }
        gsm0610_release(gsm0610_enc_state);
        if (mismatches)
        {
            printf("Test failed: %d of %d samples mismatch\n", mismatches, xxx);
            exit(2);
        }
        printf("Test passed\n");
    }

    if ((gsm0610_dec_state = gsm0610_init(NULL, GSM0610_PACKING_NONE)) == NULL)
    {
        fprintf(stderr, "    Cannot create decoder\n");
        exit(2);
    }
    xxx = gsm0610_decode(gsm0610_dec_state, out_vector, decoder_code_vector, vector_len);
    printf("Check output vector of length %d\n", vector_len);
    for (i = 0, mismatches = 0;  i < vector_len;  i++)
    {
        if (out_vector[i] != ref_out_vector[i])
        {
            printf("%8d: %6d %6d\n", i, out_vector[i], ref_out_vector[i]);
            mismatches++;
        }
    }
    if (mismatches)
    {
        printf("Test failed: %d of %d samples mismatch\n", mismatches, vector_len);
        exit(2);
    }
    gsm0610_release(gsm0610_dec_state);
    printf("Test passed\n");
    return 0;
}
Ejemplo n.º 3
0
int main(int argc, char *argv[])
{
    g726_state_t enc_state;
    g726_state_t dec_state;
    int len2;
    int len3;
    int i;
    int test;
    int bits_per_code;
    int itutests;
    int bit_rate;
    int bad_samples;
    AFfilehandle inhandle;
    AFfilehandle outhandle;
    AFfilesetup filesetup;
    int16_t amp[1024];
    int frames;
    int outframes;
    int conditioning_samples;
    int samples;
    int conditioning_adpcm;
    int adpcm;
    int packing;
    float x;

    i = 1;
    bit_rate = 32000;
    itutests = TRUE;
    packing = G726_PACKING_NONE;
    while (argc > i)
    {
        if (strcmp(argv[i], "-16") == 0)
        {
            bit_rate = 16000;
            itutests = FALSE;
            i++;
        }
        else if (strcmp(argv[i], "-24") == 0)
        {
            bit_rate = 24000;
            itutests = FALSE;
            i++;
        }
        else if (strcmp(argv[i], "-32") == 0)
        {
            bit_rate = 32000;
            itutests = FALSE;
            i++;
        }
        else if (strcmp(argv[i], "-40") == 0)
        {
            bit_rate = 40000;
            itutests = FALSE;
            i++;
        }
        else if (strcmp(argv[i], "-l") == 0)
        {
            packing = G726_PACKING_LEFT;
            i++;
        }
        else if (strcmp(argv[i], "-r") == 0)
        {
            packing = G726_PACKING_RIGHT;
            i++;
        }
        else
        {
            fprintf(stderr, "Unknown parameter %s specified.\n", argv[i]);
            exit(2);
        }
    }

    len2 = 0;
    conditioning_samples = 0;
    if (itutests)
    {
        for (test = 0;  itu_test_sets[test].rate;  test++)
        {
            printf("Test %2d: '%s' + '%s'\n"
                   "      -> '%s' + '%s'\n"
                   "      -> '%s' [%d, %d, %d]\n",
                   test,
                   itu_test_sets[test].conditioning_pcm_file,
                   itu_test_sets[test].pcm_file,
                   itu_test_sets[test].conditioning_adpcm_file,
                   itu_test_sets[test].adpcm_file,
                   itu_test_sets[test].output_file,
                   itu_test_sets[test].rate,
                   itu_test_sets[test].compression_law,
                   itu_test_sets[test].decompression_law);
            switch (itu_test_sets[test].rate)
            {
            case 16000:
                bits_per_code = 2;
                break;
            case 24000:
                bits_per_code = 3;
                break;
            case 32000:
            default:
                bits_per_code = 4;
                break;
            case 40000:
                bits_per_code = 5;
                break;
            }
            if (itu_test_sets[test].compression_law != G726_ENCODING_NONE)
            {
                /* Test the encode side */
                g726_init(&enc_state, itu_test_sets[test].rate, itu_test_sets[test].compression_law, G726_PACKING_NONE);
                if (itu_test_sets[test].conditioning_pcm_file[0])
                {
                    conditioning_samples = get_test_vector(itu_test_sets[test].conditioning_pcm_file, xlaw, MAX_TEST_VECTOR_LEN);
                    printf("Test %d: Homing %d samples at %dbps\n", test, conditioning_samples, itu_test_sets[test].rate);
                }
                else
                {
                    conditioning_samples = 0;
                }
                samples = get_test_vector(itu_test_sets[test].pcm_file, xlaw + conditioning_samples, MAX_TEST_VECTOR_LEN);
                memcpy(itudata, xlaw, samples + conditioning_samples);
                printf("Test %d: Compressing %d samples at %dbps\n", test, samples, itu_test_sets[test].rate);
                len2 = g726_encode(&enc_state, adpcmdata, itudata, conditioning_samples + samples);
            }
            /* Test the decode side */
            g726_init(&dec_state, itu_test_sets[test].rate, itu_test_sets[test].decompression_law, G726_PACKING_NONE);
            if (itu_test_sets[test].conditioning_adpcm_file[0])
            {
                conditioning_adpcm = get_test_vector(itu_test_sets[test].conditioning_adpcm_file, unpacked, MAX_TEST_VECTOR_LEN);
                printf("Test %d: Homing %d octets at %dbps\n", test, conditioning_adpcm, itu_test_sets[test].rate);
            }
            else
            {
                conditioning_adpcm = 0;
            }
            adpcm = get_test_vector(itu_test_sets[test].adpcm_file, unpacked + conditioning_adpcm, MAX_TEST_VECTOR_LEN);
            if (itu_test_sets[test].compression_law != G726_ENCODING_NONE)
            {
                /* Test our compressed version against the reference compressed version */
                printf("Test %d: Compressed data check - %d/%d octets\n", test, conditioning_adpcm + adpcm, len2);
                if (conditioning_adpcm + adpcm == len2)
                {
                    for (bad_samples = 0, i = conditioning_samples;  i < len2;  i++)
                    {
                        if (adpcmdata[i] != unpacked[i])
                        {
                            bad_samples++;
                            printf("Test %d: Compressed mismatch %d %x %x\n", test, i, adpcmdata[i], unpacked[i]);
                        }
                    }
                    if (bad_samples > 0)
                    {
                        printf("Test failed\n");
                        exit(2);
                    }
                    printf("Test passed\n");
                }
                else
                {
                    printf("Test %d: Length mismatch - ref = %d, processed = %d\n", test, conditioning_adpcm + adpcm, len2);
                    exit(2);
                }
            }

            len3 = g726_decode(&dec_state, outdata, unpacked, conditioning_adpcm + adpcm);

            /* Get the output reference data */
            samples = get_test_vector(itu_test_sets[test].output_file, xlaw, MAX_TEST_VECTOR_LEN);
            memcpy(itu_ref, xlaw, samples);
            /* Test our decompressed version against the reference decompressed version */
            printf("Test %d: Decompressed data check - %d/%d samples\n", test, samples, len3 - conditioning_adpcm);
            if (samples == len3 - conditioning_adpcm)
            {
                for (bad_samples = 0, i = 0;  i < len3;  i++)
                {
                    if (itu_ref[i] != ((uint8_t *) outdata)[i + conditioning_adpcm])
                    {
                        bad_samples++;
                        printf("Test %d: Decompressed mismatch %d %x %x\n", test, i, itu_ref[i], ((uint8_t *) outdata)[i + conditioning_adpcm]);
                    }
                }
                if (bad_samples > 0)
                {
                    printf("Test failed\n");
                    exit(2);
                }
                printf("Test passed\n");
            }
            else
            {
                printf("Test %d: Length mismatch - ref = %d, processed = %d\n", test, samples, len3 - conditioning_adpcm);
                exit(2);
            }
        }

        printf("Tests passed.\n");
    }
    else
    {
        if ((inhandle = afOpenFile(IN_FILE_NAME, "r", 0)) == AF_NULL_FILEHANDLE)
        {
            printf("    Cannot open wave file '%s'\n", IN_FILE_NAME);
            exit(2);
        }
        if ((x = afGetFrameSize(inhandle, AF_DEFAULT_TRACK, 1)) != 2.0)
        {
            printf("    Unexpected frame size in wave file '%s'\n", IN_FILE_NAME);
            exit(2);
        }
        if ((x = afGetRate(inhandle, AF_DEFAULT_TRACK)) != (float) SAMPLE_RATE)
        {
            printf("    Unexpected sample rate in wave file '%s'\n", IN_FILE_NAME);
            exit(2);
        }
        if ((x = afGetChannels(inhandle, AF_DEFAULT_TRACK)) != 1.0)
        {
            printf("    Unexpected number of channels in wave file '%s'\n", IN_FILE_NAME);
            exit(2);
        }
        if ((filesetup = afNewFileSetup()) == AF_NULL_FILESETUP)
        {
            fprintf(stderr, "    Failed to create file setup\n");
            exit(2);
        }
        afInitSampleFormat(filesetup, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, 16);
        afInitRate(filesetup, AF_DEFAULT_TRACK, (float) SAMPLE_RATE);
        afInitFileFormat(filesetup, AF_FILE_WAVE);
        afInitChannels(filesetup, AF_DEFAULT_TRACK, 1);

        outhandle = afOpenFile(OUT_FILE_NAME, "w", filesetup);
        if (outhandle == AF_NULL_FILEHANDLE)
        {
            fprintf(stderr, "    Cannot create wave file '%s'\n", OUT_FILE_NAME);
            exit(2);
        }

        printf("ADPCM packing is %d\n", packing);
        g726_init(&enc_state, bit_rate, G726_ENCODING_LINEAR, packing);
        g726_init(&dec_state, bit_rate, G726_ENCODING_LINEAR, packing);

        while ((frames = afReadFrames(inhandle, AF_DEFAULT_TRACK, amp, 159)))
        {
            adpcm = g726_encode(&enc_state, adpcmdata, amp, frames);
            frames = g726_decode(&dec_state, amp, adpcmdata, adpcm);
            outframes = afWriteFrames(outhandle, AF_DEFAULT_TRACK, amp, frames);
        }
        if (afCloseFile(inhandle) != 0)
        {
            printf("    Cannot close wave file '%s'\n", IN_FILE_NAME);
            exit(2);
        }
        if (afCloseFile(outhandle) != 0)
        {
            printf("    Cannot close wave file '%s'\n", OUT_FILE_NAME);
            exit(2);
        }
        afFreeFileSetup(filesetup);
        printf("'%s' transcoded to '%s' at %dbps.\n", IN_FILE_NAME, OUT_FILE_NAME, bit_rate);
    }
    return 0;
}