add: 增加Audio相关代码

This commit is contained in:
DoubleX69 2021-06-28 17:33:26 +08:00
parent 42d2c1b4c0
commit 5ac4e3cc72
111 changed files with 63362 additions and 0 deletions

View File

@ -0,0 +1,45 @@
#include "AudioDecoder.h"
AudioDecoder::AudioDecoder():handle_(nullptr)
, samplerate_(0)
, channels_(2)
, samplebit_(16)
{
}
AudioDecoder::~AudioDecoder(){
}
bool AudioDecoder::init(unsigned char * ADTSHead ,int headLen ){
if( handle_ == nullptr ){
handle_ = NeAACDecOpen();
}
if( handle_ == nullptr ){
return false;
}
long err = NeAACDecInit( handle_ , ( unsigned char *)ADTSHead , headLen , &samplerate_, &channels_ );
if( err != 0 ){
return false;
}
return true;
}
int AudioDecoder::inputData( unsigned char * data,int len , unsigned char ** outBuffer ){
NeAACDecFrameInfo frameInfo;
*outBuffer = static_cast<unsigned char *>(NeAACDecDecode(handle_, &frameInfo, (unsigned char *) data, len));
if( frameInfo.error != 0){
//ErroL << NeAACDecGetErrorMessage(frameInfo.error) << endl;
return -1;
}
return frameInfo.samples*frameInfo.channels;
}

View File

@ -0,0 +1,53 @@
/*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef AUDIO_AUDIODECODER_H
#define AUDIO_AUDIODECODER_H
#include "libFaad/faad.h"
class AudioDecoder {
public:
AudioDecoder();
virtual ~AudioDecoder();
bool init(unsigned char * ADTSHead ,int headLen =7);
int inputData( unsigned char * data,int len , unsigned char ** outBuffer );
unsigned long getChannels() const { return channels_ ;}
unsigned long getSampleRate() const { return samplerate_ ; }
unsigned long getSampleBit() const { return samplebit_ ;}
private:
NeAACDecHandle handle_;
unsigned long samplerate_;
unsigned char channels_;
unsigned char samplebit_;
};
#endif //AUDIO_AUDIODECODER_H

View File

@ -0,0 +1,79 @@
#include "AudioPlayer.h"
#include "Util/util.h"
#include "Util/logger.h"
using namespace toolkit;
AudioPlayer::AudioPlayer( int sampleRate ,int channels ,int sampleBit):
sampleRate_(sampleRate)
,channels_(channels)
,sampleBit_(sampleBit)
{
}
AudioPlayer::~AudioPlayer(){
}
int AudioPlayer::getPCMData(char *buf, int bufsize) {
if( buffer_->IsEmpty() ){
WarnL << "Audio Data Not Ready!";
return 0;
}
PcmPacket pcm;
buffer_->Pop(pcm);
if( bufsize > pcm.data.size() ){
bufsize = pcm.data.size() ;
}
memcpy( buf , pcm.data.data() , bufsize );
return pcm.data.size();
}
bool AudioPlayer::inputFrame( Frame::Ptr frame ){
unsigned char *pSampleBuffer = nullptr ;
if( decoder_ == nullptr ){
decoder_ = new AudioDecoder;
bool ret = decoder_->init( (unsigned char *)frame->data() );
buffer_ = new xRingBuffer<PcmPacket> ( 16 );
}
if( audioSrc_ == nullptr ){
audioSrc_ = new AudioSRC(this) ;
SDLAudioDevice::Instance().addChannel( audioSrc_ );
}
int size = decoder_->inputData( (unsigned char *)frame->data() ,frame->size(), &pSampleBuffer );
if( size < 0 ){
ErrorL << "Audio Decode Error!!" << endl;
}else{
buf_.append((char*)pSampleBuffer , size);
}
size_t offset = 0 ;
int i = 0;
int ms = 1000 * reqSize_ / ( decoder_->getChannels()*decoder_->getSampleRate()*decoder_->getSampleBit() / 8);
while( buf_.size() - offset > reqSize_ ){
PcmPacket pcm;
pcm.data.assign( buf_.data() + offset , reqSize_ );
pcm.timeStmp = i*ms + frame->dts();
buffer_->Push(std::move(pcm));
++i;
offset += reqSize_;
}
if(offset){
buf_.erase(0,offset );
}
return true;
}

78
tests/Audio/AudioPlayer.h Normal file
View File

@ -0,0 +1,78 @@
/* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef AUDIO_AUDIOPLAYER_H
#define AUDIO_AUDIOPLAYER_H
#include "SDLAudioMixer/AudioSRC.h"
#include "SDLAudioMixer/SDLAudioDevice.h"
#include "AudioDecoder.h"
#include "xRingBuffer.h"
#include "Extension/Frame.h"
using mediakit::Frame;
class PcmPacket{
public:
string data;
uint32_t timeStmp;
};
class AudioPlayer:public AudioSRCDelegate{
public:
AudioPlayer( int sampleRate ,int channels ,int sampleBit);
~AudioPlayer() override;
//audio
void setPCMBufferSize(int size) override{
InfoL << "setPCMBufferSize = " << size ;
reqSize_ = size;
}
int getPCMSampleBit() override{
return decoder_->getSampleBit();
}
int getPCMSampleRate() override{
return decoder_->getSampleRate();
}
int getPCMChannel() override{
return decoder_->getChannels();
}
int getPCMData(char *buf, int bufsize) override;
bool inputFrame( Frame::Ptr frame );
private:
int sampleRate_;
int channels_;
int sampleBit_;
string buf_;
int reqSize_ = 4096;
AudioDecoder* decoder_=nullptr;
xRingBuffer<PcmPacket>* buffer_ = nullptr;
AudioSRC * audioSrc_ = nullptr;
};
#endif //AUDIO_AUDIOPLAYER_H

View File

@ -0,0 +1,14 @@
INCLUDE_DIRECTORIES(./libFaad)
aux_source_directory(./libFaad AUDIO_SRC_LIST)
aux_source_directory(./SDLAudioMixer AUDIO_SRC_LIST)
aux_source_directory(. AUDIO_SRC_LIST)
add_definitions(-DHAVE_CONFIG_H)
add_library(audioPlayer ${AUDIO_SRC_LIST} )
list(APPEND LINK_LIB_LIST audioPlayer )
message(WARNING ${AUDIO_SRC_LIST})

View File

@ -0,0 +1,72 @@
#ifdef __cplusplus
extern "C" {
#endif
#include "SDL2/SDL.h"
#include "libavcodec/avcodec.h"
#ifdef __cplusplus
}
#endif
#include "Util/logger.h"
#include "AudioSRC.h"
#include <stdexcept>
using namespace std;
using namespace toolkit;
AudioSRC::AudioSRC(AudioSRCDelegate *del) {
_delegate = del;
}
AudioSRC::~AudioSRC() {
}
void AudioSRC::setOutputAudioConfig(const SDL_AudioSpec& cfg) {
int freq = _delegate->getPCMSampleRate();
int format = _delegate->getPCMSampleBit() == 16 ? AUDIO_S16 : AUDIO_S8;
int channels = _delegate->getPCMChannel();
if(-1 == SDL_BuildAudioCVT(&_audioCvt,format,channels,freq,cfg.format,cfg.channels,cfg.freq)){
throw std::runtime_error("the format conversion is not supported");
}
InfoL << freq << " " << format << " " << channels ;
InfoL << _audioCvt.needed << " "
<< _audioCvt.src_format << " "
<< _audioCvt.dst_format << " "
<< _audioCvt.rate_incr << " "
<< _audioCvt.len_mult << " "
<< _audioCvt.len_ratio << " ";
}
void AudioSRC::setEnableMix(bool flag){
_enableMix = flag;
}
int AudioSRC::getPCMData(char* buf, int bufsize) {
if(!_enableMix){
return 0;
}
if(!_pcmSize){
_pcmSize = bufsize / _audioCvt.len_ratio;
_delegate->setPCMBufferSize(_pcmSize);
}
if(!_delegate->getPCMData(buf,_pcmSize)){
return 0;
}
_audioCvt.buf = (Uint8 *)buf;
_audioCvt.len = _pcmSize;
if(0 != SDL_ConvertAudio(&_audioCvt)){
_audioCvt.len_cvt = 0;
TraceL << "SDL_ConvertAudio falied";
}
//return _audioCvt.len_cvt;
if(_audioCvt.len_cvt == bufsize)
{
return bufsize;
}
if(_audioCvt.len_cvt){
_pcmBuf.append(buf,_audioCvt.len_cvt);
}
if(_pcmBuf.size() < bufsize){
return 0;
}
memcpy(buf,_pcmBuf.data(),bufsize);
_pcmBuf.erase(0,bufsize);
return bufsize;
}

View File

@ -0,0 +1,74 @@
/*
* MIT License
*
* Copyright (c) 2017 xiongziliang <771730766@qq.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef SDLAUDIOMIXER_AUDIOSRC_H_
#define SDLAUDIOMIXER_AUDIOSRC_H_
#include <memory>
#include <string>
#ifdef __cplusplus
extern "C" {
#endif
#include "SDL2/SDL.h"
#ifdef __cplusplus
}
#endif
#if defined(_WIN32)
#pragma comment(lib,"SDL2.lib")
#endif //defined(_WIN32)
using namespace std;
class AudioSRCDelegate{
public:
virtual ~AudioSRCDelegate(){};
virtual void setPCMBufferSize(int bufsize) = 0;
virtual int getPCMSampleBit() = 0;
virtual int getPCMSampleRate() = 0;
virtual int getPCMChannel() = 0;
virtual int getPCMData(char *buf, int bufsize) = 0;
};
class AudioSRC
{
public:
typedef std::shared_ptr<AudioSRC> Ptr;
AudioSRC(AudioSRCDelegate *);
virtual ~AudioSRC();
void setEnableMix(bool flag);
void setOutputAudioConfig(const SDL_AudioSpec &cfg);
//此处buf大小务必要比bufsize大的多
int getPCMData(char *buf, int bufsize);
private:
AudioSRCDelegate *_delegate;
SDL_AudioCVT _audioCvt;
bool _enableMix = true;
int _pcmSize = 0;
string _pcmBuf;
};
#endif /* SDLAUDIOMIXER_AUDIOSRC_H_ */

View File

@ -0,0 +1,106 @@
#include "SDLAudioDevice.h"
#include "Util/logger.h"
using namespace std;
using namespace toolkit;
SDLAudioDevice& SDLAudioDevice::Instance() {
static SDLAudioDevice *instance(new SDLAudioDevice);
return *instance;
}
SDLAudioDevice::SDLAudioDevice() {
SDL_AudioSpec wanted_spec;
wanted_spec.freq = DEFAULT_SAMPLERATE;
wanted_spec.format = DEFAULT_SAMPLEBIT == 16 ? AUDIO_S16 : AUDIO_S8;
wanted_spec.channels = DEFAULT_CHANNEL;
wanted_spec.silence = 0;
wanted_spec.samples = DEFAULT_PCMSIZE / (DEFAULT_CHANNEL * DEFAULT_SAMPLEBIT / 8) ;
wanted_spec.size = DEFAULT_PCMSIZE;
wanted_spec.callback = SDLAudioDevice::onReqPCM;
wanted_spec.userdata = this;
if (SDL_OpenAudio(&wanted_spec, &_audioConfig)<0) {
// throw std::runtime_error("SDL_OpenAudio failed");
InfoL << "SDL_OpenAudio failed";
}else{
InfoL << "actual audioSpec: " << "freq=" << _audioConfig.freq
<< ",format=" << hex<<_audioConfig.format<<dec
<< ",channels=" << _audioConfig.channels
<< ",samples=" << _audioConfig.samples
<< ",size=" << _audioConfig.size;
}
_pcmBuf.reset(new char[_audioConfig.size * 10],[](char *ptr){
delete [] ptr;
});
}
SDLAudioDevice::~SDLAudioDevice() {
}
void SDLAudioDevice::addChannel(AudioSRC* chn) {
lock_guard<recursive_mutex> lck(_mutexChannel);
if(_channelSet.empty()){
SDL_PauseAudio(0);
}
chn->setOutputAudioConfig(_audioConfig);
_channelSet.emplace(chn);
}
void SDLAudioDevice::delChannel(AudioSRC* chn) {
lock_guard<recursive_mutex> lck(_mutexChannel);
_channelSet.erase(chn);
if(_channelSet.empty()){
SDL_PauseAudio(true);
}
}
void SDLAudioDevice::onReqPCM(void* userdata, Uint8* stream, int len) {
SDLAudioDevice *_this = (SDLAudioDevice *)userdata;
_this->onReqPCM((char *)stream,len);
}
void SDLAudioDevice::onReqPCM(char* stream, int len) {
lock_guard<recursive_mutex> lck(_mutexChannel);
int size;
int channel = 0;
for(auto &chn : _channelSet){
if(channel ==0 ){
size = chn->getPCMData(_pcmBuf.get(),len);
if(size){
//InfoL << len << " " << size;
memcpy(stream,_pcmBuf.get(),size);
}
}else{
size = chn->getPCMData(_pcmBuf.get(),len);
if(size){
//InfoL << len << " " << size;
SDL_MixAudio((Uint8*)stream,(Uint8*)_pcmBuf.get(),size,SDL_MIX_MAXVOLUME);
}
}
if(size){
channel++;
}
}
if(!channel){
memset(stream,0,len);
}
}

View File

@ -0,0 +1,62 @@
/*
* MIT License
*
* Copyright (c) 2017 xiongziliang <771730766@qq.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef SDLAUDIOMIXER_SDLAUDIODEVICE_H_
#define SDLAUDIOMIXER_SDLAUDIODEVICE_H_
#include <mutex>
#include <memory>
#include <stdexcept>
#include <unordered_set>
#include "AudioSRC.h"
using namespace std;
#define DEFAULT_SAMPLERATE 48000
#define DEFAULT_SAMPLEBIT 16
#define DEFAULT_CHANNEL 2
#define DEFAULT_PCMSIZE 4096
class SDLAudioDevice{
public:
void addChannel(AudioSRC *chn);
void delChannel(AudioSRC *chn);
static SDLAudioDevice &Instance();
virtual ~SDLAudioDevice();
protected:
private:
SDLAudioDevice();
static void onReqPCM (void *userdata, Uint8 * stream,int len);
void onReqPCM (char * stream,int len);
unordered_set<AudioSRC *> _channelSet;
recursive_mutex _mutexChannel;
SDL_AudioSpec _audioConfig;
std::shared_ptr<char> _pcmBuf;
};
#endif /* SDLAUDIOMIXER_SDLAUDIODEVICE_H_ */

View File

@ -0,0 +1,52 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: analysis.h,v 1.18 2007/11/01 12:33:29 menno Exp $
**/
#ifndef __ANALYSIS_H__
#define __ANALYSIS_H__
#ifdef __cplusplus
extern "C" {
#endif
#ifdef ANALYSIS
#define DEBUGDEC ,uint8_t print,uint16_t var,uint8_t *dbg
#define DEBUGVAR(A,B,C) ,A,B,C
extern uint16_t dbg_count;
#else
#define DEBUGDEC
#define DEBUGVAR(A,B,C)
#endif
#ifdef __cplusplus
}
#endif
#endif

271
tests/Audio/libFaad/bits.c Normal file
View File

@ -0,0 +1,271 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: bits.c,v 1.44 2007/11/01 12:33:29 menno Exp $
**/
#include "common.h"
#include "structs.h"
#include <stdlib.h>
#include "bits.h"
/* initialize buffer, call once before first getbits or showbits */
void faad_initbits(bitfile *ld, const void *_buffer, const uint32_t buffer_size)
{
uint32_t tmp;
if (ld == NULL)
return;
// useless
//memset(ld, 0, sizeof(bitfile));
if (buffer_size == 0 || _buffer == NULL)
{
ld->error = 1;
return;
}
ld->buffer = _buffer;
ld->buffer_size = buffer_size;
ld->bytes_left = buffer_size;
if (ld->bytes_left >= 4)
{
tmp = getdword((uint32_t*)ld->buffer);
ld->bytes_left -= 4;
} else {
tmp = getdword_n((uint32_t*)ld->buffer, ld->bytes_left);
ld->bytes_left = 0;
}
ld->bufa = tmp;
if (ld->bytes_left >= 4)
{
tmp = getdword((uint32_t*)ld->buffer + 1);
ld->bytes_left -= 4;
} else {
tmp = getdword_n((uint32_t*)ld->buffer + 1, ld->bytes_left);
ld->bytes_left = 0;
}
ld->bufb = tmp;
ld->start = (uint32_t*)ld->buffer;
ld->tail = ((uint32_t*)ld->buffer + 2);
ld->bits_left = 32;
ld->error = 0;
}
void faad_endbits(bitfile *ld)
{
// void
}
uint32_t faad_get_processed_bits(bitfile *ld)
{
return (uint32_t)(8 * (4*(ld->tail - ld->start) - 4) - (ld->bits_left));
}
uint8_t faad_byte_align(bitfile *ld)
{
int remainder = (32 - ld->bits_left) & 0x7;
if (remainder)
{
faad_flushbits(ld, 8 - remainder);
return (uint8_t)(8 - remainder);
}
return 0;
}
void faad_flushbits_ex(bitfile *ld, uint32_t bits)
{
uint32_t tmp;
ld->bufa = ld->bufb;
if (ld->bytes_left >= 4)
{
tmp = getdword(ld->tail);
ld->bytes_left -= 4;
} else {
tmp = getdword_n(ld->tail, ld->bytes_left);
ld->bytes_left = 0;
}
ld->bufb = tmp;
ld->tail++;
ld->bits_left += (32 - bits);
//ld->bytes_left -= 4;
// if (ld->bytes_left == 0)
// ld->no_more_reading = 1;
// if (ld->bytes_left < 0)
// ld->error = 1;
}
/* rewind to beginning */
void faad_rewindbits(bitfile *ld)
{
uint32_t tmp;
ld->bytes_left = ld->buffer_size;
if (ld->bytes_left >= 4)
{
tmp = getdword((uint32_t*)&ld->start[0]);
ld->bytes_left -= 4;
} else {
tmp = getdword_n((uint32_t*)&ld->start[0], ld->bytes_left);
ld->bytes_left = 0;
}
ld->bufa = tmp;
if (ld->bytes_left >= 4)
{
tmp = getdword((uint32_t*)&ld->start[1]);
ld->bytes_left -= 4;
} else {
tmp = getdword_n((uint32_t*)&ld->start[1], ld->bytes_left);
ld->bytes_left = 0;
}
ld->bufb = tmp;
ld->bits_left = 32;
ld->tail = &ld->start[2];
}
/* reset to a certain point */
void faad_resetbits(bitfile *ld, int bits)
{
uint32_t tmp;
int words = bits >> 5;
int remainder = bits & 0x1F;
ld->bytes_left = ld->buffer_size - words*4;
if (ld->bytes_left >= 4)
{
tmp = getdword(&ld->start[words]);
ld->bytes_left -= 4;
} else {
tmp = getdword_n(&ld->start[words], ld->bytes_left);
ld->bytes_left = 0;
}
ld->bufa = tmp;
if (ld->bytes_left >= 4)
{
tmp = getdword(&ld->start[words+1]);
ld->bytes_left -= 4;
} else {
tmp = getdword_n(&ld->start[words+1], ld->bytes_left);
ld->bytes_left = 0;
}
ld->bufb = tmp;
ld->bits_left = 32 - remainder;
ld->tail = &ld->start[words+2];
/* recheck for reading too many bytes */
ld->error = 0;
// if (ld->bytes_left == 0)
// ld->no_more_reading = 1;
// if (ld->bytes_left < 0)
// ld->error = 1;
}
uint8_t *faad_getbitbuffer(bitfile *ld, uint32_t bits
DEBUGDEC)
{
int i;
unsigned int temp;
int bytes = bits >> 3;
int remainder = bits & 0x7;
uint8_t *buffer = (uint8_t*)faad_malloc((bytes+1)*sizeof(uint8_t));
for (i = 0; i < bytes; i++)
{
buffer[i] = (uint8_t)faad_getbits(ld, 8 DEBUGVAR(print,var,dbg));
}
if (remainder)
{
temp = faad_getbits(ld, remainder DEBUGVAR(print,var,dbg)) << (8-remainder);
buffer[bytes] = (uint8_t)temp;
}
return buffer;
}
#ifdef DRM
/* return the original data buffer */
void *faad_origbitbuffer(bitfile *ld)
{
return (void*)ld->start;
}
/* return the original data buffer size */
uint32_t faad_origbitbuffer_size(bitfile *ld)
{
return ld->buffer_size;
}
#endif
/* reversed bit reading routines, used for RVLC and HCR */
void faad_initbits_rev(bitfile *ld, void *buffer,
uint32_t bits_in_buffer)
{
uint32_t tmp;
int32_t index;
ld->buffer_size = bit2byte(bits_in_buffer);
index = (bits_in_buffer+31)/32 - 1;
ld->start = (uint32_t*)buffer + index - 2;
tmp = getdword((uint32_t*)buffer + index);
ld->bufa = tmp;
tmp = getdword((uint32_t*)buffer + index - 1);
ld->bufb = tmp;
ld->tail = (uint32_t*)buffer + index;
ld->bits_left = bits_in_buffer % 32;
if (ld->bits_left == 0)
ld->bits_left = 32;
ld->bytes_left = ld->buffer_size;
ld->error = 0;
}
/* EOF */

452
tests/Audio/libFaad/bits.h Normal file
View File

@ -0,0 +1,452 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: bits.h,v 1.45 2007/11/01 12:33:29 menno Exp $
**/
#ifndef __BITS_H__
#define __BITS_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "analysis.h"
#ifdef ANALYSIS
#include <stdio.h>
#endif
#define BYTE_NUMBIT 8
#define BYTE_NUMBIT_LD 3
//#define bit2byte(a) ((a+7)/BYTE_NUMBIT)
#define bit2byte(a) ((a+7)>>BYTE_NUMBIT_LD)
typedef struct _bitfile
{
/* bit input */
uint32_t bufa;
uint32_t bufb;
uint32_t bits_left;
uint32_t buffer_size; /* size of the buffer in bytes */
uint32_t bytes_left;
uint8_t error;
uint32_t *tail;
uint32_t *start;
const void *buffer;
} bitfile;
#if 0
static uint32_t const bitmask[] = {
0x0, 0x1, 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F, 0xFF, 0x1FF,
0x3FF, 0x7FF, 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF,
0x1FFFF, 0x3FFFF, 0x7FFFF, 0xFFFFF, 0x1FFFFF, 0x3FFFFF,
0x7FFFFF, 0xFFFFFF, 0x1FFFFFF, 0x3FFFFFF, 0x7FFFFFF,
0xFFFFFFF, 0x1FFFFFFF, 0x3FFFFFFF, 0x7FFFFFFF
/* added bitmask 32, correct?!?!?! */
, 0xFFFFFFFF
};
#endif
void faad_initbits(bitfile *ld, const void *buffer, const uint32_t buffer_size);
void faad_endbits(bitfile *ld);
void faad_initbits_rev(bitfile *ld, void *buffer,
uint32_t bits_in_buffer);
uint8_t faad_byte_align(bitfile *ld);
uint32_t faad_get_processed_bits(bitfile *ld);
void faad_flushbits_ex(bitfile *ld, uint32_t bits);
void faad_rewindbits(bitfile *ld);
void faad_resetbits(bitfile *ld, int bits);
uint8_t *faad_getbitbuffer(bitfile *ld, uint32_t bits
DEBUGDEC);
#ifdef DRM
void *faad_origbitbuffer(bitfile *ld);
uint32_t faad_origbitbuffer_size(bitfile *ld);
#endif
/* circumvent memory alignment errors on ARM */
static INLINE uint32_t getdword(void *mem)
{
uint32_t tmp;
#ifndef ARCH_IS_BIG_ENDIAN
((uint8_t*)&tmp)[0] = ((uint8_t*)mem)[3];
((uint8_t*)&tmp)[1] = ((uint8_t*)mem)[2];
((uint8_t*)&tmp)[2] = ((uint8_t*)mem)[1];
((uint8_t*)&tmp)[3] = ((uint8_t*)mem)[0];
#else
((uint8_t*)&tmp)[0] = ((uint8_t*)mem)[0];
((uint8_t*)&tmp)[1] = ((uint8_t*)mem)[1];
((uint8_t*)&tmp)[2] = ((uint8_t*)mem)[2];
((uint8_t*)&tmp)[3] = ((uint8_t*)mem)[3];
#endif
return tmp;
}
/* reads only n bytes from the stream instead of the standard 4 */
static /*INLINE*/ uint32_t getdword_n(void *mem, int n)
{
uint32_t tmp = 0;
#ifndef ARCH_IS_BIG_ENDIAN
switch (n)
{
case 3:
((uint8_t*)&tmp)[1] = ((uint8_t*)mem)[2];
case 2:
((uint8_t*)&tmp)[2] = ((uint8_t*)mem)[1];
case 1:
((uint8_t*)&tmp)[3] = ((uint8_t*)mem)[0];
default:
break;
}
#else
switch (n)
{
case 3:
((uint8_t*)&tmp)[2] = ((uint8_t*)mem)[2];
case 2:
((uint8_t*)&tmp)[1] = ((uint8_t*)mem)[1];
case 1:
((uint8_t*)&tmp)[0] = ((uint8_t*)mem)[0];
default:
break;
}
#endif
return tmp;
}
static INLINE uint32_t faad_showbits(bitfile *ld, uint32_t bits)
{
if (bits <= ld->bits_left)
{
//return (ld->bufa >> (ld->bits_left - bits)) & bitmask[bits];
return (ld->bufa << (32 - ld->bits_left)) >> (32 - bits);
}
bits -= ld->bits_left;
//return ((ld->bufa & bitmask[ld->bits_left]) << bits) | (ld->bufb >> (32 - bits));
return ((ld->bufa & ((1<<ld->bits_left)-1)) << bits) | (ld->bufb >> (32 - bits));
}
static INLINE void faad_flushbits(bitfile *ld, uint32_t bits)
{
/* do nothing if error */
if (ld->error != 0)
return;
if (bits < ld->bits_left)
{
ld->bits_left -= bits;
} else {
faad_flushbits_ex(ld, bits);
}
}
/* return next n bits (right adjusted) */
static /*INLINE*/ uint32_t faad_getbits(bitfile *ld, uint32_t n DEBUGDEC)
{
uint32_t ret;
if (n == 0)
return 0;
ret = faad_showbits(ld, n);
faad_flushbits(ld, n);
#ifdef ANALYSIS
if (print)
fprintf(stdout, "%4d %2d bits, val: %4d, variable: %d %s\n", dbg_count++, n, ret, var, dbg);
#endif
return ret;
}
static INLINE uint8_t faad_get1bit(bitfile *ld DEBUGDEC)
{
uint8_t r;
if (ld->bits_left > 0)
{
ld->bits_left--;
r = (uint8_t)((ld->bufa >> ld->bits_left) & 1);
return r;
}
/* bits_left == 0 */
#if 0
r = (uint8_t)(ld->bufb >> 31);
faad_flushbits_ex(ld, 1);
#else
r = (uint8_t)faad_getbits(ld, 1);
#endif
return r;
}
/* reversed bitreading routines */
static INLINE uint32_t faad_showbits_rev(bitfile *ld, uint32_t bits)
{
uint8_t i;
uint32_t B = 0;
if (bits <= ld->bits_left)
{
for (i = 0; i < bits; i++)
{
if (ld->bufa & (1 << (i + (32 - ld->bits_left))))
B |= (1 << (bits - i - 1));
}
return B;
} else {
for (i = 0; i < ld->bits_left; i++)
{
if (ld->bufa & (1 << (i + (32 - ld->bits_left))))
B |= (1 << (bits - i - 1));
}
for (i = 0; i < bits - ld->bits_left; i++)
{
if (ld->bufb & (1 << (i + (32-ld->bits_left))))
B |= (1 << (bits - ld->bits_left - i - 1));
}
return B;
}
}
static INLINE void faad_flushbits_rev(bitfile *ld, uint32_t bits)
{
/* do nothing if error */
if (ld->error != 0)
return;
if (bits < ld->bits_left)
{
ld->bits_left -= bits;
} else {
uint32_t tmp;
ld->bufa = ld->bufb;
tmp = getdword(ld->start);
ld->bufb = tmp;
ld->start--;
ld->bits_left += (32 - bits);
if (ld->bytes_left < 4)
{
ld->error = 1;
ld->bytes_left = 0;
} else {
ld->bytes_left -= 4;
}
// if (ld->bytes_left == 0)
// ld->no_more_reading = 1;
}
}
static /*INLINE*/ uint32_t faad_getbits_rev(bitfile *ld, uint32_t n
DEBUGDEC)
{
uint32_t ret;
if (n == 0)
return 0;
ret = faad_showbits_rev(ld, n);
faad_flushbits_rev(ld, n);
#ifdef ANALYSIS
if (print)
fprintf(stdout, "%4d %2d bits, val: %4d, variable: %d %s\n", dbg_count++, n, ret, var, dbg);
#endif
return ret;
}
#ifdef DRM
/* CRC lookup table for G8 polynome in DRM standard */
static const uint8_t crc_table_G8[256] = {
0x0, 0x1d, 0x3a, 0x27, 0x74, 0x69, 0x4e, 0x53,
0xe8, 0xf5, 0xd2, 0xcf, 0x9c, 0x81, 0xa6, 0xbb,
0xcd, 0xd0, 0xf7, 0xea, 0xb9, 0xa4, 0x83, 0x9e,
0x25, 0x38, 0x1f, 0x2, 0x51, 0x4c, 0x6b, 0x76,
0x87, 0x9a, 0xbd, 0xa0, 0xf3, 0xee, 0xc9, 0xd4,
0x6f, 0x72, 0x55, 0x48, 0x1b, 0x6, 0x21, 0x3c,
0x4a, 0x57, 0x70, 0x6d, 0x3e, 0x23, 0x4, 0x19,
0xa2, 0xbf, 0x98, 0x85, 0xd6, 0xcb, 0xec, 0xf1,
0x13, 0xe, 0x29, 0x34, 0x67, 0x7a, 0x5d, 0x40,
0xfb, 0xe6, 0xc1, 0xdc, 0x8f, 0x92, 0xb5, 0xa8,
0xde, 0xc3, 0xe4, 0xf9, 0xaa, 0xb7, 0x90, 0x8d,
0x36, 0x2b, 0xc, 0x11, 0x42, 0x5f, 0x78, 0x65,
0x94, 0x89, 0xae, 0xb3, 0xe0, 0xfd, 0xda, 0xc7,
0x7c, 0x61, 0x46, 0x5b, 0x8, 0x15, 0x32, 0x2f,
0x59, 0x44, 0x63, 0x7e, 0x2d, 0x30, 0x17, 0xa,
0xb1, 0xac, 0x8b, 0x96, 0xc5, 0xd8, 0xff, 0xe2,
0x26, 0x3b, 0x1c, 0x1, 0x52, 0x4f, 0x68, 0x75,
0xce, 0xd3, 0xf4, 0xe9, 0xba, 0xa7, 0x80, 0x9d,
0xeb, 0xf6, 0xd1, 0xcc, 0x9f, 0x82, 0xa5, 0xb8,
0x3, 0x1e, 0x39, 0x24, 0x77, 0x6a, 0x4d, 0x50,
0xa1, 0xbc, 0x9b, 0x86, 0xd5, 0xc8, 0xef, 0xf2,
0x49, 0x54, 0x73, 0x6e, 0x3d, 0x20, 0x7, 0x1a,
0x6c, 0x71, 0x56, 0x4b, 0x18, 0x5, 0x22, 0x3f,
0x84, 0x99, 0xbe, 0xa3, 0xf0, 0xed, 0xca, 0xd7,
0x35, 0x28, 0xf, 0x12, 0x41, 0x5c, 0x7b, 0x66,
0xdd, 0xc0, 0xe7, 0xfa, 0xa9, 0xb4, 0x93, 0x8e,
0xf8, 0xe5, 0xc2, 0xdf, 0x8c, 0x91, 0xb6, 0xab,
0x10, 0xd, 0x2a, 0x37, 0x64, 0x79, 0x5e, 0x43,
0xb2, 0xaf, 0x88, 0x95, 0xc6, 0xdb, 0xfc, 0xe1,
0x5a, 0x47, 0x60, 0x7d, 0x2e, 0x33, 0x14, 0x9,
0x7f, 0x62, 0x45, 0x58, 0xb, 0x16, 0x31, 0x2c,
0x97, 0x8a, 0xad, 0xb0, 0xe3, 0xfe, 0xd9, 0xc4,
};
static uint8_t faad_check_CRC(bitfile *ld, uint16_t len)
{
int bytes, rem;
unsigned int CRC;
unsigned int r=255; /* Initialize to all ones */
/* CRC polynome used x^8 + x^4 + x^3 + x^2 +1 */
#define GPOLY 0435
faad_rewindbits(ld);
CRC = (unsigned int) ~faad_getbits(ld, 8
DEBUGVAR(1,999,"faad_check_CRC(): CRC")) & 0xFF; /* CRC is stored inverted */
bytes = len >> 3;
rem = len & 0x7;
for (; bytes > 0; bytes--)
{
r = crc_table_G8[( r ^ faad_getbits(ld, 8 DEBUGVAR(1,998,"")) ) & 0xFF];
}
for (; rem > 0; rem--)
{
r = ( (r << 1) ^ (( ( faad_get1bit(ld
DEBUGVAR(1,998,"")) & 1) ^ ((r >> 7) & 1)) * GPOLY )) & 0xFF;
}
if (r != CRC)
// if (0)
{
return 28;
} else {
return 0;
}
}
static uint8_t tabFlipbits[256] = {
0,128,64,192,32,160,96,224,16,144,80,208,48,176,112,240,
8,136,72,200,40,168,104,232,24,152,88,216,56,184,120,248,
4,132,68,196,36,164,100,228,20,148,84,212,52,180,116,244,
12,140,76,204,44,172,108,236,28,156,92,220,60,188,124,252,
2,130,66,194,34,162,98,226,18,146,82,210,50,178,114,242,
10,138,74,202,42,170,106,234,26,154,90,218,58,186,122,250,
6,134,70,198,38,166,102,230,22,150,86,214,54,182,118,246,
14,142,78,206,46,174,110,238,30,158,94,222,62,190,126,254,
1,129,65,193,33,161,97,225,17,145,81,209,49,177,113,241,
9,137,73,201,41,169,105,233,25,153,89,217,57,185,121,249,
5,133,69,197,37,165,101,229,21,149,85,213,53,181,117,245,
13,141,77,205,45,173,109,237,29,157,93,221,61,189,125,253,
3,131,67,195,35,163,99,227,19,147,83,211,51,179,115,243,
11,139,75,203,43,171,107,235,27,155,91,219,59,187,123,251,
7,135,71,199,39,167,103,231,23,151,87,215,55,183,119,247,
15,143,79,207,47,175,111,239,31,159,95,223,63,191,127,255
};
#endif
#ifdef ERROR_RESILIENCE
/* Modified bit reading functions for HCR */
typedef struct
{
/* bit input */
uint32_t bufa;
uint32_t bufb;
int8_t len;
} bits_t;
static INLINE uint32_t showbits_hcr(bits_t *ld, uint8_t bits)
{
if (bits == 0) return 0;
if (ld->len <= 32)
{
/* huffman_spectral_data_2 needs to read more than may be available, bits maybe
> ld->len, deliver 0 than */
if (ld->len >= bits)
return ((ld->bufa >> (ld->len - bits)) & (0xFFFFFFFF >> (32 - bits)));
else
return ((ld->bufa << (bits - ld->len)) & (0xFFFFFFFF >> (32 - bits)));
} else {
if ((ld->len - bits) < 32)
{
return ( (ld->bufb & (0xFFFFFFFF >> (64 - ld->len))) << (bits - ld->len + 32)) |
(ld->bufa >> (ld->len - bits));
} else {
return ((ld->bufb >> (ld->len - bits - 32)) & (0xFFFFFFFF >> (32 - bits)));
}
}
}
/* return 1 if position is outside of buffer, 0 otherwise */
static INLINE int8_t flushbits_hcr( bits_t *ld, uint8_t bits)
{
ld->len -= bits;
if (ld->len <0)
{
ld->len = 0;
return 1;
} else {
return 0;
}
}
static INLINE int8_t getbits_hcr(bits_t *ld, uint8_t n, uint32_t *result)
{
*result = showbits_hcr(ld, n);
return flushbits_hcr(ld, n);
}
static INLINE int8_t get1bit_hcr(bits_t *ld, uint8_t *result)
{
uint32_t res;
int8_t ret;
ret = getbits_hcr(ld, 1, &res);
*result = (int8_t)(res & 1);
return ret;
}
#endif
#ifdef __cplusplus
}
#endif
#endif

1005
tests/Audio/libFaad/cfft.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,56 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: cfft.h,v 1.24 2007/11/01 12:33:29 menno Exp $
**/
#ifndef __CFFT_H__
#define __CFFT_H__
#ifdef __cplusplus
extern "C" {
#endif
typedef struct
{
uint16_t n;
uint16_t ifac[15];
complex_t *work;
complex_t *tab;
} cfft_info;
void cfftf(cfft_info *cfft, complex_t *c);
void cfftb(cfft_info *cfft, complex_t *c);
cfft_info *cffti(uint16_t n);
void cfftu(cfft_info *cfft);
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,145 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: hcb.h,v 1.8 2007/11/01 12:34:10 menno Exp $
**/
#ifndef __HCB_H__
#define __HCB_H__
#ifdef __cplusplus
extern "C" {
#endif
/*
* Optimal huffman decoding for AAC taken from:
* "SELECTING AN OPTIMAL HUFFMAN DECODER FOR AAC" by
* VLADIMIR Z. MESAROVIC , RAGHUNATH RAO, MIROSLAV V. DOKIC, and SACHIN DEO
* AES paper 5436
*
* 2 methods are used for huffman decoding:
* - binary search
* - 2-step table lookup
*
* The choice of the "optimal" method is based on the fact that if the
* memory size for the Two-step is exorbitantly high then the decision
* is Binary search for that codebook. However, for marginally more memory
* size, if Twostep outperforms even the best case of Binary then the
* decision is Two-step for that codebook.
*
* The following methods are used for the different tables.
* codebook "optimal" method
* HCB_1 2-Step
* HCB_2 2-Step
* HCB_3 Binary
* HCB_4 2-Step
* HCB_5 Binary
* HCB_6 2-Step
* HCB_7 Binary
* HCB_8 2-Step
* HCB_9 Binary
* HCB_10 2-Step
* HCB_11 2-Step
* HCB_SF Binary
*
*/
#define ZERO_HCB 0
#define FIRST_PAIR_HCB 5
#define ESC_HCB 11
#define QUAD_LEN 4
#define PAIR_LEN 2
#define NOISE_HCB 13
#define INTENSITY_HCB2 14
#define INTENSITY_HCB 15
/* 1st step table */
typedef struct
{
uint8_t offset;
uint8_t extra_bits;
} hcb;
/* 2nd step table with quadruple data */
typedef struct
{
uint8_t bits;
int8_t x;
int8_t y;
} hcb_2_pair;
typedef struct
{
uint8_t bits;
int8_t x;
int8_t y;
int8_t v;
int8_t w;
} hcb_2_quad;
/* binary search table */
typedef struct
{
uint8_t is_leaf;
int8_t data[4];
} hcb_bin_quad;
typedef struct
{
uint8_t is_leaf;
int8_t data[2];
} hcb_bin_pair;
hcb *hcb_table[];
hcb_2_quad *hcb_2_quad_table[];
hcb_2_pair *hcb_2_pair_table[];
hcb_bin_pair *hcb_bin_table[];
uint8_t hcbN[];
uint8_t unsigned_cb[];
int hcb_2_quad_table_size[];
int hcb_2_pair_table_size[];
int hcb_bin_table_size[];
#include "codebook/hcb_1.h"
#include "codebook/hcb_2.h"
#include "codebook/hcb_3.h"
#include "codebook/hcb_4.h"
#include "codebook/hcb_5.h"
#include "codebook/hcb_6.h"
#include "codebook/hcb_7.h"
#include "codebook/hcb_8.h"
#include "codebook/hcb_9.h"
#include "codebook/hcb_10.h"
#include "codebook/hcb_11.h"
#include "codebook/hcb_sf.h"
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,186 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: hcb_1.h,v 1.5 2007/11/01 12:34:11 menno Exp $
**/
/* 2-step huffman table HCB_1 */
/* 1st step: 5 bits
* 2^5 = 32 entries
*
* Used to find offset into 2nd step table and number of extra bits to get
*/
static hcb hcb1_1[] = {
{ /* 00000 */ 0, 0 },
{ /* */ 0, 0 },
{ /* */ 0, 0 },
{ /* */ 0, 0 },
{ /* */ 0, 0 },
{ /* */ 0, 0 },
{ /* */ 0, 0 },
{ /* */ 0, 0 },
{ /* */ 0, 0 },
{ /* */ 0, 0 },
{ /* */ 0, 0 },
{ /* */ 0, 0 },
{ /* */ 0, 0 },
{ /* */ 0, 0 },
{ /* */ 0, 0 },
{ /* */ 0, 0 },
{ /* 10000 */ 1, 0 },
{ /* 10001 */ 2, 0 },
{ /* 10010 */ 3, 0 },
{ /* 10011 */ 4, 0 },
{ /* 10100 */ 5, 0 },
{ /* 10101 */ 6, 0 },
{ /* 10110 */ 7, 0 },
{ /* 10111 */ 8, 0 },
/* 7 bit codewords */
{ /* 11000 */ 9, 2 },
{ /* 11001 */ 13, 2 },
{ /* 11010 */ 17, 2 },
{ /* 11011 */ 21, 2 },
{ /* 11100 */ 25, 2 },
{ /* 11101 */ 29, 2 },
/* 9 bit codewords */
{ /* 11110 */ 33, 4 },
/* 9/10/11 bit codewords */
{ /* 11111 */ 49, 6 }
};
/* 2nd step table
*
* Gives size of codeword and actual data (x,y,v,w)
*/
static hcb_2_quad hcb1_2[] = {
/* 1 bit codeword */
{ 1, 0, 0, 0, 0 },
/* 5 bit codewords */
{ 5, 1, 0, 0, 0 },
{ 5, -1, 0, 0, 0 },
{ 5, 0, 0, 0, -1 },
{ 5, 0, 1, 0, 0 },
{ 5, 0, 0, 0, 1 },
{ 5, 0, 0, -1, 0 },
{ 5, 0, 0, 1, 0 },
{ 5, 0, -1, 0, 0 },
/* 7 bit codewords */
/* first 5 bits: 11000 */
{ 7, 1, -1, 0, 0 },
{ 7, -1, 1, 0, 0 },
{ 7, 0, 0, -1, 1 },
{ 7, 0, 1, -1, 0 },
/* first 5 bits: 11001 */
{ 7, 0, -1, 1, 0 },
{ 7, 0, 0, 1, -1 },
{ 7, 1, 1, 0, 0 },
{ 7, 0, 0, -1, -1 },
/* first 5 bits: 11010 */
{ 7, -1, -1, 0, 0 },
{ 7, 0, -1, -1, 0 },
{ 7, 1, 0, -1, 0 },
{ 7, 0, 1, 0, -1 },
/* first 5 bits: 11011 */
{ 7, -1, 0, 1, 0 },
{ 7, 0, 0, 1, 1 },
{ 7, 1, 0, 1, 0 },
{ 7, 0, -1, 0, 1 },
/* first 5 bits: 11100 */
{ 7, 0, 1, 1, 0 },
{ 7, 0, 1, 0, 1 },
{ 7, -1, 0, -1, 0 },
{ 7, 1, 0, 0, 1 },
/* first 5 bits: 11101 */
{ 7, -1, 0, 0, -1 },
{ 7, 1, 0, 0, -1 },
{ 7, -1, 0, 0, 1 },
{ 7, 0, -1, 0, -1 },
/* 9 bit codeword */
/* first 5 bits: 11110 */
{ 9, 1, 1, -1, 0 },
{ 9, -1, 1, -1, 0 },
{ 9, 1, -1, 1, 0 },
{ 9, 0, 1, 1, -1 },
{ 9, 0, 1, -1, 1 },
{ 9, 0, -1, 1, 1 },
{ 9, 0, -1, 1, -1 },
{ 9, 1, -1, -1, 0 },
{ 9, 1, 0, -1, 1 },
{ 9, 0, 1, -1, -1 },
{ 9, -1, 1, 1, 0 },
{ 9, -1, 0, 1, -1 },
{ 9, -1, -1, 1, 0 },
{ 9, 0, -1, -1, 1 },
{ 9, 1, -1, 0, 1 },
{ 9, 1, -1, 0, -1 },
/* 9/10/11 bit codewords */
/* first 5 bits: 11111 */
/* 9 bit: reading 11 bits -> 2 too much so 4 entries for each codeword */
{ 9, -1, 1, 0, -1 }, { 9, -1, 1, 0, -1 }, { 9, -1, 1, 0, -1 }, { 9, -1, 1, 0, -1 },
{ 9, -1, -1, -1, 0 }, { 9, -1, -1, -1, 0 }, { 9, -1, -1, -1, 0 }, { 9, -1, -1, -1, 0 },
{ 9, 0, -1, -1, -1 }, { 9, 0, -1, -1, -1 }, { 9, 0, -1, -1, -1 }, { 9, 0, -1, -1, -1 },
{ 9, 0, 1, 1, 1 }, { 9, 0, 1, 1, 1 }, { 9, 0, 1, 1, 1 }, { 9, 0, 1, 1, 1 },
{ 9, 1, 0, 1, -1 }, { 9, 1, 0, 1, -1 }, { 9, 1, 0, 1, -1 }, { 9, 1, 0, 1, -1 },
{ 9, 1, 1, 0, 1 }, { 9, 1, 1, 0, 1 }, { 9, 1, 1, 0, 1 }, { 9, 1, 1, 0, 1 },
{ 9, -1, 1, 0, 1 }, { 9, -1, 1, 0, 1 }, { 9, -1, 1, 0, 1 }, { 9, -1, 1, 0, 1 },
{ 9, 1, 1, 1, 0 }, { 9, 1, 1, 1, 0 }, { 9, 1, 1, 1, 0 }, { 9, 1, 1, 1, 0 },
/* 10 bit: reading 11 bits -> 1 too much so 2 entries for each codeword */
{ 10, -1, -1, 0, 1 }, { 10, -1, -1, 0, 1 },
{ 10, -1, 0, -1, -1 }, { 10, -1, 0, -1, -1 },
{ 10, 1, 1, 0, -1 }, { 10, 1, 1, 0, -1 },
{ 10, 1, 0, -1, -1 }, { 10, 1, 0, -1, -1 },
{ 10, -1, 0, -1, 1 }, { 10, -1, 0, -1, 1 },
{ 10, -1, -1, 0, -1 }, { 10, -1, -1, 0, -1 },
{ 10, -1, 0, 1, 1 }, { 10, -1, 0, 1, 1 },
{ 10, 1, 0, 1, 1 }, { 10, 1, 0, 1, 1 },
/* 11 bit */
{ 11, 1, -1, 1, -1 },
{ 11, -1, 1, -1, 1 },
{ 11, -1, 1, 1, -1 },
{ 11, 1, -1, -1, 1 },
{ 11, 1, 1, 1, 1 },
{ 11, -1, -1, 1, 1 },
{ 11, 1, 1, -1, -1 },
{ 11, -1, -1, 1, -1 },
{ 11, -1, -1, -1, -1 },
{ 11, 1, 1, -1, 1 },
{ 11, 1, -1, 1, 1 },
{ 11, -1, 1, 1, 1 },
{ 11, -1, 1, -1, -1 },
{ 11, -1, -1, -1, 1 },
{ 11, 1, -1, -1, -1 },
{ 11, 1, 1, 1, -1 }
};

View File

@ -0,0 +1,312 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: hcb_10.h,v 1.5 2007/11/01 12:34:11 menno Exp $
**/
/* 2-step huffman table HCB_10 */
/* 1st step: 6 bits
* 2^6 = 64 entries
*
* Used to find offset into 2nd step table and number of extra bits to get
*/
static hcb hcb10_1[] = {
/* 4 bit codewords */
{ /* 000000 */ 0, 0 },
{ /* */ 0, 0 },
{ /* */ 0, 0 },
{ /* */ 0, 0 },
{ /* 000100 */ 1, 0 },
{ /* */ 1, 0 },
{ /* */ 1, 0 },
{ /* */ 1, 0 },
{ /* 001000 */ 2, 0 },
{ /* */ 2, 0 },
{ /* */ 2, 0 },
{ /* */ 2, 0 },
/* 5 bit codewords */
{ /* 001100 */ 3, 0 },
{ /* */ 3, 0 },
{ /* 001110 */ 4, 0 },
{ /* */ 4, 0 },
{ /* 010000 */ 5, 0 },
{ /* */ 5, 0 },
{ /* 010010 */ 6, 0 },
{ /* */ 6, 0 },
{ /* 010100 */ 7, 0 },
{ /* */ 7, 0 },
{ /* 010110 */ 8, 0 },
{ /* */ 8, 0 },
{ /* 011000 */ 9, 0 },
{ /* */ 9, 0 },
{ /* 011010 */ 10, 0 },
{ /* */ 10, 0 },
/* 6 bit codewords */
{ /* 011100 */ 11, 0 },
{ /* 011101 */ 12, 0 },
{ /* 011110 */ 13, 0 },
{ /* 011111 */ 14, 0 },
{ /* 100000 */ 15, 0 },
{ /* 100001 */ 16, 0 },
{ /* 100010 */ 17, 0 },
{ /* 100011 */ 18, 0 },
{ /* 100100 */ 19, 0 },
{ /* 100101 */ 20, 0 },
{ /* 100110 */ 21, 0 },
{ /* 100111 */ 22, 0 },
{ /* 101000 */ 23, 0 },
{ /* 101001 */ 24, 0 },
/* 7 bit codewords */
{ /* 101010 */ 25, 1 },
{ /* 101011 */ 27, 1 },
{ /* 101100 */ 29, 1 },
{ /* 101101 */ 31, 1 },
{ /* 101110 */ 33, 1 },
{ /* 101111 */ 35, 1 },
{ /* 110000 */ 37, 1 },
{ /* 110001 */ 39, 1 },
/* 7/8 bit codewords */
{ /* 110010 */ 41, 2 },
/* 8 bit codewords */
{ /* 110011 */ 45, 2 },
{ /* 110100 */ 49, 2 },
{ /* 110101 */ 53, 2 },
{ /* 110110 */ 57, 2 },
{ /* 110111 */ 61, 2 },
/* 8/9 bit codewords */
{ /* 111000 */ 65, 3 },
/* 9 bit codewords */
{ /* 111001 */ 73, 3 },
{ /* 111010 */ 81, 3 },
{ /* 111011 */ 89, 3 },
/* 9/10 bit codewords */
{ /* 111100 */ 97, 4 },
/* 10 bit codewords */
{ /* 111101 */ 113, 4 },
{ /* 111110 */ 129, 4 },
/* 10/11/12 bit codewords */
{ /* 111111 */ 145, 6 }
};
/* 2nd step table
*
* Gives size of codeword and actual data (x,y,v,w)
*/
static hcb_2_pair hcb10_2[] = {
/* 4 bit codewords */
{ 4, 1, 1 },
{ 4, 1, 2 },
{ 4, 2, 1 },
/* 5 bit codewords */
{ 5, 2, 2 },
{ 5, 1, 0 },
{ 5, 0, 1 },
{ 5, 1, 3 },
{ 5, 3, 2 },
{ 5, 3, 1 },
{ 5, 2, 3 },
{ 5, 3, 3 },
/* 6 bit codewords */
{ 6, 2, 0 },
{ 6, 0, 2 },
{ 6, 2, 4 },
{ 6, 4, 2 },
{ 6, 1, 4 },
{ 6, 4, 1 },
{ 6, 0, 0 },
{ 6, 4, 3 },
{ 6, 3, 4 },
{ 6, 3, 0 },
{ 6, 0, 3 },
{ 6, 4, 4 },
{ 6, 2, 5 },
{ 6, 5, 2 },
/* 7 bit codewords */
{ 7, 1, 5 },
{ 7, 5, 1 },
{ 7, 5, 3 },
{ 7, 3, 5 },
{ 7, 5, 4 },
{ 7, 4, 5 },
{ 7, 6, 2 },
{ 7, 2, 6 },
{ 7, 6, 3 },
{ 7, 4, 0 },
{ 7, 6, 1 },
{ 7, 0, 4 },
{ 7, 1, 6 },
{ 7, 3, 6 },
{ 7, 5, 5 },
{ 7, 6, 4 },
/* 7/8 bit codewords */
{ 7, 4, 6 }, { 7, 4, 6 },
{ 8, 6, 5 },
{ 8, 7, 2 },
/* 8 bit codewords */
{ 8, 3, 7 },
{ 8, 2, 7 },
{ 8, 5, 6 },
{ 8, 8, 2 },
{ 8, 7, 3 },
{ 8, 5, 0 },
{ 8, 7, 1 },
{ 8, 0, 5 },
{ 8, 8, 1 },
{ 8, 1, 7 },
{ 8, 8, 3 },
{ 8, 7, 4 },
{ 8, 4, 7 },
{ 8, 2, 8 },
{ 8, 6, 6 },
{ 8, 7, 5 },
{ 8, 1, 8 },
{ 8, 3, 8 },
{ 8, 8, 4 },
{ 8, 4, 8 },
/* 8/9 bit codewords */
{ 8, 5, 7 }, { 8, 5, 7 },
{ 8, 8, 5 }, { 8, 8, 5 },
{ 8, 5, 8 }, { 8, 5, 8 },
{ 9, 7, 6 },
{ 9, 6, 7 },
/* 9 bit codewords */
{ 9, 9, 2 },
{ 9, 6, 0 },
{ 9, 6, 8 },
{ 9, 9, 3 },
{ 9, 3, 9 },
{ 9, 9, 1 },
{ 9, 2, 9 },
{ 9, 0, 6 },
{ 9, 8, 6 },
{ 9, 9, 4 },
{ 9, 4, 9 },
{ 9, 10, 2 },
{ 9, 1, 9 },
{ 9, 7, 7 },
{ 9, 8, 7 },
{ 9, 9, 5 },
{ 9, 7, 8 },
{ 9, 10, 3 },
{ 9, 5, 9 },
{ 9, 10, 4 },
{ 9, 2, 10 },
{ 9, 10, 1 },
{ 9, 3, 10 },
{ 9, 9, 6 },
/* 9/10 bit codewords */
{ 9, 6, 9 }, { 9, 6, 9 },
{ 9, 8, 0 }, { 9, 8, 0 },
{ 9, 4, 10 }, { 9, 4, 10 },
{ 9, 7, 0 }, { 9, 7, 0 },
{ 9, 11, 2 }, { 9, 11, 2 },
{ 10, 7, 9 },
{ 10, 11, 3 },
{ 10, 10, 6 },
{ 10, 1, 10 },
{ 10, 11, 1 },
{ 10, 9, 7 },
/* 10 bit codewords */
{ 10, 0, 7 },
{ 10, 8, 8 },
{ 10, 10, 5 },
{ 10, 3, 11 },
{ 10, 5, 10 },
{ 10, 8, 9 },
{ 10, 11, 5 },
{ 10, 0, 8 },
{ 10, 11, 4 },
{ 10, 2, 11 },
{ 10, 7, 10 },
{ 10, 6, 10 },
{ 10, 10, 7 },
{ 10, 4, 11 },
{ 10, 1, 11 },
{ 10, 12, 2 },
{ 10, 9, 8 },
{ 10, 12, 3 },
{ 10, 11, 6 },
{ 10, 5, 11 },
{ 10, 12, 4 },
{ 10, 11, 7 },
{ 10, 12, 5 },
{ 10, 3, 12 },
{ 10, 6, 11 },
{ 10, 9, 0 },
{ 10, 10, 8 },
{ 10, 10, 0 },
{ 10, 12, 1 },
{ 10, 0, 9 },
{ 10, 4, 12 },
{ 10, 9, 9 },
/* 10/11/12 bit codewords */
{ 10, 12, 6 }, { 10, 12, 6 }, { 10, 12, 6 }, { 10, 12, 6 },
{ 10, 2, 12 }, { 10, 2, 12 }, { 10, 2, 12 }, { 10, 2, 12 },
{ 10, 8, 10 }, { 10, 8, 10 }, { 10, 8, 10 }, { 10, 8, 10 },
{ 11, 9, 10 }, { 11, 9, 10 },
{ 11, 1, 12 }, { 11, 1, 12 },
{ 11, 11, 8 }, { 11, 11, 8 },
{ 11, 12, 7 }, { 11, 12, 7 },
{ 11, 7, 11 }, { 11, 7, 11 },
{ 11, 5, 12 }, { 11, 5, 12 },
{ 11, 6, 12 }, { 11, 6, 12 },
{ 11, 10, 9 }, { 11, 10, 9 },
{ 11, 8, 11 }, { 11, 8, 11 },
{ 11, 12, 8 }, { 11, 12, 8 },
{ 11, 0, 10 }, { 11, 0, 10 },
{ 11, 7, 12 }, { 11, 7, 12 },
{ 11, 11, 0 }, { 11, 11, 0 },
{ 11, 10, 10 }, { 11, 10, 10 },
{ 11, 11, 9 }, { 11, 11, 9 },
{ 11, 11, 10 }, { 11, 11, 10 },
{ 11, 0, 11 }, { 11, 0, 11 },
{ 11, 11, 11 }, { 11, 11, 11 },
{ 11, 9, 11 }, { 11, 9, 11 },
{ 11, 10, 11 }, { 11, 10, 11 },
{ 11, 12, 0 }, { 11, 12, 0 },
{ 11, 8, 12 }, { 11, 8, 12 },
{ 12, 12, 9 },
{ 12, 10, 12 },
{ 12, 9, 12 },
{ 12, 11, 12 },
{ 12, 12, 11 },
{ 12, 0, 12 },
{ 12, 12, 10 },
{ 12, 12, 12 }
};

View File

@ -0,0 +1,415 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: hcb_11.h,v 1.5 2007/11/01 12:34:11 menno Exp $
**/
/* 2-step huffman table HCB_11 */
/* 1st step: 5 bits
* 2^5 = 32 entries
*
* Used to find offset into 2nd step table and number of extra bits to get
*/
static hcb hcb11_1[] = {
/* 4 bits */
{ /* 00000 */ 0, 0 },
{ /* */ 0, 0 },
{ /* 00010 */ 1, 0 },
{ /* */ 1, 0 },
/* 5 bits */
{ /* 00100 */ 2, 0 },
{ /* 00101 */ 3, 0 },
{ /* 00110 */ 4, 0 },
{ /* 00111 */ 5, 0 },
{ /* 01000 */ 6, 0 },
{ /* 01001 */ 7, 0 },
/* 6 bits */
{ /* 01010 */ 8, 1 },
{ /* 01011 */ 10, 1 },
{ /* 01100 */ 12, 1 },
/* 6/7 bits */
{ /* 01101 */ 14, 2 },
/* 7 bits */
{ /* 01110 */ 18, 2 },
{ /* 01111 */ 22, 2 },
{ /* 10000 */ 26, 2 },
/* 7/8 bits */
{ /* 10001 */ 30, 3 },
/* 8 bits */
{ /* 10010 */ 38, 3 },
{ /* 10011 */ 46, 3 },
{ /* 10100 */ 54, 3 },
{ /* 10101 */ 62, 3 },
{ /* 10110 */ 70, 3 },
{ /* 10111 */ 78, 3 },
/* 8/9 bits */
{ /* 11000 */ 86, 4 },
/* 9 bits */
{ /* 11001 */ 102, 4 },
{ /* 11010 */ 118, 4 },
{ /* 11011 */ 134, 4 },
/* 9/10 bits */
{ /* 11100 */ 150, 5 },
/* 10 bits */
{ /* 11101 */ 182, 5 },
{ /* 11110 */ 214, 5 },
/* 10/11/12 bits */
{ /* 11111 */ 246, 7 }
};
/* 2nd step table
*
* Gives size of codeword and actual data (x,y,v,w)
*/
static hcb_2_pair hcb11_2[] = {
/* 4 */
{ 4, 0, 0 },
{ 4, 1, 1 },
/* 5 */
{ 5, 16, 16 },
{ 5, 1, 0 },
{ 5, 0, 1 },
{ 5, 2, 1 },
{ 5, 1, 2 },
{ 5, 2, 2 },
/* 6 */
{ 6, 1, 3 },
{ 6, 3, 1 },
{ 6, 3, 2 },
{ 6, 2, 0 },
{ 6, 2, 3 },
{ 6, 0, 2 },
/* 6/7 */
{ 6, 3, 3 }, { 6, 3, 3 },
{ 7, 4, 1 },
{ 7, 1, 4 },
/* 7 */
{ 7, 4, 2 },
{ 7, 2, 4 },
{ 7, 4, 3 },
{ 7, 3, 4 },
{ 7, 3, 0 },
{ 7, 0, 3 },
{ 7, 5, 1 },
{ 7, 5, 2 },
{ 7, 2, 5 },
{ 7, 4, 4 },
{ 7, 1, 5 },
{ 7, 5, 3 },
/* 7/8 */
{ 7, 3, 5 }, { 7, 3, 5 },
{ 7, 5, 4 }, { 7, 5, 4 },
{ 8, 4, 5 },
{ 8, 6, 2 },
{ 8, 2, 6 },
{ 8, 6, 1 },
/* 8 */
{ 8, 6, 3 },
{ 8, 3, 6 },
{ 8, 1, 6 },
{ 8, 4, 16 },
{ 8, 3, 16 },
{ 8, 16, 5 },
{ 8, 16, 3 },
{ 8, 16, 4 },
{ 8, 6, 4 },
{ 8, 16, 6 },
{ 8, 4, 0 },
{ 8, 4, 6 },
{ 8, 0, 4 },
{ 8, 2, 16 },
{ 8, 5, 5 },
{ 8, 5, 16 },
{ 8, 16, 7 },
{ 8, 16, 2 },
{ 8, 16, 8 },
{ 8, 2, 7 },
{ 8, 7, 2 },
{ 8, 3, 7 },
{ 8, 6, 5 },
{ 8, 5, 6 },
{ 8, 6, 16 },
{ 8, 16, 10 },
{ 8, 7, 3 },
{ 8, 7, 1 },
{ 8, 16, 9 },
{ 8, 7, 16 },
{ 8, 1, 16 },
{ 8, 1, 7 },
{ 8, 4, 7 },
{ 8, 16, 11 },
{ 8, 7, 4 },
{ 8, 16, 12 },
{ 8, 8, 16 },
{ 8, 16, 1 },
{ 8, 6, 6 },
{ 8, 9, 16 },
{ 8, 2, 8 },
{ 8, 5, 7 },
{ 8, 10, 16 },
{ 8, 16, 13 },
{ 8, 8, 3 },
{ 8, 8, 2 },
{ 8, 3, 8 },
{ 8, 5, 0 },
/* 8/9 */
{ 8, 16, 14 }, { 8, 16, 14 },
{ 8, 11, 16 }, { 8, 11, 16 },
{ 8, 7, 5 }, { 8, 7, 5 },
{ 8, 4, 8 }, { 8, 4, 8 },
{ 8, 6, 7 }, { 8, 6, 7 },
{ 8, 7, 6 }, { 8, 7, 6 },
{ 8, 0, 5 }, { 8, 0, 5 },
{ 9, 8, 4 },
{ 9, 16, 15 },
/* 9 */
{ 9, 12, 16 },
{ 9, 1, 8 },
{ 9, 8, 1 },
{ 9, 14, 16 },
{ 9, 5, 8 },
{ 9, 13, 16 },
{ 9, 3, 9 },
{ 9, 8, 5 },
{ 9, 7, 7 },
{ 9, 2, 9 },
{ 9, 8, 6 },
{ 9, 9, 2 },
{ 9, 9, 3 },
{ 9, 15, 16 },
{ 9, 4, 9 },
{ 9, 6, 8 },
{ 9, 6, 0 },
{ 9, 9, 4 },
{ 9, 5, 9 },
{ 9, 8, 7 },
{ 9, 7, 8 },
{ 9, 1, 9 },
{ 9, 10, 3 },
{ 9, 0, 6 },
{ 9, 10, 2 },
{ 9, 9, 1 },
{ 9, 9, 5 },
{ 9, 4, 10 },
{ 9, 2, 10 },
{ 9, 9, 6 },
{ 9, 3, 10 },
{ 9, 6, 9 },
{ 9, 10, 4 },
{ 9, 8, 8 },
{ 9, 10, 5 },
{ 9, 9, 7 },
{ 9, 11, 3 },
{ 9, 1, 10 },
{ 9, 7, 0 },
{ 9, 10, 6 },
{ 9, 7, 9 },
{ 9, 3, 11 },
{ 9, 5, 10 },
{ 9, 10, 1 },
{ 9, 4, 11 },
{ 9, 11, 2 },
{ 9, 13, 2 },
{ 9, 6, 10 },
/* 9/10 */
{ 9, 13, 3 }, { 9, 13, 3 },
{ 9, 2, 11 }, { 9, 2, 11 },
{ 9, 16, 0 }, { 9, 16, 0 },
{ 9, 5, 11 }, { 9, 5, 11 },
{ 9, 11, 5 }, { 9, 11, 5 },
{ 10, 11, 4 },
{ 10, 9, 8 },
{ 10, 7, 10 },
{ 10, 8, 9 },
{ 10, 0, 16 },
{ 10, 4, 13 },
{ 10, 0, 7 },
{ 10, 3, 13 },
{ 10, 11, 6 },
{ 10, 13, 1 },
{ 10, 13, 4 },
{ 10, 12, 3 },
{ 10, 2, 13 },
{ 10, 13, 5 },
{ 10, 8, 10 },
{ 10, 6, 11 },
{ 10, 10, 8 },
{ 10, 10, 7 },
{ 10, 14, 2 },
{ 10, 12, 4 },
{ 10, 1, 11 },
{ 10, 4, 12 },
/* 10 */
{ 10, 11, 1 },
{ 10, 3, 12 },
{ 10, 1, 13 },
{ 10, 12, 2 },
{ 10, 7, 11 },
{ 10, 3, 14 },
{ 10, 5, 12 },
{ 10, 5, 13 },
{ 10, 14, 4 },
{ 10, 4, 14 },
{ 10, 11, 7 },
{ 10, 14, 3 },
{ 10, 12, 5 },
{ 10, 13, 6 },
{ 10, 12, 6 },
{ 10, 8, 0 },
{ 10, 11, 8 },
{ 10, 2, 12 },
{ 10, 9, 9 },
{ 10, 14, 5 },
{ 10, 6, 13 },
{ 10, 10, 10 },
{ 10, 15, 2 },
{ 10, 8, 11 },
{ 10, 9, 10 },
{ 10, 14, 6 },
{ 10, 10, 9 },
{ 10, 5, 14 },
{ 10, 11, 9 },
{ 10, 14, 1 },
{ 10, 2, 14 },
{ 10, 6, 12 },
{ 10, 1, 12 },
{ 10, 13, 8 },
{ 10, 0, 8 },
{ 10, 13, 7 },
{ 10, 7, 12 },
{ 10, 12, 7 },
{ 10, 7, 13 },
{ 10, 15, 3 },
{ 10, 12, 1 },
{ 10, 6, 14 },
{ 10, 2, 15 },
{ 10, 15, 5 },
{ 10, 15, 4 },
{ 10, 1, 14 },
{ 10, 9, 11 },
{ 10, 4, 15 },
{ 10, 14, 7 },
{ 10, 8, 13 },
{ 10, 13, 9 },
{ 10, 8, 12 },
{ 10, 5, 15 },
{ 10, 3, 15 },
{ 10, 10, 11 },
{ 10, 11, 10 },
{ 10, 12, 8 },
{ 10, 15, 6 },
{ 10, 15, 7 },
{ 10, 8, 14 },
{ 10, 15, 1 },
{ 10, 7, 14 },
{ 10, 9, 0 },
{ 10, 0, 9 },
/* 10/11/12 */
{ 10, 9, 13 }, { 10, 9, 13 }, { 10, 9, 13 }, { 10, 9, 13 },
{ 10, 9, 12 }, { 10, 9, 12 }, { 10, 9, 12 }, { 10, 9, 12 },
{ 10, 12, 9 }, { 10, 12, 9 }, { 10, 12, 9 }, { 10, 12, 9 },
{ 10, 14, 8 }, { 10, 14, 8 }, { 10, 14, 8 }, { 10, 14, 8 },
{ 10, 10, 13 }, { 10, 10, 13 }, { 10, 10, 13 }, { 10, 10, 13 },
{ 10, 14, 9 }, { 10, 14, 9 }, { 10, 14, 9 }, { 10, 14, 9 },
{ 10, 12, 10 }, { 10, 12, 10 }, { 10, 12, 10 }, { 10, 12, 10 },
{ 10, 6, 15 }, { 10, 6, 15 }, { 10, 6, 15 }, { 10, 6, 15 },
{ 10, 7, 15 }, { 10, 7, 15 }, { 10, 7, 15 }, { 10, 7, 15 },
{ 11, 9, 14 }, { 11, 9, 14 },
{ 11, 15, 8 }, { 11, 15, 8 },
{ 11, 11, 11 }, { 11, 11, 11 },
{ 11, 11, 14 }, { 11, 11, 14 },
{ 11, 1, 15 }, { 11, 1, 15 },
{ 11, 10, 12 }, { 11, 10, 12 },
{ 11, 10, 14 }, { 11, 10, 14 },
{ 11, 13, 11 }, { 11, 13, 11 },
{ 11, 13, 10 }, { 11, 13, 10 },
{ 11, 11, 13 }, { 11, 11, 13 },
{ 11, 11, 12 }, { 11, 11, 12 },
{ 11, 8, 15 }, { 11, 8, 15 },
{ 11, 14, 11 }, { 11, 14, 11 },
{ 11, 13, 12 }, { 11, 13, 12 },
{ 11, 12, 13 }, { 11, 12, 13 },
{ 11, 15, 9 }, { 11, 15, 9 },
{ 11, 14, 10 }, { 11, 14, 10 },
{ 11, 10, 0 }, { 11, 10, 0 },
{ 11, 12, 11 }, { 11, 12, 11 },
{ 11, 9, 15 }, { 11, 9, 15 },
{ 11, 0, 10 }, { 11, 0, 10 },
{ 11, 12, 12 }, { 11, 12, 12 },
{ 11, 11, 0 }, { 11, 11, 0 },
{ 11, 12, 14 }, { 11, 12, 14 },
{ 11, 10, 15 }, { 11, 10, 15 },
{ 11, 13, 13 }, { 11, 13, 13 },
{ 11, 0, 13 }, { 11, 0, 13 },
{ 11, 14, 12 }, { 11, 14, 12 },
{ 11, 15, 10 }, { 11, 15, 10 },
{ 11, 15, 11 }, { 11, 15, 11 },
{ 11, 11, 15 }, { 11, 11, 15 },
{ 11, 14, 13 }, { 11, 14, 13 },
{ 11, 13, 0 }, { 11, 13, 0 },
{ 11, 0, 11 }, { 11, 0, 11 },
{ 11, 13, 14 }, { 11, 13, 14 },
{ 11, 15, 12 }, { 11, 15, 12 },
{ 11, 15, 13 }, { 11, 15, 13 },
{ 11, 12, 15 }, { 11, 12, 15 },
{ 11, 14, 0 }, { 11, 14, 0 },
{ 11, 14, 14 }, { 11, 14, 14 },
{ 11, 13, 15 }, { 11, 13, 15 },
{ 11, 12, 0 }, { 11, 12, 0 },
{ 11, 14, 15 }, { 11, 14, 15 },
{ 12, 0, 14 },
{ 12, 0, 12 },
{ 12, 15, 14 },
{ 12, 15, 0 },
{ 12, 0, 15 },
{ 12, 15, 15 }
};

View File

@ -0,0 +1,185 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: hcb_2.h,v 1.5 2007/11/01 12:34:11 menno Exp $
**/
/* 2-step huffman table HCB_2 */
/* 1st step: 5 bits
* 2^5 = 32 entries
*
* Used to find offset into 2nd step table and number of extra bits to get
*/
static hcb hcb2_1[] = {
{ /* 00000 */ 0, 0 },
{ /* */ 0, 0 },
{ /* */ 0, 0 },
{ /* */ 0, 0 },
{ /* 00100 */ 1, 0 },
{ /* */ 1, 0 },
{ /* 00110 */ 2, 0 },
{ /* 00111 */ 3, 0 },
{ /* 01000 */ 4, 0 },
{ /* 01001 */ 5, 0 },
{ /* 01010 */ 6, 0 },
{ /* 01011 */ 7, 0 },
{ /* 01100 */ 8, 0 },
/* 6 bit codewords */
{ /* 01101 */ 9, 1 },
{ /* 01110 */ 11, 1 },
{ /* 01111 */ 13, 1 },
{ /* 10000 */ 15, 1 },
{ /* 10001 */ 17, 1 },
{ /* 10010 */ 19, 1 },
{ /* 10011 */ 21, 1 },
{ /* 10100 */ 23, 1 },
{ /* 10101 */ 25, 1 },
{ /* 10110 */ 27, 1 },
{ /* 10111 */ 29, 1 },
{ /* 11000 */ 31, 1 },
/* 7 bit codewords */
{ /* 11001 */ 33, 2 },
{ /* 11010 */ 37, 2 },
{ /* 11011 */ 41, 2 },
/* 7/8 bit codewords */
{ /* 11100 */ 45, 3 },
/* 8 bit codewords */
{ /* 11101 */ 53, 3 },
{ /* 11110 */ 61, 3 },
/* 8/9 bit codewords */
{ /* 11111 */ 69, 4 }
};
/* 2nd step table
*
* Gives size of codeword and actual data (x,y,v,w)
*/
static hcb_2_quad hcb2_2[] = {
/* 3 bit codeword */
{ 3, 0, 0, 0, 0 },
/* 4 bit codeword */
{ 4, 1, 0, 0, 0 },
/* 5 bit codewords */
{ 5, -1, 0, 0, 0 },
{ 5, 0, 0, 0, 1 },
{ 5, 0, 0, -1, 0 },
{ 5, 0, 0, 0, -1 },
{ 5, 0, -1, 0, 0 },
{ 5, 0, 0, 1, 0 },
{ 5, 0, 1, 0, 0 },
/* 6 bit codewords */
{ 6, 0, -1, 1, 0 },
{ 6, -1, 1, 0, 0 },
{ 6, 0, 1, -1, 0 },
{ 6, 0, 0, 1, -1 },
{ 6, 0, 1, 0, -1 },
{ 6, 0, 0, -1, 1 },
{ 6, -1, 0, 0, -1 },
{ 6, 1, -1, 0, 0 },
{ 6, 1, 0, -1, 0 },
{ 6, -1, -1, 0, 0 },
{ 6, 0, 0, -1, -1 },
{ 6, 1, 0, 1, 0 },
{ 6, 1, 0, 0, 1 },
{ 6, 0, -1, 0, 1 },
{ 6, -1, 0, 1, 0 },
{ 6, 0, 1, 0, 1 },
{ 6, 0, -1, -1, 0 },
{ 6, -1, 0, 0, 1 },
{ 6, 0, -1, 0, -1 },
{ 6, -1, 0, -1, 0 },
{ 6, 1, 1, 0, 0 },
{ 6, 0, 1, 1, 0 },
{ 6, 0, 0, 1, 1 },
{ 6, 1, 0, 0, -1 },
/* 7 bit codewords */
{ 7, 0, 1, -1, 1 },
{ 7, 1, 0, -1, 1 },
{ 7, -1, 1, -1, 0 },
{ 7, 0, -1, 1, -1 },
{ 7, 1, -1, 1, 0 },
{ 7, 1, 1, 0, -1 },
{ 7, 1, 0, 1, 1 },
{ 7, -1, 1, 1, 0 },
{ 7, 0, -1, -1, 1 },
{ 7, 1, 1, 1, 0 },
{ 7, -1, 0, 1, -1 },
{ 7, -1, -1, -1, 0 },
/* 7/8 bit codewords */
{ 7, -1, 0, -1, 1 }, { 7, -1, 0, -1, 1 },
{ 7, 1, -1, -1, 0 }, { 7, 1, -1, -1, 0 },
{ 7, 1, 1, -1, 0 }, { 7, 1, 1, -1, 0 },
{ 8, 1, -1, 0, 1 },
{ 8, -1, 1, 0, -1 },
/* 8 bit codewords */
{ 8, -1, -1, 1, 0 },
{ 8, -1, 0, 1, 1 },
{ 8, -1, -1, 0, 1 },
{ 8, -1, -1, 0, -1 },
{ 8, 0, -1, -1, -1 },
{ 8, 1, 0, 1, -1 },
{ 8, 1, 0, -1, -1 },
{ 8, 0, 1, -1, -1 },
{ 8, 0, 1, 1, 1 },
{ 8, -1, 1, 0, 1 },
{ 8, -1, 0, -1, -1 },
{ 8, 0, 1, 1, -1 },
{ 8, 1, -1, 0, -1 },
{ 8, 0, -1, 1, 1 },
{ 8, 1, 1, 0, 1 },
{ 8, 1, -1, 1, -1 },
/* 8/9 bit codewords */
{ 8, -1, 1, -1, 1 }, { 8, -1, 1, -1, 1 },
{ 9, 1, -1, -1, 1 },
{ 9, -1, -1, -1, -1 },
{ 9, -1, 1, 1, -1 },
{ 9, -1, 1, 1, 1 },
{ 9, 1, 1, 1, 1 },
{ 9, -1, -1, 1, -1 },
{ 9, 1, -1, 1, 1 },
{ 9, -1, 1, -1, -1 },
{ 9, -1, -1, 1, 1 },
{ 9, 1, 1, -1, -1 },
{ 9, 1, -1, -1, -1 },
{ 9, -1, -1, -1, 1 },
{ 9, 1, 1, -1, 1 },
{ 9, 1, 1, 1, -1 }
};

View File

@ -0,0 +1,196 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: hcb_3.h,v 1.5 2007/11/01 12:34:11 menno Exp $
**/
/* Binary search huffman table HCB_3 */
static hcb_bin_quad hcb3[] = {
{ /* 0 */ 0, { 1, 2, 0, 0 } },
{ /* 1 */ 1, { 0, 0, 0, 0 } }, /* 0 */
{ /* 2 */ 0, { 1, 2, 0, 0 } },
{ /* 3 */ 0, { 2, 3, 0, 0 } },
{ /* 4 */ 0, { 3, 4, 0, 0 } },
{ /* 5 */ 0, { 4, 5, 0, 0 } },
{ /* 6 */ 0, { 5, 6, 0, 0 } },
{ /* 7 */ 0, { 6, 7, 0, 0 } },
{ /* 8 */ 0, { 7, 8, 0, 0 } },
{ /* 9 */ 1, { 1, 0, 0, 0 } }, /* 1000 */
{ /* 10 */ 1, { 0, 0, 0, 1 } }, /* 1001 */
{ /* 11 */ 1, { 0, 1, 0, 0 } }, /* 1010 */
{ /* 12 */ 1, { 0, 0, 1, 0 } }, /* 1011 */
{ /* 13 */ 0, { 4, 5, 0, 0 } },
{ /* 14 */ 0, { 5, 6, 0, 0 } },
{ /* 15 */ 0, { 6, 7, 0, 0 } },
{ /* 16 */ 0, { 7, 8, 0, 0 } },
{ /* 17 */ 1, { 1, 1, 0, 0 } },
{ /* 18 */ 1, { 0, 0, 1, 1 } },
{ /* 19 */ 0, { 6, 7, 0, 0 } },
{ /* 20 */ 0, { 7, 8, 0, 0 } },
{ /* 21 */ 0, { 8, 9, 0, 0 } },
{ /* 22 */ 0, { 9, 10, 0, 0 } },
{ /* 23 */ 0, { 10, 11, 0, 0 } },
{ /* 24 */ 0, { 11, 12, 0, 0 } },
{ /* 25 */ 1, { 0, 1, 1, 0 } }, /* 110100 */
{ /* 26 */ 1, { 0, 1, 0, 1 } }, /* 110101 */
{ /* 27 */ 1, { 1, 0, 1, 0 } }, /* 110110 */
{ /* 28 */ 1, { 0, 1, 1, 1 } }, /* 110111 */
{ /* 29 */ 1, { 1, 0, 0, 1 } }, /* 111000 */
{ /* 30 */ 1, { 1, 1, 1, 0 } }, /* 111001 */
{ /* 31 */ 0, { 6, 7, 0, 0 } },
{ /* 32 */ 0, { 7, 8, 0, 0 } },
{ /* 33 */ 0, { 8, 9, 0, 0 } },
{ /* 34 */ 0, { 9, 10, 0, 0 } },
{ /* 35 */ 0, { 10, 11, 0, 0 } },
{ /* 36 */ 0, { 11, 12, 0, 0 } },
{ /* 37 */ 1, { 1, 1, 1, 1 } }, /* 1110100 */
{ /* 38 */ 1, { 1, 0, 1, 1 } }, /* 1110101 */
{ /* 39 */ 1, { 1, 1, 0, 1 } }, /* 1110110 */
{ /* 40 */ 0, { 9, 10, 0, 0 } },
{ /* 41 */ 0, { 10, 11, 0, 0 } },
{ /* 42 */ 0, { 11, 12, 0, 0 } },
{ /* 43 */ 0, { 12, 13, 0, 0 } },
{ /* 44 */ 0, { 13, 14, 0, 0 } },
{ /* 45 */ 0, { 14, 15, 0, 0 } },
{ /* 46 */ 0, { 15, 16, 0, 0 } },
{ /* 47 */ 0, { 16, 17, 0, 0 } },
{ /* 48 */ 0, { 17, 18, 0, 0 } },
{ /* 49 */ 1, { 2, 0, 0, 0 } }, /* 11101110 */
{ /* 50 */ 1, { 0, 0, 0, 2 } }, /* 11101111 */
{ /* 51 */ 1, { 0, 0, 1, 2 } }, /* 11110000 */
{ /* 52 */ 1, { 2, 1, 0, 0 } }, /* 11110001 */
{ /* 53 */ 1, { 1, 2, 1, 0 } }, /* 11110010 */
{ /* 54 */ 0, { 13, 14, 0, 0 } },
{ /* 55 */ 0, { 14, 15, 0, 0 } },
{ /* 56 */ 0, { 15, 16, 0, 0 } },
{ /* 57 */ 0, { 16, 17, 0, 0 } },
{ /* 58 */ 0, { 17, 18, 0, 0 } },
{ /* 59 */ 0, { 18, 19, 0, 0 } },
{ /* 60 */ 0, { 19, 20, 0, 0 } },
{ /* 61 */ 0, { 20, 21, 0, 0 } },
{ /* 62 */ 0, { 21, 22, 0, 0 } },
{ /* 63 */ 0, { 22, 23, 0, 0 } },
{ /* 64 */ 0, { 23, 24, 0, 0 } },
{ /* 65 */ 0, { 24, 25, 0, 0 } },
{ /* 66 */ 0, { 25, 26, 0, 0 } },
{ /* 67 */ 1, { 0, 0, 2, 1 } },
{ /* 68 */ 1, { 0, 1, 2, 1 } },
{ /* 69 */ 1, { 1, 2, 0, 0 } },
{ /* 70 */ 1, { 0, 1, 1, 2 } },
{ /* 71 */ 1, { 2, 1, 1, 0 } },
{ /* 72 */ 1, { 0, 0, 2, 0 } },
{ /* 73 */ 1, { 0, 2, 1, 0 } },
{ /* 74 */ 1, { 0, 1, 2, 0 } },
{ /* 75 */ 1, { 0, 2, 0, 0 } },
{ /* 76 */ 1, { 0, 1, 0, 2 } },
{ /* 77 */ 1, { 2, 0, 1, 0 } },
{ /* 78 */ 1, { 1, 2, 1, 1 } },
{ /* 79 */ 1, { 0, 2, 1, 1 } },
{ /* 80 */ 1, { 1, 1, 2, 0 } },
{ /* 81 */ 1, { 1, 1, 2, 1 } },
{ /* 82 */ 0, { 11, 12, 0, 0 } },
{ /* 83 */ 0, { 12, 13, 0, 0 } },
{ /* 84 */ 0, { 13, 14, 0, 0 } },
{ /* 85 */ 0, { 14, 15, 0, 0 } },
{ /* 86 */ 0, { 15, 16, 0, 0 } },
{ /* 87 */ 0, { 16, 17, 0, 0 } },
{ /* 88 */ 0, { 17, 18, 0, 0 } },
{ /* 89 */ 0, { 18, 19, 0, 0 } },
{ /* 90 */ 0, { 19, 20, 0, 0 } },
{ /* 91 */ 0, { 20, 21, 0, 0 } },
{ /* 92 */ 0, { 21, 22, 0, 0 } },
{ /* 93 */ 1, { 1, 2, 0, 1 } }, /* 1111101010 */
{ /* 94 */ 1, { 1, 0, 2, 0 } }, /* 1111101011 */
{ /* 95 */ 1, { 1, 0, 2, 1 } }, /* 1111101100 */
{ /* 96 */ 1, { 0, 2, 0, 1 } }, /* 1111101101 */
{ /* 97 */ 1, { 2, 1, 1, 1 } }, /* 1111101110 */
{ /* 98 */ 1, { 1, 1, 1, 2 } }, /* 1111101111 */
{ /* 99 */ 1, { 2, 1, 0, 1 } }, /* 1111110000 */
{ /* 00 */ 1, { 1, 0, 1, 2 } }, /* 1111110001 */
{ /* 01 */ 1, { 0, 0, 2, 2 } }, /* 1111110010 */
{ /* 02 */ 1, { 0, 1, 2, 2 } }, /* 1111110011 */
{ /* 03 */ 1, { 2, 2, 1, 0 } }, /* 1111110100 */
{ /* 04 */ 1, { 1, 2, 2, 0 } }, /* 1111110101 */
{ /* 05 */ 1, { 1, 0, 0, 2 } }, /* 1111110110 */
{ /* 06 */ 1, { 2, 0, 0, 1 } }, /* 1111110111 */
{ /* 07 */ 1, { 0, 2, 2, 1 } }, /* 1111111000 */
{ /* 08 */ 0, { 7, 8, 0, 0 } },
{ /* 09 */ 0, { 8, 9, 0, 0 } },
{ /* 10 */ 0, { 9, 10, 0, 0 } },
{ /* 11 */ 0, { 10, 11, 0, 0 } },
{ /* 12 */ 0, { 11, 12, 0, 0 } },
{ /* 13 */ 0, { 12, 13, 0, 0 } },
{ /* 14 */ 0, { 13, 14, 0, 0 } },
{ /* 15 */ 1, { 2, 2, 0, 0 } }, /* 11111110010 */
{ /* 16 */ 1, { 1, 2, 2, 1 } }, /* 11111110011 */
{ /* 17 */ 1, { 1, 1, 0, 2 } }, /* 11111110100 */
{ /* 18 */ 1, { 2, 0, 1, 1 } }, /* 11111110101 */
{ /* 19 */ 1, { 1, 1, 2, 2 } }, /* 11111110110 */
{ /* 20 */ 1, { 2, 2, 1, 1 } }, /* 11111110111 */
{ /* 21 */ 1, { 0, 2, 2, 0 } }, /* 11111111000 */
{ /* 22 */ 1, { 0, 2, 1, 2 } }, /* 11111111001 */
{ /* 23 */ 0, { 6, 7, 0, 0 } },
{ /* 24 */ 0, { 7, 8, 0, 0 } },
{ /* 25 */ 0, { 8, 9, 0, 0 } },
{ /* 26 */ 0, { 9, 10, 0, 0 } },
{ /* 27 */ 0, { 10, 11, 0, 0 } },
{ /* 28 */ 0, { 11, 12, 0, 0 } },
{ /* 29 */ 1, { 1, 0, 2, 2 } }, /* 111111110100 */
{ /* 30 */ 1, { 2, 2, 0, 1 } }, /* 111111110101 */
{ /* 31 */ 1, { 2, 1, 2, 0 } }, /* 111111110110 */
{ /* 32 */ 1, { 2, 2, 2, 0 } }, /* 111111110111 */
{ /* 33 */ 1, { 0, 2, 2, 2 } }, /* 111111111000 */
{ /* 34 */ 1, { 2, 2, 2, 1 } }, /* 111111111001 */
{ /* 35 */ 1, { 2, 1, 2, 1 } }, /* 111111111010 */
{ /* 36 */ 1, { 1, 2, 1, 2 } }, /* 111111111011 */
{ /* 37 */ 1, { 1, 2, 2, 2 } }, /* 111111111100 */
{ /* 38 */ 0, { 3, 4, 0, 0 } },
{ /* 39 */ 0, { 4, 5, 0, 0 } },
{ /* 40 */ 0, { 5, 6, 0, 0 } },
{ /* 41 */ 1, { 0, 2, 0, 2 } }, /* 1111111111010 */
{ /* 42 */ 1, { 2, 0, 2, 0 } }, /* 1111111111011 */
{ /* 43 */ 1, { 1, 2, 0, 2 } }, /* 1111111111100 */
{ /* 44 */ 0, { 3, 4, 0, 0 } },
{ /* 45 */ 0, { 4, 5, 0, 0 } },
{ /* 46 */ 0, { 5, 6, 0, 0 } },
{ /* 47 */ 1, { 2, 0, 2, 1 } }, /* 11111111111010 */
{ /* 48 */ 1, { 2, 1, 1, 2 } }, /* 11111111111011 */
{ /* 49 */ 1, { 2, 1, 0, 2 } }, /* 11111111111100 */
{ /* 50 */ 0, { 3, 4, 0, 0 } },
{ /* 51 */ 0, { 4, 5, 0, 0 } },
{ /* 52 */ 0, { 5, 6, 0, 0 } },
{ /* 53 */ 1, { 2, 2, 2, 2 } }, /* 111111111111010 */
{ /* 54 */ 1, { 2, 2, 1, 2 } }, /* 111111111111011 */
{ /* 55 */ 1, { 2, 1, 2, 2 } }, /* 111111111111100 */
{ /* 56 */ 1, { 2, 0, 1, 2 } }, /* 111111111111101 */
{ /* 57 */ 1, { 2, 0, 0, 2 } }, /* 111111111111110 */
{ /* 58 */ 0, { 1, 2, 0, 0 } },
{ /* 59 */ 1, { 2, 2, 0, 2 } }, /* 1111111111111110 */
{ /* 60 */ 1, { 2, 0, 2, 2 } } /* 1111111111111111 */
};

View File

@ -0,0 +1,199 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: hcb_4.h,v 1.5 2007/11/01 12:34:11 menno Exp $
**/
/* 2-step huffman table HCB_4 */
/* 1st step: 5 bits
* 2^5 = 32 entries
*
* Used to find offset into 2nd step table and number of extra bits to get
*/
static hcb hcb4_1[] = {
/* 4 bit codewords */
{ /* 00000 */ 0, 0 },
{ /* */ 0, 0 },
{ /* 00010 */ 1, 0 },
{ /* */ 1, 0 },
{ /* 00100 */ 2, 0 },
{ /* */ 2, 0 },
{ /* 00110 */ 3, 0 },
{ /* */ 3, 0 },
{ /* 01000 */ 4, 0 },
{ /* */ 4, 0 },
{ /* 01010 */ 5, 0 },
{ /* */ 5, 0 },
{ /* 01100 */ 6, 0 },
{ /* */ 6, 0 },
{ /* 01110 */ 7, 0 },
{ /* */ 7, 0 },
{ /* 10000 */ 8, 0 },
{ /* */ 8, 0 },
{ /* 10010 */ 9, 0 },
{ /* */ 9, 0 },
/* 5 bit codewords */
{ /* 10100 */ 10, 0 },
{ /* 10101 */ 11, 0 },
{ /* 10110 */ 12, 0 },
{ /* 10111 */ 13, 0 },
{ /* 11000 */ 14, 0 },
{ /* 11001 */ 15, 0 },
/* 7 bit codewords */
{ /* 11010 */ 16, 2 },
{ /* 11011 */ 20, 2 },
/* 7/8 bit codewords */
{ /* 11100 */ 24, 3 },
/* 8 bit codewords */
{ /* 11101 */ 32, 3 },
/* 8/9 bit codewords */
{ /* 11110 */ 40, 4 },
/* 9/10/11/12 bit codewords */
{ /* 11111 */ 56, 7 }
};
/* 2nd step table
*
* Gives size of codeword and actual data (x,y,v,w)
*/
static hcb_2_quad hcb4_2[] = {
/* 4 bit codewords */
{ 4, 1, 1, 1, 1 },
{ 4, 0, 1, 1, 1 },
{ 4, 1, 1, 0, 1 },
{ 4, 1, 1, 1, 0 },
{ 4, 1, 0, 1, 1 },
{ 4, 1, 0, 0, 0 },
{ 4, 1, 1, 0, 0 },
{ 4, 0, 0, 0, 0 },
{ 4, 0, 0, 1, 1 },
{ 4, 1, 0, 1, 0 },
/* 5 bit codewords */
{ 5, 1, 0, 0, 1 },
{ 5, 0, 1, 1, 0 },
{ 5, 0, 0, 0, 1 },
{ 5, 0, 1, 0, 1 },
{ 5, 0, 0, 1, 0 },
{ 5, 0, 1, 0, 0 },
/* 7 bit codewords */
/* first 5 bits: 11010 */
{ 7, 2, 1, 1, 1 },
{ 7, 1, 1, 2, 1 },
{ 7, 1, 2, 1, 1 },
{ 7, 1, 1, 1, 2 },
/* first 5 bits: 11011 */
{ 7, 2, 1, 1, 0 },
{ 7, 2, 1, 0, 1 },
{ 7, 1, 2, 1, 0 },
{ 7, 2, 0, 1, 1 },
/* 7/8 bit codewords */
/* first 5 bits: 11100 */
{ 7, 0, 1, 2, 1 }, { 7, 0, 1, 2, 1 },
{ 8, 0, 1, 1, 2 },
{ 8, 1, 1, 2, 0 },
{ 8, 0, 2, 1, 1 },
{ 8, 1, 0, 1, 2 },
{ 8, 1, 2, 0, 1 },
{ 8, 1, 1, 0, 2 },
/* 8 bit codewords */
{ 8, 1, 0, 2, 1 },
{ 8, 2, 1, 0, 0 },
{ 8, 2, 0, 1, 0 },
{ 8, 1, 2, 0, 0 },
{ 8, 2, 0, 0, 1 },
{ 8, 0, 1, 0, 2 },
{ 8, 0, 2, 1, 0 },
{ 8, 0, 0, 1, 2 },
/* 8/9 bit codewords */
{ 8, 0, 1, 2, 0 }, { 8, 0, 1, 2, 0 },
{ 8, 0, 2, 0, 1 }, { 8, 0, 2, 0, 1 },
{ 8, 1, 0, 0, 2 }, { 8, 1, 0, 0, 2 },
{ 8, 0, 0, 2, 1 }, { 8, 0, 0, 2, 1 },
{ 8, 1, 0, 2, 0 }, { 8, 1, 0, 2, 0 },
{ 8, 2, 0, 0, 0 }, { 8, 2, 0, 0, 0 },
{ 8, 0, 0, 0, 2 }, { 8, 0, 0, 0, 2 },
{ 9, 0, 2, 0, 0 },
{ 9, 0, 0, 2, 0 },
/* 9/10/11 bit codewords */
/* 9 bit codewords repeated 2^3 = 8 times */
{ 9, 1, 2, 2, 1 }, { 9, 1, 2, 2, 1 }, { 9, 1, 2, 2, 1 }, { 9, 1, 2, 2, 1 },
{ 9, 1, 2, 2, 1 }, { 9, 1, 2, 2, 1 }, { 9, 1, 2, 2, 1 }, { 9, 1, 2, 2, 1 },
{ 9, 2, 2, 1, 1 }, { 9, 2, 2, 1, 1 }, { 9, 2, 2, 1, 1 }, { 9, 2, 2, 1, 1 },
{ 9, 2, 2, 1, 1 }, { 9, 2, 2, 1, 1 }, { 9, 2, 2, 1, 1 }, { 9, 2, 2, 1, 1 },
{ 9, 2, 1, 2, 1 }, { 9, 2, 1, 2, 1 }, { 9, 2, 1, 2, 1 }, { 9, 2, 1, 2, 1 },
{ 9, 2, 1, 2, 1 }, { 9, 2, 1, 2, 1 }, { 9, 2, 1, 2, 1 }, { 9, 2, 1, 2, 1 },
{ 9, 1, 1, 2, 2 }, { 9, 1, 1, 2, 2 }, { 9, 1, 1, 2, 2 }, { 9, 1, 1, 2, 2 },
{ 9, 1, 1, 2, 2 }, { 9, 1, 1, 2, 2 }, { 9, 1, 1, 2, 2 }, { 9, 1, 1, 2, 2 },
{ 9, 1, 2, 1, 2 }, { 9, 1, 2, 1, 2 }, { 9, 1, 2, 1, 2 }, { 9, 1, 2, 1, 2 },
{ 9, 1, 2, 1, 2 }, { 9, 1, 2, 1, 2 }, { 9, 1, 2, 1, 2 }, { 9, 1, 2, 1, 2 },
{ 9, 2, 1, 1, 2 }, { 9, 2, 1, 1, 2 }, { 9, 2, 1, 1, 2 }, { 9, 2, 1, 1, 2 },
{ 9, 2, 1, 1, 2 }, { 9, 2, 1, 1, 2 }, { 9, 2, 1, 1, 2 }, { 9, 2, 1, 1, 2 },
/* 10 bit codewords repeated 2^2 = 4 times */
{ 10, 1, 2, 2, 0 }, { 10, 1, 2, 2, 0 }, { 10, 1, 2, 2, 0 }, { 10, 1, 2, 2, 0 },
{ 10, 2, 2, 1, 0 }, { 10, 2, 2, 1, 0 }, { 10, 2, 2, 1, 0 }, { 10, 2, 2, 1, 0 },
{ 10, 2, 1, 2, 0 }, { 10, 2, 1, 2, 0 }, { 10, 2, 1, 2, 0 }, { 10, 2, 1, 2, 0 },
{ 10, 0, 2, 2, 1 }, { 10, 0, 2, 2, 1 }, { 10, 0, 2, 2, 1 }, { 10, 0, 2, 2, 1 },
{ 10, 0, 1, 2, 2 }, { 10, 0, 1, 2, 2 }, { 10, 0, 1, 2, 2 }, { 10, 0, 1, 2, 2 },
{ 10, 2, 2, 0, 1 }, { 10, 2, 2, 0, 1 }, { 10, 2, 2, 0, 1 }, { 10, 2, 2, 0, 1 },
{ 10, 0, 2, 1, 2 }, { 10, 0, 2, 1, 2 }, { 10, 0, 2, 1, 2 }, { 10, 0, 2, 1, 2 },
{ 10, 2, 0, 2, 1 }, { 10, 2, 0, 2, 1 }, { 10, 2, 0, 2, 1 }, { 10, 2, 0, 2, 1 },
{ 10, 1, 0, 2, 2 }, { 10, 1, 0, 2, 2 }, { 10, 1, 0, 2, 2 }, { 10, 1, 0, 2, 2 },
{ 10, 2, 2, 2, 1 }, { 10, 2, 2, 2, 1 }, { 10, 2, 2, 2, 1 }, { 10, 2, 2, 2, 1 },
{ 10, 1, 2, 0, 2 }, { 10, 1, 2, 0, 2 }, { 10, 1, 2, 0, 2 }, { 10, 1, 2, 0, 2 },
{ 10, 2, 0, 1, 2 }, { 10, 2, 0, 1, 2 }, { 10, 2, 0, 1, 2 }, { 10, 2, 0, 1, 2 },
{ 10, 2, 1, 0, 2 }, { 10, 2, 1, 0, 2 }, { 10, 2, 1, 0, 2 }, { 10, 2, 1, 0, 2 },
{ 10, 1, 2, 2, 2 }, { 10, 1, 2, 2, 2 }, { 10, 1, 2, 2, 2 }, { 10, 1, 2, 2, 2 },
/* 11 bit codewords repeated 2^1 = 2 times */
{ 11, 2, 1, 2, 2 }, { 11, 2, 1, 2, 2 },
{ 11, 2, 2, 1, 2 }, { 11, 2, 2, 1, 2 },
{ 11, 0, 2, 2, 0 }, { 11, 0, 2, 2, 0 },
{ 11, 2, 2, 0, 0 }, { 11, 2, 2, 0, 0 },
{ 11, 0, 0, 2, 2 }, { 11, 0, 0, 2, 2 },
{ 11, 2, 0, 2, 0 }, { 11, 2, 0, 2, 0 },
{ 11, 0, 2, 0, 2 }, { 11, 0, 2, 0, 2 },
{ 11, 2, 0, 0, 2 }, { 11, 2, 0, 0, 2 },
{ 11, 2, 2, 2, 2 }, { 11, 2, 2, 2, 2 },
{ 11, 0, 2, 2, 2 }, { 11, 0, 2, 2, 2 },
{ 11, 2, 2, 2, 0 }, { 11, 2, 2, 2, 0 },
/* 12 bit codewords */
{ 12, 2, 2, 0, 2 },
{ 12, 2, 0, 2, 2 },
};

View File

@ -0,0 +1,196 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: hcb_5.h,v 1.5 2007/11/01 12:34:11 menno Exp $
**/
/* Binary search huffman table HCB_5 */
static hcb_bin_pair hcb5[] = {
{ /* 0 */ 0, { 1, 2 } },
{ /* 1 */ 1, { 0, 0 } }, /* 0 */
{ /* 2 */ 0, { 1, 2 } },
{ /* 3 */ 0, { 2, 3 } },
{ /* 4 */ 0, { 3, 4 } },
{ /* 5 */ 0, { 4, 5 } },
{ /* 6 */ 0, { 5, 6 } },
{ /* 7 */ 0, { 6, 7 } },
{ /* 8 */ 0, { 7, 8 } },
{ /* 9 */ 1, { -1, 0 } }, /* 1000 */
{ /* 10 */ 1, { 1, 0 } }, /* 1001 */
{ /* 11 */ 1, { 0, 1 } }, /* 1010 */
{ /* 12 */ 1, { 0, -1 } }, /* 1011 */
{ /* 13 */ 0, { 4, 5 } },
{ /* 14 */ 0, { 5, 6 } },
{ /* 15 */ 0, { 6, 7 } },
{ /* 16 */ 0, { 7, 8 } },
{ /* 17 */ 1, { 1, -1 } },
{ /* 18 */ 1, { -1, 1 } },
{ /* 19 */ 1, { -1, -1 } },
{ /* 20 */ 1, { 1, 1 } },
{ /* 21 */ 0, { 4, 5 } },
{ /* 22 */ 0, { 5, 6 } },
{ /* 23 */ 0, { 6, 7 } },
{ /* 24 */ 0, { 7, 8 } },
{ /* 25 */ 0, { 8, 9 } },
{ /* 26 */ 0, { 9, 10 } },
{ /* 27 */ 0, { 10, 11 } },
{ /* 28 */ 0, { 11, 12 } },
{ /* 29 */ 0, { 12, 13 } },
{ /* 30 */ 0, { 13, 14 } },
{ /* 31 */ 0, { 14, 15 } },
{ /* 32 */ 0, { 15, 16 } },
{ /* 33 */ 1, { -2, 0 } },
{ /* 34 */ 1, { 0, 2 } },
{ /* 35 */ 1, { 2, 0 } },
{ /* 36 */ 1, { 0, -2 } },
{ /* 37 */ 0, { 12, 13 } },
{ /* 38 */ 0, { 13, 14 } },
{ /* 39 */ 0, { 14, 15 } },
{ /* 40 */ 0, { 15, 16 } },
{ /* 41 */ 0, { 16, 17 } },
{ /* 42 */ 0, { 17, 18 } },
{ /* 43 */ 0, { 18, 19 } },
{ /* 44 */ 0, { 19, 20 } },
{ /* 45 */ 0, { 20, 21 } },
{ /* 46 */ 0, { 21, 22 } },
{ /* 47 */ 0, { 22, 23 } },
{ /* 48 */ 0, { 23, 24 } },
{ /* 49 */ 1, { -2, -1 } },
{ /* 50 */ 1, { 2, 1 } },
{ /* 51 */ 1, { -1, -2 } },
{ /* 52 */ 1, { 1, 2 } },
{ /* 53 */ 1, { -2, 1 } },
{ /* 54 */ 1, { 2, -1 } },
{ /* 55 */ 1, { -1, 2 } },
{ /* 56 */ 1, { 1, -2 } },
{ /* 57 */ 1, { -3, 0 } },
{ /* 58 */ 1, { 3, 0 } },
{ /* 59 */ 1, { 0, -3 } },
{ /* 60 */ 1, { 0, 3 } },
{ /* 61 */ 0, { 12, 13 } },
{ /* 62 */ 0, { 13, 14 } },
{ /* 63 */ 0, { 14, 15 } },
{ /* 64 */ 0, { 15, 16 } },
{ /* 65 */ 0, { 16, 17 } },
{ /* 66 */ 0, { 17, 18 } },
{ /* 67 */ 0, { 18, 19 } },
{ /* 68 */ 0, { 19, 20 } },
{ /* 69 */ 0, { 20, 21 } },
{ /* 70 */ 0, { 21, 22 } },
{ /* 71 */ 0, { 22, 23 } },
{ /* 72 */ 0, { 23, 24 } },
{ /* 73 */ 1, { -3, -1 } },
{ /* 74 */ 1, { 1, 3 } },
{ /* 75 */ 1, { 3, 1 } },
{ /* 76 */ 1, { -1, -3 } },
{ /* 77 */ 1, { -3, 1 } },
{ /* 78 */ 1, { 3, -1 } },
{ /* 79 */ 1, { 1, -3 } },
{ /* 80 */ 1, { -1, 3 } },
{ /* 81 */ 1, { -2, 2 } },
{ /* 82 */ 1, { 2, 2 } },
{ /* 83 */ 1, { -2, -2 } },
{ /* 84 */ 1, { 2, -2 } },
{ /* 85 */ 0, { 12, 13 } },
{ /* 86 */ 0, { 13, 14 } },
{ /* 87 */ 0, { 14, 15 } },
{ /* 88 */ 0, { 15, 16 } },
{ /* 89 */ 0, { 16, 17 } },
{ /* 90 */ 0, { 17, 18 } },
{ /* 91 */ 0, { 18, 19 } },
{ /* 92 */ 0, { 19, 20 } },
{ /* 93 */ 0, { 20, 21 } },
{ /* 94 */ 0, { 21, 22 } },
{ /* 95 */ 0, { 22, 23 } },
{ /* 96 */ 0, { 23, 24 } },
{ /* 97 */ 1, { -3, -2 } },
{ /* 98 */ 1, { 3, -2 } },
{ /* 99 */ 1, { -2, 3 } },
{ /* 00 */ 1, { 2, -3 } },
{ /* 01 */ 1, { 3, 2 } },
{ /* 02 */ 1, { 2, 3 } },
{ /* 03 */ 1, { -3, 2 } },
{ /* 04 */ 1, { -2, -3 } },
{ /* 05 */ 1, { 0, -4 } },
{ /* 06 */ 1, { -4, 0 } },
{ /* 07 */ 1, { 4, 1 } },
{ /* 08 */ 1, { 4, 0 } },
{ /* 09 */ 0, { 12, 13 } },
{ /* 10 */ 0, { 13, 14 } },
{ /* 11 */ 0, { 14, 15 } },
{ /* 12 */ 0, { 15, 16 } },
{ /* 13 */ 0, { 16, 17 } },
{ /* 14 */ 0, { 17, 18 } },
{ /* 15 */ 0, { 18, 19 } },
{ /* 16 */ 0, { 19, 20 } },
{ /* 17 */ 0, { 20, 21 } },
{ /* 18 */ 0, { 21, 22 } },
{ /* 19 */ 0, { 22, 23 } },
{ /* 20 */ 0, { 23, 24 } },
{ /* 21 */ 1, { -4, -1 } },
{ /* 22 */ 1, { 0, 4 } },
{ /* 23 */ 1, { 4, -1 } },
{ /* 24 */ 1, { -1, -4 } },
{ /* 25 */ 1, { 1, 4 } },
{ /* 26 */ 1, { -1, 4 } },
{ /* 27 */ 1, { -4, 1 } },
{ /* 28 */ 1, { 1, -4 } },
{ /* 29 */ 1, { 3, -3 } },
{ /* 30 */ 1, { -3, -3 } },
{ /* 31 */ 1, { -3, 3 } },
{ /* 32 */ 1, { -2, 4 } },
{ /* 33 */ 1, { -4, -2 } },
{ /* 34 */ 1, { 4, 2 } },
{ /* 35 */ 1, { 2, -4 } },
{ /* 36 */ 1, { 2, 4 } },
{ /* 37 */ 1, { 3, 3 } },
{ /* 38 */ 1, { -4, 2 } },
{ /* 39 */ 0, { 6, 7 } },
{ /* 40 */ 0, { 7, 8 } },
{ /* 41 */ 0, { 8, 9 } },
{ /* 42 */ 0, { 9, 10 } },
{ /* 43 */ 0, { 10, 11 } },
{ /* 44 */ 0, { 11, 12 } },
{ /* 45 */ 1, { -2, -4 } },
{ /* 46 */ 1, { 4, -2 } },
{ /* 47 */ 1, { 3, -4 } },
{ /* 48 */ 1, { -4, -3 } },
{ /* 49 */ 1, { -4, 3 } },
{ /* 50 */ 1, { 3, 4 } },
{ /* 51 */ 1, { -3, 4 } },
{ /* 52 */ 1, { 4, 3 } },
{ /* 53 */ 1, { 4, -3 } },
{ /* 54 */ 1, { -3, -4 } },
{ /* 55 */ 0, { 2, 3 } },
{ /* 56 */ 0, { 3, 4 } },
{ /* 57 */ 1, { 4, -4 } },
{ /* 58 */ 1, { -4, 4 } },
{ /* 59 */ 1, { 4, 4 } },
{ /* 60 */ 1, { -4, -4 } }
};

View File

@ -0,0 +1,182 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: hcb_6.h,v 1.5 2007/11/01 12:34:11 menno Exp $
**/
/* 2-step huffman table HCB_6 */
/* 1st step: 5 bits
* 2^5 = 32 entries
*
* Used to find offset into 2nd step table and number of extra bits to get
*/
static hcb hcb6_1[] = {
/* 4 bit codewords */
{ /* 00000 */ 0, 0 },
{ /* */ 0, 0 },
{ /* 00010 */ 1, 0 },
{ /* */ 1, 0 },
{ /* 00100 */ 2, 0 },
{ /* */ 2, 0 },
{ /* 00110 */ 3, 0 },
{ /* */ 3, 0 },
{ /* 01000 */ 4, 0 },
{ /* */ 4, 0 },
{ /* 01010 */ 5, 0 },
{ /* */ 5, 0 },
{ /* 01100 */ 6, 0 },
{ /* */ 6, 0 },
{ /* 01110 */ 7, 0 },
{ /* */ 7, 0 },
{ /* 10000 */ 8, 0 },
{ /* */ 8, 0 },
/* 6 bit codewords */
{ /* 10010 */ 9, 1 },
{ /* 10011 */ 11, 1 },
{ /* 10100 */ 13, 1 },
{ /* 10101 */ 15, 1 },
{ /* 10110 */ 17, 1 },
{ /* 10111 */ 19, 1 },
{ /* 11000 */ 21, 1 },
{ /* 11001 */ 23, 1 },
/* 7 bit codewords */
{ /* 11010 */ 25, 2 },
{ /* 11011 */ 29, 2 },
{ /* 11100 */ 33, 2 },
/* 7/8 bit codewords */
{ /* 11101 */ 37, 3 },
/* 8/9 bit codewords */
{ /* 11110 */ 45, 4 },
/* 9/10/11 bit codewords */
{ /* 11111 */ 61, 6 }
};
/* 2nd step table
*
* Gives size of codeword and actual data (x,y,v,w)
*/
static hcb_2_pair hcb6_2[] = {
/* 4 bit codewords */
{ 4, 0, 0 },
{ 4, 1, 0 },
{ 4, 0, -1 },
{ 4, 0, 1 },
{ 4, -1, 0 },
{ 4, 1, 1 },
{ 4, -1, 1 },
{ 4, 1, -1 },
{ 4, -1, -1 },
/* 6 bit codewords */
{ 6, 2, -1 },
{ 6, 2, 1 },
{ 6, -2, 1 },
{ 6, -2, -1 },
{ 6, -2, 0 },
{ 6, -1, 2 },
{ 6, 2, 0 },
{ 6, 1, -2 },
{ 6, 1, 2 },
{ 6, 0, -2 },
{ 6, -1, -2 },
{ 6, 0, 2 },
{ 6, 2, -2 },
{ 6, -2, 2 },
{ 6, -2, -2 },
{ 6, 2, 2 },
/* 7 bit codewords */
{ 7, -3, 1 },
{ 7, 3, 1 },
{ 7, 3, -1 },
{ 7, -1, 3 },
{ 7, -3, -1 },
{ 7, 1, 3 },
{ 7, 1, -3 },
{ 7, -1, -3 },
{ 7, 3, 0 },
{ 7, -3, 0 },
{ 7, 0, -3 },
{ 7, 0, 3 },
/* 7/8 bit codewords */
{ 7, 3, 2 }, { 7, 3, 2 },
{ 8, -3, -2 },
{ 8, -2, 3 },
{ 8, 2, 3 },
{ 8, 3, -2 },
{ 8, 2, -3 },
{ 8, -2, -3 },
/* 8 bit codewords */
{ 8, -3, 2 }, { 8, -3, 2 },
{ 8, 3, 3 }, { 8, 3, 3 },
{ 9, 3, -3 },
{ 9, -3, -3 },
{ 9, -3, 3 },
{ 9, 1, -4 },
{ 9, -1, -4 },
{ 9, 4, 1 },
{ 9, -4, 1 },
{ 9, -4, -1 },
{ 9, 1, 4 },
{ 9, 4, -1 },
{ 9, -1, 4 },
{ 9, 0, -4 },
/* 9/10/11 bit codewords */
{ 9, -4, 2 }, { 9, -4, 2 }, { 9, -4, 2 }, { 9, -4, 2 },
{ 9, -4, -2 }, { 9, -4, -2 }, { 9, -4, -2 }, { 9, -4, -2 },
{ 9, 2, 4 }, { 9, 2, 4 }, { 9, 2, 4 }, { 9, 2, 4 },
{ 9, -2, -4 }, { 9, -2, -4 }, { 9, -2, -4 }, { 9, -2, -4 },
{ 9, -4, 0 }, { 9, -4, 0 }, { 9, -4, 0 }, { 9, -4, 0 },
{ 9, 4, 2 }, { 9, 4, 2 }, { 9, 4, 2 }, { 9, 4, 2 },
{ 9, 4, -2 }, { 9, 4, -2 }, { 9, 4, -2 }, { 9, 4, -2 },
{ 9, -2, 4 }, { 9, -2, 4 }, { 9, -2, 4 }, { 9, -2, 4 },
{ 9, 4, 0 }, { 9, 4, 0 }, { 9, 4, 0 }, { 9, 4, 0 },
{ 9, 2, -4 }, { 9, 2, -4 }, { 9, 2, -4 }, { 9, 2, -4 },
{ 9, 0, 4 }, { 9, 0, 4 }, { 9, 0, 4 }, { 9, 0, 4 },
{ 10, -3, -4 }, { 10, -3, -4 },
{ 10, -3, 4 }, { 10, -3, 4 },
{ 10, 3, -4 }, { 10, 3, -4 },
{ 10, 4, -3 }, { 10, 4, -3 },
{ 10, 3, 4 }, { 10, 3, 4 },
{ 10, 4, 3 }, { 10, 4, 3 },
{ 10, -4, 3 }, { 10, -4, 3 },
{ 10, -4, -3 }, { 10, -4, -3 },
{ 11, 4, 4 },
{ 11, -4, 4 },
{ 11, -4, -4 },
{ 11, 4, -4 }
};

View File

@ -0,0 +1,162 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: hcb_7.h,v 1.5 2007/11/01 12:34:11 menno Exp $
**/
/* Binary search huffman table HCB_7 */
static hcb_bin_pair hcb7[] = {
{ /* 0 */ 0, { 1, 2 } },
{ /* 1 */ 1, { 0, 0 } },
{ /* 2 */ 0, { 1, 2 } },
{ /* 3 */ 0, { 2, 3 } },
{ /* 4 */ 0, { 3, 4 } },
{ /* 5 */ 1, { 1, 0 } },
{ /* 6 */ 1, { 0, 1 } },
{ /* 7 */ 0, { 2, 3 } },
{ /* 8 */ 0, { 3, 4 } },
{ /* 9 */ 1, { 1, 1 } },
{ /* 10 */ 0, { 3, 4 } },
{ /* 11 */ 0, { 4, 5 } },
{ /* 12 */ 0, { 5, 6 } },
{ /* 13 */ 0, { 6, 7 } },
{ /* 14 */ 0, { 7, 8 } },
{ /* 15 */ 0, { 8, 9 } },
{ /* 16 */ 0, { 9, 10 } },
{ /* 17 */ 0, { 10, 11 } },
{ /* 18 */ 0, { 11, 12 } },
{ /* 19 */ 1, { 2, 1 } },
{ /* 20 */ 1, { 1, 2 } },
{ /* 21 */ 1, { 2, 0 } },
{ /* 22 */ 1, { 0, 2 } },
{ /* 23 */ 0, { 8, 9 } },
{ /* 24 */ 0, { 9, 10 } },
{ /* 25 */ 0, { 10, 11 } },
{ /* 26 */ 0, { 11, 12 } },
{ /* 27 */ 0, { 12, 13 } },
{ /* 28 */ 0, { 13, 14 } },
{ /* 29 */ 0, { 14, 15 } },
{ /* 30 */ 0, { 15, 16 } },
{ /* 31 */ 1, { 3, 1 } },
{ /* 32 */ 1, { 1, 3 } },
{ /* 33 */ 1, { 2, 2 } },
{ /* 34 */ 1, { 3, 0 } },
{ /* 35 */ 1, { 0, 3 } },
{ /* 36 */ 0, { 11, 12 } },
{ /* 37 */ 0, { 12, 13 } },
{ /* 38 */ 0, { 13, 14 } },
{ /* 39 */ 0, { 14, 15 } },
{ /* 40 */ 0, { 15, 16 } },
{ /* 41 */ 0, { 16, 17 } },
{ /* 42 */ 0, { 17, 18 } },
{ /* 43 */ 0, { 18, 19 } },
{ /* 44 */ 0, { 19, 20 } },
{ /* 45 */ 0, { 20, 21 } },
{ /* 46 */ 0, { 21, 22 } },
{ /* 47 */ 1, { 2, 3 } },
{ /* 48 */ 1, { 3, 2 } },
{ /* 49 */ 1, { 1, 4 } },
{ /* 50 */ 1, { 4, 1 } },
{ /* 51 */ 1, { 1, 5 } },
{ /* 52 */ 1, { 5, 1 } },
{ /* 53 */ 1, { 3, 3 } },
{ /* 54 */ 1, { 2, 4 } },
{ /* 55 */ 1, { 0, 4 } },
{ /* 56 */ 1, { 4, 0 } },
{ /* 57 */ 0, { 12, 13 } },
{ /* 58 */ 0, { 13, 14 } },
{ /* 59 */ 0, { 14, 15 } },
{ /* 60 */ 0, { 15, 16 } },
{ /* 61 */ 0, { 16, 17 } },
{ /* 62 */ 0, { 17, 18 } },
{ /* 63 */ 0, { 18, 19 } },
{ /* 64 */ 0, { 19, 20 } },
{ /* 65 */ 0, { 20, 21 } },
{ /* 66 */ 0, { 21, 22 } },
{ /* 67 */ 0, { 22, 23 } },
{ /* 68 */ 0, { 23, 24 } },
{ /* 69 */ 1, { 4, 2 } },
{ /* 70 */ 1, { 2, 5 } },
{ /* 71 */ 1, { 5, 2 } },
{ /* 72 */ 1, { 0, 5 } },
{ /* 73 */ 1, { 6, 1 } },
{ /* 74 */ 1, { 5, 0 } },
{ /* 75 */ 1, { 1, 6 } },
{ /* 76 */ 1, { 4, 3 } },
{ /* 77 */ 1, { 3, 5 } },
{ /* 78 */ 1, { 3, 4 } },
{ /* 79 */ 1, { 5, 3 } },
{ /* 80 */ 1, { 2, 6 } },
{ /* 81 */ 1, { 6, 2 } },
{ /* 82 */ 1, { 1, 7 } },
{ /* 83 */ 0, { 10, 11 } },
{ /* 84 */ 0, { 11, 12 } },
{ /* 85 */ 0, { 12, 13 } },
{ /* 86 */ 0, { 13, 14 } },
{ /* 87 */ 0, { 14, 15 } },
{ /* 88 */ 0, { 15, 16 } },
{ /* 89 */ 0, { 16, 17 } },
{ /* 90 */ 0, { 17, 18 } },
{ /* 91 */ 0, { 18, 19 } },
{ /* 92 */ 0, { 19, 20 } },
{ /* 93 */ 1, { 3, 6 } },
{ /* 94 */ 1, { 0, 6 } },
{ /* 95 */ 1, { 6, 0 } },
{ /* 96 */ 1, { 4, 4 } },
{ /* 97 */ 1, { 7, 1 } },
{ /* 98 */ 1, { 4, 5 } },
{ /* 99 */ 1, { 7, 2 } },
{ /* 00 */ 1, { 5, 4 } },
{ /* 01 */ 1, { 6, 3 } },
{ /* 02 */ 1, { 2, 7 } },
{ /* 03 */ 1, { 7, 3 } },
{ /* 04 */ 1, { 6, 4 } },
{ /* 05 */ 1, { 5, 5 } },
{ /* 06 */ 1, { 4, 6 } },
{ /* 07 */ 1, { 3, 7 } },
{ /* 08 */ 0, { 5, 6 } },
{ /* 09 */ 0, { 6, 7 } },
{ /* 10 */ 0, { 7, 8 } },
{ /* 11 */ 0, { 8, 9 } },
{ /* 12 */ 0, { 9, 10 } },
{ /* 13 */ 1, { 7, 0 } },
{ /* 14 */ 1, { 0, 7 } },
{ /* 15 */ 1, { 6, 5 } },
{ /* 16 */ 1, { 5, 6 } },
{ /* 17 */ 1, { 7, 4 } },
{ /* 18 */ 1, { 4, 7 } },
{ /* 19 */ 1, { 5, 7 } },
{ /* 20 */ 1, { 7, 5 } },
{ /* 21 */ 0, { 2, 3 } },
{ /* 22 */ 0, { 3, 4 } },
{ /* 23 */ 1, { 7, 6 } },
{ /* 24 */ 1, { 6, 6 } },
{ /* 25 */ 1, { 6, 7 } },
{ /* 26 */ 1, { 7, 7 } }
};

View File

@ -0,0 +1,173 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: hcb_8.h,v 1.5 2007/11/01 12:34:11 menno Exp $
**/
/* 2-step huffman table HCB_8 */
/* 1st step: 5 bits
* 2^5 = 32 entries
*
* Used to find offset into 2nd step table and number of extra bits to get
*/
static hcb hcb8_1[] = {
/* 3 bit codeword */
{ /* 00000 */ 0, 0 },
{ /* */ 0, 0 },
{ /* */ 0, 0 },
{ /* */ 0, 0 },
/* 4 bit codewords */
{ /* 00100 */ 1, 0 },
{ /* */ 1, 0 },
{ /* 00110 */ 2, 0 },
{ /* */ 2, 0 },
{ /* 01000 */ 3, 0 },
{ /* */ 3, 0 },
{ /* 01010 */ 4, 0 },
{ /* */ 4, 0 },
{ /* 01100 */ 5, 0 },
{ /* */ 5, 0 },
/* 5 bit codewords */
{ /* 01110 */ 6, 0 },
{ /* 01111 */ 7, 0 },
{ /* 10000 */ 8, 0 },
{ /* 10001 */ 9, 0 },
{ /* 10010 */ 10, 0 },
{ /* 10011 */ 11, 0 },
{ /* 10100 */ 12, 0 },
/* 6 bit codewords */
{ /* 10101 */ 13, 1 },
{ /* 10110 */ 15, 1 },
{ /* 10111 */ 17, 1 },
{ /* 11000 */ 19, 1 },
{ /* 11001 */ 21, 1 },
/* 7 bit codewords */
{ /* 11010 */ 23, 2 },
{ /* 11011 */ 27, 2 },
{ /* 11100 */ 31, 2 },
/* 7/8 bit codewords */
{ /* 11101 */ 35, 3 },
/* 8 bit codewords */
{ /* 11110 */ 43, 3 },
/* 8/9/10 bit codewords */
{ /* 11111 */ 51, 5 }
};
/* 2nd step table
*
* Gives size of codeword and actual data (x,y,v,w)
*/
static hcb_2_pair hcb8_2[] = {
/* 3 bit codeword */
{ 3, 1, 1 },
/* 4 bit codewords */
{ 4, 2, 1 },
{ 4, 1, 0 },
{ 4, 1, 2 },
{ 4, 0, 1 },
{ 4, 2, 2 },
/* 5 bit codewords */
{ 5, 0, 0 },
{ 5, 2, 0 },
{ 5, 0, 2 },
{ 5, 3, 1 },
{ 5, 1, 3 },
{ 5, 3, 2 },
{ 5, 2, 3 },
/* 6 bit codewords */
{ 6, 3, 3 },
{ 6, 4, 1 },
{ 6, 1, 4 },
{ 6, 4, 2 },
{ 6, 2, 4 },
{ 6, 3, 0 },
{ 6, 0, 3 },
{ 6, 4, 3 },
{ 6, 3, 4 },
{ 6, 5, 2 },
/* 7 bit codewords */
{ 7, 5, 1 },
{ 7, 2, 5 },
{ 7, 1, 5 },
{ 7, 5, 3 },
{ 7, 3, 5 },
{ 7, 4, 4 },
{ 7, 5, 4 },
{ 7, 0, 4 },
{ 7, 4, 5 },
{ 7, 4, 0 },
{ 7, 2, 6 },
{ 7, 6, 2 },
/* 7/8 bit codewords */
{ 7, 6, 1 }, { 7, 6, 1 },
{ 7, 1, 6 }, { 7, 1, 6 },
{ 8, 3, 6 },
{ 8, 6, 3 },
{ 8, 5, 5 },
{ 8, 5, 0 },
/* 8 bit codewords */
{ 8, 6, 4 },
{ 8, 0, 5 },
{ 8, 4, 6 },
{ 8, 7, 1 },
{ 8, 7, 2 },
{ 8, 2, 7 },
{ 8, 6, 5 },
{ 8, 7, 3 },
/* 8/9/10 bit codewords */
{ 8, 1, 7 }, { 8, 1, 7 }, { 8, 1, 7 }, { 8, 1, 7 },
{ 8, 5, 6 }, { 8, 5, 6 }, { 8, 5, 6 }, { 8, 5, 6 },
{ 8, 3, 7 }, { 8, 3, 7 }, { 8, 3, 7 }, { 8, 3, 7 },
{ 9, 6, 6 }, { 9, 6, 6 },
{ 9, 7, 4 }, { 9, 7, 4 },
{ 9, 6, 0 }, { 9, 6, 0 },
{ 9, 4, 7 }, { 9, 4, 7 },
{ 9, 0, 6 }, { 9, 0, 6 },
{ 9, 7, 5 }, { 9, 7, 5 },
{ 9, 7, 6 }, { 9, 7, 6 },
{ 9, 6, 7 }, { 9, 6, 7 },
{ 10, 5, 7 },
{ 10, 7, 0 },
{ 10, 0, 7 },
{ 10, 7, 7 }
};

View File

@ -0,0 +1,372 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: hcb_9.h,v 1.5 2007/11/01 12:34:11 menno Exp $
**/
/* Binary search huffman table HCB_9 */
static hcb_bin_pair hcb9[] = {
{ /* 0 */ 0, { 1, 2 } },
{ /* 1 */ 1, { 0, 0 } },
{ /* 2 */ 0, { 1, 2 } },
{ /* 3 */ 0, { 2, 3 } },
{ /* 4 */ 0, { 3, 4 } },
{ /* 5 */ 1, { 1, 0 } },
{ /* 6 */ 1, { 0, 1 } },
{ /* 7 */ 0, { 2, 3 } },
{ /* 8 */ 0, { 3, 4 } },
{ /* 9 */ 1, { 1, 1 } },
{ /* 10 */ 0, { 3, 4 } },
{ /* 11 */ 0, { 4, 5 } },
{ /* 12 */ 0, { 5, 6 } },
{ /* 13 */ 0, { 6, 7 } },
{ /* 14 */ 0, { 7, 8 } },
{ /* 15 */ 0, { 8, 9 } },
{ /* 16 */ 0, { 9, 10 } },
{ /* 17 */ 0, { 10, 11 } },
{ /* 18 */ 0, { 11, 12 } },
{ /* 19 */ 1, { 2, 1 } },
{ /* 20 */ 1, { 1, 2 } },
{ /* 21 */ 1, { 2, 0 } },
{ /* 22 */ 1, { 0, 2 } },
{ /* 23 */ 0, { 8, 9 } },
{ /* 24 */ 0, { 9, 10 } },
{ /* 25 */ 0, { 10, 11 } },
{ /* 26 */ 0, { 11, 12 } },
{ /* 27 */ 0, { 12, 13 } },
{ /* 28 */ 0, { 13, 14 } },
{ /* 29 */ 0, { 14, 15 } },
{ /* 30 */ 0, { 15, 16 } },
{ /* 31 */ 1, { 3, 1 } },
{ /* 32 */ 1, { 2, 2 } },
{ /* 33 */ 1, { 1, 3 } },
{ /* 34 */ 0, { 13, 14 } },
{ /* 35 */ 0, { 14, 15 } },
{ /* 36 */ 0, { 15, 16 } },
{ /* 37 */ 0, { 16, 17 } },
{ /* 38 */ 0, { 17, 18 } },
{ /* 39 */ 0, { 18, 19 } },
{ /* 40 */ 0, { 19, 20 } },
{ /* 41 */ 0, { 20, 21 } },
{ /* 42 */ 0, { 21, 22 } },
{ /* 43 */ 0, { 22, 23 } },
{ /* 44 */ 0, { 23, 24 } },
{ /* 45 */ 0, { 24, 25 } },
{ /* 46 */ 0, { 25, 26 } },
{ /* 47 */ 1, { 3, 0 } },
{ /* 48 */ 1, { 0, 3 } },
{ /* 49 */ 1, { 2, 3 } },
{ /* 50 */ 1, { 3, 2 } },
{ /* 51 */ 1, { 1, 4 } },
{ /* 52 */ 1, { 4, 1 } },
{ /* 53 */ 1, { 2, 4 } },
{ /* 54 */ 1, { 1, 5 } },
{ /* 55 */ 0, { 18, 19 } },
{ /* 56 */ 0, { 19, 20 } },
{ /* 57 */ 0, { 20, 21 } },
{ /* 58 */ 0, { 21, 22 } },
{ /* 59 */ 0, { 22, 23 } },
{ /* 60 */ 0, { 23, 24 } },
{ /* 61 */ 0, { 24, 25 } },
{ /* 62 */ 0, { 25, 26 } },
{ /* 63 */ 0, { 26, 27 } },
{ /* 64 */ 0, { 27, 28 } },
{ /* 65 */ 0, { 28, 29 } },
{ /* 66 */ 0, { 29, 30 } },
{ /* 67 */ 0, { 30, 31 } },
{ /* 68 */ 0, { 31, 32 } },
{ /* 69 */ 0, { 32, 33 } },
{ /* 70 */ 0, { 33, 34 } },
{ /* 71 */ 0, { 34, 35 } },
{ /* 72 */ 0, { 35, 36 } },
{ /* 73 */ 1, { 4, 2 } },
{ /* 74 */ 1, { 3, 3 } },
{ /* 75 */ 1, { 0, 4 } },
{ /* 76 */ 1, { 4, 0 } },
{ /* 77 */ 1, { 5, 1 } },
{ /* 78 */ 1, { 2, 5 } },
{ /* 79 */ 1, { 1, 6 } },
{ /* 80 */ 1, { 3, 4 } },
{ /* 81 */ 1, { 5, 2 } },
{ /* 82 */ 1, { 6, 1 } },
{ /* 83 */ 1, { 4, 3 } },
{ /* 84 */ 0, { 25, 26 } },
{ /* 85 */ 0, { 26, 27 } },
{ /* 86 */ 0, { 27, 28 } },
{ /* 87 */ 0, { 28, 29 } },
{ /* 88 */ 0, { 29, 30 } },
{ /* 89 */ 0, { 30, 31 } },
{ /* 90 */ 0, { 31, 32 } },
{ /* 91 */ 0, { 32, 33 } },
{ /* 92 */ 0, { 33, 34 } },
{ /* 93 */ 0, { 34, 35 } },
{ /* 94 */ 0, { 35, 36 } },
{ /* 95 */ 0, { 36, 37 } },
{ /* 96 */ 0, { 37, 38 } },
{ /* 97 */ 0, { 38, 39 } },
{ /* 98 */ 0, { 39, 40 } },
{ /* 99 */ 0, { 40, 41 } },
{ /* 00 */ 0, { 41, 42 } },
{ /* 01 */ 0, { 42, 43 } },
{ /* 02 */ 0, { 43, 44 } },
{ /* 03 */ 0, { 44, 45 } },
{ /* 04 */ 0, { 45, 46 } },
{ /* 05 */ 0, { 46, 47 } },
{ /* 06 */ 0, { 47, 48 } },
{ /* 07 */ 0, { 48, 49 } },
{ /* 08 */ 0, { 49, 50 } },
{ /* 09 */ 1, { 0, 5 } },
{ /* 10 */ 1, { 2, 6 } },
{ /* 11 */ 1, { 5, 0 } },
{ /* 12 */ 1, { 1, 7 } },
{ /* 13 */ 1, { 3, 5 } },
{ /* 14 */ 1, { 1, 8 } },
{ /* 15 */ 1, { 8, 1 } },
{ /* 16 */ 1, { 4, 4 } },
{ /* 17 */ 1, { 5, 3 } },
{ /* 18 */ 1, { 6, 2 } },
{ /* 19 */ 1, { 7, 1 } },
{ /* 20 */ 1, { 0, 6 } },
{ /* 21 */ 1, { 8, 2 } },
{ /* 22 */ 1, { 2, 8 } },
{ /* 23 */ 1, { 3, 6 } },
{ /* 24 */ 1, { 2, 7 } },
{ /* 25 */ 1, { 4, 5 } },
{ /* 26 */ 1, { 9, 1 } },
{ /* 27 */ 1, { 1, 9 } },
{ /* 28 */ 1, { 7, 2 } },
{ /* 29 */ 0, { 30, 31 } },
{ /* 30 */ 0, { 31, 32 } },
{ /* 31 */ 0, { 32, 33 } },
{ /* 32 */ 0, { 33, 34 } },
{ /* 33 */ 0, { 34, 35 } },
{ /* 34 */ 0, { 35, 36 } },
{ /* 35 */ 0, { 36, 37 } },
{ /* 36 */ 0, { 37, 38 } },
{ /* 37 */ 0, { 38, 39 } },
{ /* 38 */ 0, { 39, 40 } },
{ /* 39 */ 0, { 40, 41 } },
{ /* 40 */ 0, { 41, 42 } },
{ /* 41 */ 0, { 42, 43 } },
{ /* 42 */ 0, { 43, 44 } },
{ /* 43 */ 0, { 44, 45 } },
{ /* 44 */ 0, { 45, 46 } },
{ /* 45 */ 0, { 46, 47 } },
{ /* 46 */ 0, { 47, 48 } },
{ /* 47 */ 0, { 48, 49 } },
{ /* 48 */ 0, { 49, 50 } },
{ /* 49 */ 0, { 50, 51 } },
{ /* 50 */ 0, { 51, 52 } },
{ /* 51 */ 0, { 52, 53 } },
{ /* 52 */ 0, { 53, 54 } },
{ /* 53 */ 0, { 54, 55 } },
{ /* 54 */ 0, { 55, 56 } },
{ /* 55 */ 0, { 56, 57 } },
{ /* 56 */ 0, { 57, 58 } },
{ /* 57 */ 0, { 58, 59 } },
{ /* 58 */ 0, { 59, 60 } },
{ /* 59 */ 1, { 6, 0 } },
{ /* 60 */ 1, { 5, 4 } },
{ /* 61 */ 1, { 6, 3 } },
{ /* 62 */ 1, { 8, 3 } },
{ /* 63 */ 1, { 0, 7 } },
{ /* 64 */ 1, { 9, 2 } },
{ /* 65 */ 1, { 3, 8 } },
{ /* 66 */ 1, { 4, 6 } },
{ /* 67 */ 1, { 3, 7 } },
{ /* 68 */ 1, { 0, 8 } },
{ /* 69 */ 1, { 10, 1 } },
{ /* 70 */ 1, { 6, 4 } },
{ /* 71 */ 1, { 2, 9 } },
{ /* 72 */ 1, { 5, 5 } },
{ /* 73 */ 1, { 8, 0 } },
{ /* 74 */ 1, { 7, 0 } },
{ /* 75 */ 1, { 7, 3 } },
{ /* 76 */ 1, { 10, 2 } },
{ /* 77 */ 1, { 9, 3 } },
{ /* 78 */ 1, { 8, 4 } },
{ /* 79 */ 1, { 1, 10 } },
{ /* 80 */ 1, { 7, 4 } },
{ /* 81 */ 1, { 6, 5 } },
{ /* 82 */ 1, { 5, 6 } },
{ /* 83 */ 1, { 4, 8 } },
{ /* 84 */ 1, { 4, 7 } },
{ /* 85 */ 1, { 3, 9 } },
{ /* 86 */ 1, { 11, 1 } },
{ /* 87 */ 1, { 5, 8 } },
{ /* 88 */ 1, { 9, 0 } },
{ /* 89 */ 1, { 8, 5 } },
{ /* 90 */ 0, { 29, 30 } },
{ /* 91 */ 0, { 30, 31 } },
{ /* 92 */ 0, { 31, 32 } },
{ /* 93 */ 0, { 32, 33 } },
{ /* 94 */ 0, { 33, 34 } },
{ /* 95 */ 0, { 34, 35 } },
{ /* 96 */ 0, { 35, 36 } },
{ /* 97 */ 0, { 36, 37 } },
{ /* 98 */ 0, { 37, 38 } },
{ /* 99 */ 0, { 38, 39 } },
{ /* 00 */ 0, { 39, 40 } },
{ /* 01 */ 0, { 40, 41 } },
{ /* 02 */ 0, { 41, 42 } },
{ /* 03 */ 0, { 42, 43 } },
{ /* 04 */ 0, { 43, 44 } },
{ /* 05 */ 0, { 44, 45 } },
{ /* 06 */ 0, { 45, 46 } },
{ /* 07 */ 0, { 46, 47 } },
{ /* 08 */ 0, { 47, 48 } },
{ /* 09 */ 0, { 48, 49 } },
{ /* 10 */ 0, { 49, 50 } },
{ /* 11 */ 0, { 50, 51 } },
{ /* 12 */ 0, { 51, 52 } },
{ /* 13 */ 0, { 52, 53 } },
{ /* 14 */ 0, { 53, 54 } },
{ /* 15 */ 0, { 54, 55 } },
{ /* 16 */ 0, { 55, 56 } },
{ /* 17 */ 0, { 56, 57 } },
{ /* 18 */ 0, { 57, 58 } },
{ /* 19 */ 1, { 10, 3 } },
{ /* 20 */ 1, { 2, 10 } },
{ /* 21 */ 1, { 0, 9 } },
{ /* 22 */ 1, { 11, 2 } },
{ /* 23 */ 1, { 9, 4 } },
{ /* 24 */ 1, { 6, 6 } },
{ /* 25 */ 1, { 12, 1 } },
{ /* 26 */ 1, { 4, 9 } },
{ /* 27 */ 1, { 8, 6 } },
{ /* 28 */ 1, { 1, 11 } },
{ /* 29 */ 1, { 9, 5 } },
{ /* 30 */ 1, { 10, 4 } },
{ /* 31 */ 1, { 5, 7 } },
{ /* 32 */ 1, { 7, 5 } },
{ /* 33 */ 1, { 2, 11 } },
{ /* 34 */ 1, { 1, 12 } },
{ /* 35 */ 1, { 12, 2 } },
{ /* 36 */ 1, { 11, 3 } },
{ /* 37 */ 1, { 3, 10 } },
{ /* 38 */ 1, { 5, 9 } },
{ /* 39 */ 1, { 6, 7 } },
{ /* 40 */ 1, { 8, 7 } },
{ /* 41 */ 1, { 11, 4 } },
{ /* 42 */ 1, { 0, 10 } },
{ /* 43 */ 1, { 7, 6 } },
{ /* 44 */ 1, { 12, 3 } },
{ /* 45 */ 1, { 10, 0 } },
{ /* 46 */ 1, { 10, 5 } },
{ /* 47 */ 1, { 4, 10 } },
{ /* 48 */ 1, { 6, 8 } },
{ /* 49 */ 1, { 2, 12 } },
{ /* 50 */ 1, { 9, 6 } },
{ /* 51 */ 1, { 9, 7 } },
{ /* 52 */ 1, { 4, 11 } },
{ /* 53 */ 1, { 11, 0 } },
{ /* 54 */ 1, { 6, 9 } },
{ /* 55 */ 1, { 3, 11 } },
{ /* 56 */ 1, { 5, 10 } },
{ /* 57 */ 0, { 20, 21 } },
{ /* 58 */ 0, { 21, 22 } },
{ /* 59 */ 0, { 22, 23 } },
{ /* 60 */ 0, { 23, 24 } },
{ /* 61 */ 0, { 24, 25 } },
{ /* 62 */ 0, { 25, 26 } },
{ /* 63 */ 0, { 26, 27 } },
{ /* 64 */ 0, { 27, 28 } },
{ /* 65 */ 0, { 28, 29 } },
{ /* 66 */ 0, { 29, 30 } },
{ /* 67 */ 0, { 30, 31 } },
{ /* 68 */ 0, { 31, 32 } },
{ /* 69 */ 0, { 32, 33 } },
{ /* 70 */ 0, { 33, 34 } },
{ /* 71 */ 0, { 34, 35 } },
{ /* 72 */ 0, { 35, 36 } },
{ /* 73 */ 0, { 36, 37 } },
{ /* 74 */ 0, { 37, 38 } },
{ /* 75 */ 0, { 38, 39 } },
{ /* 76 */ 0, { 39, 40 } },
{ /* 77 */ 1, { 8, 8 } },
{ /* 78 */ 1, { 7, 8 } },
{ /* 79 */ 1, { 12, 5 } },
{ /* 80 */ 1, { 3, 12 } },
{ /* 81 */ 1, { 11, 5 } },
{ /* 82 */ 1, { 7, 7 } },
{ /* 83 */ 1, { 12, 4 } },
{ /* 84 */ 1, { 11, 6 } },
{ /* 85 */ 1, { 10, 6 } },
{ /* 86 */ 1, { 4, 12 } },
{ /* 87 */ 1, { 7, 9 } },
{ /* 88 */ 1, { 5, 11 } },
{ /* 89 */ 1, { 0, 11 } },
{ /* 90 */ 1, { 12, 6 } },
{ /* 91 */ 1, { 6, 10 } },
{ /* 92 */ 1, { 12, 0 } },
{ /* 93 */ 1, { 10, 7 } },
{ /* 94 */ 1, { 5, 12 } },
{ /* 95 */ 1, { 7, 10 } },
{ /* 96 */ 1, { 9, 8 } },
{ /* 97 */ 1, { 0, 12 } },
{ /* 98 */ 1, { 11, 7 } },
{ /* 99 */ 1, { 8, 9 } },
{ /* 00 */ 1, { 9, 9 } },
{ /* 01 */ 1, { 10, 8 } },
{ /* 02 */ 1, { 7, 11 } },
{ /* 03 */ 1, { 12, 7 } },
{ /* 04 */ 1, { 6, 11 } },
{ /* 05 */ 1, { 8, 11 } },
{ /* 06 */ 1, { 11, 8 } },
{ /* 07 */ 1, { 7, 12 } },
{ /* 08 */ 1, { 6, 12 } },
{ /* 09 */ 0, { 8, 9 } },
{ /* 10 */ 0, { 9, 10 } },
{ /* 11 */ 0, { 10, 11 } },
{ /* 12 */ 0, { 11, 12 } },
{ /* 13 */ 0, { 12, 13 } },
{ /* 14 */ 0, { 13, 14 } },
{ /* 15 */ 0, { 14, 15 } },
{ /* 16 */ 0, { 15, 16 } },
{ /* 17 */ 1, { 8, 10 } },
{ /* 18 */ 1, { 10, 9 } },
{ /* 19 */ 1, { 8, 12 } },
{ /* 20 */ 1, { 9, 10 } },
{ /* 21 */ 1, { 9, 11 } },
{ /* 22 */ 1, { 9, 12 } },
{ /* 23 */ 1, { 10, 11 } },
{ /* 24 */ 1, { 12, 9 } },
{ /* 25 */ 1, { 10, 10 } },
{ /* 26 */ 1, { 11, 9 } },
{ /* 27 */ 1, { 12, 8 } },
{ /* 28 */ 1, { 11, 10 } },
{ /* 29 */ 1, { 12, 10 } },
{ /* 30 */ 1, { 12, 11 } },
{ /* 31 */ 0, { 2, 3 } },
{ /* 32 */ 0, { 3, 4 } },
{ /* 33 */ 1, { 10, 12 } },
{ /* 34 */ 1, { 11, 11 } },
{ /* 35 */ 1, { 11, 12 } },
{ /* 36 */ 1, { 12, 12 } }
};

View File

@ -0,0 +1,276 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: hcb_sf.h,v 1.7 2007/11/01 12:34:11 menno Exp $
**/
/* Binary search huffman table HCB_SF */
static uint8_t hcb_sf[][2] = {
{ /* 0 */ 1, 2 },
{ /* 1 */ 60, 0 },
{ /* 2 */ 1, 2 },
{ /* 3 */ 2, 3 },
{ /* 4 */ 3, 4 },
{ /* 5 */ 59, 0 },
{ /* 6 */ 3, 4 },
{ /* 7 */ 4, 5 },
{ /* 8 */ 5, 6 },
{ /* 9 */ 61, 0 },
{ /* 10 */ 58, 0 },
{ /* 11 */ 62, 0 },
{ /* 12 */ 3, 4 },
{ /* 13 */ 4, 5 },
{ /* 14 */ 5, 6 },
{ /* 15 */ 57, 0 },
{ /* 16 */ 63, 0 },
{ /* 17 */ 4, 5 },
{ /* 18 */ 5, 6 },
{ /* 19 */ 6, 7 },
{ /* 20 */ 7, 8 },
{ /* 21 */ 56, 0 },
{ /* 22 */ 64, 0 },
{ /* 23 */ 55, 0 },
{ /* 24 */ 65, 0 },
{ /* 25 */ 4, 5 },
{ /* 26 */ 5, 6 },
{ /* 27 */ 6, 7 },
{ /* 28 */ 7, 8 },
{ /* 29 */ 66, 0 },
{ /* 30 */ 54, 0 },
{ /* 31 */ 67, 0 },
{ /* 32 */ 5, 6 },
{ /* 33 */ 6, 7 },
{ /* 34 */ 7, 8 },
{ /* 35 */ 8, 9 },
{ /* 36 */ 9, 10 },
{ /* 37 */ 53, 0 },
{ /* 38 */ 68, 0 },
{ /* 39 */ 52, 0 },
{ /* 40 */ 69, 0 },
{ /* 41 */ 51, 0 },
{ /* 42 */ 5, 6 },
{ /* 43 */ 6, 7 },
{ /* 44 */ 7, 8 },
{ /* 45 */ 8, 9 },
{ /* 46 */ 9, 10 },
{ /* 47 */ 70, 0 },
{ /* 48 */ 50, 0 },
{ /* 49 */ 49, 0 },
{ /* 50 */ 71, 0 },
{ /* 51 */ 6, 7 },
{ /* 52 */ 7, 8 },
{ /* 53 */ 8, 9 },
{ /* 54 */ 9, 10 },
{ /* 55 */ 10, 11 },
{ /* 56 */ 11, 12 },
{ /* 57 */ 72, 0 },
{ /* 58 */ 48, 0 },
{ /* 59 */ 73, 0 },
{ /* 60 */ 47, 0 },
{ /* 61 */ 74, 0 },
{ /* 62 */ 46, 0 },
{ /* 63 */ 6, 7 },
{ /* 64 */ 7, 8 },
{ /* 65 */ 8, 9 },
{ /* 66 */ 9, 10 },
{ /* 67 */ 10, 11 },
{ /* 68 */ 11, 12 },
{ /* 69 */ 76, 0 },
{ /* 70 */ 75, 0 },
{ /* 71 */ 77, 0 },
{ /* 72 */ 78, 0 },
{ /* 73 */ 45, 0 },
{ /* 74 */ 43, 0 },
{ /* 75 */ 6, 7 },
{ /* 76 */ 7, 8 },
{ /* 77 */ 8, 9 },
{ /* 78 */ 9, 10 },
{ /* 79 */ 10, 11 },
{ /* 80 */ 11, 12 },
{ /* 81 */ 44, 0 },
{ /* 82 */ 79, 0 },
{ /* 83 */ 42, 0 },
{ /* 84 */ 41, 0 },
{ /* 85 */ 80, 0 },
{ /* 86 */ 40, 0 },
{ /* 87 */ 6, 7 },
{ /* 88 */ 7, 8 },
{ /* 89 */ 8, 9 },
{ /* 90 */ 9, 10 },
{ /* 91 */ 10, 11 },
{ /* 92 */ 11, 12 },
{ /* 93 */ 81, 0 },
{ /* 94 */ 39, 0 },
{ /* 95 */ 82, 0 },
{ /* 96 */ 38, 0 },
{ /* 97 */ 83, 0 },
{ /* 98 */ 7, 8 },
{ /* 99 */ 8, 9 },
{ /* 00 */ 9, 10 },
{ /* 01 */ 10, 11 },
{ /* 02 */ 11, 12 },
{ /* 03 */ 12, 13 },
{ /* 04 */ 13, 14 },
{ /* 05 */ 37, 0 },
{ /* 06 */ 35, 0 },
{ /* 07 */ 85, 0 },
{ /* 08 */ 33, 0 },
{ /* 09 */ 36, 0 },
{ /* 10 */ 34, 0 },
{ /* 11 */ 84, 0 },
{ /* 12 */ 32, 0 },
{ /* 13 */ 6, 7 },
{ /* 14 */ 7, 8 },
{ /* 15 */ 8, 9 },
{ /* 16 */ 9, 10 },
{ /* 17 */ 10, 11 },
{ /* 18 */ 11, 12 },
{ /* 19 */ 87, 0 },
{ /* 20 */ 89, 0 },
{ /* 21 */ 30, 0 },
{ /* 22 */ 31, 0 },
{ /* 23 */ 8, 9 },
{ /* 24 */ 9, 10 },
{ /* 25 */ 10, 11 },
{ /* 26 */ 11, 12 },
{ /* 27 */ 12, 13 },
{ /* 28 */ 13, 14 },
{ /* 29 */ 14, 15 },
{ /* 30 */ 15, 16 },
{ /* 31 */ 86, 0 },
{ /* 32 */ 29, 0 },
{ /* 33 */ 26, 0 },
{ /* 34 */ 27, 0 },
{ /* 35 */ 28, 0 },
{ /* 36 */ 24, 0 },
{ /* 37 */ 88, 0 },
{ /* 38 */ 9, 10 },
{ /* 39 */ 10, 11 },
{ /* 40 */ 11, 12 },
{ /* 41 */ 12, 13 },
{ /* 42 */ 13, 14 },
{ /* 43 */ 14, 15 },
{ /* 44 */ 15, 16 },
{ /* 45 */ 16, 17 },
{ /* 46 */ 17, 18 },
{ /* 47 */ 25, 0 },
{ /* 48 */ 22, 0 },
{ /* 49 */ 23, 0 },
{ /* 50 */ 15, 16 },
{ /* 51 */ 16, 17 },
{ /* 52 */ 17, 18 },
{ /* 53 */ 18, 19 },
{ /* 54 */ 19, 20 },
{ /* 55 */ 20, 21 },
{ /* 56 */ 21, 22 },
{ /* 57 */ 22, 23 },
{ /* 58 */ 23, 24 },
{ /* 59 */ 24, 25 },
{ /* 60 */ 25, 26 },
{ /* 61 */ 26, 27 },
{ /* 62 */ 27, 28 },
{ /* 63 */ 28, 29 },
{ /* 64 */ 29, 30 },
{ /* 65 */ 90, 0 },
{ /* 66 */ 21, 0 },
{ /* 67 */ 19, 0 },
{ /* 68 */ 3, 0 },
{ /* 69 */ 1, 0 },
{ /* 70 */ 2, 0 },
{ /* 71 */ 0, 0 },
{ /* 72 */ 23, 24 },
{ /* 73 */ 24, 25 },
{ /* 74 */ 25, 26 },
{ /* 75 */ 26, 27 },
{ /* 76 */ 27, 28 },
{ /* 77 */ 28, 29 },
{ /* 78 */ 29, 30 },
{ /* 79 */ 30, 31 },
{ /* 80 */ 31, 32 },
{ /* 81 */ 32, 33 },
{ /* 82 */ 33, 34 },
{ /* 83 */ 34, 35 },
{ /* 84 */ 35, 36 },
{ /* 85 */ 36, 37 },
{ /* 86 */ 37, 38 },
{ /* 87 */ 38, 39 },
{ /* 88 */ 39, 40 },
{ /* 89 */ 40, 41 },
{ /* 90 */ 41, 42 },
{ /* 91 */ 42, 43 },
{ /* 92 */ 43, 44 },
{ /* 93 */ 44, 45 },
{ /* 94 */ 45, 46 },
{ /* 95 */ 98, 0 },
{ /* 96 */ 99, 0 },
{ /* 97 */ 100, 0 },
{ /* 98 */ 101, 0 },
{ /* 99 */ 102, 0 },
{ /* 00 */ 117, 0 },
{ /* 01 */ 97, 0 },
{ /* 02 */ 91, 0 },
{ /* 03 */ 92, 0 },
{ /* 04 */ 93, 0 },
{ /* 05 */ 94, 0 },
{ /* 06 */ 95, 0 },
{ /* 07 */ 96, 0 },
{ /* 08 */ 104, 0 },
{ /* 09 */ 111, 0 },
{ /* 10 */ 112, 0 },
{ /* 11 */ 113, 0 },
{ /* 12 */ 114, 0 },
{ /* 13 */ 115, 0 },
{ /* 14 */ 116, 0 },
{ /* 15 */ 110, 0 },
{ /* 16 */ 105, 0 },
{ /* 17 */ 106, 0 },
{ /* 18 */ 107, 0 },
{ /* 19 */ 108, 0 },
{ /* 20 */ 109, 0 },
{ /* 21 */ 118, 0 },
{ /* 22 */ 6, 0 },
{ /* 23 */ 8, 0 },
{ /* 24 */ 9, 0 },
{ /* 25 */ 10, 0 },
{ /* 26 */ 5, 0 },
{ /* 27 */ 103, 0 },
{ /* 28 */ 120, 0 },
{ /* 29 */ 119, 0 },
{ /* 30 */ 4, 0 },
{ /* 31 */ 7, 0 },
{ /* 32 */ 15, 0 },
{ /* 33 */ 16, 0 },
{ /* 34 */ 18, 0 },
{ /* 35 */ 20, 0 },
{ /* 36 */ 17, 0 },
{ /* 37 */ 11, 0 },
{ /* 38 */ 12, 0 },
{ /* 39 */ 14, 0 },
{ /* 40 */ 13, 0 }
};

View File

@ -0,0 +1,522 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: common.c,v 1.27 2008/03/23 23:03:28 menno Exp $
**/
/* just some common functions that could be used anywhere */
#include "common.h"
#include "structs.h"
#include <stdlib.h>
#include "syntax.h"
/* Returns the sample rate index based on the samplerate */
uint8_t get_sr_index(const uint32_t samplerate)
{
if (92017 <= samplerate) return 0;
if (75132 <= samplerate) return 1;
if (55426 <= samplerate) return 2;
if (46009 <= samplerate) return 3;
if (37566 <= samplerate) return 4;
if (27713 <= samplerate) return 5;
if (23004 <= samplerate) return 6;
if (18783 <= samplerate) return 7;
if (13856 <= samplerate) return 8;
if (11502 <= samplerate) return 9;
if (9391 <= samplerate) return 10;
if (16428320 <= samplerate) return 11;
return 11;
}
/* Returns the sample rate based on the sample rate index */
uint32_t get_sample_rate(const uint8_t sr_index)
{
static const uint32_t sample_rates[] =
{
96000, 88200, 64000, 48000, 44100, 32000,
24000, 22050, 16000, 12000, 11025, 8000
};
if (sr_index < 12)
return sample_rates[sr_index];
return 0;
}
uint8_t max_pred_sfb(const uint8_t sr_index)
{
static const uint8_t pred_sfb_max[] =
{
33, 33, 38, 40, 40, 40, 41, 41, 37, 37, 37, 34
};
if (sr_index < 12)
return pred_sfb_max[sr_index];
return 0;
}
uint8_t max_tns_sfb(const uint8_t sr_index, const uint8_t object_type,
const uint8_t is_short)
{
/* entry for each sampling rate
* 1 Main/LC long window
* 2 Main/LC short window
* 3 SSR long window
* 4 SSR short window
*/
static const uint8_t tns_sbf_max[][4] =
{
{31, 9, 28, 7}, /* 96000 */
{31, 9, 28, 7}, /* 88200 */
{34, 10, 27, 7}, /* 64000 */
{40, 14, 26, 6}, /* 48000 */
{42, 14, 26, 6}, /* 44100 */
{51, 14, 26, 6}, /* 32000 */
{46, 14, 29, 7}, /* 24000 */
{46, 14, 29, 7}, /* 22050 */
{42, 14, 23, 8}, /* 16000 */
{42, 14, 23, 8}, /* 12000 */
{42, 14, 23, 8}, /* 11025 */
{39, 14, 19, 7}, /* 8000 */
{39, 14, 19, 7}, /* 7350 */
{0,0,0,0},
{0,0,0,0},
{0,0,0,0}
};
uint8_t i = 0;
if (is_short) i++;
if (object_type == SSR) i += 2;
return tns_sbf_max[sr_index][i];
}
/* Returns 0 if an object type is decodable, otherwise returns -1 */
int8_t can_decode_ot(const uint8_t object_type)
{
switch (object_type)
{
case LC:
return 0;
case MAIN:
#ifdef MAIN_DEC
return 0;
#else
return -1;
#endif
case SSR:
#ifdef SSR_DEC
return 0;
#else
return -1;
#endif
case LTP:
#ifdef LTP_DEC
return 0;
#else
return -1;
#endif
/* ER object types */
#ifdef ERROR_RESILIENCE
case ER_LC:
#ifdef DRM
case DRM_ER_LC:
#endif
return 0;
case ER_LTP:
#ifdef LTP_DEC
return 0;
#else
return -1;
#endif
case LD:
#ifdef LD_DEC
return 0;
#else
return -1;
#endif
#endif
}
return -1;
}
void *faad_malloc(size_t size)
{
#if 0 // defined(_WIN32) && !defined(_WIN32_WCE)
return _aligned_malloc(size, 16);
#else // #ifdef 0
return malloc(size);
#endif // #ifdef 0
}
/* common free function */
void faad_free(void *b)
{
#if 0 // defined(_WIN32) && !defined(_WIN32_WCE)
_aligned_free(b);
#else
free(b);
}
#endif
static const uint8_t Parity [256] = { // parity
0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,
1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,
1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,
0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,
1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,
0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,
0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,
1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0
};
static uint32_t __r1 = 1;
static uint32_t __r2 = 1;
/*
* This is a simple random number generator with good quality for audio purposes.
* It consists of two polycounters with opposite rotation direction and different
* periods. The periods are coprime, so the total period is the product of both.
*
* -------------------------------------------------------------------------------------------------
* +-> |31:30:29:28:27:26:25:24:23:22:21:20:19:18:17:16:15:14:13:12:11:10: 9: 8: 7: 6: 5: 4: 3: 2: 1: 0|
* | -------------------------------------------------------------------------------------------------
* | | | | | | |
* | +--+--+--+-XOR-+--------+
* | |
* +--------------------------------------------------------------------------------------+
*
* -------------------------------------------------------------------------------------------------
* |31:30:29:28:27:26:25:24:23:22:21:20:19:18:17:16:15:14:13:12:11:10: 9: 8: 7: 6: 5: 4: 3: 2: 1: 0| <-+
* ------------------------------------------------------------------------------------------------- |
* | | | | |
* +--+----XOR----+--+ |
* | |
* +----------------------------------------------------------------------------------------+
*
*
* The first has an period of 3*5*17*257*65537, the second of 7*47*73*178481,
* which gives a period of 18.410.713.077.675.721.215. The result is the
* XORed values of both generators.
*/
uint32_t ne_rng(uint32_t *__r1, uint32_t *__r2)
{
uint32_t t1, t2, t3, t4;
t3 = t1 = *__r1; t4 = t2 = *__r2; // Parity calculation is done via table lookup, this is also available
t1 &= 0xF5; t2 >>= 25; // on CPUs without parity, can be implemented in C and avoid unpredictable
t1 = Parity [t1]; t2 &= 0x63; // jumps and slow rotate through the carry flag operations.
t1 <<= 31; t2 = Parity [t2];
return (*__r1 = (t3 >> 1) | t1 ) ^ (*__r2 = (t4 + t4) | t2 );
}
static uint32_t ones32(uint32_t x)
{
x -= ((x >> 1) & 0x55555555);
x = (((x >> 2) & 0x33333333) + (x & 0x33333333));
x = (((x >> 4) + x) & 0x0f0f0f0f);
x += (x >> 8);
x += (x >> 16);
return (x & 0x0000003f);
}
static uint32_t floor_log2(uint32_t x)
{
#if 1
x |= (x >> 1);
x |= (x >> 2);
x |= (x >> 4);
x |= (x >> 8);
x |= (x >> 16);
return (ones32(x) - 1);
#else
uint32_t count = 0;
while (x >>= 1)
count++;
return count;
#endif
}
/* returns position of first bit that is not 0 from msb,
* starting count at lsb */
uint32_t wl_min_lzc(uint32_t x)
{
#if 1
x |= (x >> 1);
x |= (x >> 2);
x |= (x >> 4);
x |= (x >> 8);
x |= (x >> 16);
return (ones32(x));
#else
uint32_t count = 0;
while (x >>= 1)
count++;
return (count + 1);
#endif
}
#ifdef FIXED_POINT
#define TABLE_BITS 6
/* just take the maximum number of bits for interpolation */
#define INTERP_BITS (REAL_BITS-TABLE_BITS)
static const real_t pow2_tab[] = {
REAL_CONST(1.000000000000000), REAL_CONST(1.010889286051701), REAL_CONST(1.021897148654117),
REAL_CONST(1.033024879021228), REAL_CONST(1.044273782427414), REAL_CONST(1.055645178360557),
REAL_CONST(1.067140400676824), REAL_CONST(1.078760797757120), REAL_CONST(1.090507732665258),
REAL_CONST(1.102382583307841), REAL_CONST(1.114386742595892), REAL_CONST(1.126521618608242),
REAL_CONST(1.138788634756692), REAL_CONST(1.151189229952983), REAL_CONST(1.163724858777578),
REAL_CONST(1.176396991650281), REAL_CONST(1.189207115002721), REAL_CONST(1.202156731452703),
REAL_CONST(1.215247359980469), REAL_CONST(1.228480536106870), REAL_CONST(1.241857812073484),
REAL_CONST(1.255380757024691), REAL_CONST(1.269050957191733), REAL_CONST(1.282870016078778),
REAL_CONST(1.296839554651010), REAL_CONST(1.310961211524764), REAL_CONST(1.325236643159741),
REAL_CONST(1.339667524053303), REAL_CONST(1.354255546936893), REAL_CONST(1.369002422974591),
REAL_CONST(1.383909881963832), REAL_CONST(1.398979672538311), REAL_CONST(1.414213562373095),
REAL_CONST(1.429613338391970), REAL_CONST(1.445180806977047), REAL_CONST(1.460917794180647),
REAL_CONST(1.476826145939499), REAL_CONST(1.492907728291265), REAL_CONST(1.509164427593423),
REAL_CONST(1.525598150744538), REAL_CONST(1.542210825407941), REAL_CONST(1.559004400237837),
REAL_CONST(1.575980845107887), REAL_CONST(1.593142151342267), REAL_CONST(1.610490331949254),
REAL_CONST(1.628027421857348), REAL_CONST(1.645755478153965), REAL_CONST(1.663676580326736),
REAL_CONST(1.681792830507429), REAL_CONST(1.700106353718524), REAL_CONST(1.718619298122478),
REAL_CONST(1.737333835273706), REAL_CONST(1.756252160373300), REAL_CONST(1.775376492526521),
REAL_CONST(1.794709075003107), REAL_CONST(1.814252175500399), REAL_CONST(1.834008086409342),
REAL_CONST(1.853979125083386), REAL_CONST(1.874167634110300), REAL_CONST(1.894575981586966),
REAL_CONST(1.915206561397147), REAL_CONST(1.936061793492294), REAL_CONST(1.957144124175400),
REAL_CONST(1.978456026387951), REAL_CONST(2.000000000000000)
};
static const real_t log2_tab[] = {
REAL_CONST(0.000000000000000), REAL_CONST(0.022367813028455), REAL_CONST(0.044394119358453),
REAL_CONST(0.066089190457772), REAL_CONST(0.087462841250339), REAL_CONST(0.108524456778169),
REAL_CONST(0.129283016944966), REAL_CONST(0.149747119504682), REAL_CONST(0.169925001442312),
REAL_CONST(0.189824558880017), REAL_CONST(0.209453365628950), REAL_CONST(0.228818690495881),
REAL_CONST(0.247927513443585), REAL_CONST(0.266786540694901), REAL_CONST(0.285402218862248),
REAL_CONST(0.303780748177103), REAL_CONST(0.321928094887362), REAL_CONST(0.339850002884625),
REAL_CONST(0.357552004618084), REAL_CONST(0.375039431346925), REAL_CONST(0.392317422778760),
REAL_CONST(0.409390936137702), REAL_CONST(0.426264754702098), REAL_CONST(0.442943495848728),
REAL_CONST(0.459431618637297), REAL_CONST(0.475733430966398), REAL_CONST(0.491853096329675),
REAL_CONST(0.507794640198696), REAL_CONST(0.523561956057013), REAL_CONST(0.539158811108031),
REAL_CONST(0.554588851677637), REAL_CONST(0.569855608330948), REAL_CONST(0.584962500721156),
REAL_CONST(0.599912842187128), REAL_CONST(0.614709844115208), REAL_CONST(0.629356620079610),
REAL_CONST(0.643856189774725), REAL_CONST(0.658211482751795), REAL_CONST(0.672425341971496),
REAL_CONST(0.686500527183218), REAL_CONST(0.700439718141092), REAL_CONST(0.714245517666123),
REAL_CONST(0.727920454563199), REAL_CONST(0.741466986401147), REAL_CONST(0.754887502163469),
REAL_CONST(0.768184324776926), REAL_CONST(0.781359713524660), REAL_CONST(0.794415866350106),
REAL_CONST(0.807354922057604), REAL_CONST(0.820178962415188), REAL_CONST(0.832890014164742),
REAL_CONST(0.845490050944375), REAL_CONST(0.857980995127572), REAL_CONST(0.870364719583405),
REAL_CONST(0.882643049361841), REAL_CONST(0.894817763307943), REAL_CONST(0.906890595608519),
REAL_CONST(0.918863237274595), REAL_CONST(0.930737337562886), REAL_CONST(0.942514505339240),
REAL_CONST(0.954196310386875), REAL_CONST(0.965784284662087), REAL_CONST(0.977279923499917),
REAL_CONST(0.988684686772166), REAL_CONST(1.000000000000000)
};
real_t pow2_fix(real_t val)
{
uint32_t x1, x2;
uint32_t errcorr;
uint32_t index_frac;
real_t retval;
int32_t whole = (val >> REAL_BITS);
/* rest = [0..1] */
int32_t rest = val - (whole << REAL_BITS);
/* index into pow2_tab */
int32_t index = rest >> (REAL_BITS-TABLE_BITS);
if (val == 0)
return (1<<REAL_BITS);
/* leave INTERP_BITS bits */
index_frac = rest >> (REAL_BITS-TABLE_BITS-INTERP_BITS);
index_frac = index_frac & ((1<<INTERP_BITS)-1);
if (whole > 0)
{
retval = 1 << whole;
} else {
retval = REAL_CONST(1) >> -whole;
}
x1 = pow2_tab[index & ((1<<TABLE_BITS)-1)];
x2 = pow2_tab[(index & ((1<<TABLE_BITS)-1)) + 1];
errcorr = ( (index_frac*(x2-x1))) >> INTERP_BITS;
if (whole > 0)
{
retval = retval * (errcorr + x1);
} else {
retval = MUL_R(retval, (errcorr + x1));
}
return retval;
}
int32_t pow2_int(real_t val)
{
uint32_t x1, x2;
uint32_t errcorr;
uint32_t index_frac;
real_t retval;
int32_t whole = (val >> REAL_BITS);
/* rest = [0..1] */
int32_t rest = val - (whole << REAL_BITS);
/* index into pow2_tab */
int32_t index = rest >> (REAL_BITS-TABLE_BITS);
if (val == 0)
return 1;
/* leave INTERP_BITS bits */
index_frac = rest >> (REAL_BITS-TABLE_BITS-INTERP_BITS);
index_frac = index_frac & ((1<<INTERP_BITS)-1);
if (whole > 0)
retval = 1 << whole;
else
retval = 0;
x1 = pow2_tab[index & ((1<<TABLE_BITS)-1)];
x2 = pow2_tab[(index & ((1<<TABLE_BITS)-1)) + 1];
errcorr = ( (index_frac*(x2-x1))) >> INTERP_BITS;
retval = MUL_R(retval, (errcorr + x1));
return retval;
}
/* ld(x) = ld(x*y/y) = ld(x/y) + ld(y), with y=2^N and [1 <= (x/y) < 2] */
int32_t log2_int(uint32_t val)
{
uint32_t frac;
uint32_t whole = (val);
int32_t exp = 0;
uint32_t index;
uint32_t index_frac;
uint32_t x1, x2;
uint32_t errcorr;
/* error */
if (val == 0)
return -10000;
exp = floor_log2(val);
exp -= REAL_BITS;
/* frac = [1..2] */
if (exp >= 0)
frac = val >> exp;
else
frac = val << -exp;
/* index in the log2 table */
index = frac >> (REAL_BITS-TABLE_BITS);
/* leftover part for linear interpolation */
index_frac = frac & ((1<<(REAL_BITS-TABLE_BITS))-1);
/* leave INTERP_BITS bits */
index_frac = index_frac >> (REAL_BITS-TABLE_BITS-INTERP_BITS);
x1 = log2_tab[index & ((1<<TABLE_BITS)-1)];
x2 = log2_tab[(index & ((1<<TABLE_BITS)-1)) + 1];
/* linear interpolation */
/* retval = exp + ((index_frac)*x2 + (1-index_frac)*x1) */
errcorr = (index_frac * (x2-x1)) >> INTERP_BITS;
return ((exp+REAL_BITS) << REAL_BITS) + errcorr + x1;
}
/* ld(x) = ld(x*y/y) = ld(x/y) + ld(y), with y=2^N and [1 <= (x/y) < 2] */
real_t log2_fix(uint32_t val)
{
uint32_t frac;
uint32_t whole = (val >> REAL_BITS);
int8_t exp = 0;
uint32_t index;
uint32_t index_frac;
uint32_t x1, x2;
uint32_t errcorr;
/* error */
if (val == 0)
return -100000;
exp = floor_log2(val);
exp -= REAL_BITS;
/* frac = [1..2] */
if (exp >= 0)
frac = val >> exp;
else
frac = val << -exp;
/* index in the log2 table */
index = frac >> (REAL_BITS-TABLE_BITS);
/* leftover part for linear interpolation */
index_frac = frac & ((1<<(REAL_BITS-TABLE_BITS))-1);
/* leave INTERP_BITS bits */
index_frac = index_frac >> (REAL_BITS-TABLE_BITS-INTERP_BITS);
x1 = log2_tab[index & ((1<<TABLE_BITS)-1)];
x2 = log2_tab[(index & ((1<<TABLE_BITS)-1)) + 1];
/* linear interpolation */
/* retval = exp + ((index_frac)*x2 + (1-index_frac)*x1) */
errcorr = (index_frac * (x2-x1)) >> INTERP_BITS;
return (exp << REAL_BITS) + errcorr + x1;
}
#endif

View File

@ -0,0 +1,450 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: common.h,v 1.77 2009/02/05 00:51:03 menno Exp $
**/
#ifndef __COMMON_H__
#define __COMMON_H__
#ifdef __cplusplus
extern "C" {
#endif
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "neaacdec.h"
#if 1
#define INLINE __inline
#else
#define INLINE inline
#endif
#if 0 //defined(_WIN32) && !defined(_WIN32_WCE)
#define ALIGN __declspec(align(16))
#else
#define ALIGN
#endif
#ifndef max
#define max(a, b) (((a) > (b)) ? (a) : (b))
#endif
#ifndef min
#define min(a, b) (((a) < (b)) ? (a) : (b))
#endif
/* COMPILE TIME DEFINITIONS */
/* use double precision */
/* #define USE_DOUBLE_PRECISION */
/* use fixed point reals */
//#define FIXED_POINT
//#define BIG_IQ_TABLE
/* Use if target platform has address generators with autoincrement */
//#define PREFER_POINTERS
#ifdef _WIN32_WCE
#define FIXED_POINT
#endif
#ifdef __BFIN__
#define FIXED_POINT
#endif
#define ERROR_RESILIENCE
/* Allow decoding of MAIN profile AAC */
#define MAIN_DEC
/* Allow decoding of SSR profile AAC */
//#define SSR_DEC
/* Allow decoding of LTP profile AAC */
#define LTP_DEC
/* Allow decoding of LD profile AAC */
#define LD_DEC
/* Allow decoding of Digital Radio Mondiale (DRM) */
//#define DRM
//#define DRM_PS
/* LD can't do without LTP */
#ifdef LD_DEC
#ifndef ERROR_RESILIENCE
#define ERROR_RESILIENCE
#endif
#ifndef LTP_DEC
#define LTP_DEC
#endif
#endif
#define ALLOW_SMALL_FRAMELENGTH
// Define LC_ONLY_DECODER if you want a pure AAC LC decoder (independant of SBR_DEC and PS_DEC)
//#define LC_ONLY_DECODER
#ifdef LC_ONLY_DECODER
#undef LD_DEC
#undef LTP_DEC
#undef MAIN_DEC
#undef SSR_DEC
#undef DRM
#undef ALLOW_SMALL_FRAMELENGTH
#undef ERROR_RESILIENCE
#endif
#define SBR_DEC
//#define SBR_LOW_POWER
#define PS_DEC
#ifdef SBR_LOW_POWER
#undef PS_DEC
#endif
/* FIXED POINT: No MAIN decoding */
#ifdef FIXED_POINT
# ifdef MAIN_DEC
# undef MAIN_DEC
# endif
#endif // FIXED_POINT
#ifdef DRM
# ifndef ALLOW_SMALL_FRAMELENGTH
# define ALLOW_SMALL_FRAMELENGTH
# endif
# undef LD_DEC
# undef LTP_DEC
# undef MAIN_DEC
# undef SSR_DEC
#endif
#ifdef FIXED_POINT
#define DIV_R(A, B) (((int64_t)A << REAL_BITS)/B)
#define DIV_C(A, B) (((int64_t)A << COEF_BITS)/B)
#else
#define DIV_R(A, B) ((A)/(B))
#define DIV_C(A, B) ((A)/(B))
#endif
#ifndef SBR_LOW_POWER
#define qmf_t complex_t
#define QMF_RE(A) RE(A)
#define QMF_IM(A) IM(A)
#else
#define qmf_t real_t
#define QMF_RE(A) (A)
#define QMF_IM(A)
#endif
/* END COMPILE TIME DEFINITIONS */
#if defined(_WIN32) && !defined(__MINGW32__)
#include <stdlib.h>
typedef unsigned __int64 uint64_t;
typedef unsigned __int32 uint32_t;
typedef unsigned __int16 uint16_t;
typedef unsigned __int8 uint8_t;
typedef signed __int64 int64_t;
typedef signed __int32 int32_t;
typedef signed __int16 int16_t;
typedef signed __int8 int8_t;
typedef float float32_t;
#else
#include <stdio.h>
#if HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#if HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif
#if STDC_HEADERS
# include <stdlib.h>
# include <stddef.h>
#else
# if HAVE_STDLIB_H
# include <stdlib.h>
# endif
#endif
#if HAVE_STRING_H
# if !STDC_HEADERS && HAVE_MEMORY_H
# include <memory.h>
# endif
# include <string.h>
#endif
#if HAVE_STRINGS_H
# include <strings.h>
#endif
#if HAVE_INTTYPES_H
# include <inttypes.h>
#else
# if HAVE_STDINT_H
# include <stdint.h>
# else
/* we need these... */
#ifndef __TCS__
typedef unsigned long long uint64_t;
typedef signed long long int64_t;
#else
typedef unsigned long uint64_t;
typedef signed long int64_t;
#endif
typedef unsigned long uint32_t;
typedef unsigned short uint16_t;
typedef unsigned char uint8_t;
typedef signed long int32_t;
typedef signed short int16_t;
typedef signed char int8_t;
# endif
#endif
#if HAVE_UNISTD_H
//# include <unistd.h>
#endif
#ifndef HAVE_FLOAT32_T
typedef float float32_t;
#endif
#if STDC_HEADERS
# include <string.h>
#else
# if !HAVE_STRCHR
# define strchr index
# define strrchr rindex
# endif
char *strchr(), *strrchr();
# if !HAVE_MEMCPY
# define memcpy(d, s, n) bcopy((s), (d), (n))
# define memmove(d, s, n) bcopy((s), (d), (n))
# endif
#endif
#endif
#ifdef WORDS_BIGENDIAN
#define ARCH_IS_BIG_ENDIAN
#endif
/* FIXED_POINT doesn't work with MAIN and SSR yet */
#ifdef FIXED_POINT
#undef MAIN_DEC
#undef SSR_DEC
#endif
#if defined(FIXED_POINT)
#include "fixed.h"
#elif defined(USE_DOUBLE_PRECISION)
typedef double real_t;
#include <math.h>
#define MUL_R(A,B) ((A)*(B))
#define MUL_C(A,B) ((A)*(B))
#define MUL_F(A,B) ((A)*(B))
/* Complex multiplication */
static INLINE void ComplexMult(real_t *y1, real_t *y2,
real_t x1, real_t x2, real_t c1, real_t c2)
{
*y1 = MUL_F(x1, c1) + MUL_F(x2, c2);
*y2 = MUL_F(x2, c1) - MUL_F(x1, c2);
}
#define REAL_CONST(A) ((real_t)(A))
#define COEF_CONST(A) ((real_t)(A))
#define Q2_CONST(A) ((real_t)(A))
#define FRAC_CONST(A) ((real_t)(A)) /* pure fractional part */
#else /* Normal floating point operation */
typedef float real_t;
#define MUL_R(A,B) ((A)*(B))
#define MUL_C(A,B) ((A)*(B))
#define MUL_F(A,B) ((A)*(B))
#define REAL_CONST(A) ((real_t)(A))
#define COEF_CONST(A) ((real_t)(A))
#define Q2_CONST(A) ((real_t)(A))
#define FRAC_CONST(A) ((real_t)(A)) /* pure fractional part */
/* Complex multiplication */
static INLINE void ComplexMult(real_t *y1, real_t *y2,
real_t x1, real_t x2, real_t c1, real_t c2)
{
*y1 = MUL_F(x1, c1) + MUL_F(x2, c2);
*y2 = MUL_F(x2, c1) - MUL_F(x1, c2);
}
#if defined(_WIN32) && !defined(__MINGW32__)
#define HAS_LRINTF
static INLINE int lrintf(float f)
{
int i;
__asm
{
fld f
fistp i
}
return i;
}
#elif (defined(__i386__) && defined(__GNUC__) && \
!defined(__CYGWIN__) && !defined(__MINGW32__))
#ifndef HAVE_LRINTF
#define HAS_LRINTF
// from http://www.stereopsis.com/FPU.html
static INLINE int lrintf(float f)
{
int i;
__asm__ __volatile__ (
"flds %1 \n\t"
"fistpl %0 \n\t"
: "=m" (i)
: "m" (f));
return i;
}
#endif /* HAVE_LRINTF */
#endif
#ifdef __ICL /* only Intel C compiler has fmath ??? */
#include <mathf.h>
#define sin sinf
#define cos cosf
#define log logf
#define floor floorf
#define ceil ceilf
#define sqrt sqrtf
#else
#ifdef HAVE_LRINTF
# define HAS_LRINTF
# define _ISOC9X_SOURCE 1
# define _ISOC99_SOURCE 1
# define __USE_ISOC9X 1
# define __USE_ISOC99 1
#endif
#include <math.h>
#ifdef HAVE_SINF
# define sin sinf
#error
#endif
#ifdef HAVE_COSF
# define cos cosf
#endif
#ifdef HAVE_LOGF
# define log logf
#endif
#ifdef HAVE_EXPF
# define exp expf
#endif
#ifdef HAVE_FLOORF
# define floor floorf
#endif
#ifdef HAVE_CEILF
# define ceil ceilf
#endif
#ifdef HAVE_SQRTF
# define sqrt sqrtf
#endif
#endif
#endif
#ifndef HAS_LRINTF
/* standard cast */
#define lrintf(f) ((int32_t)(f))
#endif
typedef real_t complex_t[2];
#define RE(A) A[0]
#define IM(A) A[1]
/* common functions */
uint8_t cpu_has_sse(void);
uint32_t ne_rng(uint32_t *__r1, uint32_t *__r2);
uint32_t wl_min_lzc(uint32_t x);
#ifdef FIXED_POINT
#define LOG2_MIN_INF REAL_CONST(-10000)
int32_t log2_int(uint32_t val);
int32_t log2_fix(uint32_t val);
int32_t pow2_int(real_t val);
real_t pow2_fix(real_t val);
#endif
uint8_t get_sr_index(const uint32_t samplerate);
uint8_t max_pred_sfb(const uint8_t sr_index);
uint8_t max_tns_sfb(const uint8_t sr_index, const uint8_t object_type,
const uint8_t is_short);
uint32_t get_sample_rate(const uint8_t sr_index);
int8_t can_decode_ot(const uint8_t object_type);
void *faad_malloc(size_t size);
void faad_free(void *b);
//#define PROFILE
#ifdef PROFILE
static int64_t faad_get_ts()
{
__asm
{
rdtsc
}
}
#endif
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#ifndef M_PI_2 /* PI/2 */
#define M_PI_2 1.57079632679489661923
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,135 @@
/*
* config.h
*
* Created on: 2014-7-1
* Author: root
*/
#ifndef CONFIG_H_
#define CONFIG_H_
/* config.h. Generated from config.h.in by configure. */
/* config.h.in. Generated from configure.in by autoheader. */
/* Define if you want to use libfaad together with Digital Radio Mondiale
(DRM) */
/* #undef DRM */
/* Define if you want support for Digital Radio Mondiale (DRM) parametric
stereo */
/* #undef DRM_PS */
/* Define to 1 if you have the <dlfcn.h> header file. */
#define HAVE_DLFCN_H 1
/* Define to 1 if you have the <errno.h> header file. */
#define HAVE_ERRNO_H 1
/* Define if needed */
/* #undef HAVE_FLOAT32_T */
/* Define to 1 if you have the <float.h> header file. */
#define HAVE_FLOAT_H 1
/* Define to 1 if you have the `getpwuid' function. */
#define HAVE_GETPWUID 1
/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1
/* Define if you have the IOKit API */
/* #undef HAVE_IOKIT_IOKITLIB_H */
/* Define to 1 if you have the <limits.h> header file. */
#define HAVE_LIMITS_H 1
/* Define if you have C99's lrintf function. */
#define HAVE_LRINTF 1
/* Define to 1 if you have the <mathf.h> header file. */
/* #undef HAVE_MATHF_H */
/* Define to 1 if you have the `memcpy' function. */
#define HAVE_MEMCPY 1
/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1
/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1
/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1
/* Define to 1 if you have the `strchr' function. */
#define HAVE_STRCHR 1
/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 1
/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1
/* Define to 1 if you have the `strsep' function. */
#define HAVE_STRSEP 1
/* Define to 1 if you have the <sysfs/libsysfs.h> header file. */
/* #undef HAVE_SYSFS_LIBSYSFS_H */
/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1
/* Define to 1 if you have the <sys/time.h> header file. */
#define HAVE_SYS_TIME_H 1
/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1
/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
/* Define to 1 if your C compiler doesn't accept -c and -o together. */
/* #undef NO_MINUS_C_MINUS_O */
/* Name of package */
#define PACKAGE "faad2"
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT ""
/* Define to the full name of this package. */
#define PACKAGE_NAME ""
/* Define to the full name and version of this package. */
#define PACKAGE_STRING ""
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME ""
/* Define to the version of this package. */
#define PACKAGE_VERSION ""
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
#define TIME_WITH_SYS_TIME 1
/* Version number of package */
#define VERSION "2.7.0"
/* Define to 1 if your processor stores words with the most significant byte
first (like Motorola and SPARC, unlike Intel and VAX). */
/* #undef WORDS_BIGENDIAN */
/* Define to `__inline__' or `__inline' if that's what the C compiler
calls it, or to nothing if 'inline' is not supported under any name. */
#ifndef __cplusplus
/* #undef inline */
#endif
/* Define to `long int' if <sys/types.h> does not define. */
/* #undef off_t */
#endif /* CONFIG_H_ */

File diff suppressed because it is too large Load Diff

173
tests/Audio/libFaad/drc.c Normal file
View File

@ -0,0 +1,173 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: drc.c,v 1.28 2007/11/01 12:33:30 menno Exp $
**/
#include "common.h"
#include "structs.h"
#include <stdlib.h>
#include <string.h>
#include "syntax.h"
#include "drc.h"
drc_info *drc_init(real_t cut, real_t boost)
{
drc_info *drc = (drc_info*)faad_malloc(sizeof(drc_info));
memset(drc, 0, sizeof(drc_info));
drc->ctrl1 = cut;
drc->ctrl2 = boost;
drc->num_bands = 1;
drc->band_top[0] = 1024/4 - 1;
drc->dyn_rng_sgn[0] = 1;
drc->dyn_rng_ctl[0] = 0;
return drc;
}
void drc_end(drc_info *drc)
{
if (drc) faad_free(drc);
}
#ifdef FIXED_POINT
static real_t drc_pow2_table[] =
{
COEF_CONST(0.5146511183),
COEF_CONST(0.5297315472),
COEF_CONST(0.5452538663),
COEF_CONST(0.5612310242),
COEF_CONST(0.5776763484),
COEF_CONST(0.5946035575),
COEF_CONST(0.6120267717),
COEF_CONST(0.6299605249),
COEF_CONST(0.6484197773),
COEF_CONST(0.6674199271),
COEF_CONST(0.6869768237),
COEF_CONST(0.7071067812),
COEF_CONST(0.7278265914),
COEF_CONST(0.7491535384),
COEF_CONST(0.7711054127),
COEF_CONST(0.7937005260),
COEF_CONST(0.8169577266),
COEF_CONST(0.8408964153),
COEF_CONST(0.8655365610),
COEF_CONST(0.8908987181),
COEF_CONST(0.9170040432),
COEF_CONST(0.9438743127),
COEF_CONST(0.9715319412),
COEF_CONST(1.0000000000),
COEF_CONST(1.0293022366),
COEF_CONST(1.0594630944),
COEF_CONST(1.0905077327),
COEF_CONST(1.1224620483),
COEF_CONST(1.1553526969),
COEF_CONST(1.1892071150),
COEF_CONST(1.2240535433),
COEF_CONST(1.2599210499),
COEF_CONST(1.2968395547),
COEF_CONST(1.3348398542),
COEF_CONST(1.3739536475),
COEF_CONST(1.4142135624),
COEF_CONST(1.4556531828),
COEF_CONST(1.4983070769),
COEF_CONST(1.5422108254),
COEF_CONST(1.5874010520),
COEF_CONST(1.6339154532),
COEF_CONST(1.6817928305),
COEF_CONST(1.7310731220),
COEF_CONST(1.7817974363),
COEF_CONST(1.8340080864),
COEF_CONST(1.8877486254),
COEF_CONST(1.9430638823)
};
#endif
void drc_decode(drc_info *drc, real_t *spec)
{
uint16_t i, bd, top;
#ifdef FIXED_POINT
int32_t exp, frac;
#else
real_t factor, exp;
#endif
uint16_t bottom = 0;
if (drc->num_bands == 1)
drc->band_top[0] = 1024/4 - 1;
for (bd = 0; bd < drc->num_bands; bd++)
{
top = 4 * (drc->band_top[bd] + 1);
#ifndef FIXED_POINT
/* Decode DRC gain factor */
if (drc->dyn_rng_sgn[bd]) /* compress */
exp = -drc->ctrl1 * (drc->dyn_rng_ctl[bd] - (DRC_REF_LEVEL - drc->prog_ref_level))/REAL_CONST(24.0);
else /* boost */
exp = drc->ctrl2 * (drc->dyn_rng_ctl[bd] - (DRC_REF_LEVEL - drc->prog_ref_level))/REAL_CONST(24.0);
factor = (real_t)pow(2.0, exp);
/* Apply gain factor */
for (i = bottom; i < top; i++)
spec[i] *= factor;
#else
/* Decode DRC gain factor */
if (drc->dyn_rng_sgn[bd]) /* compress */
{
exp = -1 * (drc->dyn_rng_ctl[bd] - (DRC_REF_LEVEL - drc->prog_ref_level))/ 24;
frac = -1 * (drc->dyn_rng_ctl[bd] - (DRC_REF_LEVEL - drc->prog_ref_level)) % 24;
} else { /* boost */
exp = (drc->dyn_rng_ctl[bd] - (DRC_REF_LEVEL - drc->prog_ref_level))/ 24;
frac = (drc->dyn_rng_ctl[bd] - (DRC_REF_LEVEL - drc->prog_ref_level)) % 24;
}
/* Apply gain factor */
if (exp < 0)
{
for (i = bottom; i < top; i++)
{
spec[i] >>= -exp;
if (frac)
spec[i] = MUL_R(spec[i],drc_pow2_table[frac+23]);
}
} else {
for (i = bottom; i < top; i++)
{
spec[i] <<= exp;
if (frac)
spec[i] = MUL_R(spec[i],drc_pow2_table[frac+23]);
}
}
#endif
bottom = top;
}
}

49
tests/Audio/libFaad/drc.h Normal file
View File

@ -0,0 +1,49 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: drc.h,v 1.22 2007/11/01 12:33:30 menno Exp $
**/
#ifndef __DRC_H__
#define __DRC_H__
#ifdef __cplusplus
extern "C" {
#endif
#define DRC_REF_LEVEL 20*4 /* -20 dB */
drc_info *drc_init(real_t cut, real_t boost);
void drc_end(drc_info *drc);
void drc_decode(drc_info *drc, real_t *spec);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,965 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: drm_dec.c,v 1.9 2007/11/01 12:33:30 menno Exp $
**/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "common.h"
#ifdef DRM
#include "sbr_dec.h"
#include "drm_dec.h"
#include "bits.h"
/* constants */
#define DECAY_CUTOFF 3
#define DECAY_SLOPE 0.05f
/* type definitaions */
typedef const int8_t (*drm_ps_huff_tab)[2];
/* binary search huffman tables */
static const int8_t f_huffman_sa[][2] =
{
{ /*0*/ -15, 1 }, /* index 0: 1 bits: x */
{ 2, 3 }, /* index 1: 2 bits: 1x */
{ /*7*/ -8, 4 }, /* index 2: 3 bits: 10x */
{ 5, 6 }, /* index 3: 3 bits: 11x */
{ /*1*/ -14, /*-1*/ -16 }, /* index 4: 4 bits: 101x */
{ /*-2*/ -17, 7 }, /* index 5: 4 bits: 110x */
{ 8, 9 }, /* index 6: 4 bits: 111x */
{ /*2*/ -13, /*-3*/ -18 }, /* index 7: 5 bits: 1101x */
{ /*3*/ -12, 10 }, /* index 8: 5 bits: 1110x */
{ 11, 12 }, /* index 9: 5 bits: 1111x */
{ /*4*/ -11, /*5*/ -10 }, /* index 10: 6 bits: 11101x */
{ /*-4*/ -19, /*-5*/ -20 }, /* index 11: 6 bits: 11110x */
{ /*6*/ -9, 13 }, /* index 12: 6 bits: 11111x */
{ /*-7*/ -22, /*-6*/ -21 } /* index 13: 7 bits: 111111x */
};
static const int8_t t_huffman_sa[][2] =
{
{ /*0*/ -15, 1 }, /* index 0: 1 bits: x */
{ 2, 3 }, /* index 1: 2 bits: 1x */
{ /*-1*/ -16, /*1*/ -14 }, /* index 2: 3 bits: 10x */
{ 4, 5 }, /* index 3: 3 bits: 11x */
{ /*-2*/ -17, /*2*/ -13 }, /* index 4: 4 bits: 110x */
{ 6, 7 }, /* index 5: 4 bits: 111x */
{ /*-3*/ -18, /*3*/ -12 }, /* index 6: 5 bits: 1110x */
{ 8, 9 }, /* index 7: 5 bits: 1111x */
{ /*-4*/ -19, /*4*/ -11 }, /* index 8: 6 bits: 11110x */
{ 10, 11 }, /* index 9: 6 bits: 11111x */
{ /*-5*/ -20, /*5*/ -10 }, /* index 10: 7 bits: 111110x */
{ /*-6*/ -21, 12 }, /* index 11: 7 bits: 111111x */
{ /*-7*/ -22, 13 }, /* index 12: 8 bits: 1111111x */
{ /*6*/ -9, /*7*/ -8 } /* index 13: 9 bits: 11111111x */
};
static const int8_t f_huffman_pan[][2] =
{
{ /*0*/ -15, 1 }, /* index 0: 1 bits: x */
{ /*-1*/ -16, 2 }, /* index 1: 2 bits: 1x */
{ /*1*/ -14, 3 }, /* index 2: 3 bits: 11x */
{ 4, 5 }, /* index 3: 4 bits: 111x */
{ /*-2*/ -17, /*2*/ -13 }, /* index 4: 5 bits: 1110x */
{ 6, 7 }, /* index 5: 5 bits: 1111x */
{ /*-3*/ -18, /*3*/ -12 }, /* index 6: 6 bits: 11110x */
{ 8, 9 }, /* index 7: 6 bits: 11111x */
{ /*-4*/ -19, /*4*/ -11 }, /* index 8: 7 bits: 111110x */
{ 10, 11 }, /* index 9: 7 bits: 111111x */
{ /*-5*/ -20, /*5*/ -10 }, /* index 10: 8 bits: 1111110x */
{ 12, 13 }, /* index 11: 8 bits: 1111111x */
{ /*-6*/ -21, /*6*/ -9 }, /* index 12: 9 bits: 11111110x */
{ /*-7*/ -22, 14 }, /* index 13: 9 bits: 11111111x */
{ /*7*/ -8, 15 }, /* index 14: 10 bits: 111111111x */
{ 16, 17 }, /* index 15: 11 bits: 1111111111x */
{ /*-8*/ -23, /*8*/ -7 }, /* index 16: 12 bits: 11111111110x */
{ 18, 19 }, /* index 17: 12 bits: 11111111111x */
{ /*-10*/ -25, 20 }, /* index 18: 13 bits: 111111111110x */
{ 21, 22 }, /* index 19: 13 bits: 111111111111x */
{ /*-9*/ -24, /*9*/ -6 }, /* index 20: 14 bits: 1111111111101x */
{ /*10*/ -5, 23 }, /* index 21: 14 bits: 1111111111110x */
{ 24, 25 }, /* index 22: 14 bits: 1111111111111x */
{ /*-13*/ -28, /*-11*/ -26 }, /* index 23: 15 bits: 11111111111101x */
{ /*11*/ -4, /*13*/ -2 }, /* index 24: 15 bits: 11111111111110x */
{ 26, 27 }, /* index 25: 15 bits: 11111111111111x */
{ /*-14*/ -29, /*-12*/ -27 }, /* index 26: 16 bits: 111111111111110x */
{ /*12*/ -3, /*14*/ -1 } /* index 27: 16 bits: 111111111111111x */
};
static const int8_t t_huffman_pan[][2] =
{
{ /*0*/ -15, 1 }, /* index 0: 1 bits: x */
{ /*-1*/ -16, 2 }, /* index 1: 2 bits: 1x */
{ /*1*/ -14, 3 }, /* index 2: 3 bits: 11x */
{ /*-2*/ -17, 4 }, /* index 3: 4 bits: 111x */
{ /*2*/ -13, 5 }, /* index 4: 5 bits: 1111x */
{ /*-3*/ -18, 6 }, /* index 5: 6 bits: 11111x */
{ /*3*/ -12, 7 }, /* index 6: 7 bits: 111111x */
{ /*-4*/ -19, 8 }, /* index 7: 8 bits: 1111111x */
{ /*4*/ -11, 9 }, /* index 8: 9 bits: 11111111x */
{ 10, 11 }, /* index 9: 10 bits: 111111111x */
{ /*-5*/ -20, /*5*/ -10 }, /* index 10: 11 bits: 1111111110x */
{ 12, 13 }, /* index 11: 11 bits: 1111111111x */
{ /*-6*/ -21, /*6*/ -9 }, /* index 12: 12 bits: 11111111110x */
{ 14, 15 }, /* index 13: 12 bits: 11111111111x */
{ /*-7*/ -22, /*7*/ -8 }, /* index 14: 13 bits: 111111111110x */
{ 16, 17 }, /* index 15: 13 bits: 111111111111x */
{ /*-8*/ -23, /*8*/ -7 }, /* index 16: 14 bits: 1111111111110x */
{ 18, 19 }, /* index 17: 14 bits: 1111111111111x */
{ /*-10*/ -25, /*10*/ -5 }, /* index 18: 15 bits: 11111111111110x */
{ 20, 21 }, /* index 19: 15 bits: 11111111111111x */
{ /*-9*/ -24, /*9*/ -6 }, /* index 20: 16 bits: 111111111111110x */
{ 22, 23 }, /* index 21: 16 bits: 111111111111111x */
{ 24, 25 }, /* index 22: 17 bits: 1111111111111110x */
{ 26, 27 }, /* index 23: 17 bits: 1111111111111111x */
{ /*-14*/ -29, /*-13*/ -28 }, /* index 24: 18 bits: 11111111111111100x */
{ /*-12*/ -27, /*-11*/ -26 }, /* index 25: 18 bits: 11111111111111101x */
{ /*11*/ -4, /*12*/ -3 }, /* index 26: 18 bits: 11111111111111110x */
{ /*13*/ -2, /*14*/ -1 } /* index 27: 18 bits: 11111111111111111x */
};
/* There are 3 classes in the standard but the last 2 are identical */
static const real_t sa_quant[8][2] =
{
{ FRAC_CONST(0.0000), FRAC_CONST(0.0000) },
{ FRAC_CONST(0.0501), FRAC_CONST(0.1778) },
{ FRAC_CONST(0.0706), FRAC_CONST(0.2818) },
{ FRAC_CONST(0.0995), FRAC_CONST(0.4467) },
{ FRAC_CONST(0.1399), FRAC_CONST(0.5623) },
{ FRAC_CONST(0.1957), FRAC_CONST(0.7079) },
{ FRAC_CONST(0.2713), FRAC_CONST(0.8913) },
{ FRAC_CONST(0.3699), FRAC_CONST(1.0000) },
};
/* We don't need the actual quantizer values */
#if 0
static const real_t pan_quant[8][5] =
{
{ COEF_CONST(0.0000), COEF_CONST(0.0000), COEF_CONST(0.0000), COEF_CONST(0.0000), COEF_CONST(0.0000) },
{ COEF_CONST(0.1661), COEF_CONST(0.1661), COEF_CONST(0.3322), COEF_CONST(0.3322), COEF_CONST(0.3322) },
{ COEF_CONST(0.3322), COEF_CONST(0.3322), COEF_CONST(0.6644), COEF_CONST(0.8305), COEF_CONST(0.8305) },
{ COEF_CONST(0.4983), COEF_CONST(0.6644), COEF_CONST(0.9966), COEF_CONST(1.4949), COEF_CONST(1.6610) },
{ COEF_CONST(0.6644), COEF_CONST(0.9966), COEF_CONST(1.4949), COEF_CONST(2.1593), COEF_CONST(2.4914) },
{ COEF_CONST(0.8305), COEF_CONST(1.3288), COEF_CONST(2.1593), COEF_CONST(2.9897), COEF_CONST(3.4880) },
{ COEF_CONST(0.9966), COEF_CONST(1.8271), COEF_CONST(2.8236), COEF_CONST(3.8202), COEF_CONST(4.6507) },
{ COEF_CONST(1.3288), COEF_CONST(2.3253), COEF_CONST(3.4880), COEF_CONST(4.6507), COEF_CONST(5.8134) },
};
#endif
/* 2^(pan_quant[x][y] */
static const real_t pan_pow_2_pos[8][5] = {
{ REAL_CONST(1.0000000), REAL_CONST(1.0000000), REAL_CONST(1.0000000), REAL_CONST(1.0000000), REAL_CONST(1.0000000) },
{ REAL_CONST(1.1220021), REAL_CONST(1.1220021), REAL_CONST(1.2589312), REAL_CONST(1.2589312), REAL_CONST(1.2589312) },
{ REAL_CONST(1.2589312), REAL_CONST(1.2589312), REAL_CONST(1.5849090), REAL_CONST(1.7783016), REAL_CONST(1.7783016) },
{ REAL_CONST(1.4125481), REAL_CONST(1.5849090), REAL_CONST(1.9952921), REAL_CONST(2.8184461), REAL_CONST(3.1623565) },
{ REAL_CONST(1.5849090), REAL_CONST(1.9952922), REAL_CONST(2.8184461), REAL_CONST(4.4669806), REAL_CONST(5.6232337) },
{ REAL_CONST(1.7783016), REAL_CONST(2.5119365), REAL_CONST(4.4669806), REAL_CONST(7.9430881), REAL_CONST(11.219994) },
{ REAL_CONST(1.9952921), REAL_CONST(3.5482312), REAL_CONST(7.0792671), REAL_CONST(14.125206), REAL_CONST(25.118876) },
{ REAL_CONST(2.5119365), REAL_CONST(5.0116998), REAL_CONST(11.219994), REAL_CONST(25.118876), REAL_CONST(56.235140) }
};
/* 2^(-pan_quant[x][y] */
static const real_t pan_pow_2_neg[8][5] = {
{ REAL_CONST(1), REAL_CONST(1), REAL_CONST(1), REAL_CONST(1), REAL_CONST(1) },
{ REAL_CONST(0.8912487), REAL_CONST(0.8912487), REAL_CONST(0.7943242), REAL_CONST(0.7943242), REAL_CONST(0.7943242) },
{ REAL_CONST(0.7943242), REAL_CONST(0.7943242), REAL_CONST(0.6309511), REAL_CONST(0.5623344), REAL_CONST(0.5623344) },
{ REAL_CONST(0.7079405), REAL_CONST(0.6309511), REAL_CONST(0.5011797), REAL_CONST(0.3548054), REAL_CONST(0.3162199) },
{ REAL_CONST(0.6309511), REAL_CONST(0.5011797), REAL_CONST(0.3548054), REAL_CONST(0.2238649), REAL_CONST(0.1778336) },
{ REAL_CONST(0.5623343), REAL_CONST(0.3980992), REAL_CONST(0.2238649), REAL_CONST(0.1258956), REAL_CONST(0.0891266) },
{ REAL_CONST(0.5011797), REAL_CONST(0.2818306), REAL_CONST(0.1412576), REAL_CONST(0.0707954), REAL_CONST(0.0398107) },
{ REAL_CONST(0.3980992), REAL_CONST(0.1995331), REAL_CONST(0.0891267), REAL_CONST(0.0398107), REAL_CONST(0.0177825) }
};
/* 2^(pan_quant[x][y]/30) */
static const real_t pan_pow_2_30_pos[8][5] = {
{ COEF_CONST(1), COEF_CONST(1), COEF_CONST(1), COEF_CONST(1), COEF_CONST(1) },
{ COEF_CONST(1.003845098), COEF_CONST(1.003845098), COEF_CONST(1.007704982), COEF_CONST(1.007704982), COEF_CONST(1.007704982) },
{ COEF_CONST(1.007704982), COEF_CONST(1.007704982), COEF_CONST(1.01546933), COEF_CONST(1.019373909), COEF_CONST(1.019373909) },
{ COEF_CONST(1.011579706), COEF_CONST(1.01546933), COEF_CONST(1.023293502), COEF_CONST(1.035142941), COEF_CONST(1.039123167) },
{ COEF_CONST(1.01546933), COEF_CONST(1.023293502), COEF_CONST(1.035142941), COEF_CONST(1.051155908), COEF_CONST(1.059252598) },
{ COEF_CONST(1.019373909), COEF_CONST(1.03117796), COEF_CONST(1.051155908), COEF_CONST(1.071518432), COEF_CONST(1.0839263) },
{ COEF_CONST(1.023293502), COEF_CONST(1.043118698), COEF_CONST(1.067414119), COEF_CONST(1.092277933), COEF_CONST(1.113439626) },
{ COEF_CONST(1.03117796), COEF_CONST(1.055195268), COEF_CONST(1.0839263), COEF_CONST(1.113439626), COEF_CONST(1.143756546) }
};
/* 2^(-pan_quant[x][y]/30) */
static const real_t pan_pow_2_30_neg[8][5] = {
{ COEF_CONST(1), COEF_CONST(1), COEF_CONST(1), COEF_CONST(1), COEF_CONST(1) },
{ COEF_CONST(0.99616963), COEF_CONST(0.99616963), COEF_CONST(0.992353931), COEF_CONST(0.992353931), COEF_CONST(0.99235393) },
{ COEF_CONST(0.992353931), COEF_CONST(0.992353931), COEF_CONST(0.984766325), COEF_CONST(0.980994305), COEF_CONST(0.980994305) },
{ COEF_CONST(0.988552848), COEF_CONST(0.984766325), COEF_CONST(0.977236734), COEF_CONST(0.966050157), COEF_CONST(0.962349827) },
{ COEF_CONST(0.984766325), COEF_CONST(0.977236734), COEF_CONST(0.966050157), COEF_CONST(0.951333663), COEF_CONST(0.944061881) },
{ COEF_CONST(0.980994305), COEF_CONST(0.969764715), COEF_CONST(0.951333663), COEF_CONST(0.933255062), COEF_CONST(0.922571949) },
{ COEF_CONST(0.977236734), COEF_CONST(0.958663671), COEF_CONST(0.936843519), COEF_CONST(0.915517901), COEF_CONST(0.898117847) },
{ COEF_CONST(0.969764715), COEF_CONST(0.947691892), COEF_CONST(0.922571949), COEF_CONST(0.898117847), COEF_CONST(0.874311936) }
};
static const real_t g_decayslope[MAX_SA_BAND] = {
FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(0.95),FRAC_CONST(0.9), FRAC_CONST(0.85), FRAC_CONST(0.8),
FRAC_CONST(0.75),FRAC_CONST(0.7), FRAC_CONST(0.65),FRAC_CONST(0.6), FRAC_CONST(0.55),FRAC_CONST(0.5), FRAC_CONST(0.45),
FRAC_CONST(0.4), FRAC_CONST(0.35),FRAC_CONST(0.3), FRAC_CONST(0.25),FRAC_CONST(0.2), FRAC_CONST(0.15), FRAC_CONST(0.1),
FRAC_CONST(0.05),FRAC_CONST(0), FRAC_CONST(0), FRAC_CONST(0), FRAC_CONST(0), FRAC_CONST(0), FRAC_CONST(0),
FRAC_CONST(0), FRAC_CONST(0), FRAC_CONST(0), FRAC_CONST(0), FRAC_CONST(0), FRAC_CONST(0), FRAC_CONST(0),
FRAC_CONST(0), FRAC_CONST(0), FRAC_CONST(0), FRAC_CONST(0), FRAC_CONST(0), FRAC_CONST(0), FRAC_CONST(0),
FRAC_CONST(0), FRAC_CONST(0), FRAC_CONST(0)
};
static const real_t sa_sqrt_1_minus[8][2] = {
{ FRAC_CONST(1), FRAC_CONST(1) },
{ FRAC_CONST(0.998744206), FRAC_CONST(0.984066644) },
{ FRAC_CONST(0.997504707), FRAC_CONST(0.959473168) },
{ FRAC_CONST(0.995037562), FRAC_CONST(0.894683804) },
{ FRAC_CONST(0.990165638), FRAC_CONST(0.826933317) },
{ FRAC_CONST(0.980663811), FRAC_CONST(0.706312672) },
{ FRAC_CONST(0.962494836), FRAC_CONST(0.45341406) },
{ FRAC_CONST(0.929071574), FRAC_CONST(0) }
};
static const uint8_t sa_freq_scale[9] =
{
0, 1, 2, 3, 5, 7, 10, 13, 23
};
static const uint8_t pan_freq_scale[21] =
{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 18, 22, 26, 32, 64
};
static const uint8_t pan_quant_class[20] =
{
0, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 3, 3, 3, 4, 4, 4
};
/* Inverse mapping lookup */
static const uint8_t pan_inv_freq[64] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
15, 15, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19
};
static const uint8_t sa_inv_freq[MAX_SA_BAND] = {
0, 1, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7
};
static const real_t filter_coeff[] =
{
FRAC_CONST(0.65143905754106),
FRAC_CONST(0.56471812200776),
FRAC_CONST(0.48954165955695)
};
static const uint8_t delay_length[3] =
{
3, 4, 5
};
static const real_t delay_fraction[] =
{
FRAC_CONST(0.43), FRAC_CONST(0.75), FRAC_CONST(0.347)
};
static const real_t peak_decay = FRAC_CONST(0.76592833836465);
static const real_t smooth_coeff = FRAC_CONST(0.25);
/* Please note that these are the same tables as in plain PS */
static const complex_t Q_Fract_allpass_Qmf[][3] = {
{ { FRAC_CONST(0.7804303765), FRAC_CONST(0.6252426505) }, { FRAC_CONST(0.3826834261), FRAC_CONST(0.9238795042) }, { FRAC_CONST(0.8550928831), FRAC_CONST(0.5184748173) } },
{ { FRAC_CONST(-0.4399392009), FRAC_CONST(0.8980275393) }, { FRAC_CONST(-0.9238795042), FRAC_CONST(-0.3826834261) }, { FRAC_CONST(-0.0643581524), FRAC_CONST(0.9979268909) } },
{ { FRAC_CONST(-0.9723699093), FRAC_CONST(-0.2334454209) }, { FRAC_CONST(0.9238795042), FRAC_CONST(-0.3826834261) }, { FRAC_CONST(-0.9146071672), FRAC_CONST(0.4043435752) } },
{ { FRAC_CONST(0.0157073960), FRAC_CONST(-0.9998766184) }, { FRAC_CONST(-0.3826834261), FRAC_CONST(0.9238795042) }, { FRAC_CONST(-0.7814115286), FRAC_CONST(-0.6240159869) } },
{ { FRAC_CONST(0.9792228341), FRAC_CONST(-0.2027871907) }, { FRAC_CONST(-0.3826834261), FRAC_CONST(-0.9238795042) }, { FRAC_CONST(0.1920081824), FRAC_CONST(-0.9813933372) } },
{ { FRAC_CONST(0.4115142524), FRAC_CONST(0.9114032984) }, { FRAC_CONST(0.9238795042), FRAC_CONST(0.3826834261) }, { FRAC_CONST(0.9589683414), FRAC_CONST(-0.2835132182) } },
{ { FRAC_CONST(-0.7996847630), FRAC_CONST(0.6004201174) }, { FRAC_CONST(-0.9238795042), FRAC_CONST(0.3826834261) }, { FRAC_CONST(0.6947838664), FRAC_CONST(0.7192186117) } },
{ { FRAC_CONST(-0.7604058385), FRAC_CONST(-0.6494481564) }, { FRAC_CONST(0.3826834261), FRAC_CONST(-0.9238795042) }, { FRAC_CONST(-0.3164770305), FRAC_CONST(0.9486001730) } },
{ { FRAC_CONST(0.4679299891), FRAC_CONST(-0.8837655187) }, { FRAC_CONST(0.3826834261), FRAC_CONST(0.9238795042) }, { FRAC_CONST(-0.9874414206), FRAC_CONST(0.1579856575) } },
{ { FRAC_CONST(0.9645573497), FRAC_CONST(0.2638732493) }, { FRAC_CONST(-0.9238795042), FRAC_CONST(-0.3826834261) }, { FRAC_CONST(-0.5966450572), FRAC_CONST(-0.8025052547) } },
{ { FRAC_CONST(-0.0471066870), FRAC_CONST(0.9988898635) }, { FRAC_CONST(0.9238795042), FRAC_CONST(-0.3826834261) }, { FRAC_CONST(0.4357025325), FRAC_CONST(-0.9000906944) } },
{ { FRAC_CONST(-0.9851093888), FRAC_CONST(0.1719288528) }, { FRAC_CONST(-0.3826834261), FRAC_CONST(0.9238795042) }, { FRAC_CONST(0.9995546937), FRAC_CONST(-0.0298405960) } },
{ { FRAC_CONST(-0.3826831877), FRAC_CONST(-0.9238796234) }, { FRAC_CONST(-0.3826834261), FRAC_CONST(-0.9238795042) }, { FRAC_CONST(0.4886211455), FRAC_CONST(0.8724960685) } },
{ { FRAC_CONST(0.8181498647), FRAC_CONST(-0.5750049949) }, { FRAC_CONST(0.9238795042), FRAC_CONST(0.3826834261) }, { FRAC_CONST(-0.5477093458), FRAC_CONST(0.8366686702) } },
{ { FRAC_CONST(0.7396308780), FRAC_CONST(0.6730127335) }, { FRAC_CONST(-0.9238795042), FRAC_CONST(0.3826834261) }, { FRAC_CONST(-0.9951074123), FRAC_CONST(-0.0987988561) } },
{ { FRAC_CONST(-0.4954589605), FRAC_CONST(0.8686313629) }, { FRAC_CONST(0.3826834261), FRAC_CONST(-0.9238795042) }, { FRAC_CONST(-0.3725017905), FRAC_CONST(-0.9280315042) } },
{ { FRAC_CONST(-0.9557929039), FRAC_CONST(-0.2940406799) }, { FRAC_CONST(0.3826834261), FRAC_CONST(0.9238795042) }, { FRAC_CONST(0.6506417990), FRAC_CONST(-0.7593847513) } },
{ { FRAC_CONST(0.0784594864), FRAC_CONST(-0.9969173074) }, { FRAC_CONST(-0.9238795042), FRAC_CONST(-0.3826834261) }, { FRAC_CONST(0.9741733670), FRAC_CONST(0.2258014232) } },
{ { FRAC_CONST(0.9900237322), FRAC_CONST(-0.1409008205) }, { FRAC_CONST(0.9238795042), FRAC_CONST(-0.3826834261) }, { FRAC_CONST(0.2502108514), FRAC_CONST(0.9681913853) } },
{ { FRAC_CONST(0.3534744382), FRAC_CONST(0.9354441762) }, { FRAC_CONST(-0.3826834261), FRAC_CONST(0.9238795042) }, { FRAC_CONST(-0.7427945137), FRAC_CONST(0.6695194840) } },
{ { FRAC_CONST(-0.8358076215), FRAC_CONST(0.5490224361) }, { FRAC_CONST(-0.3826834261), FRAC_CONST(-0.9238795042) }, { FRAC_CONST(-0.9370992780), FRAC_CONST(-0.3490629196) } },
{ { FRAC_CONST(-0.7181259394), FRAC_CONST(-0.6959131360) }, { FRAC_CONST(0.9238795042), FRAC_CONST(0.3826834261) }, { FRAC_CONST(-0.1237744763), FRAC_CONST(-0.9923103452) } },
{ { FRAC_CONST(0.5224990249), FRAC_CONST(-0.8526399136) }, { FRAC_CONST(-0.9238795042), FRAC_CONST(0.3826834261) }, { FRAC_CONST(0.8226406574), FRAC_CONST(-0.5685616732) } },
{ { FRAC_CONST(0.9460852146), FRAC_CONST(0.3239179254) }, { FRAC_CONST(0.3826834261), FRAC_CONST(-0.9238795042) }, { FRAC_CONST(0.8844994903), FRAC_CONST(0.4665412009) } },
{ { FRAC_CONST(-0.1097348556), FRAC_CONST(0.9939609170) }, { FRAC_CONST(0.3826834261), FRAC_CONST(0.9238795042) }, { FRAC_CONST(-0.0047125919), FRAC_CONST(0.9999889135) } },
{ { FRAC_CONST(-0.9939610362), FRAC_CONST(0.1097337380) }, { FRAC_CONST(-0.9238795042), FRAC_CONST(-0.3826834261) }, { FRAC_CONST(-0.8888573647), FRAC_CONST(0.4581840038) } },
{ { FRAC_CONST(-0.3239168525), FRAC_CONST(-0.9460855722) }, { FRAC_CONST(0.9238795042), FRAC_CONST(-0.3826834261) }, { FRAC_CONST(-0.8172453642), FRAC_CONST(-0.5762898922) } },
{ { FRAC_CONST(0.8526405096), FRAC_CONST(-0.5224980116) }, { FRAC_CONST(-0.3826834261), FRAC_CONST(0.9238795042) }, { FRAC_CONST(0.1331215799), FRAC_CONST(-0.9910997152) } },
{ { FRAC_CONST(0.6959123611), FRAC_CONST(0.7181267142) }, { FRAC_CONST(-0.3826834261), FRAC_CONST(-0.9238795042) }, { FRAC_CONST(0.9403476119), FRAC_CONST(-0.3402152061) } },
{ { FRAC_CONST(-0.5490233898), FRAC_CONST(0.8358070254) }, { FRAC_CONST(0.9238795042), FRAC_CONST(0.3826834261) }, { FRAC_CONST(0.7364512086), FRAC_CONST(0.6764906645) } },
{ { FRAC_CONST(-0.9354437590), FRAC_CONST(-0.3534754813) }, { FRAC_CONST(-0.9238795042), FRAC_CONST(0.3826834261) }, { FRAC_CONST(-0.2593250275), FRAC_CONST(0.9657900929) } },
{ { FRAC_CONST(0.1409019381), FRAC_CONST(-0.9900235534) }, { FRAC_CONST(0.3826834261), FRAC_CONST(-0.9238795042) }, { FRAC_CONST(-0.9762582779), FRAC_CONST(0.2166097313) } },
{ { FRAC_CONST(0.9969173670), FRAC_CONST(-0.0784583688) }, { FRAC_CONST(0.3826834261), FRAC_CONST(0.9238795042) }, { FRAC_CONST(-0.6434556246), FRAC_CONST(-0.7654833794) } },
{ { FRAC_CONST(0.2940396070), FRAC_CONST(0.9557932615) }, { FRAC_CONST(-0.9238795042), FRAC_CONST(-0.3826834261) }, { FRAC_CONST(0.3812320232), FRAC_CONST(-0.9244794250) } },
{ { FRAC_CONST(-0.8686318994), FRAC_CONST(0.4954580069) }, { FRAC_CONST(0.9238795042), FRAC_CONST(-0.3826834261) }, { FRAC_CONST(0.9959943891), FRAC_CONST(-0.0894154981) } },
{ { FRAC_CONST(-0.6730118990), FRAC_CONST(-0.7396316528) }, { FRAC_CONST(-0.3826834261), FRAC_CONST(0.9238795042) }, { FRAC_CONST(0.5397993922), FRAC_CONST(0.8417937160) } },
{ { FRAC_CONST(0.5750059485), FRAC_CONST(-0.8181492686) }, { FRAC_CONST(-0.3826834261), FRAC_CONST(-0.9238795042) }, { FRAC_CONST(-0.4968227744), FRAC_CONST(0.8678520322) } },
{ { FRAC_CONST(0.9238792062), FRAC_CONST(0.3826842010) }, { FRAC_CONST(0.9238795042), FRAC_CONST(0.3826834261) }, { FRAC_CONST(-0.9992290139), FRAC_CONST(-0.0392601527) } },
{ { FRAC_CONST(-0.1719299555), FRAC_CONST(0.9851091504) }, { FRAC_CONST(-0.9238795042), FRAC_CONST(0.3826834261) }, { FRAC_CONST(-0.4271997511), FRAC_CONST(-0.9041572809) } },
{ { FRAC_CONST(-0.9988899231), FRAC_CONST(0.0471055657) }, { FRAC_CONST(0.3826834261), FRAC_CONST(-0.9238795042) }, { FRAC_CONST(0.6041822433), FRAC_CONST(-0.7968461514) } },
{ { FRAC_CONST(-0.2638721764), FRAC_CONST(-0.9645576477) }, { FRAC_CONST(0.3826834261), FRAC_CONST(0.9238795042) }, { FRAC_CONST(0.9859085083), FRAC_CONST(0.1672853529) } },
{ { FRAC_CONST(0.8837660551), FRAC_CONST(-0.4679289758) }, { FRAC_CONST(-0.9238795042), FRAC_CONST(-0.3826834261) }, { FRAC_CONST(0.3075223565), FRAC_CONST(0.9515408874) } },
{ { FRAC_CONST(0.6494473219), FRAC_CONST(0.7604066133) }, { FRAC_CONST(0.9238795042), FRAC_CONST(-0.3826834261) }, { FRAC_CONST(-0.7015317082), FRAC_CONST(0.7126382589) } },
{ { FRAC_CONST(-0.6004210114), FRAC_CONST(0.7996840477) }, { FRAC_CONST(-0.3826834261), FRAC_CONST(0.9238795042) }, { FRAC_CONST(-0.9562535882), FRAC_CONST(-0.2925389707) } },
{ { FRAC_CONST(-0.9114028811), FRAC_CONST(-0.4115152657) }, { FRAC_CONST(-0.3826834261), FRAC_CONST(-0.9238795042) }, { FRAC_CONST(-0.1827499419), FRAC_CONST(-0.9831594229) } },
{ { FRAC_CONST(0.2027882934), FRAC_CONST(-0.9792225957) }, { FRAC_CONST(0.9238795042), FRAC_CONST(0.3826834261) }, { FRAC_CONST(0.7872582674), FRAC_CONST(-0.6166234016) } },
{ { FRAC_CONST(0.9998766780), FRAC_CONST(-0.0157062728) }, { FRAC_CONST(-0.9238795042), FRAC_CONST(0.3826834261) }, { FRAC_CONST(0.9107555747), FRAC_CONST(0.4129458666) } },
{ { FRAC_CONST(0.2334443331), FRAC_CONST(0.9723701477) }, { FRAC_CONST(0.3826834261), FRAC_CONST(-0.9238795042) }, { FRAC_CONST(0.0549497530), FRAC_CONST(0.9984891415) } },
{ { FRAC_CONST(-0.8980280757), FRAC_CONST(0.4399381876) }, { FRAC_CONST(0.3826834261), FRAC_CONST(0.9238795042) }, { FRAC_CONST(-0.8599416018), FRAC_CONST(0.5103924870) } },
{ { FRAC_CONST(-0.6252418160), FRAC_CONST(-0.7804310918) }, { FRAC_CONST(-0.9238795042), FRAC_CONST(-0.3826834261) }, { FRAC_CONST(-0.8501682281), FRAC_CONST(-0.5265110731) } },
{ { FRAC_CONST(0.6252435446), FRAC_CONST(-0.7804297209) }, { FRAC_CONST(0.9238795042), FRAC_CONST(-0.3826834261) }, { FRAC_CONST(0.0737608299), FRAC_CONST(-0.9972759485) } },
{ { FRAC_CONST(0.8980270624), FRAC_CONST(0.4399402142) }, { FRAC_CONST(-0.3826834261), FRAC_CONST(0.9238795042) }, { FRAC_CONST(0.9183775187), FRAC_CONST(-0.3957053721) } },
{ { FRAC_CONST(-0.2334465086), FRAC_CONST(0.9723696709) }, { FRAC_CONST(-0.3826834261), FRAC_CONST(-0.9238795042) }, { FRAC_CONST(0.7754954696), FRAC_CONST(0.6313531399) } },
{ { FRAC_CONST(-0.9998766184), FRAC_CONST(-0.0157085191) }, { FRAC_CONST(0.9238795042), FRAC_CONST(0.3826834261) }, { FRAC_CONST(-0.2012493610), FRAC_CONST(0.9795400500) } },
{ { FRAC_CONST(-0.2027861029), FRAC_CONST(-0.9792230725) }, { FRAC_CONST(-0.9238795042), FRAC_CONST(0.3826834261) }, { FRAC_CONST(-0.9615978599), FRAC_CONST(0.2744622827) } },
{ { FRAC_CONST(0.9114037752), FRAC_CONST(-0.4115132093) }, { FRAC_CONST(0.3826834261), FRAC_CONST(-0.9238795042) }, { FRAC_CONST(-0.6879743338), FRAC_CONST(-0.7257350087) } },
{ { FRAC_CONST(0.6004192233), FRAC_CONST(0.7996854186) }, { FRAC_CONST(0.3826834261), FRAC_CONST(0.9238795042) }, { FRAC_CONST(0.3254036009), FRAC_CONST(-0.9455752373) } },
{ { FRAC_CONST(-0.6494490504), FRAC_CONST(0.7604051232) }, { FRAC_CONST(-0.9238795042), FRAC_CONST(-0.3826834261) }, { FRAC_CONST(0.9888865948), FRAC_CONST(-0.1486719251) } },
{ { FRAC_CONST(-0.8837650418), FRAC_CONST(-0.4679309726) }, { FRAC_CONST(0.9238795042), FRAC_CONST(-0.3826834261) }, { FRAC_CONST(0.5890548825), FRAC_CONST(0.8080930114) } },
{ { FRAC_CONST(0.2638743520), FRAC_CONST(-0.9645570517) }, { FRAC_CONST(-0.3826834261), FRAC_CONST(0.9238795042) }, { FRAC_CONST(-0.4441666007), FRAC_CONST(0.8959442377) } },
{ { FRAC_CONST(0.9988898039), FRAC_CONST(0.0471078083) }, { FRAC_CONST(-0.3826834261), FRAC_CONST(-0.9238795042) }, { FRAC_CONST(-0.9997915030), FRAC_CONST(0.0204183888) } },
{ { FRAC_CONST(0.1719277352), FRAC_CONST(0.9851095676) }, { FRAC_CONST(0.9238795042), FRAC_CONST(0.3826834261) }, { FRAC_CONST(-0.4803760946), FRAC_CONST(-0.8770626187) } },
{ { FRAC_CONST(-0.9238800406), FRAC_CONST(0.3826821446) }, { FRAC_CONST(-0.9238795042), FRAC_CONST(0.3826834261) }, { FRAC_CONST(0.5555707216), FRAC_CONST(-0.8314692974) } },
{ { FRAC_CONST(-0.5750041008), FRAC_CONST(-0.8181505203) }, { FRAC_CONST(0.3826834261), FRAC_CONST(-0.9238795042) }, { FRAC_CONST(0.9941320419), FRAC_CONST(0.1081734300) } }
};
static const complex_t Phi_Fract_Qmf[] = {
{ FRAC_CONST(0.8181497455), FRAC_CONST(0.5750052333) },
{ FRAC_CONST(-0.2638730407), FRAC_CONST(0.9645574093) },
{ FRAC_CONST(-0.9969173074), FRAC_CONST(0.0784590989) },
{ FRAC_CONST(-0.4115143716), FRAC_CONST(-0.9114032984) },
{ FRAC_CONST(0.7181262970), FRAC_CONST(-0.6959127784) },
{ FRAC_CONST(0.8980275989), FRAC_CONST(0.4399391711) },
{ FRAC_CONST(-0.1097343117), FRAC_CONST(0.9939609766) },
{ FRAC_CONST(-0.9723699093), FRAC_CONST(0.2334453613) },
{ FRAC_CONST(-0.5490227938), FRAC_CONST(-0.8358073831) },
{ FRAC_CONST(0.6004202366), FRAC_CONST(-0.7996846437) },
{ FRAC_CONST(0.9557930231), FRAC_CONST(0.2940403223) },
{ FRAC_CONST(0.0471064523), FRAC_CONST(0.9988898635) },
{ FRAC_CONST(-0.9238795042), FRAC_CONST(0.3826834261) },
{ FRAC_CONST(-0.6730124950), FRAC_CONST(-0.7396311164) },
{ FRAC_CONST(0.4679298103), FRAC_CONST(-0.8837656379) },
{ FRAC_CONST(0.9900236726), FRAC_CONST(0.1409012377) },
{ FRAC_CONST(0.2027872950), FRAC_CONST(0.9792228341) },
{ FRAC_CONST(-0.8526401520), FRAC_CONST(0.5224985480) },
{ FRAC_CONST(-0.7804304361), FRAC_CONST(-0.6252426505) },
{ FRAC_CONST(0.3239174187), FRAC_CONST(-0.9460853338) },
{ FRAC_CONST(0.9998766184), FRAC_CONST(-0.0157073177) },
{ FRAC_CONST(0.3534748554), FRAC_CONST(0.9354440570) },
{ FRAC_CONST(-0.7604059577), FRAC_CONST(0.6494480371) },
{ FRAC_CONST(-0.8686315417), FRAC_CONST(-0.4954586625) },
{ FRAC_CONST(0.1719291061), FRAC_CONST(-0.9851093292) },
{ FRAC_CONST(0.9851093292), FRAC_CONST(-0.1719291061) },
{ FRAC_CONST(0.4954586625), FRAC_CONST(0.8686315417) },
{ FRAC_CONST(-0.6494480371), FRAC_CONST(0.7604059577) },
{ FRAC_CONST(-0.9354440570), FRAC_CONST(-0.3534748554) },
{ FRAC_CONST(0.0157073177), FRAC_CONST(-0.9998766184) },
{ FRAC_CONST(0.9460853338), FRAC_CONST(-0.3239174187) },
{ FRAC_CONST(0.6252426505), FRAC_CONST(0.7804304361) },
{ FRAC_CONST(-0.5224985480), FRAC_CONST(0.8526401520) },
{ FRAC_CONST(-0.9792228341), FRAC_CONST(-0.2027872950) },
{ FRAC_CONST(-0.1409012377), FRAC_CONST(-0.9900236726) },
{ FRAC_CONST(0.8837656379), FRAC_CONST(-0.4679298103) },
{ FRAC_CONST(0.7396311164), FRAC_CONST(0.6730124950) },
{ FRAC_CONST(-0.3826834261), FRAC_CONST(0.9238795042) },
{ FRAC_CONST(-0.9988898635), FRAC_CONST(-0.0471064523) },
{ FRAC_CONST(-0.2940403223), FRAC_CONST(-0.9557930231) },
{ FRAC_CONST(0.7996846437), FRAC_CONST(-0.6004202366) },
{ FRAC_CONST(0.8358073831), FRAC_CONST(0.5490227938) },
{ FRAC_CONST(-0.2334453613), FRAC_CONST(0.9723699093) },
{ FRAC_CONST(-0.9939609766), FRAC_CONST(0.1097343117) },
{ FRAC_CONST(-0.4399391711), FRAC_CONST(-0.8980275989) },
{ FRAC_CONST(0.6959127784), FRAC_CONST(-0.7181262970) },
{ FRAC_CONST(0.9114032984), FRAC_CONST(0.4115143716) },
{ FRAC_CONST(-0.0784590989), FRAC_CONST(0.9969173074) },
{ FRAC_CONST(-0.9645574093), FRAC_CONST(0.2638730407) },
{ FRAC_CONST(-0.5750052333), FRAC_CONST(-0.8181497455) },
{ FRAC_CONST(0.5750052333), FRAC_CONST(-0.8181497455) },
{ FRAC_CONST(0.9645574093), FRAC_CONST(0.2638730407) },
{ FRAC_CONST(0.0784590989), FRAC_CONST(0.9969173074) },
{ FRAC_CONST(-0.9114032984), FRAC_CONST(0.4115143716) },
{ FRAC_CONST(-0.6959127784), FRAC_CONST(-0.7181262970) },
{ FRAC_CONST(0.4399391711), FRAC_CONST(-0.8980275989) },
{ FRAC_CONST(0.9939609766), FRAC_CONST(0.1097343117) },
{ FRAC_CONST(0.2334453613), FRAC_CONST(0.9723699093) },
{ FRAC_CONST(-0.8358073831), FRAC_CONST(0.5490227938) },
{ FRAC_CONST(-0.7996846437), FRAC_CONST(-0.6004202366) },
{ FRAC_CONST(0.2940403223), FRAC_CONST(-0.9557930231) },
{ FRAC_CONST(0.9988898635), FRAC_CONST(-0.0471064523) },
{ FRAC_CONST(0.3826834261), FRAC_CONST(0.9238795042) },
{ FRAC_CONST(-0.7396311164), FRAC_CONST(0.6730124950) }
};
/* static function declarations */
static void drm_ps_sa_element(drm_ps_info *ps, bitfile *ld);
static void drm_ps_pan_element(drm_ps_info *ps, bitfile *ld);
static int8_t huff_dec(bitfile *ld, drm_ps_huff_tab huff);
uint16_t drm_ps_data(drm_ps_info *ps, bitfile *ld)
{
uint16_t bits = (uint16_t)faad_get_processed_bits(ld);
ps->drm_ps_data_available = 1;
ps->bs_enable_sa = faad_get1bit(ld);
ps->bs_enable_pan = faad_get1bit(ld);
if (ps->bs_enable_sa)
{
drm_ps_sa_element(ps, ld);
}
if (ps->bs_enable_pan)
{
drm_ps_pan_element(ps, ld);
}
bits = (uint16_t)faad_get_processed_bits(ld) - bits;
return bits;
}
static void drm_ps_sa_element(drm_ps_info *ps, bitfile *ld)
{
drm_ps_huff_tab huff;
uint8_t band;
ps->bs_sa_dt_flag = faad_get1bit(ld);
if (ps->bs_sa_dt_flag)
{
huff = t_huffman_sa;
} else {
huff = f_huffman_sa;
}
for (band = 0; band < DRM_NUM_SA_BANDS; band++)
{
ps->bs_sa_data[band] = huff_dec(ld, huff);
}
}
static void drm_ps_pan_element(drm_ps_info *ps, bitfile *ld)
{
drm_ps_huff_tab huff;
uint8_t band;
ps->bs_pan_dt_flag = faad_get1bit(ld);
if (ps->bs_pan_dt_flag)
{
huff = t_huffman_pan;
} else {
huff = f_huffman_pan;
}
for (band = 0; band < DRM_NUM_PAN_BANDS; band++)
{
ps->bs_pan_data[band] = huff_dec(ld, huff);
}
}
/* binary search huffman decoding */
static int8_t huff_dec(bitfile *ld, drm_ps_huff_tab huff)
{
uint8_t bit;
int16_t index = 0;
while (index >= 0)
{
bit = (uint8_t)faad_get1bit(ld);
index = huff[index][bit];
}
return index + 15;
}
static int8_t sa_delta_clip(drm_ps_info *ps, int8_t i)
{
if (i < 0) {
/* printf(" SAminclip %d", i); */
ps->sa_decode_error = 1;
return 0;
} else if (i > 7) {
/* printf(" SAmaxclip %d", i); */
ps->sa_decode_error = 1;
return 7;
} else
return i;
}
static int8_t pan_delta_clip(drm_ps_info *ps, int8_t i)
{
if (i < -7) {
/* printf(" PANminclip %d", i); */
ps->pan_decode_error = 1;
return -7;
} else if (i > 7) {
/* printf(" PANmaxclip %d", i); */
ps->pan_decode_error = 1;
return 7;
} else
return i;
}
static void drm_ps_delta_decode(drm_ps_info *ps)
{
uint8_t band;
if (ps->bs_enable_sa)
{
if (ps->bs_sa_dt_flag && !ps->g_last_had_sa)
{
/* wait until we get a DT frame */
ps->bs_enable_sa = 0;
} else if (ps->bs_sa_dt_flag) {
/* DT frame, we have a last frame, so we can decode */
ps->g_sa_index[0] = sa_delta_clip(ps, ps->g_prev_sa_index[0]+ps->bs_sa_data[0]);
} else {
/* DF always decodable */
ps->g_sa_index[0] = sa_delta_clip(ps,ps->bs_sa_data[0]);
}
for (band = 1; band < DRM_NUM_SA_BANDS; band++)
{
if (ps->bs_sa_dt_flag && ps->g_last_had_sa)
{
ps->g_sa_index[band] = sa_delta_clip(ps, ps->g_prev_sa_index[band] + ps->bs_sa_data[band]);
} else if (!ps->bs_sa_dt_flag) {
ps->g_sa_index[band] = sa_delta_clip(ps, ps->g_sa_index[band-1] + ps->bs_sa_data[band]);
}
}
}
/* An error during SA decoding implies PAN data will be undecodable, too */
/* Also, we don't like on/off switching in PS, so we force to last settings */
if (ps->sa_decode_error) {
ps->pan_decode_error = 1;
ps->bs_enable_pan = ps->g_last_had_pan;
ps->bs_enable_sa = ps->g_last_had_sa;
}
if (ps->bs_enable_sa)
{
if (ps->sa_decode_error) {
for (band = 0; band < DRM_NUM_SA_BANDS; band++)
{
ps->g_sa_index[band] = ps->g_last_good_sa_index[band];
}
} else {
for (band = 0; band < DRM_NUM_SA_BANDS; band++)
{
ps->g_last_good_sa_index[band] = ps->g_sa_index[band];
}
}
}
if (ps->bs_enable_pan)
{
if (ps->bs_pan_dt_flag && !ps->g_last_had_pan)
{
ps->bs_enable_pan = 0;
} else if (ps->bs_pan_dt_flag) {
ps->g_pan_index[0] = pan_delta_clip(ps, ps->g_prev_pan_index[0]+ps->bs_pan_data[0]);
} else {
ps->g_pan_index[0] = pan_delta_clip(ps, ps->bs_pan_data[0]);
}
for (band = 1; band < DRM_NUM_PAN_BANDS; band++)
{
if (ps->bs_pan_dt_flag && ps->g_last_had_pan)
{
ps->g_pan_index[band] = pan_delta_clip(ps, ps->g_prev_pan_index[band] + ps->bs_pan_data[band]);
} else if (!ps->bs_pan_dt_flag) {
ps->g_pan_index[band] = pan_delta_clip(ps, ps->g_pan_index[band-1] + ps->bs_pan_data[band]);
}
}
if (ps->pan_decode_error) {
for (band = 0; band < DRM_NUM_PAN_BANDS; band++)
{
ps->g_pan_index[band] = ps->g_last_good_pan_index[band];
}
} else {
for (band = 0; band < DRM_NUM_PAN_BANDS; band++)
{
ps->g_last_good_pan_index[band] = ps->g_pan_index[band];
}
}
}
}
static void drm_calc_sa_side_signal(drm_ps_info *ps, qmf_t X[38][64])
{
uint8_t s, b, k;
complex_t qfrac, tmp0, tmp, in, R0;
real_t peakdiff;
real_t nrg;
real_t power;
real_t transratio;
real_t new_delay_slopes[NUM_OF_LINKS];
uint8_t temp_delay_ser[NUM_OF_LINKS];
complex_t Phi_Fract;
#ifdef FIXED_POINT
uint32_t in_re, in_im;
#endif
for (b = 0; b < sa_freq_scale[DRM_NUM_SA_BANDS]; b++)
{
/* set delay indices */
for (k = 0; k < NUM_OF_LINKS; k++)
temp_delay_ser[k] = ps->delay_buf_index_ser[k];
RE(Phi_Fract) = RE(Phi_Fract_Qmf[b]);
IM(Phi_Fract) = IM(Phi_Fract_Qmf[b]);
for (s = 0; s < NUM_OF_SUBSAMPLES; s++)
{
const real_t gamma = REAL_CONST(1.5);
const real_t sigma = REAL_CONST(1.5625);
RE(in) = QMF_RE(X[s][b]);
IM(in) = QMF_IM(X[s][b]);
#ifdef FIXED_POINT
/* NOTE: all input is scaled by 2^(-5) because of fixed point QMF
* meaning that P will be scaled by 2^(-10) compared to floating point version
*/
in_re = ((abs(RE(in))+(1<<(REAL_BITS-1)))>>REAL_BITS);
in_im = ((abs(IM(in))+(1<<(REAL_BITS-1)))>>REAL_BITS);
power = in_re*in_re + in_im*in_im;
#else
power = MUL_R(RE(in),RE(in)) + MUL_R(IM(in),IM(in));
#endif
ps->peakdecay_fast[b] = MUL_F(ps->peakdecay_fast[b], peak_decay);
if (ps->peakdecay_fast[b] < power)
ps->peakdecay_fast[b] = power;
peakdiff = ps->prev_peakdiff[b];
peakdiff += MUL_F((ps->peakdecay_fast[b] - power - ps->prev_peakdiff[b]), smooth_coeff);
ps->prev_peakdiff[b] = peakdiff;
nrg = ps->prev_nrg[b];
nrg += MUL_F((power - ps->prev_nrg[b]), smooth_coeff);
ps->prev_nrg[b] = nrg;
if (MUL_R(peakdiff, gamma) <= nrg) {
transratio = sigma;
} else {
transratio = MUL_R(DIV_R(nrg, MUL_R(peakdiff, gamma)), sigma);
}
for (k = 0; k < NUM_OF_LINKS; k++)
{
new_delay_slopes[k] = MUL_F(g_decayslope[b], filter_coeff[k]);
}
RE(tmp0) = RE(ps->d_buff[0][b]);
IM(tmp0) = IM(ps->d_buff[0][b]);
RE(ps->d_buff[0][b]) = RE(ps->d_buff[1][b]);
IM(ps->d_buff[0][b]) = IM(ps->d_buff[1][b]);
RE(ps->d_buff[1][b]) = RE(in);
IM(ps->d_buff[1][b]) = IM(in);
ComplexMult(&RE(tmp), &IM(tmp), RE(tmp0), IM(tmp0), RE(Phi_Fract), IM(Phi_Fract));
RE(R0) = RE(tmp);
IM(R0) = IM(tmp);
for (k = 0; k < NUM_OF_LINKS; k++)
{
RE(qfrac) = RE(Q_Fract_allpass_Qmf[b][k]);
IM(qfrac) = IM(Q_Fract_allpass_Qmf[b][k]);
RE(tmp0) = RE(ps->d2_buff[k][temp_delay_ser[k]][b]);
IM(tmp0) = IM(ps->d2_buff[k][temp_delay_ser[k]][b]);
ComplexMult(&RE(tmp), &IM(tmp), RE(tmp0), IM(tmp0), RE(qfrac), IM(qfrac));
RE(tmp) += -MUL_F(new_delay_slopes[k], RE(R0));
IM(tmp) += -MUL_F(new_delay_slopes[k], IM(R0));
RE(ps->d2_buff[k][temp_delay_ser[k]][b]) = RE(R0) + MUL_F(new_delay_slopes[k], RE(tmp));
IM(ps->d2_buff[k][temp_delay_ser[k]][b]) = IM(R0) + MUL_F(new_delay_slopes[k], IM(tmp));
RE(R0) = RE(tmp);
IM(R0) = IM(tmp);
}
QMF_RE(ps->SA[s][b]) = MUL_R(RE(R0), transratio);
QMF_IM(ps->SA[s][b]) = MUL_R(IM(R0), transratio);
for (k = 0; k < NUM_OF_LINKS; k++)
{
if (++temp_delay_ser[k] >= delay_length[k])
temp_delay_ser[k] = 0;
}
}
}
for (k = 0; k < NUM_OF_LINKS; k++)
ps->delay_buf_index_ser[k] = temp_delay_ser[k];
}
static void drm_add_ambiance(drm_ps_info *ps, qmf_t X_left[38][64], qmf_t X_right[38][64])
{
uint8_t s, b, ifreq, qclass;
real_t sa_map[MAX_SA_BAND], sa_dir_map[MAX_SA_BAND], k_sa_map[MAX_SA_BAND], k_sa_dir_map[MAX_SA_BAND];
real_t new_dir_map, new_sa_map;
if (ps->bs_enable_sa)
{
/* Instead of dequantization and mapping, we use an inverse mapping
to look up all the values we need */
for (b = 0; b < sa_freq_scale[DRM_NUM_SA_BANDS]; b++)
{
const real_t inv_f_num_of_subsamples = FRAC_CONST(0.03333333333);
ifreq = sa_inv_freq[b];
qclass = (b != 0);
sa_map[b] = sa_quant[ps->g_prev_sa_index[ifreq]][qclass];
new_sa_map = sa_quant[ps->g_sa_index[ifreq]][qclass];
k_sa_map[b] = MUL_F(inv_f_num_of_subsamples, (new_sa_map - sa_map[b]));
sa_dir_map[b] = sa_sqrt_1_minus[ps->g_prev_sa_index[ifreq]][qclass];
new_dir_map = sa_sqrt_1_minus[ps->g_sa_index[ifreq]][qclass];
k_sa_dir_map[b] = MUL_F(inv_f_num_of_subsamples, (new_dir_map - sa_dir_map[b]));
}
for (s = 0; s < NUM_OF_SUBSAMPLES; s++)
{
for (b = 0; b < sa_freq_scale[DRM_NUM_SA_BANDS]; b++)
{
QMF_RE(X_right[s][b]) = MUL_F(QMF_RE(X_left[s][b]), sa_dir_map[b]) - MUL_F(QMF_RE(ps->SA[s][b]), sa_map[b]);
QMF_IM(X_right[s][b]) = MUL_F(QMF_IM(X_left[s][b]), sa_dir_map[b]) - MUL_F(QMF_IM(ps->SA[s][b]), sa_map[b]);
QMF_RE(X_left[s][b]) = MUL_F(QMF_RE(X_left[s][b]), sa_dir_map[b]) + MUL_F(QMF_RE(ps->SA[s][b]), sa_map[b]);
QMF_IM(X_left[s][b]) = MUL_F(QMF_IM(X_left[s][b]), sa_dir_map[b]) + MUL_F(QMF_IM(ps->SA[s][b]), sa_map[b]);
sa_map[b] += k_sa_map[b];
sa_dir_map[b] += k_sa_dir_map[b];
}
for (b = sa_freq_scale[DRM_NUM_SA_BANDS]; b < NUM_OF_QMF_CHANNELS; b++)
{
QMF_RE(X_right[s][b]) = QMF_RE(X_left[s][b]);
QMF_IM(X_right[s][b]) = QMF_IM(X_left[s][b]);
}
}
}
else {
for (s = 0; s < NUM_OF_SUBSAMPLES; s++)
{
for (b = 0; b < NUM_OF_QMF_CHANNELS; b++)
{
QMF_RE(X_right[s][b]) = QMF_RE(X_left[s][b]);
QMF_IM(X_right[s][b]) = QMF_IM(X_left[s][b]);
}
}
}
}
static void drm_add_pan(drm_ps_info *ps, qmf_t X_left[38][64], qmf_t X_right[38][64])
{
uint8_t s, b, qclass, ifreq;
real_t tmp, coeff1, coeff2;
real_t pan_base[MAX_PAN_BAND];
real_t pan_delta[MAX_PAN_BAND];
qmf_t temp_l, temp_r;
if (ps->bs_enable_pan)
{
for (b = 0; b < NUM_OF_QMF_CHANNELS; b++)
{
/* Instead of dequantization, 20->64 mapping and 2^G(x,y) we do an
inverse mapping 64->20 and look up the 2^G(x,y) values directly */
ifreq = pan_inv_freq[b];
qclass = pan_quant_class[ifreq];
if (ps->g_prev_pan_index[ifreq] >= 0)
{
pan_base[b] = pan_pow_2_pos[ps->g_prev_pan_index[ifreq]][qclass];
} else {
pan_base[b] = pan_pow_2_neg[-ps->g_prev_pan_index[ifreq]][qclass];
}
/* 2^((a-b)/30) = 2^(a/30) * 1/(2^(b/30)) */
/* a en b can be negative so we may need to inverse parts */
if (ps->g_pan_index[ifreq] >= 0)
{
if (ps->g_prev_pan_index[ifreq] >= 0)
{
pan_delta[b] = MUL_C(pan_pow_2_30_pos[ps->g_pan_index[ifreq]][qclass],
pan_pow_2_30_neg[ps->g_prev_pan_index[ifreq]][qclass]);
} else {
pan_delta[b] = MUL_C(pan_pow_2_30_pos[ps->g_pan_index[ifreq]][qclass],
pan_pow_2_30_pos[-ps->g_prev_pan_index[ifreq]][qclass]);
}
} else {
if (ps->g_prev_pan_index[ifreq] >= 0)
{
pan_delta[b] = MUL_C(pan_pow_2_30_neg[-ps->g_pan_index[ifreq]][qclass],
pan_pow_2_30_neg[ps->g_prev_pan_index[ifreq]][qclass]);
} else {
pan_delta[b] = MUL_C(pan_pow_2_30_neg[-ps->g_pan_index[ifreq]][qclass],
pan_pow_2_30_pos[-ps->g_prev_pan_index[ifreq]][qclass]);
}
}
}
for (s = 0; s < NUM_OF_SUBSAMPLES; s++)
{
/* PAN always uses all 64 channels */
for (b = 0; b < NUM_OF_QMF_CHANNELS; b++)
{
tmp = pan_base[b];
coeff2 = DIV_R(REAL_CONST(2.0), (REAL_CONST(1.0) + tmp));
coeff1 = MUL_R(coeff2, tmp);
QMF_RE(temp_l) = QMF_RE(X_left[s][b]);
QMF_IM(temp_l) = QMF_IM(X_left[s][b]);
QMF_RE(temp_r) = QMF_RE(X_right[s][b]);
QMF_IM(temp_r) = QMF_IM(X_right[s][b]);
QMF_RE(X_left[s][b]) = MUL_R(QMF_RE(temp_l), coeff1);
QMF_IM(X_left[s][b]) = MUL_R(QMF_IM(temp_l), coeff1);
QMF_RE(X_right[s][b]) = MUL_R(QMF_RE(temp_r), coeff2);
QMF_IM(X_right[s][b]) = MUL_R(QMF_IM(temp_r), coeff2);
/* 2^(a+k*b) = 2^a * 2^b * ... * 2^b */
/* ^^^^^^^^^^^^^^^ k times */
pan_base[b] = MUL_C(pan_base[b], pan_delta[b]);
}
}
}
}
drm_ps_info *drm_ps_init(void)
{
drm_ps_info *ps = (drm_ps_info*)faad_malloc(sizeof(drm_ps_info));
memset(ps, 0, sizeof(drm_ps_info));
return ps;
}
void drm_ps_free(drm_ps_info *ps)
{
faad_free(ps);
}
/* main DRM PS decoding function */
uint8_t drm_ps_decode(drm_ps_info *ps, uint8_t guess, qmf_t X_left[38][64], qmf_t X_right[38][64])
{
if (ps == NULL)
{
memcpy(X_right, X_left, sizeof(qmf_t)*30*64);
return 0;
}
if (!ps->drm_ps_data_available && !guess)
{
memcpy(X_right, X_left, sizeof(qmf_t)*30*64);
memset(ps->g_prev_sa_index, 0, sizeof(ps->g_prev_sa_index));
memset(ps->g_prev_pan_index, 0, sizeof(ps->g_prev_pan_index));
return 0;
}
/* if SBR CRC doesn't match out, we can assume decode errors to start with,
and we'll guess what the parameters should be */
if (!guess)
{
ps->sa_decode_error = 0;
ps->pan_decode_error = 0;
drm_ps_delta_decode(ps);
} else
{
ps->sa_decode_error = 1;
ps->pan_decode_error = 1;
/* don't even bother decoding */
}
ps->drm_ps_data_available = 0;
drm_calc_sa_side_signal(ps, X_left);
drm_add_ambiance(ps, X_left, X_right);
if (ps->bs_enable_sa)
{
ps->g_last_had_sa = 1;
memcpy(ps->g_prev_sa_index, ps->g_sa_index, sizeof(int8_t) * DRM_NUM_SA_BANDS);
} else {
ps->g_last_had_sa = 0;
}
if (ps->bs_enable_pan)
{
drm_add_pan(ps, X_left, X_right);
ps->g_last_had_pan = 1;
memcpy(ps->g_prev_pan_index, ps->g_pan_index, sizeof(int8_t) * DRM_NUM_PAN_BANDS);
} else {
ps->g_last_had_pan = 0;
}
return 0;
}
#endif

View File

@ -0,0 +1,100 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: drm_dec.h,v 1.8 2007/11/01 12:33:30 menno Exp $
**/
#ifndef __DRM_DEC_H__
#define __DRM_DEC_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "bits.h"
#define DRM_PARAMETRIC_STEREO 0
#define DRM_NUM_SA_BANDS 8
#define DRM_NUM_PAN_BANDS 20
#define NUM_OF_LINKS 3
#define NUM_OF_QMF_CHANNELS 64
#define NUM_OF_SUBSAMPLES 30
#define MAX_SA_BAND 46
#define MAX_PAN_BAND 64
#define MAX_DELAY 5
typedef struct
{
uint8_t drm_ps_data_available;
uint8_t bs_enable_sa;
uint8_t bs_enable_pan;
uint8_t bs_sa_dt_flag;
uint8_t bs_pan_dt_flag;
uint8_t g_last_had_sa;
uint8_t g_last_had_pan;
int8_t bs_sa_data[DRM_NUM_SA_BANDS];
int8_t bs_pan_data[DRM_NUM_PAN_BANDS];
int8_t g_sa_index[DRM_NUM_SA_BANDS];
int8_t g_pan_index[DRM_NUM_PAN_BANDS];
int8_t g_prev_sa_index[DRM_NUM_SA_BANDS];
int8_t g_prev_pan_index[DRM_NUM_PAN_BANDS];
int8_t sa_decode_error;
int8_t pan_decode_error;
int8_t g_last_good_sa_index[DRM_NUM_SA_BANDS];
int8_t g_last_good_pan_index[DRM_NUM_PAN_BANDS];
qmf_t SA[NUM_OF_SUBSAMPLES][MAX_SA_BAND];
complex_t d_buff[2][MAX_SA_BAND];
complex_t d2_buff[NUM_OF_LINKS][MAX_DELAY][MAX_SA_BAND];
uint8_t delay_buf_index_ser[NUM_OF_LINKS];
real_t prev_nrg[MAX_SA_BAND];
real_t prev_peakdiff[MAX_SA_BAND];
real_t peakdecay_fast[MAX_SA_BAND];
} drm_ps_info;
uint16_t drm_ps_data(drm_ps_info *ps, bitfile *ld);
drm_ps_info *drm_ps_init(void);
void drm_ps_free(drm_ps_info *ps);
uint8_t drm_ps_decode(drm_ps_info *ps, uint8_t guess, qmf_t X_left[38][64], qmf_t X_right[38][64]);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,70 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: error.c,v 1.33 2008/09/19 23:31:39 menno Exp $
**/
#include "common.h"
#include "error.h"
char *err_msg[] = {
"No error",
"Gain control not yet implemented",
"Pulse coding not allowed in short blocks",
"Invalid huffman codebook",
"Scalefactor out of range",
"Unable to find ADTS syncword",
"Channel coupling not yet implemented",
"Channel configuration not allowed in error resilient frame",
"Bit error in error resilient scalefactor decoding",
"Error decoding huffman scalefactor (bitstream error)",
"Error decoding huffman codeword (bitstream error)",
"Non existent huffman codebook number found",
"Invalid number of channels",
"Maximum number of bitstream elements exceeded",
"Input data buffer too small",
"Array index out of range",
"Maximum number of scalefactor bands exceeded",
"Quantised value out of range",
"LTP lag out of range",
"Invalid SBR parameter decoded",
"SBR called without being initialised",
"Unexpected channel configuration change",
"Error in program_config_element",
"First SBR frame is not the same as first AAC frame",
"Unexpected fill element with SBR data",
"Not all elements were provided with SBR data",
"LTP decoding not available",
"Output data buffer too small",
"CRC error in DRM data",
"PNS not allowed in DRM data stream",
"No standard extension payload allowed in DRM",
"PCE shall be the first element in a frame",
"Bitstream value not allowed by specification",
"MAIN prediction not initialised"
};

View File

@ -0,0 +1,44 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: error.h,v 1.27 2008/09/19 23:31:40 menno Exp $
**/
#ifndef __ERROR_H__
#define __ERROR_H__
#ifdef __cplusplus
extern "C" {
#endif
#define NUM_ERROR_MESSAGES 34
extern char *err_msg[];
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,35 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: faad.h,v 1.51 2007/11/01 12:33:29 menno Exp $
**/
/* warn people for update */
//#pragma message("please update faad2 include filename and function names!")
/* Backwards compatible link */
#include "neaacdec.h"

View File

@ -0,0 +1,406 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: filtbank.c,v 1.46 2009/01/26 23:51:15 menno Exp $
**/
#include "common.h"
#include "structs.h"
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32_WCE
#define assert(x)
#else
#include <assert.h>
#endif
#include "filtbank.h"
#include "syntax.h"
#include "kbd_win.h"
#include "sine_win.h"
#include "mdct.h"
fb_info *filter_bank_init(uint16_t frame_len)
{
uint16_t nshort = frame_len/8;
#ifdef LD_DEC
uint16_t frame_len_ld = frame_len/2;
#endif
fb_info *fb = (fb_info*)faad_malloc(sizeof(fb_info));
memset(fb, 0, sizeof(fb_info));
/* normal */
fb->mdct256 = faad_mdct_init(2*nshort);
fb->mdct2048 = faad_mdct_init(2*frame_len);
#ifdef LD_DEC
/* LD */
fb->mdct1024 = faad_mdct_init(2*frame_len_ld);
#endif
#ifdef ALLOW_SMALL_FRAMELENGTH
if (frame_len == 1024)
{
#endif
fb->long_window[0] = sine_long_1024;
fb->short_window[0] = sine_short_128;
fb->long_window[1] = kbd_long_1024;
fb->short_window[1] = kbd_short_128;
#ifdef LD_DEC
fb->ld_window[0] = sine_mid_512;
fb->ld_window[1] = ld_mid_512;
#endif
#ifdef ALLOW_SMALL_FRAMELENGTH
} else /* (frame_len == 960) */ {
fb->long_window[0] = sine_long_960;
fb->short_window[0] = sine_short_120;
fb->long_window[1] = kbd_long_960;
fb->short_window[1] = kbd_short_120;
#ifdef LD_DEC
fb->ld_window[0] = sine_mid_480;
fb->ld_window[1] = ld_mid_480;
#endif
}
#endif
return fb;
}
void filter_bank_end(fb_info *fb)
{
if (fb != NULL)
{
#ifdef PROFILE
printf("FB: %I64d cycles\n", fb->cycles);
#endif
faad_mdct_end(fb->mdct256);
faad_mdct_end(fb->mdct2048);
#ifdef LD_DEC
faad_mdct_end(fb->mdct1024);
#endif
faad_free(fb);
}
}
static INLINE void imdct_long(fb_info *fb, real_t *in_data, real_t *out_data, uint16_t len)
{
#ifdef LD_DEC
mdct_info *mdct = NULL;
switch (len)
{
case 2048:
case 1920:
mdct = fb->mdct2048;
break;
case 1024:
case 960:
mdct = fb->mdct1024;
break;
}
faad_imdct(mdct, in_data, out_data);
#else
faad_imdct(fb->mdct2048, in_data, out_data);
#endif
}
#ifdef LTP_DEC
static INLINE void mdct(fb_info *fb, real_t *in_data, real_t *out_data, uint16_t len)
{
mdct_info *mdct = NULL;
switch (len)
{
case 2048:
case 1920:
mdct = fb->mdct2048;
break;
case 256:
case 240:
mdct = fb->mdct256;
break;
#ifdef LD_DEC
case 1024:
case 960:
mdct = fb->mdct1024;
break;
#endif
}
faad_mdct(mdct, in_data, out_data);
}
#endif
void ifilter_bank(fb_info *fb, uint8_t window_sequence, uint8_t window_shape,
uint8_t window_shape_prev, real_t *freq_in,
real_t *time_out, real_t *overlap,
uint8_t object_type, uint16_t frame_len)
{
int16_t i;
ALIGN real_t transf_buf[2*1024] = {0};
const real_t *window_long = NULL;
const real_t *window_long_prev = NULL;
const real_t *window_short = NULL;
const real_t *window_short_prev = NULL;
uint16_t nlong = frame_len;
uint16_t nshort = frame_len/8;
uint16_t trans = nshort/2;
uint16_t nflat_ls = (nlong-nshort)/2;
#ifdef PROFILE
int64_t count = faad_get_ts();
#endif
/* select windows of current frame and previous frame (Sine or KBD) */
#ifdef LD_DEC
if (object_type == LD)
{
window_long = fb->ld_window[window_shape];
window_long_prev = fb->ld_window[window_shape_prev];
} else {
#endif
window_long = fb->long_window[window_shape];
window_long_prev = fb->long_window[window_shape_prev];
window_short = fb->short_window[window_shape];
window_short_prev = fb->short_window[window_shape_prev];
#ifdef LD_DEC
}
#endif
#if 0
for (i = 0; i < 1024; i++)
{
printf("%d\n", freq_in[i]);
}
#endif
#if 0
printf("%d %d\n", window_sequence, window_shape);
#endif
switch (window_sequence)
{
case ONLY_LONG_SEQUENCE:
/* perform iMDCT */
imdct_long(fb, freq_in, transf_buf, 2*nlong);
/* add second half output of previous frame to windowed output of current frame */
for (i = 0; i < nlong; i+=4)
{
time_out[i] = overlap[i] + MUL_F(transf_buf[i],window_long_prev[i]);
time_out[i+1] = overlap[i+1] + MUL_F(transf_buf[i+1],window_long_prev[i+1]);
time_out[i+2] = overlap[i+2] + MUL_F(transf_buf[i+2],window_long_prev[i+2]);
time_out[i+3] = overlap[i+3] + MUL_F(transf_buf[i+3],window_long_prev[i+3]);
}
/* window the second half and save as overlap for next frame */
for (i = 0; i < nlong; i+=4)
{
overlap[i] = MUL_F(transf_buf[nlong+i],window_long[nlong-1-i]);
overlap[i+1] = MUL_F(transf_buf[nlong+i+1],window_long[nlong-2-i]);
overlap[i+2] = MUL_F(transf_buf[nlong+i+2],window_long[nlong-3-i]);
overlap[i+3] = MUL_F(transf_buf[nlong+i+3],window_long[nlong-4-i]);
}
break;
case LONG_START_SEQUENCE:
/* perform iMDCT */
imdct_long(fb, freq_in, transf_buf, 2*nlong);
/* add second half output of previous frame to windowed output of current frame */
for (i = 0; i < nlong; i+=4)
{
time_out[i] = overlap[i] + MUL_F(transf_buf[i],window_long_prev[i]);
time_out[i+1] = overlap[i+1] + MUL_F(transf_buf[i+1],window_long_prev[i+1]);
time_out[i+2] = overlap[i+2] + MUL_F(transf_buf[i+2],window_long_prev[i+2]);
time_out[i+3] = overlap[i+3] + MUL_F(transf_buf[i+3],window_long_prev[i+3]);
}
/* window the second half and save as overlap for next frame */
/* construct second half window using padding with 1's and 0's */
for (i = 0; i < nflat_ls; i++)
overlap[i] = transf_buf[nlong+i];
for (i = 0; i < nshort; i++)
overlap[nflat_ls+i] = MUL_F(transf_buf[nlong+nflat_ls+i],window_short[nshort-i-1]);
for (i = 0; i < nflat_ls; i++)
overlap[nflat_ls+nshort+i] = 0;
break;
case EIGHT_SHORT_SEQUENCE:
/* perform iMDCT for each short block */
faad_imdct(fb->mdct256, freq_in+0*nshort, transf_buf+2*nshort*0);
faad_imdct(fb->mdct256, freq_in+1*nshort, transf_buf+2*nshort*1);
faad_imdct(fb->mdct256, freq_in+2*nshort, transf_buf+2*nshort*2);
faad_imdct(fb->mdct256, freq_in+3*nshort, transf_buf+2*nshort*3);
faad_imdct(fb->mdct256, freq_in+4*nshort, transf_buf+2*nshort*4);
faad_imdct(fb->mdct256, freq_in+5*nshort, transf_buf+2*nshort*5);
faad_imdct(fb->mdct256, freq_in+6*nshort, transf_buf+2*nshort*6);
faad_imdct(fb->mdct256, freq_in+7*nshort, transf_buf+2*nshort*7);
/* add second half output of previous frame to windowed output of current frame */
for (i = 0; i < nflat_ls; i++)
time_out[i] = overlap[i];
for(i = 0; i < nshort; i++)
{
time_out[nflat_ls+ i] = overlap[nflat_ls+ i] + MUL_F(transf_buf[nshort*0+i],window_short_prev[i]);
time_out[nflat_ls+1*nshort+i] = overlap[nflat_ls+nshort*1+i] + MUL_F(transf_buf[nshort*1+i],window_short[nshort-1-i]) + MUL_F(transf_buf[nshort*2+i],window_short[i]);
time_out[nflat_ls+2*nshort+i] = overlap[nflat_ls+nshort*2+i] + MUL_F(transf_buf[nshort*3+i],window_short[nshort-1-i]) + MUL_F(transf_buf[nshort*4+i],window_short[i]);
time_out[nflat_ls+3*nshort+i] = overlap[nflat_ls+nshort*3+i] + MUL_F(transf_buf[nshort*5+i],window_short[nshort-1-i]) + MUL_F(transf_buf[nshort*6+i],window_short[i]);
if (i < trans)
time_out[nflat_ls+4*nshort+i] = overlap[nflat_ls+nshort*4+i] + MUL_F(transf_buf[nshort*7+i],window_short[nshort-1-i]) + MUL_F(transf_buf[nshort*8+i],window_short[i]);
}
/* window the second half and save as overlap for next frame */
for(i = 0; i < nshort; i++)
{
if (i >= trans)
overlap[nflat_ls+4*nshort+i-nlong] = MUL_F(transf_buf[nshort*7+i],window_short[nshort-1-i]) + MUL_F(transf_buf[nshort*8+i],window_short[i]);
overlap[nflat_ls+5*nshort+i-nlong] = MUL_F(transf_buf[nshort*9+i],window_short[nshort-1-i]) + MUL_F(transf_buf[nshort*10+i],window_short[i]);
overlap[nflat_ls+6*nshort+i-nlong] = MUL_F(transf_buf[nshort*11+i],window_short[nshort-1-i]) + MUL_F(transf_buf[nshort*12+i],window_short[i]);
overlap[nflat_ls+7*nshort+i-nlong] = MUL_F(transf_buf[nshort*13+i],window_short[nshort-1-i]) + MUL_F(transf_buf[nshort*14+i],window_short[i]);
overlap[nflat_ls+8*nshort+i-nlong] = MUL_F(transf_buf[nshort*15+i],window_short[nshort-1-i]);
}
for (i = 0; i < nflat_ls; i++)
overlap[nflat_ls+nshort+i] = 0;
break;
case LONG_STOP_SEQUENCE:
/* perform iMDCT */
imdct_long(fb, freq_in, transf_buf, 2*nlong);
/* add second half output of previous frame to windowed output of current frame */
/* construct first half window using padding with 1's and 0's */
for (i = 0; i < nflat_ls; i++)
time_out[i] = overlap[i];
for (i = 0; i < nshort; i++)
time_out[nflat_ls+i] = overlap[nflat_ls+i] + MUL_F(transf_buf[nflat_ls+i],window_short_prev[i]);
for (i = 0; i < nflat_ls; i++)
time_out[nflat_ls+nshort+i] = overlap[nflat_ls+nshort+i] + transf_buf[nflat_ls+nshort+i];
/* window the second half and save as overlap for next frame */
for (i = 0; i < nlong; i++)
overlap[i] = MUL_F(transf_buf[nlong+i],window_long[nlong-1-i]);
break;
}
#if 0
for (i = 0; i < 1024; i++)
{
printf("%d\n", time_out[i]);
//printf("0x%.8X\n", time_out[i]);
}
#endif
#ifdef PROFILE
count = faad_get_ts() - count;
fb->cycles += count;
#endif
}
#ifdef LTP_DEC
/* only works for LTP -> no overlapping, no short blocks */
void filter_bank_ltp(fb_info *fb, uint8_t window_sequence, uint8_t window_shape,
uint8_t window_shape_prev, real_t *in_data, real_t *out_mdct,
uint8_t object_type, uint16_t frame_len)
{
int16_t i;
ALIGN real_t windowed_buf[2*1024] = {0};
const real_t *window_long = NULL;
const real_t *window_long_prev = NULL;
const real_t *window_short = NULL;
const real_t *window_short_prev = NULL;
uint16_t nlong = frame_len;
uint16_t nshort = frame_len/8;
uint16_t nflat_ls = (nlong-nshort)/2;
assert(window_sequence != EIGHT_SHORT_SEQUENCE);
#ifdef LD_DEC
if (object_type == LD)
{
window_long = fb->ld_window[window_shape];
window_long_prev = fb->ld_window[window_shape_prev];
} else {
#endif
window_long = fb->long_window[window_shape];
window_long_prev = fb->long_window[window_shape_prev];
window_short = fb->short_window[window_shape];
window_short_prev = fb->short_window[window_shape_prev];
#ifdef LD_DEC
}
#endif
switch(window_sequence)
{
case ONLY_LONG_SEQUENCE:
for (i = nlong-1; i >= 0; i--)
{
windowed_buf[i] = MUL_F(in_data[i], window_long_prev[i]);
windowed_buf[i+nlong] = MUL_F(in_data[i+nlong], window_long[nlong-1-i]);
}
mdct(fb, windowed_buf, out_mdct, 2*nlong);
break;
case LONG_START_SEQUENCE:
for (i = 0; i < nlong; i++)
windowed_buf[i] = MUL_F(in_data[i], window_long_prev[i]);
for (i = 0; i < nflat_ls; i++)
windowed_buf[i+nlong] = in_data[i+nlong];
for (i = 0; i < nshort; i++)
windowed_buf[i+nlong+nflat_ls] = MUL_F(in_data[i+nlong+nflat_ls], window_short[nshort-1-i]);
for (i = 0; i < nflat_ls; i++)
windowed_buf[i+nlong+nflat_ls+nshort] = 0;
mdct(fb, windowed_buf, out_mdct, 2*nlong);
break;
case LONG_STOP_SEQUENCE:
for (i = 0; i < nflat_ls; i++)
windowed_buf[i] = 0;
for (i = 0; i < nshort; i++)
windowed_buf[i+nflat_ls] = MUL_F(in_data[i+nflat_ls], window_short_prev[i]);
for (i = 0; i < nflat_ls; i++)
windowed_buf[i+nflat_ls+nshort] = in_data[i+nflat_ls+nshort];
for (i = 0; i < nlong; i++)
windowed_buf[i+nlong] = MUL_F(in_data[i+nlong], window_long[nlong-1-i]);
mdct(fb, windowed_buf, out_mdct, 2*nlong);
break;
}
}
#endif

View File

@ -0,0 +1,61 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: filtbank.h,v 1.27 2007/11/01 12:33:30 menno Exp $
**/
#ifndef __FILTBANK_H__
#define __FILTBANK_H__
#ifdef __cplusplus
extern "C" {
#endif
fb_info *filter_bank_init(uint16_t frame_len);
void filter_bank_end(fb_info *fb);
#ifdef LTP_DEC
void filter_bank_ltp(fb_info *fb,
uint8_t window_sequence,
uint8_t window_shape,
uint8_t window_shape_prev,
real_t *in_data,
real_t *out_mdct,
uint8_t object_type,
uint16_t frame_len);
#endif
void ifilter_bank(fb_info *fb, uint8_t window_sequence, uint8_t window_shape,
uint8_t window_shape_prev, real_t *freq_in,
real_t *time_out, real_t *overlap,
uint8_t object_type, uint16_t frame_len);
#ifdef __cplusplus
}
#endif
#endif

287
tests/Audio/libFaad/fixed.h Normal file
View File

@ -0,0 +1,287 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: fixed.h,v 1.32 2007/11/01 12:33:30 menno Exp $
**/
#ifndef __FIXED_H__
#define __FIXED_H__
#ifdef __cplusplus
extern "C" {
#endif
#if defined(_WIN32_WCE) && defined(_ARM_)
#include <cmnintrin.h>
#endif
#define COEF_BITS 28
#define COEF_PRECISION (1 << COEF_BITS)
#define REAL_BITS 14 // MAXIMUM OF 14 FOR FIXED POINT SBR
#define REAL_PRECISION (1 << REAL_BITS)
/* FRAC is the fractional only part of the fixed point number [0.0..1.0) */
#define FRAC_SIZE 32 /* frac is a 32 bit integer */
#define FRAC_BITS 31
#define FRAC_PRECISION ((uint32_t)(1 << FRAC_BITS))
#define FRAC_MAX 0x7FFFFFFF
typedef int32_t real_t;
#define REAL_CONST(A) (((A) >= 0) ? ((real_t)((A)*(REAL_PRECISION)+0.5)) : ((real_t)((A)*(REAL_PRECISION)-0.5)))
#define COEF_CONST(A) (((A) >= 0) ? ((real_t)((A)*(COEF_PRECISION)+0.5)) : ((real_t)((A)*(COEF_PRECISION)-0.5)))
#define FRAC_CONST(A) (((A) == 1.00) ? ((real_t)FRAC_MAX) : (((A) >= 0) ? ((real_t)((A)*(FRAC_PRECISION)+0.5)) : ((real_t)((A)*(FRAC_PRECISION)-0.5))))
//#define FRAC_CONST(A) (((A) >= 0) ? ((real_t)((A)*(FRAC_PRECISION)+0.5)) : ((real_t)((A)*(FRAC_PRECISION)-0.5)))
#define Q2_BITS 22
#define Q2_PRECISION (1 << Q2_BITS)
#define Q2_CONST(A) (((A) >= 0) ? ((real_t)((A)*(Q2_PRECISION)+0.5)) : ((real_t)((A)*(Q2_PRECISION)-0.5)))
#if defined(_WIN32) && !defined(_WIN32_WCE)
/* multiply with real shift */
static INLINE real_t MUL_R(real_t A, real_t B)
{
_asm {
mov eax,A
imul B
shrd eax,edx,REAL_BITS
}
}
/* multiply with coef shift */
static INLINE real_t MUL_C(real_t A, real_t B)
{
_asm {
mov eax,A
imul B
shrd eax,edx,COEF_BITS
}
}
static INLINE real_t MUL_Q2(real_t A, real_t B)
{
_asm {
mov eax,A
imul B
shrd eax,edx,Q2_BITS
}
}
static INLINE real_t MUL_SHIFT6(real_t A, real_t B)
{
_asm {
mov eax,A
imul B
shrd eax,edx,6
}
}
static INLINE real_t MUL_SHIFT23(real_t A, real_t B)
{
_asm {
mov eax,A
imul B
shrd eax,edx,23
}
}
#if 1
static INLINE real_t _MulHigh(real_t A, real_t B)
{
_asm {
mov eax,A
imul B
mov eax,edx
}
}
/* multiply with fractional shift */
static INLINE real_t MUL_F(real_t A, real_t B)
{
return _MulHigh(A,B) << (FRAC_SIZE-FRAC_BITS);
}
/* Complex multiplication */
static INLINE void ComplexMult(real_t *y1, real_t *y2,
real_t x1, real_t x2, real_t c1, real_t c2)
{
*y1 = (_MulHigh(x1, c1) + _MulHigh(x2, c2))<<(FRAC_SIZE-FRAC_BITS);
*y2 = (_MulHigh(x2, c1) - _MulHigh(x1, c2))<<(FRAC_SIZE-FRAC_BITS);
}
#else
static INLINE real_t MUL_F(real_t A, real_t B)
{
_asm {
mov eax,A
imul B
shrd eax,edx,FRAC_BITS
}
}
/* Complex multiplication */
static INLINE void ComplexMult(real_t *y1, real_t *y2,
real_t x1, real_t x2, real_t c1, real_t c2)
{
*y1 = MUL_F(x1, c1) + MUL_F(x2, c2);
*y2 = MUL_F(x2, c1) - MUL_F(x1, c2);
}
#endif
#elif defined(__GNUC__) && defined (__arm__)
/* taken from MAD */
#define arm_mul(x, y, SCALEBITS) \
({ \
uint32_t __hi; \
uint32_t __lo; \
uint32_t __result; \
asm("smull %0, %1, %3, %4\n\t" \
"movs %0, %0, lsr %5\n\t" \
"adc %2, %0, %1, lsl %6" \
: "=&r" (__lo), "=&r" (__hi), "=r" (__result) \
: "%r" (x), "r" (y), \
"M" (SCALEBITS), "M" (32 - (SCALEBITS)) \
: "cc"); \
__result; \
})
static INLINE real_t MUL_R(real_t A, real_t B)
{
return arm_mul(A, B, REAL_BITS);
}
static INLINE real_t MUL_C(real_t A, real_t B)
{
return arm_mul(A, B, COEF_BITS);
}
static INLINE real_t MUL_Q2(real_t A, real_t B)
{
return arm_mul(A, B, Q2_BITS);
}
static INLINE real_t MUL_SHIFT6(real_t A, real_t B)
{
return arm_mul(A, B, 6);
}
static INLINE real_t MUL_SHIFT23(real_t A, real_t B)
{
return arm_mul(A, B, 23);
}
static INLINE real_t _MulHigh(real_t x, real_t y)
{
uint32_t __lo;
uint32_t __hi;
asm("smull\t%0, %1, %2, %3"
: "=&r"(__lo),"=&r"(__hi)
: "%r"(x),"r"(y)
: "cc");
return __hi;
}
static INLINE real_t MUL_F(real_t A, real_t B)
{
return _MulHigh(A, B) << (FRAC_SIZE-FRAC_BITS);
}
/* Complex multiplication */
static INLINE void ComplexMult(real_t *y1, real_t *y2,
real_t x1, real_t x2, real_t c1, real_t c2)
{
int32_t tmp, yt1, yt2;
asm("smull %0, %1, %4, %6\n\t"
"smlal %0, %1, %5, %7\n\t"
"rsb %3, %4, #0\n\t"
"smull %0, %2, %5, %6\n\t"
"smlal %0, %2, %3, %7"
: "=&r" (tmp), "=&r" (yt1), "=&r" (yt2), "=r" (x1)
: "3" (x1), "r" (x2), "r" (c1), "r" (c2)
: "cc" );
*y1 = yt1 << (FRAC_SIZE-FRAC_BITS);
*y2 = yt2 << (FRAC_SIZE-FRAC_BITS);
}
#else
/* multiply with real shift */
#define MUL_R(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (REAL_BITS-1))) >> REAL_BITS)
/* multiply with coef shift */
#define MUL_C(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (COEF_BITS-1))) >> COEF_BITS)
/* multiply with fractional shift */
#if defined(_WIN32_WCE) && defined(_ARM_)
/* eVC for PocketPC has an intrinsic function that returns only the high 32 bits of a 32x32 bit multiply */
static INLINE real_t MUL_F(real_t A, real_t B)
{
return _MulHigh(A,B) << (32-FRAC_BITS);
}
#else
#ifdef __BFIN__
#define _MulHigh(X,Y) ({ int __xxo; \
asm ( \
"a1 = %2.H * %1.L (IS,M);\n\t" \
"a0 = %1.H * %2.H, a1+= %1.H * %2.L (IS,M);\n\t"\
"a1 = a1 >>> 16;\n\t" \
"%0 = (a0 += a1);\n\t" \
: "=d" (__xxo) : "d" (X), "d" (Y) : "A0","A1"); __xxo; })
#define MUL_F(X,Y) ({ int __xxo; \
asm ( \
"a1 = %2.H * %1.L (M);\n\t" \
"a0 = %1.H * %2.H, a1+= %1.H * %2.L (M);\n\t" \
"a1 = a1 >>> 16;\n\t" \
"%0 = (a0 += a1);\n\t" \
: "=d" (__xxo) : "d" (X), "d" (Y) : "A0","A1"); __xxo; })
#else
#define _MulHigh(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (FRAC_SIZE-1))) >> FRAC_SIZE)
#define MUL_F(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (FRAC_BITS-1))) >> FRAC_BITS)
#endif
#endif
#define MUL_Q2(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (Q2_BITS-1))) >> Q2_BITS)
#define MUL_SHIFT6(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (6-1))) >> 6)
#define MUL_SHIFT23(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (23-1))) >> 23)
/* Complex multiplication */
static INLINE void ComplexMult(real_t *y1, real_t *y2,
real_t x1, real_t x2, real_t c1, real_t c2)
{
*y1 = (_MulHigh(x1, c1) + _MulHigh(x2, c2))<<(FRAC_SIZE-FRAC_BITS);
*y2 = (_MulHigh(x2, c1) - _MulHigh(x1, c2))<<(FRAC_SIZE-FRAC_BITS);
}
#endif
#ifdef __cplusplus
}
#endif
#endif

432
tests/Audio/libFaad/hcr.c Normal file
View File

@ -0,0 +1,432 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: hcr.c,v 1.26 2009/01/26 23:51:15 menno Exp $
**/
#include "common.h"
#include "structs.h"
#include <stdlib.h>
#include <string.h>
#include "specrec.h"
#include "huffman.h"
/* ISO/IEC 14496-3/Amd.1
* 8.5.3.3: Huffman Codeword Reordering for AAC spectral data (HCR)
*
* HCR devides the spectral data in known fixed size segments, and
* sorts it by the importance of the data. The importance is firstly
* the (lower) position in the spectrum, and secondly the largest
* value in the used codebook.
* The most important data is written at the start of each segment
* (at known positions), the remaining data is interleaved inbetween,
* with the writing direction alternating.
* Data length is not increased.
*/
#ifdef ERROR_RESILIENCE
/* 8.5.3.3.1 Pre-sorting */
#define NUM_CB 6
#define NUM_CB_ER 22
#define MAX_CB 32
#define VCB11_FIRST 16
#define VCB11_LAST 31
static const uint8_t PreSortCB_STD[NUM_CB] =
{ 11, 9, 7, 5, 3, 1};
static const uint8_t PreSortCB_ER[NUM_CB_ER] =
{ 11, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 9, 7, 5, 3, 1};
/* 8.5.3.3.2 Derivation of segment width */
static const uint8_t maxCwLen[MAX_CB] = {0, 11, 9, 20, 16, 13, 11, 14, 12, 17, 14, 49,
0, 0, 0, 0, 14, 17, 21, 21, 25, 25, 29, 29, 29, 29, 33, 33, 33, 37, 37, 41};
#define segmentWidth(cb) min(maxCwLen[cb], ics->length_of_longest_codeword)
/* bit-twiddling helpers */
static const uint8_t S[] = {1, 2, 4, 8, 16};
static const uint32_t B[] = {0x55555555, 0x33333333, 0x0F0F0F0F, 0x00FF00FF, 0x0000FFFF};
typedef struct
{
uint8_t cb;
uint8_t decoded;
uint16_t sp_offset;
bits_t bits;
} codeword_t;
/* rewind and reverse */
/* 32 bit version */
static uint32_t rewrev_word(uint32_t v, const uint8_t len)
{
/* 32 bit reverse */
v = ((v >> S[0]) & B[0]) | ((v << S[0]) & ~B[0]);
v = ((v >> S[1]) & B[1]) | ((v << S[1]) & ~B[1]);
v = ((v >> S[2]) & B[2]) | ((v << S[2]) & ~B[2]);
v = ((v >> S[3]) & B[3]) | ((v << S[3]) & ~B[3]);
v = ((v >> S[4]) & B[4]) | ((v << S[4]) & ~B[4]);
/* shift off low bits */
v >>= (32 - len);
return v;
}
/* 64 bit version */
static void rewrev_lword(uint32_t *hi, uint32_t *lo, const uint8_t len)
{
if (len <= 32) {
*hi = 0;
*lo = rewrev_word(*lo, len);
} else
{
uint32_t t = *hi, v = *lo;
/* double 32 bit reverse */
v = ((v >> S[0]) & B[0]) | ((v << S[0]) & ~B[0]);
t = ((t >> S[0]) & B[0]) | ((t << S[0]) & ~B[0]);
v = ((v >> S[1]) & B[1]) | ((v << S[1]) & ~B[1]);
t = ((t >> S[1]) & B[1]) | ((t << S[1]) & ~B[1]);
v = ((v >> S[2]) & B[2]) | ((v << S[2]) & ~B[2]);
t = ((t >> S[2]) & B[2]) | ((t << S[2]) & ~B[2]);
v = ((v >> S[3]) & B[3]) | ((v << S[3]) & ~B[3]);
t = ((t >> S[3]) & B[3]) | ((t << S[3]) & ~B[3]);
v = ((v >> S[4]) & B[4]) | ((v << S[4]) & ~B[4]);
t = ((t >> S[4]) & B[4]) | ((t << S[4]) & ~B[4]);
/* last 32<>32 bit swap is implicit below */
/* shift off low bits (this is really only one 64 bit shift) */
*lo = (t >> (64 - len)) | (v << (len - 32));
*hi = v >> (64 - len);
}
}
/* bits_t version */
static void rewrev_bits(bits_t *bits)
{
if (bits->len == 0) return;
rewrev_lword(&bits->bufb, &bits->bufa, bits->len);
}
/* merge bits of a to b */
static void concat_bits(bits_t *b, bits_t *a)
{
uint32_t bl, bh, al, ah;
if (a->len == 0) return;
al = a->bufa;
ah = a->bufb;
if (b->len > 32)
{
/* maskoff superfluous high b bits */
bl = b->bufa;
bh = b->bufb & ((1 << (b->len-32)) - 1);
/* left shift a b->len bits */
ah = al << (b->len - 32);
al = 0;
} else {
bl = b->bufa & ((1 << (b->len)) - 1);
bh = 0;
ah = (ah << (b->len)) | (al >> (32 - b->len));
al = al << b->len;
}
/* merge */
b->bufa = bl | al;
b->bufb = bh | ah;
b->len += a->len;
}
static uint8_t is_good_cb(uint8_t this_CB, uint8_t this_sec_CB)
{
/* only want spectral data CB's */
if ((this_sec_CB > ZERO_HCB && this_sec_CB <= ESC_HCB) || (this_sec_CB >= VCB11_FIRST && this_sec_CB <= VCB11_LAST))
{
if (this_CB < ESC_HCB)
{
/* normal codebook pairs */
return ((this_sec_CB == this_CB) || (this_sec_CB == this_CB + 1));
} else
{
/* escape codebook */
return (this_sec_CB == this_CB);
}
}
return 0;
}
static void read_segment(bits_t *segment, uint8_t segwidth, bitfile *ld)
{
segment->len = segwidth;
if (segwidth > 32)
{
segment->bufb = faad_getbits(ld, segwidth - 32);
segment->bufa = faad_getbits(ld, 32);
} else {
segment->bufa = faad_getbits(ld, segwidth);
segment->bufb = 0;
}
}
static void fill_in_codeword(codeword_t *codeword, uint16_t index, uint16_t sp, uint8_t cb)
{
codeword[index].sp_offset = sp;
codeword[index].cb = cb;
codeword[index].decoded = 0;
codeword[index].bits.len = 0;
}
uint8_t reordered_spectral_data(NeAACDecStruct *hDecoder, ic_stream *ics,
bitfile *ld, int16_t *spectral_data)
{
uint16_t PCWs_done;
uint16_t numberOfSegments, numberOfSets, numberOfCodewords;
codeword_t codeword[512];
bits_t segment[512];
uint16_t sp_offset[8];
uint16_t g, i, sortloop, set, bitsread;
uint16_t bitsleft, codewordsleft;
uint8_t w_idx, sfb, this_CB, last_CB, this_sec_CB;
const uint16_t nshort = hDecoder->frameLength/8;
const uint16_t sp_data_len = ics->length_of_reordered_spectral_data;
const uint8_t *PreSortCb;
/* no data (e.g. silence) */
if (sp_data_len == 0)
return 0;
/* since there is spectral data, at least one codeword has nonzero length */
if (ics->length_of_longest_codeword == 0)
return 10;
if (sp_data_len < ics->length_of_longest_codeword)
return 10;
sp_offset[0] = 0;
for (g = 1; g < ics->num_window_groups; g++)
{
sp_offset[g] = sp_offset[g-1] + nshort*ics->window_group_length[g-1];
}
PCWs_done = 0;
numberOfSegments = 0;
numberOfCodewords = 0;
bitsread = 0;
/* VCB11 code books in use */
if (hDecoder->aacSectionDataResilienceFlag)
{
PreSortCb = PreSortCB_ER;
last_CB = NUM_CB_ER;
} else
{
PreSortCb = PreSortCB_STD;
last_CB = NUM_CB;
}
/* step 1: decode PCW's (set 0), and stuff data in easier-to-use format */
for (sortloop = 0; sortloop < last_CB; sortloop++)
{
/* select codebook to process this pass */
this_CB = PreSortCb[sortloop];
/* loop over sfbs */
for (sfb = 0; sfb < ics->max_sfb; sfb++)
{
/* loop over all in this sfb, 4 lines per loop */
for (w_idx = 0; 4*w_idx < (min(ics->swb_offset[sfb+1], ics->swb_offset_max) - ics->swb_offset[sfb]); w_idx++)
{
for(g = 0; g < ics->num_window_groups; g++)
{
for (i = 0; i < ics->num_sec[g]; i++)
{
/* check whether sfb used here is the one we want to process */
if ((ics->sect_start[g][i] <= sfb) && (ics->sect_end[g][i] > sfb))
{
/* check whether codebook used here is the one we want to process */
this_sec_CB = ics->sect_cb[g][i];
if (is_good_cb(this_CB, this_sec_CB))
{
/* precalculate some stuff */
uint16_t sect_sfb_size = ics->sect_sfb_offset[g][sfb+1] - ics->sect_sfb_offset[g][sfb];
uint8_t inc = (this_sec_CB < FIRST_PAIR_HCB) ? QUAD_LEN : PAIR_LEN;
uint16_t group_cws_count = (4*ics->window_group_length[g])/inc;
uint8_t segwidth = segmentWidth(this_sec_CB);
uint16_t cws;
/* read codewords until end of sfb or end of window group (shouldn't only 1 trigger?) */
for (cws = 0; (cws < group_cws_count) && ((cws + w_idx*group_cws_count) < sect_sfb_size); cws++)
{
uint16_t sp = sp_offset[g] + ics->sect_sfb_offset[g][sfb] + inc * (cws + w_idx*group_cws_count);
/* read and decode PCW */
if (!PCWs_done)
{
/* read in normal segments */
if (bitsread + segwidth <= sp_data_len)
{
read_segment(&segment[numberOfSegments], segwidth, ld);
bitsread += segwidth;
huffman_spectral_data_2(this_sec_CB, &segment[numberOfSegments], &spectral_data[sp]);
/* keep leftover bits */
rewrev_bits(&segment[numberOfSegments]);
numberOfSegments++;
} else {
/* remaining stuff after last segment, we unfortunately couldn't read
this in earlier because it might not fit in 64 bits. since we already
decoded (and removed) the PCW it is now guaranteed to fit */
if (bitsread < sp_data_len)
{
const uint8_t additional_bits = sp_data_len - bitsread;
read_segment(&segment[numberOfSegments], additional_bits, ld);
segment[numberOfSegments].len += segment[numberOfSegments-1].len;
rewrev_bits(&segment[numberOfSegments]);
if (segment[numberOfSegments-1].len > 32)
{
segment[numberOfSegments-1].bufb = segment[numberOfSegments].bufb +
showbits_hcr(&segment[numberOfSegments-1], segment[numberOfSegments-1].len - 32);
segment[numberOfSegments-1].bufa = segment[numberOfSegments].bufa +
showbits_hcr(&segment[numberOfSegments-1], 32);
} else {
segment[numberOfSegments-1].bufa = segment[numberOfSegments].bufa +
showbits_hcr(&segment[numberOfSegments-1], segment[numberOfSegments-1].len);
segment[numberOfSegments-1].bufb = segment[numberOfSegments].bufb;
}
segment[numberOfSegments-1].len += additional_bits;
}
bitsread = sp_data_len;
PCWs_done = 1;
fill_in_codeword(codeword, 0, sp, this_sec_CB);
}
} else {
fill_in_codeword(codeword, numberOfCodewords - numberOfSegments, sp, this_sec_CB);
}
numberOfCodewords++;
}
}
}
}
}
}
}
}
if (numberOfSegments == 0)
return 10;
numberOfSets = numberOfCodewords / numberOfSegments;
/* step 2: decode nonPCWs */
for (set = 1; set <= numberOfSets; set++)
{
uint16_t trial;
for (trial = 0; trial < numberOfSegments; trial++)
{
uint16_t codewordBase;
for (codewordBase = 0; codewordBase < numberOfSegments; codewordBase++)
{
const uint16_t segment_idx = (trial + codewordBase) % numberOfSegments;
const uint16_t codeword_idx = codewordBase + set*numberOfSegments - numberOfSegments;
/* data up */
if (codeword_idx >= numberOfCodewords - numberOfSegments) break;
if (!codeword[codeword_idx].decoded && segment[segment_idx].len > 0)
{
uint8_t tmplen;
if (codeword[codeword_idx].bits.len != 0)
concat_bits(&segment[segment_idx], &codeword[codeword_idx].bits);
tmplen = segment[segment_idx].len;
if (huffman_spectral_data_2(codeword[codeword_idx].cb, &segment[segment_idx],
&spectral_data[codeword[codeword_idx].sp_offset]) >= 0)
{
codeword[codeword_idx].decoded = 1;
} else
{
codeword[codeword_idx].bits = segment[segment_idx];
codeword[codeword_idx].bits.len = tmplen;
}
}
}
}
for (i = 0; i < numberOfSegments; i++)
rewrev_bits(&segment[i]);
}
#if 0 // Seems to give false errors
bitsleft = 0;
for (i = 0; i < numberOfSegments && !bitsleft; i++)
bitsleft += segment[i].len;
if (bitsleft) return 10;
codewordsleft = 0;
for (i = 0; (i < numberOfCodewords - numberOfSegments) && (!codewordsleft); i++)
if (!codeword[i].decoded)
codewordsleft++;
if (codewordsleft) return 10;
#endif
return 0;
}
#endif

View File

@ -0,0 +1,559 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: huffman.c,v 1.26 2007/11/01 12:33:30 menno Exp $
**/
#include "common.h"
#include "structs.h"
#include <stdlib.h>
#ifdef ANALYSIS
#include <stdio.h>
#endif
#include "bits.h"
#include "huffman.h"
#include "codebook/hcb.h"
/* static function declarations */
static INLINE void huffman_sign_bits(bitfile *ld, int16_t *sp, uint8_t len);
static INLINE int16_t huffman_getescape(bitfile *ld, int16_t sp);
static uint8_t huffman_2step_quad(uint8_t cb, bitfile *ld, int16_t *sp);
static uint8_t huffman_2step_quad_sign(uint8_t cb, bitfile *ld, int16_t *sp);
static uint8_t huffman_2step_pair(uint8_t cb, bitfile *ld, int16_t *sp);
static uint8_t huffman_2step_pair_sign(uint8_t cb, bitfile *ld, int16_t *sp);
static uint8_t huffman_binary_quad(uint8_t cb, bitfile *ld, int16_t *sp);
static uint8_t huffman_binary_quad_sign(uint8_t cb, bitfile *ld, int16_t *sp);
static uint8_t huffman_binary_pair(uint8_t cb, bitfile *ld, int16_t *sp);
static uint8_t huffman_binary_pair_sign(uint8_t cb, bitfile *ld, int16_t *sp);
static int16_t huffman_codebook(uint8_t i);
static void vcb11_check_LAV(uint8_t cb, int16_t *sp);
int8_t huffman_scale_factor(bitfile *ld)
{
uint16_t offset = 0;
while (hcb_sf[offset][1])
{
uint8_t b = faad_get1bit(ld
DEBUGVAR(1,255,"huffman_scale_factor()"));
offset += hcb_sf[offset][b];
if (offset > 240)
{
/* printf("ERROR: offset into hcb_sf = %d >240!\n", offset); */
return -1;
}
}
return hcb_sf[offset][0];
}
hcb *hcb_table[] = {
0, hcb1_1, hcb2_1, 0, hcb4_1, 0, hcb6_1, 0, hcb8_1, 0, hcb10_1, hcb11_1
};
hcb_2_quad *hcb_2_quad_table[] = {
0, hcb1_2, hcb2_2, 0, hcb4_2, 0, 0, 0, 0, 0, 0, 0
};
hcb_2_pair *hcb_2_pair_table[] = {
0, 0, 0, 0, 0, 0, hcb6_2, 0, hcb8_2, 0, hcb10_2, hcb11_2
};
hcb_bin_pair *hcb_bin_table[] = {
0, 0, 0, 0, 0, hcb5, 0, hcb7, 0, hcb9, 0, 0
};
uint8_t hcbN[] = { 0, 5, 5, 0, 5, 0, 5, 0, 5, 0, 6, 5 };
/* defines whether a huffman codebook is unsigned or not */
/* Table 4.6.2 */
uint8_t unsigned_cb[] = { 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0,
/* codebook 16 to 31 */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
};
int hcb_2_quad_table_size[] = { 0, 114, 86, 0, 185, 0, 0, 0, 0, 0, 0, 0 };
int hcb_2_pair_table_size[] = { 0, 0, 0, 0, 0, 0, 126, 0, 83, 0, 210, 373 };
int hcb_bin_table_size[] = { 0, 0, 0, 161, 0, 161, 0, 127, 0, 337, 0, 0 };
static INLINE void huffman_sign_bits(bitfile *ld, int16_t *sp, uint8_t len)
{
uint8_t i;
for (i = 0; i < len; i++)
{
if(sp[i])
{
if(faad_get1bit(ld
DEBUGVAR(1,5,"huffman_sign_bits(): sign bit")) & 1)
{
sp[i] = -sp[i];
}
}
}
}
static INLINE int16_t huffman_getescape(bitfile *ld, int16_t sp)
{
uint8_t neg, i;
int16_t j;
int16_t off;
if (sp < 0)
{
if (sp != -16)
return sp;
neg = 1;
} else {
if (sp != 16)
return sp;
neg = 0;
}
for (i = 4; ; i++)
{
if (faad_get1bit(ld
DEBUGVAR(1,6,"huffman_getescape(): escape size")) == 0)
{
break;
}
}
off = (int16_t)faad_getbits(ld, i
DEBUGVAR(1,9,"huffman_getescape(): escape"));
j = off | (1<<i);
if (neg)
j = -j;
return j;
}
static uint8_t huffman_2step_quad(uint8_t cb, bitfile *ld, int16_t *sp)
{
uint32_t cw;
uint16_t offset = 0;
uint8_t extra_bits;
cw = faad_showbits(ld, hcbN[cb]);
offset = hcb_table[cb][cw].offset;
extra_bits = hcb_table[cb][cw].extra_bits;
if (extra_bits)
{
/* we know for sure it's more than hcbN[cb] bits long */
faad_flushbits(ld, hcbN[cb]);
offset += (uint16_t)faad_showbits(ld, extra_bits);
faad_flushbits(ld, hcb_2_quad_table[cb][offset].bits - hcbN[cb]);
} else {
faad_flushbits(ld, hcb_2_quad_table[cb][offset].bits);
}
if (offset > hcb_2_quad_table_size[cb])
{
/* printf("ERROR: offset into hcb_2_quad_table = %d >%d!\n", offset,
hcb_2_quad_table_size[cb]); */
return 10;
}
sp[0] = hcb_2_quad_table[cb][offset].x;
sp[1] = hcb_2_quad_table[cb][offset].y;
sp[2] = hcb_2_quad_table[cb][offset].v;
sp[3] = hcb_2_quad_table[cb][offset].w;
return 0;
}
static uint8_t huffman_2step_quad_sign(uint8_t cb, bitfile *ld, int16_t *sp)
{
uint8_t err = huffman_2step_quad(cb, ld, sp);
huffman_sign_bits(ld, sp, QUAD_LEN);
return err;
}
static uint8_t huffman_2step_pair(uint8_t cb, bitfile *ld, int16_t *sp)
{
uint32_t cw;
uint16_t offset = 0;
uint8_t extra_bits;
cw = faad_showbits(ld, hcbN[cb]);
offset = hcb_table[cb][cw].offset;
extra_bits = hcb_table[cb][cw].extra_bits;
if (extra_bits)
{
/* we know for sure it's more than hcbN[cb] bits long */
faad_flushbits(ld, hcbN[cb]);
offset += (uint16_t)faad_showbits(ld, extra_bits);
faad_flushbits(ld, hcb_2_pair_table[cb][offset].bits - hcbN[cb]);
} else {
faad_flushbits(ld, hcb_2_pair_table[cb][offset].bits);
}
if (offset > hcb_2_pair_table_size[cb])
{
/* printf("ERROR: offset into hcb_2_pair_table = %d >%d!\n", offset,
hcb_2_pair_table_size[cb]); */
return 10;
}
sp[0] = hcb_2_pair_table[cb][offset].x;
sp[1] = hcb_2_pair_table[cb][offset].y;
return 0;
}
static uint8_t huffman_2step_pair_sign(uint8_t cb, bitfile *ld, int16_t *sp)
{
uint8_t err = huffman_2step_pair(cb, ld, sp);
huffman_sign_bits(ld, sp, PAIR_LEN);
return err;
}
static uint8_t huffman_binary_quad(uint8_t cb, bitfile *ld, int16_t *sp)
{
uint16_t offset = 0;
while (!hcb3[offset].is_leaf)
{
uint8_t b = faad_get1bit(ld
DEBUGVAR(1,255,"huffman_spectral_data():3"));
offset += hcb3[offset].data[b];
}
if (offset > hcb_bin_table_size[cb])
{
/* printf("ERROR: offset into hcb_bin_table = %d >%d!\n", offset,
hcb_bin_table_size[cb]); */
return 10;
}
sp[0] = hcb3[offset].data[0];
sp[1] = hcb3[offset].data[1];
sp[2] = hcb3[offset].data[2];
sp[3] = hcb3[offset].data[3];
return 0;
}
static uint8_t huffman_binary_quad_sign(uint8_t cb, bitfile *ld, int16_t *sp)
{
uint8_t err = huffman_binary_quad(cb, ld, sp);
huffman_sign_bits(ld, sp, QUAD_LEN);
return err;
}
static uint8_t huffman_binary_pair(uint8_t cb, bitfile *ld, int16_t *sp)
{
uint16_t offset = 0;
while (!hcb_bin_table[cb][offset].is_leaf)
{
uint8_t b = faad_get1bit(ld
DEBUGVAR(1,255,"huffman_spectral_data():9"));
offset += hcb_bin_table[cb][offset].data[b];
}
if (offset > hcb_bin_table_size[cb])
{
/* printf("ERROR: offset into hcb_bin_table = %d >%d!\n", offset,
hcb_bin_table_size[cb]); */
return 10;
}
sp[0] = hcb_bin_table[cb][offset].data[0];
sp[1] = hcb_bin_table[cb][offset].data[1];
return 0;
}
static uint8_t huffman_binary_pair_sign(uint8_t cb, bitfile *ld, int16_t *sp)
{
uint8_t err = huffman_binary_pair(cb, ld, sp);
huffman_sign_bits(ld, sp, PAIR_LEN);
return err;
}
static int16_t huffman_codebook(uint8_t i)
{
static const uint32_t data = 16428320;
if (i == 0) return (int16_t)(data >> 16) & 0xFFFF;
else return (int16_t)data & 0xFFFF;
}
static void vcb11_check_LAV(uint8_t cb, int16_t *sp)
{
static const uint16_t vcb11_LAV_tab[] = {
16, 31, 47, 63, 95, 127, 159, 191, 223,
255, 319, 383, 511, 767, 1023, 2047
};
uint16_t max = 0;
if (cb < 16 || cb > 31)
return;
max = vcb11_LAV_tab[cb - 16];
if ((abs(sp[0]) > max) || (abs(sp[1]) > max))
{
sp[0] = 0;
sp[1] = 0;
}
}
uint8_t huffman_spectral_data(uint8_t cb, bitfile *ld, int16_t *sp)
{
switch (cb)
{
case 1: /* 2-step method for data quadruples */
case 2:
return huffman_2step_quad(cb, ld, sp);
case 3: /* binary search for data quadruples */
return huffman_binary_quad_sign(cb, ld, sp);
case 4: /* 2-step method for data quadruples */
return huffman_2step_quad_sign(cb, ld, sp);
case 5: /* binary search for data pairs */
return huffman_binary_pair(cb, ld, sp);
case 6: /* 2-step method for data pairs */
return huffman_2step_pair(cb, ld, sp);
case 7: /* binary search for data pairs */
case 9:
return huffman_binary_pair_sign(cb, ld, sp);
case 8: /* 2-step method for data pairs */
case 10:
return huffman_2step_pair_sign(cb, ld, sp);
case 12: {
uint8_t err = huffman_2step_pair(11, ld, sp);
sp[0] = huffman_codebook(0); sp[1] = huffman_codebook(1);
return err; }
case 11:
{
uint8_t err = huffman_2step_pair_sign(11, ld, sp);
sp[0] = huffman_getescape(ld, sp[0]);
sp[1] = huffman_getescape(ld, sp[1]);
return err;
}
#ifdef ERROR_RESILIENCE
/* VCB11 uses codebook 11 */
case 16: case 17: case 18: case 19: case 20: case 21: case 22: case 23:
case 24: case 25: case 26: case 27: case 28: case 29: case 30: case 31:
{
uint8_t err = huffman_2step_pair_sign(11, ld, sp);
sp[0] = huffman_getescape(ld, sp[0]);
sp[1] = huffman_getescape(ld, sp[1]);
/* check LAV (Largest Absolute Value) */
/* this finds errors in the ESCAPE signal */
vcb11_check_LAV(cb, sp);
return err;
}
#endif
default:
/* Non existent codebook number, something went wrong */
return 11;
}
return 0;
}
#ifdef ERROR_RESILIENCE
/* Special version of huffman_spectral_data
Will not read from a bitfile but a bits_t structure.
Will keep track of the bits decoded and return the number of bits remaining.
Do not read more than ld->len, return -1 if codeword would be longer */
int8_t huffman_spectral_data_2(uint8_t cb, bits_t *ld, int16_t *sp)
{
uint32_t cw;
uint16_t offset = 0;
uint8_t extra_bits;
uint8_t i, vcb11 = 0;
switch (cb)
{
case 1: /* 2-step method for data quadruples */
case 2:
case 4:
cw = showbits_hcr(ld, hcbN[cb]);
offset = hcb_table[cb][cw].offset;
extra_bits = hcb_table[cb][cw].extra_bits;
if (extra_bits)
{
/* we know for sure it's more than hcbN[cb] bits long */
if ( flushbits_hcr(ld, hcbN[cb]) ) return -1;
offset += (uint16_t)showbits_hcr(ld, extra_bits);
if ( flushbits_hcr(ld, hcb_2_quad_table[cb][offset].bits - hcbN[cb]) ) return -1;
} else {
if ( flushbits_hcr(ld, hcb_2_quad_table[cb][offset].bits) ) return -1;
}
sp[0] = hcb_2_quad_table[cb][offset].x;
sp[1] = hcb_2_quad_table[cb][offset].y;
sp[2] = hcb_2_quad_table[cb][offset].v;
sp[3] = hcb_2_quad_table[cb][offset].w;
break;
case 6: /* 2-step method for data pairs */
case 8:
case 10:
case 11:
/* VCB11 uses codebook 11 */
case 16: case 17: case 18: case 19: case 20: case 21: case 22: case 23:
case 24: case 25: case 26: case 27: case 28: case 29: case 30: case 31:
if (cb >= 16)
{
/* store the virtual codebook */
vcb11 = cb;
cb = 11;
}
cw = showbits_hcr(ld, hcbN[cb]);
offset = hcb_table[cb][cw].offset;
extra_bits = hcb_table[cb][cw].extra_bits;
if (extra_bits)
{
/* we know for sure it's more than hcbN[cb] bits long */
if ( flushbits_hcr(ld, hcbN[cb]) ) return -1;
offset += (uint16_t)showbits_hcr(ld, extra_bits);
if ( flushbits_hcr(ld, hcb_2_pair_table[cb][offset].bits - hcbN[cb]) ) return -1;
} else {
if ( flushbits_hcr(ld, hcb_2_pair_table[cb][offset].bits) ) return -1;
}
sp[0] = hcb_2_pair_table[cb][offset].x;
sp[1] = hcb_2_pair_table[cb][offset].y;
break;
case 3: /* binary search for data quadruples */
while (!hcb3[offset].is_leaf)
{
uint8_t b;
if ( get1bit_hcr(ld, &b) ) return -1;
offset += hcb3[offset].data[b];
}
sp[0] = hcb3[offset].data[0];
sp[1] = hcb3[offset].data[1];
sp[2] = hcb3[offset].data[2];
sp[3] = hcb3[offset].data[3];
break;
case 5: /* binary search for data pairs */
case 7:
case 9:
while (!hcb_bin_table[cb][offset].is_leaf)
{
uint8_t b;
if (get1bit_hcr(ld, &b) ) return -1;
offset += hcb_bin_table[cb][offset].data[b];
}
sp[0] = hcb_bin_table[cb][offset].data[0];
sp[1] = hcb_bin_table[cb][offset].data[1];
break;
}
/* decode sign bits */
if (unsigned_cb[cb])
{
for(i = 0; i < ((cb < FIRST_PAIR_HCB) ? QUAD_LEN : PAIR_LEN); i++)
{
if(sp[i])
{
uint8_t b;
if ( get1bit_hcr(ld, &b) ) return -1;
if (b != 0) {
sp[i] = -sp[i];
}
}
}
}
/* decode huffman escape bits */
if ((cb == ESC_HCB) || (cb >= 16))
{
uint8_t k;
for (k = 0; k < 2; k++)
{
if ((sp[k] == 16) || (sp[k] == -16))
{
uint8_t neg, i;
int32_t j;
uint32_t off;
neg = (sp[k] < 0) ? 1 : 0;
for (i = 4; ; i++)
{
uint8_t b;
if (get1bit_hcr(ld, &b))
return -1;
if (b == 0)
break;
}
if (getbits_hcr(ld, i, &off))
return -1;
j = off + (1<<i);
sp[k] = (int16_t)((neg) ? -j : j);
}
}
if (vcb11 != 0)
{
/* check LAV (Largest Absolute Value) */
/* this finds errors in the ESCAPE signal */
vcb11_check_LAV(vcb11, sp);
}
}
return ld->len;
}
#endif

View File

@ -0,0 +1,47 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: huffman.h,v 1.28 2007/11/01 12:33:30 menno Exp $
**/
#ifndef __HUFFMAN_H__
#define __HUFFMAN_H__
#ifdef __cplusplus
extern "C" {
#endif
int8_t huffman_scale_factor(bitfile *ld);
uint8_t huffman_spectral_data(uint8_t cb, bitfile *ld, int16_t *sp);
#ifdef ERROR_RESILIENCE
int8_t huffman_spectral_data_2(uint8_t cb, bits_t *ld, int16_t *sp);
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,271 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: ic_predict.c,v 1.28 2007/11/01 12:33:31 menno Exp $
**/
#include "common.h"
#include "structs.h"
#ifdef MAIN_DEC
#include "syntax.h"
#include "ic_predict.h"
#include "pns.h"
static void flt_round(float32_t *pf)
{
int32_t flg;
uint32_t tmp, tmp1, tmp2;
tmp = *(uint32_t*)pf;
flg = tmp & (uint32_t)0x00008000;
tmp &= (uint32_t)0xffff0000;
tmp1 = tmp;
/* round 1/2 lsb toward infinity */
if (flg)
{
tmp &= (uint32_t)0xff800000; /* extract exponent and sign */
tmp |= (uint32_t)0x00010000; /* insert 1 lsb */
tmp2 = tmp; /* add 1 lsb and elided one */
tmp &= (uint32_t)0xff800000; /* extract exponent and sign */
*pf = *(float32_t*)&tmp1 + *(float32_t*)&tmp2 - *(float32_t*)&tmp;
} else {
*pf = *(float32_t*)&tmp;
}
}
static int16_t quant_pred(float32_t x)
{
int16_t q;
uint32_t *tmp = (uint32_t*)&x;
q = (int16_t)(*tmp>>16);
return q;
}
static float32_t inv_quant_pred(int16_t q)
{
float32_t x;
uint32_t *tmp = (uint32_t*)&x;
*tmp = ((uint32_t)q)<<16;
return x;
}
static void ic_predict(pred_state *state, real_t input, real_t *output, uint8_t pred)
{
uint16_t tmp;
int16_t i, j;
real_t dr1;
float32_t predictedvalue;
real_t e0, e1;
real_t k1, k2;
real_t r[2];
real_t COR[2];
real_t VAR[2];
r[0] = inv_quant_pred(state->r[0]);
r[1] = inv_quant_pred(state->r[1]);
COR[0] = inv_quant_pred(state->COR[0]);
COR[1] = inv_quant_pred(state->COR[1]);
VAR[0] = inv_quant_pred(state->VAR[0]);
VAR[1] = inv_quant_pred(state->VAR[1]);
#if 1
tmp = state->VAR[0];
j = (tmp >> 7);
i = tmp & 0x7f;
if (j >= 128)
{
j -= 128;
k1 = COR[0] * exp_table[j] * mnt_table[i];
} else {
k1 = REAL_CONST(0);
}
#else
{
#define B 0.953125
real_t c = COR[0];
real_t v = VAR[0];
float32_t tmp;
if (c == 0 || v <= 1)
{
k1 = 0;
} else {
tmp = B / v;
flt_round(&tmp);
k1 = c * tmp;
}
}
#endif
if (pred)
{
#if 1
tmp = state->VAR[1];
j = (tmp >> 7);
i = tmp & 0x7f;
if (j >= 128)
{
j -= 128;
k2 = COR[1] * exp_table[j] * mnt_table[i];
} else {
k2 = REAL_CONST(0);
}
#else
#define B 0.953125
real_t c = COR[1];
real_t v = VAR[1];
float32_t tmp;
if (c == 0 || v <= 1)
{
k2 = 0;
} else {
tmp = B / v;
flt_round(&tmp);
k2 = c * tmp;
}
#endif
predictedvalue = k1*r[0] + k2*r[1];
flt_round(&predictedvalue);
*output = input + predictedvalue;
}
/* calculate new state data */
e0 = *output;
e1 = e0 - k1*r[0];
dr1 = k1*e0;
VAR[0] = ALPHA*VAR[0] + 0.5f * (r[0]*r[0] + e0*e0);
COR[0] = ALPHA*COR[0] + r[0]*e0;
VAR[1] = ALPHA*VAR[1] + 0.5f * (r[1]*r[1] + e1*e1);
COR[1] = ALPHA*COR[1] + r[1]*e1;
r[1] = A * (r[0]-dr1);
r[0] = A * e0;
state->r[0] = quant_pred(r[0]);
state->r[1] = quant_pred(r[1]);
state->COR[0] = quant_pred(COR[0]);
state->COR[1] = quant_pred(COR[1]);
state->VAR[0] = quant_pred(VAR[0]);
state->VAR[1] = quant_pred(VAR[1]);
}
static void reset_pred_state(pred_state *state)
{
state->r[0] = 0;
state->r[1] = 0;
state->COR[0] = 0;
state->COR[1] = 0;
state->VAR[0] = 0x3F80;
state->VAR[1] = 0x3F80;
}
void pns_reset_pred_state(ic_stream *ics, pred_state *state)
{
uint8_t sfb, g, b;
uint16_t i, offs, offs2;
/* prediction only for long blocks */
if (ics->window_sequence == EIGHT_SHORT_SEQUENCE)
return;
for (g = 0; g < ics->num_window_groups; g++)
{
for (b = 0; b < ics->window_group_length[g]; b++)
{
for (sfb = 0; sfb < ics->max_sfb; sfb++)
{
if (is_noise(ics, g, sfb))
{
offs = ics->swb_offset[sfb];
offs2 = min(ics->swb_offset[sfb+1], ics->swb_offset_max);
for (i = offs; i < offs2; i++)
reset_pred_state(&state[i]);
}
}
}
}
}
void reset_all_predictors(pred_state *state, uint16_t frame_len)
{
uint16_t i;
for (i = 0; i < frame_len; i++)
reset_pred_state(&state[i]);
}
/* intra channel prediction */
void ic_prediction(ic_stream *ics, real_t *spec, pred_state *state,
uint16_t frame_len, uint8_t sf_index)
{
uint8_t sfb;
uint16_t bin;
if (ics->window_sequence == EIGHT_SHORT_SEQUENCE)
{
reset_all_predictors(state, frame_len);
} else {
for (sfb = 0; sfb < max_pred_sfb(sf_index); sfb++)
{
uint16_t low = ics->swb_offset[sfb];
uint16_t high = min(ics->swb_offset[sfb+1], ics->swb_offset_max);
for (bin = low; bin < high; bin++)
{
ic_predict(&state[bin], spec[bin], &spec[bin],
(ics->predictor_data_present && ics->pred.prediction_used[sfb]));
}
}
if (ics->predictor_data_present)
{
if (ics->pred.predictor_reset)
{
for (bin = ics->pred.predictor_reset_group_number - 1;
bin < frame_len; bin += 30)
{
reset_pred_state(&state[bin]);
}
}
}
}
}
#endif

View File

@ -0,0 +1,252 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: ic_predict.h,v 1.23 2007/11/01 12:33:31 menno Exp $
**/
#ifdef MAIN_DEC
#ifndef __IC_PREDICT_H__
#define __IC_PREDICT_H__
#ifdef __cplusplus
extern "C" {
#endif
#define ALPHA REAL_CONST(0.90625)
#define A REAL_CONST(0.953125)
void pns_reset_pred_state(ic_stream *ics, pred_state *state);
void reset_all_predictors(pred_state *state, uint16_t frame_len);
void ic_prediction(ic_stream *ics, real_t *spec, pred_state *state,
uint16_t frame_len, uint8_t sf_index);
ALIGN static const real_t mnt_table[128] = {
COEF_CONST(0.9531250000), COEF_CONST(0.9453125000),
COEF_CONST(0.9375000000), COEF_CONST(0.9296875000),
COEF_CONST(0.9257812500), COEF_CONST(0.9179687500),
COEF_CONST(0.9101562500), COEF_CONST(0.9023437500),
COEF_CONST(0.8984375000), COEF_CONST(0.8906250000),
COEF_CONST(0.8828125000), COEF_CONST(0.8789062500),
COEF_CONST(0.8710937500), COEF_CONST(0.8671875000),
COEF_CONST(0.8593750000), COEF_CONST(0.8515625000),
COEF_CONST(0.8476562500), COEF_CONST(0.8398437500),
COEF_CONST(0.8359375000), COEF_CONST(0.8281250000),
COEF_CONST(0.8242187500), COEF_CONST(0.8203125000),
COEF_CONST(0.8125000000), COEF_CONST(0.8085937500),
COEF_CONST(0.8007812500), COEF_CONST(0.7968750000),
COEF_CONST(0.7929687500), COEF_CONST(0.7851562500),
COEF_CONST(0.7812500000), COEF_CONST(0.7773437500),
COEF_CONST(0.7734375000), COEF_CONST(0.7656250000),
COEF_CONST(0.7617187500), COEF_CONST(0.7578125000),
COEF_CONST(0.7539062500), COEF_CONST(0.7500000000),
COEF_CONST(0.7421875000), COEF_CONST(0.7382812500),
COEF_CONST(0.7343750000), COEF_CONST(0.7304687500),
COEF_CONST(0.7265625000), COEF_CONST(0.7226562500),
COEF_CONST(0.7187500000), COEF_CONST(0.7148437500),
COEF_CONST(0.7109375000), COEF_CONST(0.7070312500),
COEF_CONST(0.6992187500), COEF_CONST(0.6953125000),
COEF_CONST(0.6914062500), COEF_CONST(0.6875000000),
COEF_CONST(0.6835937500), COEF_CONST(0.6796875000),
COEF_CONST(0.6796875000), COEF_CONST(0.6757812500),
COEF_CONST(0.6718750000), COEF_CONST(0.6679687500),
COEF_CONST(0.6640625000), COEF_CONST(0.6601562500),
COEF_CONST(0.6562500000), COEF_CONST(0.6523437500),
COEF_CONST(0.6484375000), COEF_CONST(0.6445312500),
COEF_CONST(0.6406250000), COEF_CONST(0.6406250000),
COEF_CONST(0.6367187500), COEF_CONST(0.6328125000),
COEF_CONST(0.6289062500), COEF_CONST(0.6250000000),
COEF_CONST(0.6210937500), COEF_CONST(0.6210937500),
COEF_CONST(0.6171875000), COEF_CONST(0.6132812500),
COEF_CONST(0.6093750000), COEF_CONST(0.6054687500),
COEF_CONST(0.6054687500), COEF_CONST(0.6015625000),
COEF_CONST(0.5976562500), COEF_CONST(0.5937500000),
COEF_CONST(0.5937500000), COEF_CONST(0.5898437500),
COEF_CONST(0.5859375000), COEF_CONST(0.5820312500),
COEF_CONST(0.5820312500), COEF_CONST(0.5781250000),
COEF_CONST(0.5742187500), COEF_CONST(0.5742187500),
COEF_CONST(0.5703125000), COEF_CONST(0.5664062500),
COEF_CONST(0.5664062500), COEF_CONST(0.5625000000),
COEF_CONST(0.5585937500), COEF_CONST(0.5585937500),
COEF_CONST(0.5546875000), COEF_CONST(0.5507812500),
COEF_CONST(0.5507812500), COEF_CONST(0.5468750000),
COEF_CONST(0.5429687500), COEF_CONST(0.5429687500),
COEF_CONST(0.5390625000), COEF_CONST(0.5390625000),
COEF_CONST(0.5351562500), COEF_CONST(0.5312500000),
COEF_CONST(0.5312500000), COEF_CONST(0.5273437500),
COEF_CONST(0.5273437500), COEF_CONST(0.5234375000),
COEF_CONST(0.5195312500), COEF_CONST(0.5195312500),
COEF_CONST(0.5156250000), COEF_CONST(0.5156250000),
COEF_CONST(0.5117187500), COEF_CONST(0.5117187500),
COEF_CONST(0.5078125000), COEF_CONST(0.5078125000),
COEF_CONST(0.5039062500), COEF_CONST(0.5039062500),
COEF_CONST(0.5000000000), COEF_CONST(0.4980468750),
COEF_CONST(0.4960937500), COEF_CONST(0.4941406250),
COEF_CONST(0.4921875000), COEF_CONST(0.4902343750),
COEF_CONST(0.4882812500), COEF_CONST(0.4863281250),
COEF_CONST(0.4843750000), COEF_CONST(0.4824218750),
COEF_CONST(0.4804687500), COEF_CONST(0.4785156250)
};
ALIGN static const real_t exp_table[128] = {
COEF_CONST(0.50000000000000000000000000000000000000000000000000),
COEF_CONST(0.25000000000000000000000000000000000000000000000000),
COEF_CONST(0.12500000000000000000000000000000000000000000000000),
COEF_CONST(0.06250000000000000000000000000000000000000000000000),
COEF_CONST(0.03125000000000000000000000000000000000000000000000),
COEF_CONST(0.01562500000000000000000000000000000000000000000000),
COEF_CONST(0.00781250000000000000000000000000000000000000000000),
COEF_CONST(0.00390625000000000000000000000000000000000000000000),
COEF_CONST(0.00195312500000000000000000000000000000000000000000),
COEF_CONST(0.00097656250000000000000000000000000000000000000000),
COEF_CONST(0.00048828125000000000000000000000000000000000000000),
COEF_CONST(0.00024414062500000000000000000000000000000000000000),
COEF_CONST(0.00012207031250000000000000000000000000000000000000),
COEF_CONST(0.00006103515625000000000000000000000000000000000000),
COEF_CONST(0.00003051757812500000000000000000000000000000000000),
COEF_CONST(0.00001525878906250000000000000000000000000000000000),
COEF_CONST(0.00000762939453125000000000000000000000000000000000),
COEF_CONST(0.00000381469726562500000000000000000000000000000000),
COEF_CONST(0.00000190734863281250000000000000000000000000000000),
COEF_CONST(0.00000095367431640625000000000000000000000000000000),
COEF_CONST(0.00000047683715820312500000000000000000000000000000),
COEF_CONST(0.00000023841857910156250000000000000000000000000000),
COEF_CONST(0.00000011920928955078125000000000000000000000000000),
COEF_CONST(0.00000005960464477539062500000000000000000000000000),
COEF_CONST(0.00000002980232238769531300000000000000000000000000),
COEF_CONST(0.00000001490116119384765600000000000000000000000000),
COEF_CONST(0.00000000745058059692382810000000000000000000000000),
COEF_CONST(0.00000000372529029846191410000000000000000000000000),
COEF_CONST(0.00000000186264514923095700000000000000000000000000),
COEF_CONST(0.00000000093132257461547852000000000000000000000000),
COEF_CONST(0.00000000046566128730773926000000000000000000000000),
COEF_CONST(0.00000000023283064365386963000000000000000000000000),
COEF_CONST(0.00000000011641532182693481000000000000000000000000),
COEF_CONST(0.00000000005820766091346740700000000000000000000000),
COEF_CONST(0.00000000002910383045673370400000000000000000000000),
COEF_CONST(0.00000000001455191522836685200000000000000000000000),
COEF_CONST(0.00000000000727595761418342590000000000000000000000),
COEF_CONST(0.00000000000363797880709171300000000000000000000000),
COEF_CONST(0.00000000000181898940354585650000000000000000000000),
COEF_CONST(0.00000000000090949470177292824000000000000000000000),
COEF_CONST(0.00000000000045474735088646412000000000000000000000),
COEF_CONST(0.00000000000022737367544323206000000000000000000000),
COEF_CONST(0.00000000000011368683772161603000000000000000000000),
COEF_CONST(0.00000000000005684341886080801500000000000000000000),
COEF_CONST(0.00000000000002842170943040400700000000000000000000),
COEF_CONST(0.00000000000001421085471520200400000000000000000000),
COEF_CONST(0.00000000000000710542735760100190000000000000000000),
COEF_CONST(0.00000000000000355271367880050090000000000000000000),
COEF_CONST(0.00000000000000177635683940025050000000000000000000),
COEF_CONST(0.00000000000000088817841970012523000000000000000000),
COEF_CONST(0.00000000000000044408920985006262000000000000000000),
COEF_CONST(0.00000000000000022204460492503131000000000000000000),
COEF_CONST(0.00000000000000011102230246251565000000000000000000),
COEF_CONST(0.00000000000000005551115123125782700000000000000000),
COEF_CONST(0.00000000000000002775557561562891400000000000000000),
COEF_CONST(0.00000000000000001387778780781445700000000000000000),
COEF_CONST(0.00000000000000000693889390390722840000000000000000),
COEF_CONST(0.00000000000000000346944695195361420000000000000000),
COEF_CONST(0.00000000000000000173472347597680710000000000000000),
COEF_CONST(0.00000000000000000086736173798840355000000000000000),
COEF_CONST(0.00000000000000000043368086899420177000000000000000),
COEF_CONST(0.00000000000000000021684043449710089000000000000000),
COEF_CONST(0.00000000000000000010842021724855044000000000000000),
COEF_CONST(0.00000000000000000005421010862427522200000000000000),
COEF_CONST(0.00000000000000000002710505431213761100000000000000),
COEF_CONST(0.00000000000000000001355252715606880500000000000000),
COEF_CONST(0.00000000000000000000677626357803440270000000000000),
COEF_CONST(0.00000000000000000000338813178901720140000000000000),
COEF_CONST(0.00000000000000000000169406589450860070000000000000),
COEF_CONST(0.00000000000000000000084703294725430034000000000000),
COEF_CONST(0.00000000000000000000042351647362715017000000000000),
COEF_CONST(0.00000000000000000000021175823681357508000000000000),
COEF_CONST(0.00000000000000000000010587911840678754000000000000),
COEF_CONST(0.00000000000000000000005293955920339377100000000000),
COEF_CONST(0.00000000000000000000002646977960169688600000000000),
COEF_CONST(0.00000000000000000000001323488980084844300000000000),
COEF_CONST(0.00000000000000000000000661744490042422140000000000),
COEF_CONST(0.00000000000000000000000330872245021211070000000000),
COEF_CONST(0.00000000000000000000000165436122510605530000000000),
COEF_CONST(0.00000000000000000000000082718061255302767000000000),
COEF_CONST(0.00000000000000000000000041359030627651384000000000),
COEF_CONST(0.00000000000000000000000020679515313825692000000000),
COEF_CONST(0.00000000000000000000000010339757656912846000000000),
COEF_CONST(0.00000000000000000000000005169878828456423000000000),
COEF_CONST(0.00000000000000000000000002584939414228211500000000),
COEF_CONST(0.00000000000000000000000001292469707114105700000000),
COEF_CONST(0.00000000000000000000000000646234853557052870000000),
COEF_CONST(0.00000000000000000000000000323117426778526440000000),
COEF_CONST(0.00000000000000000000000000161558713389263220000000),
COEF_CONST(0.00000000000000000000000000080779356694631609000000),
COEF_CONST(0.00000000000000000000000000040389678347315804000000),
COEF_CONST(0.00000000000000000000000000020194839173657902000000),
COEF_CONST(0.00000000000000000000000000010097419586828951000000),
COEF_CONST(0.00000000000000000000000000005048709793414475600000),
COEF_CONST(0.00000000000000000000000000002524354896707237800000),
COEF_CONST(0.00000000000000000000000000001262177448353618900000),
COEF_CONST(0.00000000000000000000000000000631088724176809440000),
COEF_CONST(0.00000000000000000000000000000315544362088404720000),
COEF_CONST(0.00000000000000000000000000000157772181044202360000),
COEF_CONST(0.00000000000000000000000000000078886090522101181000),
COEF_CONST(0.00000000000000000000000000000039443045261050590000),
COEF_CONST(0.00000000000000000000000000000019721522630525295000),
COEF_CONST(0.00000000000000000000000000000009860761315262647600),
COEF_CONST(0.00000000000000000000000000000004930380657631323800),
COEF_CONST(0.00000000000000000000000000000002465190328815661900),
COEF_CONST(0.00000000000000000000000000000001232595164407830900),
COEF_CONST(0.00000000000000000000000000000000616297582203915470),
COEF_CONST(0.00000000000000000000000000000000308148791101957740),
COEF_CONST(0.00000000000000000000000000000000154074395550978870),
COEF_CONST(0.00000000000000000000000000000000077037197775489434),
COEF_CONST(0.00000000000000000000000000000000038518598887744717),
COEF_CONST(0.00000000000000000000000000000000019259299443872359),
COEF_CONST(0.00000000000000000000000000000000009629649721936179),
COEF_CONST(0.00000000000000000000000000000000004814824860968090),
COEF_CONST(0.00000000000000000000000000000000002407412430484045),
COEF_CONST(0.00000000000000000000000000000000001203706215242022),
COEF_CONST(0.00000000000000000000000000000000000601853107621011),
COEF_CONST(0.00000000000000000000000000000000000300926553810506),
COEF_CONST(0.00000000000000000000000000000000000150463276905253),
COEF_CONST(0.00000000000000000000000000000000000075231638452626),
COEF_CONST(0.00000000000000000000000000000000000037615819226313),
COEF_CONST(0.00000000000000000000000000000000000018807909613157),
COEF_CONST(0.00000000000000000000000000000000000009403954806578),
COEF_CONST(0.00000000000000000000000000000000000004701977403289),
COEF_CONST(0.00000000000000000000000000000000000002350988701645),
COEF_CONST(0.00000000000000000000000000000000000001175494350822),
COEF_CONST(0.0 /* 0000000000000000000000000000000000000587747175411 "floating point underflow" */),
COEF_CONST(0.0)
};
#ifdef __cplusplus
}
#endif
#endif
#endif

16458
tests/Audio/libFaad/iq_table.h Normal file

File diff suppressed because it is too large Load Diff

109
tests/Audio/libFaad/is.c Normal file
View File

@ -0,0 +1,109 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: is.c,v 1.28 2007/11/01 12:33:31 menno Exp $
**/
#include "common.h"
#include "structs.h"
#include "syntax.h"
#include "is.h"
#ifdef FIXED_POINT
static real_t pow05_table[] = {
COEF_CONST(1.68179283050743), /* 0.5^(-3/4) */
COEF_CONST(1.41421356237310), /* 0.5^(-2/4) */
COEF_CONST(1.18920711500272), /* 0.5^(-1/4) */
COEF_CONST(1.0), /* 0.5^( 0/4) */
COEF_CONST(0.84089641525371), /* 0.5^(+1/4) */
COEF_CONST(0.70710678118655), /* 0.5^(+2/4) */
COEF_CONST(0.59460355750136) /* 0.5^(+3/4) */
};
#endif
void is_decode(ic_stream *ics, ic_stream *icsr, real_t *l_spec, real_t *r_spec,
uint16_t frame_len)
{
uint8_t g, sfb, b;
uint16_t i;
#ifndef FIXED_POINT
real_t scale;
#else
int32_t exp, frac;
#endif
uint16_t nshort = frame_len/8;
uint8_t group = 0;
for (g = 0; g < icsr->num_window_groups; g++)
{
/* Do intensity stereo decoding */
for (b = 0; b < icsr->window_group_length[g]; b++)
{
for (sfb = 0; sfb < icsr->max_sfb; sfb++)
{
if (is_intensity(icsr, g, sfb))
{
#ifdef MAIN_DEC
/* For scalefactor bands coded in intensity stereo the
corresponding predictors in the right channel are
switched to "off".
*/
ics->pred.prediction_used[sfb] = 0;
icsr->pred.prediction_used[sfb] = 0;
#endif
#ifndef FIXED_POINT
scale = (real_t)pow(0.5, (0.25*icsr->scale_factors[g][sfb]));
#else
exp = icsr->scale_factors[g][sfb] >> 2;
frac = icsr->scale_factors[g][sfb] & 3;
#endif
/* Scale from left to right channel,
do not touch left channel */
for (i = icsr->swb_offset[sfb]; i < min(icsr->swb_offset[sfb+1], ics->swb_offset_max); i++)
{
#ifndef FIXED_POINT
r_spec[(group*nshort)+i] = MUL_R(l_spec[(group*nshort)+i], scale);
#else
if (exp < 0)
r_spec[(group*nshort)+i] = l_spec[(group*nshort)+i] << -exp;
else
r_spec[(group*nshort)+i] = l_spec[(group*nshort)+i] >> exp;
r_spec[(group*nshort)+i] = MUL_C(r_spec[(group*nshort)+i], pow05_table[frac + 3]);
#endif
if (is_intensity(icsr, g, sfb) != invert_intensity(ics, g, sfb))
r_spec[(group*nshort)+i] = -r_spec[(group*nshort)+i];
}
}
}
group++;
}
}
}

67
tests/Audio/libFaad/is.h Normal file
View File

@ -0,0 +1,67 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: is.h,v 1.20 2007/11/01 12:33:31 menno Exp $
**/
#ifndef __IS_H__
#define __IS_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "syntax.h"
void is_decode(ic_stream *ics, ic_stream *icsr, real_t *l_spec, real_t *r_spec,
uint16_t frame_len);
static INLINE int8_t is_intensity(ic_stream *ics, uint8_t group, uint8_t sfb)
{
switch (ics->sfb_cb[group][sfb])
{
case INTENSITY_HCB:
return 1;
case INTENSITY_HCB2:
return -1;
default:
return 0;
}
}
static INLINE int8_t invert_intensity(ic_stream *ics, uint8_t group, uint8_t sfb)
{
if (ics->ms_mask_present == 1)
return (1-2*ics->ms_used[group][sfb]);
return 1;
}
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,215 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: lt_predict.c,v 1.27 2007/11/01 12:33:31 menno Exp $
**/
#include "common.h"
#include "structs.h"
#ifdef LTP_DEC
#include <stdlib.h>
#include "syntax.h"
#include "lt_predict.h"
#include "filtbank.h"
#include "tns.h"
/* static function declarations */
static int16_t real_to_int16(real_t sig_in);
/* check if the object type is an object type that can have LTP */
uint8_t is_ltp_ot(uint8_t object_type)
{
#ifdef LTP_DEC
if ((object_type == LTP)
#ifdef ERROR_RESILIENCE
|| (object_type == ER_LTP)
#endif
#ifdef LD_DEC
|| (object_type == LD)
#endif
)
{
return 1;
}
#endif
return 0;
}
ALIGN static const real_t codebook[8] =
{
REAL_CONST(0.570829),
REAL_CONST(0.696616),
REAL_CONST(0.813004),
REAL_CONST(0.911304),
REAL_CONST(0.984900),
REAL_CONST(1.067894),
REAL_CONST(1.194601),
REAL_CONST(1.369533)
};
void lt_prediction(ic_stream *ics, ltp_info *ltp, real_t *spec,
int16_t *lt_pred_stat, fb_info *fb, uint8_t win_shape,
uint8_t win_shape_prev, uint8_t sr_index,
uint8_t object_type, uint16_t frame_len)
{
uint8_t sfb;
uint16_t bin, i, num_samples;
ALIGN real_t x_est[2048];
ALIGN real_t X_est[2048];
if (ics->window_sequence != EIGHT_SHORT_SEQUENCE)
{
if (ltp->data_present)
{
num_samples = frame_len << 1;
for(i = 0; i < num_samples; i++)
{
/* The extra lookback M (N/2 for LD, 0 for LTP) is handled
in the buffer updating */
#if 0
x_est[i] = MUL_R_C(lt_pred_stat[num_samples + i - ltp->lag],
codebook[ltp->coef]);
#else
/* lt_pred_stat is a 16 bit int, multiplied with the fixed point real
this gives a real for x_est
*/
x_est[i] = (real_t)lt_pred_stat[num_samples + i - ltp->lag] * codebook[ltp->coef];
#endif
}
filter_bank_ltp(fb, ics->window_sequence, win_shape, win_shape_prev,
x_est, X_est, object_type, frame_len);
tns_encode_frame(ics, &(ics->tns), sr_index, object_type, X_est,
frame_len);
for (sfb = 0; sfb < ltp->last_band; sfb++)
{
if (ltp->long_used[sfb])
{
uint16_t low = ics->swb_offset[sfb];
uint16_t high = min(ics->swb_offset[sfb+1], ics->swb_offset_max);
for (bin = low; bin < high; bin++)
{
spec[bin] += X_est[bin];
}
}
}
}
}
}
#ifdef FIXED_POINT
static INLINE int16_t real_to_int16(real_t sig_in)
{
if (sig_in >= 0)
{
sig_in += (1 << (REAL_BITS-1));
if (sig_in >= REAL_CONST(32768))
return 32767;
} else {
sig_in += -(1 << (REAL_BITS-1));
if (sig_in <= REAL_CONST(-32768))
return -32768;
}
return (sig_in >> REAL_BITS);
}
#else
static INLINE int16_t real_to_int16(real_t sig_in)
{
if (sig_in >= 0)
{
#ifndef HAS_LRINTF
sig_in += 0.5f;
#endif
if (sig_in >= 32768.0f)
return 32767;
} else {
#ifndef HAS_LRINTF
sig_in += -0.5f;
#endif
if (sig_in <= -32768.0f)
return -32768;
}
return lrintf(sig_in);
}
#endif
void lt_update_state(int16_t *lt_pred_stat, real_t *time, real_t *overlap,
uint16_t frame_len, uint8_t object_type)
{
uint16_t i;
/*
* The reference point for index i and the content of the buffer
* lt_pred_stat are arranged so that lt_pred_stat(0 ... N/2 - 1) contains the
* last aliased half window from the IMDCT, and lt_pred_stat(N/2 ... N-1)
* is always all zeros. The rest of lt_pred_stat (i<0) contains the previous
* fully reconstructed time domain samples, i.e., output of the decoder.
*
* These values are shifted up by N*2 to avoid (i<0)
*
* For the LD object type an extra 512 samples lookback is accomodated here.
*/
#ifdef LD_DEC
if (object_type == LD)
{
for (i = 0; i < frame_len; i++)
{
lt_pred_stat[i] /* extra 512 */ = lt_pred_stat[i + frame_len];
lt_pred_stat[frame_len + i] = lt_pred_stat[i + (frame_len * 2)];
lt_pred_stat[(frame_len * 2) + i] = real_to_int16(time[i]);
lt_pred_stat[(frame_len * 3) + i] = real_to_int16(overlap[i]);
}
} else {
#endif
for (i = 0; i < frame_len; i++)
{
lt_pred_stat[i] = lt_pred_stat[i + frame_len];
lt_pred_stat[frame_len + i] = real_to_int16(time[i]);
lt_pred_stat[(frame_len * 2) + i] = real_to_int16(overlap[i]);
#if 0 /* set to zero once upon initialisation */
lt_pred_stat[(frame_len * 3) + i] = 0;
#endif
}
#ifdef LD_DEC
}
#endif
}
#endif

View File

@ -0,0 +1,66 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: lt_predict.h,v 1.20 2007/11/01 12:33:31 menno Exp $
**/
#ifdef LTP_DEC
#ifndef __LT_PREDICT_H__
#define __LT_PREDICT_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "filtbank.h"
uint8_t is_ltp_ot(uint8_t object_type);
void lt_prediction(ic_stream *ics,
ltp_info *ltp,
real_t *spec,
int16_t *lt_pred_stat,
fb_info *fb,
uint8_t win_shape,
uint8_t win_shape_prev,
uint8_t sr_index,
uint8_t object_type,
uint16_t frame_len);
void lt_update_state(int16_t *lt_pred_stat,
real_t *time,
real_t *overlap,
uint16_t frame_len,
uint8_t object_type);
#ifdef __cplusplus
}
#endif
#endif
#endif

301
tests/Audio/libFaad/mdct.c Normal file
View File

@ -0,0 +1,301 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: mdct.c,v 1.47 2007/11/01 12:33:31 menno Exp $
**/
/*
* Fast (I)MDCT Implementation using (I)FFT ((Inverse) Fast Fourier Transform)
* and consists of three steps: pre-(I)FFT complex multiplication, complex
* (I)FFT, post-(I)FFT complex multiplication,
*
* As described in:
* P. Duhamel, Y. Mahieux, and J.P. Petit, "A Fast Algorithm for the
* Implementation of Filter Banks Based on 'Time Domain Aliasing
* Cancellation," IEEE Proc. on ICASSP91, 1991, pp. 2209-2212.
*
*
* As of April 6th 2002 completely rewritten.
* This (I)MDCT can now be used for any data size n, where n is divisible by 8.
*
*/
#include "common.h"
#include "structs.h"
#include <stdlib.h>
#ifdef _WIN32_WCE
#define assert(x)
#else
#include <assert.h>
#endif
#include "cfft.h"
#include "mdct.h"
#include "mdct_tab.h"
mdct_info *faad_mdct_init(uint16_t N)
{
mdct_info *mdct = (mdct_info*)faad_malloc(sizeof(mdct_info));
assert(N % 8 == 0);
mdct->N = N;
/* NOTE: For "small framelengths" in FIXED_POINT the coefficients need to be
* scaled by sqrt("(nearest power of 2) > N" / N) */
/* RE(mdct->sincos[k]) = scale*(real_t)(cos(2.0*M_PI*(k+1./8.) / (real_t)N));
* IM(mdct->sincos[k]) = scale*(real_t)(sin(2.0*M_PI*(k+1./8.) / (real_t)N)); */
/* scale is 1 for fixed point, sqrt(N) for floating point */
switch (N)
{
case 2048: mdct->sincos = (complex_t*)mdct_tab_2048; break;
case 256: mdct->sincos = (complex_t*)mdct_tab_256; break;
#ifdef LD_DEC
case 1024: mdct->sincos = (complex_t*)mdct_tab_1024; break;
#endif
#ifdef ALLOW_SMALL_FRAMELENGTH
case 1920: mdct->sincos = (complex_t*)mdct_tab_1920; break;
case 240: mdct->sincos = (complex_t*)mdct_tab_240; break;
#ifdef LD_DEC
case 960: mdct->sincos = (complex_t*)mdct_tab_960; break;
#endif
#endif
#ifdef SSR_DEC
case 512: mdct->sincos = (complex_t*)mdct_tab_512; break;
case 64: mdct->sincos = (complex_t*)mdct_tab_64; break;
#endif
}
/* initialise fft */
mdct->cfft = cffti(N/4);
#ifdef PROFILE
mdct->cycles = 0;
mdct->fft_cycles = 0;
#endif
return mdct;
}
void faad_mdct_end(mdct_info *mdct)
{
if (mdct != NULL)
{
#ifdef PROFILE
printf("MDCT[%.4d]: %I64d cycles\n", mdct->N, mdct->cycles);
printf("CFFT[%.4d]: %I64d cycles\n", mdct->N/4, mdct->fft_cycles);
#endif
cfftu(mdct->cfft);
faad_free(mdct);
}
}
void faad_imdct(mdct_info *mdct, real_t *X_in, real_t *X_out)
{
uint16_t k;
complex_t x;
#ifdef ALLOW_SMALL_FRAMELENGTH
#ifdef FIXED_POINT
real_t scale, b_scale = 0;
#endif
#endif
ALIGN complex_t Z1[512];
complex_t *sincos = mdct->sincos;
uint16_t N = mdct->N;
uint16_t N2 = N >> 1;
uint16_t N4 = N >> 2;
uint16_t N8 = N >> 3;
#ifdef PROFILE
int64_t count1, count2 = faad_get_ts();
#endif
#ifdef ALLOW_SMALL_FRAMELENGTH
#ifdef FIXED_POINT
/* detect non-power of 2 */
if (N & (N-1))
{
/* adjust scale for non-power of 2 MDCT */
/* 2048/1920 */
b_scale = 1;
scale = COEF_CONST(1.0666666666666667);
}
#endif
#endif
/* pre-IFFT complex multiplication */
for (k = 0; k < N4; k++)
{
ComplexMult(&IM(Z1[k]), &RE(Z1[k]),
X_in[2*k], X_in[N2 - 1 - 2*k], RE(sincos[k]), IM(sincos[k]));
}
#ifdef PROFILE
count1 = faad_get_ts();
#endif
/* complex IFFT, any non-scaling FFT can be used here */
cfftb(mdct->cfft, Z1);
#ifdef PROFILE
count1 = faad_get_ts() - count1;
#endif
/* post-IFFT complex multiplication */
for (k = 0; k < N4; k++)
{
RE(x) = RE(Z1[k]);
IM(x) = IM(Z1[k]);
ComplexMult(&IM(Z1[k]), &RE(Z1[k]),
IM(x), RE(x), RE(sincos[k]), IM(sincos[k]));
#ifdef ALLOW_SMALL_FRAMELENGTH
#ifdef FIXED_POINT
/* non-power of 2 MDCT scaling */
if (b_scale)
{
RE(Z1[k]) = MUL_C(RE(Z1[k]), scale);
IM(Z1[k]) = MUL_C(IM(Z1[k]), scale);
}
#endif
#endif
}
/* reordering */
for (k = 0; k < N8; k+=2)
{
X_out[ 2*k] = IM(Z1[N8 + k]);
X_out[ 2 + 2*k] = IM(Z1[N8 + 1 + k]);
X_out[ 1 + 2*k] = -RE(Z1[N8 - 1 - k]);
X_out[ 3 + 2*k] = -RE(Z1[N8 - 2 - k]);
X_out[N4 + 2*k] = RE(Z1[ k]);
X_out[N4 + + 2 + 2*k] = RE(Z1[ 1 + k]);
X_out[N4 + 1 + 2*k] = -IM(Z1[N4 - 1 - k]);
X_out[N4 + 3 + 2*k] = -IM(Z1[N4 - 2 - k]);
X_out[N2 + 2*k] = RE(Z1[N8 + k]);
X_out[N2 + + 2 + 2*k] = RE(Z1[N8 + 1 + k]);
X_out[N2 + 1 + 2*k] = -IM(Z1[N8 - 1 - k]);
X_out[N2 + 3 + 2*k] = -IM(Z1[N8 - 2 - k]);
X_out[N2 + N4 + 2*k] = -IM(Z1[ k]);
X_out[N2 + N4 + 2 + 2*k] = -IM(Z1[ 1 + k]);
X_out[N2 + N4 + 1 + 2*k] = RE(Z1[N4 - 1 - k]);
X_out[N2 + N4 + 3 + 2*k] = RE(Z1[N4 - 2 - k]);
}
#ifdef PROFILE
count2 = faad_get_ts() - count2;
mdct->fft_cycles += count1;
mdct->cycles += (count2 - count1);
#endif
}
#ifdef LTP_DEC
void faad_mdct(mdct_info *mdct, real_t *X_in, real_t *X_out)
{
uint16_t k;
complex_t x;
ALIGN complex_t Z1[512];
complex_t *sincos = mdct->sincos;
uint16_t N = mdct->N;
uint16_t N2 = N >> 1;
uint16_t N4 = N >> 2;
uint16_t N8 = N >> 3;
#ifndef FIXED_POINT
real_t scale = REAL_CONST(N);
#else
real_t scale = REAL_CONST(4.0/N);
#endif
#ifdef ALLOW_SMALL_FRAMELENGTH
#ifdef FIXED_POINT
/* detect non-power of 2 */
if (N & (N-1))
{
/* adjust scale for non-power of 2 MDCT */
/* *= sqrt(2048/1920) */
scale = MUL_C(scale, COEF_CONST(1.0327955589886444));
}
#endif
#endif
/* pre-FFT complex multiplication */
for (k = 0; k < N8; k++)
{
uint16_t n = k << 1;
RE(x) = X_in[N - N4 - 1 - n] + X_in[N - N4 + n];
IM(x) = X_in[ N4 + n] - X_in[ N4 - 1 - n];
ComplexMult(&RE(Z1[k]), &IM(Z1[k]),
RE(x), IM(x), RE(sincos[k]), IM(sincos[k]));
RE(Z1[k]) = MUL_R(RE(Z1[k]), scale);
IM(Z1[k]) = MUL_R(IM(Z1[k]), scale);
RE(x) = X_in[N2 - 1 - n] - X_in[ n];
IM(x) = X_in[N2 + n] + X_in[N - 1 - n];
ComplexMult(&RE(Z1[k + N8]), &IM(Z1[k + N8]),
RE(x), IM(x), RE(sincos[k + N8]), IM(sincos[k + N8]));
RE(Z1[k + N8]) = MUL_R(RE(Z1[k + N8]), scale);
IM(Z1[k + N8]) = MUL_R(IM(Z1[k + N8]), scale);
}
/* complex FFT, any non-scaling FFT can be used here */
cfftf(mdct->cfft, Z1);
/* post-FFT complex multiplication */
for (k = 0; k < N4; k++)
{
uint16_t n = k << 1;
ComplexMult(&RE(x), &IM(x),
RE(Z1[k]), IM(Z1[k]), RE(sincos[k]), IM(sincos[k]));
X_out[ n] = -RE(x);
X_out[N2 - 1 - n] = IM(x);
X_out[N2 + n] = -IM(x);
X_out[N - 1 - n] = RE(x);
}
}
#endif

View File

@ -0,0 +1,48 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: mdct.h,v 1.30 2007/11/01 12:33:31 menno Exp $
**/
#ifndef __MDCT_H__
#define __MDCT_H__
#ifdef __cplusplus
extern "C" {
#endif
mdct_info *faad_mdct_init(uint16_t N);
void faad_mdct_end(mdct_info *mdct);
void faad_imdct(mdct_info *mdct, real_t *X_in, real_t *X_out);
void faad_mdct(mdct_info *mdct, real_t *X_in, real_t *X_out);
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load Diff

309
tests/Audio/libFaad/mp4.c Normal file
View File

@ -0,0 +1,309 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: mp4.c,v 1.40 2009/02/06 03:39:58 menno Exp $
**/
#include "common.h"
#include "structs.h"
#include <stdlib.h>
#include "bits.h"
#include "mp4.h"
#include "syntax.h"
/* defines if an object type can be decoded by this library or not */
static uint8_t ObjectTypesTable[32] = {
0, /* 0 NULL */
#ifdef MAIN_DEC
1, /* 1 AAC Main */
#else
0, /* 1 AAC Main */
#endif
1, /* 2 AAC LC */
#ifdef SSR_DEC
1, /* 3 AAC SSR */
#else
0, /* 3 AAC SSR */
#endif
#ifdef LTP_DEC
1, /* 4 AAC LTP */
#else
0, /* 4 AAC LTP */
#endif
#ifdef SBR_DEC
1, /* 5 SBR */
#else
0, /* 5 SBR */
#endif
0, /* 6 AAC Scalable */
0, /* 7 TwinVQ */
0, /* 8 CELP */
0, /* 9 HVXC */
0, /* 10 Reserved */
0, /* 11 Reserved */
0, /* 12 TTSI */
0, /* 13 Main synthetic */
0, /* 14 Wavetable synthesis */
0, /* 15 General MIDI */
0, /* 16 Algorithmic Synthesis and Audio FX */
/* MPEG-4 Version 2 */
#ifdef ERROR_RESILIENCE
1, /* 17 ER AAC LC */
0, /* 18 (Reserved) */
#ifdef LTP_DEC
1, /* 19 ER AAC LTP */
#else
0, /* 19 ER AAC LTP */
#endif
0, /* 20 ER AAC scalable */
0, /* 21 ER TwinVQ */
0, /* 22 ER BSAC */
#ifdef LD_DEC
1, /* 23 ER AAC LD */
#else
0, /* 23 ER AAC LD */
#endif
0, /* 24 ER CELP */
0, /* 25 ER HVXC */
0, /* 26 ER HILN */
0, /* 27 ER Parametric */
#else /* No ER defined */
0, /* 17 ER AAC LC */
0, /* 18 (Reserved) */
0, /* 19 ER AAC LTP */
0, /* 20 ER AAC scalable */
0, /* 21 ER TwinVQ */
0, /* 22 ER BSAC */
0, /* 23 ER AAC LD */
0, /* 24 ER CELP */
0, /* 25 ER HVXC */
0, /* 26 ER HILN */
0, /* 27 ER Parametric */
#endif
0, /* 28 (Reserved) */
0, /* 29 (Reserved) */
0, /* 30 (Reserved) */
0 /* 31 (Reserved) */
};
/* Table 1.6.1 */
char NEAACDECAPI NeAACDecAudioSpecificConfig(unsigned char *pBuffer,
unsigned long buffer_size,
mp4AudioSpecificConfig *mp4ASC)
{
return AudioSpecificConfig2(pBuffer, buffer_size, mp4ASC, NULL, 0);
}
int8_t AudioSpecificConfigFromBitfile(bitfile *ld,
mp4AudioSpecificConfig *mp4ASC,
program_config *pce, uint32_t buffer_size, uint8_t short_form)
{
int8_t result = 0;
uint32_t startpos = faad_get_processed_bits(ld);
#ifdef SBR_DEC
int8_t bits_to_decode = 0;
#endif
if (mp4ASC == NULL)
return -8;
memset(mp4ASC, 0, sizeof(mp4AudioSpecificConfig));
mp4ASC->objectTypeIndex = (uint8_t)faad_getbits(ld, 5
DEBUGVAR(1,1,"parse_audio_decoder_specific_info(): ObjectTypeIndex"));
mp4ASC->samplingFrequencyIndex = (uint8_t)faad_getbits(ld, 4
DEBUGVAR(1,2,"parse_audio_decoder_specific_info(): SamplingFrequencyIndex"));
if(mp4ASC->samplingFrequencyIndex==0x0f)
faad_getbits(ld, 24);
mp4ASC->channelsConfiguration = (uint8_t)faad_getbits(ld, 4
DEBUGVAR(1,3,"parse_audio_decoder_specific_info(): ChannelsConfiguration"));
mp4ASC->samplingFrequency = get_sample_rate(mp4ASC->samplingFrequencyIndex);
if (ObjectTypesTable[mp4ASC->objectTypeIndex] != 1)
{
return -1;
}
if (mp4ASC->samplingFrequency == 0)
{
return -2;
}
if (mp4ASC->channelsConfiguration > 7)
{
return -3;
}
#if (defined(PS_DEC) || defined(DRM_PS))
/* check if we have a mono file */
if (mp4ASC->channelsConfiguration == 1)
{
/* upMatrix to 2 channels for implicit signalling of PS */
mp4ASC->channelsConfiguration = 2;
}
#endif
#ifdef SBR_DEC
mp4ASC->sbr_present_flag = -1;
if (mp4ASC->objectTypeIndex == 5)
{
uint8_t tmp;
mp4ASC->sbr_present_flag = 1;
tmp = (uint8_t)faad_getbits(ld, 4
DEBUGVAR(1,5,"parse_audio_decoder_specific_info(): extensionSamplingFrequencyIndex"));
/* check for downsampled SBR */
if (tmp == mp4ASC->samplingFrequencyIndex)
mp4ASC->downSampledSBR = 1;
mp4ASC->samplingFrequencyIndex = tmp;
if (mp4ASC->samplingFrequencyIndex == 15)
{
mp4ASC->samplingFrequency = (uint32_t)faad_getbits(ld, 24
DEBUGVAR(1,6,"parse_audio_decoder_specific_info(): extensionSamplingFrequencyIndex"));
} else {
mp4ASC->samplingFrequency = get_sample_rate(mp4ASC->samplingFrequencyIndex);
}
mp4ASC->objectTypeIndex = (uint8_t)faad_getbits(ld, 5
DEBUGVAR(1,7,"parse_audio_decoder_specific_info(): ObjectTypeIndex"));
}
#endif
/* get GASpecificConfig */
if (mp4ASC->objectTypeIndex == 1 || mp4ASC->objectTypeIndex == 2 ||
mp4ASC->objectTypeIndex == 3 || mp4ASC->objectTypeIndex == 4 ||
mp4ASC->objectTypeIndex == 6 || mp4ASC->objectTypeIndex == 7)
{
result = GASpecificConfig(ld, mp4ASC, pce);
#ifdef ERROR_RESILIENCE
} else if (mp4ASC->objectTypeIndex >= ER_OBJECT_START) { /* ER */
result = GASpecificConfig(ld, mp4ASC, pce);
mp4ASC->epConfig = (uint8_t)faad_getbits(ld, 2
DEBUGVAR(1,143,"parse_audio_decoder_specific_info(): epConfig"));
if (mp4ASC->epConfig != 0)
result = -5;
#endif
} else {
result = -4;
}
#ifdef SSR_DEC
/* shorter frames not allowed for SSR */
if ((mp4ASC->objectTypeIndex == 4) && mp4ASC->frameLengthFlag)
return -6;
#endif
#ifdef SBR_DEC
if(short_form)
bits_to_decode = 0;
else
bits_to_decode = (int8_t)(buffer_size*8 - (startpos-faad_get_processed_bits(ld)));
if ((mp4ASC->objectTypeIndex != 5) && (bits_to_decode >= 16))
{
int16_t syncExtensionType = (int16_t)faad_getbits(ld, 11
DEBUGVAR(1,9,"parse_audio_decoder_specific_info(): syncExtensionType"));
if (syncExtensionType == 0x2b7)
{
uint8_t tmp_OTi = (uint8_t)faad_getbits(ld, 5
DEBUGVAR(1,10,"parse_audio_decoder_specific_info(): extensionAudioObjectType"));
if (tmp_OTi == 5)
{
mp4ASC->sbr_present_flag = (uint8_t)faad_get1bit(ld
DEBUGVAR(1,11,"parse_audio_decoder_specific_info(): sbr_present_flag"));
if (mp4ASC->sbr_present_flag)
{
uint8_t tmp;
/* Don't set OT to SBR until checked that it is actually there */
mp4ASC->objectTypeIndex = tmp_OTi;
tmp = (uint8_t)faad_getbits(ld, 4
DEBUGVAR(1,12,"parse_audio_decoder_specific_info(): extensionSamplingFrequencyIndex"));
/* check for downsampled SBR */
if (tmp == mp4ASC->samplingFrequencyIndex)
mp4ASC->downSampledSBR = 1;
mp4ASC->samplingFrequencyIndex = tmp;
if (mp4ASC->samplingFrequencyIndex == 15)
{
mp4ASC->samplingFrequency = (uint32_t)faad_getbits(ld, 24
DEBUGVAR(1,13,"parse_audio_decoder_specific_info(): extensionSamplingFrequencyIndex"));
} else {
mp4ASC->samplingFrequency = get_sample_rate(mp4ASC->samplingFrequencyIndex);
}
}
}
}
}
/* no SBR signalled, this could mean either implicit signalling or no SBR in this file */
/* MPEG specification states: assume SBR on files with samplerate <= 24000 Hz */
if (mp4ASC->sbr_present_flag == -1)
{
if (mp4ASC->samplingFrequency <= 24000)
{
mp4ASC->samplingFrequency *= 2;
mp4ASC->forceUpSampling = 1;
} else /* > 24000*/ {
mp4ASC->downSampledSBR = 1;
}
}
#endif
faad_endbits(ld);
return result;
}
int8_t AudioSpecificConfig2(uint8_t *pBuffer,
uint32_t buffer_size,
mp4AudioSpecificConfig *mp4ASC,
program_config *pce,
uint8_t short_form)
{
uint8_t ret = 0;
bitfile ld;
faad_initbits(&ld, pBuffer, buffer_size);
faad_byte_align(&ld);
ret = AudioSpecificConfigFromBitfile(&ld, mp4ASC, pce, buffer_size, short_form);
faad_endbits(&ld);
return ret;
}

52
tests/Audio/libFaad/mp4.h Normal file
View File

@ -0,0 +1,52 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: mp4.h,v 1.28 2009/02/05 00:51:03 menno Exp $
**/
#ifndef __MP4_H__
#define __MP4_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "neaacdec.h"
int8_t AudioSpecificConfig2(uint8_t *pBuffer,
uint32_t buffer_size,
mp4AudioSpecificConfig *mp4ASC,
program_config *pce, uint8_t short_form);
int8_t AudioSpecificConfigFromBitfile(bitfile *ld,
mp4AudioSpecificConfig *mp4ASC,
program_config *pce, uint32_t bsize, uint8_t short_form);
#ifdef __cplusplus
}
#endif
#endif

77
tests/Audio/libFaad/ms.c Normal file
View File

@ -0,0 +1,77 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: ms.c,v 1.21 2007/11/01 12:33:32 menno Exp $
**/
#include "common.h"
#include "structs.h"
#include "syntax.h"
#include "ms.h"
#include "is.h"
#include "pns.h"
void ms_decode(ic_stream *ics, ic_stream *icsr, real_t *l_spec, real_t *r_spec,
uint16_t frame_len)
{
uint8_t g, b, sfb;
uint8_t group = 0;
uint16_t nshort = frame_len/8;
uint16_t i, k;
real_t tmp;
if (ics->ms_mask_present >= 1)
{
for (g = 0; g < ics->num_window_groups; g++)
{
for (b = 0; b < ics->window_group_length[g]; b++)
{
for (sfb = 0; sfb < ics->max_sfb; sfb++)
{
/* If intensity stereo coding or noise substitution is on
for a particular scalefactor band, no M/S stereo decoding
is carried out.
*/
if ((ics->ms_used[g][sfb] || ics->ms_mask_present == 2) &&
!is_intensity(icsr, g, sfb) && !is_noise(ics, g, sfb))
{
for (i = ics->swb_offset[sfb]; i < min(ics->swb_offset[sfb+1], ics->swb_offset_max); i++)
{
k = (group*nshort) + i;
tmp = l_spec[k] - r_spec[k];
l_spec[k] = l_spec[k] + r_spec[k];
r_spec[k] = tmp;
}
}
}
group++;
}
}
}
}

44
tests/Audio/libFaad/ms.h Normal file
View File

@ -0,0 +1,44 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: ms.h,v 1.19 2007/11/01 12:33:32 menno Exp $
**/
#ifndef __MS_H__
#define __MS_H__
#ifdef __cplusplus
extern "C" {
#endif
void ms_decode(ic_stream *ics, ic_stream *icsr, real_t *l_spec, real_t *r_spec,
uint16_t frame_len);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,258 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: neaacdec.h,v 1.13 2009/01/26 23:51:15 menno Exp $
**/
#ifndef __NEAACDEC_H__
#define __NEAACDEC_H__
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#if 1
/* MACROS FOR BACKWARDS COMPATIBILITY */
/* structs */
#define faacDecHandle NeAACDecHandle
#define faacDecConfiguration NeAACDecConfiguration
#define faacDecConfigurationPtr NeAACDecConfigurationPtr
#define faacDecFrameInfo NeAACDecFrameInfo
/* functions */
#define faacDecGetErrorMessage NeAACDecGetErrorMessage
#define faacDecSetConfiguration NeAACDecSetConfiguration
#define faacDecGetCurrentConfiguration NeAACDecGetCurrentConfiguration
#define faacDecInit NeAACDecInit
#define faacDecInit2 NeAACDecInit2
#define faacDecInitDRM NeAACDecInitDRM
#define faacDecPostSeekReset NeAACDecPostSeekReset
#define faacDecOpen NeAACDecOpen
#define faacDecClose NeAACDecClose
#define faacDecDecode NeAACDecDecode
#define AudioSpecificConfig NeAACDecAudioSpecificConfig
#endif
#ifdef _WIN32
#pragma pack(push, 8)
#ifndef NEAACDECAPI
#define NEAACDECAPI __cdecl
#endif
#else
#ifndef NEAACDECAPI
#define NEAACDECAPI
#endif
#endif
#define FAAD2_VERSION "2.7"
/* object types for AAC */
#define MAIN 1
#define LC 2
#define SSR 3
#define LTP 4
#define HE_AAC 5
#define ER_LC 17
#define ER_LTP 19
#define LD 23
#define DRM_ER_LC 27 /* special object type for DRM */
/* header types */
#define RAW 0
#define ADIF 1
#define ADTS 2
#define LATM 3
/* SBR signalling */
#define NO_SBR 0
#define SBR_UPSAMPLED 1
#define SBR_DOWNSAMPLED 2
#define NO_SBR_UPSAMPLED 3
/* library output formats */
#define FAAD_FMT_16BIT 1
#define FAAD_FMT_24BIT 2
#define FAAD_FMT_32BIT 3
#define FAAD_FMT_FLOAT 4
#define FAAD_FMT_FIXED FAAD_FMT_FLOAT
#define FAAD_FMT_DOUBLE 5
/* Capabilities */
#define LC_DEC_CAP (1<<0) /* Can decode LC */
#define MAIN_DEC_CAP (1<<1) /* Can decode MAIN */
#define LTP_DEC_CAP (1<<2) /* Can decode LTP */
#define LD_DEC_CAP (1<<3) /* Can decode LD */
#define ERROR_RESILIENCE_CAP (1<<4) /* Can decode ER */
#define FIXED_POINT_CAP (1<<5) /* Fixed point */
/* Channel definitions */
#define FRONT_CHANNEL_CENTER (1)
#define FRONT_CHANNEL_LEFT (2)
#define FRONT_CHANNEL_RIGHT (3)
#define SIDE_CHANNEL_LEFT (4)
#define SIDE_CHANNEL_RIGHT (5)
#define BACK_CHANNEL_LEFT (6)
#define BACK_CHANNEL_RIGHT (7)
#define BACK_CHANNEL_CENTER (8)
#define LFE_CHANNEL (9)
#define UNKNOWN_CHANNEL (0)
/* DRM channel definitions */
#define DRMCH_MONO 1
#define DRMCH_STEREO 2
#define DRMCH_SBR_MONO 3
#define DRMCH_SBR_STEREO 4
#define DRMCH_SBR_PS_STEREO 5
/* A decode call can eat up to FAAD_MIN_STREAMSIZE bytes per decoded channel,
so at least so much bytes per channel should be available in this stream */
#define FAAD_MIN_STREAMSIZE 768 /* 6144 bits/channel */
typedef void *NeAACDecHandle;
typedef struct mp4AudioSpecificConfig
{
/* Audio Specific Info */
unsigned char objectTypeIndex;
unsigned char samplingFrequencyIndex;
unsigned long samplingFrequency;
unsigned char channelsConfiguration;
/* GA Specific Info */
unsigned char frameLengthFlag;
unsigned char dependsOnCoreCoder;
unsigned short coreCoderDelay;
unsigned char extensionFlag;
unsigned char aacSectionDataResilienceFlag;
unsigned char aacScalefactorDataResilienceFlag;
unsigned char aacSpectralDataResilienceFlag;
unsigned char epConfig;
char sbr_present_flag;
char forceUpSampling;
char downSampledSBR;
} mp4AudioSpecificConfig;
typedef struct NeAACDecConfiguration
{
unsigned char defObjectType;
unsigned long defSampleRate;
unsigned char outputFormat;
unsigned char downMatrix;
unsigned char useOldADTSFormat;
unsigned char dontUpSampleImplicitSBR;
} NeAACDecConfiguration, *NeAACDecConfigurationPtr;
typedef struct NeAACDecFrameInfo
{
unsigned long bytesconsumed;
unsigned long samples;
unsigned char channels;
unsigned char error;
unsigned long samplerate;
/* SBR: 0: off, 1: on; upsample, 2: on; downsampled, 3: off; upsampled */
unsigned char sbr;
/* MPEG-4 ObjectType */
unsigned char object_type;
/* AAC header type; MP4 will be signalled as RAW also */
unsigned char header_type;
/* multichannel configuration */
unsigned char num_front_channels;
unsigned char num_side_channels;
unsigned char num_back_channels;
unsigned char num_lfe_channels;
unsigned char channel_position[64];
/* PS: 0: off, 1: on */
unsigned char ps;
} NeAACDecFrameInfo;
char* NEAACDECAPI NeAACDecGetErrorMessage(unsigned char errcode);
unsigned long NEAACDECAPI NeAACDecGetCapabilities(void);
NeAACDecHandle NEAACDECAPI NeAACDecOpen(void);
NeAACDecConfigurationPtr NEAACDECAPI NeAACDecGetCurrentConfiguration(NeAACDecHandle hDecoder);
unsigned char NEAACDECAPI NeAACDecSetConfiguration(NeAACDecHandle hDecoder,
NeAACDecConfigurationPtr config);
/* Init the library based on info from the AAC file (ADTS/ADIF) */
long NEAACDECAPI NeAACDecInit(NeAACDecHandle hDecoder,
unsigned char *buffer,
unsigned long buffer_size,
unsigned long *samplerate,
unsigned char *channels);
/* Init the library using a DecoderSpecificInfo */
char NEAACDECAPI NeAACDecInit2(NeAACDecHandle hDecoder,
unsigned char *pBuffer,
unsigned long SizeOfDecoderSpecificInfo,
unsigned long *samplerate,
unsigned char *channels);
/* Init the library for DRM */
char NEAACDECAPI NeAACDecInitDRM(NeAACDecHandle *hDecoder, unsigned long samplerate,
unsigned char channels);
void NEAACDECAPI NeAACDecPostSeekReset(NeAACDecHandle hDecoder, long frame);
void NEAACDECAPI NeAACDecClose(NeAACDecHandle hDecoder);
void* NEAACDECAPI NeAACDecDecode(NeAACDecHandle hDecoder,
NeAACDecFrameInfo *hInfo,
unsigned char *buffer,
unsigned long buffer_size);
void* NEAACDECAPI NeAACDecDecode2(NeAACDecHandle hDecoder,
NeAACDecFrameInfo *hInfo,
unsigned char *buffer,
unsigned long buffer_size,
void **sample_buffer,
unsigned long sample_buffer_size);
char NEAACDECAPI NeAACDecAudioSpecificConfig(unsigned char *pBuffer,
unsigned long buffer_size,
mp4AudioSpecificConfig *mp4ASC);
#ifdef _WIN32
#pragma pack(pop)
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif

View File

@ -0,0 +1,559 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: output.c,v 1.47 2009/01/26 23:51:15 menno Exp $
**/
#include "common.h"
#include "structs.h"
#include "output.h"
#ifndef FIXED_POINT
#define FLOAT_SCALE (1.0f/(1<<15))
#define DM_MUL REAL_CONST(0.3203772410170407) // 1/(1+sqrt(2) + 1/sqrt(2))
#define RSQRT2 REAL_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 *internal_channel)
{
if (!down_matrix)
return input[internal_channel[channel]][sample];
if (channel == 0)
{
return DM_MUL * (input[internal_channel[1]][sample] +
input[internal_channel[0]][sample] * RSQRT2 +
input[internal_channel[3]][sample] * RSQRT2);
} else {
return DM_MUL * (input[internal_channel[2]][sample] +
input[internal_channel[0]][sample] * RSQRT2 +
input[internal_channel[4]][sample] * RSQRT2);
}
}
#ifndef HAS_LRINTF
#define CLIP(sample, max, min) \
if (sample >= 0.0f) \
{ \
sample += 0.5f; \
if (sample >= max) \
sample = max; \
} else { \
sample += -0.5f; \
if (sample <= min) \
sample = min; \
}
#else
#define CLIP(sample, max, min) \
if (sample >= 0.0f) \
{ \
if (sample >= max) \
sample = max; \
} else { \
if (sample <= min) \
sample = min; \
}
#endif
#define CONV(a,b) ((a<<1)|(b&0x1))
static void to_PCM_16bit(NeAACDecStruct *hDecoder, real_t **input,
uint8_t channels, uint16_t frame_len,
int16_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];
CLIP(inp, 32767.0f, -32768.0f);
(*sample_buffer)[i] = (int16_t)lrintf(inp);
}
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];
CLIP(inp0, 32767.0f, -32768.0f);
(*sample_buffer)[(i*2)+0] = (int16_t)lrintf(inp0);
(*sample_buffer)[(i*2)+1] = (int16_t)lrintf(inp0);
}
} 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];
CLIP(inp0, 32767.0f, -32768.0f);
CLIP(inp1, 32767.0f, -32768.0f);
(*sample_buffer)[(i*2)+0] = (int16_t)lrintf(inp0);
(*sample_buffer)[(i*2)+1] = (int16_t)lrintf(inp1);
}
}
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);
CLIP(inp, 32767.0f, -32768.0f);
(*sample_buffer)[(i*channels)+ch] = (int16_t)lrintf(inp);
}
}
break;
}
}
static void to_PCM_24bit(NeAACDecStruct *hDecoder, real_t **input,
uint8_t channels, uint16_t frame_len,
int32_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];
inp *= 256.0f;
CLIP(inp, 8388607.0f, -8388608.0f);
(*sample_buffer)[i] = (int32_t)lrintf(inp);
}
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];
inp0 *= 256.0f;
CLIP(inp0, 8388607.0f, -8388608.0f);
(*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
(*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp0);
}
} 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];
inp0 *= 256.0f;
inp1 *= 256.0f;
CLIP(inp0, 8388607.0f, -8388608.0f);
CLIP(inp1, 8388607.0f, -8388608.0f);
(*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
(*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp1);
}
}
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);
inp *= 256.0f;
CLIP(inp, 8388607.0f, -8388608.0f);
(*sample_buffer)[(i*channels)+ch] = (int32_t)lrintf(inp);
}
}
break;
}
}
static void to_PCM_32bit(NeAACDecStruct *hDecoder, real_t **input,
uint8_t channels, uint16_t frame_len,
int32_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];
inp *= 65536.0f;
CLIP(inp, 2147483647.0f, -2147483648.0f);
(*sample_buffer)[i] = (int32_t)lrintf(inp);
}
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];
inp0 *= 65536.0f;
CLIP(inp0, 2147483647.0f, -2147483648.0f);
(*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
(*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp0);
}
} 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];
inp0 *= 65536.0f;
inp1 *= 65536.0f;
CLIP(inp0, 2147483647.0f, -2147483648.0f);
CLIP(inp1, 2147483647.0f, -2147483648.0f);
(*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
(*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp1);
}
}
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);
inp *= 65536.0f;
CLIP(inp, 2147483647.0f, -2147483648.0f);
(*sample_buffer)[(i*channels)+ch] = (int32_t)lrintf(inp);
}
}
break;
}
}
static void to_PCM_float(NeAACDecStruct *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(NeAACDecStruct *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(NeAACDecStruct *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(NeAACDecStruct *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

View File

@ -0,0 +1,48 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: output.h,v 1.26 2009/01/26 23:51:15 menno Exp $
**/
#ifndef __OUTPUT_H__
#define __OUTPUT_H__
#ifdef __cplusplus
extern "C" {
#endif
void* output_to_PCM(NeAACDecStruct *hDecoder,
real_t **input,
void *samplebuffer,
uint8_t channels,
uint16_t frame_len,
uint8_t format);
#ifdef __cplusplus
}
#endif
#endif

271
tests/Audio/libFaad/pns.c Normal file
View File

@ -0,0 +1,271 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: pns.c,v 1.38 2007/11/01 12:33:32 menno Exp $
**/
#include "common.h"
#include "structs.h"
#include "pns.h"
/* static function declarations */
static void gen_rand_vector(real_t *spec, int16_t scale_factor, uint16_t size,
uint8_t sub,
/* RNG states */ uint32_t *__r1, uint32_t *__r2);
#ifdef FIXED_POINT
#define DIV(A, B) (((int64_t)A << REAL_BITS)/B)
#define step(shift) \
if ((0x40000000l >> shift) + root <= value) \
{ \
value -= (0x40000000l >> shift) + root; \
root = (root >> 1) | (0x40000000l >> shift); \
} else { \
root = root >> 1; \
}
/* fixed point square root approximation */
/* !!!! ONLY WORKS FOR EVEN %REAL_BITS% !!!! */
real_t fp_sqrt(real_t value)
{
real_t root = 0;
step( 0); step( 2); step( 4); step( 6);
step( 8); step(10); step(12); step(14);
step(16); step(18); step(20); step(22);
step(24); step(26); step(28); step(30);
if (root < value)
++root;
root <<= (REAL_BITS/2);
return root;
}
static real_t const pow2_table[] =
{
COEF_CONST(1.0),
COEF_CONST(1.18920711500272),
COEF_CONST(1.41421356237310),
COEF_CONST(1.68179283050743)
};
#endif
/* The function gen_rand_vector(addr, size) generates a vector of length
<size> with signed random values of average energy MEAN_NRG per random
value. A suitable random number generator can be realized using one
multiplication/accumulation per random value.
*/
static INLINE void gen_rand_vector(real_t *spec, int16_t scale_factor, uint16_t size,
uint8_t sub,
/* RNG states */ uint32_t *__r1, uint32_t *__r2)
{
#ifndef FIXED_POINT
uint16_t i;
real_t energy = 0.0;
real_t scale = (real_t)1.0/(real_t)size;
for (i = 0; i < size; i++)
{
real_t tmp = scale*(real_t)(int32_t)ne_rng(__r1, __r2);
spec[i] = tmp;
energy += tmp*tmp;
}
scale = (real_t)1.0/(real_t)sqrt(energy);
scale *= (real_t)pow(2.0, 0.25 * scale_factor);
for (i = 0; i < size; i++)
{
spec[i] *= scale;
}
#else
uint16_t i;
real_t energy = 0, scale;
int32_t exp, frac;
for (i = 0; i < size; i++)
{
/* this can be replaced by a 16 bit random generator!!!! */
real_t tmp = (int32_t)ne_rng(__r1, __r2);
if (tmp < 0)
tmp = -(tmp & ((1<<(REAL_BITS-1))-1));
else
tmp = (tmp & ((1<<(REAL_BITS-1))-1));
energy += MUL_R(tmp,tmp);
spec[i] = tmp;
}
energy = fp_sqrt(energy);
if (energy > 0)
{
scale = DIV(REAL_CONST(1),energy);
exp = scale_factor >> 2;
frac = scale_factor & 3;
/* IMDCT pre-scaling */
exp -= sub;
if (exp < 0)
scale >>= -exp;
else
scale <<= exp;
if (frac)
scale = MUL_C(scale, pow2_table[frac]);
for (i = 0; i < size; i++)
{
spec[i] = MUL_R(spec[i], scale);
}
}
#endif
}
void pns_decode(ic_stream *ics_left, ic_stream *ics_right,
real_t *spec_left, real_t *spec_right, uint16_t frame_len,
uint8_t channel_pair, uint8_t object_type,
/* RNG states */ uint32_t *__r1, uint32_t *__r2)
{
uint8_t g, sfb, b;
uint16_t size, offs;
uint8_t group = 0;
uint16_t nshort = frame_len >> 3;
uint8_t sub = 0;
#ifdef FIXED_POINT
/* IMDCT scaling */
if (object_type == LD)
{
sub = 9 /*9*/;
} else {
if (ics_left->window_sequence == EIGHT_SHORT_SEQUENCE)
sub = 7 /*7*/;
else
sub = 10 /*10*/;
}
#endif
for (g = 0; g < ics_left->num_window_groups; g++)
{
/* Do perceptual noise substitution decoding */
for (b = 0; b < ics_left->window_group_length[g]; b++)
{
for (sfb = 0; sfb < ics_left->max_sfb; sfb++)
{
if (is_noise(ics_left, g, sfb))
{
#ifdef LTP_DEC
/* Simultaneous use of LTP and PNS is not prevented in the
syntax. If both LTP, and PNS are enabled on the same
scalefactor band, PNS takes precedence, and no prediction
is applied to this band.
*/
ics_left->ltp.long_used[sfb] = 0;
ics_left->ltp2.long_used[sfb] = 0;
#endif
#ifdef MAIN_DEC
/* For scalefactor bands coded using PNS the corresponding
predictors are switched to "off".
*/
ics_left->pred.prediction_used[sfb] = 0;
#endif
offs = ics_left->swb_offset[sfb];
size = min(ics_left->swb_offset[sfb+1], ics_left->swb_offset_max) - offs;
/* Generate random vector */
gen_rand_vector(&spec_left[(group*nshort)+offs],
ics_left->scale_factors[g][sfb], size, sub, __r1, __r2);
}
/* From the spec:
If the same scalefactor band and group is coded by perceptual noise
substitution in both channels of a channel pair, the correlation of
the noise signal can be controlled by means of the ms_used field: While
the default noise generation process works independently for each channel
(separate generation of random vectors), the same random vector is used
for both channels if ms_used[] is set for a particular scalefactor band
and group. In this case, no M/S stereo coding is carried out (because M/S
stereo coding and noise substitution coding are mutually exclusive).
If the same scalefactor band and group is coded by perceptual noise
substitution in only one channel of a channel pair the setting of ms_used[]
is not evaluated.
*/
if (channel_pair)
{
if (is_noise(ics_right, g, sfb))
{
if (((ics_left->ms_mask_present == 1) &&
(ics_left->ms_used[g][sfb])) ||
(ics_left->ms_mask_present == 2))
{
uint16_t c;
offs = ics_right->swb_offset[sfb];
size = min(ics_right->swb_offset[sfb+1], ics_right->swb_offset_max) - offs;
for (c = 0; c < size; c++)
{
spec_right[(group*nshort) + offs + c] =
spec_left[(group*nshort) + offs + c];
}
} else /*if (ics_left->ms_mask_present == 0)*/ {
#ifdef LTP_DEC
ics_right->ltp.long_used[sfb] = 0;
ics_right->ltp2.long_used[sfb] = 0;
#endif
#ifdef MAIN_DEC
ics_right->pred.prediction_used[sfb] = 0;
#endif
offs = ics_right->swb_offset[sfb];
size = min(ics_right->swb_offset[sfb+1], ics_right->swb_offset_max) - offs;
/* Generate random vector */
gen_rand_vector(&spec_right[(group*nshort)+offs],
ics_right->scale_factors[g][sfb], size, sub, __r1, __r2);
}
}
}
} /* sfb */
group++;
} /* b */
} /* g */
}

57
tests/Audio/libFaad/pns.h Normal file
View File

@ -0,0 +1,57 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: pns.h,v 1.27 2007/11/01 12:33:33 menno Exp $
**/
#ifndef __PNS_H__
#define __PNS_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "syntax.h"
#define NOISE_OFFSET 90
void pns_decode(ic_stream *ics_left, ic_stream *ics_right,
real_t *spec_left, real_t *spec_right, uint16_t frame_len,
uint8_t channel_pair, uint8_t object_type,
/* RNG states */ uint32_t *__r1, uint32_t *__r2);
static INLINE uint8_t is_noise(ic_stream *ics, uint8_t group, uint8_t sfb)
{
if (ics->sfb_cb[group][sfb] == NOISE_HCB)
return 1;
return 0;
}
#ifdef __cplusplus
}
#endif
#endif

2013
tests/Audio/libFaad/ps_dec.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,152 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: ps_dec.h,v 1.13 2009/01/26 22:32:31 menno Exp $
**/
#ifndef __PS_DEC_H__
#define __PS_DEC_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "bits.h"
#define EXTENSION_ID_PS 2
#define MAX_PS_ENVELOPES 5
#define NO_ALLPASS_LINKS 3
typedef struct
{
/* bitstream parameters */
uint8_t enable_iid;
uint8_t enable_icc;
uint8_t enable_ext;
uint8_t iid_mode;
uint8_t icc_mode;
uint8_t nr_iid_par;
uint8_t nr_ipdopd_par;
uint8_t nr_icc_par;
uint8_t frame_class;
uint8_t num_env;
uint8_t border_position[MAX_PS_ENVELOPES+1];
uint8_t iid_dt[MAX_PS_ENVELOPES];
uint8_t icc_dt[MAX_PS_ENVELOPES];
uint8_t enable_ipdopd;
uint8_t ipd_mode;
uint8_t ipd_dt[MAX_PS_ENVELOPES];
uint8_t opd_dt[MAX_PS_ENVELOPES];
/* indices */
int8_t iid_index_prev[34];
int8_t icc_index_prev[34];
int8_t ipd_index_prev[17];
int8_t opd_index_prev[17];
int8_t iid_index[MAX_PS_ENVELOPES][34];
int8_t icc_index[MAX_PS_ENVELOPES][34];
int8_t ipd_index[MAX_PS_ENVELOPES][17];
int8_t opd_index[MAX_PS_ENVELOPES][17];
int8_t ipd_index_1[17];
int8_t opd_index_1[17];
int8_t ipd_index_2[17];
int8_t opd_index_2[17];
/* ps data was correctly read */
uint8_t ps_data_available;
/* a header has been read */
uint8_t header_read;
/* hybrid filterbank parameters */
void *hyb;
uint8_t use34hybrid_bands;
uint8_t numTimeSlotsRate;
/**/
uint8_t num_groups;
uint8_t num_hybrid_groups;
uint8_t nr_par_bands;
uint8_t nr_allpass_bands;
uint8_t decay_cutoff;
uint8_t *group_border;
uint16_t *map_group2bk;
/* filter delay handling */
uint8_t saved_delay;
uint8_t delay_buf_index_ser[NO_ALLPASS_LINKS];
uint8_t num_sample_delay_ser[NO_ALLPASS_LINKS];
uint8_t delay_D[64];
uint8_t delay_buf_index_delay[64];
complex_t delay_Qmf[14][64]; /* 14 samples delay max, 64 QMF channels */
complex_t delay_SubQmf[2][32]; /* 2 samples delay max (SubQmf is always allpass filtered) */
complex_t delay_Qmf_ser[NO_ALLPASS_LINKS][5][64]; /* 5 samples delay max (table 8.34), 64 QMF channels */
complex_t delay_SubQmf_ser[NO_ALLPASS_LINKS][5][32]; /* 5 samples delay max (table 8.34) */
/* transients */
real_t alpha_decay;
real_t alpha_smooth;
real_t P_PeakDecayNrg[34];
real_t P_prev[34];
real_t P_SmoothPeakDecayDiffNrg_prev[34];
/* mixing and phase */
complex_t h11_prev[50];
complex_t h12_prev[50];
complex_t h21_prev[50];
complex_t h22_prev[50];
uint8_t phase_hist;
complex_t ipd_prev[20][2];
complex_t opd_prev[20][2];
} ps_info;
/* ps_syntax.c */
uint16_t ps_data(ps_info *ps, bitfile *ld, uint8_t *header);
/* ps_dec.c */
ps_info *ps_init(uint8_t sr_index, uint8_t numTimeSlotsRate);
void ps_free(ps_info *ps);
uint8_t ps_decode(ps_info *ps, qmf_t X_left[38][64], qmf_t X_right[38][64]);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,551 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: ps_syntax.c,v 1.11 2007/11/01 12:33:33 menno Exp $
**/
#include "common.h"
#ifdef PS_DEC
#include "bits.h"
#include "ps_dec.h"
/* type definitaions */
typedef const int8_t (*ps_huff_tab)[2];
/* static data tables */
static const uint8_t nr_iid_par_tab[] = {
10, 20, 34, 10, 20, 34, 0, 0
};
static const uint8_t nr_ipdopd_par_tab[] = {
5, 11, 17, 5, 11, 17, 0, 0
};
static const uint8_t nr_icc_par_tab[] = {
10, 20, 34, 10, 20, 34, 0, 0
};
static const uint8_t num_env_tab[][4] = {
{ 0, 1, 2, 4 },
{ 1, 2, 3, 4 }
};
/* binary lookup huffman tables */
static const int8_t f_huff_iid_def[][2] = {
{ /*0*/ -31, 1 }, /* index 0: 1 bits: x */
{ 2, 3 }, /* index 1: 2 bits: 1x */
{ /*1*/ -30, /*-1*/ -32 }, /* index 2: 3 bits: 10x */
{ 4, 5 }, /* index 3: 3 bits: 11x */
{ /*2*/ -29, /*-2*/ -33 }, /* index 4: 4 bits: 110x */
{ 6, 7 }, /* index 5: 4 bits: 111x */
{ /*3*/ -28, /*-3*/ -34 }, /* index 6: 5 bits: 1110x */
{ 8, 9 }, /* index 7: 5 bits: 1111x */
{ /*-4*/ -35, /*4*/ -27 }, /* index 8: 6 bits: 11110x */
{ /*5*/ -26, 10 }, /* index 9: 6 bits: 11111x */
{ /*-5*/ -36, 11 }, /* index 10: 7 bits: 111111x */
{ /*6*/ -25, 12 }, /* index 11: 8 bits: 1111111x */
{ /*-6*/ -37, 13 }, /* index 12: 9 bits: 11111111x */
{ /*-7*/ -38, 14 }, /* index 13: 10 bits: 111111111x */
{ /*7*/ -24, 15 }, /* index 14: 11 bits: 1111111111x */
{ 16, 17 }, /* index 15: 12 bits: 11111111111x */
{ /*8*/ -23, /*-8*/ -39 }, /* index 16: 13 bits: 111111111110x */
{ 18, 19 }, /* index 17: 13 bits: 111111111111x */
{ /*9*/ -22, /*10*/ -21 }, /* index 18: 14 bits: 1111111111110x */
{ 20, 21 }, /* index 19: 14 bits: 1111111111111x */
{ /*-9*/ -40, /*11*/ -20 }, /* index 20: 15 bits: 11111111111110x */
{ 22, 23 }, /* index 21: 15 bits: 11111111111111x */
{ /*-10*/ -41, 24 }, /* index 22: 16 bits: 111111111111110x */
{ 25, 26 }, /* index 23: 16 bits: 111111111111111x */
{ /*-11*/ -42, /*-14*/ -45 }, /* index 24: 17 bits: 1111111111111101x */
{ /*-13*/ -44, /*-12*/ -43 }, /* index 25: 17 bits: 1111111111111110x */
{ /*12*/ -19, 27 }, /* index 26: 17 bits: 1111111111111111x */
{ /*13*/ -18, /*14*/ -17 } /* index 27: 18 bits: 11111111111111111x */
};
static const int8_t t_huff_iid_def[][2] = {
{ /*0*/ -31, 1 }, /* index 0: 1 bits: x */
{ /*-1*/ -32, 2 }, /* index 1: 2 bits: 1x */
{ /*1*/ -30, 3 }, /* index 2: 3 bits: 11x */
{ /*-2*/ -33, 4 }, /* index 3: 4 bits: 111x */
{ /*2*/ -29, 5 }, /* index 4: 5 bits: 1111x */
{ /*-3*/ -34, 6 }, /* index 5: 6 bits: 11111x */
{ /*3*/ -28, 7 }, /* index 6: 7 bits: 111111x */
{ /*-4*/ -35, 8 }, /* index 7: 8 bits: 1111111x */
{ /*4*/ -27, 9 }, /* index 8: 9 bits: 11111111x */
{ /*-5*/ -36, 10 }, /* index 9: 10 bits: 111111111x */
{ /*5*/ -26, 11 }, /* index 10: 11 bits: 1111111111x */
{ /*-6*/ -37, 12 }, /* index 11: 12 bits: 11111111111x */
{ /*6*/ -25, 13 }, /* index 12: 13 bits: 111111111111x */
{ /*7*/ -24, 14 }, /* index 13: 14 bits: 1111111111111x */
{ /*-7*/ -38, 15 }, /* index 14: 15 bits: 11111111111111x */
{ 16, 17 }, /* index 15: 16 bits: 111111111111111x */
{ /*8*/ -23, /*-8*/ -39 }, /* index 16: 17 bits: 1111111111111110x */
{ 18, 19 }, /* index 17: 17 bits: 1111111111111111x */
{ 20, 21 }, /* index 18: 18 bits: 11111111111111110x */
{ 22, 23 }, /* index 19: 18 bits: 11111111111111111x */
{ /*9*/ -22, /*-14*/ -45 }, /* index 20: 19 bits: 111111111111111100x */
{ /*-13*/ -44, /*-12*/ -43 }, /* index 21: 19 bits: 111111111111111101x */
{ 24, 25 }, /* index 22: 19 bits: 111111111111111110x */
{ 26, 27 }, /* index 23: 19 bits: 111111111111111111x */
{ /*-11*/ -42, /*-10*/ -41 }, /* index 24: 20 bits: 1111111111111111100x */
{ /*-9*/ -40, /*10*/ -21 }, /* index 25: 20 bits: 1111111111111111101x */
{ /*11*/ -20, /*12*/ -19 }, /* index 26: 20 bits: 1111111111111111110x */
{ /*13*/ -18, /*14*/ -17 } /* index 27: 20 bits: 1111111111111111111x */
};
static const int8_t f_huff_iid_fine[][2] = {
{ 1, /*0*/ -31 }, /* index 0: 1 bits: x */
{ 2, 3 }, /* index 1: 2 bits: 0x */
{ 4, /*-1*/ -32 }, /* index 2: 3 bits: 00x */
{ /*1*/ -30, 5 }, /* index 3: 3 bits: 01x */
{ /*-2*/ -33, /*2*/ -29 }, /* index 4: 4 bits: 000x */
{ 6, 7 }, /* index 5: 4 bits: 011x */
{ /*-3*/ -34, /*3*/ -28 }, /* index 6: 5 bits: 0110x */
{ 8, 9 }, /* index 7: 5 bits: 0111x */
{ /*-4*/ -35, /*4*/ -27 }, /* index 8: 6 bits: 01110x */
{ 10, 11 }, /* index 9: 6 bits: 01111x */
{ /*-5*/ -36, /*5*/ -26 }, /* index 10: 7 bits: 011110x */
{ 12, 13 }, /* index 11: 7 bits: 011111x */
{ /*-6*/ -37, /*6*/ -25 }, /* index 12: 8 bits: 0111110x */
{ 14, 15 }, /* index 13: 8 bits: 0111111x */
{ /*7*/ -24, 16 }, /* index 14: 9 bits: 01111110x */
{ 17, 18 }, /* index 15: 9 bits: 01111111x */
{ 19, /*-8*/ -39 }, /* index 16: 10 bits: 011111101x */
{ /*8*/ -23, 20 }, /* index 17: 10 bits: 011111110x */
{ 21, /*-7*/ -38 }, /* index 18: 10 bits: 011111111x */
{ /*10*/ -21, 22 }, /* index 19: 11 bits: 0111111010x */
{ 23, /*-9*/ -40 }, /* index 20: 11 bits: 0111111101x */
{ /*9*/ -22, 24 }, /* index 21: 11 bits: 0111111110x */
{ /*-11*/ -42, /*11*/ -20 }, /* index 22: 12 bits: 01111110101x */
{ 25, 26 }, /* index 23: 12 bits: 01111111010x */
{ 27, /*-10*/ -41 }, /* index 24: 12 bits: 01111111101x */
{ 28, /*-12*/ -43 }, /* index 25: 13 bits: 011111110100x */
{ /*12*/ -19, 29 }, /* index 26: 13 bits: 011111110101x */
{ 30, 31 }, /* index 27: 13 bits: 011111111010x */
{ 32, /*-14*/ -45 }, /* index 28: 14 bits: 0111111101000x */
{ /*14*/ -17, 33 }, /* index 29: 14 bits: 0111111101011x */
{ 34, /*-13*/ -44 }, /* index 30: 14 bits: 0111111110100x */
{ /*13*/ -18, 35 }, /* index 31: 14 bits: 0111111110101x */
{ 36, 37 }, /* index 32: 15 bits: 01111111010000x */
{ 38, /*-15*/ -46 }, /* index 33: 15 bits: 01111111010111x */
{ /*15*/ -16, 39 }, /* index 34: 15 bits: 01111111101000x */
{ 40, 41 }, /* index 35: 15 bits: 01111111101011x */
{ 42, 43 }, /* index 36: 16 bits: 011111110100000x */
{ /*-17*/ -48, /*17*/ -14 }, /* index 37: 16 bits: 011111110100001x */
{ 44, 45 }, /* index 38: 16 bits: 011111110101110x */
{ 46, 47 }, /* index 39: 16 bits: 011111111010001x */
{ 48, 49 }, /* index 40: 16 bits: 011111111010110x */
{ /*-16*/ -47, /*16*/ -15 }, /* index 41: 16 bits: 011111111010111x */
{ /*-21*/ -52, /*21*/ -10 }, /* index 42: 17 bits: 0111111101000000x */
{ /*-19*/ -50, /*19*/ -12 }, /* index 43: 17 bits: 0111111101000001x */
{ /*-18*/ -49, /*18*/ -13 }, /* index 44: 17 bits: 0111111101011100x */
{ 50, 51 }, /* index 45: 17 bits: 0111111101011101x */
{ 52, 53 }, /* index 46: 17 bits: 0111111110100010x */
{ 54, 55 }, /* index 47: 17 bits: 0111111110100011x */
{ 56, 57 }, /* index 48: 17 bits: 0111111110101100x */
{ 58, 59 }, /* index 49: 17 bits: 0111111110101101x */
{ /*-26*/ -57, /*-25*/ -56 }, /* index 50: 18 bits: 01111111010111010x */
{ /*-28*/ -59, /*-27*/ -58 }, /* index 51: 18 bits: 01111111010111011x */
{ /*-22*/ -53, /*22*/ -9 }, /* index 52: 18 bits: 01111111101000100x */
{ /*-24*/ -55, /*-23*/ -54 }, /* index 53: 18 bits: 01111111101000101x */
{ /*25*/ -6, /*26*/ -5 }, /* index 54: 18 bits: 01111111101000110x */
{ /*23*/ -8, /*24*/ -7 }, /* index 55: 18 bits: 01111111101000111x */
{ /*29*/ -2, /*30*/ -1 }, /* index 56: 18 bits: 01111111101011000x */
{ /*27*/ -4, /*28*/ -3 }, /* index 57: 18 bits: 01111111101011001x */
{ /*-30*/ -61, /*-29*/ -60 }, /* index 58: 18 bits: 01111111101011010x */
{ /*-20*/ -51, /*20*/ -11 } /* index 59: 18 bits: 01111111101011011x */
};
static const int8_t t_huff_iid_fine[][2] = {
{ 1, /*0*/ -31 }, /* index 0: 1 bits: x */
{ /*1*/ -30, 2 }, /* index 1: 2 bits: 0x */
{ 3, /*-1*/ -32 }, /* index 2: 3 bits: 01x */
{ 4, 5 }, /* index 3: 4 bits: 010x */
{ 6, 7 }, /* index 4: 5 bits: 0100x */
{ /*-2*/ -33, /*2*/ -29 }, /* index 5: 5 bits: 0101x */
{ 8, /*-3*/ -34 }, /* index 6: 6 bits: 01000x */
{ /*3*/ -28, 9 }, /* index 7: 6 bits: 01001x */
{ /*-4*/ -35, /*4*/ -27 }, /* index 8: 7 bits: 010000x */
{ 10, 11 }, /* index 9: 7 bits: 010011x */
{ /*5*/ -26, 12 }, /* index 10: 8 bits: 0100110x */
{ 13, 14 }, /* index 11: 8 bits: 0100111x */
{ /*-6*/ -37, /*6*/ -25 }, /* index 12: 9 bits: 01001101x */
{ 15, 16 }, /* index 13: 9 bits: 01001110x */
{ 17, /*-5*/ -36 }, /* index 14: 9 bits: 01001111x */
{ 18, /*-7*/ -38 }, /* index 15: 10 bits: 010011100x */
{ /*7*/ -24, 19 }, /* index 16: 10 bits: 010011101x */
{ 20, 21 }, /* index 17: 10 bits: 010011110x */
{ /*9*/ -22, 22 }, /* index 18: 11 bits: 0100111000x */
{ 23, 24 }, /* index 19: 11 bits: 0100111011x */
{ /*-8*/ -39, /*8*/ -23 }, /* index 20: 11 bits: 0100111100x */
{ 25, 26 }, /* index 21: 11 bits: 0100111101x */
{ /*11*/ -20, 27 }, /* index 22: 12 bits: 01001110001x */
{ 28, 29 }, /* index 23: 12 bits: 01001110110x */
{ /*-10*/ -41, /*10*/ -21 }, /* index 24: 12 bits: 01001110111x */
{ 30, 31 }, /* index 25: 12 bits: 01001111010x */
{ 32, /*-9*/ -40 }, /* index 26: 12 bits: 01001111011x */
{ 33, /*-13*/ -44 }, /* index 27: 13 bits: 010011100011x */
{ /*13*/ -18, 34 }, /* index 28: 13 bits: 010011101100x */
{ 35, 36 }, /* index 29: 13 bits: 010011101101x */
{ 37, /*-12*/ -43 }, /* index 30: 13 bits: 010011110100x */
{ /*12*/ -19, 38 }, /* index 31: 13 bits: 010011110101x */
{ 39, /*-11*/ -42 }, /* index 32: 13 bits: 010011110110x */
{ 40, 41 }, /* index 33: 14 bits: 0100111000110x */
{ 42, 43 }, /* index 34: 14 bits: 0100111011001x */
{ 44, 45 }, /* index 35: 14 bits: 0100111011010x */
{ 46, /*-15*/ -46 }, /* index 36: 14 bits: 0100111011011x */
{ /*15*/ -16, 47 }, /* index 37: 14 bits: 0100111101000x */
{ /*-14*/ -45, /*14*/ -17 }, /* index 38: 14 bits: 0100111101011x */
{ 48, 49 }, /* index 39: 14 bits: 0100111101100x */
{ /*-21*/ -52, /*-20*/ -51 }, /* index 40: 15 bits: 01001110001100x */
{ /*18*/ -13, /*19*/ -12 }, /* index 41: 15 bits: 01001110001101x */
{ /*-19*/ -50, /*-18*/ -49 }, /* index 42: 15 bits: 01001110110010x */
{ 50, 51 }, /* index 43: 15 bits: 01001110110011x */
{ 52, 53 }, /* index 44: 15 bits: 01001110110100x */
{ 54, 55 }, /* index 45: 15 bits: 01001110110101x */
{ 56, /*-17*/ -48 }, /* index 46: 15 bits: 01001110110110x */
{ /*17*/ -14, 57 }, /* index 47: 15 bits: 01001111010001x */
{ 58, /*-16*/ -47 }, /* index 48: 15 bits: 01001111011000x */
{ /*16*/ -15, 59 }, /* index 49: 15 bits: 01001111011001x */
{ /*-26*/ -57, /*26*/ -5 }, /* index 50: 16 bits: 010011101100110x */
{ /*-28*/ -59, /*-27*/ -58 }, /* index 51: 16 bits: 010011101100111x */
{ /*29*/ -2, /*30*/ -1 }, /* index 52: 16 bits: 010011101101000x */
{ /*27*/ -4, /*28*/ -3 }, /* index 53: 16 bits: 010011101101001x */
{ /*-30*/ -61, /*-29*/ -60 }, /* index 54: 16 bits: 010011101101010x */
{ /*-25*/ -56, /*25*/ -6 }, /* index 55: 16 bits: 010011101101011x */
{ /*-24*/ -55, /*24*/ -7 }, /* index 56: 16 bits: 010011101101100x */
{ /*-23*/ -54, /*23*/ -8 }, /* index 57: 16 bits: 010011110100011x */
{ /*-22*/ -53, /*22*/ -9 }, /* index 58: 16 bits: 010011110110000x */
{ /*20*/ -11, /*21*/ -10 } /* index 59: 16 bits: 010011110110011x */
};
static const int8_t f_huff_icc[][2] = {
{ /*0*/ -31, 1 }, /* index 0: 1 bits: x */
{ /*1*/ -30, 2 }, /* index 1: 2 bits: 1x */
{ /*-1*/ -32, 3 }, /* index 2: 3 bits: 11x */
{ /*2*/ -29, 4 }, /* index 3: 4 bits: 111x */
{ /*-2*/ -33, 5 }, /* index 4: 5 bits: 1111x */
{ /*3*/ -28, 6 }, /* index 5: 6 bits: 11111x */
{ /*-3*/ -34, 7 }, /* index 6: 7 bits: 111111x */
{ /*4*/ -27, 8 }, /* index 7: 8 bits: 1111111x */
{ /*5*/ -26, 9 }, /* index 8: 9 bits: 11111111x */
{ /*-4*/ -35, 10 }, /* index 9: 10 bits: 111111111x */
{ /*6*/ -25, 11 }, /* index 10: 11 bits: 1111111111x */
{ /*-5*/ -36, 12 }, /* index 11: 12 bits: 11111111111x */
{ /*7*/ -24, 13 }, /* index 12: 13 bits: 111111111111x */
{ /*-6*/ -37, /*-7*/ -38 } /* index 13: 14 bits: 1111111111111x */
};
static const int8_t t_huff_icc[][2] = {
{ /*0*/ -31, 1 }, /* index 0: 1 bits: x */
{ /*1*/ -30, 2 }, /* index 1: 2 bits: 1x */
{ /*-1*/ -32, 3 }, /* index 2: 3 bits: 11x */
{ /*2*/ -29, 4 }, /* index 3: 4 bits: 111x */
{ /*-2*/ -33, 5 }, /* index 4: 5 bits: 1111x */
{ /*3*/ -28, 6 }, /* index 5: 6 bits: 11111x */
{ /*-3*/ -34, 7 }, /* index 6: 7 bits: 111111x */
{ /*4*/ -27, 8 }, /* index 7: 8 bits: 1111111x */
{ /*-4*/ -35, 9 }, /* index 8: 9 bits: 11111111x */
{ /*5*/ -26, 10 }, /* index 9: 10 bits: 111111111x */
{ /*-5*/ -36, 11 }, /* index 10: 11 bits: 1111111111x */
{ /*6*/ -25, 12 }, /* index 11: 12 bits: 11111111111x */
{ /*-6*/ -37, 13 }, /* index 12: 13 bits: 111111111111x */
{ /*-7*/ -38, /*7*/ -24 } /* index 13: 14 bits: 1111111111111x */
};
static const int8_t f_huff_ipd[][2] = {
{ 1, /*0*/ -31 }, /* index 0: 1 bits: x */
{ 2, 3 }, /* index 1: 2 bits: 0x */
{ /*1*/ -30, 4 }, /* index 2: 3 bits: 00x */
{ 5, 6 }, /* index 3: 3 bits: 01x */
{ /*4*/ -27, /*5*/ -26 }, /* index 4: 4 bits: 001x */
{ /*3*/ -28, /*6*/ -25 }, /* index 5: 4 bits: 010x */
{ /*2*/ -29, /*7*/ -24 } /* index 6: 4 bits: 011x */
};
static const int8_t t_huff_ipd[][2] = {
{ 1, /*0*/ -31 }, /* index 0: 1 bits: x */
{ 2, 3 }, /* index 1: 2 bits: 0x */
{ 4, 5 }, /* index 2: 3 bits: 00x */
{ /*1*/ -30, /*7*/ -24 }, /* index 3: 3 bits: 01x */
{ /*5*/ -26, 6 }, /* index 4: 4 bits: 000x */
{ /*2*/ -29, /*6*/ -25 }, /* index 5: 4 bits: 001x */
{ /*4*/ -27, /*3*/ -28 } /* index 6: 5 bits: 0001x */
};
static const int8_t f_huff_opd[][2] = {
{ 1, /*0*/ -31 }, /* index 0: 1 bits: x */
{ 2, 3 }, /* index 1: 2 bits: 0x */
{ /*7*/ -24, /*1*/ -30 }, /* index 2: 3 bits: 00x */
{ 4, 5 }, /* index 3: 3 bits: 01x */
{ /*3*/ -28, /*6*/ -25 }, /* index 4: 4 bits: 010x */
{ /*2*/ -29, 6 }, /* index 5: 4 bits: 011x */
{ /*5*/ -26, /*4*/ -27 } /* index 6: 5 bits: 0111x */
};
static const int8_t t_huff_opd[][2] = {
{ 1, /*0*/ -31 }, /* index 0: 1 bits: x */
{ 2, 3 }, /* index 1: 2 bits: 0x */
{ 4, 5 }, /* index 2: 3 bits: 00x */
{ /*1*/ -30, /*7*/ -24 }, /* index 3: 3 bits: 01x */
{ /*5*/ -26, /*2*/ -29 }, /* index 4: 4 bits: 000x */
{ /*6*/ -25, 6 }, /* index 5: 4 bits: 001x */
{ /*4*/ -27, /*3*/ -28 } /* index 6: 5 bits: 0011x */
};
/* static function declarations */
static uint16_t ps_extension(ps_info *ps, bitfile *ld,
const uint8_t ps_extension_id,
const uint16_t num_bits_left);
static void huff_data(bitfile *ld, const uint8_t dt, const uint8_t nr_par,
ps_huff_tab t_huff, ps_huff_tab f_huff, int8_t *par);
static INLINE int8_t ps_huff_dec(bitfile *ld, ps_huff_tab t_huff);
uint16_t ps_data(ps_info *ps, bitfile *ld, uint8_t *header)
{
uint8_t tmp, n;
uint16_t bits = (uint16_t)faad_get_processed_bits(ld);
*header = 0;
/* check for new PS header */
if (faad_get1bit(ld
DEBUGVAR(1,1000,"ps_data(): enable_ps_header")))
{
*header = 1;
ps->header_read = 1;
ps->use34hybrid_bands = 0;
/* Inter-channel Intensity Difference (IID) parameters enabled */
ps->enable_iid = (uint8_t)faad_get1bit(ld
DEBUGVAR(1,1001,"ps_data(): enable_iid"));
if (ps->enable_iid)
{
ps->iid_mode = (uint8_t)faad_getbits(ld, 3
DEBUGVAR(1,1002,"ps_data(): iid_mode"));
ps->nr_iid_par = nr_iid_par_tab[ps->iid_mode];
ps->nr_ipdopd_par = nr_ipdopd_par_tab[ps->iid_mode];
if (ps->iid_mode == 2 || ps->iid_mode == 5)
ps->use34hybrid_bands = 1;
/* IPD freq res equal to IID freq res */
ps->ipd_mode = ps->iid_mode;
}
/* Inter-channel Coherence (ICC) parameters enabled */
ps->enable_icc = (uint8_t)faad_get1bit(ld
DEBUGVAR(1,1003,"ps_data(): enable_icc"));
if (ps->enable_icc)
{
ps->icc_mode = (uint8_t)faad_getbits(ld, 3
DEBUGVAR(1,1004,"ps_data(): icc_mode"));
ps->nr_icc_par = nr_icc_par_tab[ps->icc_mode];
if (ps->icc_mode == 2 || ps->icc_mode == 5)
ps->use34hybrid_bands = 1;
}
/* PS extension layer enabled */
ps->enable_ext = (uint8_t)faad_get1bit(ld
DEBUGVAR(1,1005,"ps_data(): enable_ext"));
}
/* we are here, but no header has been read yet */
if (ps->header_read == 0)
{
ps->ps_data_available = 0;
return 1;
}
ps->frame_class = (uint8_t)faad_get1bit(ld
DEBUGVAR(1,1006,"ps_data(): frame_class"));
tmp = (uint8_t)faad_getbits(ld, 2
DEBUGVAR(1,1007,"ps_data(): num_env_idx"));
ps->num_env = num_env_tab[ps->frame_class][tmp];
if (ps->frame_class)
{
for (n = 1; n < ps->num_env+1; n++)
{
ps->border_position[n] = (uint8_t)faad_getbits(ld, 5
DEBUGVAR(1,1008,"ps_data(): border_position")) + 1;
}
}
if (ps->enable_iid)
{
for (n = 0; n < ps->num_env; n++)
{
ps->iid_dt[n] = (uint8_t)faad_get1bit(ld
DEBUGVAR(1,1009,"ps_data(): iid_dt"));
/* iid_data */
if (ps->iid_mode < 3)
{
huff_data(ld, ps->iid_dt[n], ps->nr_iid_par, t_huff_iid_def,
f_huff_iid_def, ps->iid_index[n]);
} else {
huff_data(ld, ps->iid_dt[n], ps->nr_iid_par, t_huff_iid_fine,
f_huff_iid_fine, ps->iid_index[n]);
}
}
}
if (ps->enable_icc)
{
for (n = 0; n < ps->num_env; n++)
{
ps->icc_dt[n] = (uint8_t)faad_get1bit(ld
DEBUGVAR(1,1010,"ps_data(): icc_dt"));
/* icc_data */
huff_data(ld, ps->icc_dt[n], ps->nr_icc_par, t_huff_icc,
f_huff_icc, ps->icc_index[n]);
}
}
if (ps->enable_ext)
{
uint16_t num_bits_left;
uint16_t cnt = (uint16_t)faad_getbits(ld, 4
DEBUGVAR(1,1011,"ps_data(): ps_extension_size"));
if (cnt == 15)
{
cnt += (uint16_t)faad_getbits(ld, 8
DEBUGVAR(1,1012,"ps_data(): esc_count"));
}
num_bits_left = 8 * cnt;
while (num_bits_left > 7)
{
uint8_t ps_extension_id = (uint8_t)faad_getbits(ld, 2
DEBUGVAR(1,1013,"ps_data(): ps_extension_size"));
num_bits_left -= 2;
num_bits_left -= ps_extension(ps, ld, ps_extension_id, num_bits_left);
}
faad_getbits(ld, num_bits_left
DEBUGVAR(1,1014,"ps_data(): fill_bits"));
}
bits = (uint16_t)faad_get_processed_bits(ld) - bits;
ps->ps_data_available = 1;
return bits;
}
static uint16_t ps_extension(ps_info *ps, bitfile *ld,
const uint8_t ps_extension_id,
const uint16_t num_bits_left)
{
uint8_t n;
uint16_t bits = (uint16_t)faad_get_processed_bits(ld);
if (ps_extension_id == 0)
{
ps->enable_ipdopd = (uint8_t)faad_get1bit(ld
DEBUGVAR(1,1015,"ps_extension(): enable_ipdopd"));
if (ps->enable_ipdopd)
{
for (n = 0; n < ps->num_env; n++)
{
ps->ipd_dt[n] = (uint8_t)faad_get1bit(ld
DEBUGVAR(1,1016,"ps_extension(): ipd_dt"));
/* ipd_data */
huff_data(ld, ps->ipd_dt[n], ps->nr_ipdopd_par, t_huff_ipd,
f_huff_ipd, ps->ipd_index[n]);
ps->opd_dt[n] = (uint8_t)faad_get1bit(ld
DEBUGVAR(1,1017,"ps_extension(): opd_dt"));
/* opd_data */
huff_data(ld, ps->opd_dt[n], ps->nr_ipdopd_par, t_huff_opd,
f_huff_opd, ps->opd_index[n]);
}
}
faad_get1bit(ld
DEBUGVAR(1,1018,"ps_extension(): reserved_ps"));
}
/* return number of bits read */
bits = (uint16_t)faad_get_processed_bits(ld) - bits;
return bits;
}
/* read huffman data coded in either the frequency or the time direction */
static void huff_data(bitfile *ld, const uint8_t dt, const uint8_t nr_par,
ps_huff_tab t_huff, ps_huff_tab f_huff, int8_t *par)
{
uint8_t n;
if (dt)
{
/* coded in time direction */
for (n = 0; n < nr_par; n++)
{
par[n] = ps_huff_dec(ld, t_huff);
}
} else {
/* coded in frequency direction */
par[0] = ps_huff_dec(ld, f_huff);
for (n = 1; n < nr_par; n++)
{
par[n] = ps_huff_dec(ld, f_huff);
}
}
}
/* binary search huffman decoding */
static INLINE int8_t ps_huff_dec(bitfile *ld, ps_huff_tab t_huff)
{
uint8_t bit;
int16_t index = 0;
while (index >= 0)
{
bit = (uint8_t)faad_get1bit(ld);
index = t_huff[index][bit];
}
return index + 31;
}
#endif

View File

@ -0,0 +1,550 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: ps_tables.h,v 1.8 2007/11/01 12:33:33 menno Exp $
**/
#ifndef __PS_TABLES_H__
#define __PS_TABLES_H__
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _MSC_VER
#pragma warning(disable:4305)
#pragma warning(disable:4244)
#endif
#if 0
#if 0
float f_center_20[12] = {
0.5/4, 1.5/4, 2.5/4, 3.5/4,
4.5/4*0, 5.5/4*0, -1.5/4, -0.5/4,
3.5/2, 2.5/2, 4.5/2, 5.5/2
};
#else
float f_center_20[12] = {
0.5/8, 1.5/8, 2.5/8, 3.5/8,
4.5/8*0, 5.5/8*0, -1.5/8, -0.5/8,
3.5/4, 2.5/4, 4.5/4, 5.5/4
};
#endif
float f_center_34[32] = {
1/12, 3/12, 5/12, 7/12,
9/12, 11/12, 13/12, 15/12,
17/12, -5/12, -3/12, -1/12,
17/8, 19/8, 5/8, 7/8,
9/8, 11/8, 13/8, 15/8,
9/4, 11/4, 13/4, 7/4,
17/4, 11/4, 13/4, 15/4,
17/4, 19/4, 21/4, 15/4
};
static const real_t frac_delay_q[] = {
FRAC_CONST(0.43),
FRAC_CONST(0.75),
FRAC_CONST(0.347)
};
#endif
/* RE(ps->Phi_Fract_Qmf[j]) = (float)cos(M_PI*(j+0.5)*(0.39)); */
/* IM(ps->Phi_Fract_Qmf[j]) = (float)sin(M_PI*(j+0.5)*(0.39)); */
static const complex_t Phi_Fract_Qmf[] = {
{ FRAC_CONST(0.8181497455), FRAC_CONST(0.5750052333) },
{ FRAC_CONST(-0.2638730407), FRAC_CONST(0.9645574093) },
{ FRAC_CONST(-0.9969173074), FRAC_CONST(0.0784590989) },
{ FRAC_CONST(-0.4115143716), FRAC_CONST(-0.9114032984) },
{ FRAC_CONST(0.7181262970), FRAC_CONST(-0.6959127784) },
{ FRAC_CONST(0.8980275989), FRAC_CONST(0.4399391711) },
{ FRAC_CONST(-0.1097343117), FRAC_CONST(0.9939609766) },
{ FRAC_CONST(-0.9723699093), FRAC_CONST(0.2334453613) },
{ FRAC_CONST(-0.5490227938), FRAC_CONST(-0.8358073831) },
{ FRAC_CONST(0.6004202366), FRAC_CONST(-0.7996846437) },
{ FRAC_CONST(0.9557930231), FRAC_CONST(0.2940403223) },
{ FRAC_CONST(0.0471064523), FRAC_CONST(0.9988898635) },
{ FRAC_CONST(-0.9238795042), FRAC_CONST(0.3826834261) },
{ FRAC_CONST(-0.6730124950), FRAC_CONST(-0.7396311164) },
{ FRAC_CONST(0.4679298103), FRAC_CONST(-0.8837656379) },
{ FRAC_CONST(0.9900236726), FRAC_CONST(0.1409012377) },
{ FRAC_CONST(0.2027872950), FRAC_CONST(0.9792228341) },
{ FRAC_CONST(-0.8526401520), FRAC_CONST(0.5224985480) },
{ FRAC_CONST(-0.7804304361), FRAC_CONST(-0.6252426505) },
{ FRAC_CONST(0.3239174187), FRAC_CONST(-0.9460853338) },
{ FRAC_CONST(0.9998766184), FRAC_CONST(-0.0157073177) },
{ FRAC_CONST(0.3534748554), FRAC_CONST(0.9354440570) },
{ FRAC_CONST(-0.7604059577), FRAC_CONST(0.6494480371) },
{ FRAC_CONST(-0.8686315417), FRAC_CONST(-0.4954586625) },
{ FRAC_CONST(0.1719291061), FRAC_CONST(-0.9851093292) },
{ FRAC_CONST(0.9851093292), FRAC_CONST(-0.1719291061) },
{ FRAC_CONST(0.4954586625), FRAC_CONST(0.8686315417) },
{ FRAC_CONST(-0.6494480371), FRAC_CONST(0.7604059577) },
{ FRAC_CONST(-0.9354440570), FRAC_CONST(-0.3534748554) },
{ FRAC_CONST(0.0157073177), FRAC_CONST(-0.9998766184) },
{ FRAC_CONST(0.9460853338), FRAC_CONST(-0.3239174187) },
{ FRAC_CONST(0.6252426505), FRAC_CONST(0.7804304361) },
{ FRAC_CONST(-0.5224985480), FRAC_CONST(0.8526401520) },
{ FRAC_CONST(-0.9792228341), FRAC_CONST(-0.2027872950) },
{ FRAC_CONST(-0.1409012377), FRAC_CONST(-0.9900236726) },
{ FRAC_CONST(0.8837656379), FRAC_CONST(-0.4679298103) },
{ FRAC_CONST(0.7396311164), FRAC_CONST(0.6730124950) },
{ FRAC_CONST(-0.3826834261), FRAC_CONST(0.9238795042) },
{ FRAC_CONST(-0.9988898635), FRAC_CONST(-0.0471064523) },
{ FRAC_CONST(-0.2940403223), FRAC_CONST(-0.9557930231) },
{ FRAC_CONST(0.7996846437), FRAC_CONST(-0.6004202366) },
{ FRAC_CONST(0.8358073831), FRAC_CONST(0.5490227938) },
{ FRAC_CONST(-0.2334453613), FRAC_CONST(0.9723699093) },
{ FRAC_CONST(-0.9939609766), FRAC_CONST(0.1097343117) },
{ FRAC_CONST(-0.4399391711), FRAC_CONST(-0.8980275989) },
{ FRAC_CONST(0.6959127784), FRAC_CONST(-0.7181262970) },
{ FRAC_CONST(0.9114032984), FRAC_CONST(0.4115143716) },
{ FRAC_CONST(-0.0784590989), FRAC_CONST(0.9969173074) },
{ FRAC_CONST(-0.9645574093), FRAC_CONST(0.2638730407) },
{ FRAC_CONST(-0.5750052333), FRAC_CONST(-0.8181497455) },
{ FRAC_CONST(0.5750052333), FRAC_CONST(-0.8181497455) },
{ FRAC_CONST(0.9645574093), FRAC_CONST(0.2638730407) },
{ FRAC_CONST(0.0784590989), FRAC_CONST(0.9969173074) },
{ FRAC_CONST(-0.9114032984), FRAC_CONST(0.4115143716) },
{ FRAC_CONST(-0.6959127784), FRAC_CONST(-0.7181262970) },
{ FRAC_CONST(0.4399391711), FRAC_CONST(-0.8980275989) },
{ FRAC_CONST(0.9939609766), FRAC_CONST(0.1097343117) },
{ FRAC_CONST(0.2334453613), FRAC_CONST(0.9723699093) },
{ FRAC_CONST(-0.8358073831), FRAC_CONST(0.5490227938) },
{ FRAC_CONST(-0.7996846437), FRAC_CONST(-0.6004202366) },
{ FRAC_CONST(0.2940403223), FRAC_CONST(-0.9557930231) },
{ FRAC_CONST(0.9988898635), FRAC_CONST(-0.0471064523) },
{ FRAC_CONST(0.3826834261), FRAC_CONST(0.9238795042) },
{ FRAC_CONST(-0.7396311164), FRAC_CONST(0.6730124950) }
};
/* RE(Phi_Fract_SubQmf20[j]) = (float)cos(M_PI*f_center_20[j]*0.39); */
/* IM(Phi_Fract_SubQmf20[j]) = (float)sin(M_PI*f_center_20[j]*0.39); */
static const complex_t Phi_Fract_SubQmf20[] = {
{ FRAC_CONST(0.9882950187), FRAC_CONST(0.1525546312) },
{ FRAC_CONST(0.8962930441), FRAC_CONST(0.4434623122) },
{ FRAC_CONST(0.7208535671), FRAC_CONST(0.6930873394) },
{ FRAC_CONST(0.4783087075), FRAC_CONST(0.8781917691) },
{ FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) },
{ FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) },
{ FRAC_CONST(0.8962930441), FRAC_CONST(-0.4434623122) },
{ FRAC_CONST(0.9882950187), FRAC_CONST(-0.1525546312) },
{ FRAC_CONST(-0.5424415469), FRAC_CONST(0.8400935531) },
{ FRAC_CONST(0.0392598175), FRAC_CONST(0.9992290139) },
{ FRAC_CONST(-0.9268565774), FRAC_CONST(0.3754155636) },
{ FRAC_CONST(-0.9741733670), FRAC_CONST(-0.2258012742) }
};
/* RE(Phi_Fract_SubQmf34[j]) = (float)cos(M_PI*f_center_34[j]*0.39); */
/* IM(Phi_Fract_SubQmf34[j]) = (float)sin(M_PI*f_center_34[j]*0.39); */
static const complex_t Phi_Fract_SubQmf34[] = {
{ FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) },
{ FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) },
{ FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) },
{ FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) },
{ FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) },
{ FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) },
{ FRAC_CONST(0.3387379348), FRAC_CONST(0.9408807755) },
{ FRAC_CONST(0.3387379348), FRAC_CONST(0.9408807755) },
{ FRAC_CONST(0.3387379348), FRAC_CONST(0.9408807755) },
{ FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) },
{ FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) },
{ FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) },
{ FRAC_CONST(-0.7705132365), FRAC_CONST(0.6374239922) },
{ FRAC_CONST(-0.7705132365), FRAC_CONST(0.6374239922) },
{ FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) },
{ FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) },
{ FRAC_CONST(0.3387379348), FRAC_CONST(0.9408807755) },
{ FRAC_CONST(0.3387379348), FRAC_CONST(0.9408807755) },
{ FRAC_CONST(0.3387379348), FRAC_CONST(0.9408807755) },
{ FRAC_CONST(0.3387379348), FRAC_CONST(0.9408807755) },
{ FRAC_CONST(-0.7705132365), FRAC_CONST(0.6374239922) },
{ FRAC_CONST(-0.7705132365), FRAC_CONST(0.6374239922) },
{ FRAC_CONST(-0.8607420325), FRAC_CONST(-0.5090414286) },
{ FRAC_CONST(0.3387379348), FRAC_CONST(0.9408807755) },
{ FRAC_CONST(0.1873813123), FRAC_CONST(-0.9822872281) },
{ FRAC_CONST(-0.7705132365), FRAC_CONST(0.6374239922) },
{ FRAC_CONST(-0.8607420325), FRAC_CONST(-0.5090414286) },
{ FRAC_CONST(-0.8607420325), FRAC_CONST(-0.5090414286) },
{ FRAC_CONST(0.1873813123), FRAC_CONST(-0.9822872281) },
{ FRAC_CONST(0.1873813123), FRAC_CONST(-0.9822872281) },
{ FRAC_CONST(0.9876883626), FRAC_CONST(-0.1564344615) },
{ FRAC_CONST(-0.8607420325), FRAC_CONST(-0.5090414286) }
};
/* RE(Q_Fract_allpass_Qmf[j][i]) = (float)cos(M_PI*(j+0.5)*(frac_delay_q[i])); */
/* IM(Q_Fract_allpass_Qmf[j][i]) = (float)sin(M_PI*(j+0.5)*(frac_delay_q[i])); */
static const complex_t Q_Fract_allpass_Qmf[][3] = {
{ { FRAC_CONST(0.7804303765), FRAC_CONST(0.6252426505) }, { FRAC_CONST(0.3826834261), FRAC_CONST(0.9238795042) }, { FRAC_CONST(0.8550928831), FRAC_CONST(0.5184748173) } },
{ { FRAC_CONST(-0.4399392009), FRAC_CONST(0.8980275393) }, { FRAC_CONST(-0.9238795042), FRAC_CONST(-0.3826834261) }, { FRAC_CONST(-0.0643581524), FRAC_CONST(0.9979268909) } },
{ { FRAC_CONST(-0.9723699093), FRAC_CONST(-0.2334454209) }, { FRAC_CONST(0.9238795042), FRAC_CONST(-0.3826834261) }, { FRAC_CONST(-0.9146071672), FRAC_CONST(0.4043435752) } },
{ { FRAC_CONST(0.0157073960), FRAC_CONST(-0.9998766184) }, { FRAC_CONST(-0.3826834261), FRAC_CONST(0.9238795042) }, { FRAC_CONST(-0.7814115286), FRAC_CONST(-0.6240159869) } },
{ { FRAC_CONST(0.9792228341), FRAC_CONST(-0.2027871907) }, { FRAC_CONST(-0.3826834261), FRAC_CONST(-0.9238795042) }, { FRAC_CONST(0.1920081824), FRAC_CONST(-0.9813933372) } },
{ { FRAC_CONST(0.4115142524), FRAC_CONST(0.9114032984) }, { FRAC_CONST(0.9238795042), FRAC_CONST(0.3826834261) }, { FRAC_CONST(0.9589683414), FRAC_CONST(-0.2835132182) } },
{ { FRAC_CONST(-0.7996847630), FRAC_CONST(0.6004201174) }, { FRAC_CONST(-0.9238795042), FRAC_CONST(0.3826834261) }, { FRAC_CONST(0.6947838664), FRAC_CONST(0.7192186117) } },
{ { FRAC_CONST(-0.7604058385), FRAC_CONST(-0.6494481564) }, { FRAC_CONST(0.3826834261), FRAC_CONST(-0.9238795042) }, { FRAC_CONST(-0.3164770305), FRAC_CONST(0.9486001730) } },
{ { FRAC_CONST(0.4679299891), FRAC_CONST(-0.8837655187) }, { FRAC_CONST(0.3826834261), FRAC_CONST(0.9238795042) }, { FRAC_CONST(-0.9874414206), FRAC_CONST(0.1579856575) } },
{ { FRAC_CONST(0.9645573497), FRAC_CONST(0.2638732493) }, { FRAC_CONST(-0.9238795042), FRAC_CONST(-0.3826834261) }, { FRAC_CONST(-0.5966450572), FRAC_CONST(-0.8025052547) } },
{ { FRAC_CONST(-0.0471066870), FRAC_CONST(0.9988898635) }, { FRAC_CONST(0.9238795042), FRAC_CONST(-0.3826834261) }, { FRAC_CONST(0.4357025325), FRAC_CONST(-0.9000906944) } },
{ { FRAC_CONST(-0.9851093888), FRAC_CONST(0.1719288528) }, { FRAC_CONST(-0.3826834261), FRAC_CONST(0.9238795042) }, { FRAC_CONST(0.9995546937), FRAC_CONST(-0.0298405960) } },
{ { FRAC_CONST(-0.3826831877), FRAC_CONST(-0.9238796234) }, { FRAC_CONST(-0.3826834261), FRAC_CONST(-0.9238795042) }, { FRAC_CONST(0.4886211455), FRAC_CONST(0.8724960685) } },
{ { FRAC_CONST(0.8181498647), FRAC_CONST(-0.5750049949) }, { FRAC_CONST(0.9238795042), FRAC_CONST(0.3826834261) }, { FRAC_CONST(-0.5477093458), FRAC_CONST(0.8366686702) } },
{ { FRAC_CONST(0.7396308780), FRAC_CONST(0.6730127335) }, { FRAC_CONST(-0.9238795042), FRAC_CONST(0.3826834261) }, { FRAC_CONST(-0.9951074123), FRAC_CONST(-0.0987988561) } },
{ { FRAC_CONST(-0.4954589605), FRAC_CONST(0.8686313629) }, { FRAC_CONST(0.3826834261), FRAC_CONST(-0.9238795042) }, { FRAC_CONST(-0.3725017905), FRAC_CONST(-0.9280315042) } },
{ { FRAC_CONST(-0.9557929039), FRAC_CONST(-0.2940406799) }, { FRAC_CONST(0.3826834261), FRAC_CONST(0.9238795042) }, { FRAC_CONST(0.6506417990), FRAC_CONST(-0.7593847513) } },
{ { FRAC_CONST(0.0784594864), FRAC_CONST(-0.9969173074) }, { FRAC_CONST(-0.9238795042), FRAC_CONST(-0.3826834261) }, { FRAC_CONST(0.9741733670), FRAC_CONST(0.2258014232) } },
{ { FRAC_CONST(0.9900237322), FRAC_CONST(-0.1409008205) }, { FRAC_CONST(0.9238795042), FRAC_CONST(-0.3826834261) }, { FRAC_CONST(0.2502108514), FRAC_CONST(0.9681913853) } },
{ { FRAC_CONST(0.3534744382), FRAC_CONST(0.9354441762) }, { FRAC_CONST(-0.3826834261), FRAC_CONST(0.9238795042) }, { FRAC_CONST(-0.7427945137), FRAC_CONST(0.6695194840) } },
{ { FRAC_CONST(-0.8358076215), FRAC_CONST(0.5490224361) }, { FRAC_CONST(-0.3826834261), FRAC_CONST(-0.9238795042) }, { FRAC_CONST(-0.9370992780), FRAC_CONST(-0.3490629196) } },
{ { FRAC_CONST(-0.7181259394), FRAC_CONST(-0.6959131360) }, { FRAC_CONST(0.9238795042), FRAC_CONST(0.3826834261) }, { FRAC_CONST(-0.1237744763), FRAC_CONST(-0.9923103452) } },
{ { FRAC_CONST(0.5224990249), FRAC_CONST(-0.8526399136) }, { FRAC_CONST(-0.9238795042), FRAC_CONST(0.3826834261) }, { FRAC_CONST(0.8226406574), FRAC_CONST(-0.5685616732) } },
{ { FRAC_CONST(0.9460852146), FRAC_CONST(0.3239179254) }, { FRAC_CONST(0.3826834261), FRAC_CONST(-0.9238795042) }, { FRAC_CONST(0.8844994903), FRAC_CONST(0.4665412009) } },
{ { FRAC_CONST(-0.1097348556), FRAC_CONST(0.9939609170) }, { FRAC_CONST(0.3826834261), FRAC_CONST(0.9238795042) }, { FRAC_CONST(-0.0047125919), FRAC_CONST(0.9999889135) } },
{ { FRAC_CONST(-0.9939610362), FRAC_CONST(0.1097337380) }, { FRAC_CONST(-0.9238795042), FRAC_CONST(-0.3826834261) }, { FRAC_CONST(-0.8888573647), FRAC_CONST(0.4581840038) } },
{ { FRAC_CONST(-0.3239168525), FRAC_CONST(-0.9460855722) }, { FRAC_CONST(0.9238795042), FRAC_CONST(-0.3826834261) }, { FRAC_CONST(-0.8172453642), FRAC_CONST(-0.5762898922) } },
{ { FRAC_CONST(0.8526405096), FRAC_CONST(-0.5224980116) }, { FRAC_CONST(-0.3826834261), FRAC_CONST(0.9238795042) }, { FRAC_CONST(0.1331215799), FRAC_CONST(-0.9910997152) } },
{ { FRAC_CONST(0.6959123611), FRAC_CONST(0.7181267142) }, { FRAC_CONST(-0.3826834261), FRAC_CONST(-0.9238795042) }, { FRAC_CONST(0.9403476119), FRAC_CONST(-0.3402152061) } },
{ { FRAC_CONST(-0.5490233898), FRAC_CONST(0.8358070254) }, { FRAC_CONST(0.9238795042), FRAC_CONST(0.3826834261) }, { FRAC_CONST(0.7364512086), FRAC_CONST(0.6764906645) } },
{ { FRAC_CONST(-0.9354437590), FRAC_CONST(-0.3534754813) }, { FRAC_CONST(-0.9238795042), FRAC_CONST(0.3826834261) }, { FRAC_CONST(-0.2593250275), FRAC_CONST(0.9657900929) } },
{ { FRAC_CONST(0.1409019381), FRAC_CONST(-0.9900235534) }, { FRAC_CONST(0.3826834261), FRAC_CONST(-0.9238795042) }, { FRAC_CONST(-0.9762582779), FRAC_CONST(0.2166097313) } },
{ { FRAC_CONST(0.9969173670), FRAC_CONST(-0.0784583688) }, { FRAC_CONST(0.3826834261), FRAC_CONST(0.9238795042) }, { FRAC_CONST(-0.6434556246), FRAC_CONST(-0.7654833794) } },
{ { FRAC_CONST(0.2940396070), FRAC_CONST(0.9557932615) }, { FRAC_CONST(-0.9238795042), FRAC_CONST(-0.3826834261) }, { FRAC_CONST(0.3812320232), FRAC_CONST(-0.9244794250) } },
{ { FRAC_CONST(-0.8686318994), FRAC_CONST(0.4954580069) }, { FRAC_CONST(0.9238795042), FRAC_CONST(-0.3826834261) }, { FRAC_CONST(0.9959943891), FRAC_CONST(-0.0894154981) } },
{ { FRAC_CONST(-0.6730118990), FRAC_CONST(-0.7396316528) }, { FRAC_CONST(-0.3826834261), FRAC_CONST(0.9238795042) }, { FRAC_CONST(0.5397993922), FRAC_CONST(0.8417937160) } },
{ { FRAC_CONST(0.5750059485), FRAC_CONST(-0.8181492686) }, { FRAC_CONST(-0.3826834261), FRAC_CONST(-0.9238795042) }, { FRAC_CONST(-0.4968227744), FRAC_CONST(0.8678520322) } },
{ { FRAC_CONST(0.9238792062), FRAC_CONST(0.3826842010) }, { FRAC_CONST(0.9238795042), FRAC_CONST(0.3826834261) }, { FRAC_CONST(-0.9992290139), FRAC_CONST(-0.0392601527) } },
{ { FRAC_CONST(-0.1719299555), FRAC_CONST(0.9851091504) }, { FRAC_CONST(-0.9238795042), FRAC_CONST(0.3826834261) }, { FRAC_CONST(-0.4271997511), FRAC_CONST(-0.9041572809) } },
{ { FRAC_CONST(-0.9988899231), FRAC_CONST(0.0471055657) }, { FRAC_CONST(0.3826834261), FRAC_CONST(-0.9238795042) }, { FRAC_CONST(0.6041822433), FRAC_CONST(-0.7968461514) } },
{ { FRAC_CONST(-0.2638721764), FRAC_CONST(-0.9645576477) }, { FRAC_CONST(0.3826834261), FRAC_CONST(0.9238795042) }, { FRAC_CONST(0.9859085083), FRAC_CONST(0.1672853529) } },
{ { FRAC_CONST(0.8837660551), FRAC_CONST(-0.4679289758) }, { FRAC_CONST(-0.9238795042), FRAC_CONST(-0.3826834261) }, { FRAC_CONST(0.3075223565), FRAC_CONST(0.9515408874) } },
{ { FRAC_CONST(0.6494473219), FRAC_CONST(0.7604066133) }, { FRAC_CONST(0.9238795042), FRAC_CONST(-0.3826834261) }, { FRAC_CONST(-0.7015317082), FRAC_CONST(0.7126382589) } },
{ { FRAC_CONST(-0.6004210114), FRAC_CONST(0.7996840477) }, { FRAC_CONST(-0.3826834261), FRAC_CONST(0.9238795042) }, { FRAC_CONST(-0.9562535882), FRAC_CONST(-0.2925389707) } },
{ { FRAC_CONST(-0.9114028811), FRAC_CONST(-0.4115152657) }, { FRAC_CONST(-0.3826834261), FRAC_CONST(-0.9238795042) }, { FRAC_CONST(-0.1827499419), FRAC_CONST(-0.9831594229) } },
{ { FRAC_CONST(0.2027882934), FRAC_CONST(-0.9792225957) }, { FRAC_CONST(0.9238795042), FRAC_CONST(0.3826834261) }, { FRAC_CONST(0.7872582674), FRAC_CONST(-0.6166234016) } },
{ { FRAC_CONST(0.9998766780), FRAC_CONST(-0.0157062728) }, { FRAC_CONST(-0.9238795042), FRAC_CONST(0.3826834261) }, { FRAC_CONST(0.9107555747), FRAC_CONST(0.4129458666) } },
{ { FRAC_CONST(0.2334443331), FRAC_CONST(0.9723701477) }, { FRAC_CONST(0.3826834261), FRAC_CONST(-0.9238795042) }, { FRAC_CONST(0.0549497530), FRAC_CONST(0.9984891415) } },
{ { FRAC_CONST(-0.8980280757), FRAC_CONST(0.4399381876) }, { FRAC_CONST(0.3826834261), FRAC_CONST(0.9238795042) }, { FRAC_CONST(-0.8599416018), FRAC_CONST(0.5103924870) } },
{ { FRAC_CONST(-0.6252418160), FRAC_CONST(-0.7804310918) }, { FRAC_CONST(-0.9238795042), FRAC_CONST(-0.3826834261) }, { FRAC_CONST(-0.8501682281), FRAC_CONST(-0.5265110731) } },
{ { FRAC_CONST(0.6252435446), FRAC_CONST(-0.7804297209) }, { FRAC_CONST(0.9238795042), FRAC_CONST(-0.3826834261) }, { FRAC_CONST(0.0737608299), FRAC_CONST(-0.9972759485) } },
{ { FRAC_CONST(0.8980270624), FRAC_CONST(0.4399402142) }, { FRAC_CONST(-0.3826834261), FRAC_CONST(0.9238795042) }, { FRAC_CONST(0.9183775187), FRAC_CONST(-0.3957053721) } },
{ { FRAC_CONST(-0.2334465086), FRAC_CONST(0.9723696709) }, { FRAC_CONST(-0.3826834261), FRAC_CONST(-0.9238795042) }, { FRAC_CONST(0.7754954696), FRAC_CONST(0.6313531399) } },
{ { FRAC_CONST(-0.9998766184), FRAC_CONST(-0.0157085191) }, { FRAC_CONST(0.9238795042), FRAC_CONST(0.3826834261) }, { FRAC_CONST(-0.2012493610), FRAC_CONST(0.9795400500) } },
{ { FRAC_CONST(-0.2027861029), FRAC_CONST(-0.9792230725) }, { FRAC_CONST(-0.9238795042), FRAC_CONST(0.3826834261) }, { FRAC_CONST(-0.9615978599), FRAC_CONST(0.2744622827) } },
{ { FRAC_CONST(0.9114037752), FRAC_CONST(-0.4115132093) }, { FRAC_CONST(0.3826834261), FRAC_CONST(-0.9238795042) }, { FRAC_CONST(-0.6879743338), FRAC_CONST(-0.7257350087) } },
{ { FRAC_CONST(0.6004192233), FRAC_CONST(0.7996854186) }, { FRAC_CONST(0.3826834261), FRAC_CONST(0.9238795042) }, { FRAC_CONST(0.3254036009), FRAC_CONST(-0.9455752373) } },
{ { FRAC_CONST(-0.6494490504), FRAC_CONST(0.7604051232) }, { FRAC_CONST(-0.9238795042), FRAC_CONST(-0.3826834261) }, { FRAC_CONST(0.9888865948), FRAC_CONST(-0.1486719251) } },
{ { FRAC_CONST(-0.8837650418), FRAC_CONST(-0.4679309726) }, { FRAC_CONST(0.9238795042), FRAC_CONST(-0.3826834261) }, { FRAC_CONST(0.5890548825), FRAC_CONST(0.8080930114) } },
{ { FRAC_CONST(0.2638743520), FRAC_CONST(-0.9645570517) }, { FRAC_CONST(-0.3826834261), FRAC_CONST(0.9238795042) }, { FRAC_CONST(-0.4441666007), FRAC_CONST(0.8959442377) } },
{ { FRAC_CONST(0.9988898039), FRAC_CONST(0.0471078083) }, { FRAC_CONST(-0.3826834261), FRAC_CONST(-0.9238795042) }, { FRAC_CONST(-0.9997915030), FRAC_CONST(0.0204183888) } },
{ { FRAC_CONST(0.1719277352), FRAC_CONST(0.9851095676) }, { FRAC_CONST(0.9238795042), FRAC_CONST(0.3826834261) }, { FRAC_CONST(-0.4803760946), FRAC_CONST(-0.8770626187) } },
{ { FRAC_CONST(-0.9238800406), FRAC_CONST(0.3826821446) }, { FRAC_CONST(-0.9238795042), FRAC_CONST(0.3826834261) }, { FRAC_CONST(0.5555707216), FRAC_CONST(-0.8314692974) } },
{ { FRAC_CONST(-0.5750041008), FRAC_CONST(-0.8181505203) }, { FRAC_CONST(0.3826834261), FRAC_CONST(-0.9238795042) }, { FRAC_CONST(0.9941320419), FRAC_CONST(0.1081734300) } }
};
/* RE(Q_Fract_allpass_SubQmf20[j][i]) = (float)cos(M_PI*f_center_20[j]*frac_delay_q[i]); */
/* IM(Q_Fract_allpass_SubQmf20[j][i]) = (float)sin(M_PI*f_center_20[j]*frac_delay_q[i]); */
static const complex_t Q_Fract_allpass_SubQmf20[][3] = {
{ { FRAC_CONST(0.9857769012), FRAC_CONST(0.1680592746) }, { FRAC_CONST(0.9569403529), FRAC_CONST(0.2902846634) }, { FRAC_CONST(0.9907300472), FRAC_CONST(0.1358452588) } },
{ { FRAC_CONST(0.8744080663), FRAC_CONST(0.4851911962) }, { FRAC_CONST(0.6343932748), FRAC_CONST(0.7730104327) }, { FRAC_CONST(0.9175986052), FRAC_CONST(0.3975082636) } },
{ { FRAC_CONST(0.6642524004), FRAC_CONST(0.7475083470) }, { FRAC_CONST(0.0980171412), FRAC_CONST(0.9951847196) }, { FRAC_CONST(0.7767338753), FRAC_CONST(0.6298289299) } },
{ { FRAC_CONST(0.3790524006), FRAC_CONST(0.9253752232) }, { FRAC_CONST(-0.4713967443), FRAC_CONST(0.8819212914) }, { FRAC_CONST(0.5785340071), FRAC_CONST(0.8156582713) } },
{ { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) }, { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) }, { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) } },
{ { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) }, { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) }, { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) } },
{ { FRAC_CONST(0.8744080663), FRAC_CONST(-0.4851911962) }, { FRAC_CONST(0.6343932748), FRAC_CONST(-0.7730104327) }, { FRAC_CONST(0.9175986052), FRAC_CONST(-0.3975082636) } },
{ { FRAC_CONST(0.9857769012), FRAC_CONST(-0.1680592746) }, { FRAC_CONST(0.9569403529), FRAC_CONST(-0.2902846634) }, { FRAC_CONST(0.9907300472), FRAC_CONST(-0.1358452588) } },
{ { FRAC_CONST(-0.7126385570), FRAC_CONST(0.7015314102) }, { FRAC_CONST(-0.5555702448), FRAC_CONST(-0.8314695954) }, { FRAC_CONST(-0.3305967748), FRAC_CONST(0.9437720776) } },
{ { FRAC_CONST(-0.1175374240), FRAC_CONST(0.9930684566) }, { FRAC_CONST(-0.9807852507), FRAC_CONST(0.1950903237) }, { FRAC_CONST(0.2066311091), FRAC_CONST(0.9784189463) } },
{ { FRAC_CONST(-0.9947921634), FRAC_CONST(0.1019244045) }, { FRAC_CONST(0.5555702448), FRAC_CONST(-0.8314695954) }, { FRAC_CONST(-0.7720130086), FRAC_CONST(0.6356067061) } },
{ { FRAC_CONST(-0.8400934935), FRAC_CONST(-0.5424416065) }, { FRAC_CONST(0.9807852507), FRAC_CONST(0.1950903237) }, { FRAC_CONST(-0.9896889329), FRAC_CONST(0.1432335079) } }
};
/* RE(Q_Fract_allpass_SubQmf34[j][i]) = (float)cos(M_PI*f_center_34[j]*frac_delay_q[i]); */
/* IM(Q_Fract_allpass_SubQmf34[j][i]) = (float)sin(M_PI*f_center_34[j]*frac_delay_q[i]); */
static const complex_t Q_Fract_allpass_SubQmf34[][3] = {
{ { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) }, { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) }, { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) } },
{ { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) }, { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) }, { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) } },
{ { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) }, { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) }, { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) } },
{ { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) }, { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) }, { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) } },
{ { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) }, { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) }, { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) } },
{ { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) }, { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) }, { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) } },
{ { FRAC_CONST(0.2181432247), FRAC_CONST(0.9759167433) }, { FRAC_CONST(-0.7071067691), FRAC_CONST(0.7071067691) }, { FRAC_CONST(0.4623677433), FRAC_CONST(0.8866882324) } },
{ { FRAC_CONST(0.2181432247), FRAC_CONST(0.9759167433) }, { FRAC_CONST(-0.7071067691), FRAC_CONST(0.7071067691) }, { FRAC_CONST(0.4623677433), FRAC_CONST(0.8866882324) } },
{ { FRAC_CONST(0.2181432247), FRAC_CONST(0.9759167433) }, { FRAC_CONST(-0.7071067691), FRAC_CONST(0.7071067691) }, { FRAC_CONST(0.4623677433), FRAC_CONST(0.8866882324) } },
{ { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) }, { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) }, { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) } },
{ { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) }, { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) }, { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) } },
{ { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) }, { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) }, { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) } },
{ { FRAC_CONST(-0.9048270583), FRAC_CONST(0.4257792532) }, { FRAC_CONST(-0.0000000000), FRAC_CONST(-1.0000000000) }, { FRAC_CONST(-0.5724321604), FRAC_CONST(0.8199520707) } },
{ { FRAC_CONST(-0.9048270583), FRAC_CONST(0.4257792532) }, { FRAC_CONST(-0.0000000000), FRAC_CONST(-1.0000000000) }, { FRAC_CONST(-0.5724321604), FRAC_CONST(0.8199520707) } },
{ { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) }, { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) }, { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) } },
{ { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) }, { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) }, { FRAC_CONST(1.0000000000), FRAC_CONST(0.0000000000) } },
{ { FRAC_CONST(0.2181432247), FRAC_CONST(0.9759167433) }, { FRAC_CONST(-0.7071067691), FRAC_CONST(0.7071067691) }, { FRAC_CONST(0.4623677433), FRAC_CONST(0.8866882324) } },
{ { FRAC_CONST(0.2181432247), FRAC_CONST(0.9759167433) }, { FRAC_CONST(-0.7071067691), FRAC_CONST(0.7071067691) }, { FRAC_CONST(0.4623677433), FRAC_CONST(0.8866882324) } },
{ { FRAC_CONST(0.2181432247), FRAC_CONST(0.9759167433) }, { FRAC_CONST(-0.7071067691), FRAC_CONST(0.7071067691) }, { FRAC_CONST(0.4623677433), FRAC_CONST(0.8866882324) } },
{ { FRAC_CONST(0.2181432247), FRAC_CONST(0.9759167433) }, { FRAC_CONST(-0.7071067691), FRAC_CONST(0.7071067691) }, { FRAC_CONST(0.4623677433), FRAC_CONST(0.8866882324) } },
{ { FRAC_CONST(-0.9048270583), FRAC_CONST(0.4257792532) }, { FRAC_CONST(-0.0000000000), FRAC_CONST(-1.0000000000) }, { FRAC_CONST(-0.5724321604), FRAC_CONST(0.8199520707) } },
{ { FRAC_CONST(-0.9048270583), FRAC_CONST(0.4257792532) }, { FRAC_CONST(-0.0000000000), FRAC_CONST(-1.0000000000) }, { FRAC_CONST(-0.5724321604), FRAC_CONST(0.8199520707) } },
{ { FRAC_CONST(-0.6129069924), FRAC_CONST(-0.7901550531) }, { FRAC_CONST(0.7071067691), FRAC_CONST(0.7071067691) }, { FRAC_CONST(-0.9917160273), FRAC_CONST(-0.1284494549) } },
{ { FRAC_CONST(0.2181432247), FRAC_CONST(0.9759167433) }, { FRAC_CONST(-0.7071067691), FRAC_CONST(0.7071067691) }, { FRAC_CONST(0.4623677433), FRAC_CONST(0.8866882324) } },
{ { FRAC_CONST(0.6374240518), FRAC_CONST(-0.7705131769) }, { FRAC_CONST(-1.0000000000), FRAC_CONST(0.0000000000) }, { FRAC_CONST(-0.3446428776), FRAC_CONST(-0.9387338758) } },
{ { FRAC_CONST(-0.9048270583), FRAC_CONST(0.4257792532) }, { FRAC_CONST(-0.0000000000), FRAC_CONST(-1.0000000000) }, { FRAC_CONST(-0.5724321604), FRAC_CONST(0.8199520707) } },
{ { FRAC_CONST(-0.6129069924), FRAC_CONST(-0.7901550531) }, { FRAC_CONST(0.7071067691), FRAC_CONST(0.7071067691) }, { FRAC_CONST(-0.9917160273), FRAC_CONST(-0.1284494549) } },
{ { FRAC_CONST(-0.6129069924), FRAC_CONST(-0.7901550531) }, { FRAC_CONST(0.7071067691), FRAC_CONST(0.7071067691) }, { FRAC_CONST(-0.9917160273), FRAC_CONST(-0.1284494549) } },
{ { FRAC_CONST(0.6374240518), FRAC_CONST(-0.7705131769) }, { FRAC_CONST(-1.0000000000), FRAC_CONST(0.0000000000) }, { FRAC_CONST(-0.3446428776), FRAC_CONST(-0.9387338758) } },
{ { FRAC_CONST(0.6374240518), FRAC_CONST(-0.7705131769) }, { FRAC_CONST(-1.0000000000), FRAC_CONST(0.0000000000) }, { FRAC_CONST(-0.3446428776), FRAC_CONST(-0.9387338758) } },
{ { FRAC_CONST(0.8910064697), FRAC_CONST(0.4539906085) }, { FRAC_CONST(0.7071067691), FRAC_CONST(-0.7071067691) }, { FRAC_CONST(0.6730125546), FRAC_CONST(-0.7396310568) } },
{ { FRAC_CONST(-0.6129069924), FRAC_CONST(-0.7901550531) }, { FRAC_CONST(0.7071067691), FRAC_CONST(0.7071067691) }, { FRAC_CONST(-0.9917160273), FRAC_CONST(-0.1284494549) } }
};
#if 0
static float quant_rho[8] =
{
FRAC_CONST(1.0), FRAC_CONST(0.937), FRAC_CONST(0.84118), FRAC_CONST(0.60092),
FRAC_CONST(0.36764), FRAC_CONST(0.0), FRAC_CONST(-0.589), FRAC_CONST(-1.0)
};
static const uint8_t quant_iid_normal[7] =
{
2, 4, 7, 10, 14, 18, 25
};
static const uint8_t quant_iid_fine[15] =
{
2, 4, 6, 8, 10, 13, 16, 19, 22, 25, 30, 35, 40, 45, 50
};
#endif
static const real_t cos_alphas[] = {
COEF_CONST(1.0000000000), COEF_CONST(0.9841239700), COEF_CONST(0.9594738210),
COEF_CONST(0.8946843079), COEF_CONST(0.8269340931), COEF_CONST(0.7071067812),
COEF_CONST(0.4533210856), COEF_CONST(0.0000000000)
};
static const real_t sin_alphas[] = {
COEF_CONST(0.0000000000), COEF_CONST(0.1774824264), COEF_CONST(0.2817977763),
COEF_CONST(0.4466989918), COEF_CONST(0.5622988580), COEF_CONST(0.7071067812),
COEF_CONST(0.8913472911), COEF_CONST(1.0000000000)
};
static const real_t cos_betas_normal[][8] = {
{ COEF_CONST(1.0000000000), COEF_CONST(1.0000000000), COEF_CONST(1.0000000000), COEF_CONST(1.0000000000), COEF_CONST(1.0000000000), COEF_CONST(1.0000000000), COEF_CONST(1.0000000000), COEF_CONST(1.0000000000) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9995871699), COEF_CONST(0.9989419133), COEF_CONST(0.9972204583), COEF_CONST(0.9953790839), COEF_CONST(0.9920112747), COEF_CONST(0.9843408180), COEF_CONST(0.9681727381) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9984497744), COEF_CONST(0.9960279377), COEF_CONST(0.9895738413), COEF_CONST(0.9826814632), COEF_CONST(0.9701058164), COEF_CONST(0.9416098832), COEF_CONST(0.8822105900) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9959398908), COEF_CONST(0.9896038018), COEF_CONST(0.9727589768), COEF_CONST(0.9548355329), COEF_CONST(0.9223070404), COEF_CONST(0.8494349490), COEF_CONST(0.7013005535) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9932417400), COEF_CONST(0.9827071856), COEF_CONST(0.9547730996), COEF_CONST(0.9251668930), COEF_CONST(0.8717461589), COEF_CONST(0.7535520592), COEF_CONST(0.5198827312) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9902068095), COEF_CONST(0.9749613872), COEF_CONST(0.9346538534), COEF_CONST(0.8921231300), COEF_CONST(0.8158851259), COEF_CONST(0.6495964302), COEF_CONST(0.3313370772) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9880510933), COEF_CONST(0.9694670261), COEF_CONST(0.9204347876), COEF_CONST(0.8688622825), COEF_CONST(0.7768516704), COEF_CONST(0.5782161800), COEF_CONST(0.2069970356) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9858996945), COEF_CONST(0.9639898866), COEF_CONST(0.9063034786), COEF_CONST(0.8458214608), COEF_CONST(0.7384262300), COEF_CONST(0.5089811277), COEF_CONST(0.0905465944) }
};
static const real_t sin_betas_normal[][8] = {
{ COEF_CONST(0.0000000000), COEF_CONST(0.0000000000), COEF_CONST(0.0000000000), COEF_CONST(0.0000000000), COEF_CONST(0.0000000000), COEF_CONST(0.0000000000), COEF_CONST(0.0000000000), COEF_CONST(0.0000000000) },
{ COEF_CONST(0.0000000000), COEF_CONST(-0.0287313368), COEF_CONST(-0.0459897147), COEF_CONST(-0.0745074328), COEF_CONST(-0.0960233266), COEF_CONST(-0.1261492408), COEF_CONST(-0.1762757894), COEF_CONST(-0.2502829383) },
{ COEF_CONST(0.0000000000), COEF_CONST(-0.0556601118), COEF_CONST(-0.0890412670), COEF_CONST(-0.1440264301), COEF_CONST(-0.1853028382), COEF_CONST(-0.2426823129), COEF_CONST(-0.3367058477), COEF_CONST(-0.4708550466) },
{ COEF_CONST(0.0000000000), COEF_CONST(-0.0900207420), COEF_CONST(-0.1438204281), COEF_CONST(-0.2318188366), COEF_CONST(-0.2971348264), COEF_CONST(-0.3864579191), COEF_CONST(-0.5276933461), COEF_CONST(-0.7128657193) },
{ COEF_CONST(0.0000000000), COEF_CONST(-0.1160639735), COEF_CONST(-0.1851663774), COEF_CONST(-0.2973353800), COEF_CONST(-0.3795605619), COEF_CONST(-0.4899577884), COEF_CONST(-0.6573882369), COEF_CONST(-0.8542376401) },
{ COEF_CONST(0.0000000000), COEF_CONST(-0.1396082894), COEF_CONST(-0.2223742196), COEF_CONST(-0.3555589603), COEF_CONST(-0.4517923427), COEF_CONST(-0.5782140273), COEF_CONST(-0.7602792104), COEF_CONST(-0.9435124489) },
{ COEF_CONST(0.0000000000), COEF_CONST(-0.1541266914), COEF_CONST(-0.2452217065), COEF_CONST(-0.3908961522), COEF_CONST(-0.4950538699), COEF_CONST(-0.6296836366), COEF_CONST(-0.8158836002), COEF_CONST(-0.9783415698) },
{ COEF_CONST(0.0000000000), COEF_CONST(-0.1673373610), COEF_CONST(-0.2659389001), COEF_CONST(-0.4226275012), COEF_CONST(-0.5334660781), COEF_CONST(-0.6743342664), COEF_CONST(-0.8607776784), COEF_CONST(-0.9958922202) }
};
static const real_t cos_betas_fine[][8] = {
{ COEF_CONST(1.0000000000), COEF_CONST(1.0000000000), COEF_CONST(1.0000000000), COEF_CONST(1.0000000000), COEF_CONST(1.0000000000), COEF_CONST(1.0000000000), COEF_CONST(1.0000000000), COEF_CONST(1.0000000000) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9995871699), COEF_CONST(0.9989419133), COEF_CONST(0.9972204583), COEF_CONST(0.9953790839), COEF_CONST(0.9920112747), COEF_CONST(0.9843408180), COEF_CONST(0.9681727381) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9984497744), COEF_CONST(0.9960279377), COEF_CONST(0.9895738413), COEF_CONST(0.9826814632), COEF_CONST(0.9701058164), COEF_CONST(0.9416098832), COEF_CONST(0.8822105900) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9968361371), COEF_CONST(0.9918968104), COEF_CONST(0.9787540479), COEF_CONST(0.9647515190), COEF_CONST(0.9392903010), COEF_CONST(0.8820167114), COEF_CONST(0.7645325390) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9950262915), COEF_CONST(0.9872675041), COEF_CONST(0.9666584578), COEF_CONST(0.9447588606), COEF_CONST(0.9050918405), COEF_CONST(0.8165997379), COEF_CONST(0.6383824796) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9932417400), COEF_CONST(0.9827071856), COEF_CONST(0.9547730996), COEF_CONST(0.9251668930), COEF_CONST(0.8717461589), COEF_CONST(0.7535520592), COEF_CONST(0.5198827312) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9908827998), COEF_CONST(0.9766855904), COEF_CONST(0.9391249214), COEF_CONST(0.8994531782), COEF_CONST(0.8282352693), COEF_CONST(0.6723983174), COEF_CONST(0.3719473225) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9890240165), COEF_CONST(0.9719459866), COEF_CONST(0.9268448110), COEF_CONST(0.8793388536), COEF_CONST(0.7944023271), COEF_CONST(0.6101812098), COEF_CONST(0.2621501145) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9876350461), COEF_CONST(0.9684073447), COEF_CONST(0.9176973944), COEF_CONST(0.8643930070), COEF_CONST(0.7693796058), COEF_CONST(0.5646720713), COEF_CONST(0.1838899556) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9866247085), COEF_CONST(0.9658349704), COEF_CONST(0.9110590761), COEF_CONST(0.8535668048), COEF_CONST(0.7513165426), COEF_CONST(0.5320914819), COEF_CONST(0.1289530943) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9858996945), COEF_CONST(0.9639898866), COEF_CONST(0.9063034786), COEF_CONST(0.8458214608), COEF_CONST(0.7384262300), COEF_CONST(0.5089811277), COEF_CONST(0.0905465944) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9851245614), COEF_CONST(0.9620180268), COEF_CONST(0.9012265590), COEF_CONST(0.8375623272), COEF_CONST(0.7247108045), COEF_CONST(0.4845204297), COEF_CONST(0.0504115003) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9846869856), COEF_CONST(0.9609052357), COEF_CONST(0.8983639533), COEF_CONST(0.8329098386), COEF_CONST(0.7169983441), COEF_CONST(0.4708245354), COEF_CONST(0.0281732509) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9844406325), COEF_CONST(0.9602788522), COEF_CONST(0.8967533934), COEF_CONST(0.8302936455), COEF_CONST(0.7126658102), COEF_CONST(0.4631492839), COEF_CONST(0.0157851140) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9843020502), COEF_CONST(0.9599265269), COEF_CONST(0.8958477331), COEF_CONST(0.8288229094), COEF_CONST(0.7102315840), COEF_CONST(0.4588429315), COEF_CONST(0.0088578059) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9842241136), COEF_CONST(0.9597283916), COEF_CONST(0.8953385094), COEF_CONST(0.8279961409), COEF_CONST(0.7088635748), COEF_CONST(0.4564246834), COEF_CONST(0.0049751355) }
};
static const real_t sin_betas_fine[][8] = {
{ COEF_CONST(0.0000000000), COEF_CONST(0.0000000000), COEF_CONST(0.0000000000), COEF_CONST(0.0000000000), COEF_CONST(0.0000000000), COEF_CONST(0.0000000000), COEF_CONST(0.0000000000), COEF_CONST(0.0000000000) },
{ COEF_CONST(0.0000000000), COEF_CONST(-0.0287313368), COEF_CONST(-0.0459897147), COEF_CONST(-0.0745074328), COEF_CONST(-0.0960233266), COEF_CONST(-0.1261492408), COEF_CONST(-0.1762757894), COEF_CONST(-0.2502829383) },
{ COEF_CONST(0.0000000000), COEF_CONST(-0.0556601118), COEF_CONST(-0.0890412670), COEF_CONST(-0.1440264301), COEF_CONST(-0.1853028382), COEF_CONST(-0.2426823129), COEF_CONST(-0.3367058477), COEF_CONST(-0.4708550466) },
{ COEF_CONST(0.0000000000), COEF_CONST(-0.0794840594), COEF_CONST(-0.1270461238), COEF_CONST(-0.2050378347), COEF_CONST(-0.2631625097), COEF_CONST(-0.3431234916), COEF_CONST(-0.4712181245), COEF_CONST(-0.6445851354) },
{ COEF_CONST(0.0000000000), COEF_CONST(-0.0996126459), COEF_CONST(-0.1590687758), COEF_CONST(-0.2560691819), COEF_CONST(-0.3277662204), COEF_CONST(-0.4252161335), COEF_CONST(-0.5772043556), COEF_CONST(-0.7697193058) },
{ COEF_CONST(0.0000000000), COEF_CONST(-0.1160639735), COEF_CONST(-0.1851663774), COEF_CONST(-0.2973353800), COEF_CONST(-0.3795605619), COEF_CONST(-0.4899577884), COEF_CONST(-0.6573882369), COEF_CONST(-0.8542376401) },
{ COEF_CONST(0.0000000000), COEF_CONST(-0.1347266752), COEF_CONST(-0.2146747714), COEF_CONST(-0.3435758752), COEF_CONST(-0.4370171396), COEF_CONST(-0.5603805303), COEF_CONST(-0.7401895046), COEF_CONST(-0.9282538388) },
{ COEF_CONST(0.0000000000), COEF_CONST(-0.1477548470), COEF_CONST(-0.2352041647), COEF_CONST(-0.3754446647), COEF_CONST(-0.4761965776), COEF_CONST(-0.6073919186), COEF_CONST(-0.7922618830), COEF_CONST(-0.9650271071) },
{ COEF_CONST(0.0000000000), COEF_CONST(-0.1567705832), COEF_CONST(-0.2493736450), COEF_CONST(-0.3972801182), COEF_CONST(-0.5028167951), COEF_CONST(-0.6387918458), COEF_CONST(-0.8253153651), COEF_CONST(-0.9829468369) },
{ COEF_CONST(0.0000000000), COEF_CONST(-0.1630082348), COEF_CONST(-0.2591578860), COEF_CONST(-0.4122758299), COEF_CONST(-0.5209834064), COEF_CONST(-0.6599420072), COEF_CONST(-0.8466868694), COEF_CONST(-0.9916506943) },
{ COEF_CONST(0.0000000000), COEF_CONST(-0.1673373610), COEF_CONST(-0.2659389001), COEF_CONST(-0.4226275012), COEF_CONST(-0.5334660781), COEF_CONST(-0.6743342664), COEF_CONST(-0.8607776784), COEF_CONST(-0.9958922202) },
{ COEF_CONST(0.0000000000), COEF_CONST(-0.1718417832), COEF_CONST(-0.2729859267), COEF_CONST(-0.4333482310), COEF_CONST(-0.5463417868), COEF_CONST(-0.6890531546), COEF_CONST(-0.8747799456), COEF_CONST(-0.9987285320) },
{ COEF_CONST(0.0000000000), COEF_CONST(-0.1743316967), COEF_CONST(-0.2768774604), COEF_CONST(-0.4392518725), COEF_CONST(-0.5534087104), COEF_CONST(-0.6970748701), COEF_CONST(-0.8822268738), COEF_CONST(-0.9996030552) },
{ COEF_CONST(0.0000000000), COEF_CONST(-0.1757175038), COEF_CONST(-0.2790421580), COEF_CONST(-0.4425306221), COEF_CONST(-0.5573261722), COEF_CONST(-0.7015037013), COEF_CONST(-0.8862802834), COEF_CONST(-0.9998754073) },
{ COEF_CONST(0.0000000000), COEF_CONST(-0.1764921355), COEF_CONST(-0.2802517850), COEF_CONST(-0.4443611583), COEF_CONST(-0.5595110229), COEF_CONST(-0.7039681080), COEF_CONST(-0.8885173967), COEF_CONST(-0.9999607689) },
{ COEF_CONST(0.0000000000), COEF_CONST(-0.1769262394), COEF_CONST(-0.2809295540), COEF_CONST(-0.4453862969), COEF_CONST(-0.5607337966), COEF_CONST(-0.7053456119), COEF_CONST(-0.8897620516), COEF_CONST(-0.9999876239) }
};
static const real_t sincos_alphas_B_normal[][8] = {
{ COEF_CONST(0.0561454100), COEF_CONST(0.0526385859), COEF_CONST(0.0472937334), COEF_CONST(0.0338410641), COEF_CONST(0.0207261065), COEF_CONST(0.0028205635), COEF_CONST(0.0028205635), COEF_CONST(0.0028205635) },
{ COEF_CONST(0.1249065138), COEF_CONST(0.1173697697), COEF_CONST(0.1057888284), COEF_CONST(0.0761985131), COEF_CONST(0.0468732723), COEF_CONST(0.0063956103), COEF_CONST(0.0063956103), COEF_CONST(0.0063956103) },
{ COEF_CONST(0.1956693050), COEF_CONST(0.1846090179), COEF_CONST(0.1673645109), COEF_CONST(0.1220621836), COEF_CONST(0.0757362479), COEF_CONST(0.0103882630), COEF_CONST(0.0103882630), COEF_CONST(0.0103882630) },
{ COEF_CONST(0.3015113269), COEF_CONST(0.2870525790), COEF_CONST(0.2637738799), COEF_CONST(0.1984573949), COEF_CONST(0.1260749909), COEF_CONST(0.0175600126), COEF_CONST(0.0175600126), COEF_CONST(0.0175600126) },
{ COEF_CONST(0.4078449476), COEF_CONST(0.3929852420), COEF_CONST(0.3680589270), COEF_CONST(0.2911029124), COEF_CONST(0.1934512363), COEF_CONST(0.0278686716), COEF_CONST(0.0278686716), COEF_CONST(0.0278686716) },
{ COEF_CONST(0.5336171261), COEF_CONST(0.5226637762), COEF_CONST(0.5033652606), COEF_CONST(0.4349162672), COEF_CONST(0.3224682122), COEF_CONST(0.0521999036), COEF_CONST(0.0521999036), COEF_CONST(0.0521999036) },
{ COEF_CONST(0.6219832023), COEF_CONST(0.6161847276), COEF_CONST(0.6057251063), COEF_CONST(0.5654342668), COEF_CONST(0.4826149915), COEF_CONST(0.1058044758), COEF_CONST(0.1058044758), COEF_CONST(0.1058044758) },
{ COEF_CONST(0.7071067657), COEF_CONST(0.7071067657), COEF_CONST(0.7071067657), COEF_CONST(0.7071067657), COEF_CONST(0.7071067657), COEF_CONST(0.7071067657), COEF_CONST(0.7071067657), COEF_CONST(0.7071067657) },
{ COEF_CONST(0.7830305572), COEF_CONST(0.7876016373), COEF_CONST(0.7956739618), COEF_CONST(0.8247933372), COEF_CONST(0.8758325942), COEF_CONST(0.9943869542), COEF_CONST(0.9943869542), COEF_CONST(0.9943869542) },
{ COEF_CONST(0.8457261833), COEF_CONST(0.8525388778), COEF_CONST(0.8640737401), COEF_CONST(0.9004708933), COEF_CONST(0.9465802987), COEF_CONST(0.9986366532), COEF_CONST(0.9986366532), COEF_CONST(0.9986366532) },
{ COEF_CONST(0.9130511848), COEF_CONST(0.9195447612), COEF_CONST(0.9298024282), COEF_CONST(0.9566917233), COEF_CONST(0.9811098801), COEF_CONST(0.9996115928), COEF_CONST(0.9996115928), COEF_CONST(0.9996115928) },
{ COEF_CONST(0.9534625907), COEF_CONST(0.9579148236), COEF_CONST(0.9645845234), COEF_CONST(0.9801095128), COEF_CONST(0.9920207064), COEF_CONST(0.9998458099), COEF_CONST(0.9998458099), COEF_CONST(0.9998458099) },
{ COEF_CONST(0.9806699215), COEF_CONST(0.9828120260), COEF_CONST(0.9858950861), COEF_CONST(0.9925224431), COEF_CONST(0.9971278825), COEF_CONST(0.9999460406), COEF_CONST(0.9999460406), COEF_CONST(0.9999460406) },
{ COEF_CONST(0.9921685024), COEF_CONST(0.9930882705), COEF_CONST(0.9943886135), COEF_CONST(0.9970926648), COEF_CONST(0.9989008403), COEF_CONST(0.9999795479), COEF_CONST(0.9999795479), COEF_CONST(0.9999795479) },
{ COEF_CONST(0.9984226014), COEF_CONST(0.9986136287), COEF_CONST(0.9988810254), COEF_CONST(0.9994272242), COEF_CONST(0.9997851906), COEF_CONST(0.9999960221), COEF_CONST(0.9999960221), COEF_CONST(0.9999960221) }
};
static const real_t sincos_alphas_B_fine[][8] = {
{ COEF_CONST(0.0031622158), COEF_CONST(0.0029630181), COEF_CONST(0.0026599892), COEF_CONST(0.0019002704), COEF_CONST(0.0011626042), COEF_CONST(0.0001580278), COEF_CONST(0.0001580278), COEF_CONST(0.0001580278) },
{ COEF_CONST(0.0056232673), COEF_CONST(0.0052689825), COEF_CONST(0.0047302825), COEF_CONST(0.0033791756), COEF_CONST(0.0020674015), COEF_CONST(0.0002811710), COEF_CONST(0.0002811710), COEF_CONST(0.0002811710) },
{ COEF_CONST(0.0099994225), COEF_CONST(0.0093696693), COEF_CONST(0.0084117414), COEF_CONST(0.0060093796), COEF_CONST(0.0036766009), COEF_CONST(0.0005000392), COEF_CONST(0.0005000392), COEF_CONST(0.0005000392) },
{ COEF_CONST(0.0177799194), COEF_CONST(0.0166607102), COEF_CONST(0.0149581377), COEF_CONST(0.0106875809), COEF_CONST(0.0065392545), COEF_CONST(0.0008893767), COEF_CONST(0.0008893767), COEF_CONST(0.0008893767) },
{ COEF_CONST(0.0316069684), COEF_CONST(0.0296211579), COEF_CONST(0.0265987295), COEF_CONST(0.0190113813), COEF_CONST(0.0116349973), COEF_CONST(0.0015826974), COEF_CONST(0.0015826974), COEF_CONST(0.0015826974) },
{ COEF_CONST(0.0561454100), COEF_CONST(0.0526385859), COEF_CONST(0.0472937334), COEF_CONST(0.0338410641), COEF_CONST(0.0207261065), COEF_CONST(0.0028205635), COEF_CONST(0.0028205635), COEF_CONST(0.0028205635) },
{ COEF_CONST(0.0791834041), COEF_CONST(0.0742798103), COEF_CONST(0.0667907269), COEF_CONST(0.0478705292), COEF_CONST(0.0293500747), COEF_CONST(0.0039966755), COEF_CONST(0.0039966755), COEF_CONST(0.0039966755) },
{ COEF_CONST(0.1115021177), COEF_CONST(0.1047141985), COEF_CONST(0.0943053154), COEF_CONST(0.0678120561), COEF_CONST(0.0416669150), COEF_CONST(0.0056813213), COEF_CONST(0.0056813213), COEF_CONST(0.0056813213) },
{ COEF_CONST(0.1565355066), COEF_CONST(0.1473258371), COEF_CONST(0.1330924027), COEF_CONST(0.0963282233), COEF_CONST(0.0594509113), COEF_CONST(0.0081277946), COEF_CONST(0.0081277946), COEF_CONST(0.0081277946) },
{ COEF_CONST(0.2184643682), COEF_CONST(0.2064579524), COEF_CONST(0.1876265439), COEF_CONST(0.1375744167), COEF_CONST(0.0856896681), COEF_CONST(0.0117817338), COEF_CONST(0.0117817338), COEF_CONST(0.0117817338) },
{ COEF_CONST(0.3015113269), COEF_CONST(0.2870525790), COEF_CONST(0.2637738799), COEF_CONST(0.1984573949), COEF_CONST(0.1260749909), COEF_CONST(0.0175600126), COEF_CONST(0.0175600126), COEF_CONST(0.0175600126) },
{ COEF_CONST(0.3698741335), COEF_CONST(0.3547727297), COEF_CONST(0.3298252076), COEF_CONST(0.2556265829), COEF_CONST(0.1665990017), COEF_CONST(0.0236344541), COEF_CONST(0.0236344541), COEF_CONST(0.0236344541) },
{ COEF_CONST(0.4480623975), COEF_CONST(0.4339410024), COEF_CONST(0.4098613774), COEF_CONST(0.3322709108), COEF_CONST(0.2266784729), COEF_CONST(0.0334094131), COEF_CONST(0.0334094131), COEF_CONST(0.0334094131) },
{ COEF_CONST(0.5336171261), COEF_CONST(0.5226637762), COEF_CONST(0.5033652606), COEF_CONST(0.4349162672), COEF_CONST(0.3224682122), COEF_CONST(0.0521999036), COEF_CONST(0.0521999036), COEF_CONST(0.0521999036) },
{ COEF_CONST(0.6219832023), COEF_CONST(0.6161847276), COEF_CONST(0.6057251063), COEF_CONST(0.5654342668), COEF_CONST(0.4826149915), COEF_CONST(0.1058044758), COEF_CONST(0.1058044758), COEF_CONST(0.1058044758) },
{ COEF_CONST(0.7071067657), COEF_CONST(0.7071067657), COEF_CONST(0.7071067657), COEF_CONST(0.7071067657), COEF_CONST(0.7071067657), COEF_CONST(0.7071067657), COEF_CONST(0.7071067657), COEF_CONST(0.7071067657) },
{ COEF_CONST(0.7830305572), COEF_CONST(0.7876016373), COEF_CONST(0.7956739618), COEF_CONST(0.8247933372), COEF_CONST(0.8758325942), COEF_CONST(0.9943869542), COEF_CONST(0.9943869542), COEF_CONST(0.9943869542) },
{ COEF_CONST(0.8457261833), COEF_CONST(0.8525388778), COEF_CONST(0.8640737401), COEF_CONST(0.9004708933), COEF_CONST(0.9465802987), COEF_CONST(0.9986366532), COEF_CONST(0.9986366532), COEF_CONST(0.9986366532) },
{ COEF_CONST(0.8940022267), COEF_CONST(0.9009412572), COEF_CONST(0.9121477564), COEF_CONST(0.9431839770), COEF_CONST(0.9739696219), COEF_CONST(0.9994417480), COEF_CONST(0.9994417480), COEF_CONST(0.9994417480) },
{ COEF_CONST(0.9290818561), COEF_CONST(0.9349525662), COEF_CONST(0.9440420138), COEF_CONST(0.9667755833), COEF_CONST(0.9860247275), COEF_CONST(0.9997206664), COEF_CONST(0.9997206664), COEF_CONST(0.9997206664) },
{ COEF_CONST(0.9534625907), COEF_CONST(0.9579148236), COEF_CONST(0.9645845234), COEF_CONST(0.9801095128), COEF_CONST(0.9920207064), COEF_CONST(0.9998458099), COEF_CONST(0.9998458099), COEF_CONST(0.9998458099) },
{ COEF_CONST(0.9758449068), COEF_CONST(0.9784554646), COEF_CONST(0.9822404252), COEF_CONST(0.9904914275), COEF_CONST(0.9963218730), COEF_CONST(0.9999305926), COEF_CONST(0.9999305926), COEF_CONST(0.9999305926) },
{ COEF_CONST(0.9876723320), COEF_CONST(0.9890880155), COEF_CONST(0.9911036356), COEF_CONST(0.9953496173), COEF_CONST(0.9982312259), COEF_CONST(0.9999669685), COEF_CONST(0.9999669685), COEF_CONST(0.9999669685) },
{ COEF_CONST(0.9937641889), COEF_CONST(0.9945023501), COEF_CONST(0.9955433130), COEF_CONST(0.9976981117), COEF_CONST(0.9991315558), COEF_CONST(0.9999838610), COEF_CONST(0.9999838610), COEF_CONST(0.9999838610) },
{ COEF_CONST(0.9968600642), COEF_CONST(0.9972374385), COEF_CONST(0.9977670024), COEF_CONST(0.9988535464), COEF_CONST(0.9995691924), COEF_CONST(0.9999920129), COEF_CONST(0.9999920129), COEF_CONST(0.9999920129) },
{ COEF_CONST(0.9984226014), COEF_CONST(0.9986136287), COEF_CONST(0.9988810254), COEF_CONST(0.9994272242), COEF_CONST(0.9997851906), COEF_CONST(0.9999960221), COEF_CONST(0.9999960221), COEF_CONST(0.9999960221) },
{ COEF_CONST(0.9995003746), COEF_CONST(0.9995611974), COEF_CONST(0.9996461891), COEF_CONST(0.9998192657), COEF_CONST(0.9999323103), COEF_CONST(0.9999987475), COEF_CONST(0.9999987475), COEF_CONST(0.9999987475) },
{ COEF_CONST(0.9998419236), COEF_CONST(0.9998611991), COEF_CONST(0.9998881193), COEF_CONST(0.9999428861), COEF_CONST(0.9999786185), COEF_CONST(0.9999996045), COEF_CONST(0.9999996045), COEF_CONST(0.9999996045) },
{ COEF_CONST(0.9999500038), COEF_CONST(0.9999561034), COEF_CONST(0.9999646206), COEF_CONST(0.9999819429), COEF_CONST(0.9999932409), COEF_CONST(0.9999998750), COEF_CONST(0.9999998750), COEF_CONST(0.9999998750) },
{ COEF_CONST(0.9999841890), COEF_CONST(0.9999861183), COEF_CONST(0.9999888121), COEF_CONST(0.9999942902), COEF_CONST(0.9999978628), COEF_CONST(0.9999999605), COEF_CONST(0.9999999605), COEF_CONST(0.9999999605) },
{ COEF_CONST(0.9999950000), COEF_CONST(0.9999956102), COEF_CONST(0.9999964621), COEF_CONST(0.9999981945), COEF_CONST(0.9999993242), COEF_CONST(0.9999999875), COEF_CONST(0.9999999875), COEF_CONST(0.9999999875) }
};
static const real_t cos_gammas_normal[][8] = {
{ COEF_CONST(1.0000000000), COEF_CONST(0.9841239707), COEF_CONST(0.9594738226), COEF_CONST(0.8946843024), COEF_CONST(0.8269341029), COEF_CONST(0.7245688486), COEF_CONST(0.7245688486), COEF_CONST(0.7245688486) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9849690570), COEF_CONST(0.9617776789), COEF_CONST(0.9020941550), COEF_CONST(0.8436830391), COEF_CONST(0.7846832804), COEF_CONST(0.7846832804), COEF_CONST(0.7846832804) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9871656089), COEF_CONST(0.9676774734), COEF_CONST(0.9199102884), COEF_CONST(0.8785067015), COEF_CONST(0.8464232214), COEF_CONST(0.8464232214), COEF_CONST(0.8464232214) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9913533967), COEF_CONST(0.9786000177), COEF_CONST(0.9496063381), COEF_CONST(0.9277157252), COEF_CONST(0.9133354077), COEF_CONST(0.9133354077), COEF_CONST(0.9133354077) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9948924435), COEF_CONST(0.9875319180), COEF_CONST(0.9716329849), COEF_CONST(0.9604805241), COEF_CONST(0.9535949574), COEF_CONST(0.9535949574), COEF_CONST(0.9535949574) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9977406278), COEF_CONST(0.9945423840), COEF_CONST(0.9878736667), COEF_CONST(0.9833980494), COEF_CONST(0.9807207440), COEF_CONST(0.9807207440), COEF_CONST(0.9807207440) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9990607067), COEF_CONST(0.9977417734), COEF_CONST(0.9950323970), COEF_CONST(0.9932453273), COEF_CONST(0.9921884740), COEF_CONST(0.9921884740), COEF_CONST(0.9921884740) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9998081748), COEF_CONST(0.9995400312), COEF_CONST(0.9989936459), COEF_CONST(0.9986365356), COEF_CONST(0.9984265591), COEF_CONST(0.9984265591), COEF_CONST(0.9984265591) }
};
static const real_t cos_gammas_fine[][8] = {
{ COEF_CONST(1.0000000000), COEF_CONST(0.9841239707), COEF_CONST(0.9594738226), COEF_CONST(0.8946843024), COEF_CONST(0.8269341029), COEF_CONST(0.7245688486), COEF_CONST(0.7245688486), COEF_CONST(0.7245688486) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9849690570), COEF_CONST(0.9617776789), COEF_CONST(0.9020941550), COEF_CONST(0.8436830391), COEF_CONST(0.7846832804), COEF_CONST(0.7846832804), COEF_CONST(0.7846832804) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9871656089), COEF_CONST(0.9676774734), COEF_CONST(0.9199102884), COEF_CONST(0.8785067015), COEF_CONST(0.8464232214), COEF_CONST(0.8464232214), COEF_CONST(0.8464232214) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9899597309), COEF_CONST(0.9750098690), COEF_CONST(0.9402333855), COEF_CONST(0.9129698759), COEF_CONST(0.8943765944), COEF_CONST(0.8943765944), COEF_CONST(0.8943765944) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9926607607), COEF_CONST(0.9819295710), COEF_CONST(0.9580160104), COEF_CONST(0.9404993670), COEF_CONST(0.9293004472), COEF_CONST(0.9293004472), COEF_CONST(0.9293004472) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9948924435), COEF_CONST(0.9875319180), COEF_CONST(0.9716329849), COEF_CONST(0.9604805241), COEF_CONST(0.9535949574), COEF_CONST(0.9535949574), COEF_CONST(0.9535949574) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9972074644), COEF_CONST(0.9932414270), COEF_CONST(0.9849197629), COEF_CONST(0.9792926592), COEF_CONST(0.9759092525), COEF_CONST(0.9759092525), COEF_CONST(0.9759092525) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9985361982), COEF_CONST(0.9964742028), COEF_CONST(0.9922136306), COEF_CONST(0.9893845420), COEF_CONST(0.9877041371), COEF_CONST(0.9877041371), COEF_CONST(0.9877041371) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9992494366), COEF_CONST(0.9981967170), COEF_CONST(0.9960386625), COEF_CONST(0.9946185834), COEF_CONST(0.9937800239), COEF_CONST(0.9937800239), COEF_CONST(0.9937800239) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9996194722), COEF_CONST(0.9990869422), COEF_CONST(0.9979996269), COEF_CONST(0.9972873651), COEF_CONST(0.9968679747), COEF_CONST(0.9968679747), COEF_CONST(0.9968679747) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9998081748), COEF_CONST(0.9995400312), COEF_CONST(0.9989936459), COEF_CONST(0.9986365356), COEF_CONST(0.9984265591), COEF_CONST(0.9984265591), COEF_CONST(0.9984265591) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9999390971), COEF_CONST(0.9998540271), COEF_CONST(0.9996809352), COEF_CONST(0.9995679735), COEF_CONST(0.9995016284), COEF_CONST(0.9995016284), COEF_CONST(0.9995016284) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9999807170), COEF_CONST(0.9999537862), COEF_CONST(0.9998990191), COEF_CONST(0.9998632947), COEF_CONST(0.9998423208), COEF_CONST(0.9998423208), COEF_CONST(0.9998423208) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9999938979), COEF_CONST(0.9999853814), COEF_CONST(0.9999680568), COEF_CONST(0.9999567596), COEF_CONST(0.9999501270), COEF_CONST(0.9999501270), COEF_CONST(0.9999501270) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9999980703), COEF_CONST(0.9999953731), COEF_CONST(0.9999898968), COEF_CONST(0.9999863277), COEF_CONST(0.9999842265), COEF_CONST(0.9999842265), COEF_CONST(0.9999842265) },
{ COEF_CONST(1.0000000000), COEF_CONST(0.9999993891), COEF_CONST(0.9999985397), COEF_CONST(0.9999968037), COEF_CONST(0.9999956786), COEF_CONST(0.9999950155), COEF_CONST(0.9999950155), COEF_CONST(0.9999950155) }
};
static const real_t sin_gammas_normal[][8] = {
{ COEF_CONST(0.0000000000), COEF_CONST(0.1774824223), COEF_CONST(0.2817977711), COEF_CONST(0.4466990028), COEF_CONST(0.5622988435), COEF_CONST(0.6892024258), COEF_CONST(0.6892024258), COEF_CONST(0.6892024258) },
{ COEF_CONST(0.0000000000), COEF_CONST(0.1727308798), COEF_CONST(0.2738315110), COEF_CONST(0.4315392630), COEF_CONST(0.5368416242), COEF_CONST(0.6198968861), COEF_CONST(0.6198968861), COEF_CONST(0.6198968861) },
{ COEF_CONST(0.0000000000), COEF_CONST(0.1596999079), COEF_CONST(0.2521910140), COEF_CONST(0.3921288836), COEF_CONST(0.4777300236), COEF_CONST(0.5325107795), COEF_CONST(0.5325107795), COEF_CONST(0.5325107795) },
{ COEF_CONST(0.0000000000), COEF_CONST(0.1312190642), COEF_CONST(0.2057717310), COEF_CONST(0.3134450552), COEF_CONST(0.3732874674), COEF_CONST(0.4072080955), COEF_CONST(0.4072080955), COEF_CONST(0.4072080955) },
{ COEF_CONST(0.0000000000), COEF_CONST(0.1009407043), COEF_CONST(0.1574189028), COEF_CONST(0.2364938532), COEF_CONST(0.2783471983), COEF_CONST(0.3010924396), COEF_CONST(0.3010924396), COEF_CONST(0.3010924396) },
{ COEF_CONST(0.0000000000), COEF_CONST(0.0671836269), COEF_CONST(0.1043333428), COEF_CONST(0.1552598422), COEF_CONST(0.1814615013), COEF_CONST(0.1954144885), COEF_CONST(0.1954144885), COEF_CONST(0.1954144885) },
{ COEF_CONST(0.0000000000), COEF_CONST(0.0433324862), COEF_CONST(0.0671666110), COEF_CONST(0.0995516398), COEF_CONST(0.1160332699), COEF_CONST(0.1247478739), COEF_CONST(0.1247478739), COEF_CONST(0.1247478739) },
{ COEF_CONST(0.0000000000), COEF_CONST(0.0195860576), COEF_CONST(0.0303269852), COEF_CONST(0.0448519274), COEF_CONST(0.0522022017), COEF_CONST(0.0560750040), COEF_CONST(0.0560750040), COEF_CONST(0.0560750040) }
};
static const real_t sin_gammas_fine[][8] = {
{ COEF_CONST(0.0000000000), COEF_CONST(0.1774824223), COEF_CONST(0.2817977711), COEF_CONST(0.4466990028), COEF_CONST(0.5622988435), COEF_CONST(0.6892024258), COEF_CONST(0.6892024258), COEF_CONST(0.6892024258) },
{ COEF_CONST(0.0000000000), COEF_CONST(0.1727308798), COEF_CONST(0.2738315110), COEF_CONST(0.4315392630), COEF_CONST(0.5368416242), COEF_CONST(0.6198968861), COEF_CONST(0.6198968861), COEF_CONST(0.6198968861) },
{ COEF_CONST(0.0000000000), COEF_CONST(0.1596999079), COEF_CONST(0.2521910140), COEF_CONST(0.3921288836), COEF_CONST(0.4777300236), COEF_CONST(0.5325107795), COEF_CONST(0.5325107795), COEF_CONST(0.5325107795) },
{ COEF_CONST(0.0000000000), COEF_CONST(0.1413496768), COEF_CONST(0.2221615526), COEF_CONST(0.3405307340), COEF_CONST(0.4080269669), COEF_CONST(0.4473147744), COEF_CONST(0.4473147744), COEF_CONST(0.4473147744) },
{ COEF_CONST(0.0000000000), COEF_CONST(0.1209322714), COEF_CONST(0.1892467110), COEF_CONST(0.2867147079), COEF_CONST(0.3397954394), COEF_CONST(0.3693246252), COEF_CONST(0.3693246252), COEF_CONST(0.3693246252) },
{ COEF_CONST(0.0000000000), COEF_CONST(0.1009407043), COEF_CONST(0.1574189028), COEF_CONST(0.2364938532), COEF_CONST(0.2783471983), COEF_CONST(0.3010924396), COEF_CONST(0.3010924396), COEF_CONST(0.3010924396) },
{ COEF_CONST(0.0000000000), COEF_CONST(0.0746811420), COEF_CONST(0.1160666523), COEF_CONST(0.1730117353), COEF_CONST(0.2024497161), COEF_CONST(0.2181768341), COEF_CONST(0.2181768341), COEF_CONST(0.2181768341) },
{ COEF_CONST(0.0000000000), COEF_CONST(0.0540875291), COEF_CONST(0.0838997203), COEF_CONST(0.1245476266), COEF_CONST(0.1453211203), COEF_CONST(0.1563346972), COEF_CONST(0.1563346972), COEF_CONST(0.1563346972) },
{ COEF_CONST(0.0000000000), COEF_CONST(0.0387371058), COEF_CONST(0.0600276114), COEF_CONST(0.0889212171), COEF_CONST(0.1036044086), COEF_CONST(0.1113609634), COEF_CONST(0.1113609634), COEF_CONST(0.1113609634) },
{ COEF_CONST(0.0000000000), COEF_CONST(0.0275846110), COEF_CONST(0.0427233177), COEF_CONST(0.0632198125), COEF_CONST(0.0736064637), COEF_CONST(0.0790837596), COEF_CONST(0.0790837596), COEF_CONST(0.0790837596) },
{ COEF_CONST(0.0000000000), COEF_CONST(0.0195860576), COEF_CONST(0.0303269852), COEF_CONST(0.0448519274), COEF_CONST(0.0522022017), COEF_CONST(0.0560750040), COEF_CONST(0.0560750040), COEF_CONST(0.0560750040) },
{ COEF_CONST(0.0000000000), COEF_CONST(0.0110363955), COEF_CONST(0.0170857974), COEF_CONST(0.0252592108), COEF_CONST(0.0293916021), COEF_CONST(0.0315673054), COEF_CONST(0.0315673054), COEF_CONST(0.0315673054) },
{ COEF_CONST(0.0000000000), COEF_CONST(0.0062101284), COEF_CONST(0.0096138203), COEF_CONST(0.0142109649), COEF_CONST(0.0165345659), COEF_CONST(0.0177576316), COEF_CONST(0.0177576316), COEF_CONST(0.0177576316) },
{ COEF_CONST(0.0000000000), COEF_CONST(0.0034934509), COEF_CONST(0.0054071189), COEF_CONST(0.0079928316), COEF_CONST(0.0092994041), COEF_CONST(0.0099871631), COEF_CONST(0.0099871631), COEF_CONST(0.0099871631) },
{ COEF_CONST(0.0000000000), COEF_CONST(0.0019645397), COEF_CONST(0.0030419905), COEF_CONST(0.0044951511), COEF_CONST(0.0052291853), COEF_CONST(0.0056166498), COEF_CONST(0.0056166498), COEF_CONST(0.0056166498) },
{ COEF_CONST(0.0000000000), COEF_CONST(0.0011053943), COEF_CONST(0.0017089869), COEF_CONST(0.0025283670), COEF_CONST(0.0029398552), COEF_CONST(0.0031573685), COEF_CONST(0.0031573685), COEF_CONST(0.0031573685) }
};
static const real_t sf_iid_normal[] = {
COEF_CONST(1.4119827747), COEF_CONST(1.4031381607), COEF_CONST(1.3868767023),
COEF_CONST(1.3483997583), COEF_CONST(1.2912493944), COEF_CONST(1.1960374117),
COEF_CONST(1.1073724031), COEF_CONST(1.0000000000), COEF_CONST(0.8796171546),
COEF_CONST(0.7546485662), COEF_CONST(0.5767799020), COEF_CONST(0.4264014363),
COEF_CONST(0.2767182887), COEF_CONST(0.1766446233), COEF_CONST(0.0794016272)
};
static const real_t sf_iid_fine[] = {
COEF_CONST(1.4142065048), COEF_CONST(1.4141912460), COEF_CONST(1.4141428471),
COEF_CONST(1.4139900208), COEF_CONST(1.4135069847), COEF_CONST(1.4119827747),
COEF_CONST(1.4097729921), COEF_CONST(1.4053947926), COEF_CONST(1.3967796564),
COEF_CONST(1.3800530434), COEF_CONST(1.3483997583), COEF_CONST(1.3139201403),
COEF_CONST(1.2643101215), COEF_CONST(1.1960374117), COEF_CONST(1.1073724031),
COEF_CONST(1.0000000000), COEF_CONST(0.8796171546), COEF_CONST(0.7546485662),
COEF_CONST(0.6336560845), COEF_CONST(0.5230810642), COEF_CONST(0.4264014363),
COEF_CONST(0.3089554012), COEF_CONST(0.2213746458), COEF_CONST(0.1576878875),
COEF_CONST(0.1119822487), COEF_CONST(0.0794016272), COEF_CONST(0.0446990170),
COEF_CONST(0.0251446925), COEF_CONST(0.0141414283), COEF_CONST(0.0079525812),
COEF_CONST(0.0044721137)
};
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,58 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: pulse.c,v 1.21 2007/11/01 12:33:34 menno Exp $
**/
#include "common.h"
#include "structs.h"
#include "syntax.h"
#include "pulse.h"
uint8_t pulse_decode(ic_stream *ics, int16_t *spec_data, uint16_t framelen)
{
uint8_t i;
uint16_t k;
pulse_info *pul = &(ics->pul);
k = min(ics->swb_offset[pul->pulse_start_sfb], ics->swb_offset_max);
for (i = 0; i <= pul->number_pulse; i++)
{
k += pul->pulse_offset[i];
if (k >= framelen)
return 15; /* should not be possible */
if (spec_data[k] > 0)
spec_data[k] += pul->pulse_amp[i];
else
spec_data[k] -= pul->pulse_amp[i];
}
return 0;
}

View File

@ -0,0 +1,43 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: pulse.h,v 1.20 2007/11/01 12:33:34 menno Exp $
**/
#ifndef __PULSE_H__
#define __PULSE_H__
#ifdef __cplusplus
extern "C" {
#endif
uint8_t pulse_decode(ic_stream *ics, int16_t *spec_coef, uint16_t framelen);
#ifdef __cplusplus
}
#endif
#endif

533
tests/Audio/libFaad/rvlc.c Normal file
View File

@ -0,0 +1,533 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: rvlc.c,v 1.21 2007/11/01 12:33:34 menno Exp $
**/
/* RVLC scalefactor decoding
*
* RVLC works like this:
* 1. Only symmetric huffman codewords are used
* 2. Total length of the scalefactor data is stored in the bitsream
* 3. Scalefactors are DPCM coded
* 4. Next to the starting value for DPCM the ending value is also stored
*
* With all this it is possible to read the scalefactor data from 2 sides.
* If there is a bit error in the scalefactor data it is possible to start
* decoding from the other end of the data, to find all but 1 scalefactor.
*/
#include "common.h"
#include "structs.h"
#include <stdlib.h>
#include "syntax.h"
#include "bits.h"
#include "rvlc.h"
#ifdef ERROR_RESILIENCE
//#define PRINT_RVLC
/* static function declarations */
static uint8_t rvlc_decode_sf_forward(ic_stream *ics,
bitfile *ld_sf,
bitfile *ld_esc,
uint8_t *is_used);
#if 0
static uint8_t rvlc_decode_sf_reverse(ic_stream *ics,
bitfile *ld_sf,
bitfile *ld_esc,
uint8_t is_used);
#endif
static int8_t rvlc_huffman_sf(bitfile *ld_sf, bitfile *ld_esc,
int8_t direction);
static int8_t rvlc_huffman_esc(bitfile *ld_esc, int8_t direction);
uint8_t rvlc_scale_factor_data(ic_stream *ics, bitfile *ld)
{
uint8_t bits = 9;
ics->sf_concealment = faad_get1bit(ld
DEBUGVAR(1,149,"rvlc_scale_factor_data(): sf_concealment"));
ics->rev_global_gain = (uint8_t)faad_getbits(ld, 8
DEBUGVAR(1,150,"rvlc_scale_factor_data(): rev_global_gain"));
if (ics->window_sequence == EIGHT_SHORT_SEQUENCE)
bits = 11;
/* the number of bits used for the huffman codewords */
ics->length_of_rvlc_sf = (uint16_t)faad_getbits(ld, bits
DEBUGVAR(1,151,"rvlc_scale_factor_data(): length_of_rvlc_sf"));
if (ics->noise_used)
{
ics->dpcm_noise_nrg = (uint16_t)faad_getbits(ld, 9
DEBUGVAR(1,152,"rvlc_scale_factor_data(): dpcm_noise_nrg"));
ics->length_of_rvlc_sf -= 9;
}
ics->sf_escapes_present = faad_get1bit(ld
DEBUGVAR(1,153,"rvlc_scale_factor_data(): sf_escapes_present"));
if (ics->sf_escapes_present)
{
ics->length_of_rvlc_escapes = (uint8_t)faad_getbits(ld, 8
DEBUGVAR(1,154,"rvlc_scale_factor_data(): length_of_rvlc_escapes"));
}
if (ics->noise_used)
{
ics->dpcm_noise_last_position = (uint16_t)faad_getbits(ld, 9
DEBUGVAR(1,155,"rvlc_scale_factor_data(): dpcm_noise_last_position"));
}
return 0;
}
uint8_t rvlc_decode_scale_factors(ic_stream *ics, bitfile *ld)
{
uint8_t result;
uint8_t intensity_used = 0;
uint8_t *rvlc_sf_buffer = NULL;
uint8_t *rvlc_esc_buffer = NULL;
bitfile ld_rvlc_sf, ld_rvlc_esc;
// bitfile ld_rvlc_sf_rev, ld_rvlc_esc_rev;
if (ics->length_of_rvlc_sf > 0)
{
/* We read length_of_rvlc_sf bits here to put it in a
seperate bitfile.
*/
rvlc_sf_buffer = faad_getbitbuffer(ld, ics->length_of_rvlc_sf
DEBUGVAR(1,156,"rvlc_decode_scale_factors(): bitbuffer: length_of_rvlc_sf"));
faad_initbits(&ld_rvlc_sf, (void*)rvlc_sf_buffer, bit2byte(ics->length_of_rvlc_sf));
// faad_initbits_rev(&ld_rvlc_sf_rev, (void*)rvlc_sf_buffer,
// ics->length_of_rvlc_sf);
}
if (ics->sf_escapes_present)
{
/* We read length_of_rvlc_escapes bits here to put it in a
seperate bitfile.
*/
rvlc_esc_buffer = faad_getbitbuffer(ld, ics->length_of_rvlc_escapes
DEBUGVAR(1,157,"rvlc_decode_scale_factors(): bitbuffer: length_of_rvlc_escapes"));
faad_initbits(&ld_rvlc_esc, (void*)rvlc_esc_buffer, bit2byte(ics->length_of_rvlc_escapes));
// faad_initbits_rev(&ld_rvlc_esc_rev, (void*)rvlc_esc_buffer,
// ics->length_of_rvlc_escapes);
}
/* decode the rvlc scale factors and escapes */
result = rvlc_decode_sf_forward(ics, &ld_rvlc_sf,
&ld_rvlc_esc, &intensity_used);
// result = rvlc_decode_sf_reverse(ics, &ld_rvlc_sf_rev,
// &ld_rvlc_esc_rev, intensity_used);
if (rvlc_esc_buffer) faad_free(rvlc_esc_buffer);
if (rvlc_sf_buffer) faad_free(rvlc_sf_buffer);
if (ics->length_of_rvlc_sf > 0)
faad_endbits(&ld_rvlc_sf);
if (ics->sf_escapes_present)
faad_endbits(&ld_rvlc_esc);
return result;
}
static uint8_t rvlc_decode_sf_forward(ic_stream *ics, bitfile *ld_sf, bitfile *ld_esc,
uint8_t *intensity_used)
{
int8_t g, sfb;
int8_t t = 0;
int8_t error = 0;
int8_t noise_pcm_flag = 1;
int16_t scale_factor = ics->global_gain;
int16_t is_position = 0;
int16_t noise_energy = ics->global_gain - 90 - 256;
#ifdef PRINT_RVLC
printf("\nglobal_gain: %d\n", ics->global_gain);
#endif
for (g = 0; g < ics->num_window_groups; g++)
{
for (sfb = 0; sfb < ics->max_sfb; sfb++)
{
if (error)
{
ics->scale_factors[g][sfb] = 0;
} else {
switch (ics->sfb_cb[g][sfb])
{
case ZERO_HCB: /* zero book */
ics->scale_factors[g][sfb] = 0;
break;
case INTENSITY_HCB: /* intensity books */
case INTENSITY_HCB2:
*intensity_used = 1;
/* decode intensity position */
t = rvlc_huffman_sf(ld_sf, ld_esc, +1);
is_position += t;
ics->scale_factors[g][sfb] = is_position;
break;
case NOISE_HCB: /* noise books */
/* decode noise energy */
if (noise_pcm_flag)
{
int16_t n = ics->dpcm_noise_nrg;
noise_pcm_flag = 0;
noise_energy += n;
} else {
t = rvlc_huffman_sf(ld_sf, ld_esc, +1);
noise_energy += t;
}
ics->scale_factors[g][sfb] = noise_energy;
break;
default: /* spectral books */
/* decode scale factor */
t = rvlc_huffman_sf(ld_sf, ld_esc, +1);
scale_factor += t;
if (scale_factor < 0)
return 4;
ics->scale_factors[g][sfb] = scale_factor;
break;
}
#ifdef PRINT_RVLC
printf("%3d:%4d%4d\n", sfb, ics->sfb_cb[g][sfb],
ics->scale_factors[g][sfb]);
#endif
if (t == 99)
{
error = 1;
}
}
}
}
#ifdef PRINT_RVLC
printf("\n\n");
#endif
return 0;
}
#if 0 // not used right now, doesn't work correctly yet
static uint8_t rvlc_decode_sf_reverse(ic_stream *ics, bitfile *ld_sf, bitfile *ld_esc,
uint8_t intensity_used)
{
int8_t g, sfb;
int8_t t = 0;
int8_t error = 0;
int8_t noise_pcm_flag = 1, is_pcm_flag = 1, sf_pcm_flag = 1;
int16_t scale_factor = ics->rev_global_gain;
int16_t is_position = 0;
int16_t noise_energy = ics->rev_global_gain;
#ifdef PRINT_RVLC
printf("\nrev_global_gain: %d\n", ics->rev_global_gain);
#endif
if (intensity_used)
{
is_position = rvlc_huffman_sf(ld_sf, ld_esc, -1);
#ifdef PRINT_RVLC
printf("is_position: %d\n", is_position);
#endif
}
for (g = ics->num_window_groups-1; g >= 0; g--)
{
for (sfb = ics->max_sfb-1; sfb >= 0; sfb--)
{
if (error)
{
ics->scale_factors[g][sfb] = 0;
} else {
switch (ics->sfb_cb[g][sfb])
{
case ZERO_HCB: /* zero book */
ics->scale_factors[g][sfb] = 0;
break;
case INTENSITY_HCB: /* intensity books */
case INTENSITY_HCB2:
if (is_pcm_flag)
{
is_pcm_flag = 0;
ics->scale_factors[g][sfb] = is_position;
} else {
t = rvlc_huffman_sf(ld_sf, ld_esc, -1);
is_position -= t;
ics->scale_factors[g][sfb] = (uint8_t)is_position;
}
break;
case NOISE_HCB: /* noise books */
/* decode noise energy */
if (noise_pcm_flag)
{
noise_pcm_flag = 0;
noise_energy = ics->dpcm_noise_last_position;
} else {
t = rvlc_huffman_sf(ld_sf, ld_esc, -1);
noise_energy -= t;
}
ics->scale_factors[g][sfb] = (uint8_t)noise_energy;
break;
default: /* spectral books */
if (sf_pcm_flag || (sfb == 0))
{
sf_pcm_flag = 0;
if (sfb == 0)
scale_factor = ics->global_gain;
} else {
/* decode scale factor */
t = rvlc_huffman_sf(ld_sf, ld_esc, -1);
scale_factor -= t;
}
if (scale_factor < 0)
return 4;
ics->scale_factors[g][sfb] = (uint8_t)scale_factor;
break;
}
#ifdef PRINT_RVLC
printf("%3d:%4d%4d\n", sfb, ics->sfb_cb[g][sfb],
ics->scale_factors[g][sfb]);
#endif
if (t == 99)
{
error = 1;
}
}
}
}
#ifdef PRINT_RVLC
printf("\n\n");
#endif
return 0;
}
#endif
/* index == 99 means not allowed codeword */
static rvlc_huff_table book_rvlc[] = {
/*index length codeword */
{ 0, 1, 0 }, /* 0 */
{ -1, 3, 5 }, /* 101 */
{ 1, 3, 7 }, /* 111 */
{ -2, 4, 9 }, /* 1001 */
{ -3, 5, 17 }, /* 10001 */
{ 2, 5, 27 }, /* 11011 */
{ -4, 6, 33 }, /* 100001 */
{ 99, 6, 50 }, /* 110010 */
{ 3, 6, 51 }, /* 110011 */
{ 99, 6, 52 }, /* 110100 */
{ -7, 7, 65 }, /* 1000001 */
{ 99, 7, 96 }, /* 1100000 */
{ 99, 7, 98 }, /* 1100010 */
{ 7, 7, 99 }, /* 1100011 */
{ 4, 7, 107 }, /* 1101011 */
{ -5, 8, 129 }, /* 10000001 */
{ 99, 8, 194 }, /* 11000010 */
{ 5, 8, 195 }, /* 11000011 */
{ 99, 8, 212 }, /* 11010100 */
{ 99, 9, 256 }, /* 100000000 */
{ -6, 9, 257 }, /* 100000001 */
{ 99, 9, 426 }, /* 110101010 */
{ 6, 9, 427 }, /* 110101011 */
{ 99, 10, 0 } /* Shouldn't come this far */
};
static rvlc_huff_table book_escape[] = {
/*index length codeword */
{ 1, 2, 0 },
{ 0, 2, 2 },
{ 3, 3, 2 },
{ 2, 3, 6 },
{ 4, 4, 14 },
{ 7, 5, 13 },
{ 6, 5, 15 },
{ 5, 5, 31 },
{ 11, 6, 24 },
{ 10, 6, 25 },
{ 9, 6, 29 },
{ 8, 6, 61 },
{ 13, 7, 56 },
{ 12, 7, 120 },
{ 15, 8, 114 },
{ 14, 8, 242 },
{ 17, 9, 230 },
{ 16, 9, 486 },
{ 19, 10, 463 },
{ 18, 10, 974 },
{ 22, 11, 925 },
{ 20, 11, 1950 },
{ 21, 11, 1951 },
{ 23, 12, 1848 },
{ 25, 13, 3698 },
{ 24, 14, 7399 },
{ 26, 15, 14797 },
{ 49, 19, 236736 },
{ 50, 19, 236737 },
{ 51, 19, 236738 },
{ 52, 19, 236739 },
{ 53, 19, 236740 },
{ 27, 20, 473482 },
{ 28, 20, 473483 },
{ 29, 20, 473484 },
{ 30, 20, 473485 },
{ 31, 20, 473486 },
{ 32, 20, 473487 },
{ 33, 20, 473488 },
{ 34, 20, 473489 },
{ 35, 20, 473490 },
{ 36, 20, 473491 },
{ 37, 20, 473492 },
{ 38, 20, 473493 },
{ 39, 20, 473494 },
{ 40, 20, 473495 },
{ 41, 20, 473496 },
{ 42, 20, 473497 },
{ 43, 20, 473498 },
{ 44, 20, 473499 },
{ 45, 20, 473500 },
{ 46, 20, 473501 },
{ 47, 20, 473502 },
{ 48, 20, 473503 },
{ 99, 21, 0 } /* Shouldn't come this far */
};
static int8_t rvlc_huffman_sf(bitfile *ld_sf, bitfile *ld_esc,
int8_t direction)
{
uint8_t i, j;
int8_t index;
uint32_t cw;
rvlc_huff_table *h = book_rvlc;
i = h->len;
if (direction > 0)
cw = faad_getbits(ld_sf, i DEBUGVAR(1,0,""));
else
cw = faad_getbits_rev(ld_sf, i DEBUGVAR(1,0,""));
while ((cw != h->cw)
&& (i < 10))
{
h++;
j = h->len-i;
i += j;
cw <<= j;
if (direction > 0)
cw |= faad_getbits(ld_sf, j DEBUGVAR(1,0,""));
else
cw |= faad_getbits_rev(ld_sf, j DEBUGVAR(1,0,""));
}
index = h->index;
if (index == +ESC_VAL)
{
int8_t esc = rvlc_huffman_esc(ld_esc, direction);
if (esc == 99)
return 99;
index += esc;
#ifdef PRINT_RVLC
printf("esc: %d - ", esc);
#endif
}
if (index == -ESC_VAL)
{
int8_t esc = rvlc_huffman_esc(ld_esc, direction);
if (esc == 99)
return 99;
index -= esc;
#ifdef PRINT_RVLC
printf("esc: %d - ", esc);
#endif
}
return index;
}
static int8_t rvlc_huffman_esc(bitfile *ld,
int8_t direction)
{
uint8_t i, j;
uint32_t cw;
rvlc_huff_table *h = book_escape;
i = h->len;
if (direction > 0)
cw = faad_getbits(ld, i DEBUGVAR(1,0,""));
else
cw = faad_getbits_rev(ld, i DEBUGVAR(1,0,""));
while ((cw != h->cw)
&& (i < 21))
{
h++;
j = h->len-i;
i += j;
cw <<= j;
if (direction > 0)
cw |= faad_getbits(ld, j DEBUGVAR(1,0,""));
else
cw |= faad_getbits_rev(ld, j DEBUGVAR(1,0,""));
}
return h->index;
}
#endif

View File

@ -0,0 +1,56 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: rvlc.h,v 1.17 2007/11/01 12:33:34 menno Exp $
**/
#ifndef __RVLC_SCF_H__
#define __RVLC_SCF_H__
#ifdef __cplusplus
extern "C" {
#endif
typedef struct
{
int8_t index;
uint8_t len;
uint32_t cw;
} rvlc_huff_table;
#define ESC_VAL 7
uint8_t rvlc_scale_factor_data(ic_stream *ics, bitfile *ld);
uint8_t rvlc_decode_scale_factors(ic_stream *ics, bitfile *ld);
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,52 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: sbr_dct.h,v 1.19 2007/11/01 12:33:34 menno Exp $
**/
#ifndef __SBR_DCT_H__
#define __SBR_DCT_H__
#ifdef __cplusplus
extern "C" {
#endif
void dct4_kernel(real_t * in_real, real_t * in_imag, real_t * out_real, real_t * out_imag);
void DCT3_32_unscaled(real_t *y, real_t *x);
void DCT4_32(real_t *y, real_t *x);
void DST4_32(real_t *y, real_t *x);
void DCT2_32_unscaled(real_t *y, real_t *x);
void DCT4_16(real_t *y, real_t *x);
void DCT2_16_unscaled(real_t *y, real_t *x);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,690 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: sbr_dec.c,v 1.44 2009/01/26 22:32:31 menno Exp $
**/
#include "common.h"
#include "structs.h"
#ifdef SBR_DEC
#include <string.h>
#include <stdlib.h>
#include "syntax.h"
#include "bits.h"
#include "sbr_syntax.h"
#include "sbr_qmf.h"
#include "sbr_hfgen.h"
#include "sbr_hfadj.h"
/* static function declarations */
static uint8_t sbr_save_prev_data(sbr_info *sbr, uint8_t ch);
static void sbr_save_matrix(sbr_info *sbr, uint8_t ch);
sbr_info *sbrDecodeInit(uint16_t framelength, uint8_t id_aac,
uint32_t sample_rate, uint8_t downSampledSBR
#ifdef DRM
, uint8_t IsDRM
#endif
)
{
sbr_info *sbr = faad_malloc(sizeof(sbr_info));
memset(sbr, 0, sizeof(sbr_info));
/* save id of the parent element */
sbr->id_aac = id_aac;
sbr->sample_rate = sample_rate;
sbr->bs_freq_scale = 2;
sbr->bs_alter_scale = 1;
sbr->bs_noise_bands = 2;
sbr->bs_limiter_bands = 2;
sbr->bs_limiter_gains = 2;
sbr->bs_interpol_freq = 1;
sbr->bs_smoothing_mode = 1;
sbr->bs_start_freq = 5;
sbr->bs_amp_res = 1;
sbr->bs_samplerate_mode = 1;
sbr->prevEnvIsShort[0] = -1;
sbr->prevEnvIsShort[1] = -1;
sbr->header_count = 0;
sbr->Reset = 1;
#ifdef DRM
sbr->Is_DRM_SBR = IsDRM;
#endif
sbr->tHFGen = T_HFGEN;
sbr->tHFAdj = T_HFADJ;
sbr->bsco = 0;
sbr->bsco_prev = 0;
sbr->M_prev = 0;
sbr->frame_len = framelength;
/* force sbr reset */
sbr->bs_start_freq_prev = -1;
if (framelength == 960)
{
sbr->numTimeSlotsRate = RATE * NO_TIME_SLOTS_960;
sbr->numTimeSlots = NO_TIME_SLOTS_960;
} else {
sbr->numTimeSlotsRate = RATE * NO_TIME_SLOTS;
sbr->numTimeSlots = NO_TIME_SLOTS;
}
sbr->GQ_ringbuf_index[0] = 0;
sbr->GQ_ringbuf_index[1] = 0;
if (id_aac == ID_CPE)
{
/* stereo */
uint8_t j;
sbr->qmfa[0] = qmfa_init(32);
sbr->qmfa[1] = qmfa_init(32);
sbr->qmfs[0] = qmfs_init((downSampledSBR)?32:64);
sbr->qmfs[1] = qmfs_init((downSampledSBR)?32:64);
for (j = 0; j < 5; j++)
{
sbr->G_temp_prev[0][j] = faad_malloc(64*sizeof(real_t));
sbr->G_temp_prev[1][j] = faad_malloc(64*sizeof(real_t));
sbr->Q_temp_prev[0][j] = faad_malloc(64*sizeof(real_t));
sbr->Q_temp_prev[1][j] = faad_malloc(64*sizeof(real_t));
}
memset(sbr->Xsbr[0], 0, (sbr->numTimeSlotsRate+sbr->tHFGen)*64 * sizeof(qmf_t));
memset(sbr->Xsbr[1], 0, (sbr->numTimeSlotsRate+sbr->tHFGen)*64 * sizeof(qmf_t));
} else {
/* mono */
uint8_t j;
sbr->qmfa[0] = qmfa_init(32);
sbr->qmfs[0] = qmfs_init((downSampledSBR)?32:64);
sbr->qmfs[1] = NULL;
for (j = 0; j < 5; j++)
{
sbr->G_temp_prev[0][j] = faad_malloc(64*sizeof(real_t));
sbr->Q_temp_prev[0][j] = faad_malloc(64*sizeof(real_t));
}
memset(sbr->Xsbr[0], 0, (sbr->numTimeSlotsRate+sbr->tHFGen)*64 * sizeof(qmf_t));
}
return sbr;
}
void sbrDecodeEnd(sbr_info *sbr)
{
uint8_t j;
if (sbr)
{
qmfa_end(sbr->qmfa[0]);
qmfs_end(sbr->qmfs[0]);
if (sbr->qmfs[1] != NULL)
{
qmfa_end(sbr->qmfa[1]);
qmfs_end(sbr->qmfs[1]);
}
for (j = 0; j < 5; j++)
{
if (sbr->G_temp_prev[0][j]) faad_free(sbr->G_temp_prev[0][j]);
if (sbr->Q_temp_prev[0][j]) faad_free(sbr->Q_temp_prev[0][j]);
if (sbr->G_temp_prev[1][j]) faad_free(sbr->G_temp_prev[1][j]);
if (sbr->Q_temp_prev[1][j]) faad_free(sbr->Q_temp_prev[1][j]);
}
#ifdef PS_DEC
if (sbr->ps != NULL)
ps_free(sbr->ps);
#endif
#ifdef DRM_PS
if (sbr->drm_ps != NULL)
drm_ps_free(sbr->drm_ps);
#endif
faad_free(sbr);
}
}
void sbrReset(sbr_info *sbr)
{
uint8_t j;
if (sbr->qmfa[0] != NULL)
memset(sbr->qmfa[0]->x, 0, 2 * sbr->qmfa[0]->channels * 10 * sizeof(real_t));
if (sbr->qmfa[1] != NULL)
memset(sbr->qmfa[1]->x, 0, 2 * sbr->qmfa[1]->channels * 10 * sizeof(real_t));
if (sbr->qmfs[0] != NULL)
memset(sbr->qmfs[0]->v, 0, 2 * sbr->qmfs[0]->channels * 20 * sizeof(real_t));
if (sbr->qmfs[1] != NULL)
memset(sbr->qmfs[1]->v, 0, 2 * sbr->qmfs[1]->channels * 20 * sizeof(real_t));
for (j = 0; j < 5; j++)
{
if (sbr->G_temp_prev[0][j] != NULL)
memset(sbr->G_temp_prev[0][j], 0, 64*sizeof(real_t));
if (sbr->G_temp_prev[1][j] != NULL)
memset(sbr->G_temp_prev[1][j], 0, 64*sizeof(real_t));
if (sbr->Q_temp_prev[0][j] != NULL)
memset(sbr->Q_temp_prev[0][j], 0, 64*sizeof(real_t));
if (sbr->Q_temp_prev[1][j] != NULL)
memset(sbr->Q_temp_prev[1][j], 0, 64*sizeof(real_t));
}
memset(sbr->Xsbr[0], 0, (sbr->numTimeSlotsRate+sbr->tHFGen)*64 * sizeof(qmf_t));
memset(sbr->Xsbr[1], 0, (sbr->numTimeSlotsRate+sbr->tHFGen)*64 * sizeof(qmf_t));
sbr->GQ_ringbuf_index[0] = 0;
sbr->GQ_ringbuf_index[1] = 0;
sbr->header_count = 0;
sbr->Reset = 1;
sbr->L_E_prev[0] = 0;
sbr->L_E_prev[1] = 0;
sbr->bs_freq_scale = 2;
sbr->bs_alter_scale = 1;
sbr->bs_noise_bands = 2;
sbr->bs_limiter_bands = 2;
sbr->bs_limiter_gains = 2;
sbr->bs_interpol_freq = 1;
sbr->bs_smoothing_mode = 1;
sbr->bs_start_freq = 5;
sbr->bs_amp_res = 1;
sbr->bs_samplerate_mode = 1;
sbr->prevEnvIsShort[0] = -1;
sbr->prevEnvIsShort[1] = -1;
sbr->bsco = 0;
sbr->bsco_prev = 0;
sbr->M_prev = 0;
sbr->bs_start_freq_prev = -1;
sbr->f_prev[0] = 0;
sbr->f_prev[1] = 0;
for (j = 0; j < MAX_M; j++)
{
sbr->E_prev[0][j] = 0;
sbr->Q_prev[0][j] = 0;
sbr->E_prev[1][j] = 0;
sbr->Q_prev[1][j] = 0;
sbr->bs_add_harmonic_prev[0][j] = 0;
sbr->bs_add_harmonic_prev[1][j] = 0;
}
sbr->bs_add_harmonic_flag_prev[0] = 0;
sbr->bs_add_harmonic_flag_prev[1] = 0;
}
static uint8_t sbr_save_prev_data(sbr_info *sbr, uint8_t ch)
{
uint8_t i;
/* save data for next frame */
sbr->kx_prev = sbr->kx;
sbr->M_prev = sbr->M;
sbr->bsco_prev = sbr->bsco;
sbr->L_E_prev[ch] = sbr->L_E[ch];
/* sbr->L_E[ch] can become 0 on files with bit errors */
if (sbr->L_E[ch] <= 0)
return 19;
sbr->f_prev[ch] = sbr->f[ch][sbr->L_E[ch] - 1];
for (i = 0; i < MAX_M; i++)
{
sbr->E_prev[ch][i] = sbr->E[ch][i][sbr->L_E[ch] - 1];
sbr->Q_prev[ch][i] = sbr->Q[ch][i][sbr->L_Q[ch] - 1];
}
for (i = 0; i < MAX_M; i++)
{
sbr->bs_add_harmonic_prev[ch][i] = sbr->bs_add_harmonic[ch][i];
}
sbr->bs_add_harmonic_flag_prev[ch] = sbr->bs_add_harmonic_flag[ch];
if (sbr->l_A[ch] == sbr->L_E[ch])
sbr->prevEnvIsShort[ch] = 0;
else
sbr->prevEnvIsShort[ch] = -1;
return 0;
}
static void sbr_save_matrix(sbr_info *sbr, uint8_t ch)
{
uint8_t i;
for (i = 0; i < sbr->tHFGen; i++)
{
memmove(sbr->Xsbr[ch][i], sbr->Xsbr[ch][i+sbr->numTimeSlotsRate], 64 * sizeof(qmf_t));
}
for (i = sbr->tHFGen; i < MAX_NTSRHFG; i++)
{
memset(sbr->Xsbr[ch][i], 0, 64 * sizeof(qmf_t));
}
}
static uint8_t sbr_process_channel(sbr_info *sbr, real_t *channel_buf, qmf_t X[MAX_NTSR][64],
uint8_t ch, uint8_t dont_process,
const uint8_t downSampledSBR)
{
int16_t k, l;
uint8_t ret = 0;
#ifdef SBR_LOW_POWER
ALIGN real_t deg[64];
#endif
#ifdef DRM
if (sbr->Is_DRM_SBR)
{
sbr->bsco = max((int32_t)sbr->maxAACLine*32/(int32_t)sbr->frame_len - (int32_t)sbr->kx, 0);
} else {
#endif
sbr->bsco = 0;
#ifdef DRM
}
#endif
//#define PRE_QMF_PRINT
#ifdef PRE_QMF_PRINT
{
int i;
for (i = 0; i < 1024; i++)
{
printf("%d\n", channel_buf[i]);
}
}
#endif
/* subband analysis */
if (dont_process)
sbr_qmf_analysis_32(sbr, sbr->qmfa[ch], channel_buf, sbr->Xsbr[ch], sbr->tHFGen, 32);
else
sbr_qmf_analysis_32(sbr, sbr->qmfa[ch], channel_buf, sbr->Xsbr[ch], sbr->tHFGen, sbr->kx);
if (!dont_process)
{
#if 1
/* insert high frequencies here */
/* hf generation using patching */
hf_generation(sbr, sbr->Xsbr[ch], sbr->Xsbr[ch]
#ifdef SBR_LOW_POWER
,deg
#endif
,ch);
#endif
#if 0 //def SBR_LOW_POWER
for (l = sbr->t_E[ch][0]; l < sbr->t_E[ch][sbr->L_E[ch]]; l++)
{
for (k = 0; k < sbr->kx; k++)
{
QMF_RE(sbr->Xsbr[ch][sbr->tHFAdj + l][k]) = 0;
}
}
#endif
#if 1
/* hf adjustment */
ret = hf_adjustment(sbr, sbr->Xsbr[ch]
#ifdef SBR_LOW_POWER
,deg
#endif
,ch);
#endif
if (ret > 0)
{
dont_process = 1;
}
}
if ((sbr->just_seeked != 0) || dont_process)
{
for (l = 0; l < sbr->numTimeSlotsRate; l++)
{
for (k = 0; k < 32; k++)
{
QMF_RE(X[l][k]) = QMF_RE(sbr->Xsbr[ch][l + sbr->tHFAdj][k]);
#ifndef SBR_LOW_POWER
QMF_IM(X[l][k]) = QMF_IM(sbr->Xsbr[ch][l + sbr->tHFAdj][k]);
#endif
}
for (k = 32; k < 64; k++)
{
QMF_RE(X[l][k]) = 0;
#ifndef SBR_LOW_POWER
QMF_IM(X[l][k]) = 0;
#endif
}
}
} else {
for (l = 0; l < sbr->numTimeSlotsRate; l++)
{
uint8_t kx_band, M_band, bsco_band;
if (l < sbr->t_E[ch][0])
{
kx_band = sbr->kx_prev;
M_band = sbr->M_prev;
bsco_band = sbr->bsco_prev;
} else {
kx_band = sbr->kx;
M_band = sbr->M;
bsco_band = sbr->bsco;
}
#ifndef SBR_LOW_POWER
for (k = 0; k < kx_band + bsco_band; k++)
{
QMF_RE(X[l][k]) = QMF_RE(sbr->Xsbr[ch][l + sbr->tHFAdj][k]);
QMF_IM(X[l][k]) = QMF_IM(sbr->Xsbr[ch][l + sbr->tHFAdj][k]);
}
for (k = kx_band + bsco_band; k < kx_band + M_band; k++)
{
QMF_RE(X[l][k]) = QMF_RE(sbr->Xsbr[ch][l + sbr->tHFAdj][k]);
QMF_IM(X[l][k]) = QMF_IM(sbr->Xsbr[ch][l + sbr->tHFAdj][k]);
}
for (k = max(kx_band + bsco_band, kx_band + M_band); k < 64; k++)
{
QMF_RE(X[l][k]) = 0;
QMF_IM(X[l][k]) = 0;
}
#else
for (k = 0; k < kx_band + bsco_band; k++)
{
QMF_RE(X[l][k]) = QMF_RE(sbr->Xsbr[ch][l + sbr->tHFAdj][k]);
}
for (k = kx_band + bsco_band; k < min(kx_band + M_band, 63); k++)
{
QMF_RE(X[l][k]) = QMF_RE(sbr->Xsbr[ch][l + sbr->tHFAdj][k]);
}
for (k = max(kx_band + bsco_band, kx_band + M_band); k < 64; k++)
{
QMF_RE(X[l][k]) = 0;
}
QMF_RE(X[l][kx_band - 1 + bsco_band]) +=
QMF_RE(sbr->Xsbr[ch][l + sbr->tHFAdj][kx_band - 1 + bsco_band]);
#endif
}
}
return ret;
}
uint8_t sbrDecodeCoupleFrame(sbr_info *sbr, real_t *left_chan, real_t *right_chan,
const uint8_t just_seeked, const uint8_t downSampledSBR)
{
uint8_t dont_process = 0;
uint8_t ret = 0;
ALIGN qmf_t X[MAX_NTSR][64];
if (sbr == NULL)
return 20;
/* case can occur due to bit errors */
if (sbr->id_aac != ID_CPE)
return 21;
if (sbr->ret || (sbr->header_count == 0))
{
/* don't process just upsample */
dont_process = 1;
/* Re-activate reset for next frame */
if (sbr->ret && sbr->Reset)
sbr->bs_start_freq_prev = -1;
}
if (just_seeked)
{
sbr->just_seeked = 1;
} else {
sbr->just_seeked = 0;
}
sbr->ret += sbr_process_channel(sbr, left_chan, X, 0, dont_process, downSampledSBR);
/* subband synthesis */
if (downSampledSBR)
{
sbr_qmf_synthesis_32(sbr, sbr->qmfs[0], X, left_chan);
} else {
sbr_qmf_synthesis_64(sbr, sbr->qmfs[0], X, left_chan);
}
sbr->ret += sbr_process_channel(sbr, right_chan, X, 1, dont_process, downSampledSBR);
/* subband synthesis */
if (downSampledSBR)
{
sbr_qmf_synthesis_32(sbr, sbr->qmfs[1], X, right_chan);
} else {
sbr_qmf_synthesis_64(sbr, sbr->qmfs[1], X, right_chan);
}
if (sbr->bs_header_flag)
sbr->just_seeked = 0;
if (sbr->header_count != 0 && sbr->ret == 0)
{
ret = sbr_save_prev_data(sbr, 0);
if (ret) return ret;
ret = sbr_save_prev_data(sbr, 1);
if (ret) return ret;
}
sbr_save_matrix(sbr, 0);
sbr_save_matrix(sbr, 1);
sbr->frame++;
//#define POST_QMF_PRINT
#ifdef POST_QMF_PRINT
{
int i;
for (i = 0; i < 2048; i++)
{
printf("%d\n", left_chan[i]);
}
for (i = 0; i < 2048; i++)
{
printf("%d\n", right_chan[i]);
}
}
#endif
return 0;
}
uint8_t sbrDecodeSingleFrame(sbr_info *sbr, real_t *channel,
const uint8_t just_seeked, const uint8_t downSampledSBR)
{
uint8_t dont_process = 0;
uint8_t ret = 0;
ALIGN qmf_t X[MAX_NTSR][64];
if (sbr == NULL)
return 20;
/* case can occur due to bit errors */
if (sbr->id_aac != ID_SCE && sbr->id_aac != ID_LFE)
return 21;
if (sbr->ret || (sbr->header_count == 0))
{
/* don't process just upsample */
dont_process = 1;
/* Re-activate reset for next frame */
if (sbr->ret && sbr->Reset)
sbr->bs_start_freq_prev = -1;
}
if (just_seeked)
{
sbr->just_seeked = 1;
} else {
sbr->just_seeked = 0;
}
sbr->ret += sbr_process_channel(sbr, channel, X, 0, dont_process, downSampledSBR);
/* subband synthesis */
if (downSampledSBR)
{
sbr_qmf_synthesis_32(sbr, sbr->qmfs[0], X, channel);
} else {
sbr_qmf_synthesis_64(sbr, sbr->qmfs[0], X, channel);
}
if (sbr->bs_header_flag)
sbr->just_seeked = 0;
if (sbr->header_count != 0 && sbr->ret == 0)
{
ret = sbr_save_prev_data(sbr, 0);
if (ret) return ret;
}
sbr_save_matrix(sbr, 0);
sbr->frame++;
//#define POST_QMF_PRINT
#ifdef POST_QMF_PRINT
{
int i;
for (i = 0; i < 2048; i++)
{
printf("%d\n", channel[i]);
}
}
#endif
return 0;
}
#if (defined(PS_DEC) || defined(DRM_PS))
uint8_t sbrDecodeSingleFramePS(sbr_info *sbr, real_t *left_channel, real_t *right_channel,
const uint8_t just_seeked, const uint8_t downSampledSBR)
{
uint8_t l, k;
uint8_t dont_process = 0;
uint8_t ret = 0;
ALIGN qmf_t X_left[38][64] = {{0}};
ALIGN qmf_t X_right[38][64] = {{0}}; /* must set this to 0 */
if (sbr == NULL)
return 20;
/* case can occur due to bit errors */
if (sbr->id_aac != ID_SCE && sbr->id_aac != ID_LFE)
return 21;
if (sbr->ret || (sbr->header_count == 0))
{
/* don't process just upsample */
dont_process = 1;
/* Re-activate reset for next frame */
if (sbr->ret && sbr->Reset)
sbr->bs_start_freq_prev = -1;
}
if (just_seeked)
{
sbr->just_seeked = 1;
} else {
sbr->just_seeked = 0;
}
if (sbr->qmfs[1] == NULL)
{
sbr->qmfs[1] = qmfs_init((downSampledSBR)?32:64);
}
sbr->ret += sbr_process_channel(sbr, left_channel, X_left, 0, dont_process, downSampledSBR);
/* copy some extra data for PS */
for (l = sbr->numTimeSlotsRate; l < sbr->numTimeSlotsRate + 6; l++)
{
for (k = 0; k < 5; k++)
{
QMF_RE(X_left[l][k]) = QMF_RE(sbr->Xsbr[0][sbr->tHFAdj+l][k]);
QMF_IM(X_left[l][k]) = QMF_IM(sbr->Xsbr[0][sbr->tHFAdj+l][k]);
}
}
/* perform parametric stereo */
#ifdef DRM_PS
if (sbr->Is_DRM_SBR)
{
drm_ps_decode(sbr->drm_ps, (sbr->ret > 0), X_left, X_right);
} else {
#endif
#ifdef PS_DEC
ps_decode(sbr->ps, X_left, X_right);
#endif
#ifdef DRM_PS
}
#endif
/* subband synthesis */
if (downSampledSBR)
{
sbr_qmf_synthesis_32(sbr, sbr->qmfs[0], X_left, left_channel);
sbr_qmf_synthesis_32(sbr, sbr->qmfs[1], X_right, right_channel);
} else {
sbr_qmf_synthesis_64(sbr, sbr->qmfs[0], X_left, left_channel);
sbr_qmf_synthesis_64(sbr, sbr->qmfs[1], X_right, right_channel);
}
if (sbr->bs_header_flag)
sbr->just_seeked = 0;
if (sbr->header_count != 0 && sbr->ret == 0)
{
ret = sbr_save_prev_data(sbr, 0);
if (ret) return ret;
}
sbr_save_matrix(sbr, 0);
sbr->frame++;
return 0;
}
#endif
#endif

View File

@ -0,0 +1,254 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: sbr_dec.h,v 1.39 2007/11/01 12:33:34 menno Exp $
**/
#ifndef __SBR_DEC_H__
#define __SBR_DEC_H__
#ifdef __cplusplus
extern "C" {
#endif
#ifdef PS_DEC
#include "ps_dec.h"
#endif
#ifdef DRM_PS
#include "drm_dec.h"
#endif
/* MAX_NTSRHFG: maximum of number_time_slots * rate + HFGen. 16*2+8 */
#define MAX_NTSRHFG 40
#define MAX_NTSR 32 /* max number_time_slots * rate, ok for DRM and not DRM mode */
/* MAX_M: maximum value for M */
#define MAX_M 49
/* MAX_L_E: maximum value for L_E */
#define MAX_L_E 5
typedef struct {
real_t *x;
int16_t x_index;
uint8_t channels;
} qmfa_info;
typedef struct {
real_t *v;
int16_t v_index;
uint8_t channels;
} qmfs_info;
typedef struct
{
uint32_t sample_rate;
uint32_t maxAACLine;
uint8_t rate;
uint8_t just_seeked;
uint8_t ret;
uint8_t amp_res[2];
uint8_t k0;
uint8_t kx;
uint8_t M;
uint8_t N_master;
uint8_t N_high;
uint8_t N_low;
uint8_t N_Q;
uint8_t N_L[4];
uint8_t n[2];
uint8_t f_master[64];
uint8_t f_table_res[2][64];
uint8_t f_table_noise[64];
uint8_t f_table_lim[4][64];
#ifdef SBR_LOW_POWER
uint8_t f_group[5][64];
uint8_t N_G[5];
#endif
uint8_t table_map_k_to_g[64];
uint8_t abs_bord_lead[2];
uint8_t abs_bord_trail[2];
uint8_t n_rel_lead[2];
uint8_t n_rel_trail[2];
uint8_t L_E[2];
uint8_t L_E_prev[2];
uint8_t L_Q[2];
uint8_t t_E[2][MAX_L_E+1];
uint8_t t_Q[2][3];
uint8_t f[2][MAX_L_E+1];
uint8_t f_prev[2];
real_t *G_temp_prev[2][5];
real_t *Q_temp_prev[2][5];
int8_t GQ_ringbuf_index[2];
int16_t E[2][64][MAX_L_E];
int16_t E_prev[2][64];
#ifndef FIXED_POINT
real_t E_orig[2][64][MAX_L_E];
#endif
real_t E_curr[2][64][MAX_L_E];
int32_t Q[2][64][2];
#ifndef FIXED_POINT
real_t Q_div[2][64][2];
real_t Q_div2[2][64][2];
#endif
int32_t Q_prev[2][64];
int8_t l_A[2];
int8_t l_A_prev[2];
uint8_t bs_invf_mode[2][MAX_L_E];
uint8_t bs_invf_mode_prev[2][MAX_L_E];
real_t bwArray[2][64];
real_t bwArray_prev[2][64];
uint8_t noPatches;
uint8_t patchNoSubbands[64];
uint8_t patchStartSubband[64];
uint8_t bs_add_harmonic[2][64];
uint8_t bs_add_harmonic_prev[2][64];
uint16_t index_noise_prev[2];
uint8_t psi_is_prev[2];
uint8_t bs_start_freq_prev;
uint8_t bs_stop_freq_prev;
uint8_t bs_xover_band_prev;
uint8_t bs_freq_scale_prev;
uint8_t bs_alter_scale_prev;
uint8_t bs_noise_bands_prev;
int8_t prevEnvIsShort[2];
int8_t kx_prev;
uint8_t bsco;
uint8_t bsco_prev;
uint8_t M_prev;
uint16_t frame_len;
uint8_t Reset;
uint32_t frame;
uint32_t header_count;
uint8_t id_aac;
qmfa_info *qmfa[2];
qmfs_info *qmfs[2];
qmf_t Xsbr[2][MAX_NTSRHFG][64];
#ifdef DRM
uint8_t Is_DRM_SBR;
#ifdef DRM_PS
drm_ps_info *drm_ps;
#endif
#endif
uint8_t numTimeSlotsRate;
uint8_t numTimeSlots;
uint8_t tHFGen;
uint8_t tHFAdj;
#ifdef PS_DEC
ps_info *ps;
#endif
#if (defined(PS_DEC) || defined(DRM_PS))
uint8_t ps_used;
uint8_t psResetFlag;
#endif
/* to get it compiling */
/* we'll see during the coding of all the tools, whether
these are all used or not.
*/
uint8_t bs_header_flag;
uint8_t bs_crc_flag;
uint16_t bs_sbr_crc_bits;
uint8_t bs_protocol_version;
uint8_t bs_amp_res;
uint8_t bs_start_freq;
uint8_t bs_stop_freq;
uint8_t bs_xover_band;
uint8_t bs_freq_scale;
uint8_t bs_alter_scale;
uint8_t bs_noise_bands;
uint8_t bs_limiter_bands;
uint8_t bs_limiter_gains;
uint8_t bs_interpol_freq;
uint8_t bs_smoothing_mode;
uint8_t bs_samplerate_mode;
uint8_t bs_add_harmonic_flag[2];
uint8_t bs_add_harmonic_flag_prev[2];
uint8_t bs_extended_data;
uint8_t bs_extension_id;
uint8_t bs_extension_data;
uint8_t bs_coupling;
uint8_t bs_frame_class[2];
uint8_t bs_rel_bord[2][9];
uint8_t bs_rel_bord_0[2][9];
uint8_t bs_rel_bord_1[2][9];
uint8_t bs_pointer[2];
uint8_t bs_abs_bord_0[2];
uint8_t bs_abs_bord_1[2];
uint8_t bs_num_rel_0[2];
uint8_t bs_num_rel_1[2];
uint8_t bs_df_env[2][9];
uint8_t bs_df_noise[2][3];
} sbr_info;
sbr_info *sbrDecodeInit(uint16_t framelength, uint8_t id_aac,
uint32_t sample_rate, uint8_t downSampledSBR
#ifdef DRM
, uint8_t IsDRM
#endif
);
void sbrDecodeEnd(sbr_info *sbr);
void sbrReset(sbr_info *sbr);
uint8_t sbrDecodeCoupleFrame(sbr_info *sbr, real_t *left_chan, real_t *right_chan,
const uint8_t just_seeked, const uint8_t downSampledSBR);
uint8_t sbrDecodeSingleFrame(sbr_info *sbr, real_t *channel,
const uint8_t just_seeked, const uint8_t downSampledSBR);
#if (defined(PS_DEC) || defined(DRM_PS))
uint8_t sbrDecodeSingleFramePS(sbr_info *sbr, real_t *left_channel, real_t *right_channel,
const uint8_t just_seeked, const uint8_t downSampledSBR);
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,510 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: sbr_e_nf.c,v 1.22 2008/03/23 23:03:29 menno Exp $
**/
#include "common.h"
#include "structs.h"
#ifdef SBR_DEC
#include <stdlib.h>
#include "sbr_syntax.h"
#include "sbr_e_nf.h"
void extract_envelope_data(sbr_info *sbr, uint8_t ch)
{
uint8_t l, k;
for (l = 0; l < sbr->L_E[ch]; l++)
{
if (sbr->bs_df_env[ch][l] == 0)
{
for (k = 1; k < sbr->n[sbr->f[ch][l]]; k++)
{
sbr->E[ch][k][l] = sbr->E[ch][k - 1][l] + sbr->E[ch][k][l];
if (sbr->E[ch][k][l] < 0)
sbr->E[ch][k][l] = 0;
}
} else { /* bs_df_env == 1 */
uint8_t g = (l == 0) ? sbr->f_prev[ch] : sbr->f[ch][l-1];
int16_t E_prev;
if (sbr->f[ch][l] == g)
{
for (k = 0; k < sbr->n[sbr->f[ch][l]]; k++)
{
if (l == 0)
E_prev = sbr->E_prev[ch][k];
else
E_prev = sbr->E[ch][k][l - 1];
sbr->E[ch][k][l] = E_prev + sbr->E[ch][k][l];
}
} else if ((g == 1) && (sbr->f[ch][l] == 0)) {
uint8_t i;
for (k = 0; k < sbr->n[sbr->f[ch][l]]; k++)
{
for (i = 0; i < sbr->N_high; i++)
{
if (sbr->f_table_res[HI_RES][i] == sbr->f_table_res[LO_RES][k])
{
if (l == 0)
E_prev = sbr->E_prev[ch][i];
else
E_prev = sbr->E[ch][i][l - 1];
sbr->E[ch][k][l] = E_prev + sbr->E[ch][k][l];
}
}
}
} else if ((g == 0) && (sbr->f[ch][l] == 1)) {
uint8_t i;
for (k = 0; k < sbr->n[sbr->f[ch][l]]; k++)
{
for (i = 0; i < sbr->N_low; i++)
{
if ((sbr->f_table_res[LO_RES][i] <= sbr->f_table_res[HI_RES][k]) &&
(sbr->f_table_res[HI_RES][k] < sbr->f_table_res[LO_RES][i + 1]))
{
if (l == 0)
E_prev = sbr->E_prev[ch][i];
else
E_prev = sbr->E[ch][i][l - 1];
sbr->E[ch][k][l] = E_prev + sbr->E[ch][k][l];
}
}
}
}
}
}
}
void extract_noise_floor_data(sbr_info *sbr, uint8_t ch)
{
uint8_t l, k;
for (l = 0; l < sbr->L_Q[ch]; l++)
{
if (sbr->bs_df_noise[ch][l] == 0)
{
for (k = 1; k < sbr->N_Q; k++)
{
sbr->Q[ch][k][l] = sbr->Q[ch][k][l] + sbr->Q[ch][k-1][l];
}
} else {
if (l == 0)
{
for (k = 0; k < sbr->N_Q; k++)
{
sbr->Q[ch][k][l] = sbr->Q_prev[ch][k] + sbr->Q[ch][k][0];
}
} else {
for (k = 0; k < sbr->N_Q; k++)
{
sbr->Q[ch][k][l] = sbr->Q[ch][k][l - 1] + sbr->Q[ch][k][l];
}
}
}
}
}
#ifndef FIXED_POINT
/* table for Q_div values when no coupling */
static const real_t Q_div_tab[31] = {
FRAC_CONST(0.0153846), FRAC_CONST(0.030303),
FRAC_CONST(0.0588235), FRAC_CONST(0.111111),
FRAC_CONST(0.2), FRAC_CONST(0.333333),
FRAC_CONST(0.5), FRAC_CONST(0.666667),
FRAC_CONST(0.8), FRAC_CONST(0.888889),
FRAC_CONST(0.941176), FRAC_CONST(0.969697),
FRAC_CONST(0.984615), FRAC_CONST(0.992248),
FRAC_CONST(0.996109), FRAC_CONST(0.998051),
FRAC_CONST(0.999024), FRAC_CONST(0.999512),
FRAC_CONST(0.999756), FRAC_CONST(0.999878),
FRAC_CONST(0.999939), FRAC_CONST(0.999969),
FRAC_CONST(0.999985), FRAC_CONST(0.999992),
FRAC_CONST(0.999996), FRAC_CONST(0.999998),
FRAC_CONST(0.999999), FRAC_CONST(1),
FRAC_CONST(1), FRAC_CONST(1),
FRAC_CONST(1)
};
static const real_t Q_div_tab_left[31][13] = {
{ FRAC_CONST(0.969704), FRAC_CONST(0.888985), FRAC_CONST(0.667532), FRAC_CONST(0.336788), FRAC_CONST(0.117241), FRAC_CONST(0.037594), FRAC_CONST(0.0153846), FRAC_CONST(0.00967118), FRAC_CONST(0.00823245), FRAC_CONST(0.00787211), FRAC_CONST(0.00778198), FRAC_CONST(0.00775945), FRAC_CONST(0.00775382) },
{ FRAC_CONST(0.984619), FRAC_CONST(0.94123), FRAC_CONST(0.800623), FRAC_CONST(0.503876), FRAC_CONST(0.209877), FRAC_CONST(0.0724638), FRAC_CONST(0.030303), FRAC_CONST(0.0191571), FRAC_CONST(0.0163305), FRAC_CONST(0.0156212), FRAC_CONST(0.0154438), FRAC_CONST(0.0153994), FRAC_CONST(0.0153883) },
{ FRAC_CONST(0.99225), FRAC_CONST(0.969726), FRAC_CONST(0.889273), FRAC_CONST(0.670103), FRAC_CONST(0.346939), FRAC_CONST(0.135135), FRAC_CONST(0.0588235), FRAC_CONST(0.037594), FRAC_CONST(0.0321361), FRAC_CONST(0.0307619), FRAC_CONST(0.0304178), FRAC_CONST(0.0303317), FRAC_CONST(0.0303102) },
{ FRAC_CONST(0.99611), FRAC_CONST(0.98463), FRAC_CONST(0.941392), FRAC_CONST(0.802469), FRAC_CONST(0.515152), FRAC_CONST(0.238095), FRAC_CONST(0.111111), FRAC_CONST(0.0724638), FRAC_CONST(0.0622711), FRAC_CONST(0.0596878), FRAC_CONST(0.0590397), FRAC_CONST(0.0588776), FRAC_CONST(0.058837) },
{ FRAC_CONST(0.998051), FRAC_CONST(0.992256), FRAC_CONST(0.969811), FRAC_CONST(0.890411), FRAC_CONST(0.68), FRAC_CONST(0.384615), FRAC_CONST(0.2), FRAC_CONST(0.135135), FRAC_CONST(0.117241), FRAC_CONST(0.112652), FRAC_CONST(0.111497), FRAC_CONST(0.111208), FRAC_CONST(0.111135) },
{ FRAC_CONST(0.999025), FRAC_CONST(0.996113), FRAC_CONST(0.984674), FRAC_CONST(0.942029), FRAC_CONST(0.809524), FRAC_CONST(0.555556), FRAC_CONST(0.333333), FRAC_CONST(0.238095), FRAC_CONST(0.209877), FRAC_CONST(0.202492), FRAC_CONST(0.200625), FRAC_CONST(0.200156), FRAC_CONST(0.200039) },
{ FRAC_CONST(0.999512), FRAC_CONST(0.998053), FRAC_CONST(0.992278), FRAC_CONST(0.970149), FRAC_CONST(0.894737), FRAC_CONST(0.714286), FRAC_CONST(0.5), FRAC_CONST(0.384615), FRAC_CONST(0.346939), FRAC_CONST(0.336788), FRAC_CONST(0.3342), FRAC_CONST(0.33355), FRAC_CONST(0.333388) },
{ FRAC_CONST(0.999756), FRAC_CONST(0.999025), FRAC_CONST(0.996124), FRAC_CONST(0.984848), FRAC_CONST(0.944444), FRAC_CONST(0.833333), FRAC_CONST(0.666667), FRAC_CONST(0.555556), FRAC_CONST(0.515152), FRAC_CONST(0.503876), FRAC_CONST(0.500975), FRAC_CONST(0.500244), FRAC_CONST(0.500061) },
{ FRAC_CONST(0.999878), FRAC_CONST(0.999512), FRAC_CONST(0.998058), FRAC_CONST(0.992366), FRAC_CONST(0.971429), FRAC_CONST(0.909091), FRAC_CONST(0.8), FRAC_CONST(0.714286), FRAC_CONST(0.68), FRAC_CONST(0.670103), FRAC_CONST(0.667532), FRAC_CONST(0.666884), FRAC_CONST(0.666721) },
{ FRAC_CONST(0.999939), FRAC_CONST(0.999756), FRAC_CONST(0.999028), FRAC_CONST(0.996169), FRAC_CONST(0.985507), FRAC_CONST(0.952381), FRAC_CONST(0.888889), FRAC_CONST(0.833333), FRAC_CONST(0.809524), FRAC_CONST(0.802469), FRAC_CONST(0.800623), FRAC_CONST(0.800156), FRAC_CONST(0.800039) },
{ FRAC_CONST(0.999969), FRAC_CONST(0.999878), FRAC_CONST(0.999514), FRAC_CONST(0.998081), FRAC_CONST(0.992701), FRAC_CONST(0.97561), FRAC_CONST(0.941176), FRAC_CONST(0.909091), FRAC_CONST(0.894737), FRAC_CONST(0.890411), FRAC_CONST(0.889273), FRAC_CONST(0.888985), FRAC_CONST(0.888913) },
{ FRAC_CONST(0.999985), FRAC_CONST(0.999939), FRAC_CONST(0.999757), FRAC_CONST(0.999039), FRAC_CONST(0.996337), FRAC_CONST(0.987654), FRAC_CONST(0.969697), FRAC_CONST(0.952381), FRAC_CONST(0.944444), FRAC_CONST(0.942029), FRAC_CONST(0.941392), FRAC_CONST(0.94123), FRAC_CONST(0.94119) },
{ FRAC_CONST(0.999992), FRAC_CONST(0.99997), FRAC_CONST(0.999878), FRAC_CONST(0.999519), FRAC_CONST(0.998165), FRAC_CONST(0.993789), FRAC_CONST(0.984615), FRAC_CONST(0.97561), FRAC_CONST(0.971429), FRAC_CONST(0.970149), FRAC_CONST(0.969811), FRAC_CONST(0.969726), FRAC_CONST(0.969704) },
{ FRAC_CONST(0.999996), FRAC_CONST(0.999985), FRAC_CONST(0.999939), FRAC_CONST(0.99976), FRAC_CONST(0.999082), FRAC_CONST(0.996885), FRAC_CONST(0.992248), FRAC_CONST(0.987654), FRAC_CONST(0.985507), FRAC_CONST(0.984848), FRAC_CONST(0.984674), FRAC_CONST(0.98463), FRAC_CONST(0.984619) },
{ FRAC_CONST(0.999998), FRAC_CONST(0.999992), FRAC_CONST(0.99997), FRAC_CONST(0.99988), FRAC_CONST(0.999541), FRAC_CONST(0.99844), FRAC_CONST(0.996109), FRAC_CONST(0.993789), FRAC_CONST(0.992701), FRAC_CONST(0.992366), FRAC_CONST(0.992278), FRAC_CONST(0.992256), FRAC_CONST(0.99225) },
{ FRAC_CONST(0.999999), FRAC_CONST(0.999996), FRAC_CONST(0.999985), FRAC_CONST(0.99994), FRAC_CONST(0.99977), FRAC_CONST(0.999219), FRAC_CONST(0.998051), FRAC_CONST(0.996885), FRAC_CONST(0.996337), FRAC_CONST(0.996169), FRAC_CONST(0.996124), FRAC_CONST(0.996113), FRAC_CONST(0.99611) },
{ FRAC_CONST(1), FRAC_CONST(0.999998), FRAC_CONST(0.999992), FRAC_CONST(0.99997), FRAC_CONST(0.999885), FRAC_CONST(0.99961), FRAC_CONST(0.999024), FRAC_CONST(0.99844), FRAC_CONST(0.998165), FRAC_CONST(0.998081), FRAC_CONST(0.998058), FRAC_CONST(0.998053), FRAC_CONST(0.998051) },
{ FRAC_CONST(1), FRAC_CONST(0.999999), FRAC_CONST(0.999996), FRAC_CONST(0.999985), FRAC_CONST(0.999943), FRAC_CONST(0.999805), FRAC_CONST(0.999512), FRAC_CONST(0.999219), FRAC_CONST(0.999082), FRAC_CONST(0.999039), FRAC_CONST(0.999028), FRAC_CONST(0.999025), FRAC_CONST(0.999025) },
{ FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(0.999998), FRAC_CONST(0.999992), FRAC_CONST(0.999971), FRAC_CONST(0.999902), FRAC_CONST(0.999756), FRAC_CONST(0.99961), FRAC_CONST(0.999541), FRAC_CONST(0.999519), FRAC_CONST(0.999514), FRAC_CONST(0.999512), FRAC_CONST(0.999512) },
{ FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(0.999999), FRAC_CONST(0.999996), FRAC_CONST(0.999986), FRAC_CONST(0.999951), FRAC_CONST(0.999878), FRAC_CONST(0.999805), FRAC_CONST(0.99977), FRAC_CONST(0.99976), FRAC_CONST(0.999757), FRAC_CONST(0.999756), FRAC_CONST(0.999756) },
{ FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(0.999998), FRAC_CONST(0.999993), FRAC_CONST(0.999976), FRAC_CONST(0.999939), FRAC_CONST(0.999902), FRAC_CONST(0.999885), FRAC_CONST(0.99988), FRAC_CONST(0.999878), FRAC_CONST(0.999878), FRAC_CONST(0.999878) },
{ FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(0.999999), FRAC_CONST(0.999996), FRAC_CONST(0.999988), FRAC_CONST(0.999969), FRAC_CONST(0.999951), FRAC_CONST(0.999943), FRAC_CONST(0.99994), FRAC_CONST(0.999939), FRAC_CONST(0.999939), FRAC_CONST(0.999939) },
{ FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(0.999998), FRAC_CONST(0.999994), FRAC_CONST(0.999985), FRAC_CONST(0.999976), FRAC_CONST(0.999971), FRAC_CONST(0.99997), FRAC_CONST(0.99997), FRAC_CONST(0.99997), FRAC_CONST(0.999969) },
{ FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(0.999999), FRAC_CONST(0.999997), FRAC_CONST(0.999992), FRAC_CONST(0.999988), FRAC_CONST(0.999986), FRAC_CONST(0.999985), FRAC_CONST(0.999985), FRAC_CONST(0.999985), FRAC_CONST(0.999985) },
{ FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(0.999998), FRAC_CONST(0.999996), FRAC_CONST(0.999994), FRAC_CONST(0.999993), FRAC_CONST(0.999992), FRAC_CONST(0.999992), FRAC_CONST(0.999992), FRAC_CONST(0.999992) },
{ FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(0.999999), FRAC_CONST(0.999998), FRAC_CONST(0.999997), FRAC_CONST(0.999996), FRAC_CONST(0.999996), FRAC_CONST(0.999996), FRAC_CONST(0.999996), FRAC_CONST(0.999996) },
{ FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(0.999999), FRAC_CONST(0.999998), FRAC_CONST(0.999998), FRAC_CONST(0.999998), FRAC_CONST(0.999998), FRAC_CONST(0.999998), FRAC_CONST(0.999998) },
{ FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(0.999999), FRAC_CONST(0.999999), FRAC_CONST(0.999999), FRAC_CONST(0.999999), FRAC_CONST(0.999999), FRAC_CONST(0.999999) },
{ FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1) },
{ FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1) },
{ FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1) }
};
static const real_t Q_div_tab_right[31][13] = {
{ FRAC_CONST(0.00775382), FRAC_CONST(0.00775945), FRAC_CONST(0.00778198), FRAC_CONST(0.00787211), FRAC_CONST(0.00823245), FRAC_CONST(0.00967118), FRAC_CONST(0.0153846), FRAC_CONST(0.037594), FRAC_CONST(0.117241), FRAC_CONST(0.336788), FRAC_CONST(0.667532), FRAC_CONST(0.888985), FRAC_CONST(0.969704) },
{ FRAC_CONST(0.0153883), FRAC_CONST(0.0153994), FRAC_CONST(0.0154438), FRAC_CONST(0.0156212), FRAC_CONST(0.0163305), FRAC_CONST(0.0191571), FRAC_CONST(0.030303), FRAC_CONST(0.0724638), FRAC_CONST(0.209877), FRAC_CONST(0.503876), FRAC_CONST(0.800623), FRAC_CONST(0.94123), FRAC_CONST(0.984619) },
{ FRAC_CONST(0.0303102), FRAC_CONST(0.0303317), FRAC_CONST(0.0304178), FRAC_CONST(0.0307619), FRAC_CONST(0.0321361), FRAC_CONST(0.037594), FRAC_CONST(0.0588235), FRAC_CONST(0.135135), FRAC_CONST(0.346939), FRAC_CONST(0.670103), FRAC_CONST(0.889273), FRAC_CONST(0.969726), FRAC_CONST(0.99225) },
{ FRAC_CONST(0.058837), FRAC_CONST(0.0588776), FRAC_CONST(0.0590397), FRAC_CONST(0.0596878), FRAC_CONST(0.0622711), FRAC_CONST(0.0724638), FRAC_CONST(0.111111), FRAC_CONST(0.238095), FRAC_CONST(0.515152), FRAC_CONST(0.802469), FRAC_CONST(0.941392), FRAC_CONST(0.98463), FRAC_CONST(0.99611) },
{ FRAC_CONST(0.111135), FRAC_CONST(0.111208), FRAC_CONST(0.111497), FRAC_CONST(0.112652), FRAC_CONST(0.117241), FRAC_CONST(0.135135), FRAC_CONST(0.2), FRAC_CONST(0.384615), FRAC_CONST(0.68), FRAC_CONST(0.890411), FRAC_CONST(0.969811), FRAC_CONST(0.992256), FRAC_CONST(0.998051) },
{ FRAC_CONST(0.200039), FRAC_CONST(0.200156), FRAC_CONST(0.200625), FRAC_CONST(0.202492), FRAC_CONST(0.209877), FRAC_CONST(0.238095), FRAC_CONST(0.333333), FRAC_CONST(0.555556), FRAC_CONST(0.809524), FRAC_CONST(0.942029), FRAC_CONST(0.984674), FRAC_CONST(0.996113), FRAC_CONST(0.999025) },
{ FRAC_CONST(0.333388), FRAC_CONST(0.33355), FRAC_CONST(0.3342), FRAC_CONST(0.336788), FRAC_CONST(0.346939), FRAC_CONST(0.384615), FRAC_CONST(0.5), FRAC_CONST(0.714286), FRAC_CONST(0.894737), FRAC_CONST(0.970149), FRAC_CONST(0.992278), FRAC_CONST(0.998053), FRAC_CONST(0.999512) },
{ FRAC_CONST(0.500061), FRAC_CONST(0.500244), FRAC_CONST(0.500975), FRAC_CONST(0.503876), FRAC_CONST(0.515152), FRAC_CONST(0.555556), FRAC_CONST(0.666667), FRAC_CONST(0.833333), FRAC_CONST(0.944444), FRAC_CONST(0.984848), FRAC_CONST(0.996124), FRAC_CONST(0.999025), FRAC_CONST(0.999756) },
{ FRAC_CONST(0.666721), FRAC_CONST(0.666884), FRAC_CONST(0.667532), FRAC_CONST(0.670103), FRAC_CONST(0.68), FRAC_CONST(0.714286), FRAC_CONST(0.8), FRAC_CONST(0.909091), FRAC_CONST(0.971429), FRAC_CONST(0.992366), FRAC_CONST(0.998058), FRAC_CONST(0.999512), FRAC_CONST(0.999878) },
{ FRAC_CONST(0.800039), FRAC_CONST(0.800156), FRAC_CONST(0.800623), FRAC_CONST(0.802469), FRAC_CONST(0.809524), FRAC_CONST(0.833333), FRAC_CONST(0.888889), FRAC_CONST(0.952381), FRAC_CONST(0.985507), FRAC_CONST(0.996169), FRAC_CONST(0.999028), FRAC_CONST(0.999756), FRAC_CONST(0.999939) },
{ FRAC_CONST(0.888913), FRAC_CONST(0.888985), FRAC_CONST(0.889273), FRAC_CONST(0.890411), FRAC_CONST(0.894737), FRAC_CONST(0.909091), FRAC_CONST(0.941176), FRAC_CONST(0.97561), FRAC_CONST(0.992701), FRAC_CONST(0.998081), FRAC_CONST(0.999514), FRAC_CONST(0.999878), FRAC_CONST(0.999969) },
{ FRAC_CONST(0.94119), FRAC_CONST(0.94123), FRAC_CONST(0.941392), FRAC_CONST(0.942029), FRAC_CONST(0.944444), FRAC_CONST(0.952381), FRAC_CONST(0.969697), FRAC_CONST(0.987654), FRAC_CONST(0.996337), FRAC_CONST(0.999039), FRAC_CONST(0.999757), FRAC_CONST(0.999939), FRAC_CONST(0.999985) },
{ FRAC_CONST(0.969704), FRAC_CONST(0.969726), FRAC_CONST(0.969811), FRAC_CONST(0.970149), FRAC_CONST(0.971429), FRAC_CONST(0.97561), FRAC_CONST(0.984615), FRAC_CONST(0.993789), FRAC_CONST(0.998165), FRAC_CONST(0.999519), FRAC_CONST(0.999878), FRAC_CONST(0.99997), FRAC_CONST(0.999992) },
{ FRAC_CONST(0.984619), FRAC_CONST(0.98463), FRAC_CONST(0.984674), FRAC_CONST(0.984848), FRAC_CONST(0.985507), FRAC_CONST(0.987654), FRAC_CONST(0.992248), FRAC_CONST(0.996885), FRAC_CONST(0.999082), FRAC_CONST(0.99976), FRAC_CONST(0.999939), FRAC_CONST(0.999985), FRAC_CONST(0.999996) },
{ FRAC_CONST(0.99225), FRAC_CONST(0.992256), FRAC_CONST(0.992278), FRAC_CONST(0.992366), FRAC_CONST(0.992701), FRAC_CONST(0.993789), FRAC_CONST(0.996109), FRAC_CONST(0.99844), FRAC_CONST(0.999541), FRAC_CONST(0.99988), FRAC_CONST(0.99997), FRAC_CONST(0.999992), FRAC_CONST(0.999998) },
{ FRAC_CONST(0.99611), FRAC_CONST(0.996113), FRAC_CONST(0.996124), FRAC_CONST(0.996169), FRAC_CONST(0.996337), FRAC_CONST(0.996885), FRAC_CONST(0.998051), FRAC_CONST(0.999219), FRAC_CONST(0.99977), FRAC_CONST(0.99994), FRAC_CONST(0.999985), FRAC_CONST(0.999996), FRAC_CONST(0.999999) },
{ FRAC_CONST(0.998051), FRAC_CONST(0.998053), FRAC_CONST(0.998058), FRAC_CONST(0.998081), FRAC_CONST(0.998165), FRAC_CONST(0.99844), FRAC_CONST(0.999024), FRAC_CONST(0.99961), FRAC_CONST(0.999885), FRAC_CONST(0.99997), FRAC_CONST(0.999992), FRAC_CONST(0.999998), FRAC_CONST(1) },
{ FRAC_CONST(0.999025), FRAC_CONST(0.999025), FRAC_CONST(0.999028), FRAC_CONST(0.999039), FRAC_CONST(0.999082), FRAC_CONST(0.999219), FRAC_CONST(0.999512), FRAC_CONST(0.999805), FRAC_CONST(0.999943), FRAC_CONST(0.999985), FRAC_CONST(0.999996), FRAC_CONST(0.999999), FRAC_CONST(1) },
{ FRAC_CONST(0.999512), FRAC_CONST(0.999512), FRAC_CONST(0.999514), FRAC_CONST(0.999519), FRAC_CONST(0.999541), FRAC_CONST(0.99961), FRAC_CONST(0.999756), FRAC_CONST(0.999902), FRAC_CONST(0.999971), FRAC_CONST(0.999992), FRAC_CONST(0.999998), FRAC_CONST(1), FRAC_CONST(1) },
{ FRAC_CONST(0.999756), FRAC_CONST(0.999756), FRAC_CONST(0.999757), FRAC_CONST(0.99976), FRAC_CONST(0.99977), FRAC_CONST(0.999805), FRAC_CONST(0.999878), FRAC_CONST(0.999951), FRAC_CONST(0.999986), FRAC_CONST(0.999996), FRAC_CONST(0.999999), FRAC_CONST(1), FRAC_CONST(1) },
{ FRAC_CONST(0.999878), FRAC_CONST(0.999878), FRAC_CONST(0.999878), FRAC_CONST(0.99988), FRAC_CONST(0.999885), FRAC_CONST(0.999902), FRAC_CONST(0.999939), FRAC_CONST(0.999976), FRAC_CONST(0.999993), FRAC_CONST(0.999998), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1) },
{ FRAC_CONST(0.999939), FRAC_CONST(0.999939), FRAC_CONST(0.999939), FRAC_CONST(0.99994), FRAC_CONST(0.999943), FRAC_CONST(0.999951), FRAC_CONST(0.999969), FRAC_CONST(0.999988), FRAC_CONST(0.999996), FRAC_CONST(0.999999), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1) },
{ FRAC_CONST(0.999969), FRAC_CONST(0.99997), FRAC_CONST(0.99997), FRAC_CONST(0.99997), FRAC_CONST(0.999971), FRAC_CONST(0.999976), FRAC_CONST(0.999985), FRAC_CONST(0.999994), FRAC_CONST(0.999998), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1) },
{ FRAC_CONST(0.999985), FRAC_CONST(0.999985), FRAC_CONST(0.999985), FRAC_CONST(0.999985), FRAC_CONST(0.999986), FRAC_CONST(0.999988), FRAC_CONST(0.999992), FRAC_CONST(0.999997), FRAC_CONST(0.999999), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1) },
{ FRAC_CONST(0.999992), FRAC_CONST(0.999992), FRAC_CONST(0.999992), FRAC_CONST(0.999992), FRAC_CONST(0.999993), FRAC_CONST(0.999994), FRAC_CONST(0.999996), FRAC_CONST(0.999998), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1) },
{ FRAC_CONST(0.999996), FRAC_CONST(0.999996), FRAC_CONST(0.999996), FRAC_CONST(0.999996), FRAC_CONST(0.999996), FRAC_CONST(0.999997), FRAC_CONST(0.999998), FRAC_CONST(0.999999), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1) },
{ FRAC_CONST(0.999998), FRAC_CONST(0.999998), FRAC_CONST(0.999998), FRAC_CONST(0.999998), FRAC_CONST(0.999998), FRAC_CONST(0.999998), FRAC_CONST(0.999999), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1) },
{ FRAC_CONST(0.999999), FRAC_CONST(0.999999), FRAC_CONST(0.999999), FRAC_CONST(0.999999), FRAC_CONST(0.999999), FRAC_CONST(0.999999), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1) },
{ FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1) },
{ FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1) },
{ FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1), FRAC_CONST(1) }
};
/* calculates 1/(1+Q) */
/* [0..1] */
static real_t calc_Q_div(sbr_info *sbr, uint8_t ch, uint8_t m, uint8_t l)
{
if (sbr->bs_coupling)
{
/* left channel */
if ((sbr->Q[0][m][l] < 0 || sbr->Q[0][m][l] > 30) ||
(sbr->Q[1][m][l] < 0 || sbr->Q[1][m][l] > 24 /* 2*panOffset(1) */))
{
return 0;
} else {
/* the pan parameter is always even */
if (ch == 0)
{
return Q_div_tab_left[sbr->Q[0][m][l]][sbr->Q[1][m][l] >> 1];
} else {
return Q_div_tab_right[sbr->Q[0][m][l]][sbr->Q[1][m][l] >> 1];
}
}
} else {
/* no coupling */
if (sbr->Q[ch][m][l] < 0 || sbr->Q[ch][m][l] > 30)
{
return 0;
} else {
return Q_div_tab[sbr->Q[ch][m][l]];
}
}
}
/* table for Q_div2 values when no coupling */
static const real_t Q_div2_tab[31] = {
FRAC_CONST(0.984615), FRAC_CONST(0.969697),
FRAC_CONST(0.941176), FRAC_CONST(0.888889),
FRAC_CONST(0.8), FRAC_CONST(0.666667),
FRAC_CONST(0.5), FRAC_CONST(0.333333),
FRAC_CONST(0.2), FRAC_CONST(0.111111),
FRAC_CONST(0.0588235), FRAC_CONST(0.030303),
FRAC_CONST(0.0153846), FRAC_CONST(0.00775194),
FRAC_CONST(0.00389105), FRAC_CONST(0.00194932),
FRAC_CONST(0.00097561), FRAC_CONST(0.000488043),
FRAC_CONST(0.000244081), FRAC_CONST(0.000122055),
FRAC_CONST(6.10314E-005), FRAC_CONST(3.05166E-005),
FRAC_CONST(1.52586E-005), FRAC_CONST(7.62934E-006),
FRAC_CONST(3.81468E-006), FRAC_CONST(1.90734E-006),
FRAC_CONST(9.53673E-007), FRAC_CONST(4.76837E-007),
FRAC_CONST(2.38419E-007), FRAC_CONST(1.19209E-007),
FRAC_CONST(5.96046E-008)
};
static const real_t Q_div2_tab_left[31][13] = {
{ FRAC_CONST(0.0302959), FRAC_CONST(0.111015), FRAC_CONST(0.332468), FRAC_CONST(0.663212), FRAC_CONST(0.882759), FRAC_CONST(0.962406), FRAC_CONST(0.984615), FRAC_CONST(0.990329), FRAC_CONST(0.991768), FRAC_CONST(0.992128), FRAC_CONST(0.992218), FRAC_CONST(0.992241), FRAC_CONST(0.992246) },
{ FRAC_CONST(0.0153809), FRAC_CONST(0.0587695), FRAC_CONST(0.199377), FRAC_CONST(0.496124), FRAC_CONST(0.790123), FRAC_CONST(0.927536), FRAC_CONST(0.969697), FRAC_CONST(0.980843), FRAC_CONST(0.98367), FRAC_CONST(0.984379), FRAC_CONST(0.984556), FRAC_CONST(0.984601), FRAC_CONST(0.984612) },
{ FRAC_CONST(0.00775006), FRAC_CONST(0.0302744), FRAC_CONST(0.110727), FRAC_CONST(0.329897), FRAC_CONST(0.653061), FRAC_CONST(0.864865), FRAC_CONST(0.941176), FRAC_CONST(0.962406), FRAC_CONST(0.967864), FRAC_CONST(0.969238), FRAC_CONST(0.969582), FRAC_CONST(0.969668), FRAC_CONST(0.96969) },
{ FRAC_CONST(0.0038901), FRAC_CONST(0.0153698), FRAC_CONST(0.0586081), FRAC_CONST(0.197531), FRAC_CONST(0.484848), FRAC_CONST(0.761905), FRAC_CONST(0.888889), FRAC_CONST(0.927536), FRAC_CONST(0.937729), FRAC_CONST(0.940312), FRAC_CONST(0.94096), FRAC_CONST(0.941122), FRAC_CONST(0.941163) },
{ FRAC_CONST(0.00194884), FRAC_CONST(0.00774443), FRAC_CONST(0.0301887), FRAC_CONST(0.109589), FRAC_CONST(0.32), FRAC_CONST(0.615385), FRAC_CONST(0.8), FRAC_CONST(0.864865), FRAC_CONST(0.882759), FRAC_CONST(0.887348), FRAC_CONST(0.888503), FRAC_CONST(0.888792), FRAC_CONST(0.888865) },
{ FRAC_CONST(0.000975372), FRAC_CONST(0.00388727), FRAC_CONST(0.0153257), FRAC_CONST(0.057971), FRAC_CONST(0.190476), FRAC_CONST(0.444444), FRAC_CONST(0.666667), FRAC_CONST(0.761905), FRAC_CONST(0.790123), FRAC_CONST(0.797508), FRAC_CONST(0.799375), FRAC_CONST(0.799844), FRAC_CONST(0.799961) },
{ FRAC_CONST(0.000487924), FRAC_CONST(0.00194742), FRAC_CONST(0.00772201), FRAC_CONST(0.0298507), FRAC_CONST(0.105263), FRAC_CONST(0.285714), FRAC_CONST(0.5), FRAC_CONST(0.615385), FRAC_CONST(0.653061), FRAC_CONST(0.663212), FRAC_CONST(0.6658), FRAC_CONST(0.66645), FRAC_CONST(0.666612) },
{ FRAC_CONST(0.000244021), FRAC_CONST(0.000974659), FRAC_CONST(0.00387597), FRAC_CONST(0.0151515), FRAC_CONST(0.0555556), FRAC_CONST(0.166667), FRAC_CONST(0.333333), FRAC_CONST(0.444444), FRAC_CONST(0.484848), FRAC_CONST(0.496124), FRAC_CONST(0.499025), FRAC_CONST(0.499756), FRAC_CONST(0.499939) },
{ FRAC_CONST(0.000122026), FRAC_CONST(0.000487567), FRAC_CONST(0.00194175), FRAC_CONST(0.00763359), FRAC_CONST(0.0285714), FRAC_CONST(0.0909091), FRAC_CONST(0.2), FRAC_CONST(0.285714), FRAC_CONST(0.32), FRAC_CONST(0.329897), FRAC_CONST(0.332468), FRAC_CONST(0.333116), FRAC_CONST(0.333279) },
{ FRAC_CONST(6.10165E-005), FRAC_CONST(0.000243843), FRAC_CONST(0.000971817), FRAC_CONST(0.00383142), FRAC_CONST(0.0144928), FRAC_CONST(0.047619), FRAC_CONST(0.111111), FRAC_CONST(0.166667), FRAC_CONST(0.190476), FRAC_CONST(0.197531), FRAC_CONST(0.199377), FRAC_CONST(0.199844), FRAC_CONST(0.199961) },
{ FRAC_CONST(3.05092E-005), FRAC_CONST(0.000121936), FRAC_CONST(0.000486145), FRAC_CONST(0.00191939), FRAC_CONST(0.00729927), FRAC_CONST(0.0243902), FRAC_CONST(0.0588235), FRAC_CONST(0.0909091), FRAC_CONST(0.105263), FRAC_CONST(0.109589), FRAC_CONST(0.110727), FRAC_CONST(0.111015), FRAC_CONST(0.111087) },
{ FRAC_CONST(1.52548E-005), FRAC_CONST(6.09719E-005), FRAC_CONST(0.000243132), FRAC_CONST(0.000960615), FRAC_CONST(0.003663), FRAC_CONST(0.0123457), FRAC_CONST(0.030303), FRAC_CONST(0.047619), FRAC_CONST(0.0555556), FRAC_CONST(0.057971), FRAC_CONST(0.0586081), FRAC_CONST(0.0587695), FRAC_CONST(0.05881) },
{ FRAC_CONST(7.62747E-006), FRAC_CONST(3.04869E-005), FRAC_CONST(0.000121581), FRAC_CONST(0.000480538), FRAC_CONST(0.00183486), FRAC_CONST(0.00621118), FRAC_CONST(0.0153846), FRAC_CONST(0.0243902), FRAC_CONST(0.0285714), FRAC_CONST(0.0298507), FRAC_CONST(0.0301887), FRAC_CONST(0.0302744), FRAC_CONST(0.0302959) },
{ FRAC_CONST(3.81375E-006), FRAC_CONST(1.52437E-005), FRAC_CONST(6.0794E-005), FRAC_CONST(0.000240327), FRAC_CONST(0.000918274), FRAC_CONST(0.00311526), FRAC_CONST(0.00775194), FRAC_CONST(0.0123457), FRAC_CONST(0.0144928), FRAC_CONST(0.0151515), FRAC_CONST(0.0153257), FRAC_CONST(0.0153698), FRAC_CONST(0.0153809) },
{ FRAC_CONST(1.90688E-006), FRAC_CONST(7.62189E-006), FRAC_CONST(3.03979E-005), FRAC_CONST(0.000120178), FRAC_CONST(0.000459348), FRAC_CONST(0.00156006), FRAC_CONST(0.00389105), FRAC_CONST(0.00621118), FRAC_CONST(0.00729927), FRAC_CONST(0.00763359), FRAC_CONST(0.00772201), FRAC_CONST(0.00774443), FRAC_CONST(0.00775006) },
{ FRAC_CONST(9.53441E-007), FRAC_CONST(3.81096E-006), FRAC_CONST(1.51992E-005), FRAC_CONST(6.00925E-005), FRAC_CONST(0.000229727), FRAC_CONST(0.00078064), FRAC_CONST(0.00194932), FRAC_CONST(0.00311526), FRAC_CONST(0.003663), FRAC_CONST(0.00383142), FRAC_CONST(0.00387597), FRAC_CONST(0.00388727), FRAC_CONST(0.0038901) },
{ FRAC_CONST(4.76721E-007), FRAC_CONST(1.90548E-006), FRAC_CONST(7.59965E-006), FRAC_CONST(3.00472E-005), FRAC_CONST(0.000114877), FRAC_CONST(0.000390472), FRAC_CONST(0.00097561), FRAC_CONST(0.00156006), FRAC_CONST(0.00183486), FRAC_CONST(0.00191939), FRAC_CONST(0.00194175), FRAC_CONST(0.00194742), FRAC_CONST(0.00194884) },
{ FRAC_CONST(2.3836E-007), FRAC_CONST(9.52743E-007), FRAC_CONST(3.79984E-006), FRAC_CONST(1.50238E-005), FRAC_CONST(5.74416E-005), FRAC_CONST(0.000195274), FRAC_CONST(0.000488043), FRAC_CONST(0.00078064), FRAC_CONST(0.000918274), FRAC_CONST(0.000960615), FRAC_CONST(0.000971817), FRAC_CONST(0.000974659), FRAC_CONST(0.000975372) },
{ FRAC_CONST(1.1918E-007), FRAC_CONST(4.76372E-007), FRAC_CONST(1.89992E-006), FRAC_CONST(7.51196E-006), FRAC_CONST(2.87216E-005), FRAC_CONST(9.76467E-005), FRAC_CONST(0.000244081), FRAC_CONST(0.000390472), FRAC_CONST(0.000459348), FRAC_CONST(0.000480538), FRAC_CONST(0.000486145), FRAC_CONST(0.000487567), FRAC_CONST(0.000487924) },
{ FRAC_CONST(5.95901E-008), FRAC_CONST(2.38186E-007), FRAC_CONST(9.49963E-007), FRAC_CONST(3.756E-006), FRAC_CONST(1.4361E-005), FRAC_CONST(4.88257E-005), FRAC_CONST(0.000122055), FRAC_CONST(0.000195274), FRAC_CONST(0.000229727), FRAC_CONST(0.000240327), FRAC_CONST(0.000243132), FRAC_CONST(0.000243843), FRAC_CONST(0.000244021) },
{ FRAC_CONST(2.9795E-008), FRAC_CONST(1.19093E-007), FRAC_CONST(4.74982E-007), FRAC_CONST(1.878E-006), FRAC_CONST(7.18056E-006), FRAC_CONST(2.44135E-005), FRAC_CONST(6.10314E-005), FRAC_CONST(9.76467E-005), FRAC_CONST(0.000114877), FRAC_CONST(0.000120178), FRAC_CONST(0.000121581), FRAC_CONST(0.000121936), FRAC_CONST(0.000122026) },
{ FRAC_CONST(1.48975E-008), FRAC_CONST(5.95465E-008), FRAC_CONST(2.37491E-007), FRAC_CONST(9.39002E-007), FRAC_CONST(3.59029E-006), FRAC_CONST(1.22069E-005), FRAC_CONST(3.05166E-005), FRAC_CONST(4.88257E-005), FRAC_CONST(5.74416E-005), FRAC_CONST(6.00925E-005), FRAC_CONST(6.0794E-005), FRAC_CONST(6.09719E-005), FRAC_CONST(6.10165E-005) },
{ FRAC_CONST(7.44876E-009), FRAC_CONST(2.97732E-008), FRAC_CONST(1.18745E-007), FRAC_CONST(4.69501E-007), FRAC_CONST(1.79515E-006), FRAC_CONST(6.10348E-006), FRAC_CONST(1.52586E-005), FRAC_CONST(2.44135E-005), FRAC_CONST(2.87216E-005), FRAC_CONST(3.00472E-005), FRAC_CONST(3.03979E-005), FRAC_CONST(3.04869E-005), FRAC_CONST(3.05092E-005) },
{ FRAC_CONST(3.72438E-009), FRAC_CONST(1.48866E-008), FRAC_CONST(5.93727E-008), FRAC_CONST(2.34751E-007), FRAC_CONST(8.97575E-007), FRAC_CONST(3.05175E-006), FRAC_CONST(7.62934E-006), FRAC_CONST(1.22069E-005), FRAC_CONST(1.4361E-005), FRAC_CONST(1.50238E-005), FRAC_CONST(1.51992E-005), FRAC_CONST(1.52437E-005), FRAC_CONST(1.52548E-005) },
{ FRAC_CONST(1.86219E-009), FRAC_CONST(7.44331E-009), FRAC_CONST(2.96864E-008), FRAC_CONST(1.17375E-007), FRAC_CONST(4.48788E-007), FRAC_CONST(1.52588E-006), FRAC_CONST(3.81468E-006), FRAC_CONST(6.10348E-006), FRAC_CONST(7.18056E-006), FRAC_CONST(7.51196E-006), FRAC_CONST(7.59965E-006), FRAC_CONST(7.62189E-006), FRAC_CONST(7.62747E-006) },
{ FRAC_CONST(9.31095E-010), FRAC_CONST(3.72166E-009), FRAC_CONST(1.48432E-008), FRAC_CONST(5.86876E-008), FRAC_CONST(2.24394E-007), FRAC_CONST(7.62939E-007), FRAC_CONST(1.90734E-006), FRAC_CONST(3.05175E-006), FRAC_CONST(3.59029E-006), FRAC_CONST(3.756E-006), FRAC_CONST(3.79984E-006), FRAC_CONST(3.81096E-006), FRAC_CONST(3.81375E-006) },
{ FRAC_CONST(4.65548E-010), FRAC_CONST(1.86083E-009), FRAC_CONST(7.42159E-009), FRAC_CONST(2.93438E-008), FRAC_CONST(1.12197E-007), FRAC_CONST(3.8147E-007), FRAC_CONST(9.53673E-007), FRAC_CONST(1.52588E-006), FRAC_CONST(1.79515E-006), FRAC_CONST(1.878E-006), FRAC_CONST(1.89992E-006), FRAC_CONST(1.90548E-006), FRAC_CONST(1.90688E-006) },
{ FRAC_CONST(2.32774E-010), FRAC_CONST(9.30414E-010), FRAC_CONST(3.71079E-009), FRAC_CONST(1.46719E-008), FRAC_CONST(5.60985E-008), FRAC_CONST(1.90735E-007), FRAC_CONST(4.76837E-007), FRAC_CONST(7.62939E-007), FRAC_CONST(8.97575E-007), FRAC_CONST(9.39002E-007), FRAC_CONST(9.49963E-007), FRAC_CONST(9.52743E-007), FRAC_CONST(9.53441E-007) },
{ FRAC_CONST(1.16387E-010), FRAC_CONST(4.65207E-010), FRAC_CONST(1.8554E-009), FRAC_CONST(7.33596E-009), FRAC_CONST(2.80492E-008), FRAC_CONST(9.53674E-008), FRAC_CONST(2.38419E-007), FRAC_CONST(3.8147E-007), FRAC_CONST(4.48788E-007), FRAC_CONST(4.69501E-007), FRAC_CONST(4.74982E-007), FRAC_CONST(4.76372E-007), FRAC_CONST(4.76721E-007) },
{ FRAC_CONST(5.81935E-011), FRAC_CONST(2.32603E-010), FRAC_CONST(9.27699E-010), FRAC_CONST(3.66798E-009), FRAC_CONST(1.40246E-008), FRAC_CONST(4.76837E-008), FRAC_CONST(1.19209E-007), FRAC_CONST(1.90735E-007), FRAC_CONST(2.24394E-007), FRAC_CONST(2.34751E-007), FRAC_CONST(2.37491E-007), FRAC_CONST(2.38186E-007), FRAC_CONST(2.3836E-007) },
{ FRAC_CONST(2.90967E-011), FRAC_CONST(1.16302E-010), FRAC_CONST(4.63849E-010), FRAC_CONST(1.83399E-009), FRAC_CONST(7.01231E-009), FRAC_CONST(2.38419E-008), FRAC_CONST(5.96046E-008), FRAC_CONST(9.53674E-008), FRAC_CONST(1.12197E-007), FRAC_CONST(1.17375E-007), FRAC_CONST(1.18745E-007), FRAC_CONST(1.19093E-007), FRAC_CONST(1.1918E-007) }
};
static const real_t Q_div2_tab_right[31][13] = {
{ FRAC_CONST(0.992246), FRAC_CONST(0.992241), FRAC_CONST(0.992218), FRAC_CONST(0.992128), FRAC_CONST(0.991768), FRAC_CONST(0.990329), FRAC_CONST(0.984615), FRAC_CONST(0.962406), FRAC_CONST(0.882759), FRAC_CONST(0.663212), FRAC_CONST(0.332468), FRAC_CONST(0.111015), FRAC_CONST(0.0302959) },
{ FRAC_CONST(0.984612), FRAC_CONST(0.984601), FRAC_CONST(0.984556), FRAC_CONST(0.984379), FRAC_CONST(0.98367), FRAC_CONST(0.980843), FRAC_CONST(0.969697), FRAC_CONST(0.927536), FRAC_CONST(0.790123), FRAC_CONST(0.496124), FRAC_CONST(0.199377), FRAC_CONST(0.0587695), FRAC_CONST(0.0153809) },
{ FRAC_CONST(0.96969), FRAC_CONST(0.969668), FRAC_CONST(0.969582), FRAC_CONST(0.969238), FRAC_CONST(0.967864), FRAC_CONST(0.962406), FRAC_CONST(0.941176), FRAC_CONST(0.864865), FRAC_CONST(0.653061), FRAC_CONST(0.329897), FRAC_CONST(0.110727), FRAC_CONST(0.0302744), FRAC_CONST(0.00775006) },
{ FRAC_CONST(0.941163), FRAC_CONST(0.941122), FRAC_CONST(0.94096), FRAC_CONST(0.940312), FRAC_CONST(0.937729), FRAC_CONST(0.927536), FRAC_CONST(0.888889), FRAC_CONST(0.761905), FRAC_CONST(0.484848), FRAC_CONST(0.197531), FRAC_CONST(0.0586081), FRAC_CONST(0.0153698), FRAC_CONST(0.0038901) },
{ FRAC_CONST(0.888865), FRAC_CONST(0.888792), FRAC_CONST(0.888503), FRAC_CONST(0.887348), FRAC_CONST(0.882759), FRAC_CONST(0.864865), FRAC_CONST(0.8), FRAC_CONST(0.615385), FRAC_CONST(0.32), FRAC_CONST(0.109589), FRAC_CONST(0.0301887), FRAC_CONST(0.00774443), FRAC_CONST(0.00194884) },
{ FRAC_CONST(0.799961), FRAC_CONST(0.799844), FRAC_CONST(0.799375), FRAC_CONST(0.797508), FRAC_CONST(0.790123), FRAC_CONST(0.761905), FRAC_CONST(0.666667), FRAC_CONST(0.444444), FRAC_CONST(0.190476), FRAC_CONST(0.057971), FRAC_CONST(0.0153257), FRAC_CONST(0.00388727), FRAC_CONST(0.000975372) },
{ FRAC_CONST(0.666612), FRAC_CONST(0.66645), FRAC_CONST(0.6658), FRAC_CONST(0.663212), FRAC_CONST(0.653061), FRAC_CONST(0.615385), FRAC_CONST(0.5), FRAC_CONST(0.285714), FRAC_CONST(0.105263), FRAC_CONST(0.0298507), FRAC_CONST(0.00772201), FRAC_CONST(0.00194742), FRAC_CONST(0.000487924) },
{ FRAC_CONST(0.499939), FRAC_CONST(0.499756), FRAC_CONST(0.499025), FRAC_CONST(0.496124), FRAC_CONST(0.484848), FRAC_CONST(0.444444), FRAC_CONST(0.333333), FRAC_CONST(0.166667), FRAC_CONST(0.0555556), FRAC_CONST(0.0151515), FRAC_CONST(0.00387597), FRAC_CONST(0.000974659), FRAC_CONST(0.000244021) },
{ FRAC_CONST(0.333279), FRAC_CONST(0.333116), FRAC_CONST(0.332468), FRAC_CONST(0.329897), FRAC_CONST(0.32), FRAC_CONST(0.285714), FRAC_CONST(0.2), FRAC_CONST(0.0909091), FRAC_CONST(0.0285714), FRAC_CONST(0.00763359), FRAC_CONST(0.00194175), FRAC_CONST(0.000487567), FRAC_CONST(0.000122026) },
{ FRAC_CONST(0.199961), FRAC_CONST(0.199844), FRAC_CONST(0.199377), FRAC_CONST(0.197531), FRAC_CONST(0.190476), FRAC_CONST(0.166667), FRAC_CONST(0.111111), FRAC_CONST(0.047619), FRAC_CONST(0.0144928), FRAC_CONST(0.00383142), FRAC_CONST(0.000971817), FRAC_CONST(0.000243843), FRAC_CONST(6.10165E-005) },
{ FRAC_CONST(0.111087), FRAC_CONST(0.111015), FRAC_CONST(0.110727), FRAC_CONST(0.109589), FRAC_CONST(0.105263), FRAC_CONST(0.0909091), FRAC_CONST(0.0588235), FRAC_CONST(0.0243902), FRAC_CONST(0.00729927), FRAC_CONST(0.00191939), FRAC_CONST(0.000486145), FRAC_CONST(0.000121936), FRAC_CONST(3.05092E-005) },
{ FRAC_CONST(0.05881), FRAC_CONST(0.0587695), FRAC_CONST(0.0586081), FRAC_CONST(0.057971), FRAC_CONST(0.0555556), FRAC_CONST(0.047619), FRAC_CONST(0.030303), FRAC_CONST(0.0123457), FRAC_CONST(0.003663), FRAC_CONST(0.000960615), FRAC_CONST(0.000243132), FRAC_CONST(6.09719E-005), FRAC_CONST(1.52548E-005) },
{ FRAC_CONST(0.0302959), FRAC_CONST(0.0302744), FRAC_CONST(0.0301887), FRAC_CONST(0.0298507), FRAC_CONST(0.0285714), FRAC_CONST(0.0243902), FRAC_CONST(0.0153846), FRAC_CONST(0.00621118), FRAC_CONST(0.00183486), FRAC_CONST(0.000480538), FRAC_CONST(0.000121581), FRAC_CONST(3.04869E-005), FRAC_CONST(7.62747E-006) },
{ FRAC_CONST(0.0153809), FRAC_CONST(0.0153698), FRAC_CONST(0.0153257), FRAC_CONST(0.0151515), FRAC_CONST(0.0144928), FRAC_CONST(0.0123457), FRAC_CONST(0.00775194), FRAC_CONST(0.00311526), FRAC_CONST(0.000918274), FRAC_CONST(0.000240327), FRAC_CONST(6.0794E-005), FRAC_CONST(1.52437E-005), FRAC_CONST(3.81375E-006) },
{ FRAC_CONST(0.00775006), FRAC_CONST(0.00774443), FRAC_CONST(0.00772201), FRAC_CONST(0.00763359), FRAC_CONST(0.00729927), FRAC_CONST(0.00621118), FRAC_CONST(0.00389105), FRAC_CONST(0.00156006), FRAC_CONST(0.000459348), FRAC_CONST(0.000120178), FRAC_CONST(3.03979E-005), FRAC_CONST(7.62189E-006), FRAC_CONST(1.90688E-006) },
{ FRAC_CONST(0.0038901), FRAC_CONST(0.00388727), FRAC_CONST(0.00387597), FRAC_CONST(0.00383142), FRAC_CONST(0.003663), FRAC_CONST(0.00311526), FRAC_CONST(0.00194932), FRAC_CONST(0.00078064), FRAC_CONST(0.000229727), FRAC_CONST(6.00925E-005), FRAC_CONST(1.51992E-005), FRAC_CONST(3.81096E-006), FRAC_CONST(9.53441E-007) },
{ FRAC_CONST(0.00194884), FRAC_CONST(0.00194742), FRAC_CONST(0.00194175), FRAC_CONST(0.00191939), FRAC_CONST(0.00183486), FRAC_CONST(0.00156006), FRAC_CONST(0.00097561), FRAC_CONST(0.000390472), FRAC_CONST(0.000114877), FRAC_CONST(3.00472E-005), FRAC_CONST(7.59965E-006), FRAC_CONST(1.90548E-006), FRAC_CONST(4.76721E-007) },
{ FRAC_CONST(0.000975372), FRAC_CONST(0.000974659), FRAC_CONST(0.000971817), FRAC_CONST(0.000960615), FRAC_CONST(0.000918274), FRAC_CONST(0.00078064), FRAC_CONST(0.000488043), FRAC_CONST(0.000195274), FRAC_CONST(5.74416E-005), FRAC_CONST(1.50238E-005), FRAC_CONST(3.79984E-006), FRAC_CONST(9.52743E-007), FRAC_CONST(2.3836E-007) },
{ FRAC_CONST(0.000487924), FRAC_CONST(0.000487567), FRAC_CONST(0.000486145), FRAC_CONST(0.000480538), FRAC_CONST(0.000459348), FRAC_CONST(0.000390472), FRAC_CONST(0.000244081), FRAC_CONST(9.76467E-005), FRAC_CONST(2.87216E-005), FRAC_CONST(7.51196E-006), FRAC_CONST(1.89992E-006), FRAC_CONST(4.76372E-007), FRAC_CONST(1.1918E-007) },
{ FRAC_CONST(0.000244021), FRAC_CONST(0.000243843), FRAC_CONST(0.000243132), FRAC_CONST(0.000240327), FRAC_CONST(0.000229727), FRAC_CONST(0.000195274), FRAC_CONST(0.000122055), FRAC_CONST(4.88257E-005), FRAC_CONST(1.4361E-005), FRAC_CONST(3.756E-006), FRAC_CONST(9.49963E-007), FRAC_CONST(2.38186E-007), FRAC_CONST(5.95901E-008) },
{ FRAC_CONST(0.000122026), FRAC_CONST(0.000121936), FRAC_CONST(0.000121581), FRAC_CONST(0.000120178), FRAC_CONST(0.000114877), FRAC_CONST(9.76467E-005), FRAC_CONST(6.10314E-005), FRAC_CONST(2.44135E-005), FRAC_CONST(7.18056E-006), FRAC_CONST(1.878E-006), FRAC_CONST(4.74982E-007), FRAC_CONST(1.19093E-007), FRAC_CONST(2.9795E-008) },
{ FRAC_CONST(6.10165E-005), FRAC_CONST(6.09719E-005), FRAC_CONST(6.0794E-005), FRAC_CONST(6.00925E-005), FRAC_CONST(5.74416E-005), FRAC_CONST(4.88257E-005), FRAC_CONST(3.05166E-005), FRAC_CONST(1.22069E-005), FRAC_CONST(3.59029E-006), FRAC_CONST(9.39002E-007), FRAC_CONST(2.37491E-007), FRAC_CONST(5.95465E-008), FRAC_CONST(1.48975E-008) },
{ FRAC_CONST(3.05092E-005), FRAC_CONST(3.04869E-005), FRAC_CONST(3.03979E-005), FRAC_CONST(3.00472E-005), FRAC_CONST(2.87216E-005), FRAC_CONST(2.44135E-005), FRAC_CONST(1.52586E-005), FRAC_CONST(6.10348E-006), FRAC_CONST(1.79515E-006), FRAC_CONST(4.69501E-007), FRAC_CONST(1.18745E-007), FRAC_CONST(2.97732E-008), FRAC_CONST(7.44876E-009) },
{ FRAC_CONST(1.52548E-005), FRAC_CONST(1.52437E-005), FRAC_CONST(1.51992E-005), FRAC_CONST(1.50238E-005), FRAC_CONST(1.4361E-005), FRAC_CONST(1.22069E-005), FRAC_CONST(7.62934E-006), FRAC_CONST(3.05175E-006), FRAC_CONST(8.97575E-007), FRAC_CONST(2.34751E-007), FRAC_CONST(5.93727E-008), FRAC_CONST(1.48866E-008), FRAC_CONST(3.72438E-009) },
{ FRAC_CONST(7.62747E-006), FRAC_CONST(7.62189E-006), FRAC_CONST(7.59965E-006), FRAC_CONST(7.51196E-006), FRAC_CONST(7.18056E-006), FRAC_CONST(6.10348E-006), FRAC_CONST(3.81468E-006), FRAC_CONST(1.52588E-006), FRAC_CONST(4.48788E-007), FRAC_CONST(1.17375E-007), FRAC_CONST(2.96864E-008), FRAC_CONST(7.44331E-009), FRAC_CONST(1.86219E-009) },
{ FRAC_CONST(3.81375E-006), FRAC_CONST(3.81096E-006), FRAC_CONST(3.79984E-006), FRAC_CONST(3.756E-006), FRAC_CONST(3.59029E-006), FRAC_CONST(3.05175E-006), FRAC_CONST(1.90734E-006), FRAC_CONST(7.62939E-007), FRAC_CONST(2.24394E-007), FRAC_CONST(5.86876E-008), FRAC_CONST(1.48432E-008), FRAC_CONST(3.72166E-009), FRAC_CONST(9.31095E-010) },
{ FRAC_CONST(1.90688E-006), FRAC_CONST(1.90548E-006), FRAC_CONST(1.89992E-006), FRAC_CONST(1.878E-006), FRAC_CONST(1.79515E-006), FRAC_CONST(1.52588E-006), FRAC_CONST(9.53673E-007), FRAC_CONST(3.8147E-007), FRAC_CONST(1.12197E-007), FRAC_CONST(2.93438E-008), FRAC_CONST(7.42159E-009), FRAC_CONST(1.86083E-009), FRAC_CONST(4.65548E-010) },
{ FRAC_CONST(9.53441E-007), FRAC_CONST(9.52743E-007), FRAC_CONST(9.49963E-007), FRAC_CONST(9.39002E-007), FRAC_CONST(8.97575E-007), FRAC_CONST(7.62939E-007), FRAC_CONST(4.76837E-007), FRAC_CONST(1.90735E-007), FRAC_CONST(5.60985E-008), FRAC_CONST(1.46719E-008), FRAC_CONST(3.71079E-009), FRAC_CONST(9.30414E-010), FRAC_CONST(2.32774E-010) },
{ FRAC_CONST(4.76721E-007), FRAC_CONST(4.76372E-007), FRAC_CONST(4.74982E-007), FRAC_CONST(4.69501E-007), FRAC_CONST(4.48788E-007), FRAC_CONST(3.8147E-007), FRAC_CONST(2.38419E-007), FRAC_CONST(9.53674E-008), FRAC_CONST(2.80492E-008), FRAC_CONST(7.33596E-009), FRAC_CONST(1.8554E-009), FRAC_CONST(4.65207E-010), FRAC_CONST(1.16387E-010) },
{ FRAC_CONST(2.3836E-007), FRAC_CONST(2.38186E-007), FRAC_CONST(2.37491E-007), FRAC_CONST(2.34751E-007), FRAC_CONST(2.24394E-007), FRAC_CONST(1.90735E-007), FRAC_CONST(1.19209E-007), FRAC_CONST(4.76837E-008), FRAC_CONST(1.40246E-008), FRAC_CONST(3.66798E-009), FRAC_CONST(9.27699E-010), FRAC_CONST(2.32603E-010), FRAC_CONST(5.81935E-011) },
{ FRAC_CONST(1.1918E-007), FRAC_CONST(1.19093E-007), FRAC_CONST(1.18745E-007), FRAC_CONST(1.17375E-007), FRAC_CONST(1.12197E-007), FRAC_CONST(9.53674E-008), FRAC_CONST(5.96046E-008), FRAC_CONST(2.38419E-008), FRAC_CONST(7.01231E-009), FRAC_CONST(1.83399E-009), FRAC_CONST(4.63849E-010), FRAC_CONST(1.16302E-010), FRAC_CONST(2.90967E-011) }
};
/* calculates Q/(1+Q) */
/* [0..1] */
static real_t calc_Q_div2(sbr_info *sbr, uint8_t ch, uint8_t m, uint8_t l)
{
if (sbr->bs_coupling)
{
if ((sbr->Q[0][m][l] < 0 || sbr->Q[0][m][l] > 30) ||
(sbr->Q[1][m][l] < 0 || sbr->Q[1][m][l] > 24 /* 2*panOffset(1) */))
{
return 0;
} else {
/* the pan parameter is always even */
if (ch == 0)
{
return Q_div2_tab_left[sbr->Q[0][m][l]][sbr->Q[1][m][l] >> 1];
} else {
return Q_div2_tab_right[sbr->Q[0][m][l]][sbr->Q[1][m][l] >> 1];
}
}
} else {
/* no coupling */
if (sbr->Q[ch][m][l] < 0 || sbr->Q[ch][m][l] > 30)
{
return 0;
} else {
return Q_div2_tab[sbr->Q[ch][m][l]];
}
}
}
static const real_t E_deq_tab[64] = {
64.0f, 128.0f, 256.0f, 512.0f, 1024.0f, 2048.0f, 4096.0f, 8192.0f,
16384.0f, 32768.0f, 65536.0f, 131072.0f, 262144.0f, 524288.0f, 1.04858E+006f, 2.09715E+006f,
4.1943E+006f, 8.38861E+006f, 1.67772E+007f, 3.35544E+007f, 6.71089E+007f, 1.34218E+008f, 2.68435E+008f, 5.36871E+008f,
1.07374E+009f, 2.14748E+009f, 4.29497E+009f, 8.58993E+009f, 1.71799E+010f, 3.43597E+010f, 6.87195E+010f, 1.37439E+011f,
2.74878E+011f, 5.49756E+011f, 1.09951E+012f, 2.19902E+012f, 4.39805E+012f, 8.79609E+012f, 1.75922E+013f, 3.51844E+013f,
7.03687E+013f, 1.40737E+014f, 2.81475E+014f, 5.6295E+014f, 1.1259E+015f, 2.2518E+015f, 4.5036E+015f, 9.0072E+015f,
1.80144E+016f, 3.60288E+016f, 7.20576E+016f, 1.44115E+017f, 2.8823E+017f, 5.76461E+017f, 1.15292E+018f, 2.30584E+018f,
4.61169E+018f, 9.22337E+018f, 1.84467E+019f, 3.68935E+019f, 7.3787E+019f, 1.47574E+020f, 2.95148E+020f, 5.90296E+020f
};
void envelope_noise_dequantisation(sbr_info *sbr, uint8_t ch)
{
if (sbr->bs_coupling == 0)
{
int16_t exp;
uint8_t l, k;
uint8_t amp = (sbr->amp_res[ch]) ? 0 : 1;
for (l = 0; l < sbr->L_E[ch]; l++)
{
for (k = 0; k < sbr->n[sbr->f[ch][l]]; k++)
{
/* +6 for the *64 and -10 for the /32 in the synthesis QMF (fixed)
* since this is a energy value: (x/32)^2 = (x^2)/1024
*/
/* exp = (sbr->E[ch][k][l] >> amp) + 6; */
exp = (sbr->E[ch][k][l] >> amp);
if ((exp < 0) || (exp >= 64))
{
sbr->E_orig[ch][k][l] = 0;
} else {
sbr->E_orig[ch][k][l] = E_deq_tab[exp];
/* save half the table size at the cost of 1 multiply */
if (amp && (sbr->E[ch][k][l] & 1))
{
sbr->E_orig[ch][k][l] = MUL_C(sbr->E_orig[ch][k][l], COEF_CONST(1.414213562));
}
}
}
}
for (l = 0; l < sbr->L_Q[ch]; l++)
{
for (k = 0; k < sbr->N_Q; k++)
{
sbr->Q_div[ch][k][l] = calc_Q_div(sbr, ch, k, l);
sbr->Q_div2[ch][k][l] = calc_Q_div2(sbr, ch, k, l);
}
}
}
}
static const real_t E_pan_tab[25] = {
FRAC_CONST(0.000244081), FRAC_CONST(0.000488043),
FRAC_CONST(0.00097561), FRAC_CONST(0.00194932),
FRAC_CONST(0.00389105), FRAC_CONST(0.00775194),
FRAC_CONST(0.0153846), FRAC_CONST(0.030303),
FRAC_CONST(0.0588235), FRAC_CONST(0.111111),
FRAC_CONST(0.2), FRAC_CONST(0.333333),
FRAC_CONST(0.5), FRAC_CONST(0.666667),
FRAC_CONST(0.8), FRAC_CONST(0.888889),
FRAC_CONST(0.941176), FRAC_CONST(0.969697),
FRAC_CONST(0.984615), FRAC_CONST(0.992248),
FRAC_CONST(0.996109), FRAC_CONST(0.998051),
FRAC_CONST(0.999024), FRAC_CONST(0.999512),
FRAC_CONST(0.999756)
};
void unmap_envelope_noise(sbr_info *sbr)
{
real_t tmp;
int16_t exp0, exp1;
uint8_t l, k;
uint8_t amp0 = (sbr->amp_res[0]) ? 0 : 1;
uint8_t amp1 = (sbr->amp_res[1]) ? 0 : 1;
for (l = 0; l < sbr->L_E[0]; l++)
{
for (k = 0; k < sbr->n[sbr->f[0][l]]; k++)
{
/* +6: * 64 ; +1: * 2 ; */
exp0 = (sbr->E[0][k][l] >> amp0) + 1;
/* UN_MAP removed: (x / 4096) same as (x >> 12) */
/* E[1] is always even so no need for compensating the divide by 2 with
* an extra multiplication
*/
/* exp1 = (sbr->E[1][k][l] >> amp1) - 12; */
exp1 = (sbr->E[1][k][l] >> amp1);
if ((exp0 < 0) || (exp0 >= 64) ||
(exp1 < 0) || (exp1 > 24))
{
sbr->E_orig[1][k][l] = 0;
sbr->E_orig[0][k][l] = 0;
} else {
tmp = E_deq_tab[exp0];
if (amp0 && (sbr->E[0][k][l] & 1))
{
tmp = MUL_C(tmp, COEF_CONST(1.414213562));
}
/* panning */
sbr->E_orig[0][k][l] = MUL_F(tmp, E_pan_tab[exp1]);
sbr->E_orig[1][k][l] = MUL_F(tmp, E_pan_tab[24 - exp1]);
}
}
}
for (l = 0; l < sbr->L_Q[0]; l++)
{
for (k = 0; k < sbr->N_Q; k++)
{
sbr->Q_div[0][k][l] = calc_Q_div(sbr, 0, k, l);
sbr->Q_div[1][k][l] = calc_Q_div(sbr, 1, k, l);
sbr->Q_div2[0][k][l] = calc_Q_div2(sbr, 0, k, l);
sbr->Q_div2[1][k][l] = calc_Q_div2(sbr, 1, k, l);
}
}
}
#endif
#endif

View File

@ -0,0 +1,50 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: sbr_e_nf.h,v 1.18 2007/11/01 12:33:35 menno Exp $
**/
#ifndef __SBR_E_NF_H__
#define __SBR_E_NF_H__
#ifdef __cplusplus
extern "C" {
#endif
void extract_envelope_data(sbr_info *sbr, uint8_t ch);
void extract_noise_floor_data(sbr_info *sbr, uint8_t ch);
#ifndef FIXED_POINT
void envelope_noise_dequantisation(sbr_info *sbr, uint8_t ch);
void unmap_envelope_noise(sbr_info *sbr);
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,764 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: sbr_fbt.c,v 1.21 2007/11/01 12:33:35 menno Exp $
**/
/* Calculate frequency band tables */
#include "common.h"
#include "structs.h"
#ifdef SBR_DEC
#include <stdlib.h>
#include "sbr_syntax.h"
#include "sbr_fbt.h"
/* static function declarations */
static int32_t find_bands(uint8_t warp, uint8_t bands, uint8_t a0, uint8_t a1);
/* calculate the start QMF channel for the master frequency band table */
/* parameter is also called k0 */
uint8_t qmf_start_channel(uint8_t bs_start_freq, uint8_t bs_samplerate_mode,
uint32_t sample_rate)
{
static const uint8_t startMinTable[12] = { 7, 7, 10, 11, 12, 16, 16,
17, 24, 32, 35, 48 };
static const uint8_t offsetIndexTable[12] = { 5, 5, 4, 4, 4, 3, 2, 1, 0,
6, 6, 6 };
static const int8_t offset[7][16] = {
{ -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7 },
{ -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13 },
{ -5, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16 },
{ -6, -4, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16 },
{ -4, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16, 20 },
{ -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16, 20, 24 },
{ 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16, 20, 24, 28, 33 }
};
uint8_t startMin = startMinTable[get_sr_index(sample_rate)];
uint8_t offsetIndex = offsetIndexTable[get_sr_index(sample_rate)];
#if 0 /* replaced with table (startMinTable) */
if (sample_rate >= 64000)
{
startMin = (uint8_t)((5000.*128.)/(float)sample_rate + 0.5);
} else if (sample_rate < 32000) {
startMin = (uint8_t)((3000.*128.)/(float)sample_rate + 0.5);
} else {
startMin = (uint8_t)((4000.*128.)/(float)sample_rate + 0.5);
}
#endif
if (bs_samplerate_mode)
{
return startMin + offset[offsetIndex][bs_start_freq];
#if 0 /* replaced by offsetIndexTable */
switch (sample_rate)
{
case 16000:
return startMin + offset[0][bs_start_freq];
case 22050:
return startMin + offset[1][bs_start_freq];
case 24000:
return startMin + offset[2][bs_start_freq];
case 32000:
return startMin + offset[3][bs_start_freq];
default:
if (sample_rate > 64000)
{
return startMin + offset[5][bs_start_freq];
} else { /* 44100 <= sample_rate <= 64000 */
return startMin + offset[4][bs_start_freq];
}
}
#endif
} else {
return startMin + offset[6][bs_start_freq];
}
}
static int longcmp(const void *a, const void *b)
{
return ((int)(*(int32_t*)a - *(int32_t*)b));
}
/* calculate the stop QMF channel for the master frequency band table */
/* parameter is also called k2 */
uint8_t qmf_stop_channel(uint8_t bs_stop_freq, uint32_t sample_rate,
uint8_t k0)
{
if (bs_stop_freq == 15)
{
return min(64, k0 * 3);
} else if (bs_stop_freq == 14) {
return min(64, k0 * 2);
} else {
static const uint8_t stopMinTable[12] = { 13, 15, 20, 21, 23,
32, 32, 35, 48, 64, 70, 96 };
static const int8_t offset[12][14] = {
{ 0, 2, 4, 6, 8, 11, 14, 18, 22, 26, 31, 37, 44, 51 },
{ 0, 2, 4, 6, 8, 11, 14, 18, 22, 26, 31, 36, 42, 49 },
{ 0, 2, 4, 6, 8, 11, 14, 17, 21, 25, 29, 34, 39, 44 },
{ 0, 2, 4, 6, 8, 11, 14, 17, 20, 24, 28, 33, 38, 43 },
{ 0, 2, 4, 6, 8, 11, 14, 17, 20, 24, 28, 32, 36, 41 },
{ 0, 2, 4, 6, 8, 10, 12, 14, 17, 20, 23, 26, 29, 32 },
{ 0, 2, 4, 6, 8, 10, 12, 14, 17, 20, 23, 26, 29, 32 },
{ 0, 1, 3, 5, 7, 9, 11, 13, 15, 17, 20, 23, 26, 29 },
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, -1, -2, -3, -4, -5, -6, -6, -6, -6, -6, -6, -6, -6 },
{ 0, -3, -6, -9, -12, -15, -18, -20, -22, -24, -26, -28, -30, -32 }
};
#if 0
uint8_t i;
int32_t stopDk[13], stopDk_t[14], k2;
#endif
uint8_t stopMin = stopMinTable[get_sr_index(sample_rate)];
#if 0 /* replaced by table lookup */
if (sample_rate >= 64000)
{
stopMin = (uint8_t)((10000.*128.)/(float)sample_rate + 0.5);
} else if (sample_rate < 32000) {
stopMin = (uint8_t)((6000.*128.)/(float)sample_rate + 0.5);
} else {
stopMin = (uint8_t)((8000.*128.)/(float)sample_rate + 0.5);
}
#endif
#if 0 /* replaced by table lookup */
/* diverging power series */
for (i = 0; i <= 13; i++)
{
stopDk_t[i] = (int32_t)(stopMin*pow(64.0/stopMin, i/13.0) + 0.5);
}
for (i = 0; i < 13; i++)
{
stopDk[i] = stopDk_t[i+1] - stopDk_t[i];
}
/* needed? */
qsort(stopDk, 13, sizeof(stopDk[0]), longcmp);
k2 = stopMin;
for (i = 0; i < bs_stop_freq; i++)
{
k2 += stopDk[i];
}
return min(64, k2);
#endif
/* bs_stop_freq <= 13 */
return min(64, stopMin + offset[get_sr_index(sample_rate)][min(bs_stop_freq, 13)]);
}
return 0;
}
/* calculate the master frequency table from k0, k2, bs_freq_scale
and bs_alter_scale
version for bs_freq_scale = 0
*/
uint8_t master_frequency_table_fs0(sbr_info *sbr, uint8_t k0, uint8_t k2,
uint8_t bs_alter_scale)
{
int8_t incr;
uint8_t k;
uint8_t dk;
uint32_t nrBands, k2Achieved;
int32_t k2Diff, vDk[64] = {0};
/* mft only defined for k2 > k0 */
if (k2 <= k0)
{
sbr->N_master = 0;
return 1;
}
dk = bs_alter_scale ? 2 : 1;
#if 0 /* replaced by float-less design */
nrBands = 2 * (int32_t)((float)(k2-k0)/(dk*2) + (-1+dk)/2.0f);
#else
if (bs_alter_scale)
{
nrBands = (((k2-k0+2)>>2)<<1);
} else {
nrBands = (((k2-k0)>>1)<<1);
}
#endif
nrBands = min(nrBands, 63);
if (nrBands <= 0)
return 1;
k2Achieved = k0 + nrBands * dk;
k2Diff = k2 - k2Achieved;
for (k = 0; k < nrBands; k++)
vDk[k] = dk;
if (k2Diff)
{
incr = (k2Diff > 0) ? -1 : 1;
k = (uint8_t) ((k2Diff > 0) ? (nrBands-1) : 0);
while (k2Diff != 0)
{
vDk[k] -= incr;
k += incr;
k2Diff += incr;
}
}
sbr->f_master[0] = k0;
for (k = 1; k <= nrBands; k++)
sbr->f_master[k] = (uint8_t)(sbr->f_master[k-1] + vDk[k-1]);
sbr->N_master = (uint8_t)nrBands;
sbr->N_master = (min(sbr->N_master, 64));
#if 0
printf("f_master[%d]: ", nrBands);
for (k = 0; k <= nrBands; k++)
{
printf("%d ", sbr->f_master[k]);
}
printf("\n");
#endif
return 0;
}
/*
This function finds the number of bands using this formula:
bands * log(a1/a0)/log(2.0) + 0.5
*/
static int32_t find_bands(uint8_t warp, uint8_t bands, uint8_t a0, uint8_t a1)
{
#ifdef FIXED_POINT
/* table with log2() values */
static const real_t log2Table[65] = {
COEF_CONST(0.0), COEF_CONST(0.0), COEF_CONST(1.0000000000), COEF_CONST(1.5849625007),
COEF_CONST(2.0000000000), COEF_CONST(2.3219280949), COEF_CONST(2.5849625007), COEF_CONST(2.8073549221),
COEF_CONST(3.0000000000), COEF_CONST(3.1699250014), COEF_CONST(3.3219280949), COEF_CONST(3.4594316186),
COEF_CONST(3.5849625007), COEF_CONST(3.7004397181), COEF_CONST(3.8073549221), COEF_CONST(3.9068905956),
COEF_CONST(4.0000000000), COEF_CONST(4.0874628413), COEF_CONST(4.1699250014), COEF_CONST(4.2479275134),
COEF_CONST(4.3219280949), COEF_CONST(4.3923174228), COEF_CONST(4.4594316186), COEF_CONST(4.5235619561),
COEF_CONST(4.5849625007), COEF_CONST(4.6438561898), COEF_CONST(4.7004397181), COEF_CONST(4.7548875022),
COEF_CONST(4.8073549221), COEF_CONST(4.8579809951), COEF_CONST(4.9068905956), COEF_CONST(4.9541963104),
COEF_CONST(5.0000000000), COEF_CONST(5.0443941194), COEF_CONST(5.0874628413), COEF_CONST(5.1292830169),
COEF_CONST(5.1699250014), COEF_CONST(5.2094533656), COEF_CONST(5.2479275134), COEF_CONST(5.2854022189),
COEF_CONST(5.3219280949), COEF_CONST(5.3575520046), COEF_CONST(5.3923174228), COEF_CONST(5.4262647547),
COEF_CONST(5.4594316186), COEF_CONST(5.4918530963), COEF_CONST(5.5235619561), COEF_CONST(5.5545888517),
COEF_CONST(5.5849625007), COEF_CONST(5.6147098441), COEF_CONST(5.6438561898), COEF_CONST(5.6724253420),
COEF_CONST(5.7004397181), COEF_CONST(5.7279204546), COEF_CONST(5.7548875022), COEF_CONST(5.7813597135),
COEF_CONST(5.8073549221), COEF_CONST(5.8328900142), COEF_CONST(5.8579809951), COEF_CONST(5.8826430494),
COEF_CONST(5.9068905956), COEF_CONST(5.9307373376), COEF_CONST(5.9541963104), COEF_CONST(5.9772799235),
COEF_CONST(6.0)
};
real_t r0 = log2Table[a0]; /* coef */
real_t r1 = log2Table[a1]; /* coef */
real_t r2 = (r1 - r0); /* coef */
if (warp)
r2 = MUL_C(r2, COEF_CONST(1.0/1.3));
/* convert r2 to real and then multiply and round */
r2 = (r2 >> (COEF_BITS-REAL_BITS)) * bands + (1<<(REAL_BITS-1));
return (r2 >> REAL_BITS);
#else
real_t div = (real_t)log(2.0);
if (warp) div *= (real_t)1.3;
return (int32_t)(bands * log((float)a1/(float)a0)/div + 0.5);
#endif
}
static real_t find_initial_power(uint8_t bands, uint8_t a0, uint8_t a1)
{
#ifdef FIXED_POINT
/* table with log() values */
static const real_t logTable[65] = {
COEF_CONST(0.0), COEF_CONST(0.0), COEF_CONST(0.6931471806), COEF_CONST(1.0986122887),
COEF_CONST(1.3862943611), COEF_CONST(1.6094379124), COEF_CONST(1.7917594692), COEF_CONST(1.9459101491),
COEF_CONST(2.0794415417), COEF_CONST(2.1972245773), COEF_CONST(2.3025850930), COEF_CONST(2.3978952728),
COEF_CONST(2.4849066498), COEF_CONST(2.5649493575), COEF_CONST(2.6390573296), COEF_CONST(2.7080502011),
COEF_CONST(2.7725887222), COEF_CONST(2.8332133441), COEF_CONST(2.8903717579), COEF_CONST(2.9444389792),
COEF_CONST(2.9957322736), COEF_CONST(3.0445224377), COEF_CONST(3.0910424534), COEF_CONST(3.1354942159),
COEF_CONST(3.1780538303), COEF_CONST(3.2188758249), COEF_CONST(3.2580965380), COEF_CONST(3.2958368660),
COEF_CONST(3.3322045102), COEF_CONST(3.3672958300), COEF_CONST(3.4011973817), COEF_CONST(3.4339872045),
COEF_CONST(3.4657359028), COEF_CONST(3.4965075615), COEF_CONST(3.5263605246), COEF_CONST(3.5553480615),
COEF_CONST(3.5835189385), COEF_CONST(3.6109179126), COEF_CONST(3.6375861597), COEF_CONST(3.6635616461),
COEF_CONST(3.6888794541), COEF_CONST(3.7135720667), COEF_CONST(3.7376696183), COEF_CONST(3.7612001157),
COEF_CONST(3.7841896339), COEF_CONST(3.8066624898), COEF_CONST(3.8286413965), COEF_CONST(3.8501476017),
COEF_CONST(3.8712010109), COEF_CONST(3.8918202981), COEF_CONST(3.9120230054), COEF_CONST(3.9318256327),
COEF_CONST(3.9512437186), COEF_CONST(3.9702919136), COEF_CONST(3.9889840466), COEF_CONST(4.0073331852),
COEF_CONST(4.0253516907), COEF_CONST(4.0430512678), COEF_CONST(4.0604430105), COEF_CONST(4.0775374439),
COEF_CONST(4.0943445622), COEF_CONST(4.1108738642), COEF_CONST(4.1271343850), COEF_CONST(4.1431347264),
COEF_CONST(4.158883083)
};
/* standard Taylor polynomial coefficients for exp(x) around 0 */
/* a polynomial around x=1 is more precise, as most values are around 1.07,
but this is just fine already */
static const real_t c1 = COEF_CONST(1.0);
static const real_t c2 = COEF_CONST(1.0/2.0);
static const real_t c3 = COEF_CONST(1.0/6.0);
static const real_t c4 = COEF_CONST(1.0/24.0);
real_t r0 = logTable[a0]; /* coef */
real_t r1 = logTable[a1]; /* coef */
real_t r2 = (r1 - r0) / bands; /* coef */
real_t rexp = c1 + MUL_C((c1 + MUL_C((c2 + MUL_C((c3 + MUL_C(c4,r2)), r2)), r2)), r2);
return (rexp >> (COEF_BITS-REAL_BITS)); /* real */
#else
return (real_t)pow((real_t)a1/(real_t)a0, 1.0/(real_t)bands);
#endif
}
/*
version for bs_freq_scale > 0
*/
uint8_t master_frequency_table(sbr_info *sbr, uint8_t k0, uint8_t k2,
uint8_t bs_freq_scale, uint8_t bs_alter_scale)
{
uint8_t k, bands, twoRegions;
uint8_t k1;
uint8_t nrBand0, nrBand1;
int32_t vDk0[64] = {0}, vDk1[64] = {0};
int32_t vk0[64] = {0}, vk1[64] = {0};
uint8_t temp1[] = { 6, 5, 4 };
real_t q, qk;
int32_t A_1;
#ifdef FIXED_POINT
real_t rk2, rk0;
#endif
/* mft only defined for k2 > k0 */
if (k2 <= k0)
{
sbr->N_master = 0;
return 1;
}
bands = temp1[bs_freq_scale-1];
#ifdef FIXED_POINT
rk0 = (real_t)k0 << REAL_BITS;
rk2 = (real_t)k2 << REAL_BITS;
if (rk2 > MUL_C(rk0, COEF_CONST(2.2449)))
#else
if ((float)k2/(float)k0 > 2.2449)
#endif
{
twoRegions = 1;
k1 = k0 << 1;
} else {
twoRegions = 0;
k1 = k2;
}
nrBand0 = (uint8_t)(2 * find_bands(0, bands, k0, k1));
nrBand0 = min(nrBand0, 63);
if (nrBand0 <= 0)
return 1;
q = find_initial_power(nrBand0, k0, k1);
#ifdef FIXED_POINT
qk = (real_t)k0 << REAL_BITS;
//A_1 = (int32_t)((qk + REAL_CONST(0.5)) >> REAL_BITS);
A_1 = k0;
#else
qk = REAL_CONST(k0);
A_1 = (int32_t)(qk + .5);
#endif
for (k = 0; k <= nrBand0; k++)
{
int32_t A_0 = A_1;
#ifdef FIXED_POINT
qk = MUL_R(qk,q);
A_1 = (int32_t)((qk + REAL_CONST(0.5)) >> REAL_BITS);
#else
qk *= q;
A_1 = (int32_t)(qk + 0.5);
#endif
vDk0[k] = A_1 - A_0;
}
/* needed? */
qsort(vDk0, nrBand0, sizeof(vDk0[0]), longcmp);
vk0[0] = k0;
for (k = 1; k <= nrBand0; k++)
{
vk0[k] = vk0[k-1] + vDk0[k-1];
if (vDk0[k-1] == 0)
return 1;
}
if (!twoRegions)
{
for (k = 0; k <= nrBand0; k++)
sbr->f_master[k] = (uint8_t) vk0[k];
sbr->N_master = nrBand0;
sbr->N_master = min(sbr->N_master, 64);
return 0;
}
nrBand1 = (uint8_t)(2 * find_bands(1 /* warped */, bands, k1, k2));
nrBand1 = min(nrBand1, 63);
q = find_initial_power(nrBand1, k1, k2);
#ifdef FIXED_POINT
qk = (real_t)k1 << REAL_BITS;
//A_1 = (int32_t)((qk + REAL_CONST(0.5)) >> REAL_BITS);
A_1 = k1;
#else
qk = REAL_CONST(k1);
A_1 = (int32_t)(qk + .5);
#endif
for (k = 0; k <= nrBand1 - 1; k++)
{
int32_t A_0 = A_1;
#ifdef FIXED_POINT
qk = MUL_R(qk,q);
A_1 = (int32_t)((qk + REAL_CONST(0.5)) >> REAL_BITS);
#else
qk *= q;
A_1 = (int32_t)(qk + 0.5);
#endif
vDk1[k] = A_1 - A_0;
}
if (vDk1[0] < vDk0[nrBand0 - 1])
{
int32_t change;
/* needed? */
qsort(vDk1, nrBand1 + 1, sizeof(vDk1[0]), longcmp);
change = vDk0[nrBand0 - 1] - vDk1[0];
vDk1[0] = vDk0[nrBand0 - 1];
vDk1[nrBand1 - 1] = vDk1[nrBand1 - 1] - change;
}
/* needed? */
qsort(vDk1, nrBand1, sizeof(vDk1[0]), longcmp);
vk1[0] = k1;
for (k = 1; k <= nrBand1; k++)
{
vk1[k] = vk1[k-1] + vDk1[k-1];
if (vDk1[k-1] == 0)
return 1;
}
sbr->N_master = nrBand0 + nrBand1;
sbr->N_master = min(sbr->N_master, 64);
for (k = 0; k <= nrBand0; k++)
{
sbr->f_master[k] = (uint8_t) vk0[k];
}
for (k = nrBand0 + 1; k <= sbr->N_master; k++)
{
sbr->f_master[k] = (uint8_t) vk1[k - nrBand0];
}
#if 0
printf("f_master[%d]: ", sbr->N_master);
for (k = 0; k <= sbr->N_master; k++)
{
printf("%d ", sbr->f_master[k]);
}
printf("\n");
#endif
return 0;
}
/* calculate the derived frequency border tables from f_master */
uint8_t derived_frequency_table(sbr_info *sbr, uint8_t bs_xover_band,
uint8_t k2)
{
uint8_t k, i;
uint32_t minus;
/* The following relation shall be satisfied: bs_xover_band < N_Master */
if (sbr->N_master <= bs_xover_band)
return 1;
sbr->N_high = sbr->N_master - bs_xover_band;
sbr->N_low = (sbr->N_high>>1) + (sbr->N_high - ((sbr->N_high>>1)<<1));
sbr->n[0] = sbr->N_low;
sbr->n[1] = sbr->N_high;
for (k = 0; k <= sbr->N_high; k++)
{
sbr->f_table_res[HI_RES][k] = sbr->f_master[k + bs_xover_band];
}
sbr->M = sbr->f_table_res[HI_RES][sbr->N_high] - sbr->f_table_res[HI_RES][0];
sbr->kx = sbr->f_table_res[HI_RES][0];
if (sbr->kx > 32)
return 1;
if (sbr->kx + sbr->M > 64)
return 1;
minus = (sbr->N_high & 1) ? 1 : 0;
for (k = 0; k <= sbr->N_low; k++)
{
if (k == 0)
i = 0;
else
i = (uint8_t)(2*k - minus);
sbr->f_table_res[LO_RES][k] = sbr->f_table_res[HI_RES][i];
}
#if 0
printf("bs_freq_scale: %d\n", sbr->bs_freq_scale);
printf("bs_limiter_bands: %d\n", sbr->bs_limiter_bands);
printf("f_table_res[HI_RES][%d]: ", sbr->N_high);
for (k = 0; k <= sbr->N_high; k++)
{
printf("%d ", sbr->f_table_res[HI_RES][k]);
}
printf("\n");
#endif
#if 0
printf("f_table_res[LO_RES][%d]: ", sbr->N_low);
for (k = 0; k <= sbr->N_low; k++)
{
printf("%d ", sbr->f_table_res[LO_RES][k]);
}
printf("\n");
#endif
sbr->N_Q = 0;
if (sbr->bs_noise_bands == 0)
{
sbr->N_Q = 1;
} else {
#if 0
sbr->N_Q = max(1, (int32_t)(sbr->bs_noise_bands*(log(k2/(float)sbr->kx)/log(2.0)) + 0.5));
#else
sbr->N_Q = (uint8_t)(max(1, find_bands(0, sbr->bs_noise_bands, sbr->kx, k2)));
#endif
sbr->N_Q = min(5, sbr->N_Q);
}
for (k = 0; k <= sbr->N_Q; k++)
{
if (k == 0)
{
i = 0;
} else {
/* i = i + (int32_t)((sbr->N_low - i)/(sbr->N_Q + 1 - k)); */
i = i + (sbr->N_low - i)/(sbr->N_Q + 1 - k);
}
sbr->f_table_noise[k] = sbr->f_table_res[LO_RES][i];
}
/* build table for mapping k to g in hf patching */
for (k = 0; k < 64; k++)
{
uint8_t g;
for (g = 0; g < sbr->N_Q; g++)
{
if ((sbr->f_table_noise[g] <= k) &&
(k < sbr->f_table_noise[g+1]))
{
sbr->table_map_k_to_g[k] = g;
break;
}
}
}
#if 0
printf("f_table_noise[%d]: ", sbr->N_Q);
for (k = 0; k <= sbr->N_Q; k++)
{
printf("%d ", sbr->f_table_noise[k] - sbr->kx);
}
printf("\n");
#endif
return 0;
}
/* TODO: blegh, ugly */
/* Modified to calculate for all possible bs_limiter_bands always
* This reduces the number calls to this functions needed (now only on
* header reset)
*/
void limiter_frequency_table(sbr_info *sbr)
{
#if 0
static const real_t limiterBandsPerOctave[] = { REAL_CONST(1.2),
REAL_CONST(2), REAL_CONST(3) };
#else
static const real_t limiterBandsCompare[] = { REAL_CONST(1.327152),
REAL_CONST(1.185093), REAL_CONST(1.119872) };
#endif
uint8_t k, s;
int8_t nrLim;
#if 0
real_t limBands;
#endif
sbr->f_table_lim[0][0] = sbr->f_table_res[LO_RES][0] - sbr->kx;
sbr->f_table_lim[0][1] = sbr->f_table_res[LO_RES][sbr->N_low] - sbr->kx;
sbr->N_L[0] = 1;
#if 0
printf("f_table_lim[%d][%d]: ", 0, sbr->N_L[0]);
for (k = 0; k <= sbr->N_L[0]; k++)
{
printf("%d ", sbr->f_table_lim[0][k]);
}
printf("\n");
#endif
for (s = 1; s < 4; s++)
{
int32_t limTable[100 /*TODO*/] = {0};
uint8_t patchBorders[64/*??*/] = {0};
#if 0
limBands = limiterBandsPerOctave[s - 1];
#endif
patchBorders[0] = sbr->kx;
for (k = 1; k <= sbr->noPatches; k++)
{
patchBorders[k] = patchBorders[k-1] + sbr->patchNoSubbands[k-1];
}
for (k = 0; k <= sbr->N_low; k++)
{
limTable[k] = sbr->f_table_res[LO_RES][k];
}
for (k = 1; k < sbr->noPatches; k++)
{
limTable[k+sbr->N_low] = patchBorders[k];
}
/* needed */
qsort(limTable, sbr->noPatches + sbr->N_low, sizeof(limTable[0]), longcmp);
k = 1;
nrLim = sbr->noPatches + sbr->N_low - 1;
if (nrLim < 0) // TODO: BIG FAT PROBLEM
return;
restart:
if (k <= nrLim)
{
real_t nOctaves;
if (limTable[k-1] != 0)
#if 0
nOctaves = REAL_CONST(log((float)limTable[k]/(float)limTable[k-1])/log(2.0));
#else
#ifdef FIXED_POINT
nOctaves = DIV_R((limTable[k]<<REAL_BITS),REAL_CONST(limTable[k-1]));
#else
nOctaves = (real_t)limTable[k]/(real_t)limTable[k-1];
#endif
#endif
else
nOctaves = 0;
#if 0
if ((MUL_R(nOctaves,limBands)) < REAL_CONST(0.49))
#else
if (nOctaves < limiterBandsCompare[s - 1])
#endif
{
uint8_t i;
if (limTable[k] != limTable[k-1])
{
uint8_t found = 0, found2 = 0;
for (i = 0; i <= sbr->noPatches; i++)
{
if (limTable[k] == patchBorders[i])
found = 1;
}
if (found)
{
found2 = 0;
for (i = 0; i <= sbr->noPatches; i++)
{
if (limTable[k-1] == patchBorders[i])
found2 = 1;
}
if (found2)
{
k++;
goto restart;
} else {
/* remove (k-1)th element */
limTable[k-1] = sbr->f_table_res[LO_RES][sbr->N_low];
qsort(limTable, sbr->noPatches + sbr->N_low, sizeof(limTable[0]), longcmp);
nrLim--;
goto restart;
}
}
}
/* remove kth element */
limTable[k] = sbr->f_table_res[LO_RES][sbr->N_low];
qsort(limTable, nrLim, sizeof(limTable[0]), longcmp);
nrLim--;
goto restart;
} else {
k++;
goto restart;
}
}
sbr->N_L[s] = nrLim;
for (k = 0; k <= nrLim; k++)
{
sbr->f_table_lim[s][k] = limTable[k] - sbr->kx;
}
#if 0
printf("f_table_lim[%d][%d]: ", s, sbr->N_L[s]);
for (k = 0; k <= sbr->N_L[s]; k++)
{
printf("%d ", sbr->f_table_lim[s][k]);
}
printf("\n");
#endif
}
}
#endif

View File

@ -0,0 +1,55 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: sbr_fbt.h,v 1.18 2007/11/01 12:33:35 menno Exp $
**/
#ifndef __SBR_FBT_H__
#define __SBR_FBT_H__
#ifdef __cplusplus
extern "C" {
#endif
uint8_t qmf_start_channel(uint8_t bs_start_freq, uint8_t bs_samplerate_mode,
uint32_t sample_rate);
uint8_t qmf_stop_channel(uint8_t bs_stop_freq, uint32_t sample_rate,
uint8_t k0);
uint8_t master_frequency_table_fs0(sbr_info *sbr, uint8_t k0, uint8_t k2,
uint8_t bs_alter_scale);
uint8_t master_frequency_table(sbr_info *sbr, uint8_t k0, uint8_t k2,
uint8_t bs_freq_scale, uint8_t bs_alter_scale);
uint8_t derived_frequency_table(sbr_info *sbr, uint8_t bs_xover_band,
uint8_t k2);
void limiter_frequency_table(sbr_info *sbr);
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,57 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: sbr_hfadj.h,v 1.19 2007/11/01 12:33:35 menno Exp $
**/
#ifndef __SBR_HFADJ_H__
#define __SBR_HFADJ_H__
#ifdef __cplusplus
extern "C" {
#endif
typedef struct
{
real_t G_lim_boost[MAX_L_E][MAX_M];
real_t Q_M_lim_boost[MAX_L_E][MAX_M];
real_t S_M_boost[MAX_L_E][MAX_M];
} sbr_hfadj_info;
uint8_t hf_adjustment(sbr_info *sbr, qmf_t Xsbr[MAX_NTSRHFG][64]
#ifdef SBR_LOW_POWER
,real_t *deg
#endif
,uint8_t ch);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,668 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: sbr_hfgen.c,v 1.26 2007/11/01 12:33:35 menno Exp $
**/
/* High Frequency generation */
#include "common.h"
#include "structs.h"
#ifdef SBR_DEC
#include "sbr_syntax.h"
#include "sbr_hfgen.h"
#include "sbr_fbt.h"
/* static function declarations */
#ifdef SBR_LOW_POWER
static void calc_prediction_coef_lp(sbr_info *sbr, qmf_t Xlow[MAX_NTSRHFG][64],
complex_t *alpha_0, complex_t *alpha_1, real_t *rxx);
static void calc_aliasing_degree(sbr_info *sbr, real_t *rxx, real_t *deg);
#else
static void calc_prediction_coef(sbr_info *sbr, qmf_t Xlow[MAX_NTSRHFG][64],
complex_t *alpha_0, complex_t *alpha_1, uint8_t k);
#endif
static void calc_chirp_factors(sbr_info *sbr, uint8_t ch);
static void patch_construction(sbr_info *sbr);
void hf_generation(sbr_info *sbr, qmf_t Xlow[MAX_NTSRHFG][64],
qmf_t Xhigh[MAX_NTSRHFG][64]
#ifdef SBR_LOW_POWER
,real_t *deg
#endif
,uint8_t ch)
{
uint8_t l, i, x;
ALIGN complex_t alpha_0[64], alpha_1[64];
#ifdef SBR_LOW_POWER
ALIGN real_t rxx[64];
#endif
uint8_t offset = sbr->tHFAdj;
uint8_t first = sbr->t_E[ch][0];
uint8_t last = sbr->t_E[ch][sbr->L_E[ch]];
calc_chirp_factors(sbr, ch);
#ifdef SBR_LOW_POWER
memset(deg, 0, 64*sizeof(real_t));
#endif
if ((ch == 0) && (sbr->Reset))
patch_construction(sbr);
/* calculate the prediction coefficients */
#ifdef SBR_LOW_POWER
calc_prediction_coef_lp(sbr, Xlow, alpha_0, alpha_1, rxx);
calc_aliasing_degree(sbr, rxx, deg);
#endif
/* actual HF generation */
for (i = 0; i < sbr->noPatches; i++)
{
for (x = 0; x < sbr->patchNoSubbands[i]; x++)
{
real_t a0_r, a0_i, a1_r, a1_i;
real_t bw, bw2;
uint8_t q, p, k, g;
/* find the low and high band for patching */
k = sbr->kx + x;
for (q = 0; q < i; q++)
{
k += sbr->patchNoSubbands[q];
}
p = sbr->patchStartSubband[i] + x;
#ifdef SBR_LOW_POWER
if (x != 0 /*x < sbr->patchNoSubbands[i]-1*/)
deg[k] = deg[p];
else
deg[k] = 0;
#endif
g = sbr->table_map_k_to_g[k];
bw = sbr->bwArray[ch][g];
bw2 = MUL_C(bw, bw);
/* do the patching */
/* with or without filtering */
if (bw2 > 0)
{
real_t temp1_r, temp2_r, temp3_r;
#ifndef SBR_LOW_POWER
real_t temp1_i, temp2_i, temp3_i;
calc_prediction_coef(sbr, Xlow, alpha_0, alpha_1, p);
#endif
a0_r = MUL_C(RE(alpha_0[p]), bw);
a1_r = MUL_C(RE(alpha_1[p]), bw2);
#ifndef SBR_LOW_POWER
a0_i = MUL_C(IM(alpha_0[p]), bw);
a1_i = MUL_C(IM(alpha_1[p]), bw2);
#endif
temp2_r = QMF_RE(Xlow[first - 2 + offset][p]);
temp3_r = QMF_RE(Xlow[first - 1 + offset][p]);
#ifndef SBR_LOW_POWER
temp2_i = QMF_IM(Xlow[first - 2 + offset][p]);
temp3_i = QMF_IM(Xlow[first - 1 + offset][p]);
#endif
for (l = first; l < last; l++)
{
temp1_r = temp2_r;
temp2_r = temp3_r;
temp3_r = QMF_RE(Xlow[l + offset][p]);
#ifndef SBR_LOW_POWER
temp1_i = temp2_i;
temp2_i = temp3_i;
temp3_i = QMF_IM(Xlow[l + offset][p]);
#endif
#ifdef SBR_LOW_POWER
QMF_RE(Xhigh[l + offset][k]) =
temp3_r
+(MUL_R(a0_r, temp2_r) +
MUL_R(a1_r, temp1_r));
#else
QMF_RE(Xhigh[l + offset][k]) =
temp3_r
+(MUL_R(a0_r, temp2_r) -
MUL_R(a0_i, temp2_i) +
MUL_R(a1_r, temp1_r) -
MUL_R(a1_i, temp1_i));
QMF_IM(Xhigh[l + offset][k]) =
temp3_i
+(MUL_R(a0_i, temp2_r) +
MUL_R(a0_r, temp2_i) +
MUL_R(a1_i, temp1_r) +
MUL_R(a1_r, temp1_i));
#endif
}
} else {
for (l = first; l < last; l++)
{
QMF_RE(Xhigh[l + offset][k]) = QMF_RE(Xlow[l + offset][p]);
#ifndef SBR_LOW_POWER
QMF_IM(Xhigh[l + offset][k]) = QMF_IM(Xlow[l + offset][p]);
#endif
}
}
}
}
if (sbr->Reset)
{
limiter_frequency_table(sbr);
}
}
typedef struct
{
complex_t r01;
complex_t r02;
complex_t r11;
complex_t r12;
complex_t r22;
real_t det;
} acorr_coef;
#ifdef SBR_LOW_POWER
static void auto_correlation(sbr_info *sbr, acorr_coef *ac,
qmf_t buffer[MAX_NTSRHFG][64],
uint8_t bd, uint8_t len)
{
real_t r01 = 0, r02 = 0, r11 = 0;
int8_t j;
uint8_t offset = sbr->tHFAdj;
#ifdef FIXED_POINT
const real_t rel = FRAC_CONST(0.999999); // 1 / (1 + 1e-6f);
uint32_t maxi = 0;
uint32_t pow2, exp;
#else
const real_t rel = 1 / (1 + 1e-6f);
#endif
#ifdef FIXED_POINT
mask = 0;
for (j = (offset-2); j < (len + offset); j++)
{
real_t x;
x = QMF_RE(buffer[j][bd])>>REAL_BITS;
mask |= x ^ (x >> 31);
}
exp = wl_min_lzc(mask);
/* improves accuracy */
if (exp > 0)
exp -= 1;
for (j = offset; j < len + offset; j++)
{
real_t buf_j = ((QMF_RE(buffer[j][bd])+(1<<(exp-1)))>>exp);
real_t buf_j_1 = ((QMF_RE(buffer[j-1][bd])+(1<<(exp-1)))>>exp);
real_t buf_j_2 = ((QMF_RE(buffer[j-2][bd])+(1<<(exp-1)))>>exp);
/* normalisation with rounding */
r01 += MUL_R(buf_j, buf_j_1);
r02 += MUL_R(buf_j, buf_j_2);
r11 += MUL_R(buf_j_1, buf_j_1);
}
RE(ac->r12) = r01 -
MUL_R(((QMF_RE(buffer[len+offset-1][bd])+(1<<(exp-1)))>>exp), ((QMF_RE(buffer[len+offset-2][bd])+(1<<(exp-1)))>>exp)) +
MUL_R(((QMF_RE(buffer[offset-1][bd])+(1<<(exp-1)))>>exp), ((QMF_RE(buffer[offset-2][bd])+(1<<(exp-1)))>>exp));
RE(ac->r22) = r11 -
MUL_R(((QMF_RE(buffer[len+offset-2][bd])+(1<<(exp-1)))>>exp), ((QMF_RE(buffer[len+offset-2][bd])+(1<<(exp-1)))>>exp)) +
MUL_R(((QMF_RE(buffer[offset-2][bd])+(1<<(exp-1)))>>exp), ((QMF_RE(buffer[offset-2][bd])+(1<<(exp-1)))>>exp));
#else
for (j = offset; j < len + offset; j++)
{
r01 += QMF_RE(buffer[j][bd]) * QMF_RE(buffer[j-1][bd]);
r02 += QMF_RE(buffer[j][bd]) * QMF_RE(buffer[j-2][bd]);
r11 += QMF_RE(buffer[j-1][bd]) * QMF_RE(buffer[j-1][bd]);
}
RE(ac->r12) = r01 -
QMF_RE(buffer[len+offset-1][bd]) * QMF_RE(buffer[len+offset-2][bd]) +
QMF_RE(buffer[offset-1][bd]) * QMF_RE(buffer[offset-2][bd]);
RE(ac->r22) = r11 -
QMF_RE(buffer[len+offset-2][bd]) * QMF_RE(buffer[len+offset-2][bd]) +
QMF_RE(buffer[offset-2][bd]) * QMF_RE(buffer[offset-2][bd]);
#endif
RE(ac->r01) = r01;
RE(ac->r02) = r02;
RE(ac->r11) = r11;
ac->det = MUL_R(RE(ac->r11), RE(ac->r22)) - MUL_F(MUL_R(RE(ac->r12), RE(ac->r12)), rel);
}
#else
static void auto_correlation(sbr_info *sbr, acorr_coef *ac, qmf_t buffer[MAX_NTSRHFG][64],
uint8_t bd, uint8_t len)
{
real_t r01r = 0, r01i = 0, r02r = 0, r02i = 0, r11r = 0;
real_t temp1_r, temp1_i, temp2_r, temp2_i, temp3_r, temp3_i, temp4_r, temp4_i, temp5_r, temp5_i;
#ifdef FIXED_POINT
const real_t rel = FRAC_CONST(0.999999); // 1 / (1 + 1e-6f);
uint32_t mask, exp;
real_t pow2_to_exp;
#else
const real_t rel = 1 / (1 + 1e-6f);
#endif
int8_t j;
uint8_t offset = sbr->tHFAdj;
#ifdef FIXED_POINT
mask = 0;
for (j = (offset-2); j < (len + offset); j++)
{
real_t x;
x = QMF_RE(buffer[j][bd])>>REAL_BITS;
mask |= x ^ (x >> 31);
x = QMF_IM(buffer[j][bd])>>REAL_BITS;
mask |= x ^ (x >> 31);
}
exp = wl_min_lzc(mask);
/* improves accuracy */
if (exp > 0)
exp -= 1;
pow2_to_exp = 1<<(exp-1);
temp2_r = (QMF_RE(buffer[offset-2][bd]) + pow2_to_exp) >> exp;
temp2_i = (QMF_IM(buffer[offset-2][bd]) + pow2_to_exp) >> exp;
temp3_r = (QMF_RE(buffer[offset-1][bd]) + pow2_to_exp) >> exp;
temp3_i = (QMF_IM(buffer[offset-1][bd]) + pow2_to_exp) >> exp;
// Save these because they are needed after loop
temp4_r = temp2_r;
temp4_i = temp2_i;
temp5_r = temp3_r;
temp5_i = temp3_i;
for (j = offset; j < len + offset; j++)
{
temp1_r = temp2_r; // temp1_r = (QMF_RE(buffer[offset-2][bd] + (1<<(exp-1))) >> exp;
temp1_i = temp2_i; // temp1_i = (QMF_IM(buffer[offset-2][bd] + (1<<(exp-1))) >> exp;
temp2_r = temp3_r; // temp2_r = (QMF_RE(buffer[offset-1][bd] + (1<<(exp-1))) >> exp;
temp2_i = temp3_i; // temp2_i = (QMF_IM(buffer[offset-1][bd] + (1<<(exp-1))) >> exp;
temp3_r = (QMF_RE(buffer[j][bd]) + pow2_to_exp) >> exp;
temp3_i = (QMF_IM(buffer[j][bd]) + pow2_to_exp) >> exp;
r01r += MUL_R(temp3_r, temp2_r) + MUL_R(temp3_i, temp2_i);
r01i += MUL_R(temp3_i, temp2_r) - MUL_R(temp3_r, temp2_i);
r02r += MUL_R(temp3_r, temp1_r) + MUL_R(temp3_i, temp1_i);
r02i += MUL_R(temp3_i, temp1_r) - MUL_R(temp3_r, temp1_i);
r11r += MUL_R(temp2_r, temp2_r) + MUL_R(temp2_i, temp2_i);
}
// These are actual values in temporary variable at this point
// temp1_r = (QMF_RE(buffer[len+offset-1-2][bd] + (1<<(exp-1))) >> exp;
// temp1_i = (QMF_IM(buffer[len+offset-1-2][bd] + (1<<(exp-1))) >> exp;
// temp2_r = (QMF_RE(buffer[len+offset-1-1][bd] + (1<<(exp-1))) >> exp;
// temp2_i = (QMF_IM(buffer[len+offset-1-1][bd] + (1<<(exp-1))) >> exp;
// temp3_r = (QMF_RE(buffer[len+offset-1][bd]) + (1<<(exp-1))) >> exp;
// temp3_i = (QMF_IM(buffer[len+offset-1][bd]) + (1<<(exp-1))) >> exp;
// temp4_r = (QMF_RE(buffer[offset-2][bd]) + (1<<(exp-1))) >> exp;
// temp4_i = (QMF_IM(buffer[offset-2][bd]) + (1<<(exp-1))) >> exp;
// temp5_r = (QMF_RE(buffer[offset-1][bd]) + (1<<(exp-1))) >> exp;
// temp5_i = (QMF_IM(buffer[offset-1][bd]) + (1<<(exp-1))) >> exp;
RE(ac->r12) = r01r -
(MUL_R(temp3_r, temp2_r) + MUL_R(temp3_i, temp2_i)) +
(MUL_R(temp5_r, temp4_r) + MUL_R(temp5_i, temp4_i));
IM(ac->r12) = r01i -
(MUL_R(temp3_i, temp2_r) - MUL_R(temp3_r, temp2_i)) +
(MUL_R(temp5_i, temp4_r) - MUL_R(temp5_r, temp4_i));
RE(ac->r22) = r11r -
(MUL_R(temp2_r, temp2_r) + MUL_R(temp2_i, temp2_i)) +
(MUL_R(temp4_r, temp4_r) + MUL_R(temp4_i, temp4_i));
#else
temp2_r = QMF_RE(buffer[offset-2][bd]);
temp2_i = QMF_IM(buffer[offset-2][bd]);
temp3_r = QMF_RE(buffer[offset-1][bd]);
temp3_i = QMF_IM(buffer[offset-1][bd]);
// Save these because they are needed after loop
temp4_r = temp2_r;
temp4_i = temp2_i;
temp5_r = temp3_r;
temp5_i = temp3_i;
for (j = offset; j < len + offset; j++)
{
temp1_r = temp2_r; // temp1_r = QMF_RE(buffer[j-2][bd];
temp1_i = temp2_i; // temp1_i = QMF_IM(buffer[j-2][bd];
temp2_r = temp3_r; // temp2_r = QMF_RE(buffer[j-1][bd];
temp2_i = temp3_i; // temp2_i = QMF_IM(buffer[j-1][bd];
temp3_r = QMF_RE(buffer[j][bd]);
temp3_i = QMF_IM(buffer[j][bd]);
r01r += temp3_r * temp2_r + temp3_i * temp2_i;
r01i += temp3_i * temp2_r - temp3_r * temp2_i;
r02r += temp3_r * temp1_r + temp3_i * temp1_i;
r02i += temp3_i * temp1_r - temp3_r * temp1_i;
r11r += temp2_r * temp2_r + temp2_i * temp2_i;
}
// These are actual values in temporary variable at this point
// temp1_r = QMF_RE(buffer[len+offset-1-2][bd];
// temp1_i = QMF_IM(buffer[len+offset-1-2][bd];
// temp2_r = QMF_RE(buffer[len+offset-1-1][bd];
// temp2_i = QMF_IM(buffer[len+offset-1-1][bd];
// temp3_r = QMF_RE(buffer[len+offset-1][bd]);
// temp3_i = QMF_IM(buffer[len+offset-1][bd]);
// temp4_r = QMF_RE(buffer[offset-2][bd]);
// temp4_i = QMF_IM(buffer[offset-2][bd]);
// temp5_r = QMF_RE(buffer[offset-1][bd]);
// temp5_i = QMF_IM(buffer[offset-1][bd]);
RE(ac->r12) = r01r -
(temp3_r * temp2_r + temp3_i * temp2_i) +
(temp5_r * temp4_r + temp5_i * temp4_i);
IM(ac->r12) = r01i -
(temp3_i * temp2_r - temp3_r * temp2_i) +
(temp5_i * temp4_r - temp5_r * temp4_i);
RE(ac->r22) = r11r -
(temp2_r * temp2_r + temp2_i * temp2_i) +
(temp4_r * temp4_r + temp4_i * temp4_i);
#endif
RE(ac->r01) = r01r;
IM(ac->r01) = r01i;
RE(ac->r02) = r02r;
IM(ac->r02) = r02i;
RE(ac->r11) = r11r;
ac->det = MUL_R(RE(ac->r11), RE(ac->r22)) - MUL_F(rel, (MUL_R(RE(ac->r12), RE(ac->r12)) + MUL_R(IM(ac->r12), IM(ac->r12))));
}
#endif
/* calculate linear prediction coefficients using the covariance method */
#ifndef SBR_LOW_POWER
static void calc_prediction_coef(sbr_info *sbr, qmf_t Xlow[MAX_NTSRHFG][64],
complex_t *alpha_0, complex_t *alpha_1, uint8_t k)
{
real_t tmp;
acorr_coef ac;
auto_correlation(sbr, &ac, Xlow, k, sbr->numTimeSlotsRate + 6);
if (ac.det == 0)
{
RE(alpha_1[k]) = 0;
IM(alpha_1[k]) = 0;
} else {
#ifdef FIXED_POINT
tmp = (MUL_R(RE(ac.r01), RE(ac.r12)) - MUL_R(IM(ac.r01), IM(ac.r12)) - MUL_R(RE(ac.r02), RE(ac.r11)));
RE(alpha_1[k]) = DIV_R(tmp, ac.det);
tmp = (MUL_R(IM(ac.r01), RE(ac.r12)) + MUL_R(RE(ac.r01), IM(ac.r12)) - MUL_R(IM(ac.r02), RE(ac.r11)));
IM(alpha_1[k]) = DIV_R(tmp, ac.det);
#else
tmp = REAL_CONST(1.0) / ac.det;
RE(alpha_1[k]) = (MUL_R(RE(ac.r01), RE(ac.r12)) - MUL_R(IM(ac.r01), IM(ac.r12)) - MUL_R(RE(ac.r02), RE(ac.r11))) * tmp;
IM(alpha_1[k]) = (MUL_R(IM(ac.r01), RE(ac.r12)) + MUL_R(RE(ac.r01), IM(ac.r12)) - MUL_R(IM(ac.r02), RE(ac.r11))) * tmp;
#endif
}
if (RE(ac.r11) == 0)
{
RE(alpha_0[k]) = 0;
IM(alpha_0[k]) = 0;
} else {
#ifdef FIXED_POINT
tmp = -(RE(ac.r01) + MUL_R(RE(alpha_1[k]), RE(ac.r12)) + MUL_R(IM(alpha_1[k]), IM(ac.r12)));
RE(alpha_0[k]) = DIV_R(tmp, RE(ac.r11));
tmp = -(IM(ac.r01) + MUL_R(IM(alpha_1[k]), RE(ac.r12)) - MUL_R(RE(alpha_1[k]), IM(ac.r12)));
IM(alpha_0[k]) = DIV_R(tmp, RE(ac.r11));
#else
tmp = 1.0f / RE(ac.r11);
RE(alpha_0[k]) = -(RE(ac.r01) + MUL_R(RE(alpha_1[k]), RE(ac.r12)) + MUL_R(IM(alpha_1[k]), IM(ac.r12))) * tmp;
IM(alpha_0[k]) = -(IM(ac.r01) + MUL_R(IM(alpha_1[k]), RE(ac.r12)) - MUL_R(RE(alpha_1[k]), IM(ac.r12))) * tmp;
#endif
}
if ((MUL_R(RE(alpha_0[k]),RE(alpha_0[k])) + MUL_R(IM(alpha_0[k]),IM(alpha_0[k])) >= REAL_CONST(16)) ||
(MUL_R(RE(alpha_1[k]),RE(alpha_1[k])) + MUL_R(IM(alpha_1[k]),IM(alpha_1[k])) >= REAL_CONST(16)))
{
RE(alpha_0[k]) = 0;
IM(alpha_0[k]) = 0;
RE(alpha_1[k]) = 0;
IM(alpha_1[k]) = 0;
}
}
#else
static void calc_prediction_coef_lp(sbr_info *sbr, qmf_t Xlow[MAX_NTSRHFG][64],
complex_t *alpha_0, complex_t *alpha_1, real_t *rxx)
{
uint8_t k;
real_t tmp;
acorr_coef ac;
for (k = 1; k < sbr->f_master[0]; k++)
{
auto_correlation(sbr, &ac, Xlow, k, sbr->numTimeSlotsRate + 6);
if (ac.det == 0)
{
RE(alpha_0[k]) = 0;
RE(alpha_1[k]) = 0;
} else {
tmp = MUL_R(RE(ac.r01), RE(ac.r22)) - MUL_R(RE(ac.r12), RE(ac.r02));
RE(alpha_0[k]) = DIV_R(tmp, (-ac.det));
tmp = MUL_R(RE(ac.r01), RE(ac.r12)) - MUL_R(RE(ac.r02), RE(ac.r11));
RE(alpha_1[k]) = DIV_R(tmp, ac.det);
}
if ((RE(alpha_0[k]) >= REAL_CONST(4)) || (RE(alpha_1[k]) >= REAL_CONST(4)))
{
RE(alpha_0[k]) = REAL_CONST(0);
RE(alpha_1[k]) = REAL_CONST(0);
}
/* reflection coefficient */
if (RE(ac.r11) == 0)
{
rxx[k] = COEF_CONST(0.0);
} else {
rxx[k] = DIV_C(RE(ac.r01), RE(ac.r11));
rxx[k] = -rxx[k];
if (rxx[k] > COEF_CONST(1.0)) rxx[k] = COEF_CONST(1.0);
if (rxx[k] < COEF_CONST(-1.0)) rxx[k] = COEF_CONST(-1.0);
}
}
}
static void calc_aliasing_degree(sbr_info *sbr, real_t *rxx, real_t *deg)
{
uint8_t k;
rxx[0] = COEF_CONST(0.0);
deg[1] = COEF_CONST(0.0);
for (k = 2; k < sbr->k0; k++)
{
deg[k] = 0.0;
if ((k % 2 == 0) && (rxx[k] < COEF_CONST(0.0)))
{
if (rxx[k-1] < 0.0)
{
deg[k] = COEF_CONST(1.0);
if (rxx[k-2] > COEF_CONST(0.0))
{
deg[k-1] = COEF_CONST(1.0) - MUL_C(rxx[k-1], rxx[k-1]);
}
} else if (rxx[k-2] > COEF_CONST(0.0)) {
deg[k] = COEF_CONST(1.0) - MUL_C(rxx[k-1], rxx[k-1]);
}
}
if ((k % 2 == 1) && (rxx[k] > COEF_CONST(0.0)))
{
if (rxx[k-1] > COEF_CONST(0.0))
{
deg[k] = COEF_CONST(1.0);
if (rxx[k-2] < COEF_CONST(0.0))
{
deg[k-1] = COEF_CONST(1.0) - MUL_C(rxx[k-1], rxx[k-1]);
}
} else if (rxx[k-2] < COEF_CONST(0.0)) {
deg[k] = COEF_CONST(1.0) - MUL_C(rxx[k-1], rxx[k-1]);
}
}
}
}
#endif
/* FIXED POINT: bwArray = COEF */
static real_t mapNewBw(uint8_t invf_mode, uint8_t invf_mode_prev)
{
switch (invf_mode)
{
case 1: /* LOW */
if (invf_mode_prev == 0) /* NONE */
return COEF_CONST(0.6);
else
return COEF_CONST(0.75);
case 2: /* MID */
return COEF_CONST(0.9);
case 3: /* HIGH */
return COEF_CONST(0.98);
default: /* NONE */
if (invf_mode_prev == 1) /* LOW */
return COEF_CONST(0.6);
else
return COEF_CONST(0.0);
}
}
/* FIXED POINT: bwArray = COEF */
static void calc_chirp_factors(sbr_info *sbr, uint8_t ch)
{
uint8_t i;
for (i = 0; i < sbr->N_Q; i++)
{
sbr->bwArray[ch][i] = mapNewBw(sbr->bs_invf_mode[ch][i], sbr->bs_invf_mode_prev[ch][i]);
if (sbr->bwArray[ch][i] < sbr->bwArray_prev[ch][i])
sbr->bwArray[ch][i] = MUL_F(sbr->bwArray[ch][i], FRAC_CONST(0.75)) + MUL_F(sbr->bwArray_prev[ch][i], FRAC_CONST(0.25));
else
sbr->bwArray[ch][i] = MUL_F(sbr->bwArray[ch][i], FRAC_CONST(0.90625)) + MUL_F(sbr->bwArray_prev[ch][i], FRAC_CONST(0.09375));
if (sbr->bwArray[ch][i] < COEF_CONST(0.015625))
sbr->bwArray[ch][i] = COEF_CONST(0.0);
if (sbr->bwArray[ch][i] >= COEF_CONST(0.99609375))
sbr->bwArray[ch][i] = COEF_CONST(0.99609375);
sbr->bwArray_prev[ch][i] = sbr->bwArray[ch][i];
sbr->bs_invf_mode_prev[ch][i] = sbr->bs_invf_mode[ch][i];
}
}
static void patch_construction(sbr_info *sbr)
{
uint8_t i, k;
uint8_t odd, sb;
uint8_t msb = sbr->k0;
uint8_t usb = sbr->kx;
uint8_t goalSbTab[] = { 21, 23, 32, 43, 46, 64, 85, 93, 128, 0, 0, 0 };
/* (uint8_t)(2.048e6/sbr->sample_rate + 0.5); */
uint8_t goalSb = goalSbTab[get_sr_index(sbr->sample_rate)];
sbr->noPatches = 0;
if (goalSb < (sbr->kx + sbr->M))
{
for (i = 0, k = 0; sbr->f_master[i] < goalSb; i++)
k = i+1;
} else {
k = sbr->N_master;
}
if (sbr->N_master == 0)
{
sbr->noPatches = 0;
sbr->patchNoSubbands[0] = 0;
sbr->patchStartSubband[0] = 0;
return;
}
do
{
uint8_t j = k + 1;
do
{
j--;
sb = sbr->f_master[j];
odd = (sb - 2 + sbr->k0) % 2;
} while (sb > (sbr->k0 - 1 + msb - odd));
sbr->patchNoSubbands[sbr->noPatches] = max(sb - usb, 0);
sbr->patchStartSubband[sbr->noPatches] = sbr->k0 - odd -
sbr->patchNoSubbands[sbr->noPatches];
if (sbr->patchNoSubbands[sbr->noPatches] > 0)
{
usb = sb;
msb = sb;
sbr->noPatches++;
} else {
msb = sbr->kx;
}
if (sbr->f_master[k] - sb < 3)
k = sbr->N_master;
} while (sb != (sbr->kx + sbr->M));
if ((sbr->patchNoSubbands[sbr->noPatches-1] < 3) && (sbr->noPatches > 1))
{
sbr->noPatches--;
}
sbr->noPatches = min(sbr->noPatches, 5);
}
#endif

View File

@ -0,0 +1,49 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: sbr_hfgen.h,v 1.20 2007/11/01 12:33:35 menno Exp $
**/
#ifndef __SBR_HFGEN_H__
#define __SBR_HFGEN_H__
#ifdef __cplusplus
extern "C" {
#endif
void hf_generation(sbr_info *sbr, qmf_t Xlow[MAX_NTSRHFG][64],
qmf_t Xhigh[MAX_NTSRHFG][64]
#ifdef SBR_LOW_POWER
,real_t *deg
#endif
,uint8_t ch);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,360 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: sbr_huff.c,v 1.21 2007/11/01 12:33:35 menno Exp $
**/
#include "common.h"
#include "structs.h"
#ifdef SBR_DEC
#include "sbr_syntax.h"
#include "bits.h"
#include "sbr_huff.h"
#include "sbr_e_nf.h"
typedef const int8_t (*sbr_huff_tab)[2];
static const int8_t t_huffman_env_1_5dB[120][2] = {
{ 1, 2 }, { -64, -65 }, { 3, 4 }, { -63, -66 },
{ 5, 6 }, { -62, -67 }, { 7, 8 }, { -61, -68 },
{ 9, 10 }, { -60, -69 }, { 11, 12 }, { -59, -70 },
{ 13, 14 }, { -58, -71 }, { 15, 16 }, { -57, -72 },
{ 17, 18 }, { -73, -56 }, { 19, 21 }, { -74, 20 },
{ -55, -75 }, { 22, 26 }, { 23, 24 }, { -54, -76 },
{ -77, 25 }, { -53, -78 }, { 27, 34 }, { 28, 29 },
{ -52, -79 }, { 30, 31 }, { -80, -51 }, { 32, 33 },
{ -83, -82 }, { -81, -50 }, { 35, 57 }, { 36, 40 },
{ 37, 38 }, { -88, -84 }, { -48, 39 }, { -90, -85 },
{ 41, 46 }, { 42, 43 }, { -49, -87 }, { 44, 45 },
{ -89, -86 }, {-124,-123 }, { 47, 50 }, { 48, 49 },
{-122,-121 }, {-120,-119 }, { 51, 54 }, { 52, 53 },
{-118,-117 }, {-116,-115 }, { 55, 56 }, {-114,-113 },
{-112,-111 }, { 58, 89 }, { 59, 74 }, { 60, 67 },
{ 61, 64 }, { 62, 63 }, {-110,-109 }, {-108,-107 },
{ 65, 66 }, {-106,-105 }, {-104,-103 }, { 68, 71 },
{ 69, 70 }, {-102,-101 }, {-100, -99 }, { 72, 73 },
{ -98, -97 }, { -96, -95 }, { 75, 82 }, { 76, 79 },
{ 77, 78 }, { -94, -93 }, { -92, -91 }, { 80, 81 },
{ -47, -46 }, { -45, -44 }, { 83, 86 }, { 84, 85 },
{ -43, -42 }, { -41, -40 }, { 87, 88 }, { -39, -38 },
{ -37, -36 }, { 90, 105 }, { 91, 98 }, { 92, 95 },
{ 93, 94 }, { -35, -34 }, { -33, -32 }, { 96, 97 },
{ -31, -30 }, { -29, -28 }, { 99, 102 }, { 100, 101 },
{ -27, -26 }, { -25, -24 }, { 103, 104 }, { -23, -22 },
{ -21, -20 }, { 106, 113 }, { 107, 110 }, { 108, 109 },
{ -19, -18 }, { -17, -16 }, { 111, 112 }, { -15, -14 },
{ -13, -12 }, { 114, 117 }, { 115, 116 }, { -11, -10 },
{ -9, -8 }, { 118, 119 }, { -7, -6 }, { -5, -4 }
};
static const int8_t f_huffman_env_1_5dB[120][2] = {
{ 1, 2 }, { -64, -65 }, { 3, 4 }, { -63, -66 },
{ 5, 6 }, { -67, -62 }, { 7, 8 }, { -68, -61 },
{ 9, 10 }, { -69, -60 }, { 11, 13 }, { -70, 12 },
{ -59, -71 }, { 14, 16 }, { -58, 15 }, { -72, -57 },
{ 17, 19 }, { -73, 18 }, { -56, -74 }, { 20, 23 },
{ 21, 22 }, { -55, -75 }, { -54, -53 }, { 24, 27 },
{ 25, 26 }, { -76, -52 }, { -77, -51 }, { 28, 31 },
{ 29, 30 }, { -50, -78 }, { -79, -49 }, { 32, 36 },
{ 33, 34 }, { -48, -47 }, { -80, 35 }, { -81, -82 },
{ 37, 47 }, { 38, 41 }, { 39, 40 }, { -83, -46 },
{ -45, -84 }, { 42, 44 }, { -85, 43 }, { -44, -43 },
{ 45, 46 }, { -88, -87 }, { -86, -90 }, { 48, 66 },
{ 49, 56 }, { 50, 53 }, { 51, 52 }, { -92, -42 },
{ -41, -39 }, { 54, 55 }, {-105, -89 }, { -38, -37 },
{ 57, 60 }, { 58, 59 }, { -94, -91 }, { -40, -36 },
{ 61, 63 }, { -20, 62 }, {-115,-110 }, { 64, 65 },
{-108,-107 }, {-101, -97 }, { 67, 89 }, { 68, 75 },
{ 69, 72 }, { 70, 71 }, { -95, -93 }, { -34, -27 },
{ 73, 74 }, { -22, -17 }, { -16,-124 }, { 76, 82 },
{ 77, 79 }, {-123, 78 }, {-122,-121 }, { 80, 81 },
{-120,-119 }, {-118,-117 }, { 83, 86 }, { 84, 85 },
{-116,-114 }, {-113,-112 }, { 87, 88 }, {-111,-109 },
{-106,-104 }, { 90, 105 }, { 91, 98 }, { 92, 95 },
{ 93, 94 }, {-103,-102 }, {-100, -99 }, { 96, 97 },
{ -98, -96 }, { -35, -33 }, { 99, 102 }, { 100, 101 },
{ -32, -31 }, { -30, -29 }, { 103, 104 }, { -28, -26 },
{ -25, -24 }, { 106, 113 }, { 107, 110 }, { 108, 109 },
{ -23, -21 }, { -19, -18 }, { 111, 112 }, { -15, -14 },
{ -13, -12 }, { 114, 117 }, { 115, 116 }, { -11, -10 },
{ -9, -8 }, { 118, 119 }, { -7, -6 }, { -5, -4 }
};
static const int8_t t_huffman_env_bal_1_5dB[48][2] = {
{ -64, 1 }, { -63, 2 }, { -65, 3 }, { -62, 4 },
{ -66, 5 }, { -61, 6 }, { -67, 7 }, { -60, 8 },
{ -68, 9 }, { 10, 11 }, { -69, -59 }, { 12, 13 },
{ -70, -58 }, { 14, 28 }, { 15, 21 }, { 16, 18 },
{ -57, 17 }, { -71, -56 }, { 19, 20 }, { -88, -87 },
{ -86, -85 }, { 22, 25 }, { 23, 24 }, { -84, -83 },
{ -82, -81 }, { 26, 27 }, { -80, -79 }, { -78, -77 },
{ 29, 36 }, { 30, 33 }, { 31, 32 }, { -76, -75 },
{ -74, -73 }, { 34, 35 }, { -72, -55 }, { -54, -53 },
{ 37, 41 }, { 38, 39 }, { -52, -51 }, { -50, 40 },
{ -49, -48 }, { 42, 45 }, { 43, 44 }, { -47, -46 },
{ -45, -44 }, { 46, 47 }, { -43, -42 }, { -41, -40 }
};
static const int8_t f_huffman_env_bal_1_5dB[48][2] = {
{ -64, 1 }, { -65, 2 }, { -63, 3 }, { -66, 4 },
{ -62, 5 }, { -61, 6 }, { -67, 7 }, { -68, 8 },
{ -60, 9 }, { 10, 11 }, { -69, -59 }, { -70, 12 },
{ -58, 13 }, { 14, 17 }, { -71, 15 }, { -57, 16 },
{ -56, -73 }, { 18, 32 }, { 19, 25 }, { 20, 22 },
{ -72, 21 }, { -88, -87 }, { 23, 24 }, { -86, -85 },
{ -84, -83 }, { 26, 29 }, { 27, 28 }, { -82, -81 },
{ -80, -79 }, { 30, 31 }, { -78, -77 }, { -76, -75 },
{ 33, 40 }, { 34, 37 }, { 35, 36 }, { -74, -55 },
{ -54, -53 }, { 38, 39 }, { -52, -51 }, { -50, -49 },
{ 41, 44 }, { 42, 43 }, { -48, -47 }, { -46, -45 },
{ 45, 46 }, { -44, -43 }, { -42, 47 }, { -41, -40 }
};
static const int8_t t_huffman_env_3_0dB[62][2] = {
{ -64, 1 }, { -65, 2 }, { -63, 3 }, { -66, 4 },
{ -62, 5 }, { -67, 6 }, { -61, 7 }, { -68, 8 },
{ -60, 9 }, { 10, 11 }, { -69, -59 }, { 12, 14 },
{ -70, 13 }, { -71, -58 }, { 15, 18 }, { 16, 17 },
{ -72, -57 }, { -73, -74 }, { 19, 22 }, { -56, 20 },
{ -55, 21 }, { -54, -77 }, { 23, 31 }, { 24, 25 },
{ -75, -76 }, { 26, 27 }, { -78, -53 }, { 28, 29 },
{ -52, -95 }, { -94, 30 }, { -93, -92 }, { 32, 47 },
{ 33, 40 }, { 34, 37 }, { 35, 36 }, { -91, -90 },
{ -89, -88 }, { 38, 39 }, { -87, -86 }, { -85, -84 },
{ 41, 44 }, { 42, 43 }, { -83, -82 }, { -81, -80 },
{ 45, 46 }, { -79, -51 }, { -50, -49 }, { 48, 55 },
{ 49, 52 }, { 50, 51 }, { -48, -47 }, { -46, -45 },
{ 53, 54 }, { -44, -43 }, { -42, -41 }, { 56, 59 },
{ 57, 58 }, { -40, -39 }, { -38, -37 }, { 60, 61 },
{ -36, -35 }, { -34, -33 }
};
static const int8_t f_huffman_env_3_0dB[62][2] = {
{ -64, 1 }, { -65, 2 }, { -63, 3 }, { -66, 4 },
{ -62, 5 }, { -67, 6 }, { 7, 8 }, { -61, -68 },
{ 9, 10 }, { -60, -69 }, { 11, 12 }, { -59, -70 },
{ 13, 14 }, { -58, -71 }, { 15, 16 }, { -57, -72 },
{ 17, 19 }, { -56, 18 }, { -55, -73 }, { 20, 24 },
{ 21, 22 }, { -74, -54 }, { -53, 23 }, { -75, -76 },
{ 25, 30 }, { 26, 27 }, { -52, -51 }, { 28, 29 },
{ -77, -79 }, { -50, -49 }, { 31, 39 }, { 32, 35 },
{ 33, 34 }, { -78, -46 }, { -82, -88 }, { 36, 37 },
{ -83, -48 }, { -47, 38 }, { -86, -85 }, { 40, 47 },
{ 41, 44 }, { 42, 43 }, { -80, -44 }, { -43, -42 },
{ 45, 46 }, { -39, -87 }, { -84, -40 }, { 48, 55 },
{ 49, 52 }, { 50, 51 }, { -95, -94 }, { -93, -92 },
{ 53, 54 }, { -91, -90 }, { -89, -81 }, { 56, 59 },
{ 57, 58 }, { -45, -41 }, { -38, -37 }, { 60, 61 },
{ -36, -35 }, { -34, -33 }
};
static const int8_t t_huffman_env_bal_3_0dB[24][2] = {
{ -64, 1 }, { -63, 2 }, { -65, 3 }, { -66, 4 },
{ -62, 5 }, { -61, 6 }, { -67, 7 }, { -68, 8 },
{ -60, 9 }, { 10, 16 }, { 11, 13 }, { -69, 12 },
{ -76, -75 }, { 14, 15 }, { -74, -73 }, { -72, -71 },
{ 17, 20 }, { 18, 19 }, { -70, -59 }, { -58, -57 },
{ 21, 22 }, { -56, -55 }, { -54, 23 }, { -53, -52 }
};
static const int8_t f_huffman_env_bal_3_0dB[24][2] = {
{ -64, 1 }, { -65, 2 }, { -63, 3 }, { -66, 4 },
{ -62, 5 }, { -61, 6 }, { -67, 7 }, { -68, 8 },
{ -60, 9 }, { 10, 13 }, { -69, 11 }, { -59, 12 },
{ -58, -76 }, { 14, 17 }, { 15, 16 }, { -75, -74 },
{ -73, -72 }, { 18, 21 }, { 19, 20 }, { -71, -70 },
{ -57, -56 }, { 22, 23 }, { -55, -54 }, { -53, -52 }
};
static const int8_t t_huffman_noise_3_0dB[62][2] = {
{ -64, 1 }, { -63, 2 }, { -65, 3 }, { -66, 4 },
{ -62, 5 }, { -67, 6 }, { 7, 8 }, { -61, -68 },
{ 9, 30 }, { 10, 15 }, { -60, 11 }, { -69, 12 },
{ 13, 14 }, { -59, -53 }, { -95, -94 }, { 16, 23 },
{ 17, 20 }, { 18, 19 }, { -93, -92 }, { -91, -90 },
{ 21, 22 }, { -89, -88 }, { -87, -86 }, { 24, 27 },
{ 25, 26 }, { -85, -84 }, { -83, -82 }, { 28, 29 },
{ -81, -80 }, { -79, -78 }, { 31, 46 }, { 32, 39 },
{ 33, 36 }, { 34, 35 }, { -77, -76 }, { -75, -74 },
{ 37, 38 }, { -73, -72 }, { -71, -70 }, { 40, 43 },
{ 41, 42 }, { -58, -57 }, { -56, -55 }, { 44, 45 },
{ -54, -52 }, { -51, -50 }, { 47, 54 }, { 48, 51 },
{ 49, 50 }, { -49, -48 }, { -47, -46 }, { 52, 53 },
{ -45, -44 }, { -43, -42 }, { 55, 58 }, { 56, 57 },
{ -41, -40 }, { -39, -38 }, { 59, 60 }, { -37, -36 },
{ -35, 61 }, { -34, -33 }
};
static const int8_t t_huffman_noise_bal_3_0dB[24][2] = {
{ -64, 1 }, { -65, 2 }, { -63, 3 }, { 4, 9 },
{ -66, 5 }, { -62, 6 }, { 7, 8 }, { -76, -75 },
{ -74, -73 }, { 10, 17 }, { 11, 14 }, { 12, 13 },
{ -72, -71 }, { -70, -69 }, { 15, 16 }, { -68, -67 },
{ -61, -60 }, { 18, 21 }, { 19, 20 }, { -59, -58 },
{ -57, -56 }, { 22, 23 }, { -55, -54 }, { -53, -52 }
};
static INLINE int16_t sbr_huff_dec(bitfile *ld, sbr_huff_tab t_huff)
{
uint8_t bit;
int16_t index = 0;
while (index >= 0)
{
bit = (uint8_t)faad_get1bit(ld);
index = t_huff[index][bit];
}
return index + 64;
}
/* table 10 */
void sbr_envelope(bitfile *ld, sbr_info *sbr, uint8_t ch)
{
uint8_t env, band;
int8_t delta = 0;
sbr_huff_tab t_huff, f_huff;
if ((sbr->L_E[ch] == 1) && (sbr->bs_frame_class[ch] == FIXFIX))
sbr->amp_res[ch] = 0;
else
sbr->amp_res[ch] = sbr->bs_amp_res;
if ((sbr->bs_coupling) && (ch == 1))
{
delta = 1;
if (sbr->amp_res[ch])
{
t_huff = t_huffman_env_bal_3_0dB;
f_huff = f_huffman_env_bal_3_0dB;
} else {
t_huff = t_huffman_env_bal_1_5dB;
f_huff = f_huffman_env_bal_1_5dB;
}
} else {
delta = 0;
if (sbr->amp_res[ch])
{
t_huff = t_huffman_env_3_0dB;
f_huff = f_huffman_env_3_0dB;
} else {
t_huff = t_huffman_env_1_5dB;
f_huff = f_huffman_env_1_5dB;
}
}
for (env = 0; env < sbr->L_E[ch]; env++)
{
if (sbr->bs_df_env[ch][env] == 0)
{
if ((sbr->bs_coupling == 1) && (ch == 1))
{
if (sbr->amp_res[ch])
{
sbr->E[ch][0][env] = (uint16_t)(faad_getbits(ld, 5
DEBUGVAR(1,272,"sbr_envelope(): bs_data_env")) << delta);
} else {
sbr->E[ch][0][env] = (uint16_t)(faad_getbits(ld, 6
DEBUGVAR(1,273,"sbr_envelope(): bs_data_env")) << delta);
}
} else {
if (sbr->amp_res[ch])
{
sbr->E[ch][0][env] = (uint16_t)(faad_getbits(ld, 6
DEBUGVAR(1,274,"sbr_envelope(): bs_data_env")) << delta);
} else {
sbr->E[ch][0][env] = (uint16_t)(faad_getbits(ld, 7
DEBUGVAR(1,275,"sbr_envelope(): bs_data_env")) << delta);
}
}
for (band = 1; band < sbr->n[sbr->f[ch][env]]; band++)
{
sbr->E[ch][band][env] = (sbr_huff_dec(ld, f_huff) << delta);
}
} else {
for (band = 0; band < sbr->n[sbr->f[ch][env]]; band++)
{
sbr->E[ch][band][env] = (sbr_huff_dec(ld, t_huff) << delta);
}
}
}
extract_envelope_data(sbr, ch);
}
/* table 11 */
void sbr_noise(bitfile *ld, sbr_info *sbr, uint8_t ch)
{
uint8_t noise, band;
int8_t delta = 0;
sbr_huff_tab t_huff, f_huff;
if ((sbr->bs_coupling == 1) && (ch == 1))
{
delta = 1;
t_huff = t_huffman_noise_bal_3_0dB;
f_huff = f_huffman_env_bal_3_0dB;
} else {
delta = 0;
t_huff = t_huffman_noise_3_0dB;
f_huff = f_huffman_env_3_0dB;
}
for (noise = 0; noise < sbr->L_Q[ch]; noise++)
{
if(sbr->bs_df_noise[ch][noise] == 0)
{
if ((sbr->bs_coupling == 1) && (ch == 1))
{
sbr->Q[ch][0][noise] = (faad_getbits(ld, 5
DEBUGVAR(1,276,"sbr_noise(): bs_data_noise")) << delta);
} else {
sbr->Q[ch][0][noise] = (faad_getbits(ld, 5
DEBUGVAR(1,277,"sbr_noise(): bs_data_noise")) << delta);
}
for (band = 1; band < sbr->N_Q; band++)
{
sbr->Q[ch][band][noise] = (sbr_huff_dec(ld, f_huff) << delta);
}
} else {
for (band = 0; band < sbr->N_Q; band++)
{
sbr->Q[ch][band][noise] = (sbr_huff_dec(ld, t_huff) << delta);
}
}
}
extract_noise_floor_data(sbr, ch);
}
#endif

View File

@ -0,0 +1,46 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: sbr_huff.h,v 1.21 2007/11/01 12:33:35 menno Exp $
**/
#ifndef __SBR_HUFF_H__
#define __SBR_HUFF_H__
#ifdef __cplusplus
extern "C" {
#endif
void sbr_envelope(bitfile *ld, sbr_info *sbr, uint8_t ch);
void sbr_noise(bitfile *ld, sbr_info *sbr, uint8_t ch);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,564 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: sbr_noise.h,v 1.17 2007/11/01 12:33:35 menno Exp $
**/
#ifndef __SBR_NOISE_H__
#define __SBR_NOISE_H__
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _MSC_VER
#pragma warning(disable:4305)
#pragma warning(disable:4244)
#endif
/* Table 1.A.13 Noise table V */
ALIGN static const complex_t V[] = {
{ FRAC_CONST(-0.99948155879974), FRAC_CONST(-0.59483414888382) },
{ FRAC_CONST(0.97113454341888), FRAC_CONST(-0.67528516054153) },
{ FRAC_CONST(0.14130051434040), FRAC_CONST(-0.95090985298157) },
{ FRAC_CONST(-0.47005495429039), FRAC_CONST(-0.37340548634529) },
{ FRAC_CONST(0.80705064535141), FRAC_CONST(0.29653668403625) },
{ FRAC_CONST(-0.38981479406357), FRAC_CONST(0.89572608470917) },
{ FRAC_CONST(-0.01053049881011), FRAC_CONST(-0.66959059238434) },
{ FRAC_CONST(-0.91266369819641), FRAC_CONST(-0.11522938311100) },
{ FRAC_CONST(0.54840421676636), FRAC_CONST(0.75221365690231) },
{ FRAC_CONST(0.40009254217148), FRAC_CONST(-0.98929399251938) },
{ FRAC_CONST(-0.99867975711823), FRAC_CONST(-0.88147068023682) },
{ FRAC_CONST(-0.95531076192856), FRAC_CONST(0.90908759832382) },
{ FRAC_CONST(-0.45725932717323), FRAC_CONST(-0.56716322898865) },
{ FRAC_CONST(-0.72929674386978), FRAC_CONST(-0.98008275032043) },
{ FRAC_CONST(0.75622802972794), FRAC_CONST(0.20950329303741) },
{ FRAC_CONST(0.07069442421198), FRAC_CONST(-0.78247898817062) },
{ FRAC_CONST(0.74496251344681), FRAC_CONST(-0.91169005632401) },
{ FRAC_CONST(-0.96440184116364), FRAC_CONST(-0.94739919900894) },
{ FRAC_CONST(0.30424630641937), FRAC_CONST(-0.49438267946243) },
{ FRAC_CONST(0.66565030813217), FRAC_CONST(0.64652937650681) },
{ FRAC_CONST(0.91697007417679), FRAC_CONST(0.17514097690582) },
{ FRAC_CONST(-0.70774918794632), FRAC_CONST(0.52548652887344) },
{ FRAC_CONST(-0.70051413774490), FRAC_CONST(-0.45340028405190) },
{ FRAC_CONST(-0.99496513605118), FRAC_CONST(-0.90071910619736) },
{ FRAC_CONST(0.98164492845535), FRAC_CONST(-0.77463155984879) },
{ FRAC_CONST(-0.54671579599380), FRAC_CONST(-0.02570928446949) },
{ FRAC_CONST(-0.01689629070461), FRAC_CONST(0.00287506449968) },
{ FRAC_CONST(-0.86110347509384), FRAC_CONST(0.42548584938049) },
{ FRAC_CONST(-0.98892980813980), FRAC_CONST(-0.87881129980087) },
{ FRAC_CONST(0.51756626367569), FRAC_CONST(0.66926783323288) },
{ FRAC_CONST(-0.99635028839111), FRAC_CONST(-0.58107727766037) },
{ FRAC_CONST(-0.99969369173050), FRAC_CONST(0.98369991779327) },
{ FRAC_CONST(0.55266261100769), FRAC_CONST(0.59449058771133) },
{ FRAC_CONST(0.34581178426743), FRAC_CONST(0.94879418611526) },
{ FRAC_CONST(0.62664210796356), FRAC_CONST(-0.74402970075607) },
{ FRAC_CONST(-0.77149701118469), FRAC_CONST(-0.33883658051491) },
{ FRAC_CONST(-0.91592246294022), FRAC_CONST(0.03687901422381) },
{ FRAC_CONST(-0.76285493373871), FRAC_CONST(-0.91371870040894) },
{ FRAC_CONST(0.79788339138031), FRAC_CONST(-0.93180972337723) },
{ FRAC_CONST(0.54473078250885), FRAC_CONST(-0.11919206380844) },
{ FRAC_CONST(-0.85639280080795), FRAC_CONST(0.42429855465889) },
{ FRAC_CONST(-0.92882400751114), FRAC_CONST(0.27871808409691) },
{ FRAC_CONST(-0.11708371341228), FRAC_CONST(-0.99800843000412) },
{ FRAC_CONST(0.21356749534607), FRAC_CONST(-0.90716296434402) },
{ FRAC_CONST(-0.76191693544388), FRAC_CONST(0.99768120050430) },
{ FRAC_CONST(0.98111045360565), FRAC_CONST(-0.95854461193085) },
{ FRAC_CONST(-0.85913270711899), FRAC_CONST(0.95766568183899) },
{ FRAC_CONST(-0.93307244777679), FRAC_CONST(0.49431759119034) },
{ FRAC_CONST(0.30485755205154), FRAC_CONST(-0.70540034770966) },
{ FRAC_CONST(0.85289651155472), FRAC_CONST(0.46766132116318) },
{ FRAC_CONST(0.91328084468842), FRAC_CONST(-0.99839597940445) },
{ FRAC_CONST(-0.05890199914575), FRAC_CONST(0.70741826295853) },
{ FRAC_CONST(0.28398686647415), FRAC_CONST(0.34633556008339) },
{ FRAC_CONST(0.95258164405823), FRAC_CONST(-0.54893416166306) },
{ FRAC_CONST(-0.78566324710846), FRAC_CONST(-0.75568538904190) },
{ FRAC_CONST(-0.95789498090744), FRAC_CONST(-0.20423194766045) },
{ FRAC_CONST(0.82411158084869), FRAC_CONST(0.96654617786407) },
{ FRAC_CONST(-0.65185445547104), FRAC_CONST(-0.88734990358353) },
{ FRAC_CONST(-0.93643605709076), FRAC_CONST(0.99870789051056) },
{ FRAC_CONST(0.91427159309387), FRAC_CONST(-0.98290503025055) },
{ FRAC_CONST(-0.70395684242249), FRAC_CONST(0.58796799182892) },
{ FRAC_CONST(0.00563771976158), FRAC_CONST(0.61768198013306) },
{ FRAC_CONST(0.89065051078796), FRAC_CONST(0.52783352136612) },
{ FRAC_CONST(-0.68683707714081), FRAC_CONST(0.80806946754456) },
{ FRAC_CONST(0.72165340185165), FRAC_CONST(-0.69259858131409) },
{ FRAC_CONST(-0.62928247451782), FRAC_CONST(0.13627037405968) },
{ FRAC_CONST(0.29938435554504), FRAC_CONST(-0.46051329374313) },
{ FRAC_CONST(-0.91781955957413), FRAC_CONST(-0.74012714624405) },
{ FRAC_CONST(0.99298715591431), FRAC_CONST(0.40816611051559) },
{ FRAC_CONST(0.82368296384811), FRAC_CONST(-0.74036049842834) },
{ FRAC_CONST(-0.98512834310532), FRAC_CONST(-0.99972331523895) },
{ FRAC_CONST(-0.95915371179581), FRAC_CONST(-0.99237799644470) },
{ FRAC_CONST(-0.21411126852036), FRAC_CONST(-0.93424820899963) },
{ FRAC_CONST(-0.68821477890015), FRAC_CONST(-0.26892307400703) },
{ FRAC_CONST(0.91851997375488), FRAC_CONST(0.09358228743076) },
{ FRAC_CONST(-0.96062767505646), FRAC_CONST(0.36099094152451) },
{ FRAC_CONST(0.51646184921265), FRAC_CONST(-0.71373331546783) },
{ FRAC_CONST(0.61130720376968), FRAC_CONST(0.46950140595436) },
{ FRAC_CONST(0.47336128354073), FRAC_CONST(-0.27333179116249) },
{ FRAC_CONST(0.90998309850693), FRAC_CONST(0.96715664863586) },
{ FRAC_CONST(0.44844800233841), FRAC_CONST(0.99211573600769) },
{ FRAC_CONST(0.66614890098572), FRAC_CONST(0.96590173244476) },
{ FRAC_CONST(0.74922239780426), FRAC_CONST(-0.89879858493805) },
{ FRAC_CONST(-0.99571585655212), FRAC_CONST(0.52785521745682) },
{ FRAC_CONST(0.97401082515717), FRAC_CONST(-0.16855870187283) },
{ FRAC_CONST(0.72683745622635), FRAC_CONST(-0.48060774803162) },
{ FRAC_CONST(0.95432192087173), FRAC_CONST(0.68849605321884) },
{ FRAC_CONST(-0.72962206602097), FRAC_CONST(-0.76608443260193) },
{ FRAC_CONST(-0.85359477996826), FRAC_CONST(0.88738125562668) },
{ FRAC_CONST(-0.81412428617477), FRAC_CONST(-0.97480767965317) },
{ FRAC_CONST(-0.87930774688721), FRAC_CONST(0.74748307466507) },
{ FRAC_CONST(-0.71573328971863), FRAC_CONST(-0.98570609092712) },
{ FRAC_CONST(0.83524298667908), FRAC_CONST(0.83702534437180) },
{ FRAC_CONST(-0.48086065053940), FRAC_CONST(-0.98848503828049) },
{ FRAC_CONST(0.97139126062393), FRAC_CONST(0.80093622207642) },
{ FRAC_CONST(0.51992827653885), FRAC_CONST(0.80247628688812) },
{ FRAC_CONST(-0.00848591234535), FRAC_CONST(-0.76670128107071) },
{ FRAC_CONST(-0.70294374227524), FRAC_CONST(0.55359911918640) },
{ FRAC_CONST(-0.95894426107407), FRAC_CONST(-0.43265503644943) },
{ FRAC_CONST(0.97079253196716), FRAC_CONST(0.09325857460499) },
{ FRAC_CONST(-0.92404294013977), FRAC_CONST(0.85507702827454) },
{ FRAC_CONST(-0.69506472349167), FRAC_CONST(0.98633414506912) },
{ FRAC_CONST(0.26559203863144), FRAC_CONST(0.73314309120178) },
{ FRAC_CONST(0.28038442134857), FRAC_CONST(0.14537914097309) },
{ FRAC_CONST(-0.74138122797012), FRAC_CONST(0.99310338497162) },
{ FRAC_CONST(-0.01752796024084), FRAC_CONST(-0.82616633176804) },
{ FRAC_CONST(-0.55126774311066), FRAC_CONST(-0.98898541927338) },
{ FRAC_CONST(0.97960901260376), FRAC_CONST(-0.94021445512772) },
{ FRAC_CONST(-0.99196308851242), FRAC_CONST(0.67019015550613) },
{ FRAC_CONST(-0.67684930562973), FRAC_CONST(0.12631492316723) },
{ FRAC_CONST(0.09140039235353), FRAC_CONST(-0.20537731051445) },
{ FRAC_CONST(-0.71658962965012), FRAC_CONST(-0.97788202762604) },
{ FRAC_CONST(0.81014639139175), FRAC_CONST(0.53722649812698) },
{ FRAC_CONST(0.40616992115974), FRAC_CONST(-0.26469007134438) },
{ FRAC_CONST(-0.67680186033249), FRAC_CONST(0.94502049684525) },
{ FRAC_CONST(0.86849772930145), FRAC_CONST(-0.18333598971367) },
{ FRAC_CONST(-0.99500381946564), FRAC_CONST(-0.02634122036397) },
{ FRAC_CONST(0.84329187870026), FRAC_CONST(0.10406957566738) },
{ FRAC_CONST(-0.09215968847275), FRAC_CONST(0.69540011882782) },
{ FRAC_CONST(0.99956172704697), FRAC_CONST(-0.12358541786671) },
{ FRAC_CONST(-0.79732781648636), FRAC_CONST(-0.91582524776459) },
{ FRAC_CONST(0.96349972486496), FRAC_CONST(0.96640455722809) },
{ FRAC_CONST(-0.79942780733109), FRAC_CONST(0.64323902130127) },
{ FRAC_CONST(-0.11566039919853), FRAC_CONST(0.28587844967842) },
{ FRAC_CONST(-0.39922955632210), FRAC_CONST(0.94129604101181) },
{ FRAC_CONST(0.99089199304581), FRAC_CONST(-0.92062628269196) },
{ FRAC_CONST(0.28631284832954), FRAC_CONST(-0.91035044193268) },
{ FRAC_CONST(-0.83302724361420), FRAC_CONST(-0.67330408096313) },
{ FRAC_CONST(0.95404446125031), FRAC_CONST(0.49162766337395) },
{ FRAC_CONST(-0.06449863314629), FRAC_CONST(0.03250560909510) },
{ FRAC_CONST(-0.99575054645538), FRAC_CONST(0.42389783263206) },
{ FRAC_CONST(-0.65501141548157), FRAC_CONST(0.82546114921570) },
{ FRAC_CONST(-0.81254440546036), FRAC_CONST(-0.51627236604691) },
{ FRAC_CONST(-0.99646371603012), FRAC_CONST(0.84490531682968) },
{ FRAC_CONST(0.00287840608507), FRAC_CONST(0.64768260717392) },
{ FRAC_CONST(0.70176988840103), FRAC_CONST(-0.20453028380871) },
{ FRAC_CONST(0.96361881494522), FRAC_CONST(0.40706968307495) },
{ FRAC_CONST(-0.68883758783340), FRAC_CONST(0.91338956356049) },
{ FRAC_CONST(-0.34875586628914), FRAC_CONST(0.71472293138504) },
{ FRAC_CONST(0.91980081796646), FRAC_CONST(0.66507452726364) },
{ FRAC_CONST(-0.99009048938751), FRAC_CONST(0.85868018865585) },
{ FRAC_CONST(0.68865793943405), FRAC_CONST(0.55660319328308) },
{ FRAC_CONST(-0.99484401941299), FRAC_CONST(-0.20052559673786) },
{ FRAC_CONST(0.94214510917664), FRAC_CONST(-0.99696427583694) },
{ FRAC_CONST(-0.67414629459381), FRAC_CONST(0.49548220634460) },
{ FRAC_CONST(-0.47339352965355), FRAC_CONST(-0.85904330015182) },
{ FRAC_CONST(0.14323651790619), FRAC_CONST(-0.94145596027374) },
{ FRAC_CONST(-0.29268294572830), FRAC_CONST(0.05759225040674) },
{ FRAC_CONST(0.43793860077858), FRAC_CONST(-0.78904968500137) },
{ FRAC_CONST(-0.36345127224922), FRAC_CONST(0.64874434471130) },
{ FRAC_CONST(-0.08750604838133), FRAC_CONST(0.97686946392059) },
{ FRAC_CONST(-0.96495270729065), FRAC_CONST(-0.53960305452347) },
{ FRAC_CONST(0.55526942014694), FRAC_CONST(0.78891521692276) },
{ FRAC_CONST(0.73538213968277), FRAC_CONST(0.96452075242996) },
{ FRAC_CONST(-0.30889773368835), FRAC_CONST(-0.80664390325546) },
{ FRAC_CONST(0.03574995696545), FRAC_CONST(-0.97325617074966) },
{ FRAC_CONST(0.98720687627792), FRAC_CONST(0.48409134149551) },
{ FRAC_CONST(-0.81689298152924), FRAC_CONST(-0.90827703475952) },
{ FRAC_CONST(0.67866861820221), FRAC_CONST(0.81284505128860) },
{ FRAC_CONST(-0.15808570384979), FRAC_CONST(0.85279554128647) },
{ FRAC_CONST(0.80723392963409), FRAC_CONST(-0.24717418849468) },
{ FRAC_CONST(0.47788757085800), FRAC_CONST(-0.46333149075508) },
{ FRAC_CONST(0.96367555856705), FRAC_CONST(0.38486748933792) },
{ FRAC_CONST(-0.99143874645233), FRAC_CONST(-0.24945276975632) },
{ FRAC_CONST(0.83081877231598), FRAC_CONST(-0.94780850410461) },
{ FRAC_CONST(-0.58753192424774), FRAC_CONST(0.01290772389621) },
{ FRAC_CONST(0.95538109540939), FRAC_CONST(-0.85557049512863) },
{ FRAC_CONST(-0.96490919589996), FRAC_CONST(-0.64020973443985) },
{ FRAC_CONST(-0.97327101230621), FRAC_CONST(0.12378127872944) },
{ FRAC_CONST(0.91400367021561), FRAC_CONST(0.57972472906113) },
{ FRAC_CONST(-0.99925839900970), FRAC_CONST(0.71084845066071) },
{ FRAC_CONST(-0.86875903606415), FRAC_CONST(-0.20291699469090) },
{ FRAC_CONST(-0.26240035891533), FRAC_CONST(-0.68264555931091) },
{ FRAC_CONST(-0.24664412438869), FRAC_CONST(-0.87642270326614) },
{ FRAC_CONST(0.02416275814176), FRAC_CONST(0.27192914485931) },
{ FRAC_CONST(0.82068622112274), FRAC_CONST(-0.85087788105011) },
{ FRAC_CONST(0.88547372817993), FRAC_CONST(-0.89636802673340) },
{ FRAC_CONST(-0.18173077702522), FRAC_CONST(-0.26152145862579) },
{ FRAC_CONST(0.09355476498604), FRAC_CONST(0.54845124483109) },
{ FRAC_CONST(-0.54668414592743), FRAC_CONST(0.95980775356293) },
{ FRAC_CONST(0.37050989270210), FRAC_CONST(-0.59910142421722) },
{ FRAC_CONST(-0.70373594760895), FRAC_CONST(0.91227668523788) },
{ FRAC_CONST(-0.34600785374641), FRAC_CONST(-0.99441426992416) },
{ FRAC_CONST(-0.68774479627609), FRAC_CONST(-0.30238837003708) },
{ FRAC_CONST(-0.26843291521072), FRAC_CONST(0.83115667104721) },
{ FRAC_CONST(0.49072334170341), FRAC_CONST(-0.45359709858894) },
{ FRAC_CONST(0.38975992798805), FRAC_CONST(0.95515358448029) },
{ FRAC_CONST(-0.97757124900818), FRAC_CONST(0.05305894464254) },
{ FRAC_CONST(-0.17325553297997), FRAC_CONST(-0.92770671844482) },
{ FRAC_CONST(0.99948036670685), FRAC_CONST(0.58285546302795) },
{ FRAC_CONST(-0.64946246147156), FRAC_CONST(0.68645507097244) },
{ FRAC_CONST(-0.12016920745373), FRAC_CONST(-0.57147324085236) },
{ FRAC_CONST(-0.58947455883026), FRAC_CONST(-0.34847131371498) },
{ FRAC_CONST(-0.41815140843391), FRAC_CONST(0.16276422142982) },
{ FRAC_CONST(0.99885648488998), FRAC_CONST(0.11136095225811) },
{ FRAC_CONST(-0.56649613380432), FRAC_CONST(-0.90494865179062) },
{ FRAC_CONST(0.94138020277023), FRAC_CONST(0.35281917452812) },
{ FRAC_CONST(-0.75725078582764), FRAC_CONST(0.53650552034378) },
{ FRAC_CONST(0.20541973412037), FRAC_CONST(-0.94435143470764) },
{ FRAC_CONST(0.99980372190475), FRAC_CONST(0.79835915565491) },
{ FRAC_CONST(0.29078277945518), FRAC_CONST(0.35393777489662) },
{ FRAC_CONST(-0.62858772277832), FRAC_CONST(0.38765692710876) },
{ FRAC_CONST(0.43440905213356), FRAC_CONST(-0.98546332120895) },
{ FRAC_CONST(-0.98298585414886), FRAC_CONST(0.21021524071693) },
{ FRAC_CONST(0.19513028860092), FRAC_CONST(-0.94239830970764) },
{ FRAC_CONST(-0.95476663112640), FRAC_CONST(0.98364555835724) },
{ FRAC_CONST(0.93379634618759), FRAC_CONST(-0.70881992578506) },
{ FRAC_CONST(-0.85235410928726), FRAC_CONST(-0.08342348039150) },
{ FRAC_CONST(-0.86425095796585), FRAC_CONST(-0.45795026421547) },
{ FRAC_CONST(0.38879778981209), FRAC_CONST(0.97274428606033) },
{ FRAC_CONST(0.92045122385025), FRAC_CONST(-0.62433654069901) },
{ FRAC_CONST(0.89162534475327), FRAC_CONST(0.54950958490372) },
{ FRAC_CONST(-0.36834338307381), FRAC_CONST(0.96458297967911) },
{ FRAC_CONST(0.93891763687134), FRAC_CONST(-0.89968353509903) },
{ FRAC_CONST(0.99267655611038), FRAC_CONST(-0.03757034242153) },
{ FRAC_CONST(-0.94063472747803), FRAC_CONST(0.41332337260246) },
{ FRAC_CONST(0.99740225076675), FRAC_CONST(-0.16830494999886) },
{ FRAC_CONST(-0.35899412631989), FRAC_CONST(-0.46633225679398) },
{ FRAC_CONST(0.05237237364054), FRAC_CONST(-0.25640362501144) },
{ FRAC_CONST(0.36703583598137), FRAC_CONST(-0.38653266429901) },
{ FRAC_CONST(0.91653180122375), FRAC_CONST(-0.30587628483772) },
{ FRAC_CONST(0.69000804424286), FRAC_CONST(0.90952169895172) },
{ FRAC_CONST(-0.38658750057220), FRAC_CONST(0.99501574039459) },
{ FRAC_CONST(-0.29250815510750), FRAC_CONST(0.37444993853569) },
{ FRAC_CONST(-0.60182201862335), FRAC_CONST(0.86779648065567) },
{ FRAC_CONST(-0.97418588399887), FRAC_CONST(0.96468526124954) },
{ FRAC_CONST(0.88461571931839), FRAC_CONST(0.57508403062820) },
{ FRAC_CONST(0.05198933184147), FRAC_CONST(0.21269661188126) },
{ FRAC_CONST(-0.53499621152878), FRAC_CONST(0.97241556644440) },
{ FRAC_CONST(-0.49429559707642), FRAC_CONST(0.98183864355087) },
{ FRAC_CONST(-0.98935145139694), FRAC_CONST(-0.40249159932137) },
{ FRAC_CONST(-0.98081380128860), FRAC_CONST(-0.72856897115707) },
{ FRAC_CONST(-0.27338150143623), FRAC_CONST(0.99950921535492) },
{ FRAC_CONST(0.06310802698135), FRAC_CONST(-0.54539585113525) },
{ FRAC_CONST(-0.20461677014828), FRAC_CONST(-0.14209978282452) },
{ FRAC_CONST(0.66223841905594), FRAC_CONST(0.72528582811356) },
{ FRAC_CONST(-0.84764343500137), FRAC_CONST(0.02372316829860) },
{ FRAC_CONST(-0.89039862155914), FRAC_CONST(0.88866579532623) },
{ FRAC_CONST(0.95903307199478), FRAC_CONST(0.76744925975800) },
{ FRAC_CONST(0.73504126071930), FRAC_CONST(-0.03747203201056) },
{ FRAC_CONST(-0.31744435429573), FRAC_CONST(-0.36834111809731) },
{ FRAC_CONST(-0.34110826253891), FRAC_CONST(0.40211221575737) },
{ FRAC_CONST(0.47803884744644), FRAC_CONST(-0.39423218369484) },
{ FRAC_CONST(0.98299193382263), FRAC_CONST(0.01989791356027) },
{ FRAC_CONST(-0.30963072180748), FRAC_CONST(-0.18076720833778) },
{ FRAC_CONST(0.99992591142654), FRAC_CONST(-0.26281872391701) },
{ FRAC_CONST(-0.93149733543396), FRAC_CONST(-0.98313164710999) },
{ FRAC_CONST(0.99923473596573), FRAC_CONST(-0.80142992734909) },
{ FRAC_CONST(-0.26024168729782), FRAC_CONST(-0.75999760627747) },
{ FRAC_CONST(-0.35712513327599), FRAC_CONST(0.19298963248730) },
{ FRAC_CONST(-0.99899083375931), FRAC_CONST(0.74645155668259) },
{ FRAC_CONST(0.86557173728943), FRAC_CONST(0.55593866109848) },
{ FRAC_CONST(0.33408042788506), FRAC_CONST(0.86185956001282) },
{ FRAC_CONST(0.99010735750198), FRAC_CONST(0.04602397605777) },
{ FRAC_CONST(-0.66694271564484), FRAC_CONST(-0.91643613576889) },
{ FRAC_CONST(0.64016789197922), FRAC_CONST(0.15649530291557) },
{ FRAC_CONST(0.99570536613464), FRAC_CONST(0.45844584703445) },
{ FRAC_CONST(-0.63431465625763), FRAC_CONST(0.21079117059708) },
{ FRAC_CONST(-0.07706847041845), FRAC_CONST(-0.89581435918808) },
{ FRAC_CONST(0.98590087890625), FRAC_CONST(0.88241720199585) },
{ FRAC_CONST(0.80099332332611), FRAC_CONST(-0.36851897835732) },
{ FRAC_CONST(0.78368133306503), FRAC_CONST(0.45506998896599) },
{ FRAC_CONST(0.08707806468010), FRAC_CONST(0.80938994884491) },
{ FRAC_CONST(-0.86811882257462), FRAC_CONST(0.39347308874130) },
{ FRAC_CONST(-0.39466530084610), FRAC_CONST(-0.66809433698654) },
{ FRAC_CONST(0.97875326871872), FRAC_CONST(-0.72467839717865) },
{ FRAC_CONST(-0.95038563013077), FRAC_CONST(0.89563220739365) },
{ FRAC_CONST(0.17005239427090), FRAC_CONST(0.54683053493500) },
{ FRAC_CONST(-0.76910793781281), FRAC_CONST(-0.96226614713669) },
{ FRAC_CONST(0.99743282794952), FRAC_CONST(0.42697158455849) },
{ FRAC_CONST(0.95437383651733), FRAC_CONST(0.97002321481705) },
{ FRAC_CONST(0.99578905105591), FRAC_CONST(-0.54106825590134) },
{ FRAC_CONST(0.28058260679245), FRAC_CONST(-0.85361421108246) },
{ FRAC_CONST(0.85256522893906), FRAC_CONST(-0.64567607641220) },
{ FRAC_CONST(-0.50608539581299), FRAC_CONST(-0.65846014022827) },
{ FRAC_CONST(-0.97210735082626), FRAC_CONST(-0.23095212876797) },
{ FRAC_CONST(0.95424050092697), FRAC_CONST(-0.99240148067474) },
{ FRAC_CONST(-0.96926569938660), FRAC_CONST(0.73775655031204) },
{ FRAC_CONST(0.30872163176537), FRAC_CONST(0.41514959931374) },
{ FRAC_CONST(-0.24523839354515), FRAC_CONST(0.63206630945206) },
{ FRAC_CONST(-0.33813264966011), FRAC_CONST(-0.38661777973175) },
{ FRAC_CONST(-0.05826828256249), FRAC_CONST(-0.06940773874521) },
{ FRAC_CONST(-0.22898460924625), FRAC_CONST(0.97054851055145) },
{ FRAC_CONST(-0.18509915471077), FRAC_CONST(0.47565764188766) },
{ FRAC_CONST(-0.10488238185644), FRAC_CONST(-0.87769949436188) },
{ FRAC_CONST(-0.71886587142944), FRAC_CONST(0.78030979633331) },
{ FRAC_CONST(0.99793875217438), FRAC_CONST(0.90041309595108) },
{ FRAC_CONST(0.57563304901123), FRAC_CONST(-0.91034334897995) },
{ FRAC_CONST(0.28909647464752), FRAC_CONST(0.96307784318924) },
{ FRAC_CONST(0.42188999056816), FRAC_CONST(0.48148649930954) },
{ FRAC_CONST(0.93335050344467), FRAC_CONST(-0.43537023663521) },
{ FRAC_CONST(-0.97087377309799), FRAC_CONST(0.86636447906494) },
{ FRAC_CONST(0.36722871661186), FRAC_CONST(0.65291655063629) },
{ FRAC_CONST(-0.81093025207520), FRAC_CONST(0.08778370171785) },
{ FRAC_CONST(-0.26240602135658), FRAC_CONST(-0.92774093151093) },
{ FRAC_CONST(0.83996498584747), FRAC_CONST(0.55839848518372) },
{ FRAC_CONST(-0.99909615516663), FRAC_CONST(-0.96024608612061) },
{ FRAC_CONST(0.74649465084076), FRAC_CONST(0.12144893407822) },
{ FRAC_CONST(-0.74774593114853), FRAC_CONST(-0.26898062229156) },
{ FRAC_CONST(0.95781666040421), FRAC_CONST(-0.79047924280167) },
{ FRAC_CONST(0.95472306013107), FRAC_CONST(-0.08588775992393) },
{ FRAC_CONST(0.48708331584930), FRAC_CONST(0.99999040365219) },
{ FRAC_CONST(0.46332037448883), FRAC_CONST(0.10964126139879) },
{ FRAC_CONST(-0.76497006416321), FRAC_CONST(0.89210927486420) },
{ FRAC_CONST(0.57397389411926), FRAC_CONST(0.35289704799652) },
{ FRAC_CONST(0.75374317169189), FRAC_CONST(0.96705216169357) },
{ FRAC_CONST(-0.59174400568008), FRAC_CONST(-0.89405369758606) },
{ FRAC_CONST(0.75087904930115), FRAC_CONST(-0.29612672328949) },
{ FRAC_CONST(-0.98607856035233), FRAC_CONST(0.25034910440445) },
{ FRAC_CONST(-0.40761056542397), FRAC_CONST(-0.90045571327209) },
{ FRAC_CONST(0.66929268836975), FRAC_CONST(0.98629492521286) },
{ FRAC_CONST(-0.97463697195053), FRAC_CONST(-0.00190223299433) },
{ FRAC_CONST(0.90145510435104), FRAC_CONST(0.99781388044357) },
{ FRAC_CONST(-0.87259286642075), FRAC_CONST(0.99233585596085) },
{ FRAC_CONST(-0.91529458761215), FRAC_CONST(-0.15698707103729) },
{ FRAC_CONST(-0.03305738791823), FRAC_CONST(-0.37205263972282) },
{ FRAC_CONST(0.07223051041365), FRAC_CONST(-0.88805001974106) },
{ FRAC_CONST(0.99498009681702), FRAC_CONST(0.97094357013702) },
{ FRAC_CONST(-0.74904936552048), FRAC_CONST(0.99985486268997) },
{ FRAC_CONST(0.04585228487849), FRAC_CONST(0.99812334775925) },
{ FRAC_CONST(-0.89054954051971), FRAC_CONST(-0.31791913509369) },
{ FRAC_CONST(-0.83782142400742), FRAC_CONST(0.97637635469437) },
{ FRAC_CONST(0.33454805612564), FRAC_CONST(-0.86231517791748) },
{ FRAC_CONST(-0.99707579612732), FRAC_CONST(0.93237990140915) },
{ FRAC_CONST(-0.22827528417110), FRAC_CONST(0.18874759972095) },
{ FRAC_CONST(0.67248046398163), FRAC_CONST(-0.03646211326122) },
{ FRAC_CONST(-0.05146538093686), FRAC_CONST(-0.92599701881409) },
{ FRAC_CONST(0.99947297573090), FRAC_CONST(0.93625229597092) },
{ FRAC_CONST(0.66951125860214), FRAC_CONST(0.98905825614929) },
{ FRAC_CONST(-0.99602955579758), FRAC_CONST(-0.44654715061188) },
{ FRAC_CONST(0.82104903459549), FRAC_CONST(0.99540740251541) },
{ FRAC_CONST(0.99186509847641), FRAC_CONST(0.72022998332977) },
{ FRAC_CONST(-0.65284591913223), FRAC_CONST(0.52186721563339) },
{ FRAC_CONST(0.93885445594788), FRAC_CONST(-0.74895310401917) },
{ FRAC_CONST(0.96735250949860), FRAC_CONST(0.90891814231873) },
{ FRAC_CONST(-0.22225968539715), FRAC_CONST(0.57124030590057) },
{ FRAC_CONST(-0.44132784008980), FRAC_CONST(-0.92688840627670) },
{ FRAC_CONST(-0.85694974660873), FRAC_CONST(0.88844531774521) },
{ FRAC_CONST(0.91783040761948), FRAC_CONST(-0.46356892585754) },
{ FRAC_CONST(0.72556972503662), FRAC_CONST(-0.99899554252625) },
{ FRAC_CONST(-0.99711579084396), FRAC_CONST(0.58211559057236) },
{ FRAC_CONST(0.77638977766037), FRAC_CONST(0.94321835041046) },
{ FRAC_CONST(0.07717324048281), FRAC_CONST(0.58638399839401) },
{ FRAC_CONST(-0.56049829721451), FRAC_CONST(0.82522302865982) },
{ FRAC_CONST(0.98398894071579), FRAC_CONST(0.39467439055443) },
{ FRAC_CONST(0.47546947002411), FRAC_CONST(0.68613046407700) },
{ FRAC_CONST(0.65675091743469), FRAC_CONST(0.18331636488438) },
{ FRAC_CONST(0.03273375332355), FRAC_CONST(-0.74933111667633) },
{ FRAC_CONST(-0.38684144616127), FRAC_CONST(0.51337349414825) },
{ FRAC_CONST(-0.97346270084381), FRAC_CONST(-0.96549361944199) },
{ FRAC_CONST(-0.53282153606415), FRAC_CONST(-0.91423267126083) },
{ FRAC_CONST(0.99817311763763), FRAC_CONST(0.61133575439453) },
{ FRAC_CONST(-0.50254499912262), FRAC_CONST(-0.88829338550568) },
{ FRAC_CONST(0.01995873264968), FRAC_CONST(0.85223513841629) },
{ FRAC_CONST(0.99930381774902), FRAC_CONST(0.94578897953033) },
{ FRAC_CONST(0.82907766103745), FRAC_CONST(-0.06323442608118) },
{ FRAC_CONST(-0.58660709857941), FRAC_CONST(0.96840775012970) },
{ FRAC_CONST(-0.17573736608028), FRAC_CONST(-0.48166921734810) },
{ FRAC_CONST(0.83434289693832), FRAC_CONST(-0.13023450970650) },
{ FRAC_CONST(0.05946491286159), FRAC_CONST(0.20511047542095) },
{ FRAC_CONST(0.81505483388901), FRAC_CONST(-0.94685947895050) },
{ FRAC_CONST(-0.44976380467415), FRAC_CONST(0.40894573926926) },
{ FRAC_CONST(-0.89746475219727), FRAC_CONST(0.99846577644348) },
{ FRAC_CONST(0.39677256345749), FRAC_CONST(-0.74854665994644) },
{ FRAC_CONST(-0.07588948309422), FRAC_CONST(0.74096214771271) },
{ FRAC_CONST(0.76343196630478), FRAC_CONST(0.41746628284454) },
{ FRAC_CONST(-0.74490106105804), FRAC_CONST(0.94725912809372) },
{ FRAC_CONST(0.64880120754242), FRAC_CONST(0.41336661577225) },
{ FRAC_CONST(0.62319535017014), FRAC_CONST(-0.93098312616348) },
{ FRAC_CONST(0.42215818166733), FRAC_CONST(-0.07712787389755) },
{ FRAC_CONST(0.02704554051161), FRAC_CONST(-0.05417517945170) },
{ FRAC_CONST(0.80001771450043), FRAC_CONST(0.91542196273804) },
{ FRAC_CONST(-0.79351830482483), FRAC_CONST(-0.36208897829056) },
{ FRAC_CONST(0.63872361183167), FRAC_CONST(0.08128252625465) },
{ FRAC_CONST(0.52890521287918), FRAC_CONST(0.60048872232437) },
{ FRAC_CONST(0.74238550662994), FRAC_CONST(0.04491915181279) },
{ FRAC_CONST(0.99096131324768), FRAC_CONST(-0.19451183080673) },
{ FRAC_CONST(-0.80412328243256), FRAC_CONST(-0.88513815402985) },
{ FRAC_CONST(-0.64612615108490), FRAC_CONST(0.72198677062988) },
{ FRAC_CONST(0.11657770723104), FRAC_CONST(-0.83662831783295) },
{ FRAC_CONST(-0.95053184032440), FRAC_CONST(-0.96939903497696) },
{ FRAC_CONST(-0.62228870391846), FRAC_CONST(0.82767260074615) },
{ FRAC_CONST(0.03004475869238), FRAC_CONST(-0.99738895893097) },
{ FRAC_CONST(-0.97987216711044), FRAC_CONST(0.36526128649712) },
{ FRAC_CONST(-0.99986982345581), FRAC_CONST(-0.36021611094475) },
{ FRAC_CONST(0.89110648632050), FRAC_CONST(-0.97894251346588) },
{ FRAC_CONST(0.10407960414886), FRAC_CONST(0.77357792854309) },
{ FRAC_CONST(0.95964735746384), FRAC_CONST(-0.35435819625854) },
{ FRAC_CONST(0.50843232870102), FRAC_CONST(0.96107691526413) },
{ FRAC_CONST(0.17006334662437), FRAC_CONST(-0.76854026317596) },
{ FRAC_CONST(0.25872674584389), FRAC_CONST(0.99893301725388) },
{ FRAC_CONST(-0.01115998718888), FRAC_CONST(0.98496019840240) },
{ FRAC_CONST(-0.79598701000214), FRAC_CONST(0.97138410806656) },
{ FRAC_CONST(-0.99264711141586), FRAC_CONST(-0.99542820453644) },
{ FRAC_CONST(-0.99829661846161), FRAC_CONST(0.01877138763666) },
{ FRAC_CONST(-0.70801013708115), FRAC_CONST(0.33680686354637) },
{ FRAC_CONST(-0.70467054843903), FRAC_CONST(0.93272775411606) },
{ FRAC_CONST(0.99846023321152), FRAC_CONST(-0.98725748062134) },
{ FRAC_CONST(-0.63364970684052), FRAC_CONST(-0.16473594307899) },
{ FRAC_CONST(-0.16258217394352), FRAC_CONST(-0.95939123630524) },
{ FRAC_CONST(-0.43645593523979), FRAC_CONST(-0.94805032014847) },
{ FRAC_CONST(-0.99848473072052), FRAC_CONST(0.96245169639587) },
{ FRAC_CONST(-0.16796459257603), FRAC_CONST(-0.98987513780594) },
{ FRAC_CONST(-0.87979227304459), FRAC_CONST(-0.71725726127625) },
{ FRAC_CONST(0.44183099269867), FRAC_CONST(-0.93568974733353) },
{ FRAC_CONST(0.93310177326202), FRAC_CONST(-0.99913311004639) },
{ FRAC_CONST(-0.93941932916641), FRAC_CONST(-0.56409376859665) },
{ FRAC_CONST(-0.88590002059937), FRAC_CONST(0.47624599933624) },
{ FRAC_CONST(0.99971461296082), FRAC_CONST(-0.83889955282211) },
{ FRAC_CONST(-0.75376385450363), FRAC_CONST(0.00814643409103) },
{ FRAC_CONST(0.93887686729431), FRAC_CONST(-0.11284527927637) },
{ FRAC_CONST(0.85126435756683), FRAC_CONST(0.52349251508713) },
{ FRAC_CONST(0.39701420068741), FRAC_CONST(0.81779634952545) },
{ FRAC_CONST(-0.37024465203285), FRAC_CONST(-0.87071657180786) },
{ FRAC_CONST(-0.36024826765060), FRAC_CONST(0.34655734896660) },
{ FRAC_CONST(-0.93388813734055), FRAC_CONST(-0.84476542472839) },
{ FRAC_CONST(-0.65298801660538), FRAC_CONST(-0.18439576029778) },
{ FRAC_CONST(0.11960318684578), FRAC_CONST(0.99899345636368) },
{ FRAC_CONST(0.94292563199997), FRAC_CONST(0.83163905143738) },
{ FRAC_CONST(0.75081145763397), FRAC_CONST(-0.35533222556114) },
{ FRAC_CONST(0.56721979379654), FRAC_CONST(-0.24076835811138) },
{ FRAC_CONST(0.46857765316963), FRAC_CONST(-0.30140233039856) },
{ FRAC_CONST(0.97312313318253), FRAC_CONST(-0.99548190832138) },
{ FRAC_CONST(-0.38299977779388), FRAC_CONST(0.98516911268234) },
{ FRAC_CONST(0.41025799512863), FRAC_CONST(0.02116736955941) },
{ FRAC_CONST(0.09638062119484), FRAC_CONST(0.04411984235048) },
{ FRAC_CONST(-0.85283249616623), FRAC_CONST(0.91475564241409) },
{ FRAC_CONST(0.88866806030273), FRAC_CONST(-0.99735265970230) },
{ FRAC_CONST(-0.48202428221703), FRAC_CONST(-0.96805608272552) },
{ FRAC_CONST(0.27572581171989), FRAC_CONST(0.58634752035141) },
{ FRAC_CONST(-0.65889132022858), FRAC_CONST(0.58835631608963) },
{ FRAC_CONST(0.98838084936142), FRAC_CONST(0.99994349479675) },
{ FRAC_CONST(-0.20651349425316), FRAC_CONST(0.54593044519424) },
{ FRAC_CONST(-0.62126415967941), FRAC_CONST(-0.59893679618835) },
{ FRAC_CONST(0.20320105552673), FRAC_CONST(-0.86879181861877) },
{ FRAC_CONST(-0.97790551185608), FRAC_CONST(0.96290808916092) },
{ FRAC_CONST(0.11112534999847), FRAC_CONST(0.21484763920307) },
{ FRAC_CONST(-0.41368338465691), FRAC_CONST(0.28216838836670) },
{ FRAC_CONST(0.24133038520813), FRAC_CONST(0.51294362545013) },
{ FRAC_CONST(-0.66393411159515), FRAC_CONST(-0.08249679952860) },
{ FRAC_CONST(-0.53697830438614), FRAC_CONST(-0.97649902105331) },
{ FRAC_CONST(-0.97224736213684), FRAC_CONST(0.22081333398819) },
{ FRAC_CONST(0.87392479181290), FRAC_CONST(-0.12796173989773) },
{ FRAC_CONST(0.19050361216068), FRAC_CONST(0.01602615416050) },
{ FRAC_CONST(-0.46353441476822), FRAC_CONST(-0.95249038934708) },
{ FRAC_CONST(-0.07064096629620), FRAC_CONST(-0.94479805231094) },
{ FRAC_CONST(-0.92444086074829), FRAC_CONST(-0.10457590222359) },
{ FRAC_CONST(-0.83822596073151), FRAC_CONST(-0.01695043221116) },
{ FRAC_CONST(0.75214684009552), FRAC_CONST(-0.99955683946609) },
{ FRAC_CONST(-0.42102998495102), FRAC_CONST(0.99720942974091) },
{ FRAC_CONST(-0.72094786167145), FRAC_CONST(-0.35008960962296) },
{ FRAC_CONST(0.78843313455582), FRAC_CONST(0.52851396799088) },
{ FRAC_CONST(0.97394025325775), FRAC_CONST(-0.26695942878723) },
{ FRAC_CONST(0.99206465482712), FRAC_CONST(-0.57010120153427) },
{ FRAC_CONST(0.76789611577988), FRAC_CONST(-0.76519358158112) },
{ FRAC_CONST(-0.82002419233322), FRAC_CONST(-0.73530179262161) },
{ FRAC_CONST(0.81924992799759), FRAC_CONST(0.99698424339294) },
{ FRAC_CONST(-0.26719850301743), FRAC_CONST(0.68903368711472) },
{ FRAC_CONST(-0.43311259150505), FRAC_CONST(0.85321813821793) },
{ FRAC_CONST(0.99194979667664), FRAC_CONST(0.91876250505447) },
{ FRAC_CONST(-0.80691999197006), FRAC_CONST(-0.32627540826797) },
{ FRAC_CONST(0.43080005049706), FRAC_CONST(-0.21919095516205) },
{ FRAC_CONST(0.67709493637085), FRAC_CONST(-0.95478075742722) },
{ FRAC_CONST(0.56151771545410), FRAC_CONST(-0.70693808794022) },
{ FRAC_CONST(0.10831862688065), FRAC_CONST(-0.08628837019205) },
{ FRAC_CONST(0.91229414939880), FRAC_CONST(-0.65987348556519) },
{ FRAC_CONST(-0.48972892761230), FRAC_CONST(0.56289243698120) },
{ FRAC_CONST(-0.89033657312393), FRAC_CONST(-0.71656566858292) },
{ FRAC_CONST(0.65269446372986), FRAC_CONST(0.65916007757187) },
{ FRAC_CONST(0.67439478635788), FRAC_CONST(-0.81684380769730) },
{ FRAC_CONST(-0.47770830988884), FRAC_CONST(-0.16789555549622) },
{ FRAC_CONST(-0.99715977907181), FRAC_CONST(-0.93565785884857) },
{ FRAC_CONST(-0.90889590978622), FRAC_CONST(0.62034398317337) },
{ FRAC_CONST(-0.06618622690439), FRAC_CONST(-0.23812216520309) },
{ FRAC_CONST(0.99430269002914), FRAC_CONST(0.18812555074692) },
{ FRAC_CONST(0.97686403989792), FRAC_CONST(-0.28664535284042) },
{ FRAC_CONST(0.94813650846481), FRAC_CONST(-0.97506642341614) },
{ FRAC_CONST(-0.95434498786926), FRAC_CONST(-0.79607981443405) },
{ FRAC_CONST(-0.49104782938957), FRAC_CONST(0.32895213365555) },
{ FRAC_CONST(0.99881172180176), FRAC_CONST(0.88993984460831) },
{ FRAC_CONST(0.50449168682098), FRAC_CONST(-0.85995072126389) },
{ FRAC_CONST(0.47162890434265), FRAC_CONST(-0.18680204451084) },
{ FRAC_CONST(-0.62081581354141), FRAC_CONST(0.75000673532486) },
{ FRAC_CONST(-0.43867015838623), FRAC_CONST(0.99998068809509) },
{ FRAC_CONST(0.98630565404892), FRAC_CONST(-0.53578901290894) },
{ FRAC_CONST(-0.61510360240936), FRAC_CONST(-0.89515018463135) },
{ FRAC_CONST(-0.03841517493129), FRAC_CONST(-0.69888818264008) },
{ FRAC_CONST(-0.30102157592773), FRAC_CONST(-0.07667808979750) },
{ FRAC_CONST(0.41881284117699), FRAC_CONST(0.02188098989427) },
{ FRAC_CONST(-0.86135452985764), FRAC_CONST(0.98947483301163) },
{ FRAC_CONST(0.67226862907410), FRAC_CONST(-0.13494388759136) },
{ FRAC_CONST(-0.70737397670746), FRAC_CONST(-0.76547348499298) },
{ FRAC_CONST(0.94044947624207), FRAC_CONST(0.09026201069355) },
{ FRAC_CONST(-0.82386350631714), FRAC_CONST(0.08924768865108) },
{ FRAC_CONST(-0.32070666551590), FRAC_CONST(0.50143420696259) },
{ FRAC_CONST(0.57593160867691), FRAC_CONST(-0.98966425657272) },
{ FRAC_CONST(-0.36326017975807), FRAC_CONST(0.07440242916346) },
{ FRAC_CONST(0.99979043006897), FRAC_CONST(-0.14130286872387) },
{ FRAC_CONST(-0.92366021871567), FRAC_CONST(-0.97979295253754) },
{ FRAC_CONST(-0.44607177376747), FRAC_CONST(-0.54233253002167) },
{ FRAC_CONST(0.44226801395416), FRAC_CONST(0.71326756477356) },
{ FRAC_CONST(0.03671907261014), FRAC_CONST(0.63606387376785) },
{ FRAC_CONST(0.52175426483154), FRAC_CONST(-0.85396826267242) },
{ FRAC_CONST(-0.94701141119003), FRAC_CONST(-0.01826348155737) },
{ FRAC_CONST(-0.98759609460831), FRAC_CONST(0.82288712263107) },
{ FRAC_CONST(0.87434792518616), FRAC_CONST(0.89399492740631) },
{ FRAC_CONST(-0.93412041664124), FRAC_CONST(0.41374051570892) },
{ FRAC_CONST(0.96063941717148), FRAC_CONST(0.93116706609726) },
{ FRAC_CONST(0.97534251213074), FRAC_CONST(0.86150932312012) },
{ FRAC_CONST(0.99642467498779), FRAC_CONST(0.70190042257309) },
{ FRAC_CONST(-0.94705086946487), FRAC_CONST(-0.29580041766167) },
{ FRAC_CONST(0.91599804162979), FRAC_CONST(-0.98147833347321) }
};
#ifdef __cplusplus
#endif
#endif

View File

@ -0,0 +1,636 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: sbr_qmf.c,v 1.32 2007/11/01 12:33:36 menno Exp $
**/
#include "common.h"
#include "structs.h"
#ifdef SBR_DEC
#include <stdlib.h>
#include <string.h>
#include "sbr_dct.h"
#include "sbr_qmf.h"
#include "sbr_qmf_c.h"
#include "sbr_syntax.h"
qmfa_info *qmfa_init(uint8_t channels)
{
qmfa_info *qmfa = (qmfa_info*)faad_malloc(sizeof(qmfa_info));
/* x is implemented as double ringbuffer */
qmfa->x = (real_t*)faad_malloc(2 * channels * 10 * sizeof(real_t));
memset(qmfa->x, 0, 2 * channels * 10 * sizeof(real_t));
/* ringbuffer index */
qmfa->x_index = 0;
qmfa->channels = channels;
return qmfa;
}
void qmfa_end(qmfa_info *qmfa)
{
if (qmfa)
{
if (qmfa->x) faad_free(qmfa->x);
faad_free(qmfa);
}
}
void sbr_qmf_analysis_32(sbr_info *sbr, qmfa_info *qmfa, const real_t *input,
qmf_t X[MAX_NTSRHFG][64], uint8_t offset, uint8_t kx)
{
ALIGN real_t u[64];
#ifndef SBR_LOW_POWER
ALIGN real_t in_real[32], in_imag[32], out_real[32], out_imag[32];
#else
ALIGN real_t y[32];
#endif
uint32_t in = 0;
uint8_t l;
/* qmf subsample l */
for (l = 0; l < sbr->numTimeSlotsRate; l++)
{
int16_t n;
/* shift input buffer x */
/* input buffer is not shifted anymore, x is implemented as double ringbuffer */
//memmove(qmfa->x + 32, qmfa->x, (320-32)*sizeof(real_t));
/* add new samples to input buffer x */
for (n = 32 - 1; n >= 0; n--)
{
#ifdef FIXED_POINT
qmfa->x[qmfa->x_index + n] = qmfa->x[qmfa->x_index + n + 320] = (input[in++]) >> 4;
#else
qmfa->x[qmfa->x_index + n] = qmfa->x[qmfa->x_index + n + 320] = input[in++];
#endif
}
/* window and summation to create array u */
for (n = 0; n < 64; n++)
{
u[n] = MUL_F(qmfa->x[qmfa->x_index + n], qmf_c[2*n]) +
MUL_F(qmfa->x[qmfa->x_index + n + 64], qmf_c[2*(n + 64)]) +
MUL_F(qmfa->x[qmfa->x_index + n + 128], qmf_c[2*(n + 128)]) +
MUL_F(qmfa->x[qmfa->x_index + n + 192], qmf_c[2*(n + 192)]) +
MUL_F(qmfa->x[qmfa->x_index + n + 256], qmf_c[2*(n + 256)]);
}
/* update ringbuffer index */
qmfa->x_index -= 32;
if (qmfa->x_index < 0)
qmfa->x_index = (320-32);
/* calculate 32 subband samples by introducing X */
#ifdef SBR_LOW_POWER
y[0] = u[48];
for (n = 1; n < 16; n++)
y[n] = u[n+48] + u[48-n];
for (n = 16; n < 32; n++)
y[n] = -u[n-16] + u[48-n];
DCT3_32_unscaled(u, y);
for (n = 0; n < 32; n++)
{
if (n < kx)
{
#ifdef FIXED_POINT
QMF_RE(X[l + offset][n]) = u[n] /*<< 1*/;
#else
QMF_RE(X[l + offset][n]) = 2. * u[n];
#endif
} else {
QMF_RE(X[l + offset][n]) = 0;
}
}
#else
// Reordering of data moved from DCT_IV to here
in_imag[31] = u[1];
in_real[0] = u[0];
for (n = 1; n < 31; n++)
{
in_imag[31 - n] = u[n+1];
in_real[n] = -u[64-n];
}
in_imag[0] = u[32];
in_real[31] = -u[33];
// dct4_kernel is DCT_IV without reordering which is done before and after FFT
dct4_kernel(in_real, in_imag, out_real, out_imag);
// Reordering of data moved from DCT_IV to here
for (n = 0; n < 16; n++) {
if (2*n+1 < kx) {
#ifdef FIXED_POINT
QMF_RE(X[l + offset][2*n]) = out_real[n];
QMF_IM(X[l + offset][2*n]) = out_imag[n];
QMF_RE(X[l + offset][2*n+1]) = -out_imag[31-n];
QMF_IM(X[l + offset][2*n+1]) = -out_real[31-n];
#else
QMF_RE(X[l + offset][2*n]) = 2. * out_real[n];
QMF_IM(X[l + offset][2*n]) = 2. * out_imag[n];
QMF_RE(X[l + offset][2*n+1]) = -2. * out_imag[31-n];
QMF_IM(X[l + offset][2*n+1]) = -2. * out_real[31-n];
#endif
} else {
if (2*n < kx) {
#ifdef FIXED_POINT
QMF_RE(X[l + offset][2*n]) = out_real[n];
QMF_IM(X[l + offset][2*n]) = out_imag[n];
#else
QMF_RE(X[l + offset][2*n]) = 2. * out_real[n];
QMF_IM(X[l + offset][2*n]) = 2. * out_imag[n];
#endif
}
else {
QMF_RE(X[l + offset][2*n]) = 0;
QMF_IM(X[l + offset][2*n]) = 0;
}
QMF_RE(X[l + offset][2*n+1]) = 0;
QMF_IM(X[l + offset][2*n+1]) = 0;
}
}
#endif
}
}
static const complex_t qmf32_pre_twiddle[] =
{
{ FRAC_CONST(0.999924701839145), FRAC_CONST(-0.012271538285720) },
{ FRAC_CONST(0.999322384588350), FRAC_CONST(-0.036807222941359) },
{ FRAC_CONST(0.998118112900149), FRAC_CONST(-0.061320736302209) },
{ FRAC_CONST(0.996312612182778), FRAC_CONST(-0.085797312344440) },
{ FRAC_CONST(0.993906970002356), FRAC_CONST(-0.110222207293883) },
{ FRAC_CONST(0.990902635427780), FRAC_CONST(-0.134580708507126) },
{ FRAC_CONST(0.987301418157858), FRAC_CONST(-0.158858143333861) },
{ FRAC_CONST(0.983105487431216), FRAC_CONST(-0.183039887955141) },
{ FRAC_CONST(0.978317370719628), FRAC_CONST(-0.207111376192219) },
{ FRAC_CONST(0.972939952205560), FRAC_CONST(-0.231058108280671) },
{ FRAC_CONST(0.966976471044852), FRAC_CONST(-0.254865659604515) },
{ FRAC_CONST(0.960430519415566), FRAC_CONST(-0.278519689385053) },
{ FRAC_CONST(0.953306040354194), FRAC_CONST(-0.302005949319228) },
{ FRAC_CONST(0.945607325380521), FRAC_CONST(-0.325310292162263) },
{ FRAC_CONST(0.937339011912575), FRAC_CONST(-0.348418680249435) },
{ FRAC_CONST(0.928506080473216), FRAC_CONST(-0.371317193951838) },
{ FRAC_CONST(0.919113851690058), FRAC_CONST(-0.393992040061048) },
{ FRAC_CONST(0.909167983090522), FRAC_CONST(-0.416429560097637) },
{ FRAC_CONST(0.898674465693954), FRAC_CONST(-0.438616238538528) },
{ FRAC_CONST(0.887639620402854), FRAC_CONST(-0.460538710958240) },
{ FRAC_CONST(0.876070094195407), FRAC_CONST(-0.482183772079123) },
{ FRAC_CONST(0.863972856121587), FRAC_CONST(-0.503538383725718) },
{ FRAC_CONST(0.851355193105265), FRAC_CONST(-0.524589682678469) },
{ FRAC_CONST(0.838224705554838), FRAC_CONST(-0.545324988422046) },
{ FRAC_CONST(0.824589302785025), FRAC_CONST(-0.565731810783613) },
{ FRAC_CONST(0.810457198252595), FRAC_CONST(-0.585797857456439) },
{ FRAC_CONST(0.795836904608884), FRAC_CONST(-0.605511041404326) },
{ FRAC_CONST(0.780737228572094), FRAC_CONST(-0.624859488142386) },
{ FRAC_CONST(0.765167265622459), FRAC_CONST(-0.643831542889791) },
{ FRAC_CONST(0.749136394523459), FRAC_CONST(-0.662415777590172) },
{ FRAC_CONST(0.732654271672413), FRAC_CONST(-0.680600997795453) },
{ FRAC_CONST(0.715730825283819), FRAC_CONST(-0.698376249408973) }
};
qmfs_info *qmfs_init(uint8_t channels)
{
qmfs_info *qmfs = (qmfs_info*)faad_malloc(sizeof(qmfs_info));
/* v is a double ringbuffer */
qmfs->v = (real_t*)faad_malloc(2 * channels * 20 * sizeof(real_t));
memset(qmfs->v, 0, 2 * channels * 20 * sizeof(real_t));
qmfs->v_index = 0;
qmfs->channels = channels;
return qmfs;
}
void qmfs_end(qmfs_info *qmfs)
{
if (qmfs)
{
if (qmfs->v) faad_free(qmfs->v);
faad_free(qmfs);
}
}
#ifdef SBR_LOW_POWER
void sbr_qmf_synthesis_32(sbr_info *sbr, qmfs_info *qmfs, qmf_t X[MAX_NTSRHFG][64],
real_t *output)
{
ALIGN real_t x[16];
ALIGN real_t y[16];
int32_t n, k, out = 0;
uint8_t l;
/* qmf subsample l */
for (l = 0; l < sbr->numTimeSlotsRate; l++)
{
/* shift buffers */
/* we are not shifting v, it is a double ringbuffer */
//memmove(qmfs->v + 64, qmfs->v, (640-64)*sizeof(real_t));
/* calculate 64 samples */
for (k = 0; k < 16; k++)
{
#ifdef FIXED_POINT
y[k] = (QMF_RE(X[l][k]) - QMF_RE(X[l][31 - k]));
x[k] = (QMF_RE(X[l][k]) + QMF_RE(X[l][31 - k]));
#else
y[k] = (QMF_RE(X[l][k]) - QMF_RE(X[l][31 - k])) / 32.0;
x[k] = (QMF_RE(X[l][k]) + QMF_RE(X[l][31 - k])) / 32.0;
#endif
}
/* even n samples */
DCT2_16_unscaled(x, x);
/* odd n samples */
DCT4_16(y, y);
for (n = 8; n < 24; n++)
{
qmfs->v[qmfs->v_index + n*2] = qmfs->v[qmfs->v_index + 640 + n*2] = x[n-8];
qmfs->v[qmfs->v_index + n*2+1] = qmfs->v[qmfs->v_index + 640 + n*2+1] = y[n-8];
}
for (n = 0; n < 16; n++)
{
qmfs->v[qmfs->v_index + n] = qmfs->v[qmfs->v_index + 640 + n] = qmfs->v[qmfs->v_index + 32-n];
}
qmfs->v[qmfs->v_index + 48] = qmfs->v[qmfs->v_index + 640 + 48] = 0;
for (n = 1; n < 16; n++)
{
qmfs->v[qmfs->v_index + 48+n] = qmfs->v[qmfs->v_index + 640 + 48+n] = -qmfs->v[qmfs->v_index + 48-n];
}
/* calculate 32 output samples and window */
for (k = 0; k < 32; k++)
{
output[out++] = MUL_F(qmfs->v[qmfs->v_index + k], qmf_c[2*k]) +
MUL_F(qmfs->v[qmfs->v_index + 96 + k], qmf_c[64 + 2*k]) +
MUL_F(qmfs->v[qmfs->v_index + 128 + k], qmf_c[128 + 2*k]) +
MUL_F(qmfs->v[qmfs->v_index + 224 + k], qmf_c[192 + 2*k]) +
MUL_F(qmfs->v[qmfs->v_index + 256 + k], qmf_c[256 + 2*k]) +
MUL_F(qmfs->v[qmfs->v_index + 352 + k], qmf_c[320 + 2*k]) +
MUL_F(qmfs->v[qmfs->v_index + 384 + k], qmf_c[384 + 2*k]) +
MUL_F(qmfs->v[qmfs->v_index + 480 + k], qmf_c[448 + 2*k]) +
MUL_F(qmfs->v[qmfs->v_index + 512 + k], qmf_c[512 + 2*k]) +
MUL_F(qmfs->v[qmfs->v_index + 608 + k], qmf_c[576 + 2*k]);
}
/* update the ringbuffer index */
qmfs->v_index -= 64;
if (qmfs->v_index < 0)
qmfs->v_index = (640-64);
}
}
void sbr_qmf_synthesis_64(sbr_info *sbr, qmfs_info *qmfs, qmf_t X[MAX_NTSRHFG][64],
real_t *output)
{
ALIGN real_t x[64];
ALIGN real_t y[64];
int32_t n, k, out = 0;
uint8_t l;
/* qmf subsample l */
for (l = 0; l < sbr->numTimeSlotsRate; l++)
{
/* shift buffers */
/* we are not shifting v, it is a double ringbuffer */
//memmove(qmfs->v + 128, qmfs->v, (1280-128)*sizeof(real_t));
/* calculate 128 samples */
for (k = 0; k < 32; k++)
{
#ifdef FIXED_POINT
y[k] = (QMF_RE(X[l][k]) - QMF_RE(X[l][63 - k]));
x[k] = (QMF_RE(X[l][k]) + QMF_RE(X[l][63 - k]));
#else
y[k] = (QMF_RE(X[l][k]) - QMF_RE(X[l][63 - k])) / 32.0;
x[k] = (QMF_RE(X[l][k]) + QMF_RE(X[l][63 - k])) / 32.0;
#endif
}
/* even n samples */
DCT2_32_unscaled(x, x);
/* odd n samples */
DCT4_32(y, y);
for (n = 16; n < 48; n++)
{
qmfs->v[qmfs->v_index + n*2] = qmfs->v[qmfs->v_index + 1280 + n*2] = x[n-16];
qmfs->v[qmfs->v_index + n*2+1] = qmfs->v[qmfs->v_index + 1280 + n*2+1] = y[n-16];
}
for (n = 0; n < 32; n++)
{
qmfs->v[qmfs->v_index + n] = qmfs->v[qmfs->v_index + 1280 + n] = qmfs->v[qmfs->v_index + 64-n];
}
qmfs->v[qmfs->v_index + 96] = qmfs->v[qmfs->v_index + 1280 + 96] = 0;
for (n = 1; n < 32; n++)
{
qmfs->v[qmfs->v_index + 96+n] = qmfs->v[qmfs->v_index + 1280 + 96+n] = -qmfs->v[qmfs->v_index + 96-n];
}
/* calculate 64 output samples and window */
for (k = 0; k < 64; k++)
{
output[out++] = MUL_F(qmfs->v[qmfs->v_index + k], qmf_c[k]) +
MUL_F(qmfs->v[qmfs->v_index + 192 + k], qmf_c[64 + k]) +
MUL_F(qmfs->v[qmfs->v_index + 256 + k], qmf_c[128 + k]) +
MUL_F(qmfs->v[qmfs->v_index + 256 + 192 + k], qmf_c[128 + 64 + k]) +
MUL_F(qmfs->v[qmfs->v_index + 512 + k], qmf_c[256 + k]) +
MUL_F(qmfs->v[qmfs->v_index + 512 + 192 + k], qmf_c[256 + 64 + k]) +
MUL_F(qmfs->v[qmfs->v_index + 768 + k], qmf_c[384 + k]) +
MUL_F(qmfs->v[qmfs->v_index + 768 + 192 + k], qmf_c[384 + 64 + k]) +
MUL_F(qmfs->v[qmfs->v_index + 1024 + k], qmf_c[512 + k]) +
MUL_F(qmfs->v[qmfs->v_index + 1024 + 192 + k], qmf_c[512 + 64 + k]);
}
/* update the ringbuffer index */
qmfs->v_index -= 128;
if (qmfs->v_index < 0)
qmfs->v_index = (1280-128);
}
}
#else
void sbr_qmf_synthesis_32(sbr_info *sbr, qmfs_info *qmfs, qmf_t X[MAX_NTSRHFG][64],
real_t *output)
{
ALIGN real_t x1[32], x2[32];
#ifndef FIXED_POINT
real_t scale = 1.f/64.f;
#endif
int32_t n, k, out = 0;
uint8_t l;
/* qmf subsample l */
for (l = 0; l < sbr->numTimeSlotsRate; l++)
{
/* shift buffer v */
/* buffer is not shifted, we are using a ringbuffer */
//memmove(qmfs->v + 64, qmfs->v, (640-64)*sizeof(real_t));
/* calculate 64 samples */
/* complex pre-twiddle */
for (k = 0; k < 32; k++)
{
x1[k] = MUL_F(QMF_RE(X[l][k]), RE(qmf32_pre_twiddle[k])) - MUL_F(QMF_IM(X[l][k]), IM(qmf32_pre_twiddle[k]));
x2[k] = MUL_F(QMF_IM(X[l][k]), RE(qmf32_pre_twiddle[k])) + MUL_F(QMF_RE(X[l][k]), IM(qmf32_pre_twiddle[k]));
#ifndef FIXED_POINT
x1[k] *= scale;
x2[k] *= scale;
#else
x1[k] >>= 1;
x2[k] >>= 1;
#endif
}
/* transform */
DCT4_32(x1, x1);
DST4_32(x2, x2);
for (n = 0; n < 32; n++)
{
qmfs->v[qmfs->v_index + n] = qmfs->v[qmfs->v_index + 640 + n] = -x1[n] + x2[n];
qmfs->v[qmfs->v_index + 63 - n] = qmfs->v[qmfs->v_index + 640 + 63 - n] = x1[n] + x2[n];
}
/* calculate 32 output samples and window */
for (k = 0; k < 32; k++)
{
output[out++] = MUL_F(qmfs->v[qmfs->v_index + k], qmf_c[2*k]) +
MUL_F(qmfs->v[qmfs->v_index + 96 + k], qmf_c[64 + 2*k]) +
MUL_F(qmfs->v[qmfs->v_index + 128 + k], qmf_c[128 + 2*k]) +
MUL_F(qmfs->v[qmfs->v_index + 224 + k], qmf_c[192 + 2*k]) +
MUL_F(qmfs->v[qmfs->v_index + 256 + k], qmf_c[256 + 2*k]) +
MUL_F(qmfs->v[qmfs->v_index + 352 + k], qmf_c[320 + 2*k]) +
MUL_F(qmfs->v[qmfs->v_index + 384 + k], qmf_c[384 + 2*k]) +
MUL_F(qmfs->v[qmfs->v_index + 480 + k], qmf_c[448 + 2*k]) +
MUL_F(qmfs->v[qmfs->v_index + 512 + k], qmf_c[512 + 2*k]) +
MUL_F(qmfs->v[qmfs->v_index + 608 + k], qmf_c[576 + 2*k]);
}
/* update ringbuffer index */
qmfs->v_index -= 64;
if (qmfs->v_index < 0)
qmfs->v_index = (640 - 64);
}
}
void sbr_qmf_synthesis_64(sbr_info *sbr, qmfs_info *qmfs, qmf_t X[MAX_NTSRHFG][64],
real_t *output)
{
// ALIGN real_t x1[64], x2[64];
#ifndef SBR_LOW_POWER
ALIGN real_t in_real1[32], in_imag1[32], out_real1[32], out_imag1[32];
ALIGN real_t in_real2[32], in_imag2[32], out_real2[32], out_imag2[32];
#endif
qmf_t * pX;
real_t * pring_buffer_1, * pring_buffer_3;
// real_t * ptemp_1, * ptemp_2;
#ifdef PREFER_POINTERS
// These pointers are used if target platform has autoinc address generators
real_t * pring_buffer_2, * pring_buffer_4;
real_t * pring_buffer_5, * pring_buffer_6;
real_t * pring_buffer_7, * pring_buffer_8;
real_t * pring_buffer_9, * pring_buffer_10;
const real_t * pqmf_c_1, * pqmf_c_2, * pqmf_c_3, * pqmf_c_4;
const real_t * pqmf_c_5, * pqmf_c_6, * pqmf_c_7, * pqmf_c_8;
const real_t * pqmf_c_9, * pqmf_c_10;
#endif // #ifdef PREFER_POINTERS
#ifndef FIXED_POINT
real_t scale = 1.f/64.f;
#endif
int32_t n, k, out = 0;
uint8_t l;
/* qmf subsample l */
for (l = 0; l < sbr->numTimeSlotsRate; l++)
{
/* shift buffer v */
/* buffer is not shifted, we use double ringbuffer */
//memmove(qmfs->v + 128, qmfs->v, (1280-128)*sizeof(real_t));
/* calculate 128 samples */
#ifndef FIXED_POINT
pX = X[l];
in_imag1[31] = scale*QMF_RE(pX[1]);
in_real1[0] = scale*QMF_RE(pX[0]);
in_imag2[31] = scale*QMF_IM(pX[63-1]);
in_real2[0] = scale*QMF_IM(pX[63-0]);
for (k = 1; k < 31; k++)
{
in_imag1[31 - k] = scale*QMF_RE(pX[2*k + 1]);
in_real1[ k] = scale*QMF_RE(pX[2*k ]);
in_imag2[31 - k] = scale*QMF_IM(pX[63 - (2*k + 1)]);
in_real2[ k] = scale*QMF_IM(pX[63 - (2*k )]);
}
in_imag1[0] = scale*QMF_RE(pX[63]);
in_real1[31] = scale*QMF_RE(pX[62]);
in_imag2[0] = scale*QMF_IM(pX[63-63]);
in_real2[31] = scale*QMF_IM(pX[63-62]);
#else
pX = X[l];
in_imag1[31] = QMF_RE(pX[1]) >> 1;
in_real1[0] = QMF_RE(pX[0]) >> 1;
in_imag2[31] = QMF_IM(pX[62]) >> 1;
in_real2[0] = QMF_IM(pX[63]) >> 1;
for (k = 1; k < 31; k++)
{
in_imag1[31 - k] = QMF_RE(pX[2*k + 1]) >> 1;
in_real1[ k] = QMF_RE(pX[2*k ]) >> 1;
in_imag2[31 - k] = QMF_IM(pX[63 - (2*k + 1)]) >> 1;
in_real2[ k] = QMF_IM(pX[63 - (2*k )]) >> 1;
}
in_imag1[0] = QMF_RE(pX[63]) >> 1;
in_real1[31] = QMF_RE(pX[62]) >> 1;
in_imag2[0] = QMF_IM(pX[0]) >> 1;
in_real2[31] = QMF_IM(pX[1]) >> 1;
#endif
// dct4_kernel is DCT_IV without reordering which is done before and after FFT
dct4_kernel(in_real1, in_imag1, out_real1, out_imag1);
dct4_kernel(in_real2, in_imag2, out_real2, out_imag2);
pring_buffer_1 = qmfs->v + qmfs->v_index;
pring_buffer_3 = pring_buffer_1 + 1280;
#ifdef PREFER_POINTERS
pring_buffer_2 = pring_buffer_1 + 127;
pring_buffer_4 = pring_buffer_1 + (1280 + 127);
#endif // #ifdef PREFER_POINTERS
// ptemp_1 = x1;
// ptemp_2 = x2;
#ifdef PREFER_POINTERS
for (n = 0; n < 32; n ++)
{
//real_t x1 = *ptemp_1++;
//real_t x2 = *ptemp_2++;
// pring_buffer_3 and pring_buffer_4 are needed only for double ring buffer
*pring_buffer_1++ = *pring_buffer_3++ = out_real2[n] - out_real1[n];
*pring_buffer_2-- = *pring_buffer_4-- = out_real2[n] + out_real1[n];
//x1 = *ptemp_1++;
//x2 = *ptemp_2++;
*pring_buffer_1++ = *pring_buffer_3++ = out_imag2[31-n] + out_imag1[31-n];
*pring_buffer_2-- = *pring_buffer_4-- = out_imag2[31-n] - out_imag1[31-n];
}
#else // #ifdef PREFER_POINTERS
for (n = 0; n < 32; n++)
{
// pring_buffer_3 and pring_buffer_4 are needed only for double ring buffer
pring_buffer_1[2*n] = pring_buffer_3[2*n] = out_real2[n] - out_real1[n];
pring_buffer_1[127-2*n] = pring_buffer_3[127-2*n] = out_real2[n] + out_real1[n];
pring_buffer_1[2*n+1] = pring_buffer_3[2*n+1] = out_imag2[31-n] + out_imag1[31-n];
pring_buffer_1[127-(2*n+1)] = pring_buffer_3[127-(2*n+1)] = out_imag2[31-n] - out_imag1[31-n];
}
#endif // #ifdef PREFER_POINTERS
pring_buffer_1 = qmfs->v + qmfs->v_index;
#ifdef PREFER_POINTERS
pring_buffer_2 = pring_buffer_1 + 192;
pring_buffer_3 = pring_buffer_1 + 256;
pring_buffer_4 = pring_buffer_1 + (256 + 192);
pring_buffer_5 = pring_buffer_1 + 512;
pring_buffer_6 = pring_buffer_1 + (512 + 192);
pring_buffer_7 = pring_buffer_1 + 768;
pring_buffer_8 = pring_buffer_1 + (768 + 192);
pring_buffer_9 = pring_buffer_1 + 1024;
pring_buffer_10 = pring_buffer_1 + (1024 + 192);
pqmf_c_1 = qmf_c;
pqmf_c_2 = qmf_c + 64;
pqmf_c_3 = qmf_c + 128;
pqmf_c_4 = qmf_c + 192;
pqmf_c_5 = qmf_c + 256;
pqmf_c_6 = qmf_c + 320;
pqmf_c_7 = qmf_c + 384;
pqmf_c_8 = qmf_c + 448;
pqmf_c_9 = qmf_c + 512;
pqmf_c_10 = qmf_c + 576;
#endif // #ifdef PREFER_POINTERS
/* calculate 64 output samples and window */
for (k = 0; k < 64; k++)
{
#ifdef PREFER_POINTERS
output[out++] =
MUL_F(*pring_buffer_1++, *pqmf_c_1++) +
MUL_F(*pring_buffer_2++, *pqmf_c_2++) +
MUL_F(*pring_buffer_3++, *pqmf_c_3++) +
MUL_F(*pring_buffer_4++, *pqmf_c_4++) +
MUL_F(*pring_buffer_5++, *pqmf_c_5++) +
MUL_F(*pring_buffer_6++, *pqmf_c_6++) +
MUL_F(*pring_buffer_7++, *pqmf_c_7++) +
MUL_F(*pring_buffer_8++, *pqmf_c_8++) +
MUL_F(*pring_buffer_9++, *pqmf_c_9++) +
MUL_F(*pring_buffer_10++, *pqmf_c_10++);
#else // #ifdef PREFER_POINTERS
output[out++] =
MUL_F(pring_buffer_1[k+0], qmf_c[k+0]) +
MUL_F(pring_buffer_1[k+192], qmf_c[k+64]) +
MUL_F(pring_buffer_1[k+256], qmf_c[k+128]) +
MUL_F(pring_buffer_1[k+(256+192)], qmf_c[k+192]) +
MUL_F(pring_buffer_1[k+512], qmf_c[k+256]) +
MUL_F(pring_buffer_1[k+(512+192)], qmf_c[k+320]) +
MUL_F(pring_buffer_1[k+768], qmf_c[k+384]) +
MUL_F(pring_buffer_1[k+(768+192)], qmf_c[k+448]) +
MUL_F(pring_buffer_1[k+1024], qmf_c[k+512]) +
MUL_F(pring_buffer_1[k+(1024+192)], qmf_c[k+576]);
#endif // #ifdef PREFER_POINTERS
}
/* update ringbuffer index */
qmfs->v_index -= 128;
if (qmfs->v_index < 0)
qmfs->v_index = (1280 - 128);
}
}
#endif
#endif

View File

@ -0,0 +1,55 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: sbr_qmf.h,v 1.25 2007/11/01 12:33:36 menno Exp $
**/
#ifndef __SBR_QMF_H__
#define __SBR_QMF_H__
#ifdef __cplusplus
extern "C" {
#endif
qmfa_info *qmfa_init(uint8_t channels);
void qmfa_end(qmfa_info *qmfa);
qmfs_info *qmfs_init(uint8_t channels);
void qmfs_end(qmfs_info *qmfs);
void sbr_qmf_analysis_32(sbr_info *sbr, qmfa_info *qmfa, const real_t *input,
qmf_t X[MAX_NTSRHFG][64], uint8_t offset, uint8_t kx);
void sbr_qmf_synthesis_32(sbr_info *sbr, qmfs_info *qmfs, qmf_t X[MAX_NTSRHFG][64],
real_t *output);
void sbr_qmf_synthesis_64(sbr_info *sbr, qmfs_info *qmfs, qmf_t X[MAX_NTSRHFG][64],
real_t *output);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,368 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: sbr_qmf_c.h,v 1.17 2007/11/01 12:33:36 menno Exp $
**/
#ifndef __SBR_QMF_C_H__
#define __SBR_QMF_C_H__
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _MSC_VER
#pragma warning(disable:4305)
#pragma warning(disable:4244)
#endif
ALIGN static const real_t qmf_c[640] = {
FRAC_CONST(0), FRAC_CONST(-0.00055252865047),
FRAC_CONST(-0.00056176925738), FRAC_CONST(-0.00049475180896),
FRAC_CONST(-0.00048752279712), FRAC_CONST(-0.00048937912498),
FRAC_CONST(-0.00050407143497), FRAC_CONST(-0.00052265642972),
FRAC_CONST(-0.00054665656337), FRAC_CONST(-0.00056778025613),
FRAC_CONST(-0.00058709304852), FRAC_CONST(-0.00061327473938),
FRAC_CONST(-0.00063124935319), FRAC_CONST(-0.00065403333621),
FRAC_CONST(-0.00067776907764), FRAC_CONST(-0.00069416146273),
FRAC_CONST(-0.00071577364744), FRAC_CONST(-0.00072550431222),
FRAC_CONST(-0.00074409418541), FRAC_CONST(-0.00074905980532),
FRAC_CONST(-0.0007681371927), FRAC_CONST(-0.00077248485949),
FRAC_CONST(-0.00078343322877), FRAC_CONST(-0.00077798694927),
FRAC_CONST(-0.000780366471), FRAC_CONST(-0.00078014496257),
FRAC_CONST(-0.0007757977331), FRAC_CONST(-0.00076307935757),
FRAC_CONST(-0.00075300014201), FRAC_CONST(-0.00073193571525),
FRAC_CONST(-0.00072153919876), FRAC_CONST(-0.00069179375372),
FRAC_CONST(-0.00066504150893), FRAC_CONST(-0.00063415949025),
FRAC_CONST(-0.0005946118933), FRAC_CONST(-0.00055645763906),
FRAC_CONST(-0.00051455722108), FRAC_CONST(-0.00046063254803),
FRAC_CONST(-0.00040951214522), FRAC_CONST(-0.00035011758756),
FRAC_CONST(-0.00028969811748), FRAC_CONST(-0.0002098337344),
FRAC_CONST(-0.00014463809349), FRAC_CONST(-6.173344072E-005),
FRAC_CONST(1.349497418E-005), FRAC_CONST(0.00010943831274),
FRAC_CONST(0.00020430170688), FRAC_CONST(0.00029495311041),
FRAC_CONST(0.0004026540216), FRAC_CONST(0.00051073884952),
FRAC_CONST(0.00062393761391), FRAC_CONST(0.00074580258865),
FRAC_CONST(0.00086084433262), FRAC_CONST(0.00098859883015),
FRAC_CONST(0.00112501551307), FRAC_CONST(0.00125778846475),
FRAC_CONST(0.00139024948272), FRAC_CONST(0.00154432198471),
FRAC_CONST(0.00168680832531), FRAC_CONST(0.00183482654224),
FRAC_CONST(0.00198411407369), FRAC_CONST(0.00214615835557),
FRAC_CONST(0.00230172547746), FRAC_CONST(0.00246256169126),
FRAC_CONST(0.00262017586902), FRAC_CONST(0.00278704643465),
FRAC_CONST(0.00294694477165), FRAC_CONST(0.00311254206525),
FRAC_CONST(0.00327396134847), FRAC_CONST(0.00344188741828),
FRAC_CONST(0.00360082681231), FRAC_CONST(0.00376039229104),
FRAC_CONST(0.00392074323703), FRAC_CONST(0.00408197531935),
FRAC_CONST(0.0042264269227), FRAC_CONST(0.00437307196781),
FRAC_CONST(0.00452098527825), FRAC_CONST(0.00466064606118),
FRAC_CONST(0.00479325608498), FRAC_CONST(0.00491376035745),
FRAC_CONST(0.00503930226013), FRAC_CONST(0.00514073539032),
FRAC_CONST(0.00524611661324), FRAC_CONST(0.00534716811982),
FRAC_CONST(0.00541967759307), FRAC_CONST(0.00548760401507),
FRAC_CONST(0.00554757145088), FRAC_CONST(0.00559380230045),
FRAC_CONST(0.00562206432097), FRAC_CONST(0.00564551969164),
FRAC_CONST(0.00563891995151), FRAC_CONST(0.00562661141932),
FRAC_CONST(0.0055917128663), FRAC_CONST(0.005540436394),
FRAC_CONST(0.0054753783077), FRAC_CONST(0.0053838975897),
FRAC_CONST(0.00527157587272), FRAC_CONST(0.00513822754514),
FRAC_CONST(0.00498396877629), FRAC_CONST(0.004810946906),
FRAC_CONST(0.00460395301471), FRAC_CONST(0.00438018617447),
FRAC_CONST(0.0041251642327), FRAC_CONST(0.00384564081246),
FRAC_CONST(0.00354012465507), FRAC_CONST(0.00320918858098),
FRAC_CONST(0.00284467578623), FRAC_CONST(0.00245085400321),
FRAC_CONST(0.0020274176185), FRAC_CONST(0.00157846825768),
FRAC_CONST(0.00109023290512), FRAC_CONST(0.0005832264248),
FRAC_CONST(2.760451905E-005), FRAC_CONST(-0.00054642808664),
FRAC_CONST(-0.00115681355227), FRAC_CONST(-0.00180394725893),
FRAC_CONST(-0.00248267236449), FRAC_CONST(-0.003193377839),
FRAC_CONST(-0.00394011240522), FRAC_CONST(-0.004722259624),
FRAC_CONST(-0.00553372111088), FRAC_CONST(-0.00637922932685),
FRAC_CONST(-0.00726158168517), FRAC_CONST(-0.00817982333726),
FRAC_CONST(-0.00913253296085), FRAC_CONST(-0.01011502154986),
FRAC_CONST(-0.01113155480321), FRAC_CONST(-0.01218499959508),
FRAC_CONST(0.01327182200351), FRAC_CONST(0.01439046660792),
FRAC_CONST(0.01554055533423), FRAC_CONST(0.01673247129989),
FRAC_CONST(0.01794333813443), FRAC_CONST(0.01918724313698),
FRAC_CONST(0.02045317933555), FRAC_CONST(0.02174675502535),
FRAC_CONST(0.02306801692862), FRAC_CONST(0.02441609920285),
FRAC_CONST(0.02578758475467), FRAC_CONST(0.02718594296329),
FRAC_CONST(0.02860721736385), FRAC_CONST(0.03005026574279),
FRAC_CONST(0.03150176087389), FRAC_CONST(0.03297540810337),
FRAC_CONST(0.03446209487686), FRAC_CONST(0.03596975605542),
FRAC_CONST(0.03748128504252), FRAC_CONST(0.03900536794745),
FRAC_CONST(0.04053491705584), FRAC_CONST(0.04206490946367),
FRAC_CONST(0.04360975421304), FRAC_CONST(0.04514884056413),
FRAC_CONST(0.04668430272642), FRAC_CONST(0.04821657200672),
FRAC_CONST(0.04973857556014), FRAC_CONST(0.05125561555216),
FRAC_CONST(0.05276307465207), FRAC_CONST(0.05424527683589),
FRAC_CONST(0.05571736482138), FRAC_CONST(0.05716164501299),
FRAC_CONST(0.0585915683626), FRAC_CONST(0.05998374801761),
FRAC_CONST(0.06134551717207), FRAC_CONST(0.06268578081172),
FRAC_CONST(0.06397158980681), FRAC_CONST(0.0652247106438),
FRAC_CONST(0.06643675122104), FRAC_CONST(0.06760759851228),
FRAC_CONST(0.06870438283512), FRAC_CONST(0.06976302447127),
FRAC_CONST(0.07076287107266), FRAC_CONST(0.07170026731102),
FRAC_CONST(0.07256825833083), FRAC_CONST(0.07336202550803),
FRAC_CONST(0.07410036424342), FRAC_CONST(0.07474525581194),
FRAC_CONST(0.07531373362019), FRAC_CONST(0.07580083586584),
FRAC_CONST(0.07619924793396), FRAC_CONST(0.07649921704119),
FRAC_CONST(0.07670934904245), FRAC_CONST(0.07681739756964),
FRAC_CONST(0.07682300113923), FRAC_CONST(0.07672049241746),
FRAC_CONST(0.07650507183194), FRAC_CONST(0.07617483218536),
FRAC_CONST(0.07573057565061), FRAC_CONST(0.0751576255287),
FRAC_CONST(0.07446643947564), FRAC_CONST(0.0736406005762),
FRAC_CONST(0.07267746427299), FRAC_CONST(0.07158263647903),
FRAC_CONST(0.07035330735093), FRAC_CONST(0.06896640131951),
FRAC_CONST(0.06745250215166), FRAC_CONST(0.06576906686508),
FRAC_CONST(0.06394448059633), FRAC_CONST(0.06196027790387),
FRAC_CONST(0.0598166570809), FRAC_CONST(0.05751526919867),
FRAC_CONST(0.05504600343009), FRAC_CONST(0.05240938217366),
FRAC_CONST(0.04959786763445), FRAC_CONST(0.04663033051701),
FRAC_CONST(0.04347687821958), FRAC_CONST(0.04014582784127),
FRAC_CONST(0.03664181168133), FRAC_CONST(0.03295839306691),
FRAC_CONST(0.02908240060125), FRAC_CONST(0.02503075618909),
FRAC_CONST(0.02079970728622), FRAC_CONST(0.01637012582228),
FRAC_CONST(0.01176238327857), FRAC_CONST(0.00696368621617),
FRAC_CONST(0.00197656014503), FRAC_CONST(-0.00320868968304),
FRAC_CONST(-0.00857117491366), FRAC_CONST(-0.01412888273558),
FRAC_CONST(-0.01988341292573), FRAC_CONST(-0.02582272888064),
FRAC_CONST(-0.03195312745332), FRAC_CONST(-0.03827765720822),
FRAC_CONST(-0.04478068215856), FRAC_CONST(-0.05148041767934),
FRAC_CONST(-0.05837053268336), FRAC_CONST(-0.06544098531359),
FRAC_CONST(-0.07269433008129), FRAC_CONST(-0.08013729344279),
FRAC_CONST(-0.08775475365593), FRAC_CONST(-0.09555333528914),
FRAC_CONST(-0.10353295311463), FRAC_CONST(-0.1116826931773),
FRAC_CONST(-0.120007798468), FRAC_CONST(-0.12850028503878),
FRAC_CONST(-0.13715517611934), FRAC_CONST(-0.1459766491187),
FRAC_CONST(-0.15496070710605), FRAC_CONST(-0.16409588556669),
FRAC_CONST(-0.17338081721706), FRAC_CONST(-0.18281725485142),
FRAC_CONST(-0.19239667457267), FRAC_CONST(-0.20212501768103),
FRAC_CONST(-0.21197358538056), FRAC_CONST(-0.22196526964149),
FRAC_CONST(-0.23206908706791), FRAC_CONST(-0.24230168845974),
FRAC_CONST(-0.25264803095722), FRAC_CONST(-0.26310532994603),
FRAC_CONST(-0.27366340405625), FRAC_CONST(-0.28432141891085),
FRAC_CONST(-0.29507167170646), FRAC_CONST(-0.30590985751916),
FRAC_CONST(-0.31682789136456), FRAC_CONST(-0.32781137272105),
FRAC_CONST(-0.33887226938665), FRAC_CONST(-0.3499914122931),
FRAC_CONST(0.36115899031355), FRAC_CONST(0.37237955463061),
FRAC_CONST(0.38363500139043), FRAC_CONST(0.39492117615675),
FRAC_CONST(0.40623176767625), FRAC_CONST(0.41756968968409),
FRAC_CONST(0.42891199207373), FRAC_CONST(0.44025537543665),
FRAC_CONST(0.45159965356824), FRAC_CONST(0.46293080852757),
FRAC_CONST(0.47424532146115), FRAC_CONST(0.48552530911099),
FRAC_CONST(0.49677082545707), FRAC_CONST(0.50798175000434),
FRAC_CONST(0.51912349702391), FRAC_CONST(0.53022408956855),
FRAC_CONST(0.54125534487322), FRAC_CONST(0.55220512585061),
FRAC_CONST(0.5630789140137), FRAC_CONST(0.57385241316923),
FRAC_CONST(0.58454032354679), FRAC_CONST(0.59511230862496),
FRAC_CONST(0.6055783538918), FRAC_CONST(0.61591099320291),
FRAC_CONST(0.62612426956055), FRAC_CONST(0.63619801077286),
FRAC_CONST(0.64612696959461), FRAC_CONST(0.65590163024671),
FRAC_CONST(0.66551398801627), FRAC_CONST(0.67496631901712),
FRAC_CONST(0.68423532934598), FRAC_CONST(0.69332823767032),
FRAC_CONST(0.70223887193539), FRAC_CONST(0.71094104263095),
FRAC_CONST(0.71944626349561), FRAC_CONST(0.72774489002994),
FRAC_CONST(0.73582117582769), FRAC_CONST(0.74368278636488),
FRAC_CONST(0.75131374561237), FRAC_CONST(0.75870807608242),
FRAC_CONST(0.76586748650939), FRAC_CONST(0.77277808813327),
FRAC_CONST(0.77942875190216), FRAC_CONST(0.7858353120392),
FRAC_CONST(0.79197358416424), FRAC_CONST(0.797846641377),
FRAC_CONST(0.80344857518505), FRAC_CONST(0.80876950044491),
FRAC_CONST(0.81381912706217), FRAC_CONST(0.81857760046468),
FRAC_CONST(0.82304198905409), FRAC_CONST(0.8272275347336),
FRAC_CONST(0.8311038457152), FRAC_CONST(0.83469373618402),
FRAC_CONST(0.83797173378865), FRAC_CONST(0.84095413924722),
FRAC_CONST(0.84362382812005), FRAC_CONST(0.84598184698206),
FRAC_CONST(0.84803157770763), FRAC_CONST(0.84978051984268),
FRAC_CONST(0.85119715249343), FRAC_CONST(0.85230470352147),
FRAC_CONST(0.85310209497017), FRAC_CONST(0.85357205739107),
FRAC_CONST(0.85373856005937 /*max*/), FRAC_CONST(0.85357205739107),
FRAC_CONST(0.85310209497017), FRAC_CONST(0.85230470352147),
FRAC_CONST(0.85119715249343), FRAC_CONST(0.84978051984268),
FRAC_CONST(0.84803157770763), FRAC_CONST(0.84598184698206),
FRAC_CONST(0.84362382812005), FRAC_CONST(0.84095413924722),
FRAC_CONST(0.83797173378865), FRAC_CONST(0.83469373618402),
FRAC_CONST(0.8311038457152), FRAC_CONST(0.8272275347336),
FRAC_CONST(0.82304198905409), FRAC_CONST(0.81857760046468),
FRAC_CONST(0.81381912706217), FRAC_CONST(0.80876950044491),
FRAC_CONST(0.80344857518505), FRAC_CONST(0.797846641377),
FRAC_CONST(0.79197358416424), FRAC_CONST(0.7858353120392),
FRAC_CONST(0.77942875190216), FRAC_CONST(0.77277808813327),
FRAC_CONST(0.76586748650939), FRAC_CONST(0.75870807608242),
FRAC_CONST(0.75131374561237), FRAC_CONST(0.74368278636488),
FRAC_CONST(0.73582117582769), FRAC_CONST(0.72774489002994),
FRAC_CONST(0.71944626349561), FRAC_CONST(0.71094104263095),
FRAC_CONST(0.70223887193539), FRAC_CONST(0.69332823767032),
FRAC_CONST(0.68423532934598), FRAC_CONST(0.67496631901712),
FRAC_CONST(0.66551398801627), FRAC_CONST(0.65590163024671),
FRAC_CONST(0.64612696959461), FRAC_CONST(0.63619801077286),
FRAC_CONST(0.62612426956055), FRAC_CONST(0.61591099320291),
FRAC_CONST(0.6055783538918), FRAC_CONST(0.59511230862496),
FRAC_CONST(0.58454032354679), FRAC_CONST(0.57385241316923),
FRAC_CONST(0.5630789140137), FRAC_CONST(0.55220512585061),
FRAC_CONST(0.54125534487322), FRAC_CONST(0.53022408956855),
FRAC_CONST(0.51912349702391), FRAC_CONST(0.50798175000434),
FRAC_CONST(0.49677082545707), FRAC_CONST(0.48552530911099),
FRAC_CONST(0.47424532146115), FRAC_CONST(0.46293080852757),
FRAC_CONST(0.45159965356824), FRAC_CONST(0.44025537543665),
FRAC_CONST(0.42891199207373), FRAC_CONST(0.41756968968409),
FRAC_CONST(0.40623176767625), FRAC_CONST(0.39492117615675),
FRAC_CONST(0.38363500139043), FRAC_CONST(0.37237955463061),
FRAC_CONST(-0.36115899031355), FRAC_CONST(-0.3499914122931),
FRAC_CONST(-0.33887226938665), FRAC_CONST(-0.32781137272105),
FRAC_CONST(-0.31682789136456), FRAC_CONST(-0.30590985751916),
FRAC_CONST(-0.29507167170646), FRAC_CONST(-0.28432141891085),
FRAC_CONST(-0.27366340405625), FRAC_CONST(-0.26310532994603),
FRAC_CONST(-0.25264803095722), FRAC_CONST(-0.24230168845974),
FRAC_CONST(-0.23206908706791), FRAC_CONST(-0.22196526964149),
FRAC_CONST(-0.21197358538056), FRAC_CONST(-0.20212501768103),
FRAC_CONST(-0.19239667457267), FRAC_CONST(-0.18281725485142),
FRAC_CONST(-0.17338081721706), FRAC_CONST(-0.16409588556669),
FRAC_CONST(-0.15496070710605), FRAC_CONST(-0.1459766491187),
FRAC_CONST(-0.13715517611934), FRAC_CONST(-0.12850028503878),
FRAC_CONST(-0.120007798468), FRAC_CONST(-0.1116826931773),
FRAC_CONST(-0.10353295311463), FRAC_CONST(-0.09555333528914),
FRAC_CONST(-0.08775475365593), FRAC_CONST(-0.08013729344279),
FRAC_CONST(-0.07269433008129), FRAC_CONST(-0.06544098531359),
FRAC_CONST(-0.05837053268336), FRAC_CONST(-0.05148041767934),
FRAC_CONST(-0.04478068215856), FRAC_CONST(-0.03827765720822),
FRAC_CONST(-0.03195312745332), FRAC_CONST(-0.02582272888064),
FRAC_CONST(-0.01988341292573), FRAC_CONST(-0.01412888273558),
FRAC_CONST(-0.00857117491366), FRAC_CONST(-0.00320868968304),
FRAC_CONST(0.00197656014503), FRAC_CONST(0.00696368621617),
FRAC_CONST(0.01176238327857), FRAC_CONST(0.01637012582228),
FRAC_CONST(0.02079970728622), FRAC_CONST(0.02503075618909),
FRAC_CONST(0.02908240060125), FRAC_CONST(0.03295839306691),
FRAC_CONST(0.03664181168133), FRAC_CONST(0.04014582784127),
FRAC_CONST(0.04347687821958), FRAC_CONST(0.04663033051701),
FRAC_CONST(0.04959786763445), FRAC_CONST(0.05240938217366),
FRAC_CONST(0.05504600343009), FRAC_CONST(0.05751526919867),
FRAC_CONST(0.0598166570809), FRAC_CONST(0.06196027790387),
FRAC_CONST(0.06394448059633), FRAC_CONST(0.06576906686508),
FRAC_CONST(0.06745250215166), FRAC_CONST(0.06896640131951),
FRAC_CONST(0.07035330735093), FRAC_CONST(0.07158263647903),
FRAC_CONST(0.07267746427299), FRAC_CONST(0.0736406005762),
FRAC_CONST(0.07446643947564), FRAC_CONST(0.0751576255287),
FRAC_CONST(0.07573057565061), FRAC_CONST(0.07617483218536),
FRAC_CONST(0.07650507183194), FRAC_CONST(0.07672049241746),
FRAC_CONST(0.07682300113923), FRAC_CONST(0.07681739756964),
FRAC_CONST(0.07670934904245), FRAC_CONST(0.07649921704119),
FRAC_CONST(0.07619924793396), FRAC_CONST(0.07580083586584),
FRAC_CONST(0.07531373362019), FRAC_CONST(0.07474525581194),
FRAC_CONST(0.07410036424342), FRAC_CONST(0.07336202550803),
FRAC_CONST(0.07256825833083), FRAC_CONST(0.07170026731102),
FRAC_CONST(0.07076287107266), FRAC_CONST(0.06976302447127),
FRAC_CONST(0.06870438283512), FRAC_CONST(0.06760759851228),
FRAC_CONST(0.06643675122104), FRAC_CONST(0.0652247106438),
FRAC_CONST(0.06397158980681), FRAC_CONST(0.06268578081172),
FRAC_CONST(0.06134551717207), FRAC_CONST(0.05998374801761),
FRAC_CONST(0.0585915683626), FRAC_CONST(0.05716164501299),
FRAC_CONST(0.05571736482138), FRAC_CONST(0.05424527683589),
FRAC_CONST(0.05276307465207), FRAC_CONST(0.05125561555216),
FRAC_CONST(0.04973857556014), FRAC_CONST(0.04821657200672),
FRAC_CONST(0.04668430272642), FRAC_CONST(0.04514884056413),
FRAC_CONST(0.04360975421304), FRAC_CONST(0.04206490946367),
FRAC_CONST(0.04053491705584), FRAC_CONST(0.03900536794745),
FRAC_CONST(0.03748128504252), FRAC_CONST(0.03596975605542),
FRAC_CONST(0.03446209487686), FRAC_CONST(0.03297540810337),
FRAC_CONST(0.03150176087389), FRAC_CONST(0.03005026574279),
FRAC_CONST(0.02860721736385), FRAC_CONST(0.02718594296329),
FRAC_CONST(0.02578758475467), FRAC_CONST(0.02441609920285),
FRAC_CONST(0.02306801692862), FRAC_CONST(0.02174675502535),
FRAC_CONST(0.02045317933555), FRAC_CONST(0.01918724313698),
FRAC_CONST(0.01794333813443), FRAC_CONST(0.01673247129989),
FRAC_CONST(0.01554055533423), FRAC_CONST(0.01439046660792),
FRAC_CONST(-0.01327182200351), FRAC_CONST(-0.01218499959508),
FRAC_CONST(-0.01113155480321), FRAC_CONST(-0.01011502154986),
FRAC_CONST(-0.00913253296085), FRAC_CONST(-0.00817982333726),
FRAC_CONST(-0.00726158168517), FRAC_CONST(-0.00637922932685),
FRAC_CONST(-0.00553372111088), FRAC_CONST(-0.004722259624),
FRAC_CONST(-0.00394011240522), FRAC_CONST(-0.003193377839),
FRAC_CONST(-0.00248267236449), FRAC_CONST(-0.00180394725893),
FRAC_CONST(-0.00115681355227), FRAC_CONST(-0.00054642808664),
FRAC_CONST(2.760451905E-005), FRAC_CONST(0.0005832264248),
FRAC_CONST(0.00109023290512), FRAC_CONST(0.00157846825768),
FRAC_CONST(0.0020274176185), FRAC_CONST(0.00245085400321),
FRAC_CONST(0.00284467578623), FRAC_CONST(0.00320918858098),
FRAC_CONST(0.00354012465507), FRAC_CONST(0.00384564081246),
FRAC_CONST(0.0041251642327), FRAC_CONST(0.00438018617447),
FRAC_CONST(0.00460395301471), FRAC_CONST(0.004810946906),
FRAC_CONST(0.00498396877629), FRAC_CONST(0.00513822754514),
FRAC_CONST(0.00527157587272), FRAC_CONST(0.0053838975897),
FRAC_CONST(0.0054753783077), FRAC_CONST(0.005540436394),
FRAC_CONST(0.0055917128663), FRAC_CONST(0.00562661141932),
FRAC_CONST(0.00563891995151), FRAC_CONST(0.00564551969164),
FRAC_CONST(0.00562206432097), FRAC_CONST(0.00559380230045),
FRAC_CONST(0.00554757145088), FRAC_CONST(0.00548760401507),
FRAC_CONST(0.00541967759307), FRAC_CONST(0.00534716811982),
FRAC_CONST(0.00524611661324), FRAC_CONST(0.00514073539032),
FRAC_CONST(0.00503930226013), FRAC_CONST(0.00491376035745),
FRAC_CONST(0.00479325608498), FRAC_CONST(0.00466064606118),
FRAC_CONST(0.00452098527825), FRAC_CONST(0.00437307196781),
FRAC_CONST(0.0042264269227), FRAC_CONST(0.00408197531935),
FRAC_CONST(0.00392074323703), FRAC_CONST(0.00376039229104),
FRAC_CONST(0.00360082681231), FRAC_CONST(0.00344188741828),
FRAC_CONST(0.00327396134847), FRAC_CONST(0.00311254206525),
FRAC_CONST(0.00294694477165), FRAC_CONST(0.00278704643465),
FRAC_CONST(0.00262017586902), FRAC_CONST(0.00246256169126),
FRAC_CONST(0.00230172547746), FRAC_CONST(0.00214615835557),
FRAC_CONST(0.00198411407369), FRAC_CONST(0.00183482654224),
FRAC_CONST(0.00168680832531), FRAC_CONST(0.00154432198471),
FRAC_CONST(0.00139024948272), FRAC_CONST(0.00125778846475),
FRAC_CONST(0.00112501551307), FRAC_CONST(0.00098859883015),
FRAC_CONST(0.00086084433262), FRAC_CONST(0.00074580258865),
FRAC_CONST(0.00062393761391), FRAC_CONST(0.00051073884952),
FRAC_CONST(0.0004026540216), FRAC_CONST(0.00029495311041),
FRAC_CONST(0.00020430170688), FRAC_CONST(0.00010943831274),
FRAC_CONST(1.349497418E-005), FRAC_CONST(-6.173344072E-005),
FRAC_CONST(-0.00014463809349), FRAC_CONST(-0.0002098337344),
FRAC_CONST(-0.00028969811748), FRAC_CONST(-0.00035011758756),
FRAC_CONST(-0.00040951214522), FRAC_CONST(-0.00046063254803),
FRAC_CONST(-0.00051455722108), FRAC_CONST(-0.00055645763906),
FRAC_CONST(-0.0005946118933), FRAC_CONST(-0.00063415949025),
FRAC_CONST(-0.00066504150893), FRAC_CONST(-0.00069179375372),
FRAC_CONST(-0.00072153919876), FRAC_CONST(-0.00073193571525),
FRAC_CONST(-0.00075300014201), FRAC_CONST(-0.00076307935757),
FRAC_CONST(-0.0007757977331), FRAC_CONST(-0.00078014496257),
FRAC_CONST(-0.000780366471), FRAC_CONST(-0.00077798694927),
FRAC_CONST(-0.00078343322877), FRAC_CONST(-0.00077248485949),
FRAC_CONST(-0.0007681371927), FRAC_CONST(-0.00074905980532),
FRAC_CONST(-0.00074409418541), FRAC_CONST(-0.00072550431222),
FRAC_CONST(-0.00071577364744), FRAC_CONST(-0.00069416146273),
FRAC_CONST(-0.00067776907764), FRAC_CONST(-0.00065403333621),
FRAC_CONST(-0.00063124935319), FRAC_CONST(-0.00061327473938),
FRAC_CONST(-0.00058709304852), FRAC_CONST(-0.00056778025613),
FRAC_CONST(-0.00054665656337), FRAC_CONST(-0.00052265642972),
FRAC_CONST(-0.00050407143497), FRAC_CONST(-0.00048937912498),
FRAC_CONST(-0.00048752279712), FRAC_CONST(-0.00049475180896),
FRAC_CONST(-0.00056176925738), FRAC_CONST(-0.00055252865047)
};
#endif

View File

@ -0,0 +1,910 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: sbr_syntax.c,v 1.39 2009/01/26 22:32:31 menno Exp $
**/
#include "common.h"
#include "structs.h"
#ifdef SBR_DEC
#include "sbr_syntax.h"
#include "syntax.h"
#include "sbr_huff.h"
#include "sbr_fbt.h"
#include "sbr_tf_grid.h"
#include "sbr_e_nf.h"
#include "bits.h"
#ifdef PS_DEC
#include "ps_dec.h"
#endif
#ifdef DRM_PS
#include "drm_dec.h"
#endif
#include "analysis.h"
/* static function declarations */
/* static function declarations */
static void sbr_header(bitfile *ld, sbr_info *sbr);
static uint8_t calc_sbr_tables(sbr_info *sbr, uint8_t start_freq, uint8_t stop_freq,
uint8_t samplerate_mode, uint8_t freq_scale,
uint8_t alter_scale, uint8_t xover_band);
static uint8_t sbr_data(bitfile *ld, sbr_info *sbr);
static uint16_t sbr_extension(bitfile *ld, sbr_info *sbr,
uint8_t bs_extension_id, uint16_t num_bits_left);
static uint8_t sbr_single_channel_element(bitfile *ld, sbr_info *sbr);
static uint8_t sbr_channel_pair_element(bitfile *ld, sbr_info *sbr);
static uint8_t sbr_grid(bitfile *ld, sbr_info *sbr, uint8_t ch);
static void sbr_dtdf(bitfile *ld, sbr_info *sbr, uint8_t ch);
static void invf_mode(bitfile *ld, sbr_info *sbr, uint8_t ch);
static void sinusoidal_coding(bitfile *ld, sbr_info *sbr, uint8_t ch);
static void sbr_reset(sbr_info *sbr)
{
#if 0
printf("%d\n", sbr->bs_start_freq_prev);
printf("%d\n", sbr->bs_stop_freq_prev);
printf("%d\n", sbr->bs_freq_scale_prev);
printf("%d\n", sbr->bs_alter_scale_prev);
printf("%d\n", sbr->bs_xover_band_prev);
printf("%d\n\n", sbr->bs_noise_bands_prev);
#endif
/* if these are different from the previous frame: Reset = 1 */
if ((sbr->bs_start_freq != sbr->bs_start_freq_prev) ||
(sbr->bs_stop_freq != sbr->bs_stop_freq_prev) ||
(sbr->bs_freq_scale != sbr->bs_freq_scale_prev) ||
(sbr->bs_alter_scale != sbr->bs_alter_scale_prev) ||
(sbr->bs_xover_band != sbr->bs_xover_band_prev) ||
(sbr->bs_noise_bands != sbr->bs_noise_bands_prev))
{
sbr->Reset = 1;
} else {
sbr->Reset = 0;
}
sbr->bs_start_freq_prev = sbr->bs_start_freq;
sbr->bs_stop_freq_prev = sbr->bs_stop_freq;
sbr->bs_freq_scale_prev = sbr->bs_freq_scale;
sbr->bs_alter_scale_prev = sbr->bs_alter_scale;
sbr->bs_xover_band_prev = sbr->bs_xover_band;
sbr->bs_noise_bands_prev = sbr->bs_noise_bands;
}
static uint8_t calc_sbr_tables(sbr_info *sbr, uint8_t start_freq, uint8_t stop_freq,
uint8_t samplerate_mode, uint8_t freq_scale,
uint8_t alter_scale, uint8_t xover_band)
{
uint8_t result = 0;
uint8_t k2;
/* calculate the Master Frequency Table */
sbr->k0 = qmf_start_channel(start_freq, samplerate_mode, sbr->sample_rate);
k2 = qmf_stop_channel(stop_freq, sbr->sample_rate, sbr->k0);
/* check k0 and k2 */
if (sbr->sample_rate >= 48000)
{
if ((k2 - sbr->k0) > 32)
result += 1;
} else if (sbr->sample_rate <= 32000) {
if ((k2 - sbr->k0) > 48)
result += 1;
} else { /* (sbr->sample_rate == 44100) */
if ((k2 - sbr->k0) > 45)
result += 1;
}
if (freq_scale == 0)
{
result += master_frequency_table_fs0(sbr, sbr->k0, k2, alter_scale);
} else {
result += master_frequency_table(sbr, sbr->k0, k2, freq_scale, alter_scale);
}
result += derived_frequency_table(sbr, xover_band, k2);
result = (result > 0) ? 1 : 0;
return result;
}
/* table 2 */
uint8_t sbr_extension_data(bitfile *ld, sbr_info *sbr, uint16_t cnt,
uint8_t psResetFlag)
{
uint8_t result = 0;
uint16_t num_align_bits = 0;
uint16_t num_sbr_bits1 = (uint16_t)faad_get_processed_bits(ld);
uint16_t num_sbr_bits2;
uint8_t saved_start_freq, saved_samplerate_mode;
uint8_t saved_stop_freq, saved_freq_scale;
uint8_t saved_alter_scale, saved_xover_band;
#if (defined(PS_DEC) || defined(DRM_PS))
if (psResetFlag)
sbr->psResetFlag = psResetFlag;
#endif
#ifdef DRM
if (!sbr->Is_DRM_SBR)
#endif
{
uint8_t bs_extension_type = (uint8_t)faad_getbits(ld, 4
DEBUGVAR(1,198,"sbr_bitstream(): bs_extension_type"));
if (bs_extension_type == EXT_SBR_DATA_CRC)
{
sbr->bs_sbr_crc_bits = (uint16_t)faad_getbits(ld, 10
DEBUGVAR(1,199,"sbr_bitstream(): bs_sbr_crc_bits"));
}
}
/* save old header values, in case the new ones are corrupted */
saved_start_freq = sbr->bs_start_freq;
saved_samplerate_mode = sbr->bs_samplerate_mode;
saved_stop_freq = sbr->bs_stop_freq;
saved_freq_scale = sbr->bs_freq_scale;
saved_alter_scale = sbr->bs_alter_scale;
saved_xover_band = sbr->bs_xover_band;
sbr->bs_header_flag = faad_get1bit(ld
DEBUGVAR(1,200,"sbr_bitstream(): bs_header_flag"));
if (sbr->bs_header_flag)
sbr_header(ld, sbr);
/* Reset? */
sbr_reset(sbr);
/* first frame should have a header */
//if (!(sbr->frame == 0 && sbr->bs_header_flag == 0))
if (sbr->header_count != 0)
{
if (sbr->Reset || (sbr->bs_header_flag && sbr->just_seeked))
{
uint8_t rt = calc_sbr_tables(sbr, sbr->bs_start_freq, sbr->bs_stop_freq,
sbr->bs_samplerate_mode, sbr->bs_freq_scale,
sbr->bs_alter_scale, sbr->bs_xover_band);
/* if an error occured with the new header values revert to the old ones */
if (rt > 0)
{
calc_sbr_tables(sbr, saved_start_freq, saved_stop_freq,
saved_samplerate_mode, saved_freq_scale,
saved_alter_scale, saved_xover_band);
}
}
if (result == 0)
{
result = sbr_data(ld, sbr);
/* sbr_data() returning an error means that there was an error in
envelope_time_border_vector().
In this case the old time border vector is saved and all the previous
data normally read after sbr_grid() is saved.
*/
/* to be on the safe side, calculate old sbr tables in case of error */
if ((result > 0) &&
(sbr->Reset || (sbr->bs_header_flag && sbr->just_seeked)))
{
calc_sbr_tables(sbr, saved_start_freq, saved_stop_freq,
saved_samplerate_mode, saved_freq_scale,
saved_alter_scale, saved_xover_band);
}
/* we should be able to safely set result to 0 now, */
/* but practise indicates this doesn't work well */
}
} else {
result = 1;
}
num_sbr_bits2 = (uint16_t)faad_get_processed_bits(ld) - num_sbr_bits1;
/* check if we read more bits then were available for sbr */
if (8*cnt < num_sbr_bits2)
{
faad_resetbits(ld, num_sbr_bits1 + 8*cnt);
num_sbr_bits2 = 8*cnt;
#ifdef PS_DEC
/* turn off PS for the unfortunate case that we randomly read some
* PS data that looks correct */
sbr->ps_used = 0;
#endif
/* Make sure it doesn't decode SBR in this frame, or we'll get glitches */
return 1;
}
#ifdef DRM
if (!sbr->Is_DRM_SBR)
#endif
{
/* -4 does not apply, bs_extension_type is re-read in this function */
num_align_bits = 8*cnt /*- 4*/ - num_sbr_bits2;
while (num_align_bits > 7)
{
faad_getbits(ld, 8
DEBUGVAR(1,999,"sbr_bitstream(): num_align_bits"));
num_align_bits -= 8;
}
faad_getbits(ld, num_align_bits
DEBUGVAR(1,999,"sbr_bitstream(): num_align_bits"));
}
return result;
}
/* table 3 */
static void sbr_header(bitfile *ld, sbr_info *sbr)
{
uint8_t bs_header_extra_1, bs_header_extra_2;
sbr->header_count++;
sbr->bs_amp_res = faad_get1bit(ld
DEBUGVAR(1,203,"sbr_header(): bs_amp_res"));
/* bs_start_freq and bs_stop_freq must define a fequency band that does
not exceed 48 channels */
sbr->bs_start_freq = (uint8_t)faad_getbits(ld, 4
DEBUGVAR(1,204,"sbr_header(): bs_start_freq"));
sbr->bs_stop_freq = (uint8_t)faad_getbits(ld, 4
DEBUGVAR(1,205,"sbr_header(): bs_stop_freq"));
sbr->bs_xover_band = (uint8_t)faad_getbits(ld, 3
DEBUGVAR(1,206,"sbr_header(): bs_xover_band"));
faad_getbits(ld, 2
DEBUGVAR(1,207,"sbr_header(): bs_reserved_bits_hdr"));
bs_header_extra_1 = (uint8_t)faad_get1bit(ld
DEBUGVAR(1,208,"sbr_header(): bs_header_extra_1"));
bs_header_extra_2 = (uint8_t)faad_get1bit(ld
DEBUGVAR(1,209,"sbr_header(): bs_header_extra_2"));
if (bs_header_extra_1)
{
sbr->bs_freq_scale = (uint8_t)faad_getbits(ld, 2
DEBUGVAR(1,211,"sbr_header(): bs_freq_scale"));
sbr->bs_alter_scale = (uint8_t)faad_get1bit(ld
DEBUGVAR(1,212,"sbr_header(): bs_alter_scale"));
sbr->bs_noise_bands = (uint8_t)faad_getbits(ld, 2
DEBUGVAR(1,213,"sbr_header(): bs_noise_bands"));
} else {
/* Default values */
sbr->bs_freq_scale = 2;
sbr->bs_alter_scale = 1;
sbr->bs_noise_bands = 2;
}
if (bs_header_extra_2)
{
sbr->bs_limiter_bands = (uint8_t)faad_getbits(ld, 2
DEBUGVAR(1,214,"sbr_header(): bs_limiter_bands"));
sbr->bs_limiter_gains = (uint8_t)faad_getbits(ld, 2
DEBUGVAR(1,215,"sbr_header(): bs_limiter_gains"));
sbr->bs_interpol_freq = (uint8_t)faad_get1bit(ld
DEBUGVAR(1,216,"sbr_header(): bs_interpol_freq"));
sbr->bs_smoothing_mode = (uint8_t)faad_get1bit(ld
DEBUGVAR(1,217,"sbr_header(): bs_smoothing_mode"));
} else {
/* Default values */
sbr->bs_limiter_bands = 2;
sbr->bs_limiter_gains = 2;
sbr->bs_interpol_freq = 1;
sbr->bs_smoothing_mode = 1;
}
#if 0
/* print the header to screen */
printf("bs_amp_res: %d\n", sbr->bs_amp_res);
printf("bs_start_freq: %d\n", sbr->bs_start_freq);
printf("bs_stop_freq: %d\n", sbr->bs_stop_freq);
printf("bs_xover_band: %d\n", sbr->bs_xover_band);
if (bs_header_extra_1)
{
printf("bs_freq_scale: %d\n", sbr->bs_freq_scale);
printf("bs_alter_scale: %d\n", sbr->bs_alter_scale);
printf("bs_noise_bands: %d\n", sbr->bs_noise_bands);
}
if (bs_header_extra_2)
{
printf("bs_limiter_bands: %d\n", sbr->bs_limiter_bands);
printf("bs_limiter_gains: %d\n", sbr->bs_limiter_gains);
printf("bs_interpol_freq: %d\n", sbr->bs_interpol_freq);
printf("bs_smoothing_mode: %d\n", sbr->bs_smoothing_mode);
}
printf("\n");
#endif
}
/* table 4 */
static uint8_t sbr_data(bitfile *ld, sbr_info *sbr)
{
uint8_t result;
#if 0
sbr->bs_samplerate_mode = faad_get1bit(ld
DEBUGVAR(1,219,"sbr_data(): bs_samplerate_mode"));
#endif
sbr->rate = (sbr->bs_samplerate_mode) ? 2 : 1;
switch (sbr->id_aac)
{
case ID_SCE:
if ((result = sbr_single_channel_element(ld, sbr)) > 0)
return result;
break;
case ID_CPE:
if ((result = sbr_channel_pair_element(ld, sbr)) > 0)
return result;
break;
}
return 0;
}
/* table 5 */
static uint8_t sbr_single_channel_element(bitfile *ld, sbr_info *sbr)
{
uint8_t result;
if (faad_get1bit(ld
DEBUGVAR(1,220,"sbr_single_channel_element(): bs_data_extra")))
{
faad_getbits(ld, 4
DEBUGVAR(1,221,"sbr_single_channel_element(): bs_reserved_bits_data"));
}
#ifdef DRM
/* bs_coupling, from sbr_channel_pair_base_element(bs_amp_res) */
if (sbr->Is_DRM_SBR)
{
faad_get1bit(ld);
}
#endif
if ((result = sbr_grid(ld, sbr, 0)) > 0)
return result;
sbr_dtdf(ld, sbr, 0);
invf_mode(ld, sbr, 0);
sbr_envelope(ld, sbr, 0);
sbr_noise(ld, sbr, 0);
#ifndef FIXED_POINT
envelope_noise_dequantisation(sbr, 0);
#endif
memset(sbr->bs_add_harmonic[0], 0, 64*sizeof(uint8_t));
sbr->bs_add_harmonic_flag[0] = faad_get1bit(ld
DEBUGVAR(1,223,"sbr_single_channel_element(): bs_add_harmonic_flag[0]"));
if (sbr->bs_add_harmonic_flag[0])
sinusoidal_coding(ld, sbr, 0);
sbr->bs_extended_data = faad_get1bit(ld
DEBUGVAR(1,224,"sbr_single_channel_element(): bs_extended_data[0]"));
if (sbr->bs_extended_data)
{
uint16_t nr_bits_left;
#if (defined(PS_DEC) || defined(DRM_PS))
uint8_t ps_ext_read = 0;
#endif
uint16_t cnt = (uint16_t)faad_getbits(ld, 4
DEBUGVAR(1,225,"sbr_single_channel_element(): bs_extension_size"));
if (cnt == 15)
{
cnt += (uint16_t)faad_getbits(ld, 8
DEBUGVAR(1,226,"sbr_single_channel_element(): bs_esc_count"));
}
nr_bits_left = 8 * cnt;
while (nr_bits_left > 7)
{
uint16_t tmp_nr_bits = 0;
sbr->bs_extension_id = (uint8_t)faad_getbits(ld, 2
DEBUGVAR(1,227,"sbr_single_channel_element(): bs_extension_id"));
tmp_nr_bits += 2;
/* allow only 1 PS extension element per extension data */
#if (defined(PS_DEC) || defined(DRM_PS))
#if (defined(PS_DEC) && defined(DRM_PS))
if (sbr->bs_extension_id == EXTENSION_ID_PS || sbr->bs_extension_id == DRM_PARAMETRIC_STEREO)
#else
#ifdef PS_DEC
if (sbr->bs_extension_id == EXTENSION_ID_PS)
#else
#ifdef DRM_PS
if (sbr->bs_extension_id == DRM_PARAMETRIC_STEREO)
#endif
#endif
#endif
{
if (ps_ext_read == 0)
{
ps_ext_read = 1;
} else {
/* to be safe make it 3, will switch to "default"
* in sbr_extension() */
#ifdef DRM
return 1;
#else
sbr->bs_extension_id = 3;
#endif
}
}
#endif
tmp_nr_bits += sbr_extension(ld, sbr, sbr->bs_extension_id, nr_bits_left);
/* check if the data read is bigger than the number of available bits */
if (tmp_nr_bits > nr_bits_left)
return 1;
nr_bits_left -= tmp_nr_bits;
}
/* Corrigendum */
if (nr_bits_left > 0)
{
faad_getbits(ld, nr_bits_left
DEBUGVAR(1,280,"sbr_single_channel_element(): nr_bits_left"));
}
}
return 0;
}
/* table 6 */
static uint8_t sbr_channel_pair_element(bitfile *ld, sbr_info *sbr)
{
uint8_t n, result;
if (faad_get1bit(ld
DEBUGVAR(1,228,"sbr_single_channel_element(): bs_data_extra")))
{
faad_getbits(ld, 4
DEBUGVAR(1,228,"sbr_channel_pair_element(): bs_reserved_bits_data"));
faad_getbits(ld, 4
DEBUGVAR(1,228,"sbr_channel_pair_element(): bs_reserved_bits_data"));
}
sbr->bs_coupling = faad_get1bit(ld
DEBUGVAR(1,228,"sbr_channel_pair_element(): bs_coupling"));
if (sbr->bs_coupling)
{
if ((result = sbr_grid(ld, sbr, 0)) > 0)
return result;
/* need to copy some data from left to right */
sbr->bs_frame_class[1] = sbr->bs_frame_class[0];
sbr->L_E[1] = sbr->L_E[0];
sbr->L_Q[1] = sbr->L_Q[0];
sbr->bs_pointer[1] = sbr->bs_pointer[0];
for (n = 0; n <= sbr->L_E[0]; n++)
{
sbr->t_E[1][n] = sbr->t_E[0][n];
sbr->f[1][n] = sbr->f[0][n];
}
for (n = 0; n <= sbr->L_Q[0]; n++)
sbr->t_Q[1][n] = sbr->t_Q[0][n];
sbr_dtdf(ld, sbr, 0);
sbr_dtdf(ld, sbr, 1);
invf_mode(ld, sbr, 0);
/* more copying */
for (n = 0; n < sbr->N_Q; n++)
sbr->bs_invf_mode[1][n] = sbr->bs_invf_mode[0][n];
sbr_envelope(ld, sbr, 0);
sbr_noise(ld, sbr, 0);
sbr_envelope(ld, sbr, 1);
sbr_noise(ld, sbr, 1);
memset(sbr->bs_add_harmonic[0], 0, 64*sizeof(uint8_t));
memset(sbr->bs_add_harmonic[1], 0, 64*sizeof(uint8_t));
sbr->bs_add_harmonic_flag[0] = faad_get1bit(ld
DEBUGVAR(1,231,"sbr_channel_pair_element(): bs_add_harmonic_flag[0]"));
if (sbr->bs_add_harmonic_flag[0])
sinusoidal_coding(ld, sbr, 0);
sbr->bs_add_harmonic_flag[1] = faad_get1bit(ld
DEBUGVAR(1,232,"sbr_channel_pair_element(): bs_add_harmonic_flag[1]"));
if (sbr->bs_add_harmonic_flag[1])
sinusoidal_coding(ld, sbr, 1);
} else {
uint8_t saved_t_E[6] = {0}, saved_t_Q[3] = {0};
uint8_t saved_L_E = sbr->L_E[0];
uint8_t saved_L_Q = sbr->L_Q[0];
uint8_t saved_frame_class = sbr->bs_frame_class[0];
for (n = 0; n < saved_L_E; n++)
saved_t_E[n] = sbr->t_E[0][n];
for (n = 0; n < saved_L_Q; n++)
saved_t_Q[n] = sbr->t_Q[0][n];
if ((result = sbr_grid(ld, sbr, 0)) > 0)
return result;
if ((result = sbr_grid(ld, sbr, 1)) > 0)
{
/* restore first channel data as well */
sbr->bs_frame_class[0] = saved_frame_class;
sbr->L_E[0] = saved_L_E;
sbr->L_Q[0] = saved_L_Q;
for (n = 0; n < 6; n++)
sbr->t_E[0][n] = saved_t_E[n];
for (n = 0; n < 3; n++)
sbr->t_Q[0][n] = saved_t_Q[n];
return result;
}
sbr_dtdf(ld, sbr, 0);
sbr_dtdf(ld, sbr, 1);
invf_mode(ld, sbr, 0);
invf_mode(ld, sbr, 1);
sbr_envelope(ld, sbr, 0);
sbr_envelope(ld, sbr, 1);
sbr_noise(ld, sbr, 0);
sbr_noise(ld, sbr, 1);
memset(sbr->bs_add_harmonic[0], 0, 64*sizeof(uint8_t));
memset(sbr->bs_add_harmonic[1], 0, 64*sizeof(uint8_t));
sbr->bs_add_harmonic_flag[0] = faad_get1bit(ld
DEBUGVAR(1,239,"sbr_channel_pair_element(): bs_add_harmonic_flag[0]"));
if (sbr->bs_add_harmonic_flag[0])
sinusoidal_coding(ld, sbr, 0);
sbr->bs_add_harmonic_flag[1] = faad_get1bit(ld
DEBUGVAR(1,240,"sbr_channel_pair_element(): bs_add_harmonic_flag[1]"));
if (sbr->bs_add_harmonic_flag[1])
sinusoidal_coding(ld, sbr, 1);
}
#ifndef FIXED_POINT
envelope_noise_dequantisation(sbr, 0);
envelope_noise_dequantisation(sbr, 1);
if (sbr->bs_coupling)
unmap_envelope_noise(sbr);
#endif
sbr->bs_extended_data = faad_get1bit(ld
DEBUGVAR(1,233,"sbr_channel_pair_element(): bs_extended_data[0]"));
if (sbr->bs_extended_data)
{
uint16_t nr_bits_left;
uint16_t cnt = (uint16_t)faad_getbits(ld, 4
DEBUGVAR(1,234,"sbr_channel_pair_element(): bs_extension_size"));
if (cnt == 15)
{
cnt += (uint16_t)faad_getbits(ld, 8
DEBUGVAR(1,235,"sbr_channel_pair_element(): bs_esc_count"));
}
nr_bits_left = 8 * cnt;
while (nr_bits_left > 7)
{
uint16_t tmp_nr_bits = 0;
sbr->bs_extension_id = (uint8_t)faad_getbits(ld, 2
DEBUGVAR(1,236,"sbr_channel_pair_element(): bs_extension_id"));
tmp_nr_bits += 2;
tmp_nr_bits += sbr_extension(ld, sbr, sbr->bs_extension_id, nr_bits_left);
/* check if the data read is bigger than the number of available bits */
if (tmp_nr_bits > nr_bits_left)
return 1;
nr_bits_left -= tmp_nr_bits;
}
/* Corrigendum */
if (nr_bits_left > 0)
{
faad_getbits(ld, nr_bits_left
DEBUGVAR(1,280,"sbr_channel_pair_element(): nr_bits_left"));
}
}
return 0;
}
/* integer log[2](x): input range [0,10) */
static int8_t sbr_log2(const int8_t val)
{
int8_t log2tab[] = { 0, 0, 1, 2, 2, 3, 3, 3, 3, 4 };
if (val < 10 && val >= 0)
return log2tab[val];
else
return 0;
}
/* table 7 */
static uint8_t sbr_grid(bitfile *ld, sbr_info *sbr, uint8_t ch)
{
uint8_t i, env, rel, result;
uint8_t bs_abs_bord, bs_abs_bord_1;
uint8_t bs_num_env = 0;
uint8_t saved_L_E = sbr->L_E[ch];
uint8_t saved_L_Q = sbr->L_Q[ch];
uint8_t saved_frame_class = sbr->bs_frame_class[ch];
sbr->bs_frame_class[ch] = (uint8_t)faad_getbits(ld, 2
DEBUGVAR(1,248,"sbr_grid(): bs_frame_class"));
switch (sbr->bs_frame_class[ch])
{
case FIXFIX:
i = (uint8_t)faad_getbits(ld, 2
DEBUGVAR(1,249,"sbr_grid(): bs_num_env_raw"));
bs_num_env = min(1 << i, 5);
i = (uint8_t)faad_get1bit(ld
DEBUGVAR(1,250,"sbr_grid(): bs_freq_res_flag"));
for (env = 0; env < bs_num_env; env++)
sbr->f[ch][env] = i;
sbr->abs_bord_lead[ch] = 0;
sbr->abs_bord_trail[ch] = sbr->numTimeSlots;
sbr->n_rel_lead[ch] = bs_num_env - 1;
sbr->n_rel_trail[ch] = 0;
break;
case FIXVAR:
bs_abs_bord = (uint8_t)faad_getbits(ld, 2
DEBUGVAR(1,251,"sbr_grid(): bs_abs_bord")) + sbr->numTimeSlots;
bs_num_env = (uint8_t)faad_getbits(ld, 2
DEBUGVAR(1,252,"sbr_grid(): bs_num_env")) + 1;
for (rel = 0; rel < bs_num_env-1; rel++)
{
sbr->bs_rel_bord[ch][rel] = 2 * (uint8_t)faad_getbits(ld, 2
DEBUGVAR(1,253,"sbr_grid(): bs_rel_bord")) + 2;
}
i = sbr_log2(bs_num_env + 1);
sbr->bs_pointer[ch] = (uint8_t)faad_getbits(ld, i
DEBUGVAR(1,254,"sbr_grid(): bs_pointer"));
for (env = 0; env < bs_num_env; env++)
{
sbr->f[ch][bs_num_env - env - 1] = (uint8_t)faad_get1bit(ld
DEBUGVAR(1,255,"sbr_grid(): bs_freq_res"));
}
sbr->abs_bord_lead[ch] = 0;
sbr->abs_bord_trail[ch] = bs_abs_bord;
sbr->n_rel_lead[ch] = 0;
sbr->n_rel_trail[ch] = bs_num_env - 1;
break;
case VARFIX:
bs_abs_bord = (uint8_t)faad_getbits(ld, 2
DEBUGVAR(1,256,"sbr_grid(): bs_abs_bord"));
bs_num_env = (uint8_t)faad_getbits(ld, 2
DEBUGVAR(1,257,"sbr_grid(): bs_num_env")) + 1;
for (rel = 0; rel < bs_num_env-1; rel++)
{
sbr->bs_rel_bord[ch][rel] = 2 * (uint8_t)faad_getbits(ld, 2
DEBUGVAR(1,258,"sbr_grid(): bs_rel_bord")) + 2;
}
i = sbr_log2(bs_num_env + 1);
sbr->bs_pointer[ch] = (uint8_t)faad_getbits(ld, i
DEBUGVAR(1,259,"sbr_grid(): bs_pointer"));
for (env = 0; env < bs_num_env; env++)
{
sbr->f[ch][env] = (uint8_t)faad_get1bit(ld
DEBUGVAR(1,260,"sbr_grid(): bs_freq_res"));
}
sbr->abs_bord_lead[ch] = bs_abs_bord;
sbr->abs_bord_trail[ch] = sbr->numTimeSlots;
sbr->n_rel_lead[ch] = bs_num_env - 1;
sbr->n_rel_trail[ch] = 0;
break;
case VARVAR:
bs_abs_bord = (uint8_t)faad_getbits(ld, 2
DEBUGVAR(1,261,"sbr_grid(): bs_abs_bord_0"));
bs_abs_bord_1 = (uint8_t)faad_getbits(ld, 2
DEBUGVAR(1,262,"sbr_grid(): bs_abs_bord_1")) + sbr->numTimeSlots;
sbr->bs_num_rel_0[ch] = (uint8_t)faad_getbits(ld, 2
DEBUGVAR(1,263,"sbr_grid(): bs_num_rel_0"));
sbr->bs_num_rel_1[ch] = (uint8_t)faad_getbits(ld, 2
DEBUGVAR(1,264,"sbr_grid(): bs_num_rel_1"));
bs_num_env = min(5, sbr->bs_num_rel_0[ch] + sbr->bs_num_rel_1[ch] + 1);
for (rel = 0; rel < sbr->bs_num_rel_0[ch]; rel++)
{
sbr->bs_rel_bord_0[ch][rel] = 2 * (uint8_t)faad_getbits(ld, 2
DEBUGVAR(1,265,"sbr_grid(): bs_rel_bord")) + 2;
}
for(rel = 0; rel < sbr->bs_num_rel_1[ch]; rel++)
{
sbr->bs_rel_bord_1[ch][rel] = 2 * (uint8_t)faad_getbits(ld, 2
DEBUGVAR(1,266,"sbr_grid(): bs_rel_bord")) + 2;
}
i = sbr_log2(sbr->bs_num_rel_0[ch] + sbr->bs_num_rel_1[ch] + 2);
sbr->bs_pointer[ch] = (uint8_t)faad_getbits(ld, i
DEBUGVAR(1,267,"sbr_grid(): bs_pointer"));
for (env = 0; env < bs_num_env; env++)
{
sbr->f[ch][env] = (uint8_t)faad_get1bit(ld
DEBUGVAR(1,268,"sbr_grid(): bs_freq_res"));
}
sbr->abs_bord_lead[ch] = bs_abs_bord;
sbr->abs_bord_trail[ch] = bs_abs_bord_1;
sbr->n_rel_lead[ch] = sbr->bs_num_rel_0[ch];
sbr->n_rel_trail[ch] = sbr->bs_num_rel_1[ch];
break;
}
if (sbr->bs_frame_class[ch] == VARVAR)
sbr->L_E[ch] = min(bs_num_env, 5);
else
sbr->L_E[ch] = min(bs_num_env, 4);
if (sbr->L_E[ch] <= 0)
return 1;
if (sbr->L_E[ch] > 1)
sbr->L_Q[ch] = 2;
else
sbr->L_Q[ch] = 1;
/* TODO: this code can probably be integrated into the code above! */
if ((result = envelope_time_border_vector(sbr, ch)) > 0)
{
sbr->bs_frame_class[ch] = saved_frame_class;
sbr->L_E[ch] = saved_L_E;
sbr->L_Q[ch] = saved_L_Q;
return result;
}
noise_floor_time_border_vector(sbr, ch);
#if 0
for (env = 0; env < bs_num_env; env++)
{
printf("freq_res[ch:%d][env:%d]: %d\n", ch, env, sbr->f[ch][env]);
}
#endif
return 0;
}
/* table 8 */
static void sbr_dtdf(bitfile *ld, sbr_info *sbr, uint8_t ch)
{
uint8_t i;
for (i = 0; i < sbr->L_E[ch]; i++)
{
sbr->bs_df_env[ch][i] = faad_get1bit(ld
DEBUGVAR(1,269,"sbr_dtdf(): bs_df_env"));
}
for (i = 0; i < sbr->L_Q[ch]; i++)
{
sbr->bs_df_noise[ch][i] = faad_get1bit(ld
DEBUGVAR(1,270,"sbr_dtdf(): bs_df_noise"));
}
}
/* table 9 */
static void invf_mode(bitfile *ld, sbr_info *sbr, uint8_t ch)
{
uint8_t n;
for (n = 0; n < sbr->N_Q; n++)
{
sbr->bs_invf_mode[ch][n] = (uint8_t)faad_getbits(ld, 2
DEBUGVAR(1,271,"invf_mode(): bs_invf_mode"));
}
}
static uint16_t sbr_extension(bitfile *ld, sbr_info *sbr,
uint8_t bs_extension_id, uint16_t num_bits_left)
{
#ifdef PS_DEC
uint8_t header;
uint16_t ret;
#endif
switch (bs_extension_id)
{
#ifdef PS_DEC
case EXTENSION_ID_PS:
if (!sbr->ps)
{
sbr->ps = ps_init(get_sr_index(sbr->sample_rate), sbr->numTimeSlotsRate);
}
if (sbr->psResetFlag)
{
sbr->ps->header_read = 0;
}
ret = ps_data(sbr->ps, ld, &header);
/* enable PS if and only if: a header has been decoded */
if (sbr->ps_used == 0 && header == 1)
{
sbr->ps_used = 1;
}
if (header == 1)
{
sbr->psResetFlag = 0;
}
return ret;
#endif
#ifdef DRM_PS
case DRM_PARAMETRIC_STEREO:
sbr->ps_used = 1;
if (!sbr->drm_ps)
{
sbr->drm_ps = drm_ps_init();
}
return drm_ps_data(sbr->drm_ps, ld);
#endif
default:
sbr->bs_extension_data = (uint8_t)faad_getbits(ld, 6
DEBUGVAR(1,279,"sbr_single_channel_element(): bs_extension_data"));
return 6;
}
}
/* table 12 */
static void sinusoidal_coding(bitfile *ld, sbr_info *sbr, uint8_t ch)
{
uint8_t n;
for (n = 0; n < sbr->N_high; n++)
{
sbr->bs_add_harmonic[ch][n] = faad_get1bit(ld
DEBUGVAR(1,278,"sinusoidal_coding(): bs_add_harmonic"));
}
}
#endif /* SBR_DEC */

View File

@ -0,0 +1,68 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: sbr_syntax.h,v 1.23 2007/11/01 12:33:36 menno Exp $
**/
#ifndef __SBR_SYNTAX_H__
#define __SBR_SYNTAX_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "bits.h"
#define T_HFGEN 8
#define T_HFADJ 2
#define EXT_SBR_DATA 13
#define EXT_SBR_DATA_CRC 14
#define FIXFIX 0
#define FIXVAR 1
#define VARFIX 2
#define VARVAR 3
#define LO_RES 0
#define HI_RES 1
#define NO_TIME_SLOTS_960 15
#define NO_TIME_SLOTS 16
#define RATE 2
#define NOISE_FLOOR_OFFSET 6
uint8_t sbr_extension_data(bitfile *ld, sbr_info *sbr, uint16_t cnt,
uint8_t resetFlag);
#ifdef __cplusplus
}
#endif
#endif /* __SBR_SYNTAX_H__ */

View File

@ -0,0 +1,261 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: sbr_tf_grid.c,v 1.20 2008/09/19 22:50:20 menno Exp $
**/
/* Time/Frequency grid */
#include "common.h"
#include "structs.h"
#ifdef SBR_DEC
#include <stdlib.h>
#include "sbr_syntax.h"
#include "sbr_tf_grid.h"
/* static function declarations */
#if 0
static int16_t rel_bord_lead(sbr_info *sbr, uint8_t ch, uint8_t l);
static int16_t rel_bord_trail(sbr_info *sbr, uint8_t ch, uint8_t l);
#endif
static uint8_t middleBorder(sbr_info *sbr, uint8_t ch);
/* function constructs new time border vector */
/* first build into temp vector to be able to use previous vector on error */
uint8_t envelope_time_border_vector(sbr_info *sbr, uint8_t ch)
{
uint8_t l, border, temp;
uint8_t t_E_temp[6] = {0};
t_E_temp[0] = sbr->rate * sbr->abs_bord_lead[ch];
t_E_temp[sbr->L_E[ch]] = sbr->rate * sbr->abs_bord_trail[ch];
switch (sbr->bs_frame_class[ch])
{
case FIXFIX:
switch (sbr->L_E[ch])
{
case 4:
temp = (sbr->numTimeSlots / 4);
t_E_temp[3] = sbr->rate * 3 * temp;
t_E_temp[2] = sbr->rate * 2 * temp;
t_E_temp[1] = sbr->rate * temp;
break;
case 2:
t_E_temp[1] = sbr->rate * (sbr->numTimeSlots / 2);
break;
default:
break;
}
break;
case FIXVAR:
if (sbr->L_E[ch] > 1)
{
int8_t i = sbr->L_E[ch];
border = sbr->abs_bord_trail[ch];
for (l = 0; l < (sbr->L_E[ch] - 1); l++)
{
if (border < sbr->bs_rel_bord[ch][l])
return 1;
border -= sbr->bs_rel_bord[ch][l];
t_E_temp[--i] = sbr->rate * border;
}
}
break;
case VARFIX:
if (sbr->L_E[ch] > 1)
{
int8_t i = 1;
border = sbr->abs_bord_lead[ch];
for (l = 0; l < (sbr->L_E[ch] - 1); l++)
{
border += sbr->bs_rel_bord[ch][l];
if (sbr->rate * border + sbr->tHFAdj > sbr->numTimeSlotsRate+sbr->tHFGen)
return 1;
t_E_temp[i++] = sbr->rate * border;
}
}
break;
case VARVAR:
if (sbr->bs_num_rel_0[ch])
{
int8_t i = 1;
border = sbr->abs_bord_lead[ch];
for (l = 0; l < sbr->bs_num_rel_0[ch]; l++)
{
border += sbr->bs_rel_bord_0[ch][l];
if (sbr->rate * border + sbr->tHFAdj > sbr->numTimeSlotsRate+sbr->tHFGen)
return 1;
t_E_temp[i++] = sbr->rate * border;
}
}
if (sbr->bs_num_rel_1[ch])
{
int8_t i = sbr->L_E[ch];
border = sbr->abs_bord_trail[ch];
for (l = 0; l < sbr->bs_num_rel_1[ch]; l++)
{
if (border < sbr->bs_rel_bord_1[ch][l])
return 1;
border -= sbr->bs_rel_bord_1[ch][l];
t_E_temp[--i] = sbr->rate * border;
}
}
break;
}
/* no error occured, we can safely use this t_E vector */
for (l = 0; l < 6; l++)
{
sbr->t_E[ch][l] = t_E_temp[l];
}
return 0;
}
void noise_floor_time_border_vector(sbr_info *sbr, uint8_t ch)
{
sbr->t_Q[ch][0] = sbr->t_E[ch][0];
if (sbr->L_E[ch] == 1)
{
sbr->t_Q[ch][1] = sbr->t_E[ch][1];
sbr->t_Q[ch][2] = 0;
} else {
uint8_t index = middleBorder(sbr, ch);
sbr->t_Q[ch][1] = sbr->t_E[ch][index];
sbr->t_Q[ch][2] = sbr->t_E[ch][sbr->L_E[ch]];
}
}
#if 0
static int16_t rel_bord_lead(sbr_info *sbr, uint8_t ch, uint8_t l)
{
uint8_t i;
int16_t acc = 0;
switch (sbr->bs_frame_class[ch])
{
case FIXFIX:
return sbr->numTimeSlots/sbr->L_E[ch];
case FIXVAR:
return 0;
case VARFIX:
for (i = 0; i < l; i++)
{
acc += sbr->bs_rel_bord[ch][i];
}
return acc;
case VARVAR:
for (i = 0; i < l; i++)
{
acc += sbr->bs_rel_bord_0[ch][i];
}
return acc;
}
return 0;
}
static int16_t rel_bord_trail(sbr_info *sbr, uint8_t ch, uint8_t l)
{
uint8_t i;
int16_t acc = 0;
switch (sbr->bs_frame_class[ch])
{
case FIXFIX:
case VARFIX:
return 0;
case FIXVAR:
for (i = 0; i < l; i++)
{
acc += sbr->bs_rel_bord[ch][i];
}
return acc;
case VARVAR:
for (i = 0; i < l; i++)
{
acc += sbr->bs_rel_bord_1[ch][i];
}
return acc;
}
return 0;
}
#endif
static uint8_t middleBorder(sbr_info *sbr, uint8_t ch)
{
int8_t retval = 0;
switch (sbr->bs_frame_class[ch])
{
case FIXFIX:
retval = sbr->L_E[ch]/2;
break;
case VARFIX:
if (sbr->bs_pointer[ch] == 0)
retval = 1;
else if (sbr->bs_pointer[ch] == 1)
retval = sbr->L_E[ch] - 1;
else
retval = sbr->bs_pointer[ch] - 1;
break;
case FIXVAR:
case VARVAR:
if (sbr->bs_pointer[ch] > 1)
retval = sbr->L_E[ch] + 1 - sbr->bs_pointer[ch];
else
retval = sbr->L_E[ch] - 1;
break;
}
return (retval > 0) ? retval : 0;
}
#endif

View File

@ -0,0 +1,47 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: sbr_tf_grid.h,v 1.17 2007/11/01 12:33:36 menno Exp $
**/
#ifndef __SBR_TF_GRID_H__
#define __SBR_TF_GRID_H__
#ifdef __cplusplus
extern "C" {
#endif
uint8_t envelope_time_border_vector(sbr_info *sbr, uint8_t ch);
void noise_floor_time_border_vector(sbr_info *sbr, uint8_t ch);
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,49 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: specrec.h,v 1.33 2009/01/26 23:51:15 menno Exp $
**/
#ifndef __SPECREC_H__
#define __SPECREC_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "syntax.h"
uint8_t window_grouping_info(NeAACDecStruct *hDecoder, ic_stream *ics);
uint8_t reconstruct_channel_pair(NeAACDecStruct *hDecoder, ic_stream *ics1, ic_stream *ics2,
element *cpe, int16_t *spec_data1, int16_t *spec_data2);
uint8_t reconstruct_single_channel(NeAACDecStruct *hDecoder, ic_stream *ics, element *sce,
int16_t *spec_data);
#ifdef __cplusplus
}
#endif
#endif

175
tests/Audio/libFaad/ssr.c Normal file
View File

@ -0,0 +1,175 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: ssr.c,v 1.19 2007/11/01 12:33:36 menno Exp $
**/
#include "common.h"
#include "structs.h"
#ifdef SSR_DEC
#include "syntax.h"
#include "filtbank.h"
#include "ssr.h"
#include "ssr_fb.h"
void ssr_decode(ssr_info *ssr, fb_info *fb, uint8_t window_sequence,
uint8_t window_shape, uint8_t window_shape_prev,
real_t *freq_in, real_t *time_out, real_t *overlap,
real_t ipqf_buffer[SSR_BANDS][96/4],
real_t *prev_fmd, uint16_t frame_len)
{
uint8_t band;
uint16_t ssr_frame_len = frame_len/SSR_BANDS;
real_t time_tmp[2048] = {0};
real_t output[1024] = {0};
for (band = 0; band < SSR_BANDS; band++)
{
int16_t j;
/* uneven bands have inverted frequency scale */
if (band == 1 || band == 3)
{
for (j = 0; j < ssr_frame_len/2; j++)
{
real_t tmp;
tmp = freq_in[j + ssr_frame_len*band];
freq_in[j + ssr_frame_len*band] =
freq_in[ssr_frame_len - j - 1 + ssr_frame_len*band];
freq_in[ssr_frame_len - j - 1 + ssr_frame_len*band] = tmp;
}
}
/* non-overlapping inverse filterbank for SSR */
ssr_ifilter_bank(fb, window_sequence, window_shape, window_shape_prev,
freq_in + band*ssr_frame_len, time_tmp + band*ssr_frame_len,
ssr_frame_len);
/* gain control */
ssr_gain_control(ssr, time_tmp, output, overlap, prev_fmd,
band, window_sequence, ssr_frame_len);
}
/* inverse pqf to bring subbands together again */
ssr_ipqf(ssr, output, time_out, ipqf_buffer, frame_len, SSR_BANDS);
}
static void ssr_gain_control(ssr_info *ssr, real_t *data, real_t *output,
real_t *overlap, real_t *prev_fmd, uint8_t band,
uint8_t window_sequence, uint16_t frame_len)
{
uint16_t i;
real_t gc_function[2*1024/SSR_BANDS];
if (window_sequence != EIGHT_SHORT_SEQUENCE)
{
ssr_gc_function(ssr, &prev_fmd[band * frame_len*2],
gc_function, window_sequence, band, frame_len);
for (i = 0; i < frame_len*2; i++)
data[band * frame_len*2 + i] *= gc_function[i];
for (i = 0; i < frame_len; i++)
{
output[band*frame_len + i] = overlap[band*frame_len + i] +
data[band*frame_len*2 + i];
}
for (i = 0; i < frame_len; i++)
{
overlap[band*frame_len + i] =
data[band*frame_len*2 + frame_len + i];
}
} else {
uint8_t w;
for (w = 0; w < 8; w++)
{
uint16_t frame_len8 = frame_len/8;
uint16_t frame_len16 = frame_len/16;
ssr_gc_function(ssr, &prev_fmd[band*frame_len*2 + w*frame_len*2/8],
gc_function, window_sequence, frame_len);
for (i = 0; i < frame_len8*2; i++)
data[band*frame_len*2 + w*frame_len8*2+i] *= gc_function[i];
for (i = 0; i < frame_len8; i++)
{
overlap[band*frame_len + i + 7*frame_len16 + w*frame_len8] +=
data[band*frame_len*2 + 2*w*frame_len8 + i];
}
for (i = 0; i < frame_len8; i++)
{
overlap[band*frame_len + i + 7*frame_len16 + (w+1)*frame_len8] =
data[band*frame_len*2 + 2*w*frame_len8 + frame_len8 + i];
}
}
for (i = 0; i < frame_len; i++)
output[band*frame_len + i] = overlap[band*frame_len + i];
for (i = 0; i < frame_len; i++)
overlap[band*frame_len + i] = overlap[band*frame_len + i + frame_len];
}
}
static void ssr_gc_function(ssr_info *ssr, real_t *prev_fmd,
real_t *gc_function, uint8_t window_sequence,
uint8_t band, uint16_t frame_len)
{
uint16_t i;
uint16_t len_area1, len_area2;
int32_t aloc[10];
real_t alev[10];
switch (window_sequence)
{
case ONLY_LONG_SEQUENCE:
len_area1 = frame_len/SSR_BANDS;
len_area2 = 0;
break;
case LONG_START_SEQUENCE:
len_area1 = (frame_len/SSR_BANDS)*7/32;
len_area2 = (frame_len/SSR_BANDS)/16;
break;
case EIGHT_SHORT_SEQUENCE:
len_area1 = (frame_len/8)/SSR_BANDS;
len_area2 = 0;
break;
case LONG_STOP_SEQUENCE:
len_area1 = (frame_len/SSR_BANDS);
len_area2 = 0;
break;
}
/* decode bitstream information */
/* build array M */
for (i = 0; i < frame_len*2; i++)
gc_function[i] = 1;
}
#endif

59
tests/Audio/libFaad/ssr.h Normal file
View File

@ -0,0 +1,59 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: ssr.h,v 1.19 2007/11/01 12:33:36 menno Exp $
**/
#ifndef __SSR_H__
#define __SSR_H__
#ifdef __cplusplus
extern "C" {
#endif
#define SSR_BANDS 4
#define PQFTAPS 96
void ssr_decode(ssr_info *ssr, fb_info *fb, uint8_t window_sequence,
uint8_t window_shape, uint8_t window_shape_prev,
real_t *freq_in, real_t *time_out, real_t *overlap,
real_t ipqf_buffer[SSR_BANDS][96/4],
real_t *prev_fmd, uint16_t frame_len);
static void ssr_gain_control(ssr_info *ssr, real_t *data, real_t *output,
real_t *overlap, real_t *prev_fmd, uint8_t band,
uint8_t window_sequence, uint16_t frame_len);
static void ssr_gc_function(ssr_info *ssr, real_t *prev_fmd,
real_t *gc_function, uint8_t window_sequence,
uint16_t frame_len);
#ifdef __cplusplus
}
#endif
#endif

Some files were not shown because too many files have changed in this diff Show More