FFmpeg
Data Structures | Macros | Functions | Variables
atrac3.c File Reference
#include <math.h>
#include <stddef.h>
#include "libavutil/attributes.h"
#include "libavutil/float_dsp.h"
#include "libavutil/libm.h"
#include "libavutil/mem.h"
#include "libavutil/mem_internal.h"
#include "libavutil/thread.h"
#include "libavutil/tx.h"
#include "avcodec.h"
#include "bytestream.h"
#include "codec_internal.h"
#include "decode.h"
#include "get_bits.h"
#include "atrac.h"
#include "atrac3data.h"

Go to the source code of this file.

Data Structures

struct  GainBlock
 
struct  TonalComponent
 
struct  ChannelUnit
 
struct  ATRAC3Context
 

Macros

#define MIN_CHANNELS   1
 
#define MAX_CHANNELS   8
 
#define MAX_JS_PAIRS   8 / 2
 
#define JOINT_STEREO   0x12
 
#define SINGLE   0x2
 
#define SAMPLES_PER_FRAME   1024
 
#define MDCT_SIZE   512
 
#define ATRAC3_VLC_BITS   8
 
#define INTERPOLATE(old, new, nsample)   ((old) + (nsample) * 0.125 * ((new) - (old)))
 

Functions

static void imlt (ATRAC3Context *q, float *input, float *output, 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. More...
 
static int decode_bytes (const uint8_t *input, uint8_t *out, int bytes)
 
static av_cold void init_imdct_window (void)
 
static av_cold int atrac3_decode_close (AVCodecContext *avctx)
 
static void read_quant_spectral_coeffs (GetBitContext *gb, int selector, int coding_flag, int *mantissas, int num_codes)
 Mantissa decoding. More...
 
static int decode_spectrum (GetBitContext *gb, float *output)
 Restore the quantized band spectrum coefficients. More...
 
static int decode_tonal_components (GetBitContext *gb, TonalComponent *components, int num_bands)
 Restore the quantized tonal components. More...
 
static int decode_gain_control (GetBitContext *gb, GainBlock *block, int num_bands)
 Decode gain parameters for the coded bands. More...
 
static int add_tonal_components (float *spectrum, int num_components, TonalComponent *components)
 Combine the tonal band spectrum and regular band spectrum. More...
 
static void reverse_matrixing (float *su1, float *su2, int *prev_code, int *curr_code)
 
static void get_channel_weights (int index, int flag, float ch[2])
 
static void channel_weighting (float *su1, float *su2, int *p3)
 
static int decode_channel_sound_unit (ATRAC3Context *q, GetBitContext *gb, ChannelUnit *snd, float *output, int channel_num, int coding_mode)
 Decode a Sound Unit. More...
 
static int decode_frame (AVCodecContext *avctx, const uint8_t *databuf, float **out_samples)
 
static int al_decode_frame (AVCodecContext *avctx, const uint8_t *databuf, int size, float **out_samples)
 
static int atrac3_decode_frame (AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
 
static int atrac3al_decode_frame (AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
 
static av_cold void atrac3_init_static_data (void)
 
static av_cold int atrac3_decode_init (AVCodecContext *avctx)
 

Variables

static float mdct_window [MDCT_SIZE]
 
static VLCElem atrac3_vlc_table [7 *1<< ATRAC3_VLC_BITS]
 
static VLC spectral_coeff_tab [7]
 
const FFCodec ff_atrac3_decoder
 
const FFCodec ff_atrac3al_decoder
 

Detailed Description

ATRAC3 compatible decoder. This decoder handles Sony's ATRAC3 data.

Container formats used to store ATRAC3 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

◆ MIN_CHANNELS

#define MIN_CHANNELS   1

Definition at line 55 of file atrac3.c.

◆ MAX_CHANNELS

#define MAX_CHANNELS   8

Definition at line 56 of file atrac3.c.

◆ MAX_JS_PAIRS

#define MAX_JS_PAIRS   8 / 2

Definition at line 57 of file atrac3.c.

◆ JOINT_STEREO

#define JOINT_STEREO   0x12

Definition at line 59 of file atrac3.c.

◆ SINGLE

#define SINGLE   0x2

Definition at line 60 of file atrac3.c.

◆ SAMPLES_PER_FRAME

#define SAMPLES_PER_FRAME   1024

Definition at line 62 of file atrac3.c.

◆ MDCT_SIZE

#define MDCT_SIZE   512

Definition at line 63 of file atrac3.c.

◆ ATRAC3_VLC_BITS

#define ATRAC3_VLC_BITS   8

Definition at line 65 of file atrac3.c.

◆ INTERPOLATE

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

Definition at line 469 of file atrac3.c.

Function Documentation

◆ imlt()

static void imlt ( ATRAC3Context q,
float input,
float output,
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
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 135 of file atrac3.c.

Referenced by decode_channel_sound_unit().

◆ decode_bytes()

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

Definition at line 161 of file atrac3.c.

Referenced by atrac3_decode_frame().

◆ init_imdct_window()

static av_cold void init_imdct_window ( void  )
static

Definition at line 184 of file atrac3.c.

Referenced by atrac3_init_static_data().

◆ atrac3_decode_close()

static av_cold int atrac3_decode_close ( AVCodecContext avctx)
static

Definition at line 199 of file atrac3.c.

◆ read_quant_spectral_coeffs()

static void read_quant_spectral_coeffs ( GetBitContext gb,
int  selector,
int  coding_flag,
int *  mantissas,
int  num_codes 
)
static

Mantissa decoding.

Parameters
selectorwhich table the output values are coded with
coding_flagconstant length coding or variable length coding
mantissasmantissa output table
num_codesnumber of values to get

Definition at line 219 of file atrac3.c.

Referenced by decode_spectrum(), and decode_tonal_components().

◆ decode_spectrum()

static int decode_spectrum ( GetBitContext gb,
float output 
)
static

Restore the quantized band spectrum coefficients.

Returns
subband count, fix for broken specification/files

Definition at line 273 of file atrac3.c.

Referenced by decode_channel_sound_unit().

◆ decode_tonal_components()

static int decode_tonal_components ( GetBitContext gb,
TonalComponent components,
int  num_bands 
)
static

Restore the quantized tonal components.

Parameters
componentstonal components
num_bandsnumber of coded bands

Definition at line 331 of file atrac3.c.

Referenced by decode_channel_sound_unit().

◆ decode_gain_control()

static int decode_gain_control ( GetBitContext gb,
GainBlock block,
int  num_bands 
)
static

Decode gain parameters for the coded bands.

Parameters
blockthe gainblock for the current band
num_bandsamount of coded bands

Definition at line 415 of file atrac3.c.

Referenced by decode_channel_sound_unit().

◆ add_tonal_components()

static int add_tonal_components ( float spectrum,
int  num_components,
TonalComponent components 
)
static

Combine the tonal band spectrum and regular band spectrum.

Parameters
spectrumoutput spectrum buffer
num_componentsnumber of tonal components
componentstonal components for this band
Returns
position of the last tonal coefficient

Definition at line 451 of file atrac3.c.

Referenced by decode_channel_sound_unit().

◆ reverse_matrixing()

static void reverse_matrixing ( float su1,
float su2,
int *  prev_code,
int *  curr_code 
)
static

Definition at line 472 of file atrac3.c.

Referenced by decode_frame().

◆ get_channel_weights()

static void get_channel_weights ( int  index,
int  flag,
float  ch[2] 
)
static

Definition at line 534 of file atrac3.c.

Referenced by channel_weighting().

◆ channel_weighting()

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

Definition at line 547 of file atrac3.c.

Referenced by decode_frame().

◆ decode_channel_sound_unit()

static int decode_channel_sound_unit ( ATRAC3Context q,
GetBitContext gb,
ChannelUnit snd,
float output,
int  channel_num,
int  coding_mode 
)
static

Decode a Sound Unit.

Parameters
sndthe channel unit to be used
outputthe decoded samples before IQMF in float representation
channel_numchannel number
coding_modethe coding mode (JOINT_STEREO or single channels)

Definition at line 578 of file atrac3.c.

Referenced by al_decode_frame(), and decode_frame().

◆ decode_frame()

static int decode_frame ( AVCodecContext avctx,
const uint8_t *  databuf,
float **  out_samples 
)
static

Definition at line 645 of file atrac3.c.

Referenced by atrac3_decode_frame().

◆ al_decode_frame()

static int al_decode_frame ( AVCodecContext avctx,
const uint8_t *  databuf,
int  size,
float **  out_samples 
)
static

Definition at line 759 of file atrac3.c.

Referenced by atrac3al_decode_frame().

◆ atrac3_decode_frame()

static int atrac3_decode_frame ( AVCodecContext avctx,
AVFrame frame,
int *  got_frame_ptr,
AVPacket avpkt 
)
static

Definition at line 794 of file atrac3.c.

◆ atrac3al_decode_frame()

static int atrac3al_decode_frame ( AVCodecContext avctx,
AVFrame frame,
int *  got_frame_ptr,
AVPacket avpkt 
)
static

Definition at line 833 of file atrac3.c.

◆ atrac3_init_static_data()

static av_cold void atrac3_init_static_data ( void  )
static

Definition at line 854 of file atrac3.c.

Referenced by atrac3_decode_init().

◆ atrac3_decode_init()

static av_cold int atrac3_decode_init ( AVCodecContext avctx)
static

Definition at line 876 of file atrac3.c.

Variable Documentation

◆ mdct_window

float mdct_window[MDCT_SIZE]
static

Definition at line 125 of file atrac3.c.

Referenced by apply_mdct(), imlt(), and init_imdct_window().

◆ atrac3_vlc_table

VLCElem atrac3_vlc_table[7 *1<< ATRAC3_VLC_BITS]
static

Definition at line 126 of file atrac3.c.

Referenced by atrac3_init_static_data().

◆ spectral_coeff_tab

VLC spectral_coeff_tab[7]
static

Definition at line 127 of file atrac3.c.

Referenced by atrac3_init_static_data(), and read_quant_spectral_coeffs().

◆ ff_atrac3_decoder

const FFCodec ff_atrac3_decoder
Initial value:
= {
.p.name = "atrac3",
CODEC_LONG_NAME("ATRAC3 (Adaptive TRansform Acoustic Coding 3)"),
.p.type = AVMEDIA_TYPE_AUDIO,
.priv_data_size = sizeof(ATRAC3Context),
.p.capabilities =
AV_CODEC_CAP_SUBFRAMES |
.p.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
}

Definition at line 1021 of file atrac3.c.

◆ ff_atrac3al_decoder

const FFCodec ff_atrac3al_decoder
Initial value:
= {
.p.name = "atrac3al",
CODEC_LONG_NAME("ATRAC3 AL (Adaptive TRansform Acoustic Coding 3 Advanced Lossless)"),
.p.type = AVMEDIA_TYPE_AUDIO,
.priv_data_size = sizeof(ATRAC3Context),
.p.capabilities =
AV_CODEC_CAP_SUBFRAMES |
.p.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
}

Definition at line 1040 of file atrac3.c.

AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:66
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:43
atrac3al_decode_frame
static int atrac3al_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
Definition: atrac3.c:833
AV_CODEC_ID_ATRAC3
@ AV_CODEC_ID_ATRAC3
Definition: codec_id.h:478
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:311
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:296
ATRAC3Context
Definition: atrac3.c:93
AV_CODEC_ID_ATRAC3AL
@ AV_CODEC_ID_ATRAC3AL
Definition: codec_id.h:529
atrac3_decode_frame
static int atrac3_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
Definition: atrac3.c:794
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:368
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
atrac3_decode_close
static av_cold int atrac3_decode_close(AVCodecContext *avctx)
Definition: atrac3.c:199
atrac3_decode_init
static av_cold int atrac3_decode_init(AVCodecContext *avctx)
Definition: atrac3.c:876