22#include "config_components.h"
38 int i, flags1, flags2, block_align;
46 "too many channels: got %i, need %i or fewer\n",
59 "bitrate too low: got %"PRId64
", need 24000 or higher\n",
82 av_unreachable(
"This function is only used with WMAV1/2 encoders");
85 s->use_exp_vlc = flags2 & 0x0001;
86 s->use_bit_reservoir = flags2 & 0x0002;
87 s->use_variable_block_len = flags2 & 0x0004;
95 for (
i = 0;
i <
s->nb_block_sizes;
i++) {
98 0, 1 << (
s->frame_len_bits -
i), &
scale, 0);
115 const float *
const *audio = (
const float *
const *)
frame->extended_data;
117 int window_index =
s->frame_len_bits -
s->block_len_bits;
119 av_tx_fn mdct_fn =
s->mdct_fn[window_index];
121 const float *
win =
s->windows[window_index];
122 int window_len = 1 <<
s->block_len_bits;
123 float n = 2.0 * 32768.0 / window_len;
126 memcpy(
s->output,
s->frame_out[ch], window_len *
sizeof(*
s->output));
127 s->fdsp->vector_fmul_scalar(
s->frame_out[ch], audio[ch], n,
len);
128 s->fdsp->vector_fmul_reverse(&
s->output[window_len],
s->frame_out[ch],
130 s->fdsp->vector_fmul(
s->frame_out[ch],
s->frame_out[ch],
win,
len);
131 mdct_fn(mdct,
s->coefs[ch],
s->output,
sizeof(
float));
146 float v, *q, max_scale, *q_end;
148 ptr =
s->exponent_bands[
s->frame_len_bits -
s->block_len_bits];
149 q =
s->exponents[ch];
150 q_end = q +
s->block_len;
154 v =
ff_exp10(*exp_param++ *(1.0 / 16.0));
155 max_scale =
FFMAX(max_scale, v);
161 s->max_exponent[ch] = max_scale;
170 ptr =
s->exponent_bands[
s->frame_len_bits -
s->block_len_bits];
171 q =
s->exponents[ch];
172 q_end = q +
s->block_len;
173 if (
s->version == 1) {
174 last_exp = *exp_param++;
175 av_assert0(last_exp - 10 >= 0 && last_exp - 10 < 32);
181 int exp = *exp_param++;
182 int code =
exp - last_exp + 60;
195 int channels =
s->avctx->ch_layout.nb_channels;
208 if (
s->use_variable_block_len) {
209 av_unreachable(
"use_variable_block_len unimplemented, set to 0 during init");
212 s->next_block_len_bits =
s->frame_len_bits;
213 s->prev_block_len_bits =
s->frame_len_bits;
214 s->block_len_bits =
s->frame_len_bits;
217 s->block_len = 1 <<
s->block_len_bits;
219 bsize =
s->frame_len_bits -
s->block_len_bits;
222 v =
s->coefs_end[bsize] -
s->coefs_start;
226 int n4 =
s->block_len / 2;
227 mdct_norm = 1.0 / (
float) n4;
229 mdct_norm *= sqrt(n4);
237 s->channel_coded[ch] = 1;
238 if (
s->channel_coded[ch])
243 if (
s->channel_coded[ch]) {
245 float *coefs, *exponents,
mult;
248 coefs1 =
s->coefs1[ch];
249 exponents =
s->exponents[ch];
252 coefs = src_coefs[ch];
253 if (
s->use_noise_coding && 0) {
256 coefs +=
s->coefs_start;
258 for (
i = 0;
i < n;
i++) {
259 double t = *coefs++ / (exponents[
i] *
mult);
260 if (t < -32768 || t > 32767)
271 int a =
s->channel_coded[ch];
279 for (v = total_gain - 1; v >= 127; v -= 127)
285 if (
s->use_noise_coding) {
287 if (
s->channel_coded[ch]) {
289 n =
s->exponent_high_sizes[bsize];
290 for (
i = 0;
i < n;
i++) {
291 put_bits(&
s->pb, 1,
s->high_band_coded[ch][
i] = 0);
293 nb_coefs[ch] -=
s->exponent_high_bands[bsize][
i];
300 if (
s->block_len_bits !=
s->frame_len_bits)
305 if (
s->channel_coded[ch]) {
306 if (
s->use_exp_vlc) {
319 if (
s->channel_coded[ch]) {
322 tindex = (ch == 1 &&
s->ms_stereo);
323 ptr = &
s->coefs1[ch][0];
327 for (; ptr < eptr; ptr++) {
332 if (abs_level <= s->
coef_vlcs[tindex]->max_level)
334 code =
run +
s->int_table[tindex][abs_level - 1];
338 s->coef_vlcs[tindex]->huffcodes[
code]);
341 if (1 << coef_nb_bits <= abs_level)
344 put_bits(&
s->pb, coef_nb_bits, abs_level);
354 put_bits(&
s->pb,
s->coef_vlcs[tindex]->huffbits[1],
355 s->coef_vlcs[tindex]->huffcodes[1]);
364 uint8_t *buf,
int buf_size,
int total_gain)
368 if (
s->use_bit_reservoir)
369 av_unreachable(
"use_bit_reseroir unimplemented, set to 0 during init");
382 int total_gain, ret,
error;
384 s->block_len_bits =
s->frame_len_bits;
385 s->block_len = 1 <<
s->block_len_bits;
395 for (
int i = 0;
i <
s->block_len;
i++) {
396 a =
s->coefs[0][
i] * 0.5;
397 b =
s->coefs[1][
i] * 0.5;
398 s->coefs[0][
i] =
a +
b;
399 s->coefs[1][
i] =
a -
b;
407 for (
int i = 64;
i;
i >>= 1) {
414 while(total_gain <= 128 && error > 0)
417 av_log(avctx,
AV_LOG_ERROR,
"Invalid input data or requested bitrate too low, cannot encode\n");
437#if CONFIG_WMAV1_ENCODER
452#if CONFIG_WMAV2_ENCODER
static int fixed_exp(int x)
const uint32_t ff_aac_scalefactor_code[121]
const uint8_t ff_aac_scalefactor_bits[121]
static int nb_coefs(int length, int level, uint64_t sn)
static float win(SuperEqualizerContext *s, float n, int N)
const FFCodec ff_wmav2_encoder
const FFCodec ff_wmav1_encoder
static av_cold int encode_init(AVCodecContext *avctx)
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
#define av_unreachable(msg)
Asserts that are used as compiler optimization hints depending upon ASSERT_LEVEL and NBDEBUG.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
#define i(width, name, range_min, range_max)
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define CODEC_SAMPLEFMTS(...)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static int parse_exponents(DBEContext *s, DBEChannel *c)
int(* init)(AVBSFContext *ctx)
int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and allocate data.
static av_always_inline int64_t ff_samples_to_time_base(const AVCodecContext *avctx, int64_t samples)
Rescale from sample rate to AVCodecContext.time_base.
internal math functions header
static av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
#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_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
@ AV_SAMPLE_FMT_FLTP
float, planar
#define AV_NOPTS_VALUE
Undefined timestamp value.
static void scale(int *out, const int *in, const int w, const int h, const int shift)
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
static int16_t mult(Float11 *f1, Float11 *f2)
Macro definitions for various function/variable attributes.
Memory handling functions.
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static int put_bits_count(PutBitContext *s)
static int put_bytes_count(const PutBitContext *s, int round_up)
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
static int put_bytes_output(const PutBitContext *s)
static void align_put_bits(PutBitContext *s)
Pad the bitstream with zeros up to the next byte boundary.
int nb_channels
Number of channels in this layout.
main external API structure.
AVChannelLayout ch_layout
Audio channel layout.
int64_t bit_rate
the average bitrate
const struct AVCodec * codec
int initial_padding
Audio only.
int sample_rate
samples per second
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs.
int frame_size
Number of samples per channel in an audio frame.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
static void error(const char *err)
av_cold int av_tx_init(AVTXContext **ctx, av_tx_fn *tx, enum AVTXType type, int inv, int len, const void *scale, uint64_t flags)
Initialize a transform context with the given configuration (i)MDCTs with an odd length are currently...
@ AV_TX_FLOAT_MDCT
Standard MDCT with a sample data type of float, double or int32_t, respectively.
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.
int ff_wma_total_gain_to_bits(int total_gain)
av_cold int ff_wma_end(AVCodecContext *avctx)
av_cold int ff_wma_init(AVCodecContext *avctx, int flags2)
#define MAX_CODED_SUPERFRAME_SIZE
float WMACoef
type for decoded coefficients, int16_t would be enough for wma 1/2
static const CoefVLCTable coef_vlcs[6]
static void init_exp(WMACodecContext *s, int ch, const int *exp_param)
static int encode_block(WMACodecContext *s, float(*src_coefs)[BLOCK_MAX_SIZE], int total_gain)
static av_cold int encode_init(AVCodecContext *avctx)
static int encode_frame(WMACodecContext *s, float(*src_coefs)[BLOCK_MAX_SIZE], uint8_t *buf, int buf_size, int total_gain)
static int encode_superframe(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
static void encode_exp_vlc(WMACodecContext *s, int ch, const int *exp_param)
static int apply_window_and_mdct(AVCodecContext *avctx, const AVFrame *frame)