📄 mp3enc_api_fp.c
字号:
/*//////////////////////////////////////////////////////////////////////////////
//
// INTEL CORPORATION PROPRIETARY INFORMATION
// This software is supplied under the terms of a license agreement or
// nondisclosure agreement with Intel Corporation and may not be copied
// or disclosed except in accordance with the terms of that agreement.
// Copyright(c) 2002-2007 Intel Corporation. All Rights Reserved.
//
*/
#include "mp3enc_own_fp.h"
MP3Status mp3encUpdateMemMap(MP3Enc *state, Ipp32s shift)
{
Ipp32s i;
for (i = 0; i < 32; i++) {
MP3_UPDATE_PTR(void, state->com.htables[i].phuftable, shift)
}
// MP3_UPDATE_PTR(IppsMDCTFwdSpec_32f, state->pMDCTSpec12, shift)
// MP3_UPDATE_PTR(IppsMDCTFwdSpec_32f, state->pMDCTSpec36, shift)
MP3_UPDATE_PTR(Ipp8u, state->pMDCTbuf, shift)
MP3_UPDATE_PTR(IppsFFTSpec_R_32f, state->pa_pFFTSpecShort, shift)
MP3_UPDATE_PTR(IppsFFTSpec_R_32f, state->pa_pFFTSpecLong, shift)
MP3_UPDATE_PTR(Ipp8u, state->pa_pBuffer, shift)
MP3_UPDATE_PTR(Ipp8u, state->pqmf_mem, shift)
for (i = 0; i < NUM_CHANNELS; i++) {
MP3_UPDATE_PTR(IppsFilterSpec_PQMF_MP3, state->pPQMFSpec[i], shift)
}
for (i = 0; i < 3; i++) {
MP3_UPDATE_PTR(samplefbout, state->fbout[i], shift);
}
return MP3_OK;
}
static void mp3encInit_layer1(MP3Enc *state)
{
Ipp32s sb, ch, s;
Ipp32s bit_rate, sblimit_real;
if (state) {
state->com.sblimit = 32;
bit_rate = mp3_bitrate[state->com.header.id][state->com.header.layer - 1][state->com.header.bitRate] >>
(state->com.stereo - 1);
if (state->com.header.id == 0)
bit_rate <<= 1;
if (bit_rate >= 128) {
sblimit_real = 28;
} else if (bit_rate >= 96) {
sblimit_real = 23;
} else if (bit_rate >= 56) {
sblimit_real = 22;
} else {
sblimit_real = 16;
}
state->com.sblimit_real = sblimit_real;
for(sb = 0; sb < 32; sb++)
for(ch = 0; ch < 2; ch++)
state->com.allocation[ch][sb] = 0;
for(sb = 0; sb < 32; sb++)
for(ch = 0; ch < 2; ch++)
state->com.scalefactor_l1[ch][sb] = 0;
for(s = 0; s < 12; s++)
for(sb = 0; sb < 32; sb++)
for(ch = 0; ch < 2; ch++)
state->com.sample[ch][sb][s] = 0;
}
}
static void mp3encInit_layer2(MP3Enc *state)
{
Ipp32s sb, ch, s;
Ipp32s bit_rate, sblimit_real;
if (state) {
mp3_SetAllocTable(state->com.header.id,
0,
state->com.header.layer,
state->com.header.bitRate,
state->com.header.samplingFreq,
state->com.stereo,
&state->com.nbal_alloc_table,
&state->com.alloc_table,
&state->com.sblimit);
state->com.mc_sblimit = state->com.sblimit;
state->com.mc_tc_sbgr_select = 1;
bit_rate = mp3_bitrate[state->com.header.id][state->com.header.layer - 1][state->com.header.bitRate] >>
(state->com.stereo - 1);
if (state->com.header.id == 0)
bit_rate <<= 1;
if (state->com.stereo_mode_param == MPA_JOINT_STEREO && bit_rate > 48)
state->com.stereo_mode_param = MPA_LR_STEREO;
if (bit_rate >= 128) {
sblimit_real = 28;
} else if (bit_rate >= 96) {
sblimit_real = 23;
} else if (bit_rate >= 56) {
sblimit_real = 22;
} else {
sblimit_real = 32;
}
if (sblimit_real > state->com.sblimit)
sblimit_real = state->com.sblimit;
state->com.sblimit_real = sblimit_real;
state->com.jsbound = state->com.sblimit;
for(sb = 0; sb < 32; sb++)
for(ch = 0; ch < NUM_CHANNELS; ch++)
state->com.allocation[ch][sb] = 0;
for(ch = 0; ch < NUM_CHANNELS; ch++)
for (s = 0; s < 3; s++)
for(sb = 0; sb < 32; sb++)
state->com.scalefactor[ch][s][sb] = 0;
for(s = 0; s < 36; s++)
for(sb = 0; sb < 32; sb++)
for(ch = 0; ch < NUM_CHANNELS; ch++)
state->com.sample[ch][sb][s] = 0;
}
}
static void mp3encInit_layer3(MP3Enc *state, Ipp32s ns_mode, Ipp8u *mem, Ipp32s *size_all)
{
Ipp32s j;
Ipp32u *sfb_long, *sfb_short;
Ipp32s sfb_l_max = 0, sfb_s_max = 0;
Ipp32s size, ts;
size = 0;
mp3enc_mdctInit(state, mem, &ts);
size += ts;
if (mem) mem += ts;
mp3enc_huffInit(mem ? state->com.htables : NULL, mem, &ts);
size += ts;
if (mem) mem += ts;
if(state) {
state->com.si_main_data_begin = 0;
state->com.main_data_ptr = 0;
state->com.resr_bytes = 0;
state->com.resr_mod_slot = 0;
state->com.quant_mode_fast = 0;
state->com.ns_mode = ns_mode;
sfb_long = mp3enc_sfBandIndex[state->com.header.id][state->com.header.samplingFreq].l;
sfb_short = mp3enc_sfBandIndex[state->com.header.id][state->com.header.samplingFreq].s;
for (j = 0; j < SBBND_L; j++)
if ((Ipp32s)sfb_long[j] < state->com.lowpass_maxline * 18)
sfb_l_max = j + 1;
for (j = 0; j < SBBND_S; j++)
if ((Ipp32s)sfb_short[j] * 3 < state->com.lowpass_maxline * 18)
sfb_s_max = j + 1;
state->com.sfb_l_max = sfb_l_max;
state->com.sfb_s_max = sfb_s_max;
state->common_scalefactor_update[0] = 2;
state->common_scalefactor_update[1] = 2;
state->last_frame_common_scalefactor[0] = 210;
state->last_frame_common_scalefactor[1] = 210;
state->com.si_private_bits = 0;
state->com.si_beg = 0;
state->com.si_new = 0;
state->com.si_num = 0;
if (state->com.header.id)
state->com.grnum = 2;
else
state->com.grnum = 1;
state->fbout_prev = 0;
for (j = 0; j < 3; j++) {
Ipp32s ind;
ind = state->fbout_prev + j;
if (ind > 2) ind -= 3;
state->fbout[j] = &state->fbout_data[ind];
}
}
if(size_all)
*size_all = size;
}
static Ipp32s mp3encCalcSlotSize(MP3Enc *state) {
IppMP3FrameHeader *header = &state->com.header;
Ipp32s i, size;
for (i = 1; i < 15; i++) {
size = 0;
header->paddingBit = 0;
if (header->layer == 3) {
size = 72000 * (header->id + 1);
} else if (header->layer == 2) {
size = 72000 * 2;
} else if (header->layer == 1) {
size = 12000;
}
size = size * mp3_bitrate[header->id][header->layer - 1][i] /
mp3_frequency[header->id][header->samplingFreq];
if (header->layer == 1)
size *= 4;
state->com.slot_sizes[i] = size;
}
state->com.slot_size = state->com.slot_sizes[header->bitRate];
/*
up = state->com.frameSize * mp3enc_bitrate[header->layer-1][header->bitRate] * 1000;
state->com.slot_size = up / (mp3enc_frequency[header->samplingFreq] << 3);
l = state->com.slot_size * mp3enc_frequency[header->samplingFreq] << 3;
if (up - l < mp3enc_frequency[header->samplingFreq] << 2)
header->paddingBit = 0;
else
header->paddingBit = 1;
state->com.slot_size += header->paddingBit;*/
return 0;
}
MP3Status mp3encInit(MP3Enc *state,
Ipp32s sampling_frequency,
Ipp32s stereo,
Ipp32s channel_mask,
Ipp32s layer,
Ipp32s bitrate,
Ipp32s br_mode,
Ipp32s stereo_mode,
Ipp32s ns_mode,
Ipp32s force_mpeg1,
Ipp32s dematrix_procedure,
Ipp32s mc_lfe_filter_off,
Ipp32s *size_all)
{
Ipp32s j;
Ipp32f cutoff_frequency;
Ipp32f samp_rate_per_ch;
Ipp32s freq, id, br, upsample = 0;
Ipp32s size, ts;
Ipp8u *mem;
Ipp32s channels, mc_center, mc_surround, mc_lfe, mc_conf, mc_channel;
mc_center = mc_surround = mc_lfe = mc_conf = 0;
mc_channel = 0;
size = 0;
mem = NULL;
switch (sampling_frequency) {
case 44100:
freq = 0;
id = 1;
break;
case 48000:
freq = 1;
id = 1;
break;
case 32000:
freq = 2;
id = 1;
break;
case 22050:
freq = 0;
id = 0;
break;
case 24000:
freq = 1;
id = 0;
break;
case 16000:
freq = 2;
id = 0;
break;
case 11025:
freq = 0;
upsample = 1;
id = 0;
break;
case 12000:
freq = 1;
id = 0;
upsample = 1;
break;
case 8000:
freq = 2;
id = 0;
upsample = 1;
break;
default:
return MP3_FAILED_TO_INITIALIZE;
}
if (layer < 1 || layer > 3) {
return MP3_FAILED_TO_INITIALIZE;
}
if (ns_mode < 0 || ns_mode > 1) {
return MP3_FAILED_TO_INITIALIZE;
}
if (mc_lfe_filter_off < 0 || mc_lfe_filter_off > 1) {
return MP3_FAILED_TO_INITIALIZE;
}
if (br_mode != MPAENC_CBR && br_mode != MPAENC_ABR) {
return MP3_FAILED_TO_INITIALIZE;
}
if (layer == 2) {
Ipp32s chnum = 0;
channels = stereo;
stereo = 0;
if (!channel_mask) {
switch(channels) {
case 1:
channel_mask = MP3_CHANNEL_CENTER;
break;
case 2:
channel_mask = MP3_CHANNEL_STEREO;
break;
case 3:
channel_mask = MP3_CHANNEL_CENTER;
channel_mask |= MP3_CHANNEL_STEREO;
break;
case 4:
channel_mask = MP3_CHANNEL_CENTER;
channel_mask |= MP3_CHANNEL_STEREO;
channel_mask |= MP3_CHANNEL_LOW_FREQUENCY;
break;
case 5:
channel_mask = MP3_CHANNEL_CENTER;
channel_mask |= MP3_CHANNEL_STEREO;
channel_mask |= MP3_CHANNEL_SURROUND_STEREO;
break;
case 6:
channel_mask = MP3_CHANNEL_CENTER;
channel_mask |= MP3_CHANNEL_STEREO;
channel_mask |= MP3_CHANNEL_SURROUND_STEREO;
channel_mask |= MP3_CHANNEL_LOW_FREQUENCY;
break;
default:
vm_debug_trace(VM_DEBUG_ERROR, VM_STRING("Unsupported channel number\n"));
return MP3_FAILED_TO_INITIALIZE;
}
}
if (channel_mask & MP3_CHANNEL_STEREO) {
if (channel_mask & MP3_CHANNEL_CENTER) {
chnum += 3;
stereo = 2;
mc_center = 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -