FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Enumerations | Functions | Variables
aptx.c File Reference
#include "libavutil/intreadwrite.h"
#include "avcodec.h"
#include "internal.h"
#include "mathops.h"
#include "audio_frame_queue.h"

Go to the source code of this file.

Data Structures

struct  FilterSignal
 
struct  QMFAnalysis
 
struct  Quantize
 
struct  InvertQuantize
 
struct  Prediction
 
struct  Channel
 
struct  AptXContext
 
struct  ConstTables
 

Macros

#define NB_FILTERS   2
 
#define FILTER_TAPS   16
 
#define RSHIFT_SIZE(size)
 

Enumerations

enum  channels { LEFT, RIGHT, NB_CHANNELS }
 
enum  subbands {
  LF, MLF, MHF, HF,
  NB_SUBBANDS
}
 

Functions

static av_always_inline void aptx_update_codeword_history (Channel *channel)
 
static void aptx_generate_dither (Channel *channel)
 
static av_always_inline void aptx_qmf_filter_signal_push (FilterSignal *signal, int32_t sample)
 
static av_always_inline int32_t aptx_qmf_convolution (FilterSignal *signal, const int32_t coeffs[FILTER_TAPS], int shift)
 
static av_always_inline void aptx_qmf_polyphase_analysis (FilterSignal signal[NB_FILTERS], const int32_t coeffs[NB_FILTERS][FILTER_TAPS], int shift, int32_t samples[NB_FILTERS], int32_t *low_subband_output, int32_t *high_subband_output)
 
static void aptx_qmf_tree_analysis (QMFAnalysis *qmf, int32_t samples[4], int32_t subband_samples[4])
 
static av_always_inline void aptx_qmf_polyphase_synthesis (FilterSignal signal[NB_FILTERS], const int32_t coeffs[NB_FILTERS][FILTER_TAPS], int shift, int32_t low_subband_input, int32_t high_subband_input, int32_t samples[NB_FILTERS])
 
static void aptx_qmf_tree_synthesis (QMFAnalysis *qmf, int32_t subband_samples[4], int32_t samples[4])
 
static av_always_inline int32_t aptx_bin_search (int32_t value, int32_t factor, const int32_t *intervals, int32_t nb_intervals)
 
static void aptx_quantize_difference (Quantize *quantize, int32_t sample_difference, int32_t dither, int32_t quantization_factor, ConstTables *tables)
 
static void aptx_encode_channel (Channel *channel, int32_t samples[4])
 
static void aptx_decode_channel (Channel *channel, int32_t samples[4])
 
static void aptx_invert_quantization (InvertQuantize *invert_quantize, int32_t quantized_sample, int32_t dither, ConstTables *tables)
 
static int32_taptx_reconstructed_differences_update (Prediction *prediction, int32_t reconstructed_difference, int order)
 
static void aptx_prediction_filtering (Prediction *prediction, int32_t reconstructed_difference, int order)
 
static void aptx_process_subband (InvertQuantize *invert_quantize, Prediction *prediction, int32_t quantized_sample, int32_t dither, ConstTables *tables)
 
static void aptx_invert_quantize_and_prediction (Channel *channel)
 
static int32_t aptx_quantized_parity (Channel *channel)
 
static int aptx_check_parity (Channel channels[NB_CHANNELS], int32_t *idx)
 
static void aptx_insert_sync (Channel channels[NB_CHANNELS], int32_t *idx)
 
static uint16_t aptx_pack_codeword (Channel *channel)
 
static void aptx_unpack_codeword (Channel *channel, uint16_t codeword)
 
static void aptx_encode_samples (AptXContext *ctx, int32_t samples[NB_CHANNELS][4], uint8_t output[2 *NB_CHANNELS])
 
static int aptx_decode_samples (AptXContext *ctx, const uint8_t input[2 *NB_CHANNELS], int32_t samples[NB_CHANNELS][4])
 
static av_cold int aptx_init (AVCodecContext *avctx)
 
static int aptx_decode_frame (AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
 
static int aptx_encode_frame (AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
 
static av_cold int aptx_close (AVCodecContext *avctx)
 

Variables

static const int32_t quantize_intervals_LF [65]
 
static const int32_t invert_quantize_dither_factors_LF [65]
 
static const int32_t quantize_dither_factors_LF [65]
 
static const int16_t quantize_factor_select_offset_LF [65]
 
static const int32_t quantize_intervals_MLF [9]
 
static const int32_t invert_quantize_dither_factors_MLF [9]
 
static const int32_t quantize_dither_factors_MLF [9]
 
static const int16_t quantize_factor_select_offset_MLF [9]
 
static const int32_t quantize_intervals_MHF [3]
 
static const int32_t invert_quantize_dither_factors_MHF [3]
 
static const int32_t quantize_dither_factors_MHF [3]
 
static const int16_t quantize_factor_select_offset_MHF [3]
 
static const int32_t quantize_intervals_HF [5]
 
static const int32_t invert_quantize_dither_factors_HF [5]
 
static const int32_t quantize_dither_factors_HF [5]
 
static const int16_t quantize_factor_select_offset_HF [5]
 
static ConstTables tables [NB_SUBBANDS]
 
static const int16_t quantization_factors [32]
 
static const int32_t aptx_qmf_outer_coeffs [NB_FILTERS][FILTER_TAPS]
 
static const int32_t aptx_qmf_inner_coeffs [NB_FILTERS][FILTER_TAPS]
 

Macro Definition Documentation

#define NB_FILTERS   2

Definition at line 44 of file aptx.c.

Referenced by aptx_qmf_polyphase_analysis(), and aptx_qmf_polyphase_synthesis().

#define FILTER_TAPS   16

Definition at line 45 of file aptx.c.

Referenced by aptx_qmf_convolution(), and aptx_qmf_filter_signal_push().

#define RSHIFT_SIZE (   size)
Value:
av_always_inline \
static int##size##_t rshift##size(int##size##_t value, int shift) \
{ \
int##size##_t rounding = (int##size##_t)1 << (shift - 1); \
int##size##_t mask = ((int##size##_t)1 << (shift + 1)) - 1; \
return ((value + rounding) >> shift) - ((value & mask) == rounding); \
} \
av_always_inline \
static int##size##_t rshift##size##_clip24(int##size##_t value, int shift) \
{ \
return av_clip_intp2(rshift##size(value, shift), 23); \
}
static int shift(int a, int b)
Definition: sonic.c:82
ptrdiff_t size
Definition: opengl_enc.c:101
static const uint16_t mask[17]
Definition: lzw.c:38
return
GLsizei GLboolean const GLfloat * value
Definition: opengl_enc.c:109
int

Definition at line 231 of file aptx.c.

Enumeration Type Documentation

enum channels
Enumerator
LEFT 
RIGHT 
NB_CHANNELS 
Examples:
filter_audio.c.

Definition at line 30 of file aptx.c.

enum subbands
Enumerator
LF 
MLF 
MHF 
HF 
NB_SUBBANDS 

Definition at line 36 of file aptx.c.

Function Documentation

static av_always_inline void aptx_update_codeword_history ( Channel channel)
static

Definition at line 249 of file aptx.c.

Referenced by aptx_generate_dither().

static void aptx_generate_dither ( Channel channel)
static

Definition at line 257 of file aptx.c.

Referenced by aptx_decode_samples(), and aptx_encode_channel().

static av_always_inline void aptx_qmf_filter_signal_push ( FilterSignal signal,
int32_t  sample 
)
static

Definition at line 306 of file aptx.c.

Referenced by aptx_qmf_polyphase_analysis(), and aptx_qmf_polyphase_synthesis().

static av_always_inline int32_t aptx_qmf_convolution ( FilterSignal signal,
const int32_t  coeffs[FILTER_TAPS],
int  shift 
)
static

Definition at line 318 of file aptx.c.

Referenced by aptx_qmf_polyphase_analysis(), and aptx_qmf_polyphase_synthesis().

static av_always_inline void aptx_qmf_polyphase_analysis ( FilterSignal  signal[NB_FILTERS],
const int32_t  coeffs[NB_FILTERS][FILTER_TAPS],
int  shift,
int32_t  samples[NB_FILTERS],
int32_t low_subband_output,
int32_t high_subband_output 
)
static

Definition at line 339 of file aptx.c.

Referenced by aptx_qmf_tree_analysis().

static void aptx_qmf_tree_analysis ( QMFAnalysis qmf,
int32_t  samples[4],
int32_t  subband_samples[4] 
)
static

Definition at line 364 of file aptx.c.

Referenced by aptx_encode_channel().

static av_always_inline void aptx_qmf_polyphase_synthesis ( FilterSignal  signal[NB_FILTERS],
const int32_t  coeffs[NB_FILTERS][FILTER_TAPS],
int  shift,
int32_t  low_subband_input,
int32_t  high_subband_input,
int32_t  samples[NB_FILTERS] 
)
static

Definition at line 394 of file aptx.c.

Referenced by aptx_qmf_tree_synthesis().

static void aptx_qmf_tree_synthesis ( QMFAnalysis qmf,
int32_t  subband_samples[4],
int32_t  samples[4] 
)
static

Definition at line 418 of file aptx.c.

Referenced by aptx_decode_channel().

static av_always_inline int32_t aptx_bin_search ( int32_t  value,
int32_t  factor,
const int32_t intervals,
int32_t  nb_intervals 
)
static

Definition at line 444 of file aptx.c.

Referenced by aptx_quantize_difference().

static void aptx_quantize_difference ( Quantize quantize,
int32_t  sample_difference,
int32_t  dither,
int32_t  quantization_factor,
ConstTables tables 
)
static

Definition at line 457 of file aptx.c.

Referenced by aptx_encode_channel().

static void aptx_encode_channel ( Channel channel,
int32_t  samples[4] 
)
static

Definition at line 494 of file aptx.c.

Referenced by aptx_encode_samples().

static void aptx_decode_channel ( Channel channel,
int32_t  samples[4] 
)
static

Definition at line 509 of file aptx.c.

Referenced by aptx_decode_samples().

static void aptx_invert_quantization ( InvertQuantize invert_quantize,
int32_t  quantized_sample,
int32_t  dither,
ConstTables tables 
)
static

Definition at line 519 of file aptx.c.

Referenced by aptx_process_subband().

static int32_t* aptx_reconstructed_differences_update ( Prediction prediction,
int32_t  reconstructed_difference,
int  order 
)
static

Definition at line 546 of file aptx.c.

Referenced by aptx_prediction_filtering().

static void aptx_prediction_filtering ( Prediction prediction,
int32_t  reconstructed_difference,
int  order 
)
static

Definition at line 559 of file aptx.c.

Referenced by aptx_process_subband().

static void aptx_process_subband ( InvertQuantize invert_quantize,
Prediction prediction,
int32_t  quantized_sample,
int32_t  dither,
ConstTables tables 
)
static

Definition at line 585 of file aptx.c.

Referenced by aptx_invert_quantize_and_prediction().

static void aptx_invert_quantize_and_prediction ( Channel channel)
static

Definition at line 618 of file aptx.c.

Referenced by aptx_decode_samples(), and aptx_encode_samples().

static int32_t aptx_quantized_parity ( Channel channel)
static

Definition at line 629 of file aptx.c.

Referenced by aptx_check_parity(), aptx_pack_codeword(), and aptx_unpack_codeword().

static int aptx_check_parity ( Channel  channels[NB_CHANNELS],
int32_t idx 
)
static

Definition at line 642 of file aptx.c.

Referenced by aptx_decode_samples(), and aptx_insert_sync().

static void aptx_insert_sync ( Channel  channels[NB_CHANNELS],
int32_t idx 
)
static

Definition at line 653 of file aptx.c.

Referenced by aptx_encode_samples().

static uint16_t aptx_pack_codeword ( Channel channel)
static

Definition at line 671 of file aptx.c.

Referenced by aptx_encode_samples().

static void aptx_unpack_codeword ( Channel channel,
uint16_t  codeword 
)
static

Definition at line 680 of file aptx.c.

Referenced by aptx_decode_samples().

static void aptx_encode_samples ( AptXContext ctx,
int32_t  samples[NB_CHANNELS][4],
uint8_t  output[2 *NB_CHANNELS] 
)
static

Definition at line 690 of file aptx.c.

Referenced by aptx_encode_frame().

static int aptx_decode_samples ( AptXContext ctx,
const uint8_t  input[2 *NB_CHANNELS],
int32_t  samples[NB_CHANNELS][4] 
)
static

Definition at line 706 of file aptx.c.

Referenced by aptx_decode_frame().

static av_cold int aptx_init ( AVCodecContext avctx)
static

Definition at line 730 of file aptx.c.

static int aptx_decode_frame ( AVCodecContext avctx,
void data,
int got_frame_ptr,
AVPacket avpkt 
)
static

Definition at line 756 of file aptx.c.

static int aptx_encode_frame ( AVCodecContext avctx,
AVPacket avpkt,
const AVFrame frame,
int got_packet_ptr 
)
static

Definition at line 793 of file aptx.c.

static av_cold int aptx_close ( AVCodecContext avctx)
static

Definition at line 820 of file aptx.c.

Variable Documentation

const int32_t quantize_intervals_LF[65]
static
Initial value:
= {
-9948, 9948, 29860, 49808, 69822, 89926, 110144, 130502,
151026, 171738, 192666, 213832, 235264, 256982, 279014, 301384,
324118, 347244, 370790, 394782, 419250, 444226, 469742, 495832,
522536, 549890, 577936, 606720, 636290, 666700, 698006, 730270,
763562, 797958, 833538, 870398, 908640, 948376, 989740, 1032874,
1077948, 1125150, 1174700, 1226850, 1281900, 1340196, 1402156, 1468282,
1539182, 1615610, 1698514, 1789098, 1888944, 2000168, 2125700, 2269750,
2438670, 2642660, 2899462, 3243240, 3746078, 4535138, 5664098, 7102424,
8897462,
}

Definition at line 98 of file aptx.c.

const int32_t invert_quantize_dither_factors_LF[65]
static
Initial value:
= {
9948, 9948, 9962, 9988, 10026, 10078, 10142, 10218,
10306, 10408, 10520, 10646, 10784, 10934, 11098, 11274,
11462, 11664, 11880, 12112, 12358, 12618, 12898, 13194,
13510, 13844, 14202, 14582, 14988, 15422, 15884, 16380,
16912, 17484, 18098, 18762, 19480, 20258, 21106, 22030,
23044, 24158, 25390, 26760, 28290, 30008, 31954, 34172,
36728, 39700, 43202, 47382, 52462, 58762, 66770, 77280,
91642, 112348, 144452, 199326, 303512, 485546, 643414, 794914,
1000124,
}

Definition at line 109 of file aptx.c.

const int32_t quantize_dither_factors_LF[65]
static
Initial value:
= {
0, 4, 7, 10, 13, 16, 19, 22,
26, 28, 32, 35, 38, 41, 44, 47,
51, 54, 58, 62, 65, 70, 74, 79,
84, 90, 95, 102, 109, 116, 124, 133,
143, 154, 166, 180, 195, 212, 231, 254,
279, 308, 343, 383, 430, 487, 555, 639,
743, 876, 1045, 1270, 1575, 2002, 2628, 3591,
5177, 8026, 13719, 26047, 45509, 39467, 37875, 51303,
0,
}

Definition at line 120 of file aptx.c.

const int16_t quantize_factor_select_offset_LF[65]
static
Initial value:
= {
0, -21, -19, -17, -15, -12, -10, -8,
-6, -4, -1, 1, 3, 6, 8, 10,
13, 15, 18, 20, 23, 26, 29, 31,
34, 37, 40, 43, 47, 50, 53, 57,
60, 64, 68, 72, 76, 80, 85, 89,
94, 99, 105, 110, 116, 123, 129, 136,
144, 152, 161, 171, 182, 194, 207, 223,
241, 263, 291, 328, 382, 467, 522, 522,
522,
}

Definition at line 131 of file aptx.c.

const int32_t quantize_intervals_MLF[9]
static
Initial value:
= {
-89806, 89806, 278502, 494338, 759442, 1113112, 1652322, 2720256, 5190186,
}

Definition at line 144 of file aptx.c.

const int32_t invert_quantize_dither_factors_MLF[9]
static
Initial value:
= {
89806, 89806, 98890, 116946, 148158, 205512, 333698, 734236, 1735696,
}

Definition at line 147 of file aptx.c.

const int32_t quantize_dither_factors_MLF[9]
static
Initial value:
= {
0, 2271, 4514, 7803, 14339, 32047, 100135, 250365, 0,
}

Definition at line 150 of file aptx.c.

const int16_t quantize_factor_select_offset_MLF[9]
static
Initial value:
= {
0, -14, 6, 29, 58, 96, 154, 270, 521,
}

Definition at line 153 of file aptx.c.

const int32_t quantize_intervals_MHF[3]
static
Initial value:
= {
-194080, 194080, 890562,
}

Definition at line 158 of file aptx.c.

const int32_t invert_quantize_dither_factors_MHF[3]
static
Initial value:
= {
194080, 194080, 502402,
}

Definition at line 161 of file aptx.c.

const int32_t quantize_dither_factors_MHF[3]
static
Initial value:
= {
0, 77081, 0,
}

Definition at line 164 of file aptx.c.

const int16_t quantize_factor_select_offset_MHF[3]
static
Initial value:
= {
0, -33, 136,
}

Definition at line 167 of file aptx.c.

const int32_t quantize_intervals_HF[5]
static
Initial value:
= {
-163006, 163006, 542708, 1120554, 2669238,
}

Definition at line 172 of file aptx.c.

const int32_t invert_quantize_dither_factors_HF[5]
static
Initial value:
= {
163006, 163006, 216698, 361148, 1187538,
}

Definition at line 175 of file aptx.c.

const int32_t quantize_dither_factors_HF[5]
static
Initial value:
= {
0, 13423, 36113, 206598, 0,
}

Definition at line 178 of file aptx.c.

const int16_t quantize_factor_select_offset_HF[5]
static
Initial value:
= {
0, -8, 33, 95, 262,
}

Definition at line 181 of file aptx.c.

ConstTables tables[NB_SUBBANDS]
static
Initial value:
= {
7, 24 },
4, 12 },
2, 6 },
3, 12 },
}
static const int32_t quantize_dither_factors_MHF[3]
Definition: aptx.c:164
static const int16_t quantize_factor_select_offset_LF[65]
Definition: aptx.c:131
static const int16_t quantize_factor_select_offset_HF[5]
Definition: aptx.c:181
static const int32_t quantize_dither_factors_HF[5]
Definition: aptx.c:178
Definition: aptx.c:37
static const int32_t invert_quantize_dither_factors_LF[65]
Definition: aptx.c:109
static const int32_t quantize_dither_factors_MLF[9]
Definition: aptx.c:150
static const int32_t quantize_intervals_HF[5]
Definition: aptx.c:172
static const int16_t quantize_factor_select_offset_MLF[9]
Definition: aptx.c:153
static const int32_t quantize_dither_factors_LF[65]
Definition: aptx.c:120
#define FF_ARRAY_ELEMS(a)
Definition: aptx.c:38
static const int32_t quantize_intervals_MLF[9]
Definition: aptx.c:144
static const int32_t invert_quantize_dither_factors_MHF[3]
Definition: aptx.c:161
static const int32_t invert_quantize_dither_factors_HF[5]
Definition: aptx.c:175
static const int32_t quantize_intervals_MHF[3]
Definition: aptx.c:158
static const int16_t quantize_factor_select_offset_MHF[3]
Definition: aptx.c:167
static const int32_t invert_quantize_dither_factors_MLF[9]
Definition: aptx.c:147
Definition: aptx.c:40
Definition: aptx.c:39
static const int32_t quantize_intervals_LF[65]
Definition: aptx.c:98

Definition at line 195 of file aptx.c.

Referenced by ff_rtp_send_jpeg(), and truemotion1_decode_header().

const int16_t quantization_factors[32]
static
Initial value:
= {
2048, 2093, 2139, 2186, 2233, 2282, 2332, 2383,
2435, 2489, 2543, 2599, 2656, 2714, 2774, 2834,
2896, 2960, 3025, 3091, 3158, 3228, 3298, 3371,
3444, 3520, 3597, 3676, 3756, 3838, 3922, 4008,
}

Definition at line 222 of file aptx.c.

Referenced by aptx_invert_quantization().

const int32_t aptx_qmf_outer_coeffs[NB_FILTERS][FILTER_TAPS]
static
Initial value:
= {
{
730, -413, -9611, 43626, -121026, 269973, -585547, 2801966,
697128, -160481, 27611, 8478, -10043, 3511, 688, -897,
},
{
-897, 688, 3511, -10043, 8478, 27611, -160481, 697128,
2801966, -585547, 269973, -121026, 43626, -9611, -413, 730,
},
}

Definition at line 276 of file aptx.c.

Referenced by aptx_qmf_tree_analysis(), and aptx_qmf_tree_synthesis().

const int32_t aptx_qmf_inner_coeffs[NB_FILTERS][FILTER_TAPS]
static
Initial value:
= {
{
1033, -584, -13592, 61697, -171156, 381799, -828088, 3962579,
985888, -226954, 39048, 11990, -14203, 4966, 973, -1268,
},
{
-1268, 973, 4966, -14203, 11990, 39048, -226954, 985888,
3962579, -828088, 381799, -171156, 61697, -13592, -584, 1033,
},
}

Definition at line 291 of file aptx.c.

Referenced by aptx_qmf_tree_analysis(), and aptx_qmf_tree_synthesis().