FFmpeg
Loading...
Searching...
No Matches
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
23/**
24 * @file
25 * Global structures, constants and data for ATRAC3+ decoder.
26 */
27
28#ifndef AVCODEC_ATRAC3PLUS_H
29#define AVCODEC_ATRAC3PLUS_H
30
31#include <stdint.h>
32
33#include "libavutil/float_dsp.h"
35#include "libavutil/tx.h"
36
37#include "atrac.h"
38#include "avcodec.h"
39#include "get_bits.h"
40
41/** Global unit sizes */
42#define ATRAC3P_SUBBANDS 16 ///< number of PQF subbands
43#define ATRAC3P_SUBBAND_SAMPLES 128 ///< number of samples per subband
44#define ATRAC3P_FRAME_SAMPLES (ATRAC3P_SUBBAND_SAMPLES * ATRAC3P_SUBBANDS)
45
46#define ATRAC3P_PQF_FIR_LEN 12 ///< length of the prototype FIR of the PQF
47
48/** Global constants */
49#define ATRAC3P_POWER_COMP_OFF 15 ///< disable power compensation
50
51/** ATRAC3+ channel unit types */
53 CH_UNIT_MONO = 0, ///< unit containing one coded channel
54 CH_UNIT_STEREO = 1, ///< unit containing two jointly-coded channels
55 CH_UNIT_EXTENSION = 2, ///< unit containing extension information
56 CH_UNIT_TERMINATOR = 3 ///< unit sequence terminator
57};
58
59/** Per-channel IPQF history */
65
66/** Amplitude envelope of a group of sine waves */
67typedef struct Atrac3pWaveEnvelope {
68 int has_start_point; ///< indicates start point within the GHA window
69 int has_stop_point; ///< indicates stop point within the GHA window
70 int start_pos; ///< start position expressed in n*4 samples
71 int stop_pos; ///< stop position expressed in n*4 samples
73
74/** Parameters of a group of sine waves */
75typedef struct Atrac3pWavesData {
76 Atrac3pWaveEnvelope pend_env; ///< pending envelope from the previous frame
77 Atrac3pWaveEnvelope curr_env; ///< group envelope from the current frame
78 int num_wavs; ///< number of sine waves in the group
79 int start_index; ///< start index into global tones table for that subband
81
82/** Parameters of a single sine wave */
83typedef struct Atrac3pWaveParam {
84 int freq_index; ///< wave frequency index
85 int amp_sf; ///< quantized amplitude scale factor
86 int amp_index; ///< quantized amplitude index
87 int phase_index; ///< quantized phase index
89
90/** Sound channel parameters */
91typedef struct Atrac3pChanParams {
92 int ch_num;
93 int num_coded_vals; ///< number of transmitted quant unit values
96 int table_type; ///< table type: 0 - tone?, 1- noise?
97 int qu_wordlen[32]; ///< array of word lengths for each quant unit
98 int qu_sf_idx[32]; ///< array of scale factor indexes for each quant unit
99 int qu_tab_idx[32]; ///< array of code table indexes for each quant unit
100 int16_t spectrum[2048]; ///< decoded IMDCT spectrum
101 uint8_t power_levs[5]; ///< power compensation levels
102
103 /* imdct window shape history (2 frames) for overlapping. */
104 uint8_t wnd_shape_hist[2][ATRAC3P_SUBBANDS]; ///< IMDCT window shape, 0=sine/1=steep
105 uint8_t *wnd_shape; ///< IMDCT window shape for current frame
106 uint8_t *wnd_shape_prev; ///< IMDCT window shape for previous frame
107
108 /* gain control data history (2 frames) for overlapping. */
109 AtracGainInfo gain_data_hist[2][ATRAC3P_SUBBANDS]; ///< gain control data for all subbands
110 AtracGainInfo *gain_data; ///< gain control data for next frame
111 AtracGainInfo *gain_data_prev; ///< gain control data for previous frame
112 int num_gain_subbands; ///< number of subbands with gain control data
113
114 /* tones data history (2 frames) for overlapping. */
119
120/* Per-unit sine wave parameters */
122 int tones_present; ///< 1 - tones info present
123 int amplitude_mode; ///< 1 - low range, 0 - high range
124 int num_tone_bands; ///< number of PQF bands with tones
125 uint8_t tone_sharing[ATRAC3P_SUBBANDS]; ///< 1 - subband-wise tone sharing flags
126 uint8_t tone_master[ATRAC3P_SUBBANDS]; ///< 1 - subband-wise tone channel swapping
127 uint8_t invert_phase[ATRAC3P_SUBBANDS]; ///< 1 - subband-wise phase inversion
128 int tones_index; ///< total sum of tones in this unit
131
132/** Channel unit parameters */
133typedef struct Atrac3pChanUnitCtx {
134 /* channel unit variables */
135 int unit_type; ///< unit type (mono/stereo)
138 int used_quant_units; ///< number of quant units with coded spectrum
139 int num_coded_subbands; ///< number of subbands with coded spectrum
140 int mute_flag; ///< mute flag
141 int use_full_table; ///< 1 - full table list, 0 - restricted one
142 int noise_present; ///< 1 - global noise info present
143 int noise_level_index; ///< global noise level index
144 int noise_table_index; ///< global noise RNG table index
145 uint8_t swap_channels[ATRAC3P_SUBBANDS]; ///< 1 - perform subband-wise channel swapping
146 uint8_t negate_coeffs[ATRAC3P_SUBBANDS]; ///< 1 - subband-wise IMDCT coefficients negation
148
149 /* Variables related to GHA tones */
150 Atrac3pWaveSynthParams wave_synth_hist[2]; ///< waves synth history for two frames
153
155 DECLARE_ALIGNED(32, float, prev_buf)[2][ATRAC3P_FRAME_SAMPLES]; ///< overlapping buffer
157
158/**
159 * Initialize VLC tables for bitstream parsing.
160 */
161void ff_atrac3p_init_vlcs(void);
162
163/**
164 * Decode bitstream data of a channel unit.
165 *
166 * @param[in] gb the GetBit context
167 * @param[in,out] ctx ptr to the channel unit context
168 * @param[in] num_channels number of channels to process
169 * @param[in] avctx ptr to the AVCodecContext
170 * @return result code: 0 = OK, otherwise - error code
171 */
173 int num_channels, AVCodecContext *avctx);
174
175/**
176 * Initialize sine waves synthesizer and ff_sine_* tables.
177 */
179
180/**
181 * Synthesize sine waves for a particular subband.
182 *
183 * @param[in] ch_unit pointer to the channel unit context
184 * @param[in] fdsp pointer to float DSP context
185 * @param[in] ch_num which channel to process
186 * @param[in] sb which subband to process
187 * @param[out] out receives processed data
188 */
190 int ch_num, int sb, float *out);
191
192/**
193 * Perform power compensation aka noise dithering.
194 *
195 * @param[in] ctx ptr to the channel context
196 * @param[in] fdsp pointer to float DSP context
197 * @param[in] ch_index which channel to process
198 * @param[in,out] sp ptr to channel spectrum to process
199 * @param[in] rng_index indicates which RNG table to use
200 * @param[in] sb_num which subband to process
201 */
203 int ch_index, float *sp, int rng_index, int sb_num);
204
205/**
206 * Regular IMDCT and windowing without overlapping,
207 * with spectrum reversal in the odd subbands.
208 *
209 * @param[in] fdsp pointer to float DSP context
210 * @param[in] mdct_ctx pointer to MDCT transform context
211 * @param[in] pIn float input
212 * @param[out] pOut float output
213 * @param[in] wind_id which MDCT window to apply
214 * @param[in] sb subband number
215 */
217 av_tx_fn mdct_fn, float *pIn, float *pOut,
218 int wind_id, int sb);
219
220/**
221 * Subband synthesis filter based on the polyphase quadrature (pseudo-QMF)
222 * filter bank.
223 *
224 * @param[in] dct_ctx ptr to the pre-initialized IDCT context
225 * @param[in,out] hist ptr to the filter history
226 * @param[in] in input data to process
227 * @param[out] out receives processed data
228 */
229void ff_atrac3p_ipqf(AVTXContext *dct_ctx, av_tx_fn dct_fn,
230 Atrac3pIPQFChannelCtx *hist, const float *in, float *out);
231
232extern const uint16_t ff_atrac3p_qu_to_spec_pos[33];
233extern const float ff_atrac3p_sf_tab[64];
234extern const float ff_atrac3p_mant_tab[8];
235
236#endif /* AVCODEC_ATRAC3PLUS_H */
void ff_atrac3p_init_dsp_static(void)
Initialize sine waves synthesizer and ff_sine_* tables.
const uint16_t ff_atrac3p_qu_to_spec_pos[33]
Map quant unit number to its position in the spectrum.
#define ATRAC3P_FRAME_SAMPLES
Definition atrac3plus.h:44
#define ATRAC3P_PQF_FIR_LEN
length of the prototype FIR of the PQF
Definition atrac3plus.h:46
const float ff_atrac3p_mant_tab[8]
void ff_atrac3p_ipqf(AVTXContext *dct_ctx, av_tx_fn dct_fn, Atrac3pIPQFChannelCtx *hist, const float *in, float *out)
Subband synthesis filter based on the polyphase quadrature (pseudo-QMF) filter bank.
const float ff_atrac3p_sf_tab[64]
int ff_atrac3p_decode_channel_unit(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, int num_channels, AVCodecContext *avctx)
Decode bitstream data of a channel unit.
void ff_atrac3p_generate_tones(Atrac3pChanUnitCtx *ch_unit, AVFloatDSPContext *fdsp, int ch_num, int sb, float *out)
Synthesize sine waves for a particular subband.
#define ATRAC3P_SUBBANDS
Global unit sizes.
Definition atrac3plus.h:42
Atrac3pChannelUnitTypes
ATRAC3+ channel unit types.
Definition atrac3plus.h:52
@ CH_UNIT_TERMINATOR
unit sequence terminator
Definition atrac3plus.h:56
@ CH_UNIT_EXTENSION
unit containing extension information
Definition atrac3plus.h:55
@ CH_UNIT_STEREO
unit containing two jointly-coded channels
Definition atrac3plus.h:54
@ CH_UNIT_MONO
unit containing one coded channel
Definition atrac3plus.h:53
void ff_atrac3p_init_vlcs(void)
Initialize VLC tables for bitstream parsing.
Definition atrac3plus.c:76
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.
void ff_atrac3p_imdct(AVFloatDSPContext *fdsp, AVTXContext *mdct_ctx, av_tx_fn mdct_fn, float *pIn, float *pOut, int wind_id, int sb)
Regular IMDCT and windowing without overlapping, with spectrum reversal in the odd subbands.
ATRAC common header.
Libavcodec external API header.
bitstream reader API header.
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
main external API structure.
Definition avcodec.h:443
Sound channel parameters.
Definition atrac3plus.h:91
uint8_t wnd_shape_hist[2][ATRAC3P_SUBBANDS]
IMDCT window shape, 0=sine/1=steep.
Definition atrac3plus.h:104
int qu_sf_idx[32]
array of scale factor indexes for each quant unit
Definition atrac3plus.h:98
int qu_tab_idx[32]
array of code table indexes for each quant unit
Definition atrac3plus.h:99
int qu_wordlen[32]
array of word lengths for each quant unit
Definition atrac3plus.h:97
uint8_t * wnd_shape
IMDCT window shape for current frame.
Definition atrac3plus.h:105
uint8_t power_levs[5]
power compensation levels
Definition atrac3plus.h:101
AtracGainInfo * gain_data_prev
gain control data for previous frame
Definition atrac3plus.h:111
int16_t spectrum[2048]
decoded IMDCT spectrum
Definition atrac3plus.h:100
uint8_t * wnd_shape_prev
IMDCT window shape for previous frame.
Definition atrac3plus.h:106
int num_gain_subbands
number of subbands with gain control data
Definition atrac3plus.h:112
int table_type
table type: 0 - tone?, 1- noise?
Definition atrac3plus.h:96
AtracGainInfo * gain_data
gain control data for next frame
Definition atrac3plus.h:110
int num_coded_vals
number of transmitted quant unit values
Definition atrac3plus.h:93
AtracGainInfo gain_data_hist[2][ATRAC3P_SUBBANDS]
gain control data for all subbands
Definition atrac3plus.h:109
Atrac3pWavesData * tones_info
Definition atrac3plus.h:116
Atrac3pWavesData * tones_info_prev
Definition atrac3plus.h:117
Atrac3pWavesData tones_info_hist[2][ATRAC3P_SUBBANDS]
Definition atrac3plus.h:115
Channel unit parameters.
Definition atrac3plus.h:133
Atrac3pWaveSynthParams wave_synth_hist[2]
waves synth history for two frames
Definition atrac3plus.h:150
Atrac3pWaveSynthParams * waves_info
Definition atrac3plus.h:151
int noise_level_index
global noise level index
Definition atrac3plus.h:143
int use_full_table
1 - full table list, 0 - restricted one
Definition atrac3plus.h:141
float prev_buf[2][ATRAC3P_FRAME_SAMPLES]
overlapping buffer
Definition atrac3plus.h:155
uint8_t swap_channels[ATRAC3P_SUBBANDS]
1 - perform subband-wise channel swapping
Definition atrac3plus.h:145
uint8_t negate_coeffs[ATRAC3P_SUBBANDS]
1 - subband-wise IMDCT coefficients negation
Definition atrac3plus.h:146
int mute_flag
mute flag
Definition atrac3plus.h:140
int noise_present
1 - global noise info present
Definition atrac3plus.h:142
int used_quant_units
number of quant units with coded spectrum
Definition atrac3plus.h:138
Atrac3pChanParams channels[2]
Definition atrac3plus.h:147
Atrac3pIPQFChannelCtx ipqf_ctx[2]
Definition atrac3plus.h:154
Atrac3pWaveSynthParams * waves_info_prev
Definition atrac3plus.h:152
int num_coded_subbands
number of subbands with coded spectrum
Definition atrac3plus.h:139
int unit_type
unit type (mono/stereo)
Definition atrac3plus.h:135
int noise_table_index
global noise RNG table index
Definition atrac3plus.h:144
Per-channel IPQF history.
Definition atrac3plus.h:60
float buf1[ATRAC3P_PQF_FIR_LEN *2][8]
Definition atrac3plus.h:61
float buf2[ATRAC3P_PQF_FIR_LEN *2][8]
Definition atrac3plus.h:62
Amplitude envelope of a group of sine waves.
Definition atrac3plus.h:67
int has_stop_point
indicates stop point within the GHA window
Definition atrac3plus.h:69
int has_start_point
indicates start point within the GHA window
Definition atrac3plus.h:68
int stop_pos
stop position expressed in n*4 samples
Definition atrac3plus.h:71
int start_pos
start position expressed in n*4 samples
Definition atrac3plus.h:70
Parameters of a single sine wave.
Definition atrac3plus.h:83
int phase_index
quantized phase index
Definition atrac3plus.h:87
int freq_index
wave frequency index
Definition atrac3plus.h:84
int amp_sf
quantized amplitude scale factor
Definition atrac3plus.h:85
int amp_index
quantized amplitude index
Definition atrac3plus.h:86
int tones_present
1 - tones info present
Definition atrac3plus.h:122
int amplitude_mode
1 - low range, 0 - high range
Definition atrac3plus.h:123
uint8_t invert_phase[ATRAC3P_SUBBANDS]
1 - subband-wise phase inversion
Definition atrac3plus.h:127
int tones_index
total sum of tones in this unit
Definition atrac3plus.h:128
uint8_t tone_sharing[ATRAC3P_SUBBANDS]
1 - subband-wise tone sharing flags
Definition atrac3plus.h:125
int num_tone_bands
number of PQF bands with tones
Definition atrac3plus.h:124
Atrac3pWaveParam waves[48]
Definition atrac3plus.h:129
uint8_t tone_master[ATRAC3P_SUBBANDS]
1 - subband-wise tone channel swapping
Definition atrac3plus.h:126
Parameters of a group of sine waves.
Definition atrac3plus.h:75
int num_wavs
number of sine waves in the group
Definition atrac3plus.h:78
Atrac3pWaveEnvelope pend_env
pending envelope from the previous frame
Definition atrac3plus.h:76
Atrac3pWaveEnvelope curr_env
group envelope from the current frame
Definition atrac3plus.h:77
int start_index
start index into global tones table for that subband
Definition atrac3plus.h:79
Gain control parameters for one subband.
Definition atrac.h:35
static FILE * out
Definition movenc.c:55
static AVFormatContext * ctx
Definition movenc.c:49
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.
Definition tx.h:151