CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/ext/at3_standalone/atrac3plus.h
Views: 1401
/*1* ATRAC3+ compatible decoder2*3* Copyright (c) 2010-2013 Maxim Poliakovski4*5* This file is part of FFmpeg.6*7* FFmpeg is free software; you can redistribute it and/or8* modify it under the terms of the GNU Lesser General Public9* License as published by the Free Software Foundation; either10* version 2.1 of the License, or (at your option) any later version.11*12* FFmpeg is distributed in the hope that it will be useful,13* but WITHOUT ANY WARRANTY; without even the implied warranty of14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU15* Lesser General Public License for more details.16*17* You should have received a copy of the GNU Lesser General Public18* License along with FFmpeg; if not, write to the Free Software19* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA20*/2122/**23* @file24* Global structures, constants and data for ATRAC3+ decoder.25*/2627#ifndef AVCODEC_ATRAC3PLUS_H28#define AVCODEC_ATRAC3PLUS_H2930#include <stdint.h>3132#include "float_dsp.h"33#include "atrac.h"34#include "fft.h"35#include "get_bits.h"3637/** Global unit sizes */38#define ATRAC3P_SUBBANDS 16 ///< number of PQF subbands39#define ATRAC3P_SUBBAND_SAMPLES 128 ///< number of samples per subband40#define ATRAC3P_FRAME_SAMPLES (ATRAC3P_SUBBAND_SAMPLES * ATRAC3P_SUBBANDS)4142#define ATRAC3P_PQF_FIR_LEN 12 ///< length of the prototype FIR of the PQF4344/** Global constants */45#define ATRAC3P_POWER_COMP_OFF 15 ///< disable power compensation4647/** ATRAC3+ channel unit types */48enum Atrac3pChannelUnitTypes {49CH_UNIT_MONO = 0, ///< unit containing one coded channel50CH_UNIT_STEREO = 1, ///< unit containing two jointly-coded channels51CH_UNIT_EXTENSION = 2, ///< unit containing extension information52CH_UNIT_TERMINATOR = 3 ///< unit sequence terminator53};5455/** Per-channel IPQF history */56typedef struct Atrac3pIPQFChannelCtx {57DECLARE_ALIGNED(32, float, buf1)[ATRAC3P_PQF_FIR_LEN * 2][8];58DECLARE_ALIGNED(32, float, buf2)[ATRAC3P_PQF_FIR_LEN * 2][8];59int pos;60} Atrac3pIPQFChannelCtx;6162/** Amplitude envelope of a group of sine waves */63typedef struct Atrac3pWaveEnvelope {64int has_start_point; ///< indicates start point within the GHA window65int has_stop_point; ///< indicates stop point within the GHA window66int start_pos; ///< start position expressed in n*4 samples67int stop_pos; ///< stop position expressed in n*4 samples68} Atrac3pWaveEnvelope;6970/** Parameters of a group of sine waves */71typedef struct Atrac3pWavesData {72Atrac3pWaveEnvelope pend_env; ///< pending envelope from the previous frame73Atrac3pWaveEnvelope curr_env; ///< group envelope from the current frame74int num_wavs; ///< number of sine waves in the group75int start_index; ///< start index into global tones table for that subband76} Atrac3pWavesData;7778/** Parameters of a single sine wave */79typedef struct Atrac3pWaveParam {80int freq_index; ///< wave frequency index81int amp_sf; ///< quantized amplitude scale factor82int amp_index; ///< quantized amplitude index83int phase_index; ///< quantized phase index84} Atrac3pWaveParam;8586/** Sound channel parameters */87typedef struct Atrac3pChanParams {88int ch_num;89int num_coded_vals; ///< number of transmitted quant unit values90int fill_mode;91int split_point;92int table_type; ///< table type: 0 - tone?, 1- noise?93int qu_wordlen[32]; ///< array of word lengths for each quant unit94int qu_sf_idx[32]; ///< array of scale factor indexes for each quant unit95int qu_tab_idx[32]; ///< array of code table indexes for each quant unit96int16_t spectrum[2048]; ///< decoded IMDCT spectrum97uint8_t power_levs[5]; ///< power compensation levels9899/* imdct window shape history (2 frames) for overlapping. */100uint8_t wnd_shape_hist[2][ATRAC3P_SUBBANDS]; ///< IMDCT window shape, 0=sine/1=steep101uint8_t *wnd_shape; ///< IMDCT window shape for current frame102uint8_t *wnd_shape_prev; ///< IMDCT window shape for previous frame103104/* gain control data history (2 frames) for overlapping. */105AtracGainInfo gain_data_hist[2][ATRAC3P_SUBBANDS]; ///< gain control data for all subbands106AtracGainInfo *gain_data; ///< gain control data for next frame107AtracGainInfo *gain_data_prev; ///< gain control data for previous frame108int num_gain_subbands; ///< number of subbands with gain control data109110/* tones data history (2 frames) for overlapping. */111Atrac3pWavesData tones_info_hist[2][ATRAC3P_SUBBANDS];112Atrac3pWavesData *tones_info;113Atrac3pWavesData *tones_info_prev;114} Atrac3pChanParams;115116/* Per-unit sine wave parameters */117typedef struct Atrac3pWaveSynthParams {118int tones_present; ///< 1 - tones info present119int amplitude_mode; ///< 1 - low range, 0 - high range120int num_tone_bands; ///< number of PQF bands with tones121uint8_t tone_sharing[ATRAC3P_SUBBANDS]; ///< 1 - subband-wise tone sharing flags122uint8_t tone_master[ATRAC3P_SUBBANDS]; ///< 1 - subband-wise tone channel swapping123uint8_t invert_phase[ATRAC3P_SUBBANDS]; ///< 1 - subband-wise phase inversion124int tones_index; ///< total sum of tones in this unit125Atrac3pWaveParam waves[48];126} Atrac3pWaveSynthParams;127128/** Channel unit parameters */129typedef struct Atrac3pChanUnitCtx {130/* channel unit variables */131int unit_type; ///< unit type (mono/stereo)132int num_quant_units;133int num_subbands;134int used_quant_units; ///< number of quant units with coded spectrum135int num_coded_subbands; ///< number of subbands with coded spectrum136int mute_flag; ///< mute flag137int use_full_table; ///< 1 - full table list, 0 - restricted one138int noise_present; ///< 1 - global noise info present139int noise_level_index; ///< global noise level index140int noise_table_index; ///< global noise RNG table index141uint8_t swap_channels[ATRAC3P_SUBBANDS]; ///< 1 - perform subband-wise channel swapping142uint8_t negate_coeffs[ATRAC3P_SUBBANDS]; ///< 1 - subband-wise IMDCT coefficients negation143Atrac3pChanParams channels[2];144145/* Variables related to GHA tones */146Atrac3pWaveSynthParams wave_synth_hist[2]; ///< waves synth history for two frames147Atrac3pWaveSynthParams *waves_info;148Atrac3pWaveSynthParams *waves_info_prev;149150Atrac3pIPQFChannelCtx ipqf_ctx[2];151DECLARE_ALIGNED(32, float, prev_buf)[2][ATRAC3P_FRAME_SAMPLES]; ///< overlapping buffer152} Atrac3pChanUnitCtx;153154/**155* Initialize VLC tables for bitstream parsing.156*/157void ff_atrac3p_init_vlcs(void);158159/**160* Decode bitstream data of a channel unit.161*162* @param[in] gb the GetBit context163* @param[in,out] ctx ptr to the channel unit context164* @param[in] num_channels number of channels to process165* @return result code: 0 = OK, otherwise - error code166*/167int ff_atrac3p_decode_channel_unit(GetBitContext *gb, Atrac3pChanUnitCtx *ctx,168int num_channels);169170/**171* Initialize IMDCT transform.172*173* @param[in] mdct_ctx pointer to MDCT transform context174*/175void ff_atrac3p_init_imdct(FFTContext *mdct_ctx);176177/**178* Initialize sine waves synthesizer.179*/180void ff_atrac3p_init_wave_synth(void);181182/**183* Synthesize sine waves for a particular subband.184*185* @param[in] ch_unit pointer to the channel unit context186* @param[in] fdsp pointer to float DSP context187* @param[in] ch_num which channel to process188* @param[in] sb which subband to process189* @param[out] out receives processed data190*/191void ff_atrac3p_generate_tones(Atrac3pChanUnitCtx *ch_unit, int ch_num, int sb, float *out);192193/**194* Perform power compensation aka noise dithering.195*196* @param[in] ctx ptr to the channel context197* @param[in] ch_index which channel to process198* @param[in,out] sp ptr to channel spectrum to process199* @param[in] rng_index indicates which RNG table to use200* @param[in] sb_num which subband to process201*/202void ff_atrac3p_power_compensation(Atrac3pChanUnitCtx *ctx, int ch_index,203float *sp, int rng_index, int sb_num);204205/**206* Regular IMDCT and windowing without overlapping,207* with spectrum reversal in the odd subbands.208*209* @param[in] fdsp pointer to float DSP context210* @param[in] mdct_ctx pointer to MDCT transform context211* @param[in] pIn float input212* @param[out] pOut float output213* @param[in] wind_id which MDCT window to apply214* @param[in] sb subband number215*/216void ff_atrac3p_imdct(FFTContext *mdct_ctx, float *pIn,217float *pOut, int wind_id, int sb);218219/**220* Subband synthesis filter based on the polyphase quadrature (pseudo-QMF)221* filter bank.222*223* @param[in] dct_ctx ptr to the pre-initialized IDCT context224* @param[in,out] hist ptr to the filter history225* @param[in] in input data to process226* @param[out] out receives processed data227*/228void ff_atrac3p_ipqf(FFTContext *dct_ctx, Atrac3pIPQFChannelCtx *hist,229const float *in, float *out);230231extern const uint16_t av_atrac3p_qu_to_spec_pos[33];232extern const float av_atrac3p_sf_tab[64];233extern const float av_atrac3p_mant_tab[8];234235#endif /* AVCODEC_ATRAC3PLUS_H */236237238