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

📄 output.c

📁 aac解码器源程序在Visual C++下的实现
💻 C
📖 第 1 页 / 共 2 页
字号:
            {                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);                inp *= 65536.0f;                CLIP(inp, 2147483647.0f, -2147483648.0f);                (*sample_buffer)[(i*channels)+ch] = (int32_t)lrintf(inp);            }        }        break;    }}static void to_PCM_float(NeAACDecHandle hDecoder, real_t **input,                         uint8_t channels, uint16_t frame_len,                         float32_t **sample_buffer){    uint8_t ch, ch1;    uint16_t i;    switch (CONV(channels,hDecoder->downMatrix))    {    case CONV(1,0):    case CONV(1,1):        for(i = 0; i < frame_len; i++)        {            real_t inp = input[hDecoder->internal_channel[0]][i];            (*sample_buffer)[i] = inp*FLOAT_SCALE;        }        break;    case CONV(2,0):        if (hDecoder->upMatrix)        {            ch = hDecoder->internal_channel[0];            for(i = 0; i < frame_len; i++)            {                real_t inp0 = input[ch][i];                (*sample_buffer)[(i*2)+0] = inp0*FLOAT_SCALE;                (*sample_buffer)[(i*2)+1] = inp0*FLOAT_SCALE;            }        } else {            ch  = hDecoder->internal_channel[0];            ch1 = hDecoder->internal_channel[1];            for(i = 0; i < frame_len; i++)            {                real_t inp0 = input[ch ][i];                real_t inp1 = input[ch1][i];                (*sample_buffer)[(i*2)+0] = inp0*FLOAT_SCALE;                (*sample_buffer)[(i*2)+1] = inp1*FLOAT_SCALE;            }        }        break;    default:        for (ch = 0; ch < channels; ch++)        {            for(i = 0; i < frame_len; i++)            {                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);                (*sample_buffer)[(i*channels)+ch] = inp*FLOAT_SCALE;            }        }        break;    }}static void to_PCM_double(NeAACDecHandle hDecoder, real_t **input,                          uint8_t channels, uint16_t frame_len,                          double **sample_buffer){    uint8_t ch, ch1;    uint16_t i;    switch (CONV(channels,hDecoder->downMatrix))    {    case CONV(1,0):    case CONV(1,1):        for(i = 0; i < frame_len; i++)        {            real_t inp = input[hDecoder->internal_channel[0]][i];            (*sample_buffer)[i] = (double)inp*FLOAT_SCALE;        }        break;    case CONV(2,0):        if (hDecoder->upMatrix)        {            ch = hDecoder->internal_channel[0];            for(i = 0; i < frame_len; i++)            {                real_t inp0 = input[ch][i];                (*sample_buffer)[(i*2)+0] = (double)inp0*FLOAT_SCALE;                (*sample_buffer)[(i*2)+1] = (double)inp0*FLOAT_SCALE;            }        } else {            ch  = hDecoder->internal_channel[0];            ch1 = hDecoder->internal_channel[1];            for(i = 0; i < frame_len; i++)            {                real_t inp0 = input[ch ][i];                real_t inp1 = input[ch1][i];                (*sample_buffer)[(i*2)+0] = (double)inp0*FLOAT_SCALE;                (*sample_buffer)[(i*2)+1] = (double)inp1*FLOAT_SCALE;            }        }        break;    default:        for (ch = 0; ch < channels; ch++)        {            for(i = 0; i < frame_len; i++)            {                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);                (*sample_buffer)[(i*channels)+ch] = (double)inp*FLOAT_SCALE;            }        }        break;    }}void *output_to_PCM(NeAACDecHandle hDecoder,                    real_t **input, void *sample_buffer, uint8_t channels,                    uint16_t frame_len, uint8_t format){    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;    float32_t *float_sample_buffer = (float32_t*)sample_buffer;    double    *double_sample_buffer = (double*)sample_buffer;#ifdef PROFILE    int64_t count = faad_get_ts();#endif    /* Copy output to a standard PCM buffer */    switch (format)    {    case FAAD_FMT_16BIT:        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);        break;    case FAAD_FMT_24BIT:        to_PCM_24bit(hDecoder, input, channels, frame_len, &int_sample_buffer);        break;    case FAAD_FMT_32BIT:        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);        break;    case FAAD_FMT_FLOAT:        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);        break;    case FAAD_FMT_DOUBLE:        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);        break;    }#ifdef PROFILE    count = faad_get_ts() - count;    hDecoder->output_cycles += count;#endif    return sample_buffer;}#else#define DM_MUL FRAC_CONST(0.3203772410170407) // 1/(1+sqrt(2) + 1/sqrt(2))#define RSQRT2 FRAC_CONST(0.7071067811865475244) // 1/sqrt(2)static INLINE real_t get_sample(real_t **input, uint8_t channel, uint16_t sample,                                uint8_t down_matrix, uint8_t up_matrix,                                uint8_t *internal_channel){    if (up_matrix == 1)        return input[internal_channel[0]][sample];    if (!down_matrix)        return input[internal_channel[channel]][sample];    if (channel == 0)    {        real_t C   = MUL_F(input[internal_channel[0]][sample], RSQRT2);        real_t L_S = MUL_F(input[internal_channel[3]][sample], RSQRT2);        real_t cum = input[internal_channel[1]][sample] + C + L_S;        return MUL_F(cum, DM_MUL);    } else {        real_t C   = MUL_F(input[internal_channel[0]][sample], RSQRT2);        real_t R_S = MUL_F(input[internal_channel[4]][sample], RSQRT2);        real_t cum = input[internal_channel[2]][sample] + C + R_S;        return MUL_F(cum, DM_MUL);    }}void* output_to_PCM(NeAACDecHandle hDecoder,                    real_t **input, void *sample_buffer, uint8_t channels,                    uint16_t frame_len, uint8_t format){    uint8_t ch;    uint16_t i;    int16_t *short_sample_buffer = (int16_t*)sample_buffer;    int32_t *int_sample_buffer = (int32_t*)sample_buffer;    /* Copy output to a standard PCM buffer */    for (ch = 0; ch < channels; ch++)    {        switch (format)        {        case FAAD_FMT_16BIT:            for(i = 0; i < frame_len; i++)            {                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,                    hDecoder->internal_channel);                if (tmp >= 0)                {                    tmp += (1 << (REAL_BITS-1));                    if (tmp >= REAL_CONST(32767))                    {                        tmp = REAL_CONST(32767);                    }                } else {                    tmp += -(1 << (REAL_BITS-1));                    if (tmp <= REAL_CONST(-32768))                    {                        tmp = REAL_CONST(-32768);                    }                }                tmp >>= REAL_BITS;                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;            }            break;        case FAAD_FMT_24BIT:            for(i = 0; i < frame_len; i++)            {                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,                    hDecoder->internal_channel);                if (tmp >= 0)                {                    tmp += (1 << (REAL_BITS-9));                    tmp >>= (REAL_BITS-8);                    if (tmp >= 8388607)                    {                        tmp = 8388607;                    }                } else {                    tmp += -(1 << (REAL_BITS-9));                    tmp >>= (REAL_BITS-8);                    if (tmp <= -8388608)                    {                        tmp = -8388608;                    }                }                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;            }            break;        case FAAD_FMT_32BIT:            for(i = 0; i < frame_len; i++)            {                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,                    hDecoder->internal_channel);                if (tmp >= 0)                {                    tmp += (1 << (16-REAL_BITS-1));                    tmp <<= (16-REAL_BITS);                } else {                    tmp += -(1 << (16-REAL_BITS-1));                    tmp <<= (16-REAL_BITS);                }                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;            }            break;        case FAAD_FMT_FIXED:            for(i = 0; i < frame_len; i++)            {                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,                    hDecoder->internal_channel);                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;            }            break;        }    }    return sample_buffer;}#endif

⌨️ 快捷键说明

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