mirror of
https://github.com/shadps4-emu/ext-LibAtrac9.git
synced 2026-01-31 00:55:24 +01:00
Quick and dirty port to C
Very direct port from C# version. Same files, function/variable names. Band extension isn't handled. Tables are pre-generated instead of being created at runtime. Extensive testing has not been done.
This commit is contained in:
119
C/bit_allocation.c
Normal file
119
C/bit_allocation.c
Normal file
@@ -0,0 +1,119 @@
|
||||
#include "bit_allocation.h"
|
||||
#include "tables.h"
|
||||
#include "utility.h"
|
||||
#include <string.h>
|
||||
|
||||
at9_status CreateGradient(block* block)
|
||||
{
|
||||
int valueCount = block->GradientEndValue - block->GradientStartValue;
|
||||
int unitCount = block->GradientEndUnit - block->GradientStartUnit;
|
||||
|
||||
for (int i = 0; i < block->GradientEndUnit; i++)
|
||||
{
|
||||
block->Gradient[i] = block->GradientStartValue;
|
||||
}
|
||||
|
||||
for (int i = block->GradientEndUnit; i <= block->QuantizationUnitCount; i++)
|
||||
{
|
||||
block->Gradient[i] = block->GradientEndValue;
|
||||
}
|
||||
if (unitCount <= 0) return ERR_SUCCESS;
|
||||
if (valueCount == 0) return ERR_SUCCESS;
|
||||
|
||||
const unsigned char* curve = GradientCurves[unitCount - 1];
|
||||
if (valueCount <= 0)
|
||||
{
|
||||
double scale = (-valueCount - 1) / 31.0;
|
||||
int baseVal = block->GradientStartValue - 1;
|
||||
for (int i = block->GradientStartUnit; i < block->GradientEndUnit; i++)
|
||||
{
|
||||
block->Gradient[i] = baseVal - (int)(curve[i - block->GradientStartUnit] * scale);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
double scale = (valueCount - 1) / 31.0;
|
||||
int baseVal = block->GradientStartValue + 1;
|
||||
for (int i = block->GradientStartUnit; i < block->GradientEndUnit; i++)
|
||||
{
|
||||
block->Gradient[i] = baseVal + (int)(curve[i - block->GradientStartUnit] * scale);
|
||||
}
|
||||
}
|
||||
|
||||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
void CalculateMask(channel* channel)
|
||||
{
|
||||
memset(channel->PrecisionMask, 0, sizeof(channel->PrecisionMask));
|
||||
for (int i = 1; i < channel->Block->QuantizationUnitCount; i++)
|
||||
{
|
||||
const int delta = channel->ScaleFactors[i] - channel->ScaleFactors[i - 1];
|
||||
if (delta > 1)
|
||||
{
|
||||
channel->PrecisionMask[i] += min(delta - 1, 5);
|
||||
}
|
||||
else if (delta < -1)
|
||||
{
|
||||
channel->PrecisionMask[i - 1] += min(delta * -1 - 1, 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CalculatePrecisions(channel* channel)
|
||||
{
|
||||
block* block = channel->Block;
|
||||
|
||||
if (block->GradientMode != 0)
|
||||
{
|
||||
for (int i = 0; i < block->QuantizationUnitCount; i++)
|
||||
{
|
||||
channel->Precisions[i] = channel->ScaleFactors[i] + channel->PrecisionMask[i] - block->Gradient[i];
|
||||
if (channel->Precisions[i] > 0)
|
||||
{
|
||||
switch (block->GradientMode)
|
||||
{
|
||||
case 1:
|
||||
channel->Precisions[i] /= 2;
|
||||
break;
|
||||
case 2:
|
||||
channel->Precisions[i] = 3 * channel->Precisions[i] / 8;
|
||||
break;
|
||||
case 3:
|
||||
channel->Precisions[i] /= 4;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < block->QuantizationUnitCount; i++)
|
||||
{
|
||||
channel->Precisions[i] = channel->ScaleFactors[i] - block->Gradient[i];
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < block->QuantizationUnitCount; i++)
|
||||
{
|
||||
if (channel->Precisions[i] < 1)
|
||||
{
|
||||
channel->Precisions[i] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < block->GradientBoundary; i++)
|
||||
{
|
||||
channel->Precisions[i]++;
|
||||
}
|
||||
|
||||
for (int i = 0; i < block->QuantizationUnitCount; i++)
|
||||
{
|
||||
channel->PrecisionsFine[i] = 0;
|
||||
if (channel->Precisions[i] > 15)
|
||||
{
|
||||
channel->PrecisionsFine[i] = channel->Precisions[i] - 15;
|
||||
channel->Precisions[i] = 15;
|
||||
}
|
||||
}
|
||||
}
|
||||
6
C/bit_allocation.h
Normal file
6
C/bit_allocation.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
#include "unpack.h"
|
||||
|
||||
at9_status CreateGradient(block* block);
|
||||
void CalculateMask(channel* channel);
|
||||
void CalculatePrecisions(channel* channel);
|
||||
110
C/bit_reader.c
Normal file
110
C/bit_reader.c
Normal file
@@ -0,0 +1,110 @@
|
||||
#include "bit_reader.h"
|
||||
#include "utility.h"
|
||||
|
||||
static int peek_int_fallback(bit_reader_cxt* br, int bit_count);
|
||||
|
||||
void init_bit_reader_cxt(bit_reader_cxt* br, const void * buffer)
|
||||
{
|
||||
br->buffer = buffer;
|
||||
br->position = 0;
|
||||
}
|
||||
|
||||
int read_int(bit_reader_cxt* br, const int bits)
|
||||
{
|
||||
const int value = peek_int(br, bits);
|
||||
br->position += bits;
|
||||
return value;
|
||||
}
|
||||
|
||||
int read_signed_int(bit_reader_cxt* br, const int bits)
|
||||
{
|
||||
const int value = peek_int(br, bits);
|
||||
br->position += bits;
|
||||
return SignExtend32(value, bits);
|
||||
}
|
||||
|
||||
int read_offset_binary(bit_reader_cxt* br, const int bits)
|
||||
{
|
||||
const int offset = 1 << (bits - 1);
|
||||
const int value = peek_int(br, bits) - offset;
|
||||
br->position += bits;
|
||||
return value;
|
||||
}
|
||||
|
||||
int peek_int(bit_reader_cxt* br, const int bits)
|
||||
{
|
||||
const int byte_index = br->position / 8;
|
||||
const int bit_index = br->position % 8;
|
||||
const unsigned char* buffer = br->buffer;
|
||||
|
||||
if (bits <= 9)
|
||||
{
|
||||
int value = buffer[byte_index] << 8 | buffer[byte_index + 1];
|
||||
value &= 0xFFFF >> bit_index;
|
||||
value >>= 16 - bits - bit_index;
|
||||
return value;
|
||||
}
|
||||
|
||||
if (bits <= 17)
|
||||
{
|
||||
int value = buffer[byte_index] << 16 | buffer[byte_index + 1] << 8 | buffer[byte_index + 2];
|
||||
value &= 0xFFFFFF >> bit_index;
|
||||
value >>= 24 - bits - bit_index;
|
||||
return value;
|
||||
}
|
||||
|
||||
if (bits <= 25)
|
||||
{
|
||||
int value = buffer[byte_index] << 24
|
||||
| buffer[byte_index + 1] << 16
|
||||
| buffer[byte_index + 2] << 8
|
||||
| buffer[byte_index + 3];
|
||||
|
||||
value &= (int)(0xFFFFFFFF >> bit_index);
|
||||
value >>= 32 - bits - bit_index;
|
||||
return value;
|
||||
}
|
||||
return peek_int_fallback(br, bits);
|
||||
}
|
||||
|
||||
void align_position(bit_reader_cxt* br, const unsigned int multiple)
|
||||
{
|
||||
const int position = br->position;
|
||||
if (position % multiple == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
br->position = position + multiple - position % multiple;
|
||||
}
|
||||
|
||||
static int peek_int_fallback(bit_reader_cxt* br, int bit_count)
|
||||
{
|
||||
int value = 0;
|
||||
int byte_index = br->position / 8;
|
||||
int bit_index = br->position % 8;
|
||||
const unsigned char* buffer = br->buffer;
|
||||
|
||||
while (bit_count > 0)
|
||||
{
|
||||
if (bit_index >= 8)
|
||||
{
|
||||
bit_index = 0;
|
||||
byte_index++;
|
||||
}
|
||||
|
||||
int bits_to_read = bit_count;
|
||||
if (bits_to_read > 8 - bit_index)
|
||||
{
|
||||
bits_to_read = 8 - bit_index;
|
||||
}
|
||||
|
||||
const int mask = 0xFF >> bit_index;
|
||||
const int current_byte = (mask & buffer[byte_index]) >> (8 - bit_index - bits_to_read);
|
||||
|
||||
value = (value << bits_to_read) | current_byte;
|
||||
bit_index += bits_to_read;
|
||||
bit_count -= bits_to_read;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
13
C/bit_reader.h
Normal file
13
C/bit_reader.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
typedef struct {
|
||||
const unsigned char * buffer;
|
||||
int position;
|
||||
} bit_reader_cxt;
|
||||
|
||||
void init_bit_reader_cxt(bit_reader_cxt* br, const void * buffer);
|
||||
int peek_int(bit_reader_cxt* br, const int bits);
|
||||
int read_int(bit_reader_cxt* br, const int bits);
|
||||
int read_signed_int(bit_reader_cxt* br, const int bits);
|
||||
int read_offset_binary(bit_reader_cxt* br, const int bits);
|
||||
void align_position(bit_reader_cxt* br, const unsigned int multiple);
|
||||
110
C/decinit.c
Normal file
110
C/decinit.c
Normal file
@@ -0,0 +1,110 @@
|
||||
#include "bit_reader.h"
|
||||
#include "decinit.h"
|
||||
#include "error_codes.h"
|
||||
#include "structures.h"
|
||||
#include "tables.h"
|
||||
#include <string.h>
|
||||
|
||||
static int BlockTypeToChannelCount(BlockType block_type);
|
||||
|
||||
at9_status init_decoder(atrac9_handle* handle, unsigned char* config_data, int wlength)
|
||||
{
|
||||
ERROR_CHECK(init_config_data(&handle->config, config_data));
|
||||
ERROR_CHECK(init_frame(handle));
|
||||
handle->wlength = wlength;
|
||||
handle->initialized = 1;
|
||||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
at9_status init_config_data(ConfigData* config, unsigned char* config_data)
|
||||
{
|
||||
memcpy(config->ConfigData, config_data, CONFIG_DATA_SIZE);
|
||||
ERROR_CHECK(read_config_data(config));
|
||||
|
||||
config->FramesPerSuperframe = 1 << config->SuperframeIndex;
|
||||
config->SuperframeBytes = config->FrameBytes << config->SuperframeIndex;
|
||||
|
||||
config->ChannelConfig = ChannelConfigs[config->ChannelConfigIndex];
|
||||
config->ChannelCount = config->ChannelConfig.ChannelCount;
|
||||
config->SampleRate = SampleRates[config->SampleRateIndex];
|
||||
config->HighSampleRate = config->SampleRateIndex > 7;
|
||||
config->FrameSamplesPower = SamplingRateIndexToFrameSamplesPower[config->SampleRateIndex];
|
||||
config->FrameSamples = 1 << config->FrameSamplesPower;
|
||||
config->SuperframeSamples = config->FrameSamples * config->FramesPerSuperframe;
|
||||
|
||||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
at9_status read_config_data(ConfigData* config)
|
||||
{
|
||||
bit_reader_cxt br;
|
||||
init_bit_reader_cxt(&br, &config->ConfigData);
|
||||
|
||||
const int header = read_int(&br, 8);
|
||||
config->SampleRateIndex = read_int(&br, 4);
|
||||
config->ChannelConfigIndex = read_int(&br, 3);
|
||||
const int validation_bit = read_int(&br, 1);
|
||||
config->FrameBytes = read_int(&br, 11) + 1;
|
||||
config->SuperframeIndex = read_int(&br, 2);
|
||||
|
||||
if (header != 0xFE || validation_bit != 0)
|
||||
{
|
||||
return ERR_BAD_CONFIG_DATA;
|
||||
}
|
||||
|
||||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
at9_status init_frame(atrac9_handle* handle)
|
||||
{
|
||||
const int block_count = handle->config.ChannelConfig.BlockCount;
|
||||
handle->frame.config = &handle->config;
|
||||
|
||||
for (int i = 0; i < block_count; i++)
|
||||
{
|
||||
ERROR_CHECK(init_block(&handle->frame.Blocks[i], &handle->frame, i));
|
||||
}
|
||||
|
||||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
at9_status init_block(block* block, frame* parent_frame, int block_index)
|
||||
{
|
||||
block->Frame = parent_frame;
|
||||
block->BlockIndex = block_index;
|
||||
block->config = parent_frame->config;
|
||||
block->BlockType = block->config->ChannelConfig.Types[block_index];
|
||||
block->ChannelCount = BlockTypeToChannelCount(block->BlockType);
|
||||
|
||||
for (int i = 0; i < block->ChannelCount; i++)
|
||||
{
|
||||
ERROR_CHECK(init_channel(&block->Channels[i], block, i));
|
||||
}
|
||||
|
||||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
at9_status init_channel(channel* channel, block* parent_block, int channel_index)
|
||||
{
|
||||
channel->Block = parent_block;
|
||||
channel->Frame = parent_block->Frame;
|
||||
channel->config = parent_block->config;
|
||||
channel->ChannelIndex = channel_index;
|
||||
channel->mdct.bits = parent_block->config->FrameSamplesPower;
|
||||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
static int BlockTypeToChannelCount(BlockType block_type)
|
||||
{
|
||||
switch (block_type)
|
||||
{
|
||||
case Mono:
|
||||
return 1;
|
||||
case Stereo:
|
||||
return 2;
|
||||
case LFE:
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
11
C/decinit.h
Normal file
11
C/decinit.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "error_codes.h"
|
||||
#include "structures.h"
|
||||
|
||||
at9_status init_decoder(atrac9_handle* handle, unsigned char * config_data, int wlength);
|
||||
at9_status init_config_data(ConfigData* config, unsigned char * config_data);
|
||||
at9_status read_config_data(ConfigData* config);
|
||||
at9_status init_frame(atrac9_handle* handle);
|
||||
at9_status init_block(block* block, frame* parent_frame, int block_index);
|
||||
at9_status init_channel(channel* channel, block* parent_block, int channel_index);
|
||||
99
C/decoder.c
Normal file
99
C/decoder.c
Normal file
@@ -0,0 +1,99 @@
|
||||
#include "decoder.h"
|
||||
#include "unpack.h"
|
||||
#include "quantization.h"
|
||||
#include "tables.h"
|
||||
#include "imdct.h"
|
||||
#include <math.h>
|
||||
#include "utility.h"
|
||||
|
||||
at9_status Decode(atrac9_handle* handle, const unsigned char* audio, unsigned char* pcm, int* bytesUsed)
|
||||
{
|
||||
handle->frame.frameNum++;
|
||||
bit_reader_cxt br;
|
||||
init_bit_reader_cxt(&br, audio);
|
||||
ERROR_CHECK(DecodeFrame(&handle->frame, &br));
|
||||
|
||||
PcmFloatToShort(&handle->frame, (short*)pcm);
|
||||
|
||||
|
||||
*bytesUsed = br.position / 8;
|
||||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
at9_status DecodeFrame(frame* frame, bit_reader_cxt* br)
|
||||
{
|
||||
ERROR_CHECK(UnpackFrame(frame, br));
|
||||
|
||||
for (int i = 0; i < frame->config->ChannelConfig.BlockCount; i++)
|
||||
{
|
||||
block* block = &frame->Blocks[i];
|
||||
|
||||
DequantizeSpectra(block);
|
||||
ApplyIntensityStereo(block);
|
||||
ScaleSpectrumBlock(block);
|
||||
ImdctBlock(block);
|
||||
}
|
||||
|
||||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
void PcmFloatToShort(frame* frame, short* pcmOut)
|
||||
{
|
||||
const int endSample = frame->config->FrameSamples;
|
||||
short* dest = pcmOut;
|
||||
for (int d = 0, s = 0; s < endSample; d++, s++)
|
||||
{
|
||||
for (int i = 0; i < frame->config->ChannelConfig.BlockCount; i++)
|
||||
{
|
||||
block* block = &frame->Blocks[i];
|
||||
|
||||
for (int j = 0; j < block->ChannelCount; j++)
|
||||
{
|
||||
channel* channel = &block->Channels[j];
|
||||
double* pcmSrc = channel->Pcm;
|
||||
|
||||
const double sample = pcmSrc[d];
|
||||
const int roundedSample = (int)floor(sample + 0.5);
|
||||
*dest++ = Clamp16(roundedSample);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ImdctBlock(block* block)
|
||||
{
|
||||
for (int i = 0; i < block->ChannelCount; i++)
|
||||
{
|
||||
channel* channel = &block->Channels[i];
|
||||
|
||||
RunImdct(&channel->mdct, channel->Spectra, channel->Pcm);
|
||||
}
|
||||
}
|
||||
|
||||
void ApplyIntensityStereo(block* block)
|
||||
{
|
||||
if (block->BlockType != Stereo) return;
|
||||
|
||||
const int totalUnits = block->QuantizationUnitCount;
|
||||
const int stereoUnits = block->StereoQuantizationUnit;
|
||||
if (stereoUnits >= totalUnits) return;
|
||||
|
||||
channel* source = &block->Channels[block->PrimaryChannelIndex == 0 ? 0 : 1];
|
||||
channel* dest = &block->Channels[block->PrimaryChannelIndex == 0 ? 1 : 0];
|
||||
|
||||
for (int i = stereoUnits; i < totalUnits; i++)
|
||||
{
|
||||
const int sign = block->JointStereoSigns[i];
|
||||
for (int sb = QuantUnitToCoeffIndex[i]; sb < QuantUnitToCoeffIndex[i + 1]; sb++)
|
||||
{
|
||||
if (sign > 0)
|
||||
{
|
||||
dest->Spectra[sb] = -source->Spectra[sb];
|
||||
}
|
||||
else
|
||||
{
|
||||
dest->Spectra[sb] = source->Spectra[sb];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
10
C/decoder.h
Normal file
10
C/decoder.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
#include "bit_reader.h"
|
||||
#include "error_codes.h"
|
||||
#include "structures.h"
|
||||
|
||||
at9_status Decode(atrac9_handle* handle, const unsigned char* audio, unsigned char* pcm, int* bytesUsed);
|
||||
at9_status DecodeFrame(frame* frame, bit_reader_cxt* br);
|
||||
void ImdctBlock(block* block);
|
||||
void ApplyIntensityStereo(block* block);
|
||||
void PcmFloatToShort(frame* frame, short* pcmOut);
|
||||
31
C/error_codes.h
Normal file
31
C/error_codes.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
typedef enum at9_status
|
||||
{
|
||||
ERR_SUCCESS = 0,
|
||||
|
||||
ERR_NOT_IMPLEMENTED = 0x80000000,
|
||||
|
||||
ERR_BAD_CONFIG_DATA = 0x81000000,
|
||||
|
||||
ERR_UNPACK_SUPERFRAME_FLAG_INVALID = 0x82000000,
|
||||
ERR_UNPACK_REUSE_BAND_PARAMS_INVALID,
|
||||
ERR_UNPACK_BAND_PARAMS_INVALID,
|
||||
|
||||
ERR_UNPACK_GRAD_BOUNDARY_INVALID = 0x82100000,
|
||||
ERR_UNPACK_GRAD_START_UNIT_OOB,
|
||||
ERR_UNPACK_GRAD_END_UNIT_OOB,
|
||||
ERR_UNPACK_GRAD_START_VALUE_OOB,
|
||||
ERR_UNPACK_GRAD_END_VALUE_OOB,
|
||||
ERR_UNPACK_GRAD_END_UNIT_INVALID, // start_unit > end_unit
|
||||
|
||||
ERR_UNPACK_SCALE_FACTOR_MODE_INVALID,
|
||||
ERR_UNPACK_SCALE_FACTOR_OOB
|
||||
} at9_status;
|
||||
|
||||
#define ERROR_CHECK(x) do { \
|
||||
at9_status status = (x); \
|
||||
if (status != ERR_SUCCESS) { \
|
||||
return status; \
|
||||
} \
|
||||
} while (0)
|
||||
27
C/huffCodes.c
Normal file
27
C/huffCodes.c
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "huffCodes.h"
|
||||
#include "utility.h"
|
||||
|
||||
int ReadHuffmanValue(const HuffmanCodebook* huff, bit_reader_cxt* br, int is_signed)
|
||||
{
|
||||
const int code = peek_int(br, huff->MaxBitSize);
|
||||
const unsigned char value = huff->Lookup[code];
|
||||
const int bits = huff->Bits[value];
|
||||
br->position += bits;
|
||||
return is_signed ? SignExtend32(value, huff->ValueBits) : value;
|
||||
}
|
||||
|
||||
void DecodeHuffmanValues(int* spectrum, int index, int bandCount, const HuffmanCodebook* huff, const int* values)
|
||||
{
|
||||
const int valueCount = bandCount >> huff->ValueCountPower;
|
||||
const int mask = (1 << huff->ValueBits) - 1;
|
||||
|
||||
for (int i = 0; i < valueCount; i++)
|
||||
{
|
||||
int value = values[i];
|
||||
for (int j = 0; j < huff->ValueCount; j++)
|
||||
{
|
||||
spectrum[index++] = SignExtend32(value & mask, huff->ValueBits);
|
||||
value >>= huff->ValueBits;
|
||||
}
|
||||
}
|
||||
}
|
||||
3186
C/huffCodes.h
Normal file
3186
C/huffCodes.h
Normal file
File diff suppressed because it is too large
Load Diff
80
C/imdct.c
Normal file
80
C/imdct.c
Normal file
@@ -0,0 +1,80 @@
|
||||
#include "imdct.h"
|
||||
#include "tables.h"
|
||||
|
||||
void RunImdct(mdct* mdct, double* input, double* output)
|
||||
{
|
||||
const int size = 1 << mdct->bits;
|
||||
const int half = size / 2;
|
||||
double dctOut[MAX_FRAME_SAMPLES];
|
||||
const double* window = ImdctWindow[mdct->bits - 6];
|
||||
double* previous = mdct->_imdctPrevious;
|
||||
|
||||
Dct4(mdct, input, dctOut);
|
||||
|
||||
for (int i = 0; i < half; i++)
|
||||
{
|
||||
output[i] = window[i] * dctOut[i + half] + previous[i];
|
||||
output[i + half] = window[i + half] * -dctOut[size - 1 - i] - previous[i + half];
|
||||
previous[i] = window[size - 1 - i] * -dctOut[half - i - 1];
|
||||
previous[i + half] = window[half - i - 1] * dctOut[i];
|
||||
}
|
||||
}
|
||||
|
||||
void Dct4(mdct* mdct, double* input, double* output)
|
||||
{
|
||||
int MdctBits = mdct->bits;
|
||||
int MdctSize = 1 << MdctBits;
|
||||
const int* shuffleTable = ShuffleTables[MdctBits];
|
||||
const double* sinTable = SinTables[MdctBits];
|
||||
const double* cosTable = CosTables[MdctBits];
|
||||
double dctTemp[MAX_FRAME_SAMPLES];
|
||||
|
||||
int size = MdctSize;
|
||||
int lastIndex = size - 1;
|
||||
int halfSize = size / 2;
|
||||
|
||||
for (int i = 0; i < halfSize; i++)
|
||||
{
|
||||
int i2 = i * 2;
|
||||
double a = input[i2];
|
||||
double b = input[lastIndex - i2];
|
||||
double sin = sinTable[i];
|
||||
double cos = cosTable[i];
|
||||
dctTemp[i2] = a * cos + b * sin;
|
||||
dctTemp[i2 + 1] = a * sin - b * cos;
|
||||
}
|
||||
int stageCount = MdctBits - 1;
|
||||
|
||||
for (int stage = 0; stage < stageCount; stage++)
|
||||
{
|
||||
int blockCount = 1 << stage;
|
||||
int blockSizeBits = stageCount - stage;
|
||||
int blockHalfSizeBits = blockSizeBits - 1;
|
||||
int blockSize = 1 << blockSizeBits;
|
||||
int blockHalfSize = 1 << blockHalfSizeBits;
|
||||
sinTable = SinTables[blockHalfSizeBits];
|
||||
cosTable = CosTables[blockHalfSizeBits];
|
||||
|
||||
for (int block = 0; block < blockCount; block++)
|
||||
{
|
||||
for (int i = 0; i < blockHalfSize; i++)
|
||||
{
|
||||
int frontPos = (block * blockSize + i) * 2;
|
||||
int backPos = frontPos + blockSize;
|
||||
double a = dctTemp[frontPos] - dctTemp[backPos];
|
||||
double b = dctTemp[frontPos + 1] - dctTemp[backPos + 1];
|
||||
double sin = sinTable[i];
|
||||
double cos = cosTable[i];
|
||||
dctTemp[frontPos] += dctTemp[backPos];
|
||||
dctTemp[frontPos + 1] += dctTemp[backPos + 1];
|
||||
dctTemp[backPos] = a * cos + b * sin;
|
||||
dctTemp[backPos + 1] = a * sin - b * cos;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < MdctSize; i++)
|
||||
{
|
||||
output[i] = dctTemp[shuffleTable[i]];
|
||||
}
|
||||
}
|
||||
6
C/imdct.h
Normal file
6
C/imdct.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "structures.h"
|
||||
|
||||
void RunImdct(mdct* mdct, double* input, double* output);
|
||||
void Dct4(mdct* mdct, double* input, double* output);
|
||||
51
C/libatrac9.c
Normal file
51
C/libatrac9.c
Normal file
@@ -0,0 +1,51 @@
|
||||
#include "libatrac9.h"
|
||||
#include "structures.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "decinit.h"
|
||||
#include "decoder.h"
|
||||
|
||||
HANDLE_ATRAC9 GetHandle()
|
||||
{
|
||||
struct atrac9_handle* handle = malloc(sizeof(atrac9_handle));
|
||||
memset(handle, 0, sizeof(atrac9_handle));
|
||||
return handle;
|
||||
}
|
||||
|
||||
void ReleaseHandle(HANDLE_ATRAC9 handle)
|
||||
{
|
||||
free(handle);
|
||||
}
|
||||
|
||||
int DecInit(HANDLE_ATRAC9 handle, unsigned char * pConfigData, int wlength)
|
||||
{
|
||||
if (wlength != 16)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
ERROR_CHECK(init_decoder(handle, pConfigData, wlength));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DecDecode(HANDLE_ATRAC9 handle, const unsigned char * pStreamBuffer, int * pNByteUsed, void * pPcmBuffer)
|
||||
{
|
||||
at9_status status = Decode(handle, pStreamBuffer, pPcmBuffer, pNByteUsed);
|
||||
return status;
|
||||
}
|
||||
|
||||
int GetCodecInfo(HANDLE_ATRAC9 handle, CodecInfo * pCodecInfo)
|
||||
{
|
||||
atrac9_handle* h = handle;
|
||||
|
||||
pCodecInfo->channels = h->config.ChannelCount;
|
||||
pCodecInfo->channelConfigIndex = h->config.ChannelConfigIndex;
|
||||
pCodecInfo->samplingRate = h->config.SampleRate;
|
||||
pCodecInfo->superframeSize = h->config.SuperframeBytes;
|
||||
pCodecInfo->framesInSuperframe = h->config.FramesPerSuperframe;
|
||||
pCodecInfo->frameSamples = h->config.FrameSamples;
|
||||
pCodecInfo->wlength = h->wlength;
|
||||
memcpy(pCodecInfo->configData, h->config.ConfigData, CONFIG_DATA_SIZE);
|
||||
return ERR_SUCCESS;
|
||||
}
|
||||
34
C/libatrac9.h
Normal file
34
C/libatrac9.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef COMPILING_DLL
|
||||
#define DLLEXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define DLLEXPORT __declspec(dllimport)
|
||||
#endif
|
||||
|
||||
typedef void* HANDLE_ATRAC9;
|
||||
|
||||
typedef struct {
|
||||
int channels;
|
||||
int channelConfigIndex;
|
||||
int samplingRate;
|
||||
int superframeSize;
|
||||
int framesInSuperframe;
|
||||
int frameSamples;
|
||||
int wlength;
|
||||
unsigned char configData[4];
|
||||
} CodecInfo;
|
||||
|
||||
DLLEXPORT HANDLE_ATRAC9 GetHandle(void);
|
||||
DLLEXPORT void ReleaseHandle(HANDLE_ATRAC9 handle);
|
||||
|
||||
DLLEXPORT int DecInit(HANDLE_ATRAC9 handle, unsigned char *pConfigData, int wlength);
|
||||
DLLEXPORT int DecDecode(HANDLE_ATRAC9 handle, const unsigned char *pStreamBuffer, int *pNByteUsed, void *pPcmBuffer);
|
||||
DLLEXPORT int GetCodecInfo(HANDLE_ATRAC9 handle, CodecInfo *pCodecInfo);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
31
C/libatrac9.sln
Normal file
31
C/libatrac9.sln
Normal file
@@ -0,0 +1,31 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.27130.2010
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libatrac9", "libatrac9.vcxproj", "{2425F2CC-BB1B-4069-BC10-1C7F535EF8E8}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{2425F2CC-BB1B-4069-BC10-1C7F535EF8E8}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{2425F2CC-BB1B-4069-BC10-1C7F535EF8E8}.Debug|x64.Build.0 = Debug|x64
|
||||
{2425F2CC-BB1B-4069-BC10-1C7F535EF8E8}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{2425F2CC-BB1B-4069-BC10-1C7F535EF8E8}.Debug|x86.Build.0 = Debug|Win32
|
||||
{2425F2CC-BB1B-4069-BC10-1C7F535EF8E8}.Release|x64.ActiveCfg = Release|x64
|
||||
{2425F2CC-BB1B-4069-BC10-1C7F535EF8E8}.Release|x64.Build.0 = Release|x64
|
||||
{2425F2CC-BB1B-4069-BC10-1C7F535EF8E8}.Release|x86.ActiveCfg = Release|Win32
|
||||
{2425F2CC-BB1B-4069-BC10-1C7F535EF8E8}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {BB003D83-77D8-4E7B-896D-7C9ADA458F73}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
159
C/libatrac9.vcxproj
Normal file
159
C/libatrac9.vcxproj
Normal file
@@ -0,0 +1,159 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
<ProjectGuid>{2425F2CC-BB1B-4069-BC10-1C7F535EF8E8}</ProjectGuid>
|
||||
<RootNamespace>libatrac9</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
|
||||
<ProjectName>libatrac9</ProjectName>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<PreprocessorDefinitions>_WINDLL;COMPILING_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<CompileAs>CompileAsC</CompileAs>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<CompileAs>CompileAsC</CompileAs>
|
||||
<PreprocessorDefinitions>_WINDLL;COMPILING_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<CompileAs>CompileAsC</CompileAs>
|
||||
<PreprocessorDefinitions>_WINDLL;COMPILING_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ExceptionHandling>Sync</ExceptionHandling>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<CompileAs>CompileAsC</CompileAs>
|
||||
<PreprocessorDefinitions>_WINDLL;COMPILING_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="bit_allocation.h" />
|
||||
<ClInclude Include="bit_reader.h" />
|
||||
<ClInclude Include="decinit.h" />
|
||||
<ClInclude Include="decoder.h" />
|
||||
<ClInclude Include="error_codes.h" />
|
||||
<ClInclude Include="huffCodes.h" />
|
||||
<ClInclude Include="imdct.h" />
|
||||
<ClInclude Include="libatrac9.h" />
|
||||
<ClInclude Include="quantization.h" />
|
||||
<ClInclude Include="scale_factors.h" />
|
||||
<ClInclude Include="structures.h" />
|
||||
<ClInclude Include="tables.h" />
|
||||
<ClInclude Include="unpack.h" />
|
||||
<ClInclude Include="utility.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="bit_allocation.c" />
|
||||
<ClCompile Include="bit_reader.c" />
|
||||
<ClCompile Include="decinit.c" />
|
||||
<ClCompile Include="decoder.c" />
|
||||
<ClCompile Include="huffCodes.c" />
|
||||
<ClCompile Include="imdct.c" />
|
||||
<ClCompile Include="libatrac9.c" />
|
||||
<ClCompile Include="quantization.c" />
|
||||
<ClCompile Include="scale_factors.c" />
|
||||
<ClCompile Include="unpack.c" />
|
||||
<ClCompile Include="utility.c" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
96
C/libatrac9.vcxproj.filters
Normal file
96
C/libatrac9.vcxproj.filters
Normal file
@@ -0,0 +1,96 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="libatrac9.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="bit_allocation.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="bit_reader.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="decinit.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="decoder.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="error_codes.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="huffCodes.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="imdct.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="quantization.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="scale_factors.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="structures.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="tables.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="unpack.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="utility.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="libatrac9.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="bit_allocation.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="bit_reader.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="decinit.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="decoder.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="huffCodes.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="imdct.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="quantization.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="scale_factors.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="unpack.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="utility.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
54
C/quantization.c
Normal file
54
C/quantization.c
Normal file
@@ -0,0 +1,54 @@
|
||||
#include "quantization.h"
|
||||
#include <string.h>
|
||||
#include "tables.h"
|
||||
|
||||
void DequantizeSpectra(block* block)
|
||||
{
|
||||
for (int i = 0; i < block->ChannelCount; i++)
|
||||
{
|
||||
channel* channel = &block->Channels[i];
|
||||
memset(channel->Spectra, 0, sizeof(channel->Spectra));
|
||||
|
||||
for (int j = 0; j < channel->CodedQuantUnits; j++)
|
||||
{
|
||||
DequantizeQuantUnit(channel, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DequantizeQuantUnit(channel* channel, int band)
|
||||
{
|
||||
const int subBandIndex = QuantUnitToCoeffIndex[band];
|
||||
const int subBandCount = QuantUnitToCoeffCount[band];
|
||||
const double stepSize = QuantizerStepSize[channel->Precisions[band]];
|
||||
const double stepSizeFine = QuantizerFineStepSize[channel->PrecisionsFine[band]];
|
||||
|
||||
for (int sb = 0; sb < subBandCount; sb++)
|
||||
{
|
||||
const double coarse = channel->QuantizedSpectra[subBandIndex + sb] * stepSize;
|
||||
const double fine = channel->QuantizedSpectraFine[subBandIndex + sb] * stepSizeFine;
|
||||
channel->Spectra[subBandIndex + sb] = coarse + fine;
|
||||
}
|
||||
}
|
||||
|
||||
void ScaleSpectrumBlock(block* block)
|
||||
{
|
||||
for (int i = 0; i < block->ChannelCount; i++)
|
||||
{
|
||||
ScaleSpectrumChannel(&block->Channels[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void ScaleSpectrumChannel(channel* channel)
|
||||
{
|
||||
const int quantUnitCount = channel->Block->QuantizationUnitCount;
|
||||
double* spectra = channel->Spectra;
|
||||
|
||||
for (int i = 0; i < quantUnitCount; i++)
|
||||
{
|
||||
for (int sb = QuantUnitToCoeffIndex[i]; sb < QuantUnitToCoeffIndex[i + 1]; sb++)
|
||||
{
|
||||
spectra[sb] *= SpectrumScale[channel->ScaleFactors[i]];
|
||||
}
|
||||
}
|
||||
}
|
||||
8
C/quantization.h
Normal file
8
C/quantization.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "structures.h"
|
||||
|
||||
void DequantizeSpectra(block* block);
|
||||
void DequantizeQuantUnit(channel* channel, int band);
|
||||
void ScaleSpectrumBlock(block* block);
|
||||
void ScaleSpectrumChannel(channel* channel);
|
||||
146
C/scale_factors.c
Normal file
146
C/scale_factors.c
Normal file
@@ -0,0 +1,146 @@
|
||||
#include <string.h>
|
||||
#include "huffCodes.h"
|
||||
#include "scale_factors.h"
|
||||
#include "tables.h"
|
||||
#include "utility.h"
|
||||
|
||||
at9_status read_scale_factors(channel * channel, bit_reader_cxt * br)
|
||||
{
|
||||
memset(channel->ScaleFactors, 0, sizeof(channel->ScaleFactors));
|
||||
|
||||
channel->ScaleFactorCodingMode = read_int(br, 2);
|
||||
if (channel->ChannelIndex == 0)
|
||||
{
|
||||
switch (channel->ScaleFactorCodingMode)
|
||||
{
|
||||
case 0:
|
||||
ReadVlcDeltaOffset(channel, br);
|
||||
break;
|
||||
case 1:
|
||||
ReadClcOffset(channel, br);
|
||||
break;
|
||||
case 2:
|
||||
if (channel->Block->FirstInSuperframe) return ERR_UNPACK_SCALE_FACTOR_MODE_INVALID;
|
||||
ReadVlcDistanceToBaseline(channel, br, channel->ScaleFactorsPrev, channel->Block->QuantizationUnitsPrev);
|
||||
break;
|
||||
case 3:
|
||||
if (channel->Block->FirstInSuperframe) return ERR_UNPACK_SCALE_FACTOR_MODE_INVALID;
|
||||
ReadVlcDeltaOffsetWithBaseline(channel, br, channel->ScaleFactorsPrev, channel->Block->QuantizationUnitsPrev);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (channel->ScaleFactorCodingMode)
|
||||
{
|
||||
case 0:
|
||||
ReadVlcDeltaOffset(channel, br);
|
||||
break;
|
||||
case 1:
|
||||
ReadVlcDistanceToBaseline(channel, br, channel->Block->Channels[0].ScaleFactors, channel->Block->ExtensionUnit);
|
||||
break;
|
||||
case 2:
|
||||
ReadVlcDeltaOffsetWithBaseline(channel, br, channel->Block->Channels[0].ScaleFactors, channel->Block->ExtensionUnit);
|
||||
break;
|
||||
case 3:
|
||||
if (channel->Block->FirstInSuperframe) return ERR_UNPACK_SCALE_FACTOR_MODE_INVALID;
|
||||
ReadVlcDistanceToBaseline(channel, br, channel->ScaleFactorsPrev, channel->Block->QuantizationUnitsPrev);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < channel->Block->ExtensionUnit; i++)
|
||||
{
|
||||
if (channel->ScaleFactors[i] < 0 || channel->ScaleFactors[i] > 31)
|
||||
{
|
||||
return ERR_UNPACK_SCALE_FACTOR_OOB;
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(channel->ScaleFactorsPrev, channel->ScaleFactors, sizeof(channel->ScaleFactors));
|
||||
|
||||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
void ReadClcOffset(channel* channel, bit_reader_cxt* br)
|
||||
{
|
||||
const int maxBits = 5;
|
||||
int* sf = channel->ScaleFactors;
|
||||
const int bitLength = read_int(br, 2) + 2;
|
||||
const int baseValue = bitLength < maxBits ? read_int(br, maxBits) : 0;
|
||||
|
||||
for (int i = 0; i < channel->Block->ExtensionUnit; i++)
|
||||
{
|
||||
sf[i] = read_int(br, bitLength) + baseValue;
|
||||
}
|
||||
}
|
||||
|
||||
void ReadVlcDeltaOffset(channel* channel, bit_reader_cxt* br)
|
||||
{
|
||||
const int weightIndex = read_int(br, 3);
|
||||
const unsigned char* weights = ScaleFactorWeights[weightIndex];
|
||||
|
||||
int* sf = channel->ScaleFactors;
|
||||
const int baseValue = read_int(br, 5);
|
||||
const int bitLength = read_int(br, 2) + 3;
|
||||
const HuffmanCodebook* codebook = &HuffmanScaleFactorsUnsigned[bitLength];
|
||||
|
||||
sf[0] = read_int(br, bitLength);
|
||||
|
||||
for (int i = 1; i < channel->Block->ExtensionUnit; i++)
|
||||
{
|
||||
const int delta = ReadHuffmanValue(codebook, br, 0);
|
||||
sf[i] = (sf[i - 1] + delta) & (codebook->ValueMax - 1);
|
||||
}
|
||||
|
||||
for (int i = 0; i < channel->Block->ExtensionUnit; i++)
|
||||
{
|
||||
sf[i] += baseValue - weights[i];
|
||||
}
|
||||
}
|
||||
|
||||
void ReadVlcDistanceToBaseline(channel* channel, bit_reader_cxt* br, int* baseline, int baselineLength)
|
||||
{
|
||||
int* sf = channel->ScaleFactors;
|
||||
const int bit_length = read_int(br, 2) + 2;
|
||||
const HuffmanCodebook* codebook = &HuffmanScaleFactorsSigned[bit_length];
|
||||
const int unitCount = min(channel->Block->ExtensionUnit, baselineLength);
|
||||
|
||||
for (int i = 0; i < unitCount; i++)
|
||||
{
|
||||
const int distance = ReadHuffmanValue(codebook, br, TRUE);
|
||||
sf[i] = (baseline[i] + distance) & 31;
|
||||
}
|
||||
|
||||
for (int i = unitCount; i < channel->Block->ExtensionUnit; i++)
|
||||
{
|
||||
sf[i] = read_int(br, 5);
|
||||
}
|
||||
}
|
||||
|
||||
void ReadVlcDeltaOffsetWithBaseline(channel* channel, bit_reader_cxt* br, int* baseline, int baselineLength)
|
||||
{
|
||||
int* sf = channel->ScaleFactors;
|
||||
const int baseValue = read_offset_binary(br, 5);
|
||||
const int bitLength = read_int(br, 2) + 1;
|
||||
const HuffmanCodebook* codebook = &HuffmanScaleFactorsUnsigned[bitLength];
|
||||
const int unitCount = min(channel->Block->ExtensionUnit, baselineLength);
|
||||
|
||||
sf[0] = read_int(br, bitLength);
|
||||
|
||||
for (int i = 1; i < unitCount; i++)
|
||||
{
|
||||
const int delta = ReadHuffmanValue(codebook, br, FALSE);
|
||||
sf[i] = (sf[i - 1] + delta) & (codebook->ValueMax - 1);
|
||||
}
|
||||
|
||||
for (int i = 0; i < unitCount; i++)
|
||||
{
|
||||
sf[i] += baseValue + baseline[i];
|
||||
}
|
||||
|
||||
for (int i = unitCount; i < channel->Block->ExtensionUnit; i++)
|
||||
{
|
||||
sf[i] = read_int(br, 5);
|
||||
}
|
||||
}
|
||||
8
C/scale_factors.h
Normal file
8
C/scale_factors.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
#include "bit_allocation.h"
|
||||
|
||||
at9_status read_scale_factors(channel* channel, bit_reader_cxt* br);
|
||||
void ReadClcOffset(channel* channel, bit_reader_cxt* br);
|
||||
void ReadVlcDeltaOffset(channel* channel, bit_reader_cxt* br);
|
||||
void ReadVlcDistanceToBaseline(channel* channel, bit_reader_cxt* br, int* baseline, int baselineLength);
|
||||
void ReadVlcDeltaOffsetWithBaseline(channel* channel, bit_reader_cxt* br, int* baseline, int baselineLength);
|
||||
142
C/structures.h
Normal file
142
C/structures.h
Normal file
@@ -0,0 +1,142 @@
|
||||
#pragma once
|
||||
|
||||
#define CONFIG_DATA_SIZE 4
|
||||
#define MAX_BLOCK_COUNT 5
|
||||
#define MAX_BLOCK_CHANNEL_COUNT 2
|
||||
#define MAX_FRAME_SAMPLES 256
|
||||
#define MAX_BEX_VALUES 4
|
||||
|
||||
#define MAX_QUANT_UNITS 30
|
||||
|
||||
typedef struct frame frame;
|
||||
typedef struct block block;
|
||||
|
||||
typedef enum BlockType {
|
||||
Mono = 0,
|
||||
Stereo = 1,
|
||||
LFE = 2
|
||||
} BlockType;
|
||||
|
||||
typedef struct {
|
||||
int BlockCount;
|
||||
int ChannelCount;
|
||||
enum BlockType Types[MAX_BLOCK_COUNT];
|
||||
} ChannelConfig;
|
||||
|
||||
typedef struct {
|
||||
unsigned char ConfigData[CONFIG_DATA_SIZE];
|
||||
int SampleRateIndex;
|
||||
int ChannelConfigIndex;
|
||||
int FrameBytes;
|
||||
int SuperframeIndex;
|
||||
|
||||
ChannelConfig ChannelConfig;
|
||||
int ChannelCount;
|
||||
int SampleRate;
|
||||
int HighSampleRate;
|
||||
int FramesPerSuperframe;
|
||||
int FrameSamplesPower;
|
||||
int FrameSamples;
|
||||
int SuperframeBytes;
|
||||
int SuperframeSamples;
|
||||
} ConfigData;
|
||||
|
||||
typedef struct {
|
||||
unsigned short stateA;
|
||||
unsigned short stateB;
|
||||
unsigned short stateC;
|
||||
unsigned short stateD;
|
||||
} rng_cxt;
|
||||
|
||||
typedef struct {
|
||||
int bits;
|
||||
int size;
|
||||
double scale;
|
||||
double _imdctPrevious[MAX_FRAME_SAMPLES];
|
||||
double* window;
|
||||
double* sinTable;
|
||||
double* cosTable;
|
||||
} mdct;
|
||||
|
||||
typedef struct {
|
||||
frame* Frame;
|
||||
block* Block;
|
||||
ConfigData* config;
|
||||
int ChannelIndex;
|
||||
|
||||
mdct mdct;
|
||||
|
||||
double Pcm[MAX_FRAME_SAMPLES];
|
||||
double Spectra[MAX_FRAME_SAMPLES];
|
||||
|
||||
int CodedQuantUnits;
|
||||
int ScaleFactorCodingMode;
|
||||
|
||||
int ScaleFactors[31];
|
||||
int ScaleFactorsPrev[31];
|
||||
|
||||
int Precisions[MAX_QUANT_UNITS];
|
||||
int PrecisionsFine[MAX_QUANT_UNITS];
|
||||
int PrecisionMask[MAX_QUANT_UNITS];
|
||||
|
||||
int CodebookSet[MAX_QUANT_UNITS];
|
||||
|
||||
int QuantizedSpectra[MAX_FRAME_SAMPLES];
|
||||
int QuantizedSpectraFine[MAX_FRAME_SAMPLES];
|
||||
|
||||
int BexMode;
|
||||
int BexValueCount;
|
||||
int BexValues[MAX_BEX_VALUES];
|
||||
|
||||
rng_cxt rng;
|
||||
} channel;
|
||||
|
||||
struct block {
|
||||
frame* Frame;
|
||||
ConfigData* config;
|
||||
enum BlockType BlockType;
|
||||
int BlockIndex;
|
||||
channel Channels[MAX_BLOCK_CHANNEL_COUNT];
|
||||
int ChannelCount;
|
||||
int FirstInSuperframe;
|
||||
int ReuseBandParams;
|
||||
|
||||
int BandCount;
|
||||
int StereoBand;
|
||||
int ExtensionBand;
|
||||
int QuantizationUnitCount;
|
||||
int StereoQuantizationUnit;
|
||||
int ExtensionUnit;
|
||||
int QuantizationUnitsPrev;
|
||||
|
||||
int Gradient[31];
|
||||
int GradientMode;
|
||||
int GradientStartUnit;
|
||||
int GradientStartValue;
|
||||
int GradientEndUnit;
|
||||
int GradientEndValue;
|
||||
int GradientBoundary;
|
||||
|
||||
int PrimaryChannelIndex;
|
||||
int HasJointStereoSigns;
|
||||
int JointStereoSigns[MAX_QUANT_UNITS];
|
||||
|
||||
int BandExtensionEnabled;
|
||||
int HasExtensionData;
|
||||
int BexDataLength;
|
||||
int BexMode;
|
||||
};
|
||||
|
||||
struct frame {
|
||||
ConfigData* config;
|
||||
int FrameIndex;
|
||||
block Blocks[MAX_BLOCK_COUNT];
|
||||
int frameNum;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
int initialized;
|
||||
int wlength;
|
||||
ConfigData config;
|
||||
frame frame;
|
||||
} atrac9_handle;
|
||||
642
C/tables.h
Normal file
642
C/tables.h
Normal file
@@ -0,0 +1,642 @@
|
||||
#pragma once
|
||||
|
||||
#include "structures.h"
|
||||
|
||||
static const ChannelConfig ChannelConfigs[6] =
|
||||
{
|
||||
{1, 1, Mono},
|
||||
{2, 2, Mono, Mono},
|
||||
{1, 2, Stereo},
|
||||
{4, 6, Stereo, Mono, LFE, Stereo},
|
||||
{5, 8, Stereo, Mono, LFE, Stereo, Stereo},
|
||||
{2, 4, Stereo, Stereo},
|
||||
};
|
||||
|
||||
static const int MaxHuffPrecision[2] = { 7, 1 };
|
||||
static const int MinBandCount[2] = { 3, 1 };
|
||||
static const int MaxExtensionBand[2] = { 18, 16 };
|
||||
|
||||
static const int SamplingRateIndexToFrameSamplesPower[16] =
|
||||
{ 6, 6, 7, 7, 7, 8, 8, 8, 6, 6, 7, 7, 7, 8, 8, 8 };
|
||||
|
||||
static const int MaxBandCount[16] =
|
||||
{ 8, 8, 12, 12, 12, 18, 18, 18, 8, 8, 12, 12, 12, 16, 16, 16 };
|
||||
|
||||
static const int BandToQuantUnitCount[19] =
|
||||
{ 0, 4, 8, 10, 12, 13, 14, 15, 16, 18, 20, 21, 22, 23, 24, 25, 26, 28, 30 };
|
||||
|
||||
static const int QuantUnitToCoeffCount[30] =
|
||||
{
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 4, 4, 8, 8, 8,
|
||||
8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16
|
||||
};
|
||||
|
||||
static const int QuantUnitToCoeffIndex[31] =
|
||||
{
|
||||
0, 2, 4, 6, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
|
||||
64, 72, 80, 88, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 256
|
||||
};
|
||||
|
||||
static const int QuantUnitToCodebookIndex[30] =
|
||||
{
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
|
||||
};
|
||||
|
||||
static const int SampleRates[16] =
|
||||
{
|
||||
11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000,
|
||||
44100, 48000, 64000, 88200, 96000, 128000, 176400, 192000
|
||||
};
|
||||
|
||||
static const unsigned char GradientCurves[48][48] = {
|
||||
{ 1 },
|
||||
{ 1, 16 },
|
||||
{ 1, 7, 25 },
|
||||
{ 1, 4, 16, 27 },
|
||||
{ 1, 3, 10, 21, 28 },
|
||||
{ 1, 3, 7, 16, 25, 29 },
|
||||
{ 1, 2, 5, 11, 20, 26, 29 },
|
||||
{ 1, 2, 4, 9, 16, 23, 27, 29 },
|
||||
{ 1, 2, 3, 7, 12, 19, 25, 28, 29 },
|
||||
{ 1, 2, 3, 5, 10, 16, 21, 26, 28, 29 },
|
||||
{ 1, 2, 3, 5, 8, 12, 19, 23, 26, 28, 29 },
|
||||
{ 1, 2, 3, 4, 7, 11, 16, 21, 25, 27, 29, 30 },
|
||||
{ 1, 1, 2, 4, 5, 9, 13, 18, 22, 26, 27, 29, 30 },
|
||||
{ 1, 1, 2, 3, 5, 8, 11, 16, 20, 23, 26, 28, 29, 30 },
|
||||
{ 1, 1, 2, 3, 4, 7, 10, 13, 18, 21, 25, 27, 28, 29, 30 },
|
||||
{ 1, 1, 2, 3, 4, 6, 9, 12, 16, 20, 23, 26, 27, 28, 29, 30 },
|
||||
{ 1, 1, 2, 3, 4, 5, 7, 10, 13, 18, 21, 24, 26, 27, 28, 29, 30 },
|
||||
{ 1, 1, 2, 3, 3, 5, 7, 9, 12, 16, 19, 22, 25, 26, 28, 29, 29, 30 },
|
||||
{ 1, 1, 2, 2, 3, 4, 6, 8, 11, 13, 18, 20, 23, 25, 27, 28, 29, 29, 30 },
|
||||
{ 1, 1, 2, 2, 3, 4, 5, 7, 10, 12, 16, 19, 21, 24, 26, 27, 28, 29, 29, 30 },
|
||||
{ 1, 1, 2, 2, 3, 4, 5, 7, 9, 11, 13, 18, 20, 22, 25, 26, 27, 28, 29, 29, 30 },
|
||||
{ 1, 1, 2, 2, 3, 3, 5, 6, 8, 10, 12, 16, 19, 21, 23, 25, 26, 28, 28, 29, 29,
|
||||
30 },
|
||||
{ 1, 1, 2, 2, 3, 3, 4, 5, 7, 9, 11, 13, 18, 20, 22, 24, 26, 27, 28, 28, 29,
|
||||
29, 30 },
|
||||
{ 1, 1, 2, 2, 3, 3, 4, 5, 7, 9, 11, 13, 16, 19, 21, 23, 25, 26, 27, 28, 29,
|
||||
29, 30, 30 },
|
||||
{ 1, 1, 1, 2, 2, 3, 4, 5, 6, 8, 10, 12, 15, 16, 19, 21, 23, 25, 26, 27, 28,
|
||||
29, 29, 30, 30 },
|
||||
{ 1, 1, 1, 2, 2, 3, 4, 4, 5, 7, 9, 11, 13, 16, 18, 20, 22, 24, 26, 27, 27,
|
||||
28, 29, 29, 30, 30 },
|
||||
{ 1, 1, 1, 2, 2, 3, 3, 4, 5, 7, 8, 10, 12, 15, 16, 19, 21, 23, 25, 26, 27,
|
||||
28, 28, 29, 29, 30, 30 },
|
||||
{ 1, 1, 1, 2, 2, 3, 3, 4, 5, 6, 8, 9, 11, 13, 16, 18, 20, 22, 23, 25, 26, 27,
|
||||
28, 28, 29, 29, 30, 30 },
|
||||
{ 1, 1, 1, 2, 2, 3, 3, 4, 5, 5, 7, 9, 10, 12, 15, 16, 19, 21, 22, 24, 26, 26,
|
||||
27, 28, 28, 29, 29, 30, 30 },
|
||||
{ 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 7, 8, 10, 11, 13, 16, 18, 20, 21, 23, 25, 26,
|
||||
27, 27, 28, 29, 29, 29, 30, 30 },
|
||||
{ 1, 1, 1, 2, 2, 2, 3, 3, 4, 5, 6, 8, 9, 11, 12, 15, 16, 19, 20, 22, 23, 25,
|
||||
26, 27, 28, 28, 29, 29, 29, 30, 30 },
|
||||
{ 1, 1, 1, 2, 2, 2, 3, 3, 4, 5, 6, 7, 9, 10, 12, 13, 16, 18, 20, 21, 23, 24,
|
||||
26, 26, 27, 28, 28, 29, 29, 29, 30, 30 },
|
||||
{ 1, 1, 1, 2, 2, 2, 3, 3, 4, 5, 5, 7, 8, 9, 11, 12, 15, 16, 19, 20, 22, 23,
|
||||
25, 26, 26, 27, 28, 28, 29, 29, 29, 30, 30 },
|
||||
{ 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 6, 7, 9, 10, 12, 13, 16, 18, 19, 21, 22,
|
||||
24, 25, 26, 27, 27, 28, 28, 29, 29, 29, 30, 30 },
|
||||
{ 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 5, 6, 7, 8, 10, 11, 12, 15, 16, 19, 20, 21,
|
||||
23, 24, 25, 26, 27, 28, 28, 28, 29, 29, 29, 30, 30 },
|
||||
{ 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 5, 5, 7, 8, 9, 11, 12, 13, 16, 18, 19, 21,
|
||||
22, 23, 25, 26, 26, 27, 28, 28, 29, 29, 29, 30, 30, 30 },
|
||||
{ 1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 6, 7, 9, 10, 11, 13, 15, 16, 18, 20,
|
||||
21, 22, 24, 25, 26, 27, 27, 28, 28, 29, 29, 29, 30, 30, 30 },
|
||||
{ 1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 6, 7, 8, 9, 11, 12, 13, 16, 18, 19, 20,
|
||||
22, 23, 24, 25, 26, 27, 27, 28, 28, 29, 29, 29, 30, 30, 30 },
|
||||
{ 1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 5, 7, 8, 9, 10, 11, 13, 15, 16, 18, 20,
|
||||
21, 22, 23, 25, 26, 26, 27, 27, 28, 28, 29, 29, 29, 30, 30, 30 },
|
||||
{ 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 5, 5, 6, 7, 9, 10, 11, 12, 13, 16, 18, 19,
|
||||
20, 21, 23, 24, 25, 26, 26, 27, 28, 28, 28, 29, 29, 29, 30, 30, 30 },
|
||||
{ 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 6, 7, 8, 9, 10, 12, 13, 15, 16, 18,
|
||||
19, 21, 22, 23, 24, 25, 26, 27, 27, 28, 28, 28, 29, 29, 29, 30, 30, 30 },
|
||||
{ 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 7, 8, 9, 10, 11, 12, 13, 16, 18,
|
||||
19, 20, 21, 22, 23, 25, 26, 26, 27, 27, 28, 28, 29, 29, 29, 29, 30, 30,
|
||||
30 },
|
||||
{ 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6, 7, 8, 9, 11, 12, 13, 15, 16,
|
||||
18, 19, 20, 22, 23, 24, 25, 26, 26, 27, 27, 28, 28, 29, 29, 29, 29, 30, 30,
|
||||
30 },
|
||||
{ 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 5, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16,
|
||||
18, 19, 20, 21, 22, 23, 24, 25, 26, 26, 27, 28, 28, 28, 29, 29, 29, 29, 30,
|
||||
30, 30 },
|
||||
{ 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 7, 8, 9, 10, 11, 12, 13, 15,
|
||||
16, 18, 19, 20, 21, 22, 23, 25, 26, 26, 27, 27, 28, 28, 28, 29, 29, 29, 29,
|
||||
30, 30, 30 },
|
||||
{ 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 7, 8, 9, 10, 11, 12, 13,
|
||||
16, 18, 19, 20, 21, 22, 23, 24, 25, 26, 26, 27, 27, 28, 28, 28, 29, 29, 29,
|
||||
29, 30, 30, 30 },
|
||||
{ 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 7, 8, 9, 10, 11, 12, 13,
|
||||
15, 16, 18, 19, 20, 21, 22, 23, 24, 25, 26, 26, 27, 27, 28, 28, 28, 29, 29,
|
||||
29, 29, 30, 30, 30 },
|
||||
{ 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 7, 8, 9, 10, 11, 12, 13,
|
||||
15, 16, 18, 19, 20, 21, 22, 23, 24, 25, 26, 26, 27, 27, 28, 28, 28, 29, 29,
|
||||
29, 29, 30, 30, 30, 30 }
|
||||
};
|
||||
|
||||
static const unsigned char ScaleFactorWeights[8][32] = {
|
||||
{ 0, 0, 0, 1, 1, 2, 2, 2, 2, 2, 2, 3, 2, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 6, 6,
|
||||
7, 7, 8, 10, 12, 12, 12 },
|
||||
{ 3, 2, 2, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 2, 3,
|
||||
3, 4, 5, 7, 10, 10, 10 },
|
||||
{ 0, 2, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7,
|
||||
7, 7, 8, 9, 12, 12, 12 },
|
||||
{ 0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 8, 8, 10,
|
||||
11, 11, 12, 13, 13, 13, 13 },
|
||||
{ 0, 2, 2, 3, 3, 4, 4, 5, 4, 5, 5, 5, 5, 6, 7, 8, 8, 8, 8, 9, 9, 9, 10, 10,
|
||||
11, 12, 12, 13, 13, 14, 14, 14 },
|
||||
{ 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 5,
|
||||
6, 7, 7, 9, 11, 11, 11 },
|
||||
{ 0, 5, 8, 10, 11, 11, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
|
||||
13, 13, 13, 13, 13, 12, 12, 12, 12, 13, 15, 15, 15 },
|
||||
{ 0, 2, 3, 4, 5, 6, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 11, 11,
|
||||
11, 12, 12, 12, 12, 13, 13, 15, 15, 15 }
|
||||
};
|
||||
|
||||
static const double SpectrumScale[] =
|
||||
{
|
||||
3.0517578125e-5, 6.1035156250e-5, 1.2207031250e-4, 2.4414062500e-4,
|
||||
4.8828125000e-4, 9.7656250000e-4, 1.9531250000e-3, 3.9062500000e-3,
|
||||
7.8125000000e-3, 1.5625000000e-2, 3.1250000000e-2, 6.2500000000e-2,
|
||||
1.2500000000e-1, 2.5000000000e-1, 5.0000000000e-1, 1.0000000000e+0,
|
||||
2.0000000000e+0, 4.0000000000e+0, 8.0000000000e+0, 1.6000000000e+1,
|
||||
3.2000000000e+1, 6.4000000000e+1, 1.2800000000e+2, 2.5600000000e+2,
|
||||
5.1200000000e+2, 1.0240000000e+3, 2.0480000000e+3, 4.0960000000e+3,
|
||||
8.1920000000e+3, 1.6384000000e+4, 3.2768000000e+4, 6.5536000000e+4
|
||||
};
|
||||
|
||||
static const double QuantizerInverseStepSize[] =
|
||||
{
|
||||
0.5, 1.5, 3.5, 7.5, 15.5, 31.5, 63.5, 127.5,
|
||||
255.5, 511.5, 1023.5, 2047.5, 4095.5, 8191.5, 16383.5, 32767.5
|
||||
};
|
||||
|
||||
static const double QuantizerStepSize[] =
|
||||
{
|
||||
2.0000000000000000e+0, 6.6666666666666663e-1, 2.8571428571428570e-1, 1.3333333333333333e-1,
|
||||
6.4516129032258063e-2, 3.1746031746031744e-2, 1.5748031496062992e-2, 7.8431372549019607e-3,
|
||||
3.9138943248532287e-3, 1.9550342130987292e-3, 9.7703957010258913e-4, 4.8840048840048840e-4,
|
||||
2.4417043096081065e-4, 1.2207776353537203e-4, 6.1037018951994385e-5, 3.0518043793392844e-5
|
||||
};
|
||||
|
||||
static const double QuantizerFineStepSize[] =
|
||||
{
|
||||
3.0518043793392844e-05, 1.0172681264464281e-05, 4.3597205419132631e-06, 2.0345362528928561e-06,
|
||||
9.8445302559331759e-07, 4.8441339354591809e-07, 2.4029955742829012e-07, 1.1967860311134448e-07,
|
||||
5.9722199204291275e-08, 2.9831909866464167e-08, 1.4908668194134265e-08, 7.4525137468602791e-09,
|
||||
3.7258019525568114e-09, 1.8627872668859698e-09, 9.3136520869755679e-10, 4.6567549848772173e-10
|
||||
};
|
||||
|
||||
static const double ImdctWindow[3][256] =
|
||||
{
|
||||
{
|
||||
1.5063601381680520e-4, 1.3584474462543723e-3, 3.7886177320335095e-3, 7.4703503843107054e-3,
|
||||
1.2447713421893925e-2, 1.8779928743902802e-2, 2.6541711957177316e-2, 3.5823617534646725e-2,
|
||||
4.6732325615097686e-2, 5.9390783134218215e-2, 7.3938082263507912e-2, 9.0528922524202596e-2,
|
||||
1.0933245918379739e-1, 1.3053029043162839e-1, 1.5431328196962155e-1, 1.8087687549234890e-1,
|
||||
2.1041448667730642e-1, 2.4310858398841248e-1, 2.7911907387439294e-1, 3.1856872996596264e-1,
|
||||
3.6152562795443521e-1, 4.0798291770561540e-1, 4.5783680167276436e-1, 5.1086428598490341e-1,
|
||||
5.6670306751604915e-1, 6.2483668296959261e-1, 6.8458855955238673e-1, 7.4512859813279642e-1,
|
||||
8.0549512595071404e-1, 8.6463333603715664e-1, 9.2144879049936534e-1, 9.7487163368853114e-1,
|
||||
1.0239245475428549e+0, 1.0677859781525272e+0, 1.1058403504640593e+0, 1.1377089681197508e+0,
|
||||
1.1632585999272456e+0, 1.1825885024539857e+0, 1.1959998581789721e+0, 1.2039536211881783e+0,
|
||||
1.2070233145307432e+0, 1.2058486131649040e+0, 1.2010940425977306e+0, 1.1934153504838110e+0,
|
||||
1.1834344842439808e+0, 1.1717228717811341e+0, 1.1587919249501784e+0, 1.1450893197640399e+0,
|
||||
1.1309995494487093e+0, 1.1168473822408471e+0, 1.1029030881588375e+0, 1.0893885582131881e+0,
|
||||
1.0764836829527871e+0, 1.0643325635250040e+0, 1.0530492907625166e+0, 1.0427231479840364e+0,
|
||||
1.0334231771880351e+0, 1.0252021034645231e+0, 1.0180996458407172e+0, 1.0121452604998511e+0,
|
||||
1.0073603692144730e+0, 1.0037601255634609e+0, 1.0013547666740490e+0, 1.0001505906450658e+0
|
||||
}, {
|
||||
3.7651915440994232e-5, 3.3903736493218477e-4, 9.4271596562609417e-4, 1.8505048571780937e-3,
|
||||
3.0651340559987531e-3, 4.5902515284472088e-3, 6.4304297938873409e-3, 8.5911739140682852e-3,
|
||||
1.1078930682637963e-2, 1.3901098781352234e-2, 1.7066039616689482e-2, 2.0583088491103220e-2,
|
||||
2.4462565695958088e-2, 2.8715787037224924e-2, 3.3355073219146852e-2, 3.8393757414250607e-2,
|
||||
4.3846190239227485e-2, 4.9727741234403468e-2, 5.6054795808958245e-2, 6.2844746464207860e-2,
|
||||
7.0115976942893413e-2, 7.7887837773809712e-2, 8.6180611489131392e-2, 9.5015465588190032e-2,
|
||||
1.0441439110899919e-1, 1.1440012445165516e-1, 1.2499604988161275e-1, 1.3622607993355360e-1,
|
||||
1.4811451074825102e-1, 1.6068584921843129e-1, 1.7396460871118313e-1, 1.8797507009352904e-1,
|
||||
2.0274100483757931e-1, 2.1828535714932726e-1, 2.3462988238128749e-1, 2.5179473948771497e-1,
|
||||
2.6979803599809959e-1, 2.8865532495679624e-1, 3.0837905453917885e-1, 3.2897797263820194e-1,
|
||||
3.5045649064171047e-1, 3.7281401289878474e-1, 3.9604424099221475e-1, 4.2013446485772571e-1,
|
||||
4.4506485595071510e-1, 4.7080778095190723e-1, 4.9732715777574310e-1, 5.2457787870593686e-1,
|
||||
5.5250532809467989e-1, 5.8104502395207014e-1, 6.1012241362349240e-1, 6.3965285330398725e-1,
|
||||
6.6954179909221967e-1, 6.9968523342026989e-1, 7.2997034487883472e-1, 7.6027647168828361e-1,
|
||||
7.9047630950129577e-1, 8.2043737319873378e-1, 8.5002369037661385e-1, 8.7909769200424248e-1,
|
||||
9.0752225407332920e-1, 9.3516283382959753e-1, 9.6188963623878732e-1, 9.8757974143721583e-1,
|
||||
1.0121191226072481e+0, 1.0354044862860237e+0, 1.0573448735328910e+0, 1.0778629702922595e+0,
|
||||
1.0968960880396657e+0, 1.1143967904987269e+0, 1.1303331578280613e+0, 1.1446886951223105e+0,
|
||||
1.1574619063379246e+0, 1.1686655669886925e+0, 1.1783257385311958e+0, 1.1864805739134745e+0,
|
||||
1.1931789671968236e+0, 1.1984791006306033e+0, 1.2024469404108813e+0, 1.2051547280715558e+0,
|
||||
1.2066795086022493e+0, 1.2071017295371607e+0, 1.2065039379557967e+0, 1.2049695950523571e+0,
|
||||
1.2025820210455416e+0, 1.1994234769930983e+0, 1.1955743847246600e+0, 1.1911126817016218e+0,
|
||||
1.1861133041685319e+0, 1.1806477894334932e+0, 1.1747839864214937e+0, 1.1685858626755936e+0,
|
||||
1.1621133956159084e+0, 1.1554225359834911e+0, 1.1485652318799691e+0, 1.1415895025598750e+0,
|
||||
1.1345395520508252e+0, 1.1274559136920683e+0, 1.1203756177344357e+0, 1.1133323751882473e+0,
|
||||
1.1063567721065632e+0, 1.0994764694261203e+0, 1.0927164043428366e+0, 1.0860989899652926e+0,
|
||||
1.0796443106658165e+0, 1.0733703111362594e+0, 1.0672929776585733e+0, 1.0614265105249636e+0,
|
||||
1.0557834868958031e+0, 1.0503750136731993e+0, 1.0452108702017300e+0, 1.0402996407927114e+0,
|
||||
1.0356488372113455e+0, 1.0312650113735067e+0, 1.0271538585764670e+0, 1.0233203116405181e+0,
|
||||
1.0197686263706869e+0, 1.0165024587632581e+0, 1.0135249343839337e+0, 1.0108387103358234e+0,
|
||||
1.0084460302183964e+0, 1.0063487724548694e+0, 1.0045484923368146e+0, 1.0030464581022487e+0,
|
||||
1.0018436813281120e+0, 1.0009409418806117e+0, 1.0003388076279887e+0, 1.0000376490803209e+0
|
||||
}, {
|
||||
9.4125358861057580e-6, 8.4723454567934287e-5, 2.3540199944993968e-4, 4.6156161284434405e-4,
|
||||
7.6337252627811040e-4, 1.1410618417977527e-3, 1.5949136397635877e-3, 2.1252691126038246e-3,
|
||||
2.7325267238603361e-3, 3.4171423917127887e-3, 4.1796296960223351e-3, 5.0205601077783681e-3,
|
||||
5.9405632396719189e-3, 6.9403271163487401e-3, 8.0205984627170716e-3, 9.1821830084947605e-3,
|
||||
1.0425945806983514e-2, 1.1752811565843454e-2, 1.3163764987419446e-2, 1.4659851115929995e-2,
|
||||
1.6242175688578154e-2, 1.7911905487372128e-2, 1.9670268688158944e-2, 2.1518555203066853e-2,
|
||||
2.3458117012231147e-2, 2.5490368480329692e-2, 2.7616786653092303e-2, 2.9838911528555608e-2,
|
||||
3.2158346297426151e-2, 3.4576757546475517e-2, 3.7095875418430582e-2, 3.9717493721334048e-2,
|
||||
4.2443469979832761e-2, 4.5275725420312357e-2, 4.8216244881222385e-2, 5.1267076639338320e-2,
|
||||
5.4430332142078826e-2, 5.7708185635340262e-2, 6.1102873675624066e-2, 6.4616694514523759e-2,
|
||||
6.8252007342895715e-2, 7.2011231381276714e-2, 7.5896844802323671e-2, 7.9911383470241099e-2,
|
||||
8.4057439481337801e-2, 8.8337659489012607e-2, 9.2754742795618184e-2, 9.7311439192797680e-2,
|
||||
1.0201054653103089e-1, 1.0685490799828457e-1, 1.1184740908682539e-1, 1.1699097422645341e-1,
|
||||
1.2228856306163924e-1, 1.2774316634932814e-1, 1.3335780145351064e-1, 1.3913550741207273e-1,
|
||||
1.4507933955094346e-1, 1.5119236362017258e-1, 1.5747764942631495e-1, 1.6393826393539396e-1,
|
||||
1.7057726382078942e-1, 1.7739768743066411e-1, 1.8440254615004589e-1, 1.9159481513343729e-1,
|
||||
1.9897742338487026e-1, 2.0655324316369295e-1, 2.1432507869609080e-1, 2.2229565417446207e-1,
|
||||
2.3046760102930014e-1, 2.3884344446123953e-1, 2.4742558922441760e-1, 2.5621630465634182e-1,
|
||||
2.6521770895405600e-1, 2.7443175270160086e-1, 2.8386020165960929e-1, 2.9350461883436230e-1,
|
||||
3.0336634585081029e-1, 3.1344648366192157e-1, 3.2374587263528420e-1, 3.3426507206713507e-1,
|
||||
3.4500433918392642e-1, 3.5596360770212615e-1, 3.6714246602814504e-1, 3.7854013519204033e-1,
|
||||
3.9015544662088664e-1, 4.0198681987032736e-1, 4.1403224044573772e-1, 4.2628923785747552e-1,
|
||||
4.3875486406774339e-1, 4.5142567249943838e-1, 4.6429769778983110e-1, 4.7736643648376575e-1,
|
||||
4.9062682887207903e-1, 5.0407324219080429e-1, 5.1769945540522078e-1, 5.3149864580960171e-1,
|
||||
5.4546337767832298e-1, 5.5958559320651569e-1, 5.7385660597837662e-1, 5.8826709719829806e-1,
|
||||
6.0280711491388439e-1, 6.1746607645042140e-1, 6.3223277426326774e-1, 6.4709538539776845e-1,
|
||||
6.6204148472553526e-1, 6.7705806210126773e-1, 6.9213154355570450e-1, 7.0724781660791802e-1,
|
||||
7.2239225974418442e-1, 7.3754977607134042e-1, 7.5270483111028141e-1, 7.6784149465049434e-1,
|
||||
7.8294348653984391e-1, 7.9799422623585203e-1, 8.1297688589617634e-1, 8.2787444673767518e-1,
|
||||
8.4266975834616653e-1, 8.5734560057365039e-1, 8.7188474761721291e-1, 8.8627003383497205e-1,
|
||||
9.0048442082009783e-1, 9.1451106522491854e-1, 9.2833338680417532e-1, 9.4193513613017210e-1,
|
||||
9.5530046142343950e-1, 9.6841397394092599e-1, 9.8126081136987864e-1, 9.9382669868953555e-1,
|
||||
1.0060980059844091e+0, 1.0180618027220363e+0, 1.0297059080441424e+0, 1.0410189366626670e+0,
|
||||
1.0519903400002633e+0, 1.0626104422678846e+0, 1.0728704712289712e+0, 1.0827625834595000e+0,
|
||||
1.0922798839747383e+0, 1.1014164401558058e+0, 1.1101672899710839e+0, 1.1185284445480093e+0,
|
||||
1.1264968852089079e+0, 1.1340705551393566e+0, 1.1412483459082730e+0, 1.1480300791048799e+0,
|
||||
1.1544164833982939e+0, 1.1604091673602994e+0, 1.1660105884206766e+0, 1.1712240183469862e+0,
|
||||
1.1760535056570971e+0, 1.1805038353829482e+0, 1.1845804866083633e+0, 1.1882895882024833e+0,
|
||||
1.1916378731638992e+0, 1.1946326319794081e+0, 1.1972816653859069e+0, 1.1995932369049056e+0,
|
||||
1.2015760254970136e+0, 1.2032390786591391e+0, 1.2045917662605969e+0, 1.2056437353864047e+0,
|
||||
1.2064048664272926e+0, 1.2068852306268385e+0, 1.2070950492671089e+0, 1.2070446546456641e+0,
|
||||
1.2067444529690747e+0, 1.2062048892615329e+0, 1.2054364143619665e+0, 1.2044494540594373e+0,
|
||||
1.2032543803947247e+0, 1.2018614851359353e+0, 1.2002809554178011e+0, 1.1985228515180752e+0,
|
||||
1.1965970867300784e+0, 1.1945134092779761e+0, 1.1922813862107031e+0, 1.1899103892015168e+0,
|
||||
1.1874095821728761e+0, 1.1847879106605945e+0, 1.1820540928268801e+0, 1.1792166120288408e+0,
|
||||
1.1762837108471988e+0, 1.1732633864791515e+0, 1.1701633873994670e+0, 1.1669912111948835e+0,
|
||||
1.1637541034785324e+0, 1.1604590577934164e+0, 1.1571128164167324e+0, 1.1537218719800488e+0,
|
||||
1.1502924698238557e+0, 1.1468306110087907e+0, 1.1433420559098040e+0, 1.1398323283235916e+0,
|
||||
1.1363067200237802e+0, 1.1327702957024974e+0, 1.1292278982411037e+0, 1.1256841542569240e+0,
|
||||
1.1221434798768233e+0, 1.1186100866923183e+0, 1.1150879878546791e+0, 1.1115810042720471e+0,
|
||||
1.1080927708740320e+0, 1.1046267429125149e+0, 1.1011862022704582e+0, 1.0977742637534329e+0,
|
||||
1.0943938813413197e+0, 1.0910478543801592e+0, 1.0877388336965346e+0, 1.0844693276190560e+0,
|
||||
1.0812417078935614e+0, 1.0780582154805316e+0, 1.0749209662249377e+0, 1.0718319563903185e+0,
|
||||
1.0687930680503352e+0, 1.0658060743323419e+0, 1.0628726445087104e+0, 1.0599943489327022e+0,
|
||||
1.0571726638166488e+0, 1.0544089758510451e+0, 1.0517045866639296e+0, 1.0490607171205948e+0,
|
||||
1.0464785114642610e+0, 1.0439590412988613e+0, 1.0415033094155353e+0, 1.0391122534648085e+0,
|
||||
1.0367867494767635e+0, 1.0345276152317773e+0, 1.0323356134846211e+0, 1.0302114550449104e+0,
|
||||
1.0281558017170187e+0, 1.0261692691026814e+0, 1.0242524292695903e+0, 1.0224058132893159e+0,
|
||||
1.0206299136479189e+0, 1.0189251865326008e+0, 1.0172920539977235e+0, 1.0157309060134747e+0,
|
||||
1.0142421024004051e+0, 1.0128259746529766e+0, 1.0114828276551826e+0, 1.0102129412911960e+0,
|
||||
1.0090165719538935e+0, 1.0078939539539893e+0, 1.0068453008323810e+0, 1.0058708065781889e+0,
|
||||
1.0049706467548214e+0, 1.0041449795362705e+0, 1.0033939466556858e+0, 1.0027176742681361e+0,
|
||||
1.0021162737293055e+0, 1.0015898422917326e+0, 1.0011384637200291e+0, 1.0007622088263692e+0,
|
||||
1.0004611359273783e+0, 1.0002352912233887e+0, 1.0000847091008724e+0, 1.0000094123586978e+0
|
||||
}
|
||||
};
|
||||
|
||||
static const double SinTables[9][256] =
|
||||
{
|
||||
{
|
||||
7.0710678118654746e-1
|
||||
}, {
|
||||
3.8268343236508978e-1, 9.2387953251128674e-1
|
||||
}, {
|
||||
1.9509032201612825e-1, 8.3146961230254524e-1, 9.8078528040323043e-1, 5.5557023301960218e-1
|
||||
}, {
|
||||
9.8017140329560604e-2, 4.7139673682599764e-1, 7.7301045336273699e-1, 9.5694033573220894e-1,
|
||||
9.9518472667219693e-1, 8.8192126434835505e-1, 6.3439328416364549e-1, 2.9028467725446239e-1
|
||||
}, {
|
||||
4.9067674327418015e-2, 2.4298017990326387e-1, 4.2755509343028208e-1, 5.9569930449243336e-1,
|
||||
7.4095112535495911e-1, 8.5772861000027212e-1, 9.4154406518302081e-1, 9.8917650996478101e-1,
|
||||
9.9879545620517241e-1, 9.7003125319454397e-1, 9.0398929312344345e-1, 8.0320753148064494e-1,
|
||||
6.7155895484701855e-1, 5.1410274419322177e-1, 3.3688985339222033e-1, 1.4673047445536180e-1
|
||||
}, {
|
||||
2.4541228522912288e-2, 1.2241067519921620e-1, 2.1910124015686980e-1, 3.1368174039889152e-1,
|
||||
4.0524131400498986e-1, 4.9289819222978404e-1, 5.7580819141784534e-1, 6.5317284295377676e-1,
|
||||
7.2424708295146689e-1, 7.8834642762660623e-1, 8.4485356524970701e-1, 8.9322430119551532e-1,
|
||||
9.3299279883473885e-1, 9.6377606579543984e-1, 9.8527764238894122e-1, 9.9729045667869021e-1,
|
||||
9.9969881869620425e-1, 9.9247953459870997e-1, 9.7570213003852857e-1, 9.4952818059303667e-1,
|
||||
9.1420975570353069e-1, 8.7008699110871146e-1, 8.1758481315158371e-1, 7.5720884650648468e-1,
|
||||
6.8954054473706705e-1, 6.1523159058062693e-1, 5.3499761988709715e-1, 4.4961132965460687e-1,
|
||||
3.5989503653498833e-1, 2.6671275747489848e-1, 1.7096188876030122e-1, 7.3564563599667732e-2
|
||||
}, {
|
||||
1.2271538285719925e-2, 6.1320736302208578e-2, 1.1022220729388306e-1, 1.5885814333386145e-1,
|
||||
2.0711137619221856e-1, 2.5486565960451457e-1, 3.0200594931922808e-1, 3.4841868024943456e-1,
|
||||
3.9399204006104810e-1, 4.3861623853852766e-1, 4.8218377207912272e-1, 5.2458968267846895e-1,
|
||||
5.6573181078361312e-1, 6.0551104140432555e-1, 6.4383154288979139e-1, 6.8060099779545302e-1,
|
||||
7.1573082528381859e-1, 7.4913639452345926e-1, 7.8073722857209438e-1, 8.1045719825259477e-1,
|
||||
8.3822470555483797e-1, 8.6397285612158670e-1, 8.8763962040285393e-1, 9.0916798309052227e-1,
|
||||
9.2850608047321548e-1, 9.4560732538052128e-1, 9.6043051941556579e-1, 9.7293995220556007e-1,
|
||||
9.8310548743121629e-1, 9.9090263542778001e-1, 9.9631261218277800e-1, 9.9932238458834954e-1,
|
||||
9.9992470183914450e-1, 9.9811811290014918e-1, 9.9390697000235606e-1, 9.8730141815785843e-1,
|
||||
9.7831737071962765e-1, 9.6697647104485207e-1, 9.5330604035419386e-1, 9.3733901191257496e-1,
|
||||
9.1911385169005777e-1, 8.9867446569395393e-1, 8.7607009419540660e-1, 8.5135519310526520e-1,
|
||||
8.2458930278502518e-1, 7.9583690460888357e-1, 7.6516726562245907e-1, 7.3265427167241282e-1,
|
||||
6.9837624940897292e-1, 6.6241577759017201e-1, 6.2485948814238634e-1, 5.8579785745643898e-1,
|
||||
5.4532498842204635e-1, 5.0353838372571769e-1, 4.6053871095824023e-1, 4.1642956009763715e-1,
|
||||
3.7131719395183771e-1, 3.2531029216226326e-1, 2.7851968938505317e-1, 2.3105810828067133e-1,
|
||||
1.8303988795514090e-1, 1.3458070850712628e-1, 8.5797312344440158e-2, 3.6807222941358832e-2
|
||||
}, {
|
||||
6.1358846491544753e-3, 3.0674803176636626e-2, 5.5195244349689934e-2, 7.9682437971430126e-2,
|
||||
1.0412163387205459e-1, 1.2849811079379317e-1, 1.5279718525844344e-1, 1.7700422041214875e-1,
|
||||
2.0110463484209190e-1, 2.2508391135979283e-1, 2.4892760574572015e-1, 2.7262135544994898e-1,
|
||||
2.9615088824362379e-1, 3.1950203081601569e-1, 3.4266071731199438e-1, 3.6561299780477385e-1,
|
||||
3.8834504669882625e-1, 4.1084317105790391e-1, 4.3309381885315196e-1, 4.5508358712634384e-1,
|
||||
4.7679923006332209e-1, 4.9822766697278187e-1, 5.1935599016558964e-1, 5.4017147272989285e-1,
|
||||
5.6066157619733603e-1, 5.8081395809576453e-1, 6.0061647938386897e-1, 6.2005721176328910e-1,
|
||||
6.3912444486377573e-1, 6.5780669329707864e-1, 6.7609270357531592e-1, 6.9397146088965400e-1,
|
||||
7.1143219574521643e-1, 7.2846439044822520e-1, 7.4505778544146595e-1, 7.6120238548426178e-1,
|
||||
7.7688846567323244e-1, 7.9210657730021239e-1, 8.0684755354379922e-1, 8.2110251499110465e-1,
|
||||
8.3486287498638001e-1, 8.4812034480329712e-1, 8.6086693863776731e-1, 8.7309497841829009e-1,
|
||||
8.8479709843093779e-1, 8.9596624975618511e-1, 9.0659570451491533e-1, 9.1667905992104270e-1,
|
||||
9.2621024213831127e-1, 9.3518350993894750e-1, 9.4359345816196039e-1, 9.5143502096900834e-1,
|
||||
9.5870347489587160e-1, 9.6539444169768940e-1, 9.7150389098625178e-1, 9.7702814265775439e-1,
|
||||
9.8196386910955524e-1, 9.8630809724459867e-1, 9.9005821026229712e-1, 9.9321194923479450e-1,
|
||||
9.9576741446765982e-1, 9.9772306664419164e-1, 9.9907772775264536e-1, 9.9983058179582340e-1,
|
||||
9.9998117528260111e-1, 9.9952941750109314e-1, 9.9847558057329477e-1, 9.9682029929116578e-1,
|
||||
9.9456457073425542e-1, 9.9170975366909953e-1, 9.8825756773074946e-1, 9.8421009238692903e-1,
|
||||
9.7956976568544052e-1, 9.7433938278557586e-1, 9.6852209427441738e-1, 9.6212140426904158e-1,
|
||||
9.5514116830577067e-1, 9.4758559101774120e-1, 9.3945922360218992e-1, 9.3076696107898371e-1,
|
||||
9.2151403934204201e-1, 9.1170603200542988e-1, 9.0134884704602203e-1, 8.9044872324475799e-1,
|
||||
8.7901222642863353e-1, 8.6704624551569276e-1, 8.5455798836540053e-1, 8.4155497743689844e-1,
|
||||
8.2804504525775580e-1, 8.1403632970594852e-1, 7.9953726910790524e-1, 7.8455659715557513e-1,
|
||||
7.6910333764557959e-1, 7.5318679904361252e-1, 7.3681656887737002e-1, 7.2000250796138177e-1,
|
||||
7.0275474445722519e-1, 6.8508366777270036e-1, 6.6699992230363758e-1, 6.4851440102211255e-1,
|
||||
6.2963823891492721e-1, 6.1038280627630970e-1, 5.9075970185887416e-1, 5.7078074588696726e-1,
|
||||
5.5045797293660492e-1, 5.2980362468629483e-1, 5.0883014254310732e-1, 4.8755016014843588e-1,
|
||||
4.6597649576796618e-1, 4.4412214457042931e-1, 4.2200027079979985e-1, 3.9962419984564707e-1,
|
||||
3.7700741021641815e-1, 3.5416352542049040e-1, 3.3110630575987648e-1, 3.0784964004153503e-1,
|
||||
2.8440753721127210e-1, 2.6079411791527585e-1, 2.3702360599436717e-1, 2.1311031991609142e-1,
|
||||
1.8906866414980636e-1, 1.6491312048997014e-1, 1.4065823933284954e-1, 1.1631863091190471e-1,
|
||||
9.1908956497132752e-2, 6.7443919563664176e-2, 4.2938256934941021e-2, 1.8406729905805101e-2
|
||||
}, {
|
||||
3.0679567629659761e-3, 1.5339206284988100e-2, 2.7608145778965740e-2, 3.9872927587739811e-2,
|
||||
5.2131704680283324e-2, 6.4382630929857465e-2, 7.6623861392031492e-2, 8.8853552582524600e-2,
|
||||
1.0106986275482782e-1, 1.1327095217756435e-1, 1.2545498341154623e-1, 1.3762012158648604e-1,
|
||||
1.4976453467732151e-1, 1.6188639378011183e-1, 1.7398387338746382e-1, 1.8605515166344663e-1,
|
||||
1.9809841071795356e-1, 2.1011183688046961e-1, 2.2209362097320351e-1, 2.3404195858354343e-1,
|
||||
2.4595505033579459e-1, 2.5783110216215899e-1, 2.6966832557291509e-1, 2.8146493792575794e-1,
|
||||
2.9321916269425863e-1, 3.0492922973540237e-1, 3.1659337555616585e-1, 3.2820984357909250e-1,
|
||||
3.3977688440682685e-1, 3.5129275608556709e-1, 3.6275572436739723e-1, 3.7416406297145793e-1,
|
||||
3.8551605384391885e-1, 3.9680998741671031e-1, 4.0804416286497869e-1, 4.1921688836322391e-1,
|
||||
4.3032648134008261e-1, 4.4137126873171667e-1, 4.5234958723377089e-1, 4.6325978355186015e-1,
|
||||
4.7410021465054997e-1, 4.8486924800079106e-1, 4.9556526182577254e-1, 5.0618664534515523e-1,
|
||||
5.1673179901764987e-1, 5.2719913478190128e-1, 5.3758707629564539e-1, 5.4789405917310019e-1,
|
||||
5.5811853122055610e-1, 5.6825895267013149e-1, 5.7831379641165559e-1, 5.8828154822264522e-1,
|
||||
5.9816070699634227e-1, 6.0794978496777363e-1, 6.1764730793780387e-1, 6.2725181549514408e-1,
|
||||
6.3676186123628420e-1, 6.4617601298331628e-1, 6.5549285299961535e-1, 6.6471097820334479e-1,
|
||||
6.7382900037875604e-1, 6.8284554638524808e-1, 6.9175925836415775e-1, 7.0056879394324834e-1,
|
||||
7.0927282643886558e-1, 7.1787004505573171e-1, 7.2635915508434601e-1, 7.3473887809596339e-1,
|
||||
7.4300795213512172e-1, 7.5116513190968637e-1, 7.5920918897838796e-1, 7.6713891193582040e-1,
|
||||
7.7495310659487382e-1, 7.8265059616657573e-1, 7.9023022143731003e-1, 7.9769084094339104e-1,
|
||||
8.0503133114296366e-1, 8.1225058658520388e-1, 8.1934752007679690e-1, 8.2632106284566342e-1,
|
||||
8.3317016470191319e-1, 8.3989379419599941e-1, 8.4649093877405202e-1, 8.5296060493036363e-1,
|
||||
8.5930181835700836e-1, 8.6551362409056898e-1, 8.7159508665595109e-1, 8.7754529020726124e-1,
|
||||
8.8336333866573158e-1, 8.8904835585466457e-1, 8.9459948563138258e-1, 9.0001589201616028e-1,
|
||||
9.0529675931811882e-1, 9.1044129225806714e-1, 9.1544871608826783e-1, 9.2031827670911048e-1,
|
||||
9.2504924078267758e-1, 9.2964089584318133e-1, 9.3409255040425887e-1, 9.3840353406310806e-1,
|
||||
9.4257319760144687e-1, 9.4660091308328353e-1, 9.5048607394948170e-1, 9.5422809510910567e-1,
|
||||
9.5782641302753291e-1, 9.6128048581132064e-1, 9.6458979328981265e-1, 9.6775383709347551e-1,
|
||||
9.7077214072895035e-1, 9.7364424965081187e-1, 9.7636973133002114e-1, 9.7894817531906220e-1,
|
||||
9.8137919331375456e-1, 9.8366241921173025e-1, 9.8579750916756737e-1, 9.8778414164457218e-1,
|
||||
9.8962201746320078e-1, 9.9131085984611544e-1, 9.9285041445986510e-1, 9.9424044945318790e-1,
|
||||
9.9548075549192694e-1, 9.9657114579055484e-1, 9.9751145614030345e-1, 9.9830154493389289e-1,
|
||||
9.9894129318685687e-1, 9.9943060455546173e-1, 9.9976940535121528e-1, 9.9995764455196390e-1,
|
||||
9.9999529380957619e-1, 9.9988234745421256e-1, 9.9961882249517864e-1, 9.9920475861836389e-1,
|
||||
9.9864021818026527e-1, 9.9792528619859600e-1, 9.9706007033948296e-1, 9.9604470090125197e-1,
|
||||
9.9487933079480562e-1, 9.9356413552059530e-1, 9.9209931314219180e-1, 9.9048508425645698e-1,
|
||||
9.8872169196032378e-1, 9.8680940181418553e-1, 9.8474850180190421e-1, 9.8253930228744124e-1,
|
||||
9.8018213596811743e-1, 9.7767735782450993e-1, 9.7502534506699412e-1, 9.7222649707893638e-1,
|
||||
9.6928123535654853e-1, 9.6619000344541262e-1, 9.6295326687368388e-1, 9.5957151308198452e-1,
|
||||
9.5604525134999652e-1, 9.5237501271976588e-1, 9.4856134991573038e-1, 9.4460483726148026e-1,
|
||||
9.4050607059326830e-1, 9.3626566717027826e-1, 9.3188426558166815e-1, 9.2736252565040111e-1,
|
||||
9.2270112833387852e-1, 9.1790077562139050e-1, 9.1296219042839821e-1, 9.0788611648766615e-1,
|
||||
9.0267331823725883e-1, 8.9732458070541832e-1, 8.9184070939234272e-1, 8.8622253014888064e-1,
|
||||
8.8047088905216087e-1, 8.7458665227817622e-1, 8.6857070597134101e-1, 8.6242395611104061e-1,
|
||||
8.5614732837519458e-1, 8.4974176800085266e-1, 8.4320823964184544e-1, 8.3654772722351201e-1,
|
||||
8.2976123379452305e-1, 8.2284978137582632e-1, 8.1581441080673378e-1, 8.0865618158817509e-1,
|
||||
8.0137617172314035e-1, 7.9397547755433728e-1, 7.8645521359908588e-1, 7.7881651238147609e-1,
|
||||
7.7106052426181371e-1, 7.6318841726338127e-1, 7.5520137689653655e-1, 7.4710060598018013e-1,
|
||||
7.3888732446061522e-1, 7.3056276922782759e-1, 7.2212819392921546e-1, 7.1358486878079375e-1,
|
||||
7.0493408037590510e-1, 6.9617713149146310e-1, 6.8731534089175927e-1, 6.7835004312986136e-1,
|
||||
6.6928258834663601e-1, 6.6011434206742048e-1, 6.5084668499638099e-1, 6.4148101280858316e-1,
|
||||
6.3201873593980906e-1, 6.2246127937415008e-1, 6.1281008242940982e-1, 6.0306659854034839e-1,
|
||||
5.9323229503980002e-1, 5.8330865293769851e-1, 5.7329716669804209e-1, 5.6319934401383409e-1,
|
||||
5.5301670558002758e-1, 5.4275078486451589e-1, 5.3240312787719801e-1, 5.2197529293715450e-1,
|
||||
5.1146885043797052e-1, 5.0088538261124094e-1, 4.9022648328829138e-1, 4.7949375766015329e-1,
|
||||
4.6868882203582785e-1, 4.5781330359887717e-1, 4.4686884016237416e-1, 4.3585707992225553e-1,
|
||||
4.2477968120910886e-1, 4.1363831223843461e-1, 4.0243465085941860e-1, 3.9117038430225404e-1,
|
||||
3.7984720892405138e-1, 3.6846682995337260e-1, 3.5703096123343031e-1, 3.4554132496398898e-1,
|
||||
3.3399965144200938e-1, 3.2240767880106985e-1, 3.1076715274961153e-1, 2.9907982630804053e-1,
|
||||
2.8734745954472962e-1, 2.7557181931095831e-1, 2.6375467897483157e-1, 2.5189781815421719e-1,
|
||||
2.4000302244874178e-1, 2.2807208317088606e-1, 2.1610679707621944e-1, 2.0410896609281684e-1,
|
||||
1.9208039704989247e-1, 1.8002290140569957e-1, 1.6793829497473128e-1, 1.5582839765426537e-1,
|
||||
1.4369503315029464e-1, 1.3154002870288334e-1, 1.1936521481099163e-1, 1.0717242495680916e-1,
|
||||
9.4963495329638908e-2, 8.2740264549375636e-2, 7.0504573389613856e-2, 5.8258264500435794e-2,
|
||||
4.6003182130914706e-2, 3.3741171851377705e-2, 2.1474080275469667e-2, 9.2037547820600207e-3
|
||||
}
|
||||
};
|
||||
static const double CosTables[9][256] =
|
||||
{
|
||||
{
|
||||
+7.0710678118654757e-1
|
||||
}, {
|
||||
+9.2387953251128674e-1, -3.8268343236508973e-1
|
||||
}, {
|
||||
+9.8078528040323043e-1, +5.5557023301960229e-1, -1.9509032201612819e-1, -8.3146961230254535e-1
|
||||
}, {
|
||||
+9.9518472667219693e-1, +8.8192126434835505e-1, +6.3439328416364549e-1, +2.9028467725446233e-1,
|
||||
-9.8017140329560645e-2, -4.7139673682599770e-1, -7.7301045336273699e-1, -9.5694033573220882e-1
|
||||
}, {
|
||||
+9.9879545620517241e-1, +9.7003125319454397e-1, +9.0398929312344334e-1, +8.0320753148064494e-1,
|
||||
+6.7155895484701833e-1, +5.1410274419322166e-1, +3.3688985339222005e-1, +1.4673047445536175e-1,
|
||||
-4.9067674327418008e-2, -2.4298017990326387e-1, -4.2755509343028186e-1, -5.9569930449243336e-1,
|
||||
-7.4095112535495888e-1, -8.5772861000027201e-1, -9.4154406518302070e-1, -9.8917650996478101e-1
|
||||
}, {
|
||||
+9.9969881869620425e-1, +9.9247953459870997e-1, +9.7570213003852857e-1, +9.4952818059303667e-1,
|
||||
+9.1420975570353069e-1, +8.7008699110871146e-1, +8.1758481315158371e-1, +7.5720884650648457e-1,
|
||||
+6.8954054473706694e-1, +6.1523159058062682e-1, +5.3499761988709726e-1, +4.4961132965460660e-1,
|
||||
+3.5989503653498828e-1, +2.6671275747489842e-1, +1.7096188876030136e-1, +7.3564563599667454e-2,
|
||||
-2.4541228522912142e-2, -1.2241067519921615e-1, -2.1910124015686966e-1, -3.1368174039889141e-1,
|
||||
-4.0524131400498975e-1, -4.9289819222978398e-1, -5.7580819141784534e-1, -6.5317284295377653e-1,
|
||||
-7.2424708295146678e-1, -7.8834642762660623e-1, -8.4485356524970712e-1, -8.9322430119551521e-1,
|
||||
-9.3299279883473885e-1, -9.6377606579543984e-1, -9.8527764238894122e-1, -9.9729045667869021e-1
|
||||
}, {
|
||||
+9.9992470183914450e-1, +9.9811811290014918e-1, +9.9390697000235606e-1, +9.8730141815785843e-1,
|
||||
+9.7831737071962765e-1, +9.6697647104485207e-1, +9.5330604035419386e-1, +9.3733901191257496e-1,
|
||||
+9.1911385169005777e-1, +8.9867446569395382e-1, +8.7607009419540660e-1, +8.5135519310526520e-1,
|
||||
+8.2458930278502529e-1, +7.9583690460888357e-1, +7.6516726562245896e-1, +7.3265427167241282e-1,
|
||||
+6.9837624940897292e-1, +6.6241577759017178e-1, +6.2485948814238645e-1, +5.8579785745643886e-1,
|
||||
+5.4532498842204646e-1, +5.0353838372571758e-1, +4.6053871095824001e-1, +4.1642956009763732e-1,
|
||||
+3.7131719395183760e-1, +3.2531029216226298e-1, +2.7851968938505306e-1, +2.3105810828067128e-1,
|
||||
+1.8303988795514106e-1, +1.3458070850712622e-1, +8.5797312344439880e-2, +3.6807222941358991e-2,
|
||||
-1.2271538285719823e-2, -6.1320736302208530e-2, -1.1022220729388306e-1, -1.5885814333386128e-1,
|
||||
-2.0711137619221845e-1, -2.5486565960451452e-1, -3.0200594931922808e-1, -3.4841868024943440e-1,
|
||||
-3.9399204006104799e-1, -4.3861623853852738e-1, -4.8218377207912272e-1, -5.2458968267846873e-1,
|
||||
-5.6573181078361323e-1, -6.0551104140432543e-1, -6.4383154288979128e-1, -6.8060099779545302e-1,
|
||||
-7.1573082528381859e-1, -7.4913639452345915e-1, -7.8073722857209449e-1, -8.1045719825259466e-1,
|
||||
-8.3822470555483808e-1, -8.6397285612158670e-1, -8.8763962040285382e-1, -9.0916798309052238e-1,
|
||||
-9.2850608047321548e-1, -9.4560732538052117e-1, -9.6043051941556579e-1, -9.7293995220556007e-1,
|
||||
-9.8310548743121629e-1, -9.9090263542778001e-1, -9.9631261218277800e-1, -9.9932238458834954e-1
|
||||
}, {
|
||||
+9.9998117528260111e-1, +9.9952941750109314e-1, +9.9847558057329477e-1, +9.9682029929116567e-1,
|
||||
+9.9456457073425542e-1, +9.9170975366909953e-1, +9.8825756773074946e-1, +9.8421009238692903e-1,
|
||||
+9.7956976568544052e-1, +9.7433938278557586e-1, +9.6852209427441738e-1, +9.6212140426904158e-1,
|
||||
+9.5514116830577078e-1, +9.4758559101774109e-1, +9.3945922360218992e-1, +9.3076696107898371e-1,
|
||||
+9.2151403934204201e-1, +9.1170603200542988e-1, +9.0134884704602203e-1, +8.9044872324475788e-1,
|
||||
+8.7901222642863353e-1, +8.6704624551569265e-1, +8.5455798836540053e-1, +8.4155497743689844e-1,
|
||||
+8.2804504525775580e-1, +8.1403632970594841e-1, +7.9953726910790501e-1, +7.8455659715557524e-1,
|
||||
+7.6910333764557970e-1, +7.5318679904361252e-1, +7.3681656887736990e-1, +7.2000250796138165e-1,
|
||||
+7.0275474445722530e-1, +6.8508366777270036e-1, +6.6699992230363747e-1, +6.4851440102211255e-1,
|
||||
+6.2963823891492710e-1, +6.1038280627630948e-1, +5.9075970185887428e-1, +5.7078074588696737e-1,
|
||||
+5.5045797293660481e-1, +5.2980362468629483e-1, +5.0883014254310699e-1, +4.8755016014843605e-1,
|
||||
+4.6597649576796613e-1, +4.4412214457042926e-1, +4.2200027079979979e-1, +3.9962419984564679e-1,
|
||||
+3.7700741021641831e-1, +3.5416352542049051e-1, +3.3110630575987643e-1, +3.0784964004153498e-1,
|
||||
+2.8440753721127182e-1, +2.6079411791527557e-1, +2.3702360599436734e-1, +2.1311031991609136e-1,
|
||||
+1.8906866414980628e-1, +1.6491312048997009e-1, +1.4065823933284924e-1, +1.1631863091190488e-1,
|
||||
+9.1908956497132696e-2, +6.7443919563664106e-2, +4.2938256934940959e-2, +1.8406729905804820e-2,
|
||||
-6.1358846491543929e-3, -3.0674803176636459e-2, -5.5195244349689913e-2, -7.9682437971430015e-2,
|
||||
-1.0412163387205460e-1, -1.2849811079379311e-1, -1.5279718525844330e-1, -1.7700422041214875e-1,
|
||||
-2.0110463484209182e-1, -2.2508391135979267e-1, -2.4892760574572012e-1, -2.7262135544994887e-1,
|
||||
-2.9615088824362384e-1, -3.1950203081601564e-1, -3.4266071731199427e-1, -3.6561299780477385e-1,
|
||||
-3.8834504669882619e-1, -4.1084317105790380e-1, -4.3309381885315190e-1, -4.5508358712634372e-1,
|
||||
-4.7679923006332192e-1, -4.9822766697278159e-1, -5.1935599016558964e-1, -5.4017147272989285e-1,
|
||||
-5.6066157619733592e-1, -5.8081395809576442e-1, -6.0061647938386875e-1, -6.2005721176328921e-1,
|
||||
-6.3912444486377573e-1, -6.5780669329707864e-1, -6.7609270357531581e-1, -6.9397146088965378e-1,
|
||||
-7.1143219574521654e-1, -7.2846439044822520e-1, -7.4505778544146595e-1, -7.6120238548426167e-1,
|
||||
-7.7688846567323233e-1, -7.9210657730021217e-1, -8.0684755354379933e-1, -8.2110251499110465e-1,
|
||||
-8.3486287498638001e-1, -8.4812034480329712e-1, -8.6086693863776709e-1, -8.7309497841829009e-1,
|
||||
-8.8479709843093779e-1, -8.9596624975618511e-1, -9.0659570451491533e-1, -9.1667905992104259e-1,
|
||||
-9.2621024213831138e-1, -9.3518350993894761e-1, -9.4359345816196039e-1, -9.5143502096900834e-1,
|
||||
-9.5870347489587149e-1, -9.6539444169768929e-1, -9.7150389098625178e-1, -9.7702814265775439e-1,
|
||||
-9.8196386910955524e-1, -9.8630809724459856e-1, -9.9005821026229701e-1, -9.9321194923479450e-1,
|
||||
-9.9576741446765982e-1, -9.9772306664419164e-1, -9.9907772775264536e-1, -9.9983058179582340e-1
|
||||
}, {
|
||||
+9.9999529380957619e-1, +9.9988234745421256e-1, +9.9961882249517864e-1, +9.9920475861836389e-1,
|
||||
+9.9864021818026527e-1, +9.9792528619859600e-1, +9.9706007033948296e-1, +9.9604470090125197e-1,
|
||||
+9.9487933079480562e-1, +9.9356413552059530e-1, +9.9209931314219180e-1, +9.9048508425645709e-1,
|
||||
+9.8872169196032378e-1, +9.8680940181418553e-1, +9.8474850180190421e-1, +9.8253930228744124e-1,
|
||||
+9.8018213596811743e-1, +9.7767735782450993e-1, +9.7502534506699412e-1, +9.7222649707893627e-1,
|
||||
+9.6928123535654853e-1, +9.6619000344541250e-1, +9.6295326687368388e-1, +9.5957151308198452e-1,
|
||||
+9.5604525134999641e-1, +9.5237501271976588e-1, +9.4856134991573027e-1, +9.4460483726148026e-1,
|
||||
+9.4050607059326830e-1, +9.3626566717027826e-1, +9.3188426558166815e-1, +9.2736252565040111e-1,
|
||||
+9.2270112833387863e-1, +9.1790077562139050e-1, +9.1296219042839821e-1, +9.0788611648766626e-1,
|
||||
+9.0267331823725883e-1, +8.9732458070541832e-1, +8.9184070939234272e-1, +8.8622253014888064e-1,
|
||||
+8.8047088905216075e-1, +8.7458665227817611e-1, +8.6857070597134090e-1, +8.6242395611104061e-1,
|
||||
+8.5614732837519447e-1, +8.4974176800085255e-1, +8.4320823964184544e-1, +8.3654772722351201e-1,
|
||||
+8.2976123379452305e-1, +8.2284978137582643e-1, +8.1581441080673378e-1, +8.0865618158817498e-1,
|
||||
+8.0137617172314024e-1, +7.9397547755433717e-1, +7.8645521359908577e-1, +7.7881651238147598e-1,
|
||||
+7.7106052426181382e-1, +7.6318841726338127e-1, +7.5520137689653655e-1, +7.4710060598018013e-1,
|
||||
+7.3888732446061511e-1, +7.3056276922782759e-1, +7.2212819392921535e-1, +7.1358486878079364e-1,
|
||||
+7.0493408037590499e-1, +6.9617713149146299e-1, +6.8731534089175916e-1, +6.7835004312986158e-1,
|
||||
+6.6928258834663601e-1, +6.6011434206742048e-1, +6.5084668499638099e-1, +6.4148101280858316e-1,
|
||||
+6.3201873593980906e-1, +6.2246127937415008e-1, +6.1281008242940971e-1, +6.0306659854034828e-1,
|
||||
+5.9323229503979980e-1, +5.8330865293769829e-1, +5.7329716669804232e-1, +5.6319934401383409e-1,
|
||||
+5.5301670558002758e-1, +5.4275078486451600e-1, +5.3240312787719801e-1, +5.2197529293715439e-1,
|
||||
+5.1146885043797052e-1, +5.0088538261124094e-1, +4.9022648328829110e-1, +4.7949375766015301e-1,
|
||||
+4.6868882203582796e-1, +4.5781330359887729e-1, +4.4686884016237433e-1, +4.3585707992225547e-1,
|
||||
+4.2477968120910881e-1, +4.1363831223843456e-1, +4.0243465085941854e-1, +3.9117038430225398e-1,
|
||||
+3.7984720892405111e-1, +3.6846682995337232e-1, +3.5703096123343003e-1, +3.4554132496398915e-1,
|
||||
+3.3399965144200949e-1, +3.2240767880107002e-1, +3.1076715274961147e-1, +2.9907982630804048e-1,
|
||||
+2.8734745954472957e-1, +2.7557181931095825e-1, +2.6375467897483151e-1, +2.5189781815421691e-1,
|
||||
+2.4000302244874150e-1, +2.2807208317088579e-1, +2.1610679707621960e-1, +2.0410896609281701e-1,
|
||||
+1.9208039704989238e-1, +1.8002290140569951e-1, +1.6793829497473123e-1, +1.5582839765426532e-1,
|
||||
+1.4369503315029458e-1, +1.3154002870288328e-1, +1.1936521481099135e-1, +1.0717242495680887e-1,
|
||||
+9.4963495329639061e-2, +8.2740264549375803e-2, +7.0504573389614009e-2, +5.8258264500435732e-2,
|
||||
+4.6003182130914644e-2, +3.3741171851377642e-2, +2.1474080275469605e-2, +9.2037547820599599e-3,
|
||||
-3.0679567629660156e-3, -1.5339206284988098e-2, -2.7608145778965698e-2, -3.9872927587739727e-2,
|
||||
-5.2131704680283192e-2, -6.4382630929857285e-2, -7.6623861392031506e-2, -8.8853552582524559e-2,
|
||||
-1.0106986275482775e-1, -1.1327095217756424e-1, -1.2545498341154607e-1, -1.3762012158648607e-1,
|
||||
-1.4976453467732151e-1, -1.6188639378011177e-1, -1.7398387338746371e-1, -1.8605515166344649e-1,
|
||||
-1.9809841071795362e-1, -2.1011183688046961e-1, -2.2209362097320348e-1, -2.3404195858354332e-1,
|
||||
-2.4595505033579448e-1, -2.5783110216215882e-1, -2.6966832557291509e-1, -2.8146493792575794e-1,
|
||||
-2.9321916269425857e-1, -3.0492922973540226e-1, -3.1659337555616573e-1, -3.2820984357909255e-1,
|
||||
-3.3977688440682685e-1, -3.5129275608556704e-1, -3.6275572436739711e-1, -3.7416406297145788e-1,
|
||||
-3.8551605384391890e-1, -3.9680998741671031e-1, -4.0804416286497863e-1, -4.1921688836322407e-1,
|
||||
-4.3032648134008272e-1, -4.4137126873171673e-1, -4.5234958723377089e-1, -4.6325978355186015e-1,
|
||||
-4.7410021465054991e-1, -4.8486924800079101e-1, -4.9556526182577237e-1, -5.0618664534515512e-1,
|
||||
-5.1673179901764965e-1, -5.2719913478190106e-1, -5.3758707629564562e-1, -5.4789405917310019e-1,
|
||||
-5.5811853122055610e-1, -5.6825895267013149e-1, -5.7831379641165548e-1, -5.8828154822264522e-1,
|
||||
-5.9816070699634216e-1, -6.0794978496777352e-1, -6.1764730793780376e-1, -6.2725181549514386e-1,
|
||||
-6.3676186123628431e-1, -6.4617601298331639e-1, -6.5549285299961546e-1, -6.6471097820334490e-1,
|
||||
-6.7382900037875604e-1, -6.8284554638524797e-1, -6.9175925836415764e-1, -7.0056879394324822e-1,
|
||||
-7.0927282643886547e-1, -7.1787004505573160e-1, -7.2635915508434579e-1, -7.3473887809596350e-1,
|
||||
-7.4300795213512172e-1, -7.5116513190968648e-1, -7.5920918897838807e-1, -7.6713891193582029e-1,
|
||||
-7.7495310659487382e-1, -7.8265059616657562e-1, -7.9023022143730992e-1, -7.9769084094339093e-1,
|
||||
-8.0503133114296344e-1, -8.1225058658520377e-1, -8.1934752007679701e-1, -8.2632106284566353e-1,
|
||||
-8.3317016470191319e-1, -8.3989379419599952e-1, -8.4649093877405202e-1, -8.5296060493036363e-1,
|
||||
-8.5930181835700836e-1, -8.6551362409056898e-1, -8.7159508665595087e-1, -8.7754529020726113e-1,
|
||||
-8.8336333866573169e-1, -8.8904835585466457e-1, -8.9459948563138270e-1, -9.0001589201616017e-1,
|
||||
-9.0529675931811870e-1, -9.1044129225806714e-1, -9.1544871608826772e-1, -9.2031827670911048e-1,
|
||||
-9.2504924078267747e-1, -9.2964089584318121e-1, -9.3409255040425876e-1, -9.3840353406310817e-1,
|
||||
-9.4257319760144687e-1, -9.4660091308328353e-1, -9.5048607394948170e-1, -9.5422809510910556e-1,
|
||||
-9.5782641302753291e-1, -9.6128048581132064e-1, -9.6458979328981265e-1, -9.6775383709347540e-1,
|
||||
-9.7077214072895024e-1, -9.7364424965081187e-1, -9.7636973133002114e-1, -9.7894817531906220e-1,
|
||||
-9.8137919331375456e-1, -9.8366241921173025e-1, -9.8579750916756737e-1, -9.8778414164457218e-1,
|
||||
-9.8962201746320078e-1, -9.9131085984611544e-1, -9.9285041445986510e-1, -9.9424044945318790e-1,
|
||||
-9.9548075549192694e-1, -9.9657114579055484e-1, -9.9751145614030345e-1, -9.9830154493389289e-1,
|
||||
-9.9894129318685687e-1, -9.9943060455546173e-1, -9.9976940535121528e-1, -9.9995764455196390e-1
|
||||
}
|
||||
};
|
||||
|
||||
static const int ShuffleTables[9][256] =
|
||||
{
|
||||
{
|
||||
0x00
|
||||
}, {
|
||||
0x00, 0x01
|
||||
}, {
|
||||
0x00, 0x02, 0x03, 0x01
|
||||
}, {
|
||||
0x00, 0x04, 0x06, 0x02, 0x03, 0x07, 0x05, 0x01
|
||||
}, {
|
||||
0x00, 0x08, 0x0C, 0x04, 0x06, 0x0E, 0x0A, 0x02, 0x03, 0x0B, 0x0F, 0x07, 0x05, 0x0D, 0x09, 0x01
|
||||
}, {
|
||||
0x00, 0x10, 0x18, 0x08, 0x0C, 0x1C, 0x14, 0x04, 0x06, 0x16, 0x1E, 0x0E, 0x0A, 0x1A, 0x12, 0x02,
|
||||
0x03, 0x13, 0x1B, 0x0B, 0x0F, 0x1F, 0x17, 0x07, 0x05, 0x15, 0x1D, 0x0D, 0x09, 0x19, 0x11, 0x01
|
||||
}, {
|
||||
0x00, 0x20, 0x30, 0x10, 0x18, 0x38, 0x28, 0x08, 0x0C, 0x2C, 0x3C, 0x1C, 0x14, 0x34, 0x24, 0x04,
|
||||
0x06, 0x26, 0x36, 0x16, 0x1E, 0x3E, 0x2E, 0x0E, 0x0A, 0x2A, 0x3A, 0x1A, 0x12, 0x32, 0x22, 0x02,
|
||||
0x03, 0x23, 0x33, 0x13, 0x1B, 0x3B, 0x2B, 0x0B, 0x0F, 0x2F, 0x3F, 0x1F, 0x17, 0x37, 0x27, 0x07,
|
||||
0x05, 0x25, 0x35, 0x15, 0x1D, 0x3D, 0x2D, 0x0D, 0x09, 0x29, 0x39, 0x19, 0x11, 0x31, 0x21, 0x01
|
||||
}, {
|
||||
0x00, 0x40, 0x60, 0x20, 0x30, 0x70, 0x50, 0x10, 0x18, 0x58, 0x78, 0x38, 0x28, 0x68, 0x48, 0x08,
|
||||
0x0C, 0x4C, 0x6C, 0x2C, 0x3C, 0x7C, 0x5C, 0x1C, 0x14, 0x54, 0x74, 0x34, 0x24, 0x64, 0x44, 0x04,
|
||||
0x06, 0x46, 0x66, 0x26, 0x36, 0x76, 0x56, 0x16, 0x1E, 0x5E, 0x7E, 0x3E, 0x2E, 0x6E, 0x4E, 0x0E,
|
||||
0x0A, 0x4A, 0x6A, 0x2A, 0x3A, 0x7A, 0x5A, 0x1A, 0x12, 0x52, 0x72, 0x32, 0x22, 0x62, 0x42, 0x02,
|
||||
0x03, 0x43, 0x63, 0x23, 0x33, 0x73, 0x53, 0x13, 0x1B, 0x5B, 0x7B, 0x3B, 0x2B, 0x6B, 0x4B, 0x0B,
|
||||
0x0F, 0x4F, 0x6F, 0x2F, 0x3F, 0x7F, 0x5F, 0x1F, 0x17, 0x57, 0x77, 0x37, 0x27, 0x67, 0x47, 0x07,
|
||||
0x05, 0x45, 0x65, 0x25, 0x35, 0x75, 0x55, 0x15, 0x1D, 0x5D, 0x7D, 0x3D, 0x2D, 0x6D, 0x4D, 0x0D,
|
||||
0x09, 0x49, 0x69, 0x29, 0x39, 0x79, 0x59, 0x19, 0x11, 0x51, 0x71, 0x31, 0x21, 0x61, 0x41, 0x01
|
||||
}, {
|
||||
0x00, 0x80, 0xC0, 0x40, 0x60, 0xE0, 0xA0, 0x20, 0x30, 0xB0, 0xF0, 0x70, 0x50, 0xD0, 0x90, 0x10,
|
||||
0x18, 0x98, 0xD8, 0x58, 0x78, 0xF8, 0xB8, 0x38, 0x28, 0xA8, 0xE8, 0x68, 0x48, 0xC8, 0x88, 0x08,
|
||||
0x0C, 0x8C, 0xCC, 0x4C, 0x6C, 0xEC, 0xAC, 0x2C, 0x3C, 0xBC, 0xFC, 0x7C, 0x5C, 0xDC, 0x9C, 0x1C,
|
||||
0x14, 0x94, 0xD4, 0x54, 0x74, 0xF4, 0xB4, 0x34, 0x24, 0xA4, 0xE4, 0x64, 0x44, 0xC4, 0x84, 0x04,
|
||||
0x06, 0x86, 0xC6, 0x46, 0x66, 0xE6, 0xA6, 0x26, 0x36, 0xB6, 0xF6, 0x76, 0x56, 0xD6, 0x96, 0x16,
|
||||
0x1E, 0x9E, 0xDE, 0x5E, 0x7E, 0xFE, 0xBE, 0x3E, 0x2E, 0xAE, 0xEE, 0x6E, 0x4E, 0xCE, 0x8E, 0x0E,
|
||||
0x0A, 0x8A, 0xCA, 0x4A, 0x6A, 0xEA, 0xAA, 0x2A, 0x3A, 0xBA, 0xFA, 0x7A, 0x5A, 0xDA, 0x9A, 0x1A,
|
||||
0x12, 0x92, 0xD2, 0x52, 0x72, 0xF2, 0xB2, 0x32, 0x22, 0xA2, 0xE2, 0x62, 0x42, 0xC2, 0x82, 0x02,
|
||||
0x03, 0x83, 0xC3, 0x43, 0x63, 0xE3, 0xA3, 0x23, 0x33, 0xB3, 0xF3, 0x73, 0x53, 0xD3, 0x93, 0x13,
|
||||
0x1B, 0x9B, 0xDB, 0x5B, 0x7B, 0xFB, 0xBB, 0x3B, 0x2B, 0xAB, 0xEB, 0x6B, 0x4B, 0xCB, 0x8B, 0x0B,
|
||||
0x0F, 0x8F, 0xCF, 0x4F, 0x6F, 0xEF, 0xAF, 0x2F, 0x3F, 0xBF, 0xFF, 0x7F, 0x5F, 0xDF, 0x9F, 0x1F,
|
||||
0x17, 0x97, 0xD7, 0x57, 0x77, 0xF7, 0xB7, 0x37, 0x27, 0xA7, 0xE7, 0x67, 0x47, 0xC7, 0x87, 0x07,
|
||||
0x05, 0x85, 0xC5, 0x45, 0x65, 0xE5, 0xA5, 0x25, 0x35, 0xB5, 0xF5, 0x75, 0x55, 0xD5, 0x95, 0x15,
|
||||
0x1D, 0x9D, 0xDD, 0x5D, 0x7D, 0xFD, 0xBD, 0x3D, 0x2D, 0xAD, 0xED, 0x6D, 0x4D, 0xCD, 0x8D, 0x0D,
|
||||
0x09, 0x89, 0xC9, 0x49, 0x69, 0xE9, 0xA9, 0x29, 0x39, 0xB9, 0xF9, 0x79, 0x59, 0xD9, 0x99, 0x19,
|
||||
0x11, 0x91, 0xD1, 0x51, 0x71, 0xF1, 0xB1, 0x31, 0x21, 0xA1, 0xE1, 0x61, 0x41, 0xC1, 0x81, 0x01
|
||||
}
|
||||
};
|
||||
328
C/unpack.c
Normal file
328
C/unpack.c
Normal file
@@ -0,0 +1,328 @@
|
||||
#include "tables.h"
|
||||
#include "unpack.h"
|
||||
#include "bit_allocation.h"
|
||||
#include <string.h>
|
||||
#include "scale_factors.h"
|
||||
#include "utility.h"
|
||||
#include "huffCodes.h"
|
||||
|
||||
at9_status UnpackFrame(frame* frame, bit_reader_cxt* br)
|
||||
{
|
||||
const int block_count = frame->config->ChannelConfig.BlockCount;
|
||||
|
||||
for (int i = 0; i < block_count; i++)
|
||||
{
|
||||
ERROR_CHECK(UnpackBlock(&frame->Blocks[i], br));
|
||||
}
|
||||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
at9_status UnpackBlock(block* block, bit_reader_cxt* br)
|
||||
{
|
||||
ERROR_CHECK(ReadBlockHeader(block, br));
|
||||
|
||||
if (block->BlockType == LFE)
|
||||
{
|
||||
ERROR_CHECK(UnpackLfeBlock(block, br));
|
||||
}
|
||||
else
|
||||
{
|
||||
ERROR_CHECK(UnpackStandardBlock(block, br));
|
||||
}
|
||||
|
||||
align_position(br, 8);
|
||||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
at9_status ReadBlockHeader(block* block, bit_reader_cxt* br)
|
||||
{
|
||||
int firstInSuperframe = block->Frame->FrameIndex == 0;
|
||||
block->FirstInSuperframe = !read_int(br, 1);
|
||||
block->ReuseBandParams = read_int(br, 1);
|
||||
|
||||
if (block->FirstInSuperframe && block->ReuseBandParams && block->BlockType != LFE)
|
||||
{
|
||||
return ERR_UNPACK_REUSE_BAND_PARAMS_INVALID;
|
||||
}
|
||||
|
||||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
at9_status UnpackStandardBlock(block* block, bit_reader_cxt* br)
|
||||
{
|
||||
if (!block->ReuseBandParams)
|
||||
{
|
||||
ERROR_CHECK(ReadBandParams(block, br));
|
||||
}
|
||||
|
||||
ERROR_CHECK(ReadGradientParams(block, br));
|
||||
ERROR_CHECK(CreateGradient(block));
|
||||
ERROR_CHECK(ReadStereoParams(block, br));
|
||||
ERROR_CHECK(ReadExtensionParams(block, br));
|
||||
|
||||
for (int i = 0; i < block->ChannelCount; i++)
|
||||
{
|
||||
channel* channel = &block->Channels[i];
|
||||
UpdateCodedUnits(channel);
|
||||
|
||||
ERROR_CHECK(read_scale_factors(channel, br));
|
||||
CalculateMask(channel);
|
||||
CalculatePrecisions(channel);
|
||||
CalculateSpectrumCodebookIndex(channel);
|
||||
|
||||
ERROR_CHECK(ReadSpectra(channel, br));
|
||||
ERROR_CHECK(ReadSpectraFine(channel, br));
|
||||
}
|
||||
|
||||
block->QuantizationUnitsPrev = block->BandExtensionEnabled ? block->ExtensionUnit : block->QuantizationUnitCount;
|
||||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
at9_status ReadBandParams(block* block, bit_reader_cxt* br)
|
||||
{
|
||||
const int minBandCount = MinBandCount[block->config->HighSampleRate];
|
||||
const int maxExtensionBand = MaxExtensionBand[block->config->HighSampleRate];
|
||||
block->BandCount = read_int(br, 4) + minBandCount;
|
||||
block->QuantizationUnitCount = BandToQuantUnitCount[block->BandCount];
|
||||
|
||||
if (block->BandCount < minBandCount || block->BandCount >
|
||||
MaxBandCount[block->config->SampleRateIndex])
|
||||
{
|
||||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
if (block->BlockType == Stereo)
|
||||
{
|
||||
block->StereoBand = read_int(br, 4);
|
||||
block->StereoBand += minBandCount;
|
||||
block->StereoQuantizationUnit = BandToQuantUnitCount[block->StereoBand];
|
||||
}
|
||||
else
|
||||
{
|
||||
block->StereoBand = block->BandCount;
|
||||
}
|
||||
|
||||
block->BandExtensionEnabled = read_int(br, 1);
|
||||
if (block->BandExtensionEnabled)
|
||||
{
|
||||
block->ExtensionBand = read_int(br, 4);
|
||||
block->ExtensionBand += minBandCount;
|
||||
|
||||
if (block->ExtensionBand < block->BandCount || block->ExtensionBand > maxExtensionBand)
|
||||
{
|
||||
return ERR_UNPACK_BAND_PARAMS_INVALID;
|
||||
}
|
||||
|
||||
block->ExtensionUnit = BandToQuantUnitCount[block->ExtensionBand];
|
||||
}
|
||||
else
|
||||
{
|
||||
block->ExtensionBand = block->BandCount;
|
||||
block->ExtensionUnit = block->QuantizationUnitCount;
|
||||
}
|
||||
|
||||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
at9_status ReadGradientParams(block* block, bit_reader_cxt* br)
|
||||
{
|
||||
block->GradientMode = read_int(br, 2);
|
||||
if (block->GradientMode > 0)
|
||||
{
|
||||
block->GradientEndUnit = 31;
|
||||
block->GradientEndValue = 31;
|
||||
block->GradientStartUnit = read_int(br, 5);
|
||||
block->GradientStartValue = read_int(br, 5);
|
||||
}
|
||||
else
|
||||
{
|
||||
block->GradientStartUnit = read_int(br, 6);
|
||||
block->GradientEndUnit = read_int(br, 6) + 1;
|
||||
block->GradientStartValue = read_int(br, 5);
|
||||
block->GradientEndValue = read_int(br, 5);
|
||||
}
|
||||
block->GradientBoundary = read_int(br, 4);
|
||||
|
||||
if (block->GradientBoundary > block->QuantizationUnitCount)
|
||||
{
|
||||
return ERR_UNPACK_GRAD_BOUNDARY_INVALID;
|
||||
}
|
||||
if (block->GradientStartUnit < 1 || block->GradientStartUnit >= 48)
|
||||
{
|
||||
return ERR_UNPACK_GRAD_START_UNIT_OOB;
|
||||
}
|
||||
if (block->GradientEndUnit < 1 || block->GradientEndUnit >= 48)
|
||||
{
|
||||
return ERR_UNPACK_GRAD_END_UNIT_OOB;
|
||||
}
|
||||
if (block->GradientStartUnit > block->GradientEndUnit)
|
||||
{
|
||||
return ERR_UNPACK_GRAD_END_UNIT_INVALID;
|
||||
}
|
||||
if (block->GradientStartValue < 0 || block->GradientStartValue >= 32)
|
||||
{
|
||||
return ERR_UNPACK_GRAD_START_VALUE_OOB;
|
||||
}
|
||||
if (block->GradientEndValue < 0 || block->GradientEndValue >= 32)
|
||||
{
|
||||
return ERR_UNPACK_GRAD_END_VALUE_OOB;
|
||||
}
|
||||
|
||||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
at9_status ReadStereoParams(block* block, bit_reader_cxt* br)
|
||||
{
|
||||
if (block->BlockType != Stereo) return ERR_SUCCESS;
|
||||
|
||||
block->PrimaryChannelIndex = read_int(br, 1);
|
||||
block->HasJointStereoSigns = read_int(br, 1);
|
||||
if (block->HasJointStereoSigns)
|
||||
{
|
||||
for (int i = block->StereoQuantizationUnit; i < block->QuantizationUnitCount; i++)
|
||||
{
|
||||
block->JointStereoSigns[i] = read_int(br, 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
memset(block->JointStereoSigns, 0, sizeof(block->JointStereoSigns));
|
||||
}
|
||||
|
||||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
at9_status ReadExtensionParams(block* block, bit_reader_cxt* br)
|
||||
{
|
||||
if (block->BandExtensionEnabled)
|
||||
{
|
||||
return ERR_NOT_IMPLEMENTED;
|
||||
}
|
||||
block->HasExtensionData = read_int(br, 1);
|
||||
|
||||
if (!block->HasExtensionData) return ERR_SUCCESS;
|
||||
|
||||
return ERR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
void UpdateCodedUnits(channel* channel)
|
||||
{
|
||||
if (channel->Block->PrimaryChannelIndex == channel->ChannelIndex)
|
||||
{
|
||||
channel->CodedQuantUnits = channel->Block->QuantizationUnitCount;
|
||||
}
|
||||
else
|
||||
{
|
||||
channel->CodedQuantUnits = channel->Block->StereoQuantizationUnit;
|
||||
}
|
||||
}
|
||||
|
||||
void CalculateSpectrumCodebookIndex(channel* channel)
|
||||
{
|
||||
memset(channel->CodebookSet, 0, sizeof(channel->CodebookSet));
|
||||
const int quantUnits = channel->CodedQuantUnits;
|
||||
int* sf = channel->ScaleFactors;
|
||||
|
||||
if (quantUnits <= 1) return;
|
||||
if (channel->config->HighSampleRate) return;
|
||||
|
||||
// Temporarily setting this value allows for simpler code by
|
||||
// making the last value a non-special case.
|
||||
const int originalScaleTmp = sf[quantUnits];
|
||||
sf[quantUnits] = sf[quantUnits - 1];
|
||||
|
||||
int avg = 0;
|
||||
if (quantUnits > 12)
|
||||
{
|
||||
for (int i = 0; i < 12; i++)
|
||||
{
|
||||
avg += sf[i];
|
||||
}
|
||||
avg = (avg + 6) / 12;
|
||||
}
|
||||
|
||||
for (int i = 8; i < quantUnits; i++)
|
||||
{
|
||||
const int prevSf = sf[i - 1];
|
||||
const int nextSf = sf[i + 1];
|
||||
const int minSf = min(prevSf, nextSf);
|
||||
if (sf[i] - minSf >= 3 || sf[i] - prevSf + sf[i] - nextSf >= 3)
|
||||
{
|
||||
channel->CodebookSet[i] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 12; i < quantUnits; i++)
|
||||
{
|
||||
if (channel->CodebookSet[i] == 0)
|
||||
{
|
||||
const int minSf = min(sf[i - 1], sf[i + 1]);
|
||||
if (sf[i] - minSf >= 2 && sf[i] >= avg - (QuantUnitToCoeffCount[i] == 16 ? 1 : 0))
|
||||
{
|
||||
channel->CodebookSet[i] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sf[quantUnits] = originalScaleTmp;
|
||||
}
|
||||
|
||||
at9_status ReadSpectra(channel* channel, bit_reader_cxt* br)
|
||||
{
|
||||
int values[16];
|
||||
memset(channel->QuantizedSpectra, 0, sizeof(channel->QuantizedSpectra));
|
||||
const int maxHuffPrecision = MaxHuffPrecision[channel->config->HighSampleRate];
|
||||
|
||||
for (int i = 0; i < channel->CodedQuantUnits; i++)
|
||||
{
|
||||
const int subbandCount = QuantUnitToCoeffCount[i];
|
||||
const int precision = channel->Precisions[i] + 1;
|
||||
if (precision <= maxHuffPrecision)
|
||||
{
|
||||
const HuffmanCodebook* huff = &HuffmanSpectrum[channel->CodebookSet[i]][precision][QuantUnitToCodebookIndex[i]];
|
||||
const int groupCount = subbandCount >> huff->ValueCountPower;
|
||||
for (int j = 0; j < groupCount; j++)
|
||||
{
|
||||
values[j] = ReadHuffmanValue(huff, br, FALSE);
|
||||
}
|
||||
|
||||
DecodeHuffmanValues(channel->QuantizedSpectra, QuantUnitToCoeffIndex[i], subbandCount, huff, values);
|
||||
}
|
||||
else
|
||||
{
|
||||
const int subbandIndex = QuantUnitToCoeffIndex[i];
|
||||
for (int j = subbandIndex; j < QuantUnitToCoeffIndex[i + 1]; j++)
|
||||
{
|
||||
channel->QuantizedSpectra[j] = read_signed_int(br, precision);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
at9_status ReadSpectraFine(channel* channel, bit_reader_cxt* br)
|
||||
{
|
||||
memset(channel->QuantizedSpectraFine, 0, sizeof(channel->QuantizedSpectraFine));
|
||||
|
||||
for (int i = 0; i < channel->CodedQuantUnits; i++)
|
||||
{
|
||||
if (channel->PrecisionsFine[i] > 0)
|
||||
{
|
||||
const int overflowBits = channel->PrecisionsFine[i] + 1;
|
||||
const int startSubband = QuantUnitToCoeffIndex[i];
|
||||
const int endSubband = QuantUnitToCoeffIndex[i + 1];
|
||||
|
||||
for (int j = startSubband; j < endSubband; j++)
|
||||
{
|
||||
channel->QuantizedSpectraFine[j] = read_signed_int(br, overflowBits);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
at9_status UnpackLfeBlock(block* block, bit_reader_cxt* br)
|
||||
{
|
||||
return ERR_NOT_IMPLEMENTED;
|
||||
}
|
||||
20
C/unpack.h
Normal file
20
C/unpack.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include "bit_reader.h"
|
||||
#include "error_codes.h"
|
||||
#include "structures.h"
|
||||
|
||||
at9_status UnpackFrame(frame* frame, bit_reader_cxt* br);
|
||||
at9_status UnpackBlock(block* block, bit_reader_cxt* br);
|
||||
at9_status ReadBlockHeader(block* block, bit_reader_cxt* br);
|
||||
at9_status UnpackStandardBlock(block* block, bit_reader_cxt* br);
|
||||
at9_status ReadBandParams(block* block, bit_reader_cxt* br);
|
||||
at9_status ReadGradientParams(block* block, bit_reader_cxt* br);
|
||||
at9_status ReadStereoParams(block* block, bit_reader_cxt* br);
|
||||
at9_status ReadExtensionParams(block* block, bit_reader_cxt* br);
|
||||
void UpdateCodedUnits(channel* channel);
|
||||
void CalculateSpectrumCodebookIndex(channel* channel);
|
||||
|
||||
at9_status ReadSpectra(channel* channel, bit_reader_cxt* br);
|
||||
at9_status ReadSpectraFine(channel* channel, bit_reader_cxt* br);
|
||||
|
||||
at9_status UnpackLfeBlock(block* block, bit_reader_cxt* br);
|
||||
20
C/utility.c
Normal file
20
C/utility.c
Normal file
@@ -0,0 +1,20 @@
|
||||
#include "utility.h"
|
||||
#include <limits.h>
|
||||
|
||||
int max(int a, int b) { return a > b ? a : b; }
|
||||
int min(int a, int b) { return a > b ? b : a; }
|
||||
|
||||
int SignExtend32(int value, int bits)
|
||||
{
|
||||
const int shift = 8 * sizeof(int) - bits;
|
||||
return (value << shift) >> shift;
|
||||
}
|
||||
|
||||
short Clamp16(int value)
|
||||
{
|
||||
if (value > SHRT_MAX)
|
||||
return SHRT_MAX;
|
||||
if (value < SHRT_MIN)
|
||||
return SHRT_MIN;
|
||||
return (short)value;
|
||||
}
|
||||
9
C/utility.h
Normal file
9
C/utility.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#define FALSE 0
|
||||
#define TRUE 1
|
||||
|
||||
int max(int a, int b);
|
||||
int min(int a, int b);
|
||||
int SignExtend32(int value, int bits);
|
||||
short Clamp16(int value);
|
||||
Reference in New Issue
Block a user