61 int32_t intermediate_samples[4];
65 for (
i = 0;
i < 2;
i++)
69 &intermediate_samples[0+
i],
70 &intermediate_samples[2+
i]);
73 for (
i = 0;
i < 2;
i++)
76 &intermediate_samples[2*
i],
77 &subband_samples[2*
i+0],
78 &subband_samples[2*
i+1]);
88 for (
i = nb_intervals >> 1;
i > 0;
i >>= 1)
102 int32_t quantized_sample, dithered_sample, parity_change;
103 int32_t d,
mean, interval, inv, sample_difference_abs;
106 sample_difference_abs =
FFABS(sample_difference);
107 sample_difference_abs =
FFMIN(sample_difference_abs, (1 << 23) - 1);
111 intervals,
tables->tables_size);
114 d = rshift64(
MUL64(d,
tables->quantize_dither_factors[quantized_sample]), 23);
116 intervals += quantized_sample;
117 mean = (intervals[1] + intervals[0]) / 2;
118 interval = (intervals[1] - intervals[0]) * (-(sample_difference < 0) | 1);
121 error = ((
int64_t)sample_difference_abs << 20) -
MUL64(dithered_sample, quantization_factor);
124 parity_change = quantized_sample;
130 inv = -(sample_difference < 0);
131 quantize->quantized_sample = quantized_sample ^ inv;
132 quantize->quantized_sample_parity_change = parity_change ^ inv;
141 for (subband = 0; subband <
NB_SUBBANDS; subband++) {
145 channel->invert_quantize[subband].quantization_factor,
155 static const int map[] = { 1, 2, 0, 3 };
159 if (
c->quantize[
map[
i]].error <
min->error)
164 min->quantized_sample =
min->quantized_sample_parity_change;
171 return (((
channel->quantize[3].quantized_sample & 0x06) |
parity) << 13)
172 | (((
channel->quantize[2].quantized_sample & 0x03) ) << 11)
173 | (((
channel->quantize[1].quantized_sample & 0x0F) ) << 7)
174 | (((
channel->quantize[0].quantized_sample & 0x7F) ) << 0);
180 return (((
channel->quantize[3].quantized_sample & 0x01E) |
parity) << 19)
181 | (((
channel->quantize[2].quantized_sample & 0x00F) ) << 15)
182 | (((
channel->quantize[1].quantized_sample & 0x03F) ) << 9)
183 | (((
channel->quantize[0].quantized_sample & 0x1FF) ) << 0);
220 for (
pos = 0, ipos = 0;
pos < output_size;
pos +=
s->block_size, ipos += 4) {
242 #if CONFIG_APTX_ENCODER
257 .supported_samplerates = (
const int[]) {8000, 16000, 24000, 32000, 44100, 48000, 0},
261 #if CONFIG_APTX_HD_ENCODER
276 .supported_samplerates = (
const int[]) {8000, 16000, 24000, 32000, 44100, 48000, 0},
AVCodec ff_aptx_hd_encoder
av_cold int ff_aptx_init(AVCodecContext *avctx)
ConstTables ff_aptx_quant_tables[2][NB_SUBBANDS]
void ff_aptx_invert_quantize_and_prediction(Channel *channel, int hd)
void ff_aptx_generate_dither(Channel *channel)
static av_always_inline void aptx_qmf_filter_signal_push(FilterSignal *signal, int32_t sample)
static const int32_t aptx_qmf_outer_coeffs[NB_FILTERS][FILTER_TAPS]
static int aptx_check_parity(Channel channels[NB_CHANNELS], int32_t *idx)
static int32_t aptx_quantized_parity(Channel *channel)
static const int32_t aptx_qmf_inner_coeffs[NB_FILTERS][FILTER_TAPS]
static av_always_inline int32_t aptx_qmf_convolution(FilterSignal *signal, const int32_t coeffs[FILTER_TAPS], int shift)
static void aptx_quantize_difference(Quantize *quantize, int32_t sample_difference, int32_t dither, int32_t quantization_factor, ConstTables *tables)
static uint32_t aptxhd_pack_codeword(Channel *channel)
static av_cold int aptx_close(AVCodecContext *avctx)
static void aptx_encode_samples(AptXContext *ctx, int32_t samples[NB_CHANNELS][4], uint8_t *output)
static void aptx_encode_channel(Channel *channel, int32_t samples[4], int hd)
static void aptx_qmf_tree_analysis(QMFAnalysis *qmf, int32_t samples[4], int32_t subband_samples[4])
static int aptx_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
static void aptx_insert_sync(Channel channels[NB_CHANNELS], int32_t *idx)
static uint16_t aptx_pack_codeword(Channel *channel)
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 av_always_inline int32_t aptx_bin_search(int32_t value, int32_t factor, const int32_t *intervals, int32_t nb_intervals)
void ff_af_queue_close(AudioFrameQueue *afq)
Close AudioFrameQueue.
void ff_af_queue_remove(AudioFrameQueue *afq, int nb_samples, int64_t *pts, int64_t *duration)
Remove frame(s) from the queue.
int ff_af_queue_add(AudioFrameQueue *afq, const AVFrame *f)
Add a frame to the queue.
static av_cold int init(AVCodecContext *avctx)
static int quantize(CinepakEncContext *s, int h, uint8_t *data[4], int linesize[4], int v1mode, strip_info *info, mb_encoding encoding)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static const uint16_t channel_layouts[7]
channel
Use these values when setting the channel map with ebur128_set_channel().
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
#define AV_CH_LAYOUT_STEREO
#define AV_CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
AVSampleFormat
Audio sample formats.
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
const VDPAUPixFmtMap * map
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static int shift(int a, int b)
main external API structure.
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
int nb_samples
number of audio samples (per channel) described by this frame
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
This structure stores compressed data.
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
FilterSignal inner_filter_signal[NB_FILTERS][NB_FILTERS]
FilterSignal outer_filter_signal[NB_FILTERS]
static void error(const char *err)
static const uint8_t *const tables[]
static const uint8_t dither[8][8]
static float mean(const float *input, int size)
static av_always_inline int diff(const uint32_t a, const uint32_t b)
static const int factor[16]