47 #define AAC_MAX_CHANNELS 6
50 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8,
51 12, 12, 12, 12, 12, 16, 16, 24, 28, 36, 44,
52 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
56 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8,
57 12, 12, 12, 16, 16, 16, 20, 24, 24, 28, 36,
58 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40
62 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8,
63 12, 12, 12, 12, 16, 16, 20, 20, 24, 24, 28, 28,
64 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
69 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8,
70 12, 12, 12, 12, 16, 16, 20, 20, 24, 24, 28, 28,
71 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32
75 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
76 12, 12, 12, 12, 16, 16, 16, 20, 20, 24, 24, 28, 28,
77 32, 36, 36, 40, 44, 48, 52, 52, 64, 64, 64, 64, 64
81 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
82 12, 12, 12, 12, 12, 12, 12, 12, 12, 16, 16, 16, 16, 20, 20, 20, 24, 24, 28, 28,
83 32, 36, 40, 40, 44, 48, 52, 56, 60, 64, 64, 64
87 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
88 16, 16, 16, 16, 16, 16, 16, 20, 20, 20, 20, 24, 24, 24, 28, 28,
89 32, 36, 36, 40, 44, 48, 52, 56, 60, 64, 80
100 4, 4, 4, 4, 4, 4, 8, 8, 8, 16, 28, 36
104 4, 4, 4, 4, 4, 8, 8, 8, 12, 12, 12, 16, 16, 16
108 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 12, 12, 16, 16, 20
112 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 12, 12, 16, 20, 20
116 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 12, 16, 20, 20
167 const uint8_t *
sizes[2];
173 for (i = 0; i < 16; i++)
214 for (i = 0; i < s->
chan_map[0]; i++)
235 float *output = sce->
ret;
238 memcpy(output, sce->
saved,
sizeof(
float)*1024);
240 memset(output, 0,
sizeof(output[0]) * 448);
241 for (i = 448; i < 576; i++)
242 output[i] = sce->
saved[i] * pwindow[i - 448];
243 for (i = 576; i < 704; i++)
244 output[i] = sce->
saved[i];
247 for (i = 0; i < 1024; i++) {
248 output[i+1024] = audio[i * chans] * lwindow[1024 - i - 1];
249 sce->
saved[i] = audio[i * chans] * lwindow[i];
252 for (i = 0; i < 448; i++)
253 output[i+1024] = audio[i * chans];
255 output[i+1024] = audio[i * chans] * swindow[576 - i - 1];
256 memset(output+1024+576, 0,
sizeof(output[0]) * 448);
257 for (i = 0; i < 1024; i++)
258 sce->
saved[i] = audio[i * chans];
262 for (k = 0; k < 1024; k += 128) {
263 for (i = 448 + k; i < 448 + k + 256; i++)
264 output[i - 448 - k] = (i < 1024)
266 : audio[(i-1024)*chans];
271 for (i = 0; i < 1024; i++)
272 sce->
saved[i] = audio[i * chans];
292 for (w = 1; w < 8; w++)
318 int start, maxsfb, cmaxsfb;
320 for (ch = 0; ch < chans; ch++) {
326 for (g = 0; g < ics->
num_swb; g++) {
336 for (cmaxsfb = ics->
num_swb; cmaxsfb > 0 && cpe->
ch[ch].
zeroes[w+cmaxsfb-1]; cmaxsfb--)
338 maxsfb =
FFMAX(maxsfb, cmaxsfb);
344 for (g = 0; g < ics->
max_sfb; g++) {
346 for (w2 = w; w2 < w + ics->
group_len[w]; w2++) {
347 if (!cpe->
ch[ch].
zeroes[w2*16 + g]) {
364 for (i = 0; i < ics0->
max_sfb; i++)
367 if (msc == 0 || ics0->
max_sfb == 0)
396 if (!sce->
zeroes[w*16 + i]) {
398 if (diff < 0 || diff > 120)
400 off = sce->
sf_idx[w*16 + i];
436 if (sce->
zeroes[w*16 + i]) {
476 int i, namelen, padbits;
478 namelen = strlen(name) + 2;
486 for (i = 0; i < namelen - 2; i++)
492 uint8_t *frame,
int buf_size,
void *
data)
497 int i, ch, w,
g, chans,
tag, start_ch;
498 int chan_el_counter[4];
510 for (i = 0; i < s->
chan_map[0]; i++) {
514 samples2 + start_ch, start_ch, chans);
526 for (i = 0; i < s->
chan_map[0]; i++) {
531 for (ch = 0; ch < chans; ch++) {
533 int cur_channel = start_ch + ch;
534 samples2 = samples + cur_channel;
535 la = samples2 + (448+64) * avctx->
channels;
573 memset(chan_el_counter, 0,
sizeof(chan_el_counter));
574 for (i = 0; i < s->
chan_map[0]; i++) {
582 for (ch = 0; ch < chans; ch++)
585 for (ch = 0; ch < chans; ch++) {
591 && wi[0].window_type[0] == wi[1].window_type[0]
592 && wi[0].window_shape == wi[1].window_shape) {
596 if (wi[0].grouping[w] != wi[1].grouping[w]) {
607 for (g = 0; g < ics->
num_swb; g++)
621 for (ch = 0; ch < chans; ch++) {
629 if (frame_bits <= 6144 * avctx->channels - 3) {
669 #define AACENC_FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM
671 {
"stereo_mode",
"Stereo coding method", offsetof(
AACEncContext,
options.stereo_mode),
AV_OPT_TYPE_INT, {.dbl = 0}, -1, 1,
AACENC_FLAGS,
"stereo_mode"},
674 {
"ms_force",
"Force Mid/Side for the whole frame if possible", 0,
AV_OPT_TYPE_CONST, {.dbl = 1 }, INT_MIN, INT_MAX,
AACENC_FLAGS,
"stereo_mode"},
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static const int16_t coeffs[28]
static const uint8_t aac_chan_configs[6][5]
default channel configurations
void(* search_for_ms)(struct AACEncContext *s, ChannelElement *cpe, const float lambda)
uint8_t use_kb_window[2]
If set, use Kaiser-Bessel window, otherwise use a sinus window.
static const uint8_t swb_size_1024_64[]
int grouping[8]
window grouping (for e.g. AAC)
uint8_t ** bands
scalefactor band sizes for possible frame sizes
void(* mdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input)
static const AVClass aacenc_class
av_cold void ff_kbd_window_init(float *window, float alpha, int n)
Generate a Kaiser-Bessel Derived Window.
#define SCALE_DIFF_ZERO
codebook index corresponding to zero scalefactor indices difference
av_cold void ff_psy_preprocess_end(struct FFPsyPreprocessContext *ctx)
Cleanup audio preprocessing module.
AACCoefficientsEncoder * coder
void avpriv_align_put_bits(PutBitContext *s)
Pad the bitstream with zeros up to the next byte boundary.
static void put_ics_info(AACEncContext *s, IndividualChannelStream *info)
Encode ics_info element.
int common_window
Set if channels share a common 'IndividualChannelStream' in bitstream.
av_cold int ff_psy_init(FFPsyContext *ctx, AVCodecContext *avctx, int num_lens, const uint8_t **bands, const int *num_bands, int num_groups, const uint8_t *group_map)
Initialize psychoacoustic model.
uint8_t ms_mask[128]
Set if mid/side stereo is used for each scalefactor window band.
static const uint8_t swb_size_128_8[]
static void apply_window_and_mdct(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, short *audio)
static const uint8_t swb_size_1024_8[]
static const uint8_t swb_size_128_96[]
static void encode_spectral_coeffs(AACEncContext *s, SingleChannelElement *sce)
Encode spectral coefficients processed by psychoacoustic model.
int * num_bands
number of scalefactor bands for possible frame sizes
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
const uint8_t ff_aac_num_swb_128[]
int16_t * samples
saved preprocessed input
AACEncOptions options
encoding options
void(* quantize_and_encode_band)(struct AACEncContext *s, PutBitContext *pb, const float *in, int size, int scale_idx, int cb, const float lambda)
SingleChannelElement ch[2]
int samplerate_index
MPEG-4 samplerate index.
const uint8_t * chan_map
channel configuration map
const uint8_t ff_aac_scalefactor_bits[121]
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
static const uint8_t swb_size_1024_48[]
static void adjust_frame_information(AACEncContext *apc, ChannelElement *cpe, int chans)
Produce integer coefficients from scalefactors provided by the model.
av_cold void dsputil_init(DSPContext *c, AVCodecContext *avctx)
static int init(AVCodecParserContext *s)
#define CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
static const AVOption aacenc_options[]
static const uint8_t swb_size_1024_24[]
float coeffs[1024]
coefficients for IMDCT
void ff_psy_preprocess(struct FFPsyPreprocessContext *ctx, const int16_t *audio, int16_t *dest, int tag, int channels)
Preprocess several channel in audio frame in order to compress it better.
const uint8_t ff_aac_num_swb_1024[]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
FFPsyWindowInfo(* window)(FFPsyContext *ctx, const int16_t *audio, const int16_t *la, int channel, int prev_type)
Suggest window sequence for channel.
float ff_aac_kbd_long_1024[1024]
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
int num_windows
number of windows in a frame
uint8_t max_sfb
number of scalefactor bands per group
static void put_bits(PutBitContext *s, int n, unsigned int value)
Write up to 31 bits into a bitstream.
int num_swb
number of scalefactor window bands
void(* search_for_quantizers)(AVCodecContext *avctx, struct AACEncContext *s, SingleChannelElement *sce, const float lambda)
static int put_bits_count(PutBitContext *s)
struct AACEncContext AACEncContext
AAC encoder context.
int bit_rate
the average bitrate
enum WindowSequence window_sequence[2]
static void put_bitstream_info(AVCodecContext *avctx, AACEncContext *s, const char *name)
Write some auxiliary information about the created AAC file.
float ret[2048]
PCM output.
void(* analyze)(FFPsyContext *ctx, int channel, const float **coeffs, const FFPsyWindowInfo *wi)
Perform psychoacoustic analysis and set band info (threshold, energy) for a group of channels...
#define FF_PROFILE_AAC_LOW
#define FF_PROFILE_UNKNOWN
AAC definitions and structures.
FFTContext mdct128
short (128 samples) frame transform context
static const uint8_t swb_size_128_48[]
static const uint8_t swb_size_128_24[]
struct FFPsyContext::@42 bitres
static const uint8_t swb_size_1024_16[]
static av_cold int aac_encode_end(AVCodecContext *avctx)
int frame_size
Samples per packet, initialized when calling 'init'.
static const uint8_t swb_size_1024_32[]
static void put_audio_specific_config(AVCodecContext *avctx)
Make AAC audio config object.
int sample_rate
samples per second
float ff_aac_kbd_short_128[128]
static void encode_ms_info(PutBitContext *pb, ChannelElement *cpe)
Encode MS data.
int frame_bits
number of bits used for the previously encoded frame
static const OptionDef options[]
main external API structure.
static void close(AVCodecParserContext *s)
int bits
number of bits used in the bitresevoir
#define CODEC_FLAG_QSCALE
Use fixed qscale.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
IndividualChannelStream ics
void(* encode_window_bands_info)(struct AACEncContext *s, SingleChannelElement *sce, int win, int group_len, const float lambda)
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Describe the class of an AVClass context structure.
static const uint8_t swb_size_1024_96[]
int window_shape
window shape (sine/KBD/whatever)
static void encode_pulses(AACEncContext *s, Pulse *pulse)
Encode pulse data.
static const uint8_t swb_size_128_16[]
const uint8_t * swb_sizes
table of scalefactor band sizes for a particular window
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
const uint32_t ff_aac_scalefactor_code[121]
const struct FFPsyModel * model
encoder-specific model functions
int ms_mode
Signals mid/side stereo flags coding mode (used by encoder)
void(* vector_fmul_reverse)(float *dst, const float *src0, const float *src1, int len)
static const uint8_t * swb_size_1024[]
struct FFPsyPreprocessContext * psypp
int global_quality
Global quality for codecs which cannot change it per frame.
uint8_t zeroes[128]
band is not coded (used by encoder)
#define CODEC_CAP_EXPERIMENTAL
Codec is experimental and is thus avoided in favor of non experimental encoders.
int sf_idx[128]
scalefactor indices (used by encoder)
const int avpriv_mpeg4audio_sample_rates[16]
Y Spectral Band Replication.
static av_cold int aac_encode_init(AVCodecContext *avctx)
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Single Channel Element - used for both SCE and LFE elements.
windowing related information
void(* vector_fmul)(float *dst, const float *src0, const float *src1, int len)
av_cold struct FFPsyPreprocessContext * ff_psy_preprocess_init(AVCodecContext *avctx)
psychoacoustic model audio preprocessing initialization
AACCoefficientsEncoder ff_aac_coders[]
static void encode_scale_factors(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce)
Encode scalefactors.
AVSampleFormat
all in native-endian format
ChannelElement * cpe
channel elements
Individual Channel Stream.
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static const uint8_t * swb_size_128[]
channel element - generic struct for SCE/CPE/CCE/LFE
FFTContext mdct1024
long (1024 samples) frame transform context
int channels
number of audio channels
static void encode_band_info(AACEncContext *s, SingleChannelElement *sce)
Encode scalefactor band coding type.
static int aac_encode_frame(AVCodecContext *avctx, uint8_t *frame, int buf_size, void *data)
enum BandType band_type[128]
band types
int frame_number
audio or video frame number
void ff_aac_tableinit(void)
static int encode_individual_channel(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, int common_window)
Encode one channel of audio data.
#define CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
static const int sizes[][2]
#define CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
av_cold void ff_psy_end(FFPsyContext *ctx)
Cleanup model context at the end.
int window_type[3]
window type (short/long/transitional, etc.) - current, previous and next
void ff_init_ff_sine_windows(int index)
initialize the specified entry of ff_sine_windows