FFmpeg
Macros | Functions | Variables
atrac3plusdsp.c File Reference
#include <math.h>
#include "libavutil/float_dsp.h"
#include "libavutil/libm.h"
#include "avcodec.h"
#include "sinewin.h"
#include "fft.h"
#include "atrac3plus.h"

Go to the source code of this file.

Macros

#define ATRAC3P_MDCT_SIZE   (ATRAC3P_SUBBAND_SAMPLES * 2)
 
#define TWOPI   (2 * M_PI)
 
#define DEQUANT_PHASE(ph)   (((ph) & 0x1F) << 6)
 

Functions

av_cold void ff_atrac3p_init_imdct (AVCodecContext *avctx, FFTContext *mdct_ctx)
 Initialize IMDCT transform. More...
 
av_cold void ff_atrac3p_init_wave_synth (void)
 Initialize sine waves synthesizer. More...
 
static void waves_synth (Atrac3pWaveSynthParams *synth_param, Atrac3pWavesData *waves_info, Atrac3pWaveEnvelope *envelope, AVFloatDSPContext *fdsp, int invert_phase, int reg_offset, float *out)
 Synthesize sine waves according to given parameters. More...
 
void ff_atrac3p_generate_tones (Atrac3pChanUnitCtx *ch_unit, AVFloatDSPContext *fdsp, int ch_num, int sb, float *out)
 Synthesize sine waves for a particular subband. More...
 
void ff_atrac3p_power_compensation (Atrac3pChanUnitCtx *ctx, AVFloatDSPContext *fdsp, int ch_index, float *sp, int rng_index, int sb)
 Perform power compensation aka noise dithering. More...
 
void ff_atrac3p_imdct (AVFloatDSPContext *fdsp, FFTContext *mdct_ctx, float *pIn, float *pOut, int wind_id, int sb)
 Regular IMDCT and windowing without overlapping, with spectrum reversal in the odd subbands. More...
 
void ff_atrac3p_ipqf (FFTContext *dct_ctx, Atrac3pIPQFChannelCtx *hist, const float *in, float *out)
 Subband synthesis filter based on the polyphase quadrature (pseudo-QMF) filter bank. More...
 

Variables

const uint16_t ff_atrac3p_qu_to_spec_pos [33]
 Map quant unit number to its position in the spectrum. More...
 
const float ff_atrac3p_sf_tab [64]
 
const float ff_atrac3p_mant_tab [8]
 
static float sine_table [2048]
 wave table More...
 
static float hann_window [256]
 Hann windowing function. More...
 
static float amp_sf_tab [64]
 scalefactors for quantized amplitudes More...
 
static const uint8_t subband_to_powgrp [ATRAC3P_SUBBANDS]
 
static const float noise_tab [1024]
 
static const float pwc_levs [16]
 Noise level table for power compensation. More...
 
static const uint8_t subband_to_qu [17]
 Map subband number to quant unit number. More...
 
static const int mod23_lut [26]
 
static const float ipqf_coeffs1 [ATRAC3P_PQF_FIR_LEN][16]
 
static const float ipqf_coeffs2 [ATRAC3P_PQF_FIR_LEN][16]
 

Detailed Description

DSP functions for ATRAC3+ decoder.

Definition in file atrac3plusdsp.c.

Macro Definition Documentation

◆ ATRAC3P_MDCT_SIZE

#define ATRAC3P_MDCT_SIZE   (ATRAC3P_SUBBAND_SAMPLES * 2)

Definition at line 78 of file atrac3plusdsp.c.

◆ TWOPI

#define TWOPI   (2 * M_PI)

Definition at line 89 of file atrac3plusdsp.c.

◆ DEQUANT_PHASE

#define DEQUANT_PHASE (   ph)    (((ph) & 0x1F) << 6)

Definition at line 91 of file atrac3plusdsp.c.

Function Documentation

◆ ff_atrac3p_init_imdct()

av_cold void ff_atrac3p_init_imdct ( AVCodecContext avctx,
FFTContext mdct_ctx 
)

Initialize IMDCT transform.

Parameters
[in]avctxptr to the AVCodecContext
[in]mdct_ctxpointer to MDCT transform context

Definition at line 80 of file atrac3plusdsp.c.

Referenced by atrac3p_decode_init().

◆ ff_atrac3p_init_wave_synth()

av_cold void ff_atrac3p_init_wave_synth ( void  )

Initialize sine waves synthesizer.

Definition at line 97 of file atrac3plusdsp.c.

Referenced by atrac3p_decode_init().

◆ waves_synth()

static void waves_synth ( Atrac3pWaveSynthParams synth_param,
Atrac3pWavesData waves_info,
Atrac3pWaveEnvelope envelope,
AVFloatDSPContext fdsp,
int  invert_phase,
int  reg_offset,
float *  out 
)
static

Synthesize sine waves according to given parameters.

Parameters
[in]synth_paramptr to common synthesis parameters
[in]waves_infoparameters for each sine wave
[in]envelopeenvelope data for all waves in a group
[in]fdspptr to floating-point DSP context
[in]invert_phaseflag indicating 180° phase shift
[in]reg_offsetregion offset for trimming envelope data
[out]outreceives sythesized data

Definition at line 125 of file atrac3plusdsp.c.

Referenced by ff_atrac3p_generate_tones().

◆ ff_atrac3p_generate_tones()

void ff_atrac3p_generate_tones ( Atrac3pChanUnitCtx ch_unit,
AVFloatDSPContext fdsp,
int  ch_num,
int  sb,
float *  out 
)

Synthesize sine waves for a particular subband.

Parameters
[in]ch_unitpointer to the channel unit context
[in]fdsppointer to float DSP context
[in]ch_numwhich channel to process
[in]sbwhich subband to process
[out]outreceives processed data

Definition at line 184 of file atrac3plusdsp.c.

Referenced by reconstruct_frame().

◆ ff_atrac3p_power_compensation()

void ff_atrac3p_power_compensation ( Atrac3pChanUnitCtx ctx,
AVFloatDSPContext fdsp,
int  ch_index,
float *  sp,
int  rng_index,
int  sb_num 
)

Perform power compensation aka noise dithering.

Parameters
[in]ctxptr to the channel context
[in]fdsppointer to float DSP context
[in]ch_indexwhich channel to process
[in,out]spptr to channel spectrum to process
[in]rng_indexindicates which RNG table to use
[in]sb_numwhich subband to process

Definition at line 418 of file atrac3plusdsp.c.

Referenced by decode_residual_spectrum().

◆ ff_atrac3p_imdct()

void ff_atrac3p_imdct ( AVFloatDSPContext fdsp,
FFTContext mdct_ctx,
float *  pIn,
float *  pOut,
int  wind_id,
int  sb 
)

Regular IMDCT and windowing without overlapping, with spectrum reversal in the odd subbands.

Parameters
[in]fdsppointer to float DSP context
[in]mdct_ctxpointer to MDCT transform context
[in]pInfloat input
[out]pOutfloat output
[in]wind_idwhich MDCT window to apply
[in]sbsubband number

Definition at line 464 of file atrac3plusdsp.c.

Referenced by reconstruct_frame().

◆ ff_atrac3p_ipqf()

void ff_atrac3p_ipqf ( FFTContext dct_ctx,
Atrac3pIPQFChannelCtx hist,
const float *  in,
float *  out 
)

Subband synthesis filter based on the polyphase quadrature (pseudo-QMF) filter bank.

Parameters
[in]dct_ctxptr to the pre-initialized IDCT context
[in,out]histptr to the filter history
[in]ininput data to process
[out]outreceives processed data

Definition at line 605 of file atrac3plusdsp.c.

Referenced by reconstruct_frame().

Variable Documentation

◆ ff_atrac3p_qu_to_spec_pos

const uint16_t ff_atrac3p_qu_to_spec_pos[33]
Initial value:
= {
0, 16, 32, 48, 64, 80, 96, 112,
128, 160, 192, 224, 256, 288, 320, 352,
384, 448, 512, 576, 640, 704, 768, 896,
1024, 1152, 1280, 1408, 1536, 1664, 1792, 1920,
2048
}

Map quant unit number to its position in the spectrum.

To get the number of spectral lines in each quant unit do the following: num_specs = qu_to_spec_pos[i+1] - qu_to_spec_pos[i]

Definition at line 42 of file atrac3plusdsp.c.

Referenced by decode_residual_spectrum(), decode_spectrum(), and ff_atrac3p_power_compensation().

◆ ff_atrac3p_sf_tab

const float ff_atrac3p_sf_tab[64]
Initial value:
= {
0.027852058, 0.0350914, 0.044212341, 0.055704117, 0.0701828,
0.088424683, 0.11140823, 0.1403656, 0.17684937, 0.22281647, 0.2807312, 0.35369873,
0.44563293, 0.5614624, 0.70739746, 0.89126587, 1.1229248, 1.4147949, 1.7825317,
2.2458496, 2.8295898, 3.5650635, 4.4916992, 5.6591797, 7.130127, 8.9833984,
11.318359, 14.260254, 17.966797, 22.636719, 28.520508, 35.933594, 45.273438,
57.041016, 71.867188, 90.546875, 114.08203, 143.73438, 181.09375, 228.16406,
287.46875, 362.1875, 456.32812, 574.9375, 724.375, 912.65625, 1149.875,
1448.75, 1825.3125, 2299.75, 2897.5, 3650.625, 4599.5, 5795.0,
7301.25, 9199.0, 11590.0, 14602.5, 18398.0, 23180.0, 29205.0,
36796.0, 46360.0, 58410.0
}

Definition at line 52 of file atrac3plusdsp.c.

Referenced by decode_residual_spectrum(), and ff_atrac3p_power_compensation().

◆ ff_atrac3p_mant_tab

const float ff_atrac3p_mant_tab[8]
Initial value:
= {
0.0,
0.74801636,
0.44882202,
0.32058716,
0.20400238,
0.1496048,
0.07239151,
0.035619736
}

Definition at line 67 of file atrac3plusdsp.c.

Referenced by decode_residual_spectrum(), and ff_atrac3p_power_compensation().

◆ sine_table

float sine_table[2048]
static

wave table

Definition at line 93 of file atrac3plusdsp.c.

Referenced by ff_atrac3p_init_wave_synth(), and waves_synth().

◆ hann_window

float hann_window[256]
static

Hann windowing function.

Definition at line 94 of file atrac3plusdsp.c.

Referenced by ff_atrac3p_generate_tones(), ff_atrac3p_init_wave_synth(), and waves_synth().

◆ amp_sf_tab

float amp_sf_tab[64]
static

scalefactors for quantized amplitudes

Definition at line 95 of file atrac3plusdsp.c.

Referenced by ff_atrac3p_init_wave_synth(), and waves_synth().

◆ subband_to_powgrp

const uint8_t subband_to_powgrp[ATRAC3P_SUBBANDS]
static
Initial value:
= {
0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4
}

Definition at line 251 of file atrac3plusdsp.c.

Referenced by ff_atrac3p_power_compensation().

◆ noise_tab

const float noise_tab[1024]
static

Definition at line 256 of file atrac3plusdsp.c.

Referenced by ff_atrac3p_power_compensation().

◆ pwc_levs

const float pwc_levs[16]
static
Initial value:
= {
3.96875, 3.15625, 2.5, 2.0, 1.59375, 1.25, 1.0, 0.78125,
0.625, 0.5, 0.40625, 0.3125, 0.25, 0.1875, 0.15625, 0.0
}

Noise level table for power compensation.

Equ: pow(2.0f, (double)(6 - i) / 3.0f) where i = 0...15

Definition at line 408 of file atrac3plusdsp.c.

Referenced by ff_atrac3p_power_compensation().

◆ subband_to_qu

const uint8_t subband_to_qu[17]
static
Initial value:
= {
0, 8, 12, 16, 18, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32
}

Map subband number to quant unit number.

Definition at line 414 of file atrac3plusdsp.c.

Referenced by ff_atrac3p_power_compensation().

◆ mod23_lut

const int mod23_lut[26]
static
Initial value:
= {
23, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 0
}

Definition at line 496 of file atrac3plusdsp.c.

Referenced by ff_atrac3p_ipqf().

◆ ipqf_coeffs1

const float ipqf_coeffs1[ATRAC3P_PQF_FIR_LEN][16]
static

Definition at line 502 of file atrac3plusdsp.c.

Referenced by ff_atrac3p_ipqf().

◆ ipqf_coeffs2

const float ipqf_coeffs2[ATRAC3P_PQF_FIR_LEN][16]
static

Definition at line 554 of file atrac3plusdsp.c.

Referenced by ff_atrac3p_ipqf().