34 int i, flags1, flags2, block_align;
42 "too many channels: got %i, need %i or fewer\n",
55 "bitrate too low: got %"PRId64
", need 24000 or higher\n",
81 s->use_exp_vlc = flags2 & 0x0001;
82 s->use_bit_reservoir = flags2 & 0x0002;
83 s->use_variable_block_len = flags2 & 0x0004;
91 for (
i = 0;
i <
s->nb_block_sizes;
i++) {
111 int window_index =
s->frame_len_bits -
s->block_len_bits;
114 const float *
win =
s->windows[window_index];
115 int window_len = 1 <<
s->block_len_bits;
116 float n = 2.0 * 32768.0 / window_len;
119 memcpy(
s->output,
s->frame_out[ch], window_len *
sizeof(*
s->output));
120 s->fdsp->vector_fmul_scalar(
s->frame_out[ch], audio[ch], n,
len);
121 s->fdsp->vector_fmul_reverse(&
s->output[window_len],
s->frame_out[ch],
123 s->fdsp->vector_fmul(
s->frame_out[ch],
s->frame_out[ch],
win,
len);
124 mdct->mdct_calc(mdct,
s->coefs[ch],
s->output);
139 float v, *q, max_scale, *q_end;
141 ptr =
s->exponent_bands[
s->frame_len_bits -
s->block_len_bits];
142 q =
s->exponents[ch];
143 q_end = q +
s->block_len;
147 v =
ff_exp10(*exp_param++ *(1.0 / 16.0));
148 max_scale =
FFMAX(max_scale, v);
154 s->max_exponent[ch] = max_scale;
163 ptr =
s->exponent_bands[
s->frame_len_bits -
s->block_len_bits];
164 q =
s->exponents[ch];
165 q_end = q +
s->block_len;
166 if (
s->version == 1) {
167 last_exp = *exp_param++;
168 av_assert0(last_exp - 10 >= 0 && last_exp - 10 < 32);
174 int exp = *exp_param++;
175 int code =
exp - last_exp + 60;
200 if (
s->use_variable_block_len) {
204 s->next_block_len_bits =
s->frame_len_bits;
205 s->prev_block_len_bits =
s->frame_len_bits;
206 s->block_len_bits =
s->frame_len_bits;
209 s->block_len = 1 <<
s->block_len_bits;
211 bsize =
s->frame_len_bits -
s->block_len_bits;
214 v =
s->coefs_end[bsize] -
s->coefs_start;
215 for (ch = 0; ch <
s->avctx->channels; ch++)
218 int n4 =
s->block_len / 2;
219 mdct_norm = 1.0 / (float) n4;
221 mdct_norm *= sqrt(n4);
224 if (
s->avctx->channels == 2)
227 for (ch = 0; ch <
s->avctx->channels; ch++) {
229 s->channel_coded[ch] = 1;
230 if (
s->channel_coded[ch])
234 for (ch = 0; ch <
s->avctx->channels; ch++) {
235 if (
s->channel_coded[ch]) {
237 float *coefs, *exponents,
mult;
240 coefs1 =
s->coefs1[ch];
241 exponents =
s->exponents[ch];
244 coefs = src_coefs[ch];
245 if (
s->use_noise_coding && 0) {
248 coefs +=
s->coefs_start;
250 for (
i = 0;
i < n;
i++) {
251 double t = *coefs++ / (exponents[
i] *
mult);
252 if (t < -32768 || t > 32767)
262 for (ch = 0; ch <
s->avctx->channels; ch++) {
263 int a =
s->channel_coded[ch];
271 for (v = total_gain - 1; v >= 127; v -= 127)
277 if (
s->use_noise_coding) {
278 for (ch = 0; ch <
s->avctx->channels; ch++) {
279 if (
s->channel_coded[ch]) {
281 n =
s->exponent_high_sizes[bsize];
282 for (
i = 0;
i < n;
i++) {
283 put_bits(&
s->pb, 1,
s->high_band_coded[ch][
i] = 0);
285 nb_coefs[ch] -=
s->exponent_high_bands[bsize][
i];
292 if (
s->block_len_bits !=
s->frame_len_bits)
296 for (ch = 0; ch <
s->avctx->channels; ch++) {
297 if (
s->channel_coded[ch]) {
298 if (
s->use_exp_vlc) {
309 for (ch = 0; ch <
s->avctx->channels; ch++) {
310 if (
s->channel_coded[ch]) {
313 tindex = (ch == 1 &&
s->ms_stereo);
314 ptr = &
s->coefs1[ch][0];
315 eptr = ptr + nb_coefs[ch];
318 for (; ptr < eptr; ptr++) {
323 if (abs_level <= s->
coef_vlcs[tindex]->max_level)
324 if (run < s->
coef_vlcs[tindex]->levels[abs_level - 1])
325 code =
run +
s->int_table[tindex][abs_level - 1];
329 s->coef_vlcs[tindex]->huffcodes[
code]);
332 if (1 << coef_nb_bits <= abs_level)
335 put_bits(&
s->pb, coef_nb_bits, abs_level);
345 put_bits(&
s->pb,
s->coef_vlcs[tindex]->huffbits[1],
346 s->coef_vlcs[tindex]->huffcodes[1]);
348 if (
s->version == 1 &&
s->avctx->channels >= 2)
355 uint8_t *buf,
int buf_size,
int total_gain)
359 if (
s->use_bit_reservoir)
373 int i, total_gain, ret,
error;
375 s->block_len_bits =
s->frame_len_bits;
376 s->block_len = 1 <<
s->block_len_bits;
387 for (
i = 0;
i <
s->block_len;
i++) {
388 a =
s->coefs[0][
i] * 0.5;
389 b =
s->coefs[1][
i] * 0.5;
390 s->coefs[0][
i] =
a +
b;
391 s->coefs[1][
i] =
a -
b;
399 for (
i = 64;
i;
i >>= 1) {
406 while(total_gain <= 128 && error > 0)
409 av_log(avctx,
AV_LOG_ERROR,
"Invalid input data or requested bitrate too low, cannot encode\n");
430 #if CONFIG_WMAV1_ENCODER
445 #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 enum AVSampleFormat sample_fmts[]
static float win(SuperEqualizerContext *s, float n, int N)
Macro definitions for various function/variable attributes.
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_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
static av_cold int init(AVCodecContext *avctx)
#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 ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
internal math functions header
static av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
#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.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
AVSampleFormat
Audio sample formats.
@ AV_SAMPLE_FMT_FLTP
float, planar
#define AV_NOPTS_VALUE
Undefined timestamp value.
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
static int16_t mult(Float11 *f1, Float11 *f2)
static av_always_inline int64_t ff_samples_to_time_base(AVCodecContext *avctx, int64_t samples)
Rescale from sample rate to AVCodecContext.time_base.
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static uint8_t * put_bits_ptr(PutBitContext *s)
Return the pointer to the byte where the bitstream writer will put the next bit.
static int put_bits_count(PutBitContext *s)
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
static void align_put_bits(PutBitContext *s)
Pad the bitstream with zeros up to the next byte boundary.
main external API structure.
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
some codecs need / can use extradata like Huffman tables.
int channels
number of audio channels
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.
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
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
uint8_t ** extended_data
pointers to the data planes/channels.
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)
int ff_wma_total_gain_to_bits(int total_gain)
av_cold int ff_wma_init(AVCodecContext *avctx, int flags2)
int ff_wma_end(AVCodecContext *avctx)
#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)