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

📄 alac.c

📁 alac decoder,内容详细
💻 C
📖 第 1 页 / 共 3 页
字号:
            /* now read the number of samples,             * as a 32bit integer */            outputsamples = readbits(alac, 32);            *outputsize = outputsamples * alac->bytespersample;        }        readsamplesize = alac->setinfo_sample_size - (wasted_bytes * 8);        if (!isnotcompressed)        { /* so it is compressed */            int16_t predictor_coef_table[32];            int predictor_coef_num;            int prediction_type;            int prediction_quantitization;            int i;            /* skip 16 bits, not sure what they are. seem to be used in             * two channel case */            readbits(alac, 8);            readbits(alac, 8);            prediction_type = readbits(alac, 4);            prediction_quantitization = readbits(alac, 4);            ricemodifier = readbits(alac, 3);            predictor_coef_num = readbits(alac, 5);            /* read the predictor table */            for (i = 0; i < predictor_coef_num; i++)            {                predictor_coef_table[i] = (int16_t)readbits(alac, 16);            }            if (wasted_bytes)            {                /* these bytes seem to have something to do with                 * > 2 channel files.                 */                fprintf(stderr, "FIXME: unimplemented, unhandling of wasted_bytes\n");            }            basterdised_rice_decompress(alac,                                        alac->predicterror_buffer_a,                                        outputsamples,                                        readsamplesize,                                        alac->setinfo_rice_initialhistory,                                        alac->setinfo_rice_kmodifier,                                        ricemodifier * alac->setinfo_rice_historymult / 4,                                        (1 << alac->setinfo_rice_kmodifier) - 1);            if (prediction_type == 0)            { /* adaptive fir */                predictor_decompress_fir_adapt(alac->predicterror_buffer_a,                                               alac->outputsamples_buffer_a,                                               outputsamples,                                               readsamplesize,                                               predictor_coef_table,                                               predictor_coef_num,                                               prediction_quantitization);            }            else            {                fprintf(stderr, "FIXME: unhandled predicition type: %i\n", prediction_type);                /* i think the only other prediction type (or perhaps this is just a                 * boolean?) runs adaptive fir twice.. like:                 * predictor_decompress_fir_adapt(predictor_error, tempout, ...)                 * predictor_decompress_fir_adapt(predictor_error, outputsamples ...)                 * little strange..                 */            }        }        else        { /* not compressed, easy case */            if (readsamplesize <= 16)            {                int i;                for (i = 0; i < outputsamples; i++)                {                    int32_t audiobits = readbits(alac, readsamplesize);                    audiobits = SIGN_EXTENDED32(audiobits, readsamplesize);                    alac->outputsamples_buffer_a[i] = audiobits;                }            }            else            {                int i;                for (i = 0; i < outputsamples; i++)                {                    int32_t audiobits;                    audiobits = readbits(alac, 16);                    /* special case of sign extension..                     * as we'll be ORing the low 16bits into this */                    audiobits = audiobits << 16;                    audiobits = audiobits >> (32 - readsamplesize);                    audiobits |= readbits(alac, readsamplesize - 16);                    alac->outputsamples_buffer_a[i] = audiobits;                }            }            /* wasted_bytes = 0; // unused */        }        switch(alac->setinfo_sample_size)        {        case 16:        {            int i;            for (i = 0; i < outputsamples; i++)            {                int16_t sample = alac->outputsamples_buffer_a[i];                if (host_bigendian)                    _Swap16(sample);                ((int16_t*)outbuffer)[i * alac->numchannels] = sample;            }            break;        }        case 20:        case 24:        case 32:            fprintf(stderr, "FIXME: unimplemented sample size %i\n", alac->setinfo_sample_size);            break;        default:            break;        }        break;    }    case 1: /* 2 channels */    {        int hassize;        int isnotcompressed;        int readsamplesize;        int wasted_bytes;        uint8_t interlacing_shift;        uint8_t interlacing_leftweight;        /* 2^result = something to do with output waiting.         * perhaps matters if we read > 1 frame in a pass?         */        readbits(alac, 4);        readbits(alac, 12); /* unknown, skip 12 bits */        hassize = readbits(alac, 1); /* the output sample size is stored soon */        wasted_bytes = readbits(alac, 2); /* unknown ? */        isnotcompressed = readbits(alac, 1); /* whether the frame is compressed */        if (hassize)        {            /* now read the number of samples,             * as a 32bit integer */            outputsamples = readbits(alac, 32);            *outputsize = outputsamples * alac->bytespersample;        }        readsamplesize = alac->setinfo_sample_size - (wasted_bytes * 8) + 1;        if (!isnotcompressed)        { /* compressed */            int16_t predictor_coef_table_a[32];            int predictor_coef_num_a;            int prediction_type_a;            int prediction_quantitization_a;            int ricemodifier_a;            int16_t predictor_coef_table_b[32];            int predictor_coef_num_b;            int prediction_type_b;            int prediction_quantitization_b;            int ricemodifier_b;            int i;            interlacing_shift = readbits(alac, 8);            interlacing_leftweight = readbits(alac, 8);            /******** channel 1 ***********/            prediction_type_a = readbits(alac, 4);            prediction_quantitization_a = readbits(alac, 4);            ricemodifier_a = readbits(alac, 3);            predictor_coef_num_a = readbits(alac, 5);            /* read the predictor table */            for (i = 0; i < predictor_coef_num_a; i++)            {                predictor_coef_table_a[i] = (int16_t)readbits(alac, 16);            }            /******** channel 2 *********/            prediction_type_b = readbits(alac, 4);            prediction_quantitization_b = readbits(alac, 4);            ricemodifier_b = readbits(alac, 3);            predictor_coef_num_b = readbits(alac, 5);            /* read the predictor table */            for (i = 0; i < predictor_coef_num_b; i++)            {                predictor_coef_table_b[i] = (int16_t)readbits(alac, 16);            }            /*********************/            if (wasted_bytes)            { /* see mono case */                fprintf(stderr, "FIXME: unimplemented, unhandling of wasted_bytes\n");            }            /* channel 1 */            basterdised_rice_decompress(alac,                                        alac->predicterror_buffer_a,                                        outputsamples,                                        readsamplesize,                                        alac->setinfo_rice_initialhistory,                                        alac->setinfo_rice_kmodifier,                                        ricemodifier_a * alac->setinfo_rice_historymult / 4,                                        (1 << alac->setinfo_rice_kmodifier) - 1);            if (prediction_type_a == 0)            { /* adaptive fir */                predictor_decompress_fir_adapt(alac->predicterror_buffer_a,                                               alac->outputsamples_buffer_a,                                               outputsamples,                                               readsamplesize,                                               predictor_coef_table_a,                                               predictor_coef_num_a,                                               prediction_quantitization_a);            }            else            { /* see mono case */                fprintf(stderr, "FIXME: unhandled predicition type: %i\n", prediction_type_a);            }            /* channel 2 */            basterdised_rice_decompress(alac,                                        alac->predicterror_buffer_b,                                        outputsamples,                                        readsamplesize,                                        alac->setinfo_rice_initialhistory,                                        alac->setinfo_rice_kmodifier,                                        ricemodifier_b * alac->setinfo_rice_historymult / 4,                                        (1 << alac->setinfo_rice_kmodifier) - 1);            if (prediction_type_b == 0)            { /* adaptive fir */                predictor_decompress_fir_adapt(alac->predicterror_buffer_b,                                               alac->outputsamples_buffer_b,                                               outputsamples,                                               readsamplesize,                                               predictor_coef_table_b,                                               predictor_coef_num_b,                                               prediction_quantitization_b);            }            else            {                fprintf(stderr, "FIXME: unhandled predicition type: %i\n", prediction_type_b);            }        }        else        { /* not compressed, easy case */            if (alac->setinfo_sample_size <= 16)            {                int i;                for (i = 0; i < outputsamples; i++)                {                    int32_t audiobits_a, audiobits_b;                    audiobits_a = readbits(alac, alac->setinfo_sample_size);                    audiobits_b = readbits(alac, alac->setinfo_sample_size);                    audiobits_a = SIGN_EXTENDED32(audiobits_a, alac->setinfo_sample_size);                    audiobits_b = SIGN_EXTENDED32(audiobits_b, alac->setinfo_sample_size);                    alac->outputsamples_buffer_a[i] = audiobits_a;                    alac->outputsamples_buffer_b[i] = audiobits_b;                }            }            else            {                int i;                for (i = 0; i < outputsamples; i++)                {                    int32_t audiobits_a, audiobits_b;                    audiobits_a = readbits(alac, 16);                    audiobits_a = audiobits_a << 16;                    audiobits_a = audiobits_a >> (32 - alac->setinfo_sample_size);                    audiobits_a |= readbits(alac, alac->setinfo_sample_size - 16);                    audiobits_b = readbits(alac, 16);                    audiobits_b = audiobits_b << 16;                    audiobits_b = audiobits_b >> (32 - alac->setinfo_sample_size);                    audiobits_b |= readbits(alac, alac->setinfo_sample_size - 16);                    alac->outputsamples_buffer_a[i] = audiobits_a;                    alac->outputsamples_buffer_b[i] = audiobits_b;                }            }            /* wasted_bytes = 0; */            interlacing_shift = 0;            interlacing_leftweight = 0;        }        switch(alac->setinfo_sample_size)        {        case 16:        {            deinterlace_16(alac->outputsamples_buffer_a,                           alac->outputsamples_buffer_b,                           (int16_t*)outbuffer,                           alac->numchannels,                           outputsamples,                           interlacing_shift,                           interlacing_leftweight);            break;        }        case 20:        case 24:        case 32:            fprintf(stderr, "FIXME: unimplemented sample size %i\n", alac->setinfo_sample_size);            break;        default:            break;        }        break;    }    }}alac_file *create_alac(int samplesize, int numchannels){    alac_file *newfile = malloc(sizeof(alac_file));    newfile->samplesize = samplesize;    newfile->numchannels = numchannels;    newfile->bytespersample = (samplesize / 8) * numchannels;    return newfile;}

⌨️ 快捷键说明

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