23#include "config_components.h"
73 int32_t intermediate_samples[4];
77 for (
i = 0;
i < 2;
i++)
81 &intermediate_samples[0+
i],
82 &intermediate_samples[2+
i]);
85 for (
i = 0;
i < 2;
i++)
88 &intermediate_samples[2*
i],
89 &subband_samples[2*
i+0],
90 &subband_samples[2*
i+1]);
100 for (
i = nb_intervals >> 1;
i > 0;
i >>= 1)
114 int32_t quantized_sample, dithered_sample, parity_change;
115 int32_t d,
mean, interval, inv, sample_difference_abs;
118 sample_difference_abs =
FFABS(sample_difference);
119 sample_difference_abs =
FFMIN(sample_difference_abs, (1 << 23) - 1);
123 intervals,
tables->tables_size);
126 d = rshift64(
MUL64(d,
tables->quantize_dither_factors[quantized_sample]), 23);
128 intervals += quantized_sample;
129 mean = (intervals[1] + intervals[0]) / 2;
130 interval = (intervals[1] - intervals[0]) * (-(sample_difference < 0) | 1);
133 error = ((
int64_t)sample_difference_abs << 20) -
MUL64(dithered_sample, quantization_factor);
136 parity_change = quantized_sample;
142 inv = -(sample_difference < 0);
143 quantize->quantized_sample = quantized_sample ^ inv;
144 quantize->quantized_sample_parity_change = parity_change ^ inv;
153 for (subband = 0; subband <
NB_SUBBANDS; subband++) {
157 channel->invert_quantize[subband].quantization_factor,
167 static const int map[] = { 1, 2, 0, 3 };
171 if (
c->quantize[
map[
i]].error <
min->error)
176 min->quantized_sample =
min->quantized_sample_parity_change;
183 return (((
channel->quantize[3].quantized_sample & 0x06) |
parity) << 13)
184 | (((
channel->quantize[2].quantized_sample & 0x03) ) << 11)
185 | (((
channel->quantize[1].quantized_sample & 0x0F) ) << 7)
186 | (((
channel->quantize[0].quantized_sample & 0x7F) ) << 0);
192 return (((
channel->quantize[3].quantized_sample & 0x01E) |
parity) << 19)
193 | (((
channel->quantize[2].quantized_sample & 0x00F) ) << 15)
194 | (((
channel->quantize[1].quantized_sample & 0x03F) ) << 9)
195 | (((
channel->quantize[0].quantized_sample & 0x1FF) ) << 0);
229 output_size =
s->block_size *
frame->nb_samples/4;
233 for (
pos = 0, ipos = 0;
pos < output_size;
pos +=
s->block_size, ipos += 4) {
271#if CONFIG_APTX_ENCODER
288#if CONFIG_APTX_HD_ENCODER
291 CODEC_LONG_NAME(
"aptX HD (Audio Processing Technology for Bluetooth)"),
const FFCodec ff_aptx_hd_encoder
const FFCodec ff_aptx_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 av_cold int aptx_encode_init(AVCodecContext *avctx)
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)
av_cold void ff_af_queue_close(AudioFrameQueue *afq)
Close AudioFrameQueue.
av_cold void ff_af_queue_init(AVCodecContext *avctx, AudioFrameQueue *afq)
Initialize AudioFrameQueue.
int ff_af_queue_remove(AudioFrameQueue *afq, int nb_samples, AVPacket *pkt)
Remove frame(s) from the queue.
int ff_af_queue_add(AudioFrameQueue *afq, const AVFrame *f)
Add a frame to the queue.
#define i(width, name, range_min, range_max)
Public libavutil channel layout APIs header.
static int quantize(CinepakEncContext *s, int h, uint8_t *data[4], int linesize[4], int v1mode, strip_info *info, mb_encoding encoding)
#define CODEC_CH_LAYOUTS(...)
#define CODEC_SAMPLERATES(...)
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
#define CODEC_SAMPLEFMTS(...)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
int(* init)(AVBSFContext *ctx)
channel
Use these values when setting the channel map with ebur128_set_channel().
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CHANNEL_LAYOUT_STEREO
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
const VDPAUPixFmtMap * map
static int shift(int a, int b)
common internal api header.
static const int factor[16]
main external API structure.
int frame_size
Number of samples per channel in an audio frame.
struct AVCodecInternal * internal
Private context used for internal data.
int pad_samples
Audio encoders can set this flag during init to indicate that they want the small last frame to be pa...
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
FilterSignal inner_filter_signal[NB_FILTERS][NB_FILTERS]
FilterSignal outer_filter_signal[NB_FILTERS]
static void error(const char *err)
static AVFormatContext * ctx
static const uint8_t *const tables[]
static const uint16_t dither[8][8]
static float mean(const float *input, int size)
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)