?? mp3einit.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) 2003 Intel Corporation. All Rights Reserved.//// Description:// Intel(R) Integrated Performance Primitives Sample Code MP3 Encoder// // Function List:// encoder_init_alloc_mp3()// encoder_free_mp3()******************************************************************************/#include "sampmp3.h"/******************************************************************************// Name: encoder_init_alloc_mp3// Description: Initialize for MP3 encoder.// Input Arguments : enc_state - pointer to encoder state structure.// Output Arguments: sound - pointer to sound structure.// stream_buf - pointer to stream structure.// enc_state - pointer to updated encoder state structure.// Returns: // SAMPLE_STATUS_BADARG_ERR - Bad argument// SAMPLE_STATUS_NOERR - Initialize successfully******************************************************************************/sample_status encoder_init_alloc_mp3(sample_sound *sound, sample_bitstream *stream_buf, mp3_enc_state *enc_state){ int headsideInfo_length; int bit_rate; int sampling_freq; IppMP3FrameHeader *frame_header; IppMP3EncPsychoAcousticModel2State *psy_state; IppMP3PsychoacousticModelTwoAnalysis *psy_info; int i,j,k; int buf_size; int align; /* Bad argument check */ if(!(sound && stream_buf && enc_state)) { return SAMPLE_STATUS_BADARG_ERR; } /* Allocate buffer for input PCM */ buf_size = (enc_state->channel_num == 1)?2304: 4608; align = 2; if (alloc_align_mem_mp3((void*)&sound->snd_frame, buf_size, align) != SAMPLE_STATUS_NOERR) { return SAMPLE_STATUS_NOMEM_ERR; } /* Initialize sound structure */ sound->snd_len = (enc_state->channel_num == 1)?2304:4608; sound->snd_channel_num = enc_state->channel_num; sound->snd_sample_rate = mpeg1_samplerate_table[enc_state->sample_rate]; /* Allocate buffer for input PCM */ buf_size = 1024*8 + 1; align = 1; if (alloc_align_mem_mp3((void*)&stream_buf->bs_buffer, buf_size, align) != SAMPLE_STATUS_NOERR) { return SAMPLE_STATUS_NOMEM_ERR; } /* Initialize output bit stream structure */ stream_buf->bs_bytelen = MP3_STREAMBUF_SIZE; stream_buf->bs_cur_byte = stream_buf->bs_buffer; stream_buf->bs_cur_bitoffset = 0; /* Initialize encode state structure */ headsideInfo_length = 4 + ((enc_state->channel_num == 2)?32:17); enc_state->hdsi_len = headsideInfo_length; enc_state->bytes_per_frame = mpeg1_slot_table[enc_state->sample_rate]\ [enc_state->bitrate_index]; enc_state->bits_per_frame = ((enc_state->bytes_per_frame) <<3); enc_state->meanbits_num = enc_state->bits_per_frame - ((enc_state->hdsi_len)<<3); /* enc_state->frame_byte_dif is used to detemine whether //or not to use padding */ bit_rate = mpeg1_bitrate_table[enc_state->bitrate_index]; sampling_freq = mpeg1_samplerate_table[enc_state->sample_rate]; enc_state->frame_byte_dif = 144 * bit_rate - \ ( enc_state->bytes_per_frame) * sampling_freq; /* Initialize the header and side info buffer */ enc_state->hdsi_buf_ptr = enc_state->hdsi_buf; for(i=0; i<MP3_HEADERSIDEINFOBUF_SIZE; i++) { enc_state->hdsi_buf_ptr[i] = 0; } /* Initialize the main data buffer */ enc_state->cur_maindata_buf = enc_state->maindata_buf; for(i=0; i<MP3_MAINDATABUF_SIZE; i++) { enc_state->cur_maindata_buf[i] = 0; } /* Initialize the scalefactor buffer */ for(i = 0; i < IPP_MP3_SF_BUF_LEN*MP3_MAXGRANNULE_NUM*MP3_MAXCHANNEL_NUM; i ++) { enc_state->scale_factor[i] = 0; } /* Initialize the scalefactor selection info */ for(i = 0; i < MP3_SCFBANDGROUP_NUM*IPP_MP3_CHANNEL_NUM; i ++) { enc_state->scfsi[i] = 0; } for(i=0; i<6; i++) { enc_state->is_sfb_bound[i] = 0; } for(i = 0; i < MP3_FRAME_LEN; i ++) { enc_state->overlap_buf[i] = 0; } /* Initialize the input PCM buffer */ for(i = 0; i < MP3_INPUTPCMBUF_SIZE; i ++) { enc_state->pcm_state_buf[i] = 0; } buffer_set_audio(0, enc_state->work_buf, MP3_WORKBUF_SIZE); enc_state->rest = 0; /*Initialize the psycho-acoustic model status */ for(i = 0; i < MP3_MAXGRANPERFRAME_NUM; i ++) { psy_state = &(enc_state->psy_state[i]); for(j = 0; j < 2; j ++) { for(k = 0; k < IPP_MP3_PSY_BAND_LONG_NUM; k ++) { psy_state->pPrevMaskedThresholdLong[j][k] = (Ipp64s)0; } for(k = 0; k < FIRST_6_CW; k ++) { psy_state->pPrevFFT[j][k].re = 0; psy_state->pPrevFFT[j][k].im = 0; psy_state->pPrevFFTMag[j][k] = 0; } } for(j = 0; j < IPP_MP3_PSY_BAND_SHORT_NUM; j ++) { psy_state->pPrevMaskedThresholdShort[j] = 0; } psy_state->nextPerceptualEntropy = 0; psy_state->nextBlockType = 0; for(j = 0; j < IPP_MP3_SF_BUF_LEN; j ++) { psy_state->pNextMSRLong[j] = 0; psy_state->pNextMSRShort[j] = 0; } } /* Initialize the psycho-acoustic model output info */ for(i=0;i<MP3_MAXGRANPERFRAME_NUM;i++) { psy_info = &(enc_state->psy_info[i]); for(j=0; j< 36; j++) { psy_info->pPsyMSR[j] = 0; } psy_info->PE = 0; } /* Initialize the output buffer control information */ buffer_set_audio(0, &(enc_state->bufferedframe_num), 1); buffer_set_audio(0, &(enc_state->bufferedframe_index),1); buffer_set_audio(0, enc_state->mdframe_buf_len, MP3_MAXBUFFEREDFRAME_NUM); buffer_set_audio(0, enc_state->frame_len, MP3_MAXBUFFEREDFRAME_NUM); for(i =0; i<MP3_MAXBUFFEREDFRAME_NUM; i++) { enc_state->mdframe_buf_ptr[i] = NULL; } /* Initialize frame header */ frame_header = &enc_state->frame_header; frame_header->samplingFreq = enc_state->sample_rate; frame_header->bitRate = enc_state->bitrate_index; frame_header->id = 1; if(enc_state->channel_num == 2) { frame_header->mode = 1; frame_header->modeExt = 2; } else { frame_header->mode = 3; frame_header->modeExt = 0; } frame_header->layer = 1; frame_header->protectionBit = 1; frame_header->paddingBit = 1; frame_header->privateBit = 0; frame_header->copyright = 0; frame_header->originalCopy = 0; frame_header->emphasis = 0; frame_header->CRCWord = 0; /* Intialize the bit reservoir */ ippsBitReservoirInit_MP3(&(enc_state->bit_resv), frame_header); return SAMPLE_STATUS_NOERR;} sample_status encoder_free_mp3(sample_sound *sound, sample_bitstream *stream_buf){ /* Free buffer for input PCM */ free_align_mem_mp3((void*)&sound->snd_frame); /* Free buffer for output bit stream */ free_align_mem_mp3((void*)&stream_buf->bs_buffer); return SAMPLE_STATUS_NOERR;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -