/* Helper functions */
-unsigned int ff_vorbis_nth_root(unsigned int x, unsigned int n) { // x^(1/n)
+// x^(1/n)
+unsigned int ff_vorbis_nth_root(unsigned int x, unsigned int n)
+{
unsigned int ret=0, i, j;
do {
// the two bits[p] > 32 checks should be redundant, all calling code should
// already ensure that, but since it allows overwriting the stack it seems
// reasonable to check redundantly.
-int ff_vorbis_len2vlc(uint8_t *bits, uint32_t *codes, uint_fast32_t num) {
+int ff_vorbis_len2vlc(uint8_t *bits, uint32_t *codes, uint_fast32_t num)
+{
uint_fast32_t exit_at_level[33]={404,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
codes[p]=0;
if (bits[p] > 32) return 1;
- for(i=0;i<bits[p];++i) {
+ for(i=0;i<bits[p];++i)
exit_at_level[i+1]=1<<i;
- }
#ifdef V_DEBUG
av_log(NULL, AV_LOG_INFO, " %d. of %d code len %d code %d - ", p, num, bits[p], codes[p]);
init_get_bits(&gb, (uint_fast8_t *)&codes[p], bits[p]);
- for(i=0;i<bits[p];++i) {
+ for(i=0;i<bits[p];++i)
av_log(NULL, AV_LOG_INFO, "%s", get_bits1(&gb) ? "1" : "0");
- }
av_log(NULL, AV_LOG_INFO, "\n");
#endif
if (bits[p] > 32) return 1;
if (bits[p]==0) continue;
// find corresponding exit(node which the tree can grow further from)
- for(i=bits[p];i>0;--i) {
+ for(i=bits[p];i>0;--i)
if (exit_at_level[i]) break;
- }
if (!i) return 1; // overspecified tree
code=exit_at_level[i];
exit_at_level[i]=0;
// construct code (append 0s to end) and introduce new exits
- for(j=i+1;j<=bits[p];++j) {
+ for(j=i+1;j<=bits[p];++j)
exit_at_level[j]=code+(1<<(j-1));
- }
codes[p]=code;
#ifdef V_DEBUG
av_log(NULL, AV_LOG_INFO, " %d. code len %d code %d - ", p, bits[p], codes[p]);
init_get_bits(&gb, (uint_fast8_t *)&codes[p], bits[p]);
- for(i=0;i<bits[p];++i) {
+ for(i=0;i<bits[p];++i)
av_log(NULL, AV_LOG_INFO, "%s", get_bits1(&gb) ? "1" : "0");
- }
av_log(NULL, AV_LOG_INFO, "\n");
#endif
return 0;
}
-void ff_vorbis_ready_floor1_list(vorbis_floor1_entry * list, int values) {
+void ff_vorbis_ready_floor1_list(vorbis_floor1_entry * list, int values)
+{
int i;
list[0].sort = 0;
list[1].sort = 1;
}
}
-static inline void render_line_unrolled(intptr_t x, intptr_t y, int x1, intptr_t sy, int ady, int adx, float * buf) {
+static inline void render_line_unrolled(intptr_t x, intptr_t y, int x1,
+ intptr_t sy, int ady, int adx,
+ float * buf)
+{
int err = -adx;
x -= x1-1;
buf += x1-1;
}
}
-static void render_line(int x0, int y0, int x1, int y1, float * buf) {
+static void render_line(int x0, int y0, int x1, int y1, float * buf)
+{
int dy = y1 - y0;
int adx = x1 - x0;
int ady = FFABS(dy);
}
}
-void ff_vorbis_floor1_render_list(vorbis_floor1_entry * list, int values, uint_fast16_t * y_list, int * flag, int multiplier, float * out, int samples) {
+void ff_vorbis_floor1_render_list(vorbis_floor1_entry * list, int values,
+ uint_fast16_t * y_list, int * flag,
+ int multiplier, float * out, int samples)
+{
int lx, ly, i;
lx = 0;
ly = y_list[0] * multiplier;
void ff_vorbis_ready_floor1_list(vorbis_floor1_entry * list, int values);
unsigned int ff_vorbis_nth_root(unsigned int x, unsigned int n); // x^(1/n)
int ff_vorbis_len2vlc(uint8_t *bits, uint32_t *codes, uint_fast32_t num);
-void ff_vorbis_floor1_render_list(vorbis_floor1_entry * list, int values, uint_fast16_t * y_list, int * flag, int multiplier, float * out, int samples);
+void ff_vorbis_floor1_render_list(vorbis_floor1_entry * list, int values,
+ uint_fast16_t * y_list, int * flag,
+ int multiplier, float * out, int samples);
#define ilog(i) av_log2(2*(i))
0.82788260F, 0.88168307F, 0.9389798F, 1.F,
};
-const float * const ff_vorbis_vwin[8] = { vwin64, vwin128, vwin256, vwin512, vwin1024, vwin2048, vwin4096, vwin8192 };
+const float * const ff_vorbis_vwin[8] = {
+ vwin64, vwin128, vwin256, vwin512,
+ vwin1024, vwin2048, vwin4096, vwin8192
+};
typedef struct {
uint_fast8_t floor_type;
vorbis_floor_decode_func decode;
- union vorbis_floor_u
- {
- struct vorbis_floor0_s
- {
+ union vorbis_floor_u {
+ struct vorbis_floor0_s {
uint_fast8_t order;
uint_fast16_t rate;
uint_fast16_t bark_map_size;
uint_fast8_t * book_list;
float * lsp;
} t0;
- struct vorbis_floor1_s
- {
+ struct vorbis_floor1_s {
uint_fast8_t partitions;
uint_fast8_t maximum_class;
uint_fast8_t partition_class[32];
#define BARK(x) \
(13.1f*atan(0.00074f*(x))+2.24f*atan(1.85e-8f*(x)*(x))+1e-4f*(x))
-static float vorbisfloat2float(uint_fast32_t val) {
+static float vorbisfloat2float(uint_fast32_t val)
+{
double mant=val&0x1fffff;
long exp=(val&0x7fe00000L)>>21;
- if (val&0x80000000) mant=-mant;
+ if (val&0x80000000)
+ mant=-mant;
return ldexp(mant, exp - 20 - 768);
}
// Free all allocated memory -----------------------------------------
-static void vorbis_free(vorbis_context *vc) {
+static void vorbis_free(vorbis_context *vc)
+{
int_fast16_t i;
av_freep(&vc->channel_residues);
av_free(vc->floors[i].data.t0.map[1]);
av_free(vc->floors[i].data.t0.book_list);
av_free(vc->floors[i].data.t0.lsp);
- }
- else {
+ } else {
av_free(vc->floors[i].data.t1.list);
}
}
// Process codebooks part
-static int vorbis_parse_setup_hdr_codebooks(vorbis_context *vc) {
+static int vorbis_parse_setup_hdr_codebooks(vorbis_context *vc)
+{
uint_fast16_t cb;
uint8_t *tmp_vlc_bits;
uint32_t *tmp_vlc_codes;
if (flag) {
tmp_vlc_bits[ce]=get_bits(gb, 5)+1;
++used_entries;
- }
- else tmp_vlc_bits[ce]=0;
+ } else
+ tmp_vlc_bits[ce]=0;
}
} else {
AV_DEBUG(" not sparse \n");
used_entries=entries;
- for(ce=0;ce<entries;++ce) {
+ for(ce=0;ce<entries;++ce)
tmp_vlc_bits[ce]=get_bits(gb, 5)+1;
- }
}
} else {
uint_fast16_t current_entry=0;
AV_DEBUG(" number: %d \n", number);
- for(i=current_entry;i<number+current_entry;++i) {
- if (i<used_entries) tmp_vlc_bits[i]=current_length;
- }
+ for(i=current_entry;i<number+current_entry;++i)
+ if (i<used_entries)
+ tmp_vlc_bits[i]=current_length;
current_entry+=number;
}
for(k=0;k<dim;++k) {
uint_fast32_t multiplicand_offset = lookup_offset % codebook_lookup_values;
codebook_setup->codevectors[j*dim+k]=codebook_multiplicands[multiplicand_offset]*codebook_delta_value+codebook_minimum_value+last;
- if (codebook_sequence_p) {
+ if (codebook_sequence_p)
last=codebook_setup->codevectors[j*dim+k];
- }
lookup_offset/=codebook_lookup_values;
}
tmp_vlc_bits[j]=tmp_vlc_bits[i];
#ifdef V_DEBUG
av_log(vc->avccontext, AV_LOG_INFO, "real lookup offset %d, vector: ", j);
- for(k=0;k<dim;++k) {
+ for(k=0;k<dim;++k)
av_log(vc->avccontext, AV_LOG_INFO, " %f ", codebook_setup->codevectors[j*dim+k]);
- }
av_log(vc->avccontext, AV_LOG_INFO, "\n");
#endif
goto error;
}
entries=used_entries;
- }
- else if (codebook_setup->lookup_type>=2) {
+ } else if (codebook_setup->lookup_type>=2) {
av_log(vc->avccontext, AV_LOG_ERROR, "Codebook lookup type not supported. \n");
goto error;
}
}
codebook_setup->maxdepth=0;
for(t=0;t<entries;++t)
- if (tmp_vlc_bits[t]>=codebook_setup->maxdepth) codebook_setup->maxdepth=tmp_vlc_bits[t];
+ if (tmp_vlc_bits[t]>=codebook_setup->maxdepth)
+ codebook_setup->maxdepth=tmp_vlc_bits[t];
- if(codebook_setup->maxdepth > 3*V_NB_BITS) codebook_setup->nb_bits=V_NB_BITS2;
- else codebook_setup->nb_bits=V_NB_BITS;
+ if(codebook_setup->maxdepth > 3*V_NB_BITS)
+ codebook_setup->nb_bits=V_NB_BITS2;
+ else
+ codebook_setup->nb_bits=V_NB_BITS;
codebook_setup->maxdepth=(codebook_setup->maxdepth+codebook_setup->nb_bits-1)/codebook_setup->nb_bits;
// Process time domain transforms part (unused in Vorbis I)
-static int vorbis_parse_setup_hdr_tdtransforms(vorbis_context *vc) {
+static int vorbis_parse_setup_hdr_tdtransforms(vorbis_context *vc)
+{
GetBitContext *gb=&vc->gb;
uint_fast8_t i;
uint_fast8_t vorbis_time_count=get_bits(gb, 6)+1;
static void create_map( vorbis_context * vc, uint_fast8_t floor_number );
static uint_fast8_t vorbis_floor1_decode(vorbis_context *vc,
vorbis_floor_data *vfu, float *vec);
-static int vorbis_parse_setup_hdr_floors(vorbis_context *vc) {
+static int vorbis_parse_setup_hdr_floors(vorbis_context *vc)
+{
GetBitContext *gb=&vc->gb;
uint_fast16_t i,j,k;
for(j=0;j<floor_setup->data.t1.partitions;++j) {
floor_setup->data.t1.partition_class[j]=get_bits(gb, 4);
- if (floor_setup->data.t1.partition_class[j]>maximum_class) maximum_class=floor_setup->data.t1.partition_class[j];
+ if (floor_setup->data.t1.partition_class[j]>maximum_class)
+ maximum_class=floor_setup->data.t1.partition_class[j];
AV_DEBUG(" %d. floor %d partition class %d \n", i, j, floor_setup->data.t1.partition_class[j]);
floor_setup->data.t1.multiplier=get_bits(gb, 2)+1;
floor_setup->data.t1.x_list_dim=2;
- for(j=0;j<floor_setup->data.t1.partitions;++j) {
+ for(j=0;j<floor_setup->data.t1.partitions;++j)
floor_setup->data.t1.x_list_dim+=floor_setup->data.t1.class_dimensions[floor_setup->data.t1.partition_class[j]];
- }
floor_setup->data.t1.list=av_mallocz(floor_setup->data.t1.x_list_dim * sizeof(vorbis_floor1_entry));
// Precalculate order of x coordinates - needed for decode
ff_vorbis_ready_floor1_list(floor_setup->data.t1.list, floor_setup->data.t1.x_list_dim);
- }
- else if(floor_setup->floor_type==0) {
+ } else if(floor_setup->floor_type==0) {
uint_fast8_t max_codebook_dim=0;
floor_setup->decode=vorbis_floor0_decode;
/* allocate mem for booklist */
floor_setup->data.t0.book_list=
av_malloc(floor_setup->data.t0.num_books);
- if(!floor_setup->data.t0.book_list) { return -1; }
+ if(!floor_setup->data.t0.book_list)
+ return -1;
/* read book indexes */
{
int idx;
floor_setup->data.t0.lsp=
av_malloc((floor_setup->data.t0.order+1 + max_codebook_dim)
* sizeof(float));
- if(!floor_setup->data.t0.lsp) { return -1; }
+ if(!floor_setup->data.t0.lsp)
+ return -1;
}
#ifdef V_DEBUG /* debug output parsed headers */
}
}
#endif
- }
- else {
+ } else {
av_log(vc->avccontext, AV_LOG_ERROR, "Invalid floor type!\n");
return -1;
}
// Process residues part
-static int vorbis_parse_setup_hdr_residues(vorbis_context *vc){
+static int vorbis_parse_setup_hdr_residues(vorbis_context *vc)
+{
GetBitContext *gb=&vc->gb;
uint_fast8_t i, j, k;
for(j=0;j<res_setup->classifications;++j) {
high_bits=0;
low_bits=get_bits(gb, 3);
- if (get_bits1(gb)) {
+ if (get_bits1(gb))
high_bits=get_bits(gb, 5);
- }
cascade[j]=(high_bits<<3)+low_bits;
AV_DEBUG(" %d class casscade depth: %d \n", j, ilog(cascade[j]));
AV_DEBUG(" %d class casscade depth %d book: %d \n", j, k, res_setup->books[j][k]);
- if (k>res_setup->maxpass) {
+ if (k>res_setup->maxpass)
res_setup->maxpass=k;
- }
} else {
res_setup->books[j][k]=-1;
}
// Process mappings part
-static int vorbis_parse_setup_hdr_mappings(vorbis_context *vc) {
+static int vorbis_parse_setup_hdr_mappings(vorbis_context *vc)
+{
GetBitContext *gb=&vc->gb;
uint_fast8_t i, j;
int_fast32_t * map;
int_fast32_t n; //TODO: could theoretically be smaller?
- for (blockflag=0;blockflag<2;++blockflag)
- {
+ for (blockflag=0;blockflag<2;++blockflag) {
n=vc->blocksize[blockflag]/2;
floors[floor_number].data.t0.map[blockflag]=
av_malloc((n+1) * sizeof(int_fast32_t)); // n+sentinel
map[idx]=floor( BARK((vf->rate*idx)/(2.0f*n)) *
((vf->bark_map_size)/
BARK(vf->rate/2.0f )) );
- if (vf->bark_map_size-1 < map[idx]) {
+ if (vf->bark_map_size-1 < map[idx])
map[idx]=vf->bark_map_size-1;
- }
}
map[n]=-1;
vf->map_size[blockflag]=n;
# endif
}
-static int vorbis_parse_setup_hdr_modes(vorbis_context *vc) {
+static int vorbis_parse_setup_hdr_modes(vorbis_context *vc)
+{
GetBitContext *gb=&vc->gb;
uint_fast8_t i;
// Process the whole setup header using the functions above
-static int vorbis_parse_setup_hdr(vorbis_context *vc) {
+static int vorbis_parse_setup_hdr(vorbis_context *vc)
+{
GetBitContext *gb=&vc->gb;
if ((get_bits(gb, 8)!='v') || (get_bits(gb, 8)!='o') ||
// Process the identification header
-static int vorbis_parse_id_hdr(vorbis_context *vc){
+static int vorbis_parse_id_hdr(vorbis_context *vc)
+{
GetBitContext *gb=&vc->gb;
uint_fast8_t bl0, bl1;
// Process the extradata using the functions above (identification header, setup header)
-static av_cold int vorbis_decode_init(AVCodecContext *avccontext) {
+static av_cold int vorbis_decode_init(AVCodecContext *avccontext)
+{
vorbis_context *vc = avccontext->priv_data ;
uint8_t *headers = avccontext->extradata;
int headers_len=avccontext->extradata_size;
// Read and decode floor
static uint_fast8_t vorbis_floor0_decode(vorbis_context *vc,
- vorbis_floor_data *vfu, float *vec) {
+ vorbis_floor_data *vfu, float *vec)
+{
vorbis_floor0 * vf=&vfu->t0;
float * lsp=vf->lsp;
uint_fast32_t amplitude;
codebook.dimensions;
AV_DEBUG( "floor0 dec: vector offset: %d\n", vec_off );
/* copy each vector component and add last to it */
- for (idx=0; idx<codebook.dimensions; ++idx) {
+ for (idx=0; idx<codebook.dimensions; ++idx)
lsp[lsp_len+idx]=codebook.codevectors[vec_off+idx]+last;
- }
last=lsp[lsp_len+idx-1]; /* set last to last vector component */
lsp_len += codebook.dimensions;
int order=vf->order;
float wstep=M_PI/vf->bark_map_size;
- for(i=0;i<order;i++) { lsp[i]=2.0f*cos(lsp[i]); }
+ for(i=0;i<order;i++)
+ lsp[i]=2.0f*cos(lsp[i]);
AV_DEBUG("floor0 synth: map_size=%d; m=%d; wstep=%f\n",
vf->map_size, order, wstep);
if(j==order) { // even order
p *= p*(2.0f-two_cos_w);
q *= q*(2.0f+two_cos_w);
- }
- else { // odd order
+ } else { // odd order
q *= two_cos_w-lsp[j]; // one more time for q
/* final step and square */
}
/* fill vector */
- do { vec[i]=q; ++i; }while(vf->map[blockflag][i]==iter_cond);
+ do {
+ vec[i]=q; ++i;
+ } while (vf->map[blockflag][i]==iter_cond);
}
}
- }
- else {
+ } else {
/* this channel is unused */
return 1;
}
return 0;
}
-static uint_fast8_t vorbis_floor1_decode(vorbis_context *vc, vorbis_floor_data *vfu, float *vec) {
+static uint_fast8_t vorbis_floor1_decode(vorbis_context *vc,
+ vorbis_floor_data *vfu, float *vec)
+{
vorbis_floor1 * vf=&vfu->t1;
GetBitContext *gb=&vc->gb;
uint_fast16_t range_v[4]={ 256, 128, 86, 64 };
AV_DEBUG("Cbits %d \n", cbits);
- if (cbits) { // this reads all subclasses for this partition's class
+ if (cbits) // this reads all subclasses for this partition's class
cval=get_vlc2(gb, vc->codebooks[vf->class_masterbook[class_]].vlc.table,
vc->codebooks[vf->class_masterbook[class_]].nb_bits, 3);
- }
for(j=0;j<cdim;++j) {
book=vf->subclass_books[class_][cval & csub];
// Read and decode residue
-static av_always_inline int vorbis_residue_decode_internal(vorbis_context *vc, vorbis_residue *vr, uint_fast8_t ch, uint_fast8_t *do_not_decode, float *vec, uint_fast16_t vlen, int vr_type) {
+static av_always_inline int vorbis_residue_decode_internal(vorbis_context *vc,
+ vorbis_residue *vr,
+ uint_fast8_t ch,
+ uint_fast8_t *do_not_decode,
+ float *vec,
+ uint_fast16_t
+ vlen, int vr_type)
+{
GetBitContext *gb=&vc->gb;
uint_fast8_t c_p_c=vc->codebooks[vr->classbook].dimensions;
uint_fast16_t n_to_read=vr->end-vr->begin;
uint_fast16_t k;
if (vr_type==2) {
- for(j=1;j<ch;++j) {
+ for(j=1;j<ch;++j)
do_not_decode[0]&=do_not_decode[j]; // FIXME - clobbering input
- }
- if (do_not_decode[0]) return 0;
+ if (do_not_decode[0])
+ return 0;
ch_used=1;
} else {
ch_used=ch;
uint_fast32_t temp2;
temp2=(((uint_fast64_t)temp) * inverse_class)>>32;
- if (partition_count+c_p_c-1-i < ptns_to_read) {
+ if (partition_count+c_p_c-1-i < ptns_to_read)
classifs[j_times_ptns_to_read+partition_count+c_p_c-1-i]=temp-temp2*vr->classifications;
- }
temp=temp2;
}
}
voffs=voffset+j*vlen;
for(k=0;k<step;++k) {
coffs=get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3) * dim;
- for(l=0;l<dim;++l) {
+ for(l=0;l<dim;++l)
vec[voffs+k+l*step]+=codebook.codevectors[coffs+l]; // FPMATH
- }
}
- }
- else if (vr_type==1) {
+ } else if (vr_type==1) {
voffs=voffset+j*vlen;
for(k=0;k<step;++k) {
coffs=get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3) * dim;
AV_DEBUG(" pass %d offs: %d curr: %f change: %f cv offs.: %d \n", pass, voffs, vec[voffs], codebook.codevectors[coffs+l], coffs);
}
}
- }
- else if (vr_type==2 && ch==2 && (voffset&1)==0 && (dim&1)==0) { // most frequent case optimized
+ } else if (vr_type==2 && ch==2 && (voffset&1)==0 && (dim&1)==0) { // most frequent case optimized
voffs=voffset>>1;
if(dim==2) {
}
}
- }
- else if (vr_type==2) {
+ } else if (vr_type==2) {
voffs=voffset;
for(k=0;k<step;++k) {
return 0;
}
-static inline int vorbis_residue_decode(vorbis_context *vc, vorbis_residue *vr, uint_fast8_t ch, uint_fast8_t *do_not_decode, float *vec, uint_fast16_t vlen)
+static inline int vorbis_residue_decode(vorbis_context *vc, vorbis_residue *vr,
+ uint_fast8_t ch,
+ uint_fast8_t *do_not_decode,
+ float *vec, uint_fast16_t vlen)
{
if (vr->type==2)
return vorbis_residue_decode_internal(vc, vr, ch, do_not_decode, vec, vlen, 2);
void vorbis_inverse_coupling(float *mag, float *ang, int blocksize)
{
int i;
- for(i=0; i<blocksize; i++)
- {
+ for(i=0; i<blocksize; i++) {
if (mag[i]>0.0) {
if (ang[i]>0.0) {
ang[i]=mag[i]-ang[i];
}
}
-static void copy_normalize(float *dst, float *src, int len, int exp_bias, float add_bias)
+static void copy_normalize(float *dst, float *src, int len, int exp_bias,
+ float add_bias)
{
int i;
if(exp_bias) {
// Decode the audio packet using the functions above
-static int vorbis_parse_audio_packet(vorbis_context *vc) {
+static int vorbis_parse_audio_packet(vorbis_context *vc)
+{
GetBitContext *gb=&vc->gb;
uint_fast8_t previous_window=vc->previous_window;
blockflag=vc->modes[mode_number].blockflag;
blocksize=vc->blocksize[blockflag];
- if (blockflag) {
+ if (blockflag)
skip_bits(gb, 2); // previous_window, next_window
- }
memset(ch_res_ptr, 0, sizeof(float)*vc->audio_channels*blocksize/2); //FIXME can this be removed ?
memset(ch_floor_ptr, 0, sizeof(float)*vc->audio_channels*blocksize/2); //FIXME can this be removed ?
int_fast16_t len;
- if(!buf_size){
+ if(!buf_size)
return 0;
- }
AV_DEBUG("packet length %d \n", buf_size);
// Close decoder
-static av_cold int vorbis_decode_close(AVCodecContext *avccontext) {
+static av_cold int vorbis_decode_close(AVCodecContext *avccontext)
+{
vorbis_context *vc = avccontext->priv_data;
vorbis_free(vc);
int64_t sample_count;
} vorbis_enc_context;
-static inline void put_codeword(PutBitContext * pb, vorbis_enc_codebook * cb, int entry) {
+static inline void put_codeword(PutBitContext * pb, vorbis_enc_codebook * cb,
+ int entry)
+{
assert(entry >= 0);
assert(entry < cb->nentries);
assert(cb->lens[entry]);
put_bits(pb, cb->lens[entry], cb->codewords[entry]);
}
-static int cb_lookup_vals(int lookup, int dimentions, int entries) {
- if (lookup == 1) return ff_vorbis_nth_root(entries, dimentions);
- else if (lookup == 2) return dimentions * entries;
+static int cb_lookup_vals(int lookup, int dimentions, int entries)
+{
+ if (lookup == 1)
+ return ff_vorbis_nth_root(entries, dimentions);
+ else if (lookup == 2)
+ return dimentions * entries;
return 0;
}
-static void ready_codebook(vorbis_enc_codebook * cb) {
+static void ready_codebook(vorbis_enc_codebook * cb)
+{
int i;
ff_vorbis_len2vlc(cb->lens, cb->codewords, cb->nentries);
}
}
-static void ready_residue(vorbis_enc_residue * rc, vorbis_enc_context * venc) {
+static void ready_residue(vorbis_enc_residue * rc, vorbis_enc_context * venc)
+{
int i;
assert(rc->type == 2);
rc->maxes = av_mallocz(sizeof(float[2]) * rc->classifications);
int j;
vorbis_enc_codebook * cb;
for (j = 0; j < 8; j++)
- if (rc->books[i][j] != -1) break;
- if (j == 8) continue; // zero
+ if (rc->books[i][j] != -1)
+ break;
+ if (j == 8)
+ continue; // zero
cb = &venc->codebooks[rc->books[i][j]];
assert(cb->ndimentions >= 2);
assert(cb->lookup);
for (j = 0; j < cb->nentries; j++) {
float a;
- if (!cb->lens[j]) continue;
+ if (!cb->lens[j])
+ continue;
a = fabs(cb->dimentions[j * cb->ndimentions]);
if (a > rc->maxes[i][0])
rc->maxes[i][0] = a;
}
}
-static void create_vorbis_context(vorbis_enc_context * venc, AVCodecContext * avccontext) {
+static void create_vorbis_context(vorbis_enc_context * venc,
+ AVCodecContext * avccontext)
+{
vorbis_enc_floor * fc;
vorbis_enc_residue * rc;
vorbis_enc_mapping * mc;
ff_mdct_init(&venc->mdct[1], venc->log2_blocksize[1], 0, 1.0);
}
-static void put_float(PutBitContext * pb, float f) {
+static void put_float(PutBitContext * pb, float f)
+{
int exp, mant;
uint32_t res = 0;
mant = (int)ldexp(frexp(f, &exp), 20);
exp += 788 - 20;
- if (mant < 0) { res |= (1 << 31); mant = -mant; }
+ if (mant < 0) {
+ res |= (1 << 31);
+ mant = -mant;
+ }
res |= mant | (exp << 21);
put_bits(pb, 32, res);
}
-static void put_codebook_header(PutBitContext * pb, vorbis_enc_codebook * cb) {
+static void put_codebook_header(PutBitContext * pb, vorbis_enc_codebook * cb)
+{
int i;
int ordered = 0;
put_bits(pb, 24, cb->nentries);
for (i = 1; i < cb->nentries; i++)
- if (cb->lens[i] < cb->lens[i-1]) break;
+ if (cb->lens[i] < cb->lens[i-1])
+ break;
if (i == cb->nentries)
ordered = 1;
while (i < cb->nentries) {
int j;
for (j = 0; j+i < cb->nentries; j++)
- if (cb->lens[j+i] != len) break;
+ if (cb->lens[j+i] != len)
+ break;
put_bits(pb, ilog(cb->nentries - i), j);
i += j;
len++;
} else {
int sparse = 0;
for (i = 0; i < cb->nentries; i++)
- if (!cb->lens[i]) break;
+ if (!cb->lens[i])
+ break;
if (i != cb->nentries)
sparse = 1;
put_bits(pb, 1, sparse);
for (i = 0; i < cb->nentries; i++) {
- if (sparse) put_bits(pb, 1, !!cb->lens[i]);
- if (cb->lens[i]) put_bits(pb, 5, cb->lens[i] - 1);
+ if (sparse)
+ put_bits(pb, 1, !!cb->lens[i]);
+ if (cb->lens[i])
+ put_bits(pb, 5, cb->lens[i] - 1);
}
}
}
}
-static void put_floor_header(PutBitContext * pb, vorbis_enc_floor * fc) {
+static void put_floor_header(PutBitContext * pb, vorbis_enc_floor * fc)
+{
int i;
put_bits(pb, 16, 1); // type, only floor1 is supported
put_bits(pb, fc->rangebits, fc->list[i].x);
}
-static void put_residue_header(PutBitContext * pb, vorbis_enc_residue * rc) {
+static void put_residue_header(PutBitContext * pb, vorbis_enc_residue * rc)
+{
int i;
put_bits(pb, 16, rc->type);
}
}
-static int put_main_header(vorbis_enc_context * venc, uint8_t ** out) {
+static int put_main_header(vorbis_enc_context * venc, uint8_t ** out)
+{
int i;
PutBitContext pb;
uint8_t buffer[50000] = {0}, * p = buffer;
return p - *out;
}
-static float get_floor_average(vorbis_enc_floor * fc, float * coeffs, int i) {
+static float get_floor_average(vorbis_enc_floor * fc, float * coeffs, int i)
+{
int begin = fc->list[fc->list[FFMAX(i-1, 0)].sort].x;
int end = fc->list[fc->list[FFMIN(i+1, fc->values - 1)].sort].x;
int j;
return average / (end - begin);
}
-static void floor_fit(vorbis_enc_context * venc, vorbis_enc_floor * fc, float * coeffs, uint_fast16_t * posts, int samples) {
+static void floor_fit(vorbis_enc_context * venc, vorbis_enc_floor * fc,
+ float * coeffs, uint_fast16_t * posts, int samples)
+{
int range = 255 / fc->multiplier + 1;
int i;
float tot_average = 0.;
average *= pow(tot_average / average, 0.5) * pow(1.25, position/200.); // MAGIC!
for (j = 0; j < range - 1; j++)
- if (ff_vorbis_floor1_inverse_db_table[j * fc->multiplier] > average) break;
+ if (ff_vorbis_floor1_inverse_db_table[j * fc->multiplier] > average)
+ break;
posts[fc->list[i].sort] = j;
}
}
-static int render_point(int x0, int y0, int x1, int y1, int x) {
+static int render_point(int x0, int y0, int x1, int y1, int x)
+{
return y0 + (x - x0) * (y1 - y0) / (x1 - x0);
}
-static void floor_encode(vorbis_enc_context * venc, vorbis_enc_floor * fc, PutBitContext * pb, uint_fast16_t * posts, float * floor, int samples) {
+static void floor_encode(vorbis_enc_context * venc, vorbis_enc_floor * fc,
+ PutBitContext * pb, uint_fast16_t * posts,
+ float * floor, int samples)
+{
int range = 255 / fc->multiplier + 1;
int coded[fc->values]; // first 2 values are unused
int i, counter;
coded[i] = 0; // must be used later as flag!
continue;
} else {
- if (!coded[fc->list[i].low ]) coded[fc->list[i].low ] = -1;
- if (!coded[fc->list[i].high]) coded[fc->list[i].high] = -1;
+ if (!coded[fc->list[i].low ])
+ coded[fc->list[i].low ] = -1;
+ if (!coded[fc->list[i].high])
+ coded[fc->list[i].high] = -1;
}
if (posts[i] > predicted) {
if (posts[i] - predicted > room)
if (c->books[l] != -1)
maxval = venc->codebooks[c->books[l]].nentries;
// coded could be -1, but this still works, cause that is 0
- if (coded[counter + k] < maxval) break;
+ if (coded[counter + k] < maxval)
+ break;
}
assert(l != csub);
cval |= l << cshift;
int book = c->books[cval & (csub-1)];
int entry = coded[counter++];
cval >>= c->subclass;
- if (book == -1) continue;
- if (entry == -1) entry = 0;
+ if (book == -1)
+ continue;
+ if (entry == -1)
+ entry = 0;
put_codeword(pb, &venc->codebooks[book], entry);
}
}
ff_vorbis_floor1_render_list(fc->list, fc->values, posts, coded, fc->multiplier, floor, samples);
}
-static float * put_vector(vorbis_enc_codebook * book, PutBitContext * pb, float * num) {
+static float * put_vector(vorbis_enc_codebook * book, PutBitContext * pb, float * num)
+{
int i, entry = -1;
float distance = FLT_MAX;
assert(book->dimentions);
for (i = 0; i < book->nentries; i++) {
float * vec = book->dimentions + i * book->ndimentions, d = book->pow2[i];
int j;
- if (!book->lens[i]) continue;
+ if (!book->lens[i])
+ continue;
for (j = 0; j < book->ndimentions; j++)
d -= vec[j] * num[j];
if (distance > d) {
return &book->dimentions[entry * book->ndimentions];
}
-static void residue_encode(vorbis_enc_context * venc, vorbis_enc_residue * rc, PutBitContext * pb, float * coeffs, int samples, int real_ch) {
+static void residue_encode(vorbis_enc_context * venc, vorbis_enc_residue * rc,
+ PutBitContext * pb, float * coeffs, int samples,
+ int real_ch)
+{
int pass, i, j, p, k;
int psize = rc->partition_size;
int partitions = (rc->end - rc->begin) / psize;
max2 = FFMAX(max2, fabs(coeffs[samples + k / real_ch]));
}
- for (i = 0; i < rc->classifications - 1; i++) {
- if (max1 < rc->maxes[i][0] && max2 < rc->maxes[i][1]) break;
- }
+ for (i = 0; i < rc->classifications - 1; i++)
+ if (max1 < rc->maxes[i][0] && max2 < rc->maxes[i][1])
+ break;
classes[0][p] = i;
}
int nbook = rc->books[classes[j][p]][pass];
vorbis_enc_codebook * book = &venc->codebooks[nbook];
float * buf = coeffs + samples*j + rc->begin + p*psize;
- if (nbook == -1) continue;
+ if (nbook == -1)
+ continue;
assert(rc->type == 0 || rc->type == 2);
assert(!(psize % book->ndimentions));
}
}
-static int apply_window_and_mdct(vorbis_enc_context * venc, signed short * audio, int samples) {
+static int apply_window_and_mdct(vorbis_enc_context * venc,
+ signed short * audio, int samples)
+{
int i, j, channel;
const float * win = venc->win[0];
int window_len = 1 << (venc->log2_blocksize[0] - 1);
if (!venc->have_saved && !samples) return 0;
- if (venc->have_saved) {
- for (channel = 0; channel < venc->channels; channel++) {
+ if (venc->have_saved)
+ for (channel = 0; channel < venc->channels; channel++)
memcpy(venc->samples + channel*window_len*2, venc->saved + channel*window_len, sizeof(float)*window_len);
- }
- } else {
- for (channel = 0; channel < venc->channels; channel++) {
+ else
+ for (channel = 0; channel < venc->channels; channel++)
memset(venc->samples + channel*window_len*2, 0, sizeof(float)*window_len);
- }
- }
if (samples) {
for (channel = 0; channel < venc->channels; channel++) {
offset[i] = -audio[j] / 32768. / n * win[window_len - i - 1]; //FIXME find out why the sign has to be fliped
}
} else {
- for (channel = 0; channel < venc->channels; channel++) {
+ for (channel = 0; channel < venc->channels; channel++)
memset(venc->samples + channel*window_len*2 + window_len, 0, sizeof(float)*window_len);
- }
}
- for (channel = 0; channel < venc->channels; channel++) {
+ for (channel = 0; channel < venc->channels; channel++)
ff_mdct_calc(&venc->mdct[0], venc->coeffs + channel*window_len, venc->samples + channel*window_len*2);
- }
if (samples) {
for (channel = 0; channel < venc->channels; channel++) {
PutBitContext pb;
int i;
- if (!apply_window_and_mdct(venc, audio, samples)) return 0;
+ if (!apply_window_and_mdct(venc, audio, samples))
+ return 0;
samples = 1 << (venc->log2_blocksize[0] - 1);
init_put_bits(&pb, packets, buf_size);
floor_encode(venc, fc, &pb, posts, &venc->floor[i * samples], samples);
}
- for (i = 0; i < venc->channels * samples; i++) {
+ for (i = 0; i < venc->channels * samples; i++)
venc->coeffs[i] /= venc->floor[i];
- }
for (i = 0; i < mapping->coupling_steps; i++) {
float * mag = venc->coeffs + mapping->magnitude[i] * samples;
for (j = 0; j < samples; j++) {
float a = ang[j];
ang[j] -= mag[j];
- if (mag[j] > 0) ang[j] = -ang[j];
- if (ang[j] < 0) mag[j] = a;
+ if (mag[j] > 0)
+ ang[j] = -ang[j];
+ if (ang[j] < 0)
+ mag[j] = a;
}
}