📄 paac.c
字号:
/* Copyright (C) 2007 ROCK-CHIPS FUZHOU . All Rights Reserved. */
/*
File : \Audio\AACDec
Desc : AAC解码。
Author : evanwu , Vincent Hisung ,fsh
Date : 2007-08-xx
Notes : 功能尚未完整实现[可搜索TODO]
$Log :
* evanwu 2007/08/xx 建立此文件
*
* vincent 2007/08/xx 修正BUG
* fsh 2007/12/15 bitrate update
*/
/****************************************************************/
#include <string.h>
#include "../include/audio_main.h"
#ifdef AAC_DEC_INCLUDE
#include "aacdec.h"
#include "../include/audio_globals.h"
#include "../include/file_access.h"
#define READBUF_SIZE (2 * AAC_MAINBUF_SIZE * AAC_MAX_NCHANS) /* pick something big enough to hold a bunch of frames */
#define SKIP_FRAMES 0 /* discard first SKIP_FRAMES decoded frames */
#ifdef AAC_ENABLE_SBR
#define SBR_MUL 2
#else
#define SBR_MUL 1
#endif
#define ARMULATE_MUL_FACT 1
#define MAX_FRAMES -1
//Global
short * aac_OutLeft = NULL;
short * aac_OutRight = NULL;
//Local
static short outBuf[AAC_MAX_NCHANS * AAC_MAX_NSAMPS * SBR_MUL];
static unsigned char readBuf[READBUF_SIZE];
static int nRead;
static AACFrameInfo aacFrameInfo;
static HAACDecoder *hAACDecoder;
static int bytesLeft = 0;
static int eofReached = 0;
static unsigned char *readPtr = readBuf;
static int err = 0;
static int skipFrames = SKIP_FRAMES;
static int nFramesTNSOn = 0;
static int nFramesTNSOff = 0;
static long OutLength;
extern short VideoPlaying;
//****************************************************************************
//
// Data Read for the AAC decoder.
//
//****************************************************************************
static int FillReadBuffer(unsigned char *readBuf, unsigned char *readPtr, int bufSize, int bytesLeft, MY_FILE *infile)
{
int nRead;
/* move last, small chunk from end of buffer to start, then fill with new data */
memmove(readBuf, readPtr, bytesLeft);
nRead = RKFIO_FRead(pRawFileCache, readBuf + bytesLeft, bufSize - bytesLeft);
/* zero-pad to avoid finding false sync word after last frame (from old data in readBuf) */
if (nRead < bufSize - bytesLeft)
memset(readBuf + bytesLeft + nRead, 0, bufSize - bytesLeft - nRead);
return nRead;
}
//****************************************************************************
//
// The codec plug-in entry point for the AAC decoder.
//
//****************************************************************************
//功能实现情况:
//SUBFN_CODEC_GETNAME : 不支持
//SUBFN_CODEC_GETARTIST: 不支持
//SUBFN_CODEC_GETTITLE : 不支持
//SUBFN_CODEC_GETBITRATE: 得到码率
//SUBFN_CODEC_GETSAMPLERATE: 得到采样率
//SUBFN_CODEC_GETCHANNELS: 得到声道数目
//SUBFN_CODEC_GETLENGTH : 不支持
//SUBFN_CODEC_GETTIME : 不支持
//SUBFN_CODEC_OPEN_DEC : 打开解码器(初始化)
//SUBFN_CODEC_SETBUFFER: 不支持
//SUBFN_CODEC_DECODE : 解码
//SUBFN_CODEC_ENCODE : 不支持
//SUBFN_CODEC_SEEK : 按时间直接定位 [单位:毫秒]
//SUBFN_CODEC_CLOSE : 关闭解码器
/******************************************************
Name: AACDecFunction
Desc: AAC解码器接口函数
Param: ulIoctl 子功能号
ulParam1 子功能参数1
ulParam2 子功能参数2
ulParam3 子功能参数3
ulParam4 子功能参数4
Return: 0-失败 1-成功
Global: 无
Note: 无
Author: evan wu
Log:
******************************************************/
int tst = 0;
unsigned long
AACDecFunction(unsigned long ulSubFn, unsigned long ulParam1, unsigned long ulParam2,
unsigned long ulParam3, unsigned long ulParam4)
{
// Determine what to do based on the specified IOCTL.
switch (ulSubFn)
{
case SUBFN_CODEC_GETCAPTUREBUFFER:
{
*(unsigned long *)ulParam2 = (unsigned long) aac_OutLeft ;
*(unsigned long *)ulParam3 = (unsigned long) aac_OutRight;
*(unsigned long *)ulParam4 = (unsigned long) OutLength ;
return(1);
}
// Return the name for this codec.
case SUBFN_CODEC_GETNAME:
{
char **ppcName;
// The secod parameter is a pointer for the name.
ppcName = (char **)ulParam2;
// Return the name of this codec. The first four characters are
// the short name and the string starting at the fifth character
// is the long name.
*ppcName = "AAC Decoder";
// Success.
return(1);
}
// Return the name of the artist.
case SUBFN_CODEC_GETARTIST:
{
//TODO !
// Success.
return(1);
}
// Return the name of the song
case SUBFN_CODEC_GETTITLE:
{
//TODO !
// Success.
return(1);
}
// Return the bitrate at which this file is encoded.
case SUBFN_CODEC_GETBITRATE:
{
unsigned long *pulBitRate;
//The second parameter is a pointer for the bitrate.
pulBitRate = (unsigned long *)ulParam2;
// Return the average bitrate of the file.
*pulBitRate = aacFrameInfo.bitRate;
// Success.
return(1);
}
// Return the sample rate at which this file is encoded.
case SUBFN_CODEC_GETSAMPLERATE:
{
unsigned long *pulSampleRate;
// The second parameter is a pointer for the sample rate.
pulSampleRate = (unsigned long *)ulParam2;
// Return the sample rate of the file.
*pulSampleRate = aacFrameInfo.sampRateOut;
// Success.
return(1);
}
// Return the number of channels in the file.
case SUBFN_CODEC_GETCHANNELS:
{
unsigned long *pulChannels;
// The second parameter is a pointer for the number of channels.
pulChannels = (unsigned long *)ulParam2;
// Return the number of channels in the file.
*pulChannels = aacFrameInfo.nChans;
// Success.
return(1);
}
// Return the length (in milliseconds) of the file.
case SUBFN_CODEC_GETLENGTH:
{
unsigned long *pulLength;
tAAC *pAAC;
pAAC = (tAAC *)ulParam1;
pulLength = (unsigned long *)ulParam2;
// Return the length of the file.
*pulLength = pAAC->ulTimeLength;
// Success.
return(1);
}
// Return the current position (in milliseconds) within the file.
case SUBFN_CODEC_GETTIME:
{
unsigned long *pulTime;
tAAC *pAAC;
pAAC = (tAAC *)ulParam1;
// The second parameter is a pointer for the number of seconds.
pulTime = (unsigned long *)ulParam2;
if (pAAC->usSampleRate)
{
// Determine the time based on the sample rate.
*pulTime = ((pAAC->ulTimePos / pAAC->usSampleRate) * 1000) +
(((pAAC->ulTimePos % pAAC->usSampleRate) * 1000) /
pAAC->usSampleRate);
}
// Success.
return(1);
}
// Prepare the codec to decode a file.
case SUBFN_CODEC_OPEN_DEC:
{
int byte_1 = 0, byte_2 = 0, time = 0, j;
tAAC *pAAC;
pAAC = (tAAC *)ulParam1;
hAACDecoder = (HAACDecoder *)AACInitDecoder();
bytesLeft = 0;
eofReached = 0;
tst = 0;
pAAC->ulLength = (unsigned long)RKFIO_FLength(pRawFileCache);
aac_OutLeft = (short *)malloc(AAC_MAX_NCHANS * AAC_MAX_NSAMPS * SBR_MUL * sizeof(short));
aac_OutRight = (short *)malloc(AAC_MAX_NCHANS * AAC_MAX_NSAMPS * SBR_MUL * sizeof(short));
if (!hAACDecoder)
{
return 0;
}
//initialize frame information
if (bytesLeft < AAC_MAX_NCHANS * AAC_MAINBUF_SIZE && !eofReached)
{
nRead = FillReadBuffer(readBuf, readPtr, READBUF_SIZE, bytesLeft, pRawFileCache);
bytesLeft += nRead;
readPtr = readBuf;
if (nRead == 0)
eofReached = 1;
}
err = AACDecode(hAACDecoder, &readPtr, &bytesLeft, outBuf);
if (err)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -