31 int i, flags1, flags2;
100 const float * win = s->
windows[window_index];
102 float n = window_len/2;
104 for (channel = 0; channel < avctx->
channels; channel++) {
108 s->
output[i+window_len] = audio[j] / n * win[window_len - i - 1];
109 s->
frame_out[channel][i] = audio[j] / n * win[i];
119 float v, *q, max_scale, *q_end;
127 v = pow(10, *exp_param++ * (1.0 / 16.0));
128 max_scale=
FFMAX(max_scale, v);
146 last_exp= *exp_param++;
147 assert(last_exp-10 >= 0 && last_exp-10 < 32);
153 int exp = *exp_param++;
154 int code = exp - last_exp + 60;
155 assert(code >= 0 && code < 120);
164 int v, bsize, ch, coef_nb_bits, parse_exponents;
167 static const int fixed_exp[25]={20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20};
189 mdct_norm = 1.0 / (float)n4;
191 mdct_norm *= sqrt(n4);
209 float *coefs, *exponents,
mult;
214 mult = pow(10, total_gain * 0.05) / s->
max_exponent[ch];
216 coefs = src_coefs[ch];
222 for(i = 0;i < n; i++){
223 double t= *coefs++ / (exponents[i] *
mult);
224 if(t<-32768 || t>32767)
227 coefs1[i] =
lrint(t);
243 for(v= total_gain-1; v>=127; v-= 127)
268 if (parse_exponents) {
289 eptr = ptr + nb_coefs[ch];
292 for(;ptr < eptr; ptr++){
295 int abs_level=
FFABS(level);
297 if(abs_level <= s->
coef_vlcs[tindex]->max_level){
298 if(run < s->
coef_vlcs[tindex]->levels[abs_level-1])
299 code= run + s->
int_table[tindex][abs_level-1];
306 if(1<<coef_nb_bits <= abs_level)
348 unsigned char *buf,
int buf_size,
void *
data){
363 a = s->
coefs[0][i]*0.5;
364 b = s->
coefs[1][i]*0.5;
389 if(scoreL <
FFMIN(best, scoreR)){
392 }
else if(scoreR < best){
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
void(* mdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input)
int next_block_len_bits
log2 of next block length
void avpriv_align_put_bits(PutBitContext *s)
Pad the bitstream with zeros up to the next byte boundary.
int block_len
block length in samples
const uint8_t * huffbits
VLC bit size.
float exponents[MAX_CHANNELS][BLOCK_MAX_SIZE]
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
float WMACoef
type for decoded coefficients, int16_t would be enough for wma 1/2
const uint8_t ff_aac_scalefactor_bits[121]
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
const uint32_t * huffcodes
VLC bit values.
static int encode_frame(WMACodecContext *s, float(*src_coefs)[BLOCK_MAX_SIZE], uint8_t *buf, int buf_size, int total_gain)
static int encode_init(AVCodecContext *avctx)
static int init(AVCodecParserContext *s)
int nb_block_sizes
number of block sizes
int ff_wma_total_gain_to_bits(int total_gain)
static uint8_t * put_bits_ptr(PutBitContext *s)
Return the pointer to the byte where the bitstream writer will put the next bit.
static void encode_exp_vlc(WMACodecContext *s, int ch, const int *exp_param)
uint16_t exponent_bands[BLOCK_NB_SIZES][25]
uint8_t channel_coded[MAX_CHANNELS]
true if channel is coded
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
static void put_bits(PutBitContext *s, int n, unsigned int value)
Write up to 31 bits into a bitstream.
FFTSample output[BLOCK_MAX_SIZE *2]
static int put_bits_count(PutBitContext *s)
int exponent_high_bands[BLOCK_NB_SIZES][HIGH_BAND_MAX_SIZE]
int ff_wma_end(AVCodecContext *avctx)
int bit_rate
the average bitrate
static int encode_superframe(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data)
float * windows[BLOCK_NB_SIZES]
#define MAX_CODED_SUPERFRAME_SIZE
int version
1 = 0x160 (WMAV1), 2 = 0x161 (WMAV2)
int frame_len
frame length in samples
static void init_exp(WMACodecContext *s, int ch, const int *exp_param)
int frame_size
Samples per packet, initialized when calling 'init'.
int frame_len_bits
frame_len = 1 << frame_len_bits
int sample_rate
samples per second
int use_exp_vlc
exponent coding: 0 = lsp, 1 = vlc + delta
main external API structure.
static void close(AVCodecParserContext *s)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
float frame_out[MAX_CHANNELS][BLOCK_MAX_SIZE *2]
static int16_t mult(Float11 *f1, Float11 *f2)
int exponent_high_sizes[BLOCK_NB_SIZES]
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static void apply_window_and_mdct(AVCodecContext *avctx, const signed short *audio, int len)
int use_noise_coding
true if perceptual noise is added
static av_always_inline av_const long int lrint(double x)
int use_variable_block_len
uint8_t ms_stereo
true if mid/side stereo mode
FFTContext mdct_ctx[BLOCK_NB_SIZES]
const uint32_t ff_aac_scalefactor_code[121]
float coefs[MAX_CHANNELS][BLOCK_MAX_SIZE]
int prev_block_len_bits
log2 of prev block length
static int encode_block(WMACodecContext *s, float(*src_coefs)[BLOCK_MAX_SIZE], int total_gain)
int coefs_end[BLOCK_NB_SIZES]
max number of coded coefficients
struct WMACodecContext WMACodecContext
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
AVSampleFormat
all in native-endian format
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
int channels
number of audio channels
WMACoef coefs1[MAX_CHANNELS][BLOCK_MAX_SIZE]
static const CoefVLCTable coef_vlcs[6]
float max_exponent[MAX_CHANNELS]
int coefs_start
first coded coef
int block_len_bits
log2 of current block length
#define CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
int high_band_coded[MAX_CHANNELS][HIGH_BAND_MAX_SIZE]
int ff_wma_init(AVCodecContext *avctx, int flags2)
const CoefVLCTable * coef_vlcs[2]