?? mp3eutil.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_parse_cmdline_mp3()
// buffer_copy_audio()
// buffer_set_audio()
// encoder_flushbitstream_mp3()
******************************************************************************/
#include <malloc.h>
#include <memory.h>
#include "sampmp3.h"
/******************************************************************************
// Name: buffer_copy_audio
// Description: copy content of one buffer to another buffer
// Input Arguments : src - pointer to input buffer.
// len - length for copy.
// Output Arguments: dst - pointer to output buffer.
// Returns: N/A
******************************************************************************/
void buffer_copy_audio(const Ipp32s * src, Ipp32s * dst, int len)
{
int i;
for (i = 0; i < len; i++) {
dst[i] = src[i];
}
return;
}
/******************************************************************************
// Name: buffer_set_audio
// Description: set the content of buffer to be a const.
// Input Arguments : val - value to set the buffer.
// len - buffer length for set.
// Output Arguments: dst - pointer to output buffer.
// Returns: N/A
******************************************************************************/
void buffer_set_audio(Ipp32s val, Ipp32s * dst, int len)
{
int i;
for ( i = 0; i < len; i ++ ) {
dst[i] = val;
}
return;
}
/******************************************************************************
// Name: free_align_mem_mp3
// Description: Free aligned memory blocks
//
// Input Arguments:
// buf_addr_ptr Pointer to the void pointer to the allocated space
// with alignment off_set.
//
// Output Arguments:
// buf_addr_ptr Pointer to a NULL void pointer
//
// Returns:
// SAMPLE_STATUS_NOERR If succeeds
******************************************************************************/
sample_status free_align_mem_mp3(void **buf_addr_ptr)
{
Ipp8u off_set = 0;
Ipp8u *addr = NULL;
addr = (Ipp8u*)(*buf_addr_ptr);
off_set = *(addr - 1);
addr -= off_set;
free((void*)addr);
*buf_addr_ptr = NULL;
return SAMPLE_STATUS_NOERR;
}
/******************************************************************************
// Name: alloc_align_mem_mp3
// Description: Allocate aligned memory blocks
//
// Input Arguments:
// buf_addr_ptr Pointer to the void pointer to the allocated space
// size Number of bytes to be allocated
// alignstatus Number of bytes to be aligned, e.g., 2 for half
// word aligned, 4 for word aligned, 8 for double word
// aligned
//
// Output Arguments:
// buf_addr_ptr Pointer to the void pointer to the allocated space
//
// Returns:
// SAMPLE_STATUS_NOERR If succeeds
// SAMPLE_STATUS_NOMEM_ERR If memory allocation fails
******************************************************************************/
sample_status alloc_align_mem_mp3(void **buf_addr_ptr,
int size,
int alignstatus)
{
Ipp8u *addr = NULL;
Ipp8u tmp = 0;
size += alignstatus;
addr = malloc(size);
if (!addr) {
*buf_addr_ptr = NULL;
return SAMPLE_STATUS_NOMEM_ERR;
}
tmp = (Ipp8u)((Ipp32u)(addr) & (alignstatus - 1));
tmp = (Ipp8u)(alignstatus - tmp);
addr += tmp;
*(addr - 1) = tmp;
*buf_addr_ptr = (void*)addr;
return SAMPLE_STATUS_NOERR;
}
/******************************************************************************
// Name: encoder_flushbitstream_mp3
// Description: flush the encoded data into output buffer.
// Input Arguments : enc_state - pointer to encode state structure.
// Output Arguments: stream_buf - pointer to output structure.
// Returns: N/A
******************************************************************************/
void encoder_flushbitstream_mp3(mp3_enc_state *enc_state,
sample_bitstream *stream_buf)
{
int i,j;
int bytes_per_frame;
int maindataindex;
int bytesbuffered;
int bufferedframeindex;
int bufferedmaindataindex;
int bufferedframe_num;
/*Check if the bits are enough to flush*/
maindataindex = enc_state->bufferedframe_index - \
enc_state->bufferedframe_num;
bufferedframe_num = enc_state->bufferedframe_num;
if(maindataindex < 0) {
maindataindex +=9;
}
bytesbuffered = enc_state->hdsi_len;
for ( i = maindataindex; i < maindataindex + bufferedframe_num; i ++ ) {
j = i;
if (i>=9) {
j-=9;
}
bytesbuffered += enc_state->mdframe_buf_len[j];
}
bufferedframeindex = maindataindex;
bufferedmaindataindex = bufferedframeindex;
bytes_per_frame = enc_state->frame_len[bufferedframeindex];
if ( bytesbuffered > bytes_per_frame ) {
int len1, len2;
/* Flush header information and side infomation */
for ( i = 0; i < enc_state->hdsi_len; i ++ ) {
*stream_buf->bs_cur_byte ++ = enc_state->hdsi_buf\
[bufferedframeindex*enc_state->hdsi_len+i];
}
len1 = bytes_per_frame - enc_state->hdsi_len;
/* Flush main data */
while ( len1 > 0 && bufferedframe_num > 0 ) {
len2 = IPP_MIN(len1, enc_state->mdframe_buf_len\
[bufferedmaindataindex]);
j = 0;
for (j = 0; j < len2; i ++, j ++ ) {
*stream_buf->bs_cur_byte ++ = enc_state->mdframe_buf_ptr\
[bufferedmaindataindex][j];
}
len1 -= len2;
enc_state->mdframe_buf_len[bufferedmaindataindex] -= len2;
enc_state->mdframe_buf_ptr[bufferedmaindataindex] += len2;
bufferedmaindataindex ++;
if(bufferedmaindataindex == 9) {
bufferedmaindataindex =0;
}
}
bufferedframe_num --;
}
enc_state->bufferedframe_num = bufferedframe_num;
return;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -