atrac3.c File Reference

Atrac 3 compatible decoder. More...

#include <math.h>
#include <stddef.h>
#include <stdio.h>
#include "avcodec.h"
#include "internal.h"
#include "get_bits.h"
#include "dsputil.h"
#include "bytestream.h"
#include "fft.h"
#include "fmtconvert.h"
#include "atrac.h"
#include "atrac3data.h"

Go to the source code of this file.

Data Structures

struct  gain_info
struct  gain_block
struct  tonal_component
struct  channel_unit
struct  ATRAC3Context

Macros

#define JOINT_STEREO   0x12
#define STEREO   0x2
#define SAMPLES_PER_FRAME   1024
#define MDCT_SIZE   512
#define INTERPOLATE(old, new, nsample)   ((old) + (nsample)*0.125*((new)-(old)))

Functions

static void IMLT (ATRAC3Context *q, float *pInput, float *pOutput, int odd_band)
 Regular 512 points IMDCT without overlapping, with the exception of the swapping of odd bands caused by the reverse spectra of the QMF.
static int decode_bytes (const uint8_t *inbuffer, uint8_t *out, int bytes)
 Atrac 3 indata descrambling, only used for data coming from the rm container.
static av_cold int init_atrac3_transforms (ATRAC3Context *q, int is_float)
static av_cold int atrac3_decode_close (AVCodecContext *avctx)
 Atrac3 uninit, free all allocated memory.
static void readQuantSpectralCoeffs (GetBitContext *gb, int selector, int codingFlag, int *mantissas, int numCodes)
 / * Mantissa decoding
static int decodeSpectrum (GetBitContext *gb, float *pOut)
 Restore the quantized band spectrum coefficients.
static int decodeTonalComponents (GetBitContext *gb, tonal_component *pComponent, int numBands)
 Restore the quantized tonal components.
static int decodeGainControl (GetBitContext *gb, gain_block *pGb, int numBands)
 Decode gain parameters for the coded bands.
static void gainCompensateAndOverlap (float *pIn, float *pPrev, float *pOut, gain_info *pGain1, gain_info *pGain2)
 Apply gain parameters and perform the MDCT overlapping part.
static int addTonalComponents (float *pSpectrum, int numComponents, tonal_component *pComponent)
 Combine the tonal band spectrum and regular band spectrum Return position of the last tonal coefficient.
static void reverseMatrixing (float *su1, float *su2, int *pPrevCode, int *pCurrCode)
static void getChannelWeights (int indx, int flag, float ch[2])
static void channelWeighting (float *su1, float *su2, int *p3)
static int decodeChannelSoundUnit (ATRAC3Context *q, GetBitContext *gb, channel_unit *pSnd, float *pOut, int channelNum, int codingMode)
 Decode a Sound Unit.
static int decodeFrame (ATRAC3Context *q, const uint8_t *databuf, float **out_samples)
 Frame handling.
static int atrac3_decode_frame (AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
 Atrac frame decoding.
static av_cold int atrac3_decode_init (AVCodecContext *avctx)
 Atrac3 initialization.

Variables

static float mdct_window [MDCT_SIZE]
static VLC spectral_coeff_tab [7]
static float gain_tab1 [16]
static float gain_tab2 [31]
static DSPContext dsp
AVCodec ff_atrac3_decoder

Detailed Description

Atrac 3 compatible decoder.

This decoder handles Sony's ATRAC3 data.

Container formats used to store atrac 3 data: RealMedia (.rm), RIFF WAV (.wav, .at3), Sony OpenMG (.oma, .aa3).

To use this decoder, a calling application must supply the extradata bytes provided in the containers above.

Definition in file atrac3.c.

Macro Definition Documentation

#define INTERPOLATE (   old,
  new,
  nsample 
)    ((old) + (nsample)*0.125*((new)-(old)))

Definition at line 557 of file atrac3.c.

Referenced by channelWeighting(), and reverseMatrixing().

#define JOINT_STEREO   0x12
#define MDCT_SIZE   512

Definition at line 54 of file atrac3.c.

Referenced by IMLT().

#define SAMPLES_PER_FRAME   1024
#define STEREO   0x2

Definition at line 51 of file atrac3.c.

Referenced by atrac3_decode_init().

Function Documentation

static int addTonalComponents ( float *  pSpectrum,
int  numComponents,
tonal_component pComponent 
)
static

Combine the tonal band spectrum and regular band spectrum Return position of the last tonal coefficient.

Parameters
pSpectrumoutput spectrum buffer
numComponentsamount of tonal components
pComponenttonal components for this band

Definition at line 539 of file atrac3.c.

Referenced by decodeChannelSoundUnit().

static av_cold int atrac3_decode_close ( AVCodecContext avctx)
static

Atrac3 uninit, free all allocated memory.

Definition at line 227 of file atrac3.c.

Referenced by atrac3_decode_init().

static int atrac3_decode_frame ( AVCodecContext avctx,
void data,
int *  got_frame_ptr,
AVPacket avpkt 
)
static

Atrac frame decoding.

Parameters
avctxpointer to the AVCodecContext

Definition at line 837 of file atrac3.c.

static av_cold int atrac3_decode_init ( AVCodecContext avctx)
static

Atrac3 initialization.

Parameters
avctxpointer to the AVCodecContext

Definition at line 905 of file atrac3.c.

static void channelWeighting ( float *  su1,
float *  su2,
int *  p3 
)
static

Definition at line 634 of file atrac3.c.

Referenced by decodeFrame().

static int decode_bytes ( const uint8_t *  inbuffer,
uint8_t *  out,
int  bytes 
)
static

Atrac 3 indata descrambling, only used for data coming from the rm container.

Parameters
inbufferpointer to 8 bit array of indata
outpointer to 8 bit array of outdata
bytesamount of bytes

Definition at line 181 of file atrac3.c.

Referenced by atrac3_decode_frame().

static int decodeChannelSoundUnit ( ATRAC3Context q,
GetBitContext gb,
channel_unit pSnd,
float *  pOut,
int  channelNum,
int  codingMode 
)
static

Decode a Sound Unit.

Parameters
gbthe GetBit context
pSndthe channel unit to be used
pOutthe decoded samples before IQMF in float representation
channelNumchannel number
codingModethe coding mode (JOINT_STEREO or regular stereo/mono)

Definition at line 671 of file atrac3.c.

Referenced by decodeFrame().

static int decodeFrame ( ATRAC3Context q,
const uint8_t *  databuf,
float **  out_samples 
)
static

Frame handling.

Parameters
qAtrac3 private context
databufthe input data

Definition at line 737 of file atrac3.c.

Referenced by atrac3_decode_frame().

static int decodeGainControl ( GetBitContext gb,
gain_block pGb,
int  numBands 
)
static

Decode gain parameters for the coded bands.

Parameters
gbthe GetBit context
pGbthe gainblock for the current band
numBandsamount of coded bands

Definition at line 443 of file atrac3.c.

Referenced by decodeChannelSoundUnit().

static int decodeSpectrum ( GetBitContext gb,
float *  pOut 
)
static

Restore the quantized band spectrum coefficients.

Parameters
gbthe GetBit context
pOutdecoded band spectrum
Returns
outSubbands subband counter, fix for broken specification/files

Definition at line 308 of file atrac3.c.

Referenced by decodeChannelSoundUnit().

static int decodeTonalComponents ( GetBitContext gb,
tonal_component pComponent,
int  numBands 
)
static

Restore the quantized tonal components.

Parameters
gbthe GetBit context
pComponenttone component
numBandsamount of coded bands

Definition at line 366 of file atrac3.c.

Referenced by decodeChannelSoundUnit().

static void gainCompensateAndOverlap ( float *  pIn,
float *  pPrev,
float *  pOut,
gain_info pGain1,
gain_info pGain2 
)
static

Apply gain parameters and perform the MDCT overlapping part.

Parameters
pIninput float buffer
pPrevprevious float buffer to perform overlap against
pOutoutput float buffer
pGain1current band gain info
pGain2next band gain info

Definition at line 482 of file atrac3.c.

Referenced by decodeChannelSoundUnit().

static void getChannelWeights ( int  indx,
int  flag,
float  ch[2] 
)
static

Definition at line 621 of file atrac3.c.

Referenced by channelWeighting().

static void IMLT ( ATRAC3Context q,
float *  pInput,
float *  pOutput,
int  odd_band 
)
static

Regular 512 points IMDCT without overlapping, with the exception of the swapping of odd bands caused by the reverse spectra of the QMF.

Parameters
pInputfloat input
pOutputfloat output
odd_band1 if the band is an odd band

Reverse the odd bands before IMDCT, this is an effect of the QMF transform or it gives better compression to do it this way. FIXME: It should be possible to handle this in imdct_calc for that to happen a modification of the prerotation step of all SIMD code and C code is needed. Or fix the functions before so they generate a pre reversed spectrum.

Definition at line 147 of file atrac3.c.

Referenced by decodeChannelSoundUnit().

static av_cold int init_atrac3_transforms ( ATRAC3Context q,
int  is_float 
)
static

Definition at line 204 of file atrac3.c.

Referenced by atrac3_decode_init().

static void readQuantSpectralCoeffs ( GetBitContext gb,
int  selector,
int  codingFlag,
int *  mantissas,
int  numCodes 
)
static

/ * Mantissa decoding

Parameters
gbthe GetBit context
selectorwhat table is the output values coded with
codingFlagconstant length coding or variable length coding
mantissasmantissa output table
numCodesamount of values to get

Definition at line 250 of file atrac3.c.

Referenced by decodeSpectrum(), and decodeTonalComponents().

static void reverseMatrixing ( float *  su1,
float *  su2,
int *  pPrevCode,
int *  pCurrCode 
)
static

Definition at line 559 of file atrac3.c.

Referenced by decodeFrame().

Variable Documentation

AVCodec ff_atrac3_decoder
Initial value:
{
.name = "atrac3",
.priv_data_size = sizeof(ATRAC3Context),
.long_name = NULL_IF_CONFIG_SMALL("Atrac 3 (Adaptive TRansform Acoustic Coding 3)"),
}

Definition at line 1074 of file atrac3.c.

float gain_tab1[16]
static

Definition at line 133 of file atrac3.c.

Referenced by atrac3_decode_init(), and gainCompensateAndOverlap().

float gain_tab2[31]
static

Definition at line 134 of file atrac3.c.

Referenced by atrac3_decode_init(), and gainCompensateAndOverlap().

float mdct_window[MDCT_SIZE]
static

Definition at line 131 of file atrac3.c.

Referenced by IMLT(), and init_atrac3_transforms().

VLC spectral_coeff_tab[7]
static

Definition at line 132 of file atrac3.c.