FFmpeg
atrac3plus.h
Go to the documentation of this file.
1 /*
2  * ATRAC3+ compatible decoder
3  *
4  * Copyright (c) 2010-2013 Maxim Poliakovski
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
28 #ifndef AVCODEC_ATRAC3PLUS_H
29 #define AVCODEC_ATRAC3PLUS_H
30 
31 #include <stdint.h>
32 
33 #include "libavutil/float_dsp.h"
34 #include "atrac.h"
35 #include "avcodec.h"
36 #include "fft.h"
37 #include "get_bits.h"
38 
40 #define ATRAC3P_SUBBANDS 16
41 #define ATRAC3P_SUBBAND_SAMPLES 128
42 #define ATRAC3P_FRAME_SAMPLES (ATRAC3P_SUBBAND_SAMPLES * ATRAC3P_SUBBANDS)
43 
44 #define ATRAC3P_PQF_FIR_LEN 12
45 
46 
47 #define ATRAC3P_POWER_COMP_OFF 15
48 
49 
55 };
56 
58 typedef struct Atrac3pIPQFChannelCtx {
59  DECLARE_ALIGNED(32, float, buf1)[ATRAC3P_PQF_FIR_LEN * 2][8];
60  DECLARE_ALIGNED(32, float, buf2)[ATRAC3P_PQF_FIR_LEN * 2][8];
61  int pos;
63 
65 typedef struct Atrac3pWaveEnvelope {
68  int start_pos;
69  int stop_pos;
71 
73 typedef struct Atrac3pWavesData {
76  int num_wavs;
79 
81 typedef struct Atrac3pWaveParam {
82  int freq_index;
83  int amp_sf;
84  int amp_index;
87 
89 typedef struct Atrac3pChanParams {
90  int ch_num;
92  int fill_mode;
93  int split_point;
94  int table_type;
95  int qu_wordlen[32];
96  int qu_sf_idx[32];
97  int qu_tab_idx[32];
98  int16_t spectrum[2048];
99  uint8_t power_levs[5];
100 
101  /* imdct window shape history (2 frames) for overlapping. */
102  uint8_t wnd_shape_hist[2][ATRAC3P_SUBBANDS];
103  uint8_t *wnd_shape;
104  uint8_t *wnd_shape_prev;
105 
106  /* gain control data history (2 frames) for overlapping. */
107  AtracGainInfo gain_data_hist[2][ATRAC3P_SUBBANDS];
111 
112  /* tones data history (2 frames) for overlapping. */
113  Atrac3pWavesData tones_info_hist[2][ATRAC3P_SUBBANDS];
114  Atrac3pWavesData *tones_info;
115  Atrac3pWavesData *tones_info_prev;
117 
118 /* Per-unit sine wave parameters */
119 typedef struct Atrac3pWaveSynthParams {
123  uint8_t tone_sharing[ATRAC3P_SUBBANDS];
124  uint8_t tone_master[ATRAC3P_SUBBANDS];
125  uint8_t invert_phase[ATRAC3P_SUBBANDS];
127  Atrac3pWaveParam waves[48];
129 
131 typedef struct Atrac3pChanUnitCtx {
132  /* channel unit variables */
133  int unit_type;
134  int num_quant_units;
135  int num_subbands;
138  int mute_flag;
143  uint8_t swap_channels[ATRAC3P_SUBBANDS];
144  uint8_t negate_coeffs[ATRAC3P_SUBBANDS];
145  Atrac3pChanParams channels[2];
146 
147  /* Variables related to GHA tones */
148  Atrac3pWaveSynthParams wave_synth_hist[2];
149  Atrac3pWaveSynthParams *waves_info;
150  Atrac3pWaveSynthParams *waves_info_prev;
151 
152  Atrac3pIPQFChannelCtx ipqf_ctx[2];
153  DECLARE_ALIGNED(32, float, prev_buf)[2][ATRAC3P_FRAME_SAMPLES];
155 
159 void ff_atrac3p_init_vlcs(void);
160 
171  int num_channels, AVCodecContext *avctx);
172 
179 void ff_atrac3p_init_imdct(AVCodecContext *avctx, FFTContext *mdct_ctx);
180 
184 void ff_atrac3p_init_wave_synth(void);
185 
196  int ch_num, int sb, float *out);
197 
209  int ch_index, float *sp, int rng_index, int sb_num);
210 
222 void ff_atrac3p_imdct(AVFloatDSPContext *fdsp, FFTContext *mdct_ctx, float *pIn,
223  float *pOut, int wind_id, int sb);
224 
235  const float *in, float *out);
236 
237 extern const uint16_t ff_atrac3p_qu_to_spec_pos[33];
238 extern const float ff_atrac3p_sf_tab[64];
239 extern const float ff_atrac3p_mant_tab[8];
240 
241 #endif /* AVCODEC_ATRAC3PLUS_H */
const uint16_t ff_atrac3p_qu_to_spec_pos[33]
Map quant unit number to its position in the spectrum.
Definition: atrac3plusdsp.c:42
void ff_atrac3p_init_wave_synth(void)
Initialize sine waves synthesizer.
Definition: atrac3plusdsp.c:97
int num_tone_bands
number of PQF bands with tones
Definition: atrac3plus.h:122
int num_coded_subbands
number of subbands with coded spectrum
Definition: atrac3plus.h:137
int table_type
table type: 0 - tone?, 1- noise?
Definition: atrac3plus.h:94
int num_wavs
number of sine waves in the group
Definition: atrac3plus.h:76
int used_quant_units
number of quant units with coded spectrum
Definition: atrac3plus.h:136
#define ATRAC3P_SUBBANDS
Global unit sizes.
Definition: atrac3plus.h:40
AtracGainInfo * gain_data_prev
gain control data for previous frame
Definition: atrac3plus.h:109
struct Atrac3pChanParams Atrac3pChanParams
Sound channel parameters.
int ff_atrac3p_decode_channel_unit(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, int num_channels, AVCodecContext *avctx)
Decode bitstream data of a channel unit.
Definition: atrac3plus.c:1757
int stop_pos
stop position expressed in n*4 samples
Definition: atrac3plus.h:69
struct Atrac3pChanUnitCtx Atrac3pChanUnitCtx
Channel unit parameters.
#define ATRAC3P_PQF_FIR_LEN
length of the prototype FIR of the PQF
Definition: atrac3plus.h:44
int amp_index
quantized amplitude index
Definition: atrac3plus.h:84
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
Definition: mem.h:120
Parameters of a single sine wave.
Definition: atrac3plus.h:81
Atrac3pWaveEnvelope pend_env
pending envelope from the previous frame
Definition: atrac3plus.h:74
ATRAC common header.
bitstream reader API header.
int tones_index
total sum of tones in this unit
Definition: atrac3plus.h:126
uint8_t * wnd_shape
IMDCT window shape for current frame.
Definition: atrac3plus.h:103
int noise_level_index
global noise level index
Definition: atrac3plus.h:141
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...
Definition: atrac3plusdsp.c:464
Amplitude envelope of a group of sine waves.
Definition: atrac3plus.h:65
struct Atrac3pIPQFChannelCtx Atrac3pIPQFChannelCtx
Per-channel IPQF history.
uint8_t * wnd_shape_prev
IMDCT window shape for previous frame.
Definition: atrac3plus.h:104
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.
Definition: atrac3plusdsp.c:605
Parameters of a group of sine waves.
Definition: atrac3plus.h:73
int noise_table_index
global noise RNG table index
Definition: atrac3plus.h:142
int amplitude_mode
1 - low range, 0 - high range
Definition: atrac3plus.h:121
Definition: fft.h:88
unit containing one coded channel
Definition: atrac3plus.h:51
int use_full_table
1 - full table list, 0 - restricted one
Definition: atrac3plus.h:139
int unit_type
unit type (mono/stereo)
Definition: atrac3plus.h:133
int num_gain_subbands
number of subbands with gain control data
Definition: atrac3plus.h:110
int num_coded_vals
number of transmitted quant unit values
Definition: atrac3plus.h:91
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.
Definition: atrac3plusdsp.c:418
Definition: float_dsp.h:24
struct Atrac3pWavesData Atrac3pWavesData
Parameters of a group of sine waves.
void ff_atrac3p_init_imdct(AVCodecContext *avctx, FFTContext *mdct_ctx)
Initialize IMDCT transform.
Definition: atrac3plusdsp.c:80
int start_index
start index into global tones table for that subband
Definition: atrac3plus.h:77
Gain control parameters for one subband.
Definition: atrac.h:35
int freq_index
wave frequency index
Definition: atrac3plus.h:82
Libavcodec external API header.
int phase_index
quantized phase index
Definition: atrac3plus.h:85
void ff_atrac3p_generate_tones(Atrac3pChanUnitCtx *ch_unit, AVFloatDSPContext *fdsp, int ch_num, int sb, float *out)
Synthesize sine waves for a particular subband.
Definition: atrac3plusdsp.c:184
main external API structure.
Definition: avcodec.h:1518
Channel unit parameters.
Definition: atrac3plus.h:131
int amp_sf
quantized amplitude scale factor
Definition: atrac3plus.h:83
Sound channel parameters.
Definition: atrac3plus.h:89
unit sequence terminator
Definition: atrac3plus.h:54
Atrac3pWaveEnvelope curr_env
group envelope from the current frame
Definition: atrac3plus.h:75
Per-channel IPQF history.
Definition: atrac3plus.h:58
Definition: atrac3plus.h:119
void ff_atrac3p_init_vlcs(void)
Initialize VLC tables for bitstream parsing.
Definition: atrac3plus.c:80
Definition: get_bits.h:56
int has_start_point
indicates start point within the GHA window
Definition: atrac3plus.h:66
AtracGainInfo * gain_data
gain control data for next frame
Definition: atrac3plus.h:108
int has_stop_point
indicates stop point within the GHA window
Definition: atrac3plus.h:67
unit containing two jointly-coded channels
Definition: atrac3plus.h:52
int noise_present
1 - global noise info present
Definition: atrac3plus.h:140
struct Atrac3pWaveEnvelope Atrac3pWaveEnvelope
Amplitude envelope of a group of sine waves.
int start_pos
start position expressed in n*4 samples
Definition: atrac3plus.h:68
int mute_flag
mute flag
Definition: atrac3plus.h:138
int tones_present
1 - tones info present
Definition: atrac3plus.h:120
unit containing extension information
Definition: atrac3plus.h:53
Atrac3pChannelUnitTypes
ATRAC3+ channel unit types.
Definition: atrac3plus.h:50
struct Atrac3pWaveParam Atrac3pWaveParam
Parameters of a single sine wave.