Revision a7adcf29 libavcodec/vorbis_dec.c

View differences:

libavcodec/vorbis_dec.c
2 2
 * @file libavcodec/vorbis_dec.c
3 3
 * Vorbis I decoder
4 4
 * @author Denes Balatoni  ( dbalatoni programozo hu )
5

  
5
 *
6 6
 * This file is part of FFmpeg.
7 7
 *
8 8
 * FFmpeg is free software; you can redistribute it and/or
......
36 36

  
37 37
#define V_NB_BITS 8
38 38
#define V_NB_BITS2 11
39
#define V_MAX_VLCS (1<<16)
40
#define V_MAX_PARTITIONS (1<<20)
39
#define V_MAX_VLCS (1 << 16)
40
#define V_MAX_PARTITIONS (1 << 20)
41 41

  
42 42
#ifndef V_DEBUG
43 43
#define AV_DEBUG(...)
......
55 55
    unsigned int nb_bits;
56 56
} vorbis_codebook;
57 57

  
58
typedef union vorbis_floor_u vorbis_floor_data;
58
typedef union  vorbis_floor_u  vorbis_floor_data;
59 59
typedef struct vorbis_floor0_s vorbis_floor0;
60 60
typedef struct vorbis_floor1_s vorbis_floor1;
61 61
struct vorbis_context_s;
......
67 67
    vorbis_floor_decode_func decode;
68 68
    union vorbis_floor_u {
69 69
        struct vorbis_floor0_s {
70
            uint_fast8_t order;
70
            uint_fast8_t  order;
71 71
            uint_fast16_t rate;
72 72
            uint_fast16_t bark_map_size;
73
            int_fast32_t * map[2];
73
            int_fast32_t *map[2];
74 74
            uint_fast32_t map_size[2];
75
            uint_fast8_t amplitude_bits;
76
            uint_fast8_t amplitude_offset;
77
            uint_fast8_t num_books;
78
            uint_fast8_t * book_list;
79
            float * lsp;
75
            uint_fast8_t  amplitude_bits;
76
            uint_fast8_t  amplitude_offset;
77
            uint_fast8_t  num_books;
78
            uint_fast8_t *book_list;
79
            float        *lsp;
80 80
        } t0;
81 81
        struct vorbis_floor1_s {
82 82
            uint_fast8_t partitions;
......
88 88
            int_fast16_t subclass_books[16][8];
89 89
            uint_fast8_t multiplier;
90 90
            uint_fast16_t x_list_dim;
91
            vorbis_floor1_entry * list;
91
            vorbis_floor1_entry *list;
92 92
        } t1;
93 93
    } data;
94 94
} vorbis_floor;
......
98 98
    uint_fast32_t begin;
99 99
    uint_fast32_t end;
100 100
    uint_fast32_t partition_size;
101
    uint_fast8_t classifications;
102
    uint_fast8_t classbook;
103
    int_fast16_t books[64][8];
104
    uint_fast8_t maxpass;
101
    uint_fast8_t  classifications;
102
    uint_fast8_t  classbook;
103
    int_fast16_t  books[64][8];
104
    uint_fast8_t  maxpass;
105 105
} vorbis_residue;
106 106

  
107 107
typedef struct {
108
    uint_fast8_t submaps;
108
    uint_fast8_t  submaps;
109 109
    uint_fast16_t coupling_steps;
110 110
    uint_fast8_t *magnitude;
111 111
    uint_fast8_t *angle;
112 112
    uint_fast8_t *mux;
113
    uint_fast8_t submap_floor[16];
114
    uint_fast8_t submap_residue[16];
113
    uint_fast8_t  submap_floor[16];
114
    uint_fast8_t  submap_residue[16];
115 115
} vorbis_mapping;
116 116

  
117 117
typedef struct {
118
    uint_fast8_t blockflag;
118
    uint_fast8_t  blockflag;
119 119
    uint_fast16_t windowtype;
120 120
    uint_fast16_t transformtype;
121
    uint_fast8_t mapping;
121
    uint_fast8_t  mapping;
122 122
} vorbis_mode;
123 123

  
124 124
typedef struct vorbis_context_s {
......
127 127
    DSPContext dsp;
128 128

  
129 129
    FFTContext mdct[2];
130
    uint_fast8_t first_frame;
130
    uint_fast8_t  first_frame;
131 131
    uint_fast32_t version;
132
    uint_fast8_t audio_channels;
132
    uint_fast8_t  audio_channels;
133 133
    uint_fast32_t audio_samplerate;
134 134
    uint_fast32_t bitrate_maximum;
135 135
    uint_fast32_t bitrate_nominal;
136 136
    uint_fast32_t bitrate_minimum;
137 137
    uint_fast32_t blocksize[2];
138
    const float * win[2];
138
    const float  *win[2];
139 139
    uint_fast16_t codebook_count;
140 140
    vorbis_codebook *codebooks;
141
    uint_fast8_t floor_count;
141
    uint_fast8_t  floor_count;
142 142
    vorbis_floor *floors;
143
    uint_fast8_t residue_count;
143
    uint_fast8_t  residue_count;
144 144
    vorbis_residue *residues;
145
    uint_fast8_t mapping_count;
145
    uint_fast8_t  mapping_count;
146 146
    vorbis_mapping *mappings;
147
    uint_fast8_t mode_count;
148
    vorbis_mode *modes;
149
    uint_fast8_t mode_number; // mode number for the current packet
150
    uint_fast8_t previous_window;
151
    float *channel_residues;
152
    float *channel_floors;
153
    float *saved;
147
    uint_fast8_t  mode_count;
148
    vorbis_mode  *modes;
149
    uint_fast8_t  mode_number; // mode number for the current packet
150
    uint_fast8_t  previous_window;
151
    float        *channel_residues;
152
    float        *channel_floors;
153
    float        *saved;
154 154
    uint_fast32_t add_bias; // for float->int conversion
155 155
    uint_fast32_t exp_bias;
156 156
} vorbis_context;
......
158 158
/* Helper functions */
159 159

  
160 160
#define BARK(x) \
161
    (13.1f*atan(0.00074f*(x))+2.24f*atan(1.85e-8f*(x)*(x))+1e-4f*(x))
161
    (13.1f * atan(0.00074f * (x)) + 2.24f * atan(1.85e-8f * (x) * (x)) + 1e-4f * (x))
162 162

  
163 163
static float vorbisfloat2float(uint_fast32_t val)
164 164
{
165
    double mant=val&0x1fffff;
166
    long exp=(val&0x7fe00000L)>>21;
167
    if (val&0x80000000)
168
        mant=-mant;
165
    double mant = val & 0x1fffff;
166
    long exp    = (val & 0x7fe00000L) >> 21;
167
    if (val & 0x80000000)
168
        mant = -mant;
169 169
    return ldexp(mant, exp - 20 - 768);
170 170
}
171 171

  
......
186 186
    ff_mdct_end(&vc->mdct[0]);
187 187
    ff_mdct_end(&vc->mdct[1]);
188 188

  
189
    for(i=0;i<vc->codebook_count;++i) {
189
    for (i = 0; i < vc->codebook_count; ++i) {
190 190
        av_free(vc->codebooks[i].codevectors);
191 191
        free_vlc(&vc->codebooks[i].vlc);
192 192
    }
193 193
    av_freep(&vc->codebooks);
194 194

  
195
    for(i=0;i<vc->floor_count;++i) {
196
        if(vc->floors[i].floor_type==0) {
195
    for (i = 0; i < vc->floor_count; ++i) {
196
        if (vc->floors[i].floor_type == 0) {
197 197
            av_free(vc->floors[i].data.t0.map[0]);
198 198
            av_free(vc->floors[i].data.t0.map[1]);
199 199
            av_free(vc->floors[i].data.t0.book_list);
......
204 204
    }
205 205
    av_freep(&vc->floors);
206 206

  
207
    for(i=0;i<vc->mapping_count;++i) {
207
    for (i = 0; i < vc->mapping_count; ++i) {
208 208
        av_free(vc->mappings[i].magnitude);
209 209
        av_free(vc->mappings[i].angle);
210 210
        av_free(vc->mappings[i].mux);
......
219 219
static int vorbis_parse_setup_hdr_codebooks(vorbis_context *vc)
220 220
{
221 221
    uint_fast16_t cb;
222
    uint8_t *tmp_vlc_bits;
222
    uint8_t  *tmp_vlc_bits;
223 223
    uint32_t *tmp_vlc_codes;
224
    GetBitContext *gb=&vc->gb;
224
    GetBitContext *gb = &vc->gb;
225 225

  
226
    vc->codebook_count=get_bits(gb,8)+1;
226
    vc->codebook_count = get_bits(gb, 8) + 1;
227 227

  
228 228
    AV_DEBUG(" Codebooks: %d \n", vc->codebook_count);
229 229

  
230
    vc->codebooks=av_mallocz(vc->codebook_count * sizeof(vorbis_codebook));
231
    tmp_vlc_bits =av_mallocz(V_MAX_VLCS * sizeof(uint8_t));
232
    tmp_vlc_codes=av_mallocz(V_MAX_VLCS * sizeof(uint32_t));
230
    vc->codebooks = av_mallocz(vc->codebook_count * sizeof(vorbis_codebook));
231
    tmp_vlc_bits  = av_mallocz(V_MAX_VLCS * sizeof(uint8_t));
232
    tmp_vlc_codes = av_mallocz(V_MAX_VLCS * sizeof(uint32_t));
233 233

  
234
    for(cb=0;cb<vc->codebook_count;++cb) {
235
        vorbis_codebook *codebook_setup=&vc->codebooks[cb];
234
    for (cb = 0; cb < vc->codebook_count; ++cb) {
235
        vorbis_codebook *codebook_setup = &vc->codebooks[cb];
236 236
        uint_fast8_t ordered;
237
        uint_fast32_t t, used_entries=0;
237
        uint_fast32_t t, used_entries = 0;
238 238
        uint_fast32_t entries;
239 239

  
240 240
        AV_DEBUG(" %d. Codebook \n", cb);
241 241

  
242
        if (get_bits(gb, 24)!=0x564342) {
242
        if (get_bits(gb, 24) != 0x564342) {
243 243
            av_log(vc->avccontext, AV_LOG_ERROR, " %"PRIdFAST16". Codebook setup data corrupt. \n", cb);
244 244
            goto error;
245 245
        }
246 246

  
247 247
        codebook_setup->dimensions=get_bits(gb, 16);
248
        if (codebook_setup->dimensions>16||codebook_setup->dimensions==0) {
248
        if (codebook_setup->dimensions > 16 || codebook_setup->dimensions == 0) {
249 249
            av_log(vc->avccontext, AV_LOG_ERROR, " %"PRIdFAST16". Codebook's dimension is invalid (%d). \n", cb, codebook_setup->dimensions);
250 250
            goto error;
251 251
        }
252
        entries=get_bits(gb, 24);
253
        if (entries>V_MAX_VLCS) {
252
        entries = get_bits(gb, 24);
253
        if (entries > V_MAX_VLCS) {
254 254
            av_log(vc->avccontext, AV_LOG_ERROR, " %"PRIdFAST16". Codebook has too many entries (%"PRIdFAST32"). \n", cb, entries);
255 255
            goto error;
256 256
        }
257 257

  
258
        ordered=get_bits1(gb);
258
        ordered = get_bits1(gb);
259 259

  
260 260
        AV_DEBUG(" codebook_dimensions %d, codebook_entries %d \n", codebook_setup->dimensions, entries);
261 261

  
262 262
        if (!ordered) {
263 263
            uint_fast16_t ce;
264
            uint_fast8_t flag;
265
            uint_fast8_t sparse=get_bits1(gb);
264
            uint_fast8_t  flag;
265
            uint_fast8_t  sparse = get_bits1(gb);
266 266

  
267 267
            AV_DEBUG(" not ordered \n");
268 268

  
269 269
            if (sparse) {
270 270
                AV_DEBUG(" sparse \n");
271 271

  
272
                used_entries=0;
273
                for(ce=0;ce<entries;++ce) {
274
                    flag=get_bits1(gb);
272
                used_entries = 0;
273
                for (ce = 0; ce < entries; ++ce) {
274
                    flag = get_bits1(gb);
275 275
                    if (flag) {
276
                        tmp_vlc_bits[ce]=get_bits(gb, 5)+1;
276
                        tmp_vlc_bits[ce] = get_bits(gb, 5) + 1;
277 277
                        ++used_entries;
278 278
                    } else
279
                        tmp_vlc_bits[ce]=0;
279
                        tmp_vlc_bits[ce] = 0;
280 280
                }
281 281
            } else {
282 282
                AV_DEBUG(" not sparse \n");
283 283

  
284
                used_entries=entries;
285
                for(ce=0;ce<entries;++ce)
286
                    tmp_vlc_bits[ce]=get_bits(gb, 5)+1;
284
                used_entries = entries;
285
                for (ce = 0; ce < entries; ++ce)
286
                    tmp_vlc_bits[ce] = get_bits(gb, 5) + 1;
287 287
            }
288 288
        } else {
289
            uint_fast16_t current_entry=0;
290
            uint_fast8_t current_length=get_bits(gb, 5)+1;
289
            uint_fast16_t current_entry = 0;
290
            uint_fast8_t current_length = get_bits(gb, 5)+1;
291 291

  
292 292
            AV_DEBUG(" ordered, current length: %d \n", current_length);  //FIXME
293 293

  
294
            used_entries=entries;
295
            for(;current_entry<used_entries && current_length <= 32;++current_length) {
294
            used_entries = entries;
295
            for (; current_entry < used_entries && current_length <= 32; ++current_length) {
296 296
                uint_fast16_t i, number;
297 297

  
298 298
                AV_DEBUG(" number bits: %d ", ilog(entries - current_entry));
299 299

  
300
                number=get_bits(gb, ilog(entries - current_entry));
300
                number = get_bits(gb, ilog(entries - current_entry));
301 301

  
302 302
                AV_DEBUG(" number: %d \n", number);
303 303

  
304
                for(i=current_entry;i<number+current_entry;++i)
305
                    if (i<used_entries)
306
                        tmp_vlc_bits[i]=current_length;
304
                for (i = current_entry; i < number+current_entry; ++i)
305
                    if (i < used_entries)
306
                        tmp_vlc_bits[i] = current_length;
307 307

  
308 308
                current_entry+=number;
309 309
            }
......
313 313
            }
314 314
        }
315 315

  
316
        codebook_setup->lookup_type=get_bits(gb, 4);
316
        codebook_setup->lookup_type = get_bits(gb, 4);
317 317

  
318
        AV_DEBUG(" lookup type: %d : %s \n", codebook_setup->lookup_type, codebook_setup->lookup_type ? "vq" : "no lookup" );
318
        AV_DEBUG(" lookup type: %d : %s \n", codebook_setup->lookup_type, codebook_setup->lookup_type ? "vq" : "no lookup");
319 319

  
320 320
// If the codebook is used for (inverse) VQ, calculate codevectors.
321 321

  
322
        if (codebook_setup->lookup_type==1) {
322
        if (codebook_setup->lookup_type == 1) {
323 323
            uint_fast16_t i, j, k;
324
            uint_fast16_t codebook_lookup_values=ff_vorbis_nth_root(entries, codebook_setup->dimensions);
324
            uint_fast16_t codebook_lookup_values = ff_vorbis_nth_root(entries, codebook_setup->dimensions);
325 325
            uint_fast16_t codebook_multiplicands[codebook_lookup_values];
326 326

  
327
            float codebook_minimum_value=vorbisfloat2float(get_bits_long(gb, 32));
328
            float codebook_delta_value=vorbisfloat2float(get_bits_long(gb, 32));
329
            uint_fast8_t codebook_value_bits=get_bits(gb, 4)+1;
330
            uint_fast8_t codebook_sequence_p=get_bits1(gb);
327
            float codebook_minimum_value = vorbisfloat2float(get_bits_long(gb, 32));
328
            float codebook_delta_value   = vorbisfloat2float(get_bits_long(gb, 32));
329
            uint_fast8_t codebook_value_bits = get_bits(gb, 4)+1;
330
            uint_fast8_t codebook_sequence_p = get_bits1(gb);
331 331

  
332 332
            AV_DEBUG(" We expect %d numbers for building the codevectors. \n", codebook_lookup_values);
333 333
            AV_DEBUG("  delta %f minmum %f \n", codebook_delta_value, codebook_minimum_value);
334 334

  
335
            for(i=0;i<codebook_lookup_values;++i) {
336
                codebook_multiplicands[i]=get_bits(gb, codebook_value_bits);
335
            for (i = 0; i < codebook_lookup_values; ++i) {
336
                codebook_multiplicands[i] = get_bits(gb, codebook_value_bits);
337 337

  
338 338
                AV_DEBUG(" multiplicands*delta+minmum : %e \n", (float)codebook_multiplicands[i]*codebook_delta_value+codebook_minimum_value);
339 339
                AV_DEBUG(" multiplicand %d \n", codebook_multiplicands[i]);
340 340
            }
341 341

  
342 342
// Weed out unused vlcs and build codevector vector
343
            codebook_setup->codevectors=used_entries ? av_mallocz(used_entries*codebook_setup->dimensions * sizeof(float)) : NULL;
344
            for(j=0, i=0;i<entries;++i) {
345
                uint_fast8_t dim=codebook_setup->dimensions;
343
            codebook_setup->codevectors = used_entries ? av_mallocz(used_entries*codebook_setup->dimensions * sizeof(float)) : NULL;
344
            for (j = 0, i = 0; i < entries; ++i) {
345
                uint_fast8_t dim = codebook_setup->dimensions;
346 346

  
347 347
                if (tmp_vlc_bits[i]) {
348
                    float last=0.0;
349
                    uint_fast32_t lookup_offset=i;
348
                    float last = 0.0;
349
                    uint_fast32_t lookup_offset = i;
350 350

  
351 351
#ifdef V_DEBUG
352 352
                    av_log(vc->avccontext, AV_LOG_INFO, "Lookup offset %d ,", i);
353 353
#endif
354 354

  
355
                    for(k=0;k<dim;++k) {
355
                    for (k = 0; k < dim; ++k) {
356 356
                        uint_fast32_t multiplicand_offset = lookup_offset % codebook_lookup_values;
357
                        codebook_setup->codevectors[j*dim+k]=codebook_multiplicands[multiplicand_offset]*codebook_delta_value+codebook_minimum_value+last;
357
                        codebook_setup->codevectors[j * dim + k] = codebook_multiplicands[multiplicand_offset] * codebook_delta_value + codebook_minimum_value + last;
358 358
                        if (codebook_sequence_p)
359
                            last=codebook_setup->codevectors[j*dim+k];
359
                            last = codebook_setup->codevectors[j * dim + k];
360 360
                        lookup_offset/=codebook_lookup_values;
361 361
                    }
362
                    tmp_vlc_bits[j]=tmp_vlc_bits[i];
362
                    tmp_vlc_bits[j] = tmp_vlc_bits[i];
363 363

  
364 364
#ifdef V_DEBUG
365 365
                    av_log(vc->avccontext, AV_LOG_INFO, "real lookup offset %d, vector: ", j);
366
                    for(k=0;k<dim;++k)
367
                        av_log(vc->avccontext, AV_LOG_INFO, " %f ", codebook_setup->codevectors[j*dim+k]);
366
                    for (k = 0; k < dim; ++k)
367
                        av_log(vc->avccontext, AV_LOG_INFO, " %f ", codebook_setup->codevectors[j * dim + k]);
368 368
                    av_log(vc->avccontext, AV_LOG_INFO, "\n");
369 369
#endif
370 370

  
371 371
                    ++j;
372 372
                }
373 373
            }
374
            if (j!=used_entries) {
374
            if (j != used_entries) {
375 375
                av_log(vc->avccontext, AV_LOG_ERROR, "Bug in codevector vector building code. \n");
376 376
                goto error;
377 377
            }
378
            entries=used_entries;
379
        } else if (codebook_setup->lookup_type>=2) {
378
            entries = used_entries;
379
        } else if (codebook_setup->lookup_type >= 2) {
380 380
            av_log(vc->avccontext, AV_LOG_ERROR, "Codebook lookup type not supported. \n");
381 381
            goto error;
382 382
        }
......
386 386
            av_log(vc->avccontext, AV_LOG_ERROR, " Invalid code lengths while generating vlcs. \n");
387 387
            goto error;
388 388
        }
389
        codebook_setup->maxdepth=0;
390
        for(t=0;t<entries;++t)
391
            if (tmp_vlc_bits[t]>=codebook_setup->maxdepth)
392
                codebook_setup->maxdepth=tmp_vlc_bits[t];
389
        codebook_setup->maxdepth = 0;
390
        for (t = 0; t < entries; ++t)
391
            if (tmp_vlc_bits[t] >= codebook_setup->maxdepth)
392
                codebook_setup->maxdepth = tmp_vlc_bits[t];
393 393

  
394
        if(codebook_setup->maxdepth > 3*V_NB_BITS)
395
            codebook_setup->nb_bits=V_NB_BITS2;
394
        if (codebook_setup->maxdepth > 3 * V_NB_BITS)
395
            codebook_setup->nb_bits = V_NB_BITS2;
396 396
        else
397
            codebook_setup->nb_bits=V_NB_BITS;
397
            codebook_setup->nb_bits = V_NB_BITS;
398 398

  
399
        codebook_setup->maxdepth=(codebook_setup->maxdepth+codebook_setup->nb_bits-1)/codebook_setup->nb_bits;
399
        codebook_setup->maxdepth = (codebook_setup->maxdepth+codebook_setup->nb_bits - 1) / codebook_setup->nb_bits;
400 400

  
401 401
        if (init_vlc(&codebook_setup->vlc, codebook_setup->nb_bits, entries, tmp_vlc_bits, sizeof(*tmp_vlc_bits), sizeof(*tmp_vlc_bits), tmp_vlc_codes, sizeof(*tmp_vlc_codes), sizeof(*tmp_vlc_codes), INIT_VLC_LE)) {
402 402
            av_log(vc->avccontext, AV_LOG_ERROR, " Error generating vlc tables. \n");
......
419 419

  
420 420
static int vorbis_parse_setup_hdr_tdtransforms(vorbis_context *vc)
421 421
{
422
    GetBitContext *gb=&vc->gb;
422
    GetBitContext *gb = &vc->gb;
423 423
    uint_fast8_t i;
424
    uint_fast8_t vorbis_time_count=get_bits(gb, 6)+1;
424
    uint_fast8_t vorbis_time_count = get_bits(gb, 6) + 1;
425 425

  
426
    for(i=0;i<vorbis_time_count;++i) {
427
        uint_fast16_t vorbis_tdtransform=get_bits(gb, 16);
426
    for (i = 0; i < vorbis_time_count; ++i) {
427
        uint_fast16_t vorbis_tdtransform = get_bits(gb, 16);
428 428

  
429 429
        AV_DEBUG(" Vorbis time domain transform %d: %d \n", vorbis_time_count, vorbis_tdtransform);
430 430

  
......
440 440

  
441 441
static uint_fast8_t vorbis_floor0_decode(vorbis_context *vc,
442 442
                                         vorbis_floor_data *vfu, float *vec);
443
static void create_map( vorbis_context * vc, uint_fast8_t floor_number );
443
static void create_map(vorbis_context *vc, uint_fast8_t floor_number);
444 444
static uint_fast8_t vorbis_floor1_decode(vorbis_context *vc,
445 445
                                         vorbis_floor_data *vfu, float *vec);
446 446
static int vorbis_parse_setup_hdr_floors(vorbis_context *vc)
447 447
{
448
    GetBitContext *gb=&vc->gb;
448
    GetBitContext *gb = &vc->gb;
449 449
    uint_fast16_t i,j,k;
450 450

  
451
    vc->floor_count=get_bits(gb, 6)+1;
451
    vc->floor_count = get_bits(gb, 6) + 1;
452 452

  
453
    vc->floors=av_mallocz(vc->floor_count * sizeof(vorbis_floor));
453
    vc->floors = av_mallocz(vc->floor_count * sizeof(vorbis_floor));
454 454

  
455
    for (i=0;i<vc->floor_count;++i) {
456
        vorbis_floor *floor_setup=&vc->floors[i];
455
    for (i = 0; i < vc->floor_count; ++i) {
456
        vorbis_floor *floor_setup = &vc->floors[i];
457 457

  
458
        floor_setup->floor_type=get_bits(gb, 16);
458
        floor_setup->floor_type = get_bits(gb, 16);
459 459

  
460 460
        AV_DEBUG(" %d. floor type %d \n", i, floor_setup->floor_type);
461 461

  
462
        if (floor_setup->floor_type==1) {
463
            uint_fast8_t maximum_class=0;
464
            uint_fast8_t rangebits;
465
            uint_fast16_t floor1_values=2;
462
        if (floor_setup->floor_type == 1) {
463
            uint_fast8_t  maximum_class = 0;
464
            uint_fast8_t  rangebits;
465
            uint_fast16_t floor1_values = 2;
466 466

  
467
            floor_setup->decode=vorbis_floor1_decode;
467
            floor_setup->decode = vorbis_floor1_decode;
468 468

  
469
            floor_setup->data.t1.partitions=get_bits(gb, 5);
469
            floor_setup->data.t1.partitions = get_bits(gb, 5);
470 470

  
471 471
            AV_DEBUG(" %d.floor: %d partitions \n", i, floor_setup->data.t1.partitions);
472 472

  
473
            for(j=0;j<floor_setup->data.t1.partitions;++j) {
474
                floor_setup->data.t1.partition_class[j]=get_bits(gb, 4);
475
                if (floor_setup->data.t1.partition_class[j]>maximum_class)
476
                    maximum_class=floor_setup->data.t1.partition_class[j];
473
            for (j = 0; j < floor_setup->data.t1.partitions; ++j) {
474
                floor_setup->data.t1.partition_class[j] = get_bits(gb, 4);
475
                if (floor_setup->data.t1.partition_class[j] > maximum_class)
476
                    maximum_class = floor_setup->data.t1.partition_class[j];
477 477

  
478 478
                AV_DEBUG(" %d. floor %d partition class %d \n", i, j, floor_setup->data.t1.partition_class[j]);
479 479

  
......
481 481

  
482 482
            AV_DEBUG(" maximum class %d \n", maximum_class);
483 483

  
484
            floor_setup->data.t1.maximum_class=maximum_class;
484
            floor_setup->data.t1.maximum_class = maximum_class;
485 485

  
486
            for(j=0;j<=maximum_class;++j) {
487
                floor_setup->data.t1.class_dimensions[j]=get_bits(gb, 3)+1;
488
                floor_setup->data.t1.class_subclasses[j]=get_bits(gb, 2);
486
            for (j = 0; j <= maximum_class; ++j) {
487
                floor_setup->data.t1.class_dimensions[j] = get_bits(gb, 3) + 1;
488
                floor_setup->data.t1.class_subclasses[j] = get_bits(gb, 2);
489 489

  
490 490
                AV_DEBUG(" %d floor %d class dim: %d subclasses %d \n", i, j, floor_setup->data.t1.class_dimensions[j], floor_setup->data.t1.class_subclasses[j]);
491 491

  
492 492
                if (floor_setup->data.t1.class_subclasses[j]) {
493
                    int bits=get_bits(gb, 8);
494
                    if (bits>=vc->codebook_count) {
493
                    int bits = get_bits(gb, 8);
494
                    if (bits >= vc->codebook_count) {
495 495
                        av_log(vc->avccontext, AV_LOG_ERROR, "Masterbook index %d is out of range.\n", bits);
496 496
                        return -1;
497 497
                    }
498
                    floor_setup->data.t1.class_masterbook[j]=bits;
498
                    floor_setup->data.t1.class_masterbook[j] = bits;
499 499

  
500 500
                    AV_DEBUG("   masterbook: %d \n", floor_setup->data.t1.class_masterbook[j]);
501 501
                }
502 502

  
503
                for(k=0;k<(1<<floor_setup->data.t1.class_subclasses[j]);++k) {
504
                    int16_t bits=get_bits(gb, 8)-1;
505
                    if (bits!=-1 && bits>=vc->codebook_count) {
503
                for (k = 0; k < (1 << floor_setup->data.t1.class_subclasses[j]); ++k) {
504
                    int16_t bits = get_bits(gb, 8) - 1;
505
                    if (bits != -1 && bits >= vc->codebook_count) {
506 506
                        av_log(vc->avccontext, AV_LOG_ERROR, "Subclass book index %d is out of range.\n", bits);
507 507
                        return -1;
508 508
                    }
509
                    floor_setup->data.t1.subclass_books[j][k]=bits;
509
                    floor_setup->data.t1.subclass_books[j][k] = bits;
510 510

  
511 511
                    AV_DEBUG("    book %d. : %d \n", k, floor_setup->data.t1.subclass_books[j][k]);
512 512
                }
513 513
            }
514 514

  
515
            floor_setup->data.t1.multiplier=get_bits(gb, 2)+1;
516
            floor_setup->data.t1.x_list_dim=2;
515
            floor_setup->data.t1.multiplier = get_bits(gb, 2) + 1;
516
            floor_setup->data.t1.x_list_dim = 2;
517 517

  
518
            for(j=0;j<floor_setup->data.t1.partitions;++j)
518
            for (j = 0; j < floor_setup->data.t1.partitions; ++j)
519 519
                floor_setup->data.t1.x_list_dim+=floor_setup->data.t1.class_dimensions[floor_setup->data.t1.partition_class[j]];
520 520

  
521
            floor_setup->data.t1.list=av_mallocz(floor_setup->data.t1.x_list_dim * sizeof(vorbis_floor1_entry));
521
            floor_setup->data.t1.list = av_mallocz(floor_setup->data.t1.x_list_dim * sizeof(vorbis_floor1_entry));
522 522

  
523 523

  
524
            rangebits=get_bits(gb, 4);
524
            rangebits = get_bits(gb, 4);
525 525
            floor_setup->data.t1.list[0].x = 0;
526
            floor_setup->data.t1.list[1].x = (1<<rangebits);
526
            floor_setup->data.t1.list[1].x = (1 << rangebits);
527 527

  
528
            for(j=0;j<floor_setup->data.t1.partitions;++j) {
529
                for(k=0;k<floor_setup->data.t1.class_dimensions[floor_setup->data.t1.partition_class[j]];++k,++floor1_values) {
530
                    floor_setup->data.t1.list[floor1_values].x=get_bits(gb, rangebits);
528
            for (j = 0; j < floor_setup->data.t1.partitions; ++j) {
529
                for (k = 0; k < floor_setup->data.t1.class_dimensions[floor_setup->data.t1.partition_class[j]]; ++k, ++floor1_values) {
530
                    floor_setup->data.t1.list[floor1_values].x = get_bits(gb, rangebits);
531 531

  
532 532
                    AV_DEBUG(" %d. floor1 Y coord. %d \n", floor1_values, floor_setup->data.t1.list[floor1_values].x);
533 533
                }
......
535 535

  
536 536
// Precalculate order of x coordinates - needed for decode
537 537
            ff_vorbis_ready_floor1_list(floor_setup->data.t1.list, floor_setup->data.t1.x_list_dim);
538
        } else if(floor_setup->floor_type==0) {
539
            uint_fast8_t max_codebook_dim=0;
538
        } else if (floor_setup->floor_type == 0) {
539
            uint_fast8_t max_codebook_dim = 0;
540 540

  
541
            floor_setup->decode=vorbis_floor0_decode;
541
            floor_setup->decode = vorbis_floor0_decode;
542 542

  
543
            floor_setup->data.t0.order=get_bits(gb, 8);
544
            floor_setup->data.t0.rate=get_bits(gb, 16);
545
            floor_setup->data.t0.bark_map_size=get_bits(gb, 16);
546
            floor_setup->data.t0.amplitude_bits=get_bits(gb, 6);
543
            floor_setup->data.t0.order          = get_bits(gb,  8);
544
            floor_setup->data.t0.rate           = get_bits(gb, 16);
545
            floor_setup->data.t0.bark_map_size  = get_bits(gb, 16);
546
            floor_setup->data.t0.amplitude_bits = get_bits(gb,  6);
547 547
            /* zero would result in a div by zero later *
548 548
             * 2^0 - 1 == 0                             */
549 549
            if (floor_setup->data.t0.amplitude_bits == 0) {
......
551 551
                     "Floor 0 amplitude bits is 0.\n");
552 552
              return -1;
553 553
            }
554
            floor_setup->data.t0.amplitude_offset=get_bits(gb, 8);
555
            floor_setup->data.t0.num_books=get_bits(gb, 4)+1;
554
            floor_setup->data.t0.amplitude_offset = get_bits(gb, 8);
555
            floor_setup->data.t0.num_books        = get_bits(gb, 4) + 1;
556 556

  
557 557
            /* allocate mem for booklist */
558
            floor_setup->data.t0.book_list=
558
            floor_setup->data.t0.book_list =
559 559
                av_malloc(floor_setup->data.t0.num_books);
560
            if(!floor_setup->data.t0.book_list)
560
            if (!floor_setup->data.t0.book_list)
561 561
                return -1;
562 562
            /* read book indexes */
563 563
            {
564 564
                int idx;
565 565
                uint_fast8_t book_idx;
566
                for (idx=0;idx<floor_setup->data.t0.num_books;++idx) {
567
                    book_idx=get_bits(gb, 8);
568
                    if (book_idx>=vc->codebook_count)
566
                for (idx = 0; idx < floor_setup->data.t0.num_books; ++idx) {
567
                    book_idx = get_bits(gb, 8);
568
                    if (book_idx >= vc->codebook_count)
569 569
                        return -1;
570
                    floor_setup->data.t0.book_list[idx]=book_idx;
570
                    floor_setup->data.t0.book_list[idx] = book_idx;
571 571
                    if (vc->codebooks[book_idx].dimensions > max_codebook_dim)
572
                        max_codebook_dim=vc->codebooks[book_idx].dimensions;
572
                        max_codebook_dim = vc->codebooks[book_idx].dimensions;
573 573
                }
574 574
            }
575 575

  
576
            create_map( vc, i );
576
            create_map(vc, i);
577 577

  
578 578
            /* allocate mem for lsp coefficients */
579 579
            {
580 580
                /* codebook dim is for padding if codebook dim doesn't *
581 581
                 * divide order+1 then we need to read more data       */
582
                floor_setup->data.t0.lsp=
582
                floor_setup->data.t0.lsp =
583 583
                    av_malloc((floor_setup->data.t0.order+1 + max_codebook_dim)
584 584
                              * sizeof(float));
585
                if(!floor_setup->data.t0.lsp)
585
                if (!floor_setup->data.t0.lsp)
586 586
                    return -1;
587 587
            }
588 588

  
......
601 601
              floor_setup->data.t0.book_list);
602 602
            {
603 603
              int idx;
604
              for (idx=0;idx<floor_setup->data.t0.num_books;++idx) {
605
                AV_DEBUG( "  Book %d: %u\n",
606
                  idx+1,
607
                  floor_setup->data.t0.book_list[idx] );
604
              for (idx = 0; idx < floor_setup->data.t0.num_books; ++idx) {
605
                  AV_DEBUG("  Book %d: %u\n",
606
                           idx+1,
607
                           floor_setup->data.t0.book_list[idx]);
608 608
              }
609 609
            }
610 610
#endif
......
620 620

  
621 621
static int vorbis_parse_setup_hdr_residues(vorbis_context *vc)
622 622
{
623
    GetBitContext *gb=&vc->gb;
623
    GetBitContext *gb = &vc->gb;
624 624
    uint_fast8_t i, j, k;
625 625

  
626
    vc->residue_count=get_bits(gb, 6)+1;
627
    vc->residues=av_mallocz(vc->residue_count * sizeof(vorbis_residue));
626
    vc->residue_count = get_bits(gb, 6)+1;
627
    vc->residues      = av_mallocz(vc->residue_count * sizeof(vorbis_residue));
628 628

  
629 629
    AV_DEBUG(" There are %d residues. \n", vc->residue_count);
630 630

  
631
    for(i=0;i<vc->residue_count;++i) {
632
        vorbis_residue *res_setup=&vc->residues[i];
631
    for (i = 0; i < vc->residue_count; ++i) {
632
        vorbis_residue *res_setup = &vc->residues[i];
633 633
        uint_fast8_t cascade[64];
634 634
        uint_fast8_t high_bits;
635 635
        uint_fast8_t low_bits;
636 636

  
637
        res_setup->type=get_bits(gb, 16);
637
        res_setup->type = get_bits(gb, 16);
638 638

  
639 639
        AV_DEBUG(" %d. residue type %d \n", i, res_setup->type);
640 640

  
641
        res_setup->begin=get_bits(gb, 24);
642
        res_setup->end=get_bits(gb, 24);
643
        res_setup->partition_size=get_bits(gb, 24)+1;
641
        res_setup->begin          = get_bits(gb, 24);
642
        res_setup->end            = get_bits(gb, 24);
643
        res_setup->partition_size = get_bits(gb, 24) + 1;
644 644
        /* Validations to prevent a buffer overflow later. */
645
        if (res_setup->begin>res_setup->end
646
        || res_setup->end>vc->blocksize[1]/(res_setup->type==2?1:2)
647
        || (res_setup->end-res_setup->begin)/res_setup->partition_size>V_MAX_PARTITIONS) {
648
            av_log(vc->avccontext, AV_LOG_ERROR, "partition out of bounds: type, begin, end, size, blocksize: %"PRIdFAST16", %"PRIdFAST32", %"PRIdFAST32", %"PRIdFAST32", %"PRIdFAST32"\n", res_setup->type, res_setup->begin, res_setup->end, res_setup->partition_size, vc->blocksize[1]/2);
645
        if (res_setup->begin>res_setup->end ||
646
            res_setup->end>vc->blocksize[1] / (res_setup->type == 2 ? 1 : 2) ||
647
            (res_setup->end-res_setup->begin) / res_setup->partition_size > V_MAX_PARTITIONS) {
648
            av_log(vc->avccontext, AV_LOG_ERROR, "partition out of bounds: type, begin, end, size, blocksize: %"PRIdFAST16", %"PRIdFAST32", %"PRIdFAST32", %"PRIdFAST32", %"PRIdFAST32"\n", res_setup->type, res_setup->begin, res_setup->end, res_setup->partition_size, vc->blocksize[1] / 2);
649 649
            return -1;
650 650
        }
651 651

  
652
        res_setup->classifications=get_bits(gb, 6)+1;
653
        res_setup->classbook=get_bits(gb, 8);
654
        if (res_setup->classbook>=vc->codebook_count) {
652
        res_setup->classifications = get_bits(gb, 6) + 1;
653
        res_setup->classbook = get_bits(gb, 8);
654
        if (res_setup->classbook >= vc->codebook_count) {
655 655
            av_log(vc->avccontext, AV_LOG_ERROR, "classbook value %d out of range. \n", res_setup->classbook);
656 656
            return -1;
657 657
        }
......
659 659
        AV_DEBUG("    begin %d end %d part.size %d classif.s %d classbook %d \n", res_setup->begin, res_setup->end, res_setup->partition_size,
660 660
          res_setup->classifications, res_setup->classbook);
661 661

  
662
        for(j=0;j<res_setup->classifications;++j) {
663
            high_bits=0;
664
            low_bits=get_bits(gb, 3);
662
        for (j = 0; j < res_setup->classifications; ++j) {
663
            high_bits = 0;
664
            low_bits  = get_bits(gb, 3);
665 665
            if (get_bits1(gb))
666
                high_bits=get_bits(gb, 5);
667
            cascade[j]=(high_bits<<3)+low_bits;
666
                high_bits = get_bits(gb, 5);
667
            cascade[j] = (high_bits << 3) + low_bits;
668 668

  
669 669
            AV_DEBUG("     %d class casscade depth: %d \n", j, ilog(cascade[j]));
670 670
        }
671 671

  
672
        res_setup->maxpass=0;
673
        for(j=0;j<res_setup->classifications;++j) {
674
            for(k=0;k<8;++k) {
675
                if (cascade[j]&(1<<k)) {
676
                    int bits=get_bits(gb, 8);
677
                    if (bits>=vc->codebook_count) {
672
        res_setup->maxpass = 0;
673
        for (j = 0; j < res_setup->classifications; ++j) {
674
            for (k = 0; k < 8; ++k) {
675
                if (cascade[j]&(1 << k)) {
676
                    int bits = get_bits(gb, 8);
677
                    if (bits >= vc->codebook_count) {
678 678
                        av_log(vc->avccontext, AV_LOG_ERROR, "book value %d out of range. \n", bits);
679 679
                        return -1;
680 680
                    }
681
                    res_setup->books[j][k]=bits;
681
                    res_setup->books[j][k] = bits;
682 682

  
683 683
                    AV_DEBUG("     %d class casscade depth %d book: %d \n", j, k, res_setup->books[j][k]);
684 684

  
685 685
                    if (k>res_setup->maxpass)
686
                        res_setup->maxpass=k;
686
                        res_setup->maxpass = k;
687 687
                } else {
688
                    res_setup->books[j][k]=-1;
688
                    res_setup->books[j][k] = -1;
689 689
                }
690 690
            }
691 691
        }
......
697 697

  
698 698
static int vorbis_parse_setup_hdr_mappings(vorbis_context *vc)
699 699
{
700
    GetBitContext *gb=&vc->gb;
700
    GetBitContext *gb = &vc->gb;
701 701
    uint_fast8_t i, j;
702 702

  
703
    vc->mapping_count=get_bits(gb, 6)+1;
704
    vc->mappings=av_mallocz(vc->mapping_count * sizeof(vorbis_mapping));
703
    vc->mapping_count = get_bits(gb, 6)+1;
704
    vc->mappings      = av_mallocz(vc->mapping_count * sizeof(vorbis_mapping));
705 705

  
706 706
    AV_DEBUG(" There are %d mappings. \n", vc->mapping_count);
707 707

  
708
    for(i=0;i<vc->mapping_count;++i) {
709
        vorbis_mapping *mapping_setup=&vc->mappings[i];
708
    for (i = 0; i < vc->mapping_count; ++i) {
709
        vorbis_mapping *mapping_setup = &vc->mappings[i];
710 710

  
711 711
        if (get_bits(gb, 16)) {
712 712
            av_log(vc->avccontext, AV_LOG_ERROR, "Other mappings than type 0 are not compliant with the Vorbis I specification. \n");
713 713
            return -1;
714 714
        }
715 715
        if (get_bits1(gb)) {
716
            mapping_setup->submaps=get_bits(gb, 4)+1;
716
            mapping_setup->submaps = get_bits(gb, 4) + 1;
717 717
        } else {
718
            mapping_setup->submaps=1;
718
            mapping_setup->submaps = 1;
719 719
        }
720 720

  
721 721
        if (get_bits1(gb)) {
722
            mapping_setup->coupling_steps=get_bits(gb, 8)+1;
723
            mapping_setup->magnitude=av_mallocz(mapping_setup->coupling_steps * sizeof(uint_fast8_t));
724
            mapping_setup->angle    =av_mallocz(mapping_setup->coupling_steps * sizeof(uint_fast8_t));
725
            for(j=0;j<mapping_setup->coupling_steps;++j) {
726
                mapping_setup->magnitude[j]=get_bits(gb, ilog(vc->audio_channels-1));
727
                mapping_setup->angle[j]=get_bits(gb, ilog(vc->audio_channels-1));
728
                if (mapping_setup->magnitude[j]>=vc->audio_channels) {
722
            mapping_setup->coupling_steps = get_bits(gb, 8) + 1;
723
            mapping_setup->magnitude      = av_mallocz(mapping_setup->coupling_steps * sizeof(uint_fast8_t));
724
            mapping_setup->angle          = av_mallocz(mapping_setup->coupling_steps * sizeof(uint_fast8_t));
725
            for (j = 0; j < mapping_setup->coupling_steps; ++j) {
726
                mapping_setup->magnitude[j] = get_bits(gb, ilog(vc->audio_channels - 1));
727
                mapping_setup->angle[j] = get_bits(gb, ilog(vc->audio_channels - 1));
728
                if (mapping_setup->magnitude[j] >= vc->audio_channels) {
729 729
                    av_log(vc->avccontext, AV_LOG_ERROR, "magnitude channel %d out of range. \n", mapping_setup->magnitude[j]);
730 730
                    return -1;
731 731
                }
732
                if (mapping_setup->angle[j]>=vc->audio_channels) {
732
                if (mapping_setup->angle[j] >= vc->audio_channels) {
733 733
                    av_log(vc->avccontext, AV_LOG_ERROR, "angle channel %d out of range. \n", mapping_setup->angle[j]);
734 734
                    return -1;
735 735
                }
736 736
            }
737 737
        } else {
738
            mapping_setup->coupling_steps=0;
738
            mapping_setup->coupling_steps = 0;
739 739
        }
740 740

  
741 741
        AV_DEBUG("   %d mapping coupling steps: %d \n", i, mapping_setup->coupling_steps);
742 742

  
743
        if(get_bits(gb, 2)) {
743
        if (get_bits(gb, 2)) {
744 744
            av_log(vc->avccontext, AV_LOG_ERROR, "%d. mapping setup data invalid. \n", i);
745 745
            return -1; // following spec.
746 746
        }
747 747

  
748 748
        if (mapping_setup->submaps>1) {
749
            mapping_setup->mux=av_mallocz(vc->audio_channels * sizeof(uint_fast8_t));
750
            for(j=0;j<vc->audio_channels;++j)
751
                mapping_setup->mux[j]=get_bits(gb, 4);
749
            mapping_setup->mux = av_mallocz(vc->audio_channels * sizeof(uint_fast8_t));
750
            for (j = 0; j < vc->audio_channels; ++j)
751
                mapping_setup->mux[j] = get_bits(gb, 4);
752 752
        }
753 753

  
754
        for(j=0;j<mapping_setup->submaps;++j) {
754
        for (j = 0; j < mapping_setup->submaps; ++j) {
755 755
            int bits;
756 756
            skip_bits(gb, 8); // FIXME check?
757
            bits=get_bits(gb, 8);
758
            if (bits>=vc->floor_count) {
757
            bits = get_bits(gb, 8);
758
            if (bits >= vc->floor_count) {
759 759
                av_log(vc->avccontext, AV_LOG_ERROR, "submap floor value %d out of range. \n", bits);
760 760
                return -1;
761 761
            }
762
            mapping_setup->submap_floor[j]=bits;
763
            bits=get_bits(gb, 8);
764
            if (bits>=vc->residue_count) {
762
            mapping_setup->submap_floor[j] = bits;
763
            bits = get_bits(gb, 8);
764
            if (bits >= vc->residue_count) {
765 765
                av_log(vc->avccontext, AV_LOG_ERROR, "submap residue value %d out of range. \n", bits);
766 766
                return -1;
767 767
            }
768
            mapping_setup->submap_residue[j]=bits;
768
            mapping_setup->submap_residue[j] = bits;
769 769

  
770 770
            AV_DEBUG("   %d mapping %d submap : floor %d, residue %d \n", i, j, mapping_setup->submap_floor[j], mapping_setup->submap_residue[j]);
771 771
        }
......
775 775

  
776 776
// Process modes part
777 777

  
778
static void create_map( vorbis_context * vc, uint_fast8_t floor_number )
778
static void create_map(vorbis_context *vc, uint_fast8_t floor_number)
779 779
{
780
    vorbis_floor * floors=vc->floors;
781
    vorbis_floor0 * vf;
780
    vorbis_floor *floors = vc->floors;
781
    vorbis_floor0 *vf;
782 782
    int idx;
783 783
    int_fast8_t blockflag;
784
    int_fast32_t * map;
784
    int_fast32_t *map;
785 785
    int_fast32_t n; //TODO: could theoretically be smaller?
786 786

  
787
    for (blockflag=0;blockflag<2;++blockflag) {
788
    n=vc->blocksize[blockflag]/2;
789
    floors[floor_number].data.t0.map[blockflag]=
790
        av_malloc((n+1) * sizeof(int_fast32_t)); // n+sentinel
787
    for (blockflag = 0; blockflag < 2; ++blockflag) {
788
        n = vc->blocksize[blockflag] / 2;
789
        floors[floor_number].data.t0.map[blockflag] =
790
            av_malloc((n+1) * sizeof(int_fast32_t)); // n + sentinel
791 791

  
792
    map=floors[floor_number].data.t0.map[blockflag];
793
    vf=&floors[floor_number].data.t0;
792
        map =  floors[floor_number].data.t0.map[blockflag];
793
        vf  = &floors[floor_number].data.t0;
794 794

  
795
    for (idx=0; idx<n;++idx) {
796
        map[idx]=floor( BARK((vf->rate*idx)/(2.0f*n)) *
797
                              ((vf->bark_map_size)/
798
                               BARK(vf->rate/2.0f )) );
799
        if (vf->bark_map_size-1 < map[idx])
800
            map[idx]=vf->bark_map_size-1;
801
    }
802
    map[n]=-1;
803
    vf->map_size[blockflag]=n;
795
        for (idx = 0; idx < n; ++idx) {
796
            map[idx] = floor(BARK((vf->rate * idx) / (2.0f * n)) *
797
                             ((vf->bark_map_size) /
798
                              BARK(vf->rate / 2.0f)));
799
            if (vf->bark_map_size-1 < map[idx])
800
                map[idx] = vf->bark_map_size - 1;
801
        }
802
        map[n] = -1;
803
        vf->map_size[blockflag] = n;
804 804
    }
805 805

  
806 806
#   ifdef V_DEBUG
807
    for(idx=0;idx<=n;++idx) {
807
    for (idx = 0; idx <= n; ++idx) {
808 808
        AV_DEBUG("floor0 map: map at pos %d is %d\n",
809 809
                 idx, map[idx]);
810 810
    }
......
813 813

  
814 814
static int vorbis_parse_setup_hdr_modes(vorbis_context *vc)
815 815
{
816
    GetBitContext *gb=&vc->gb;
816
    GetBitContext *gb = &vc->gb;
817 817
    uint_fast8_t i;
818 818

  
819
    vc->mode_count=get_bits(gb, 6)+1;
820
    vc->modes=av_mallocz(vc->mode_count * sizeof(vorbis_mode));
819
    vc->mode_count = get_bits(gb, 6) + 1;
820
    vc->modes      = av_mallocz(vc->mode_count * sizeof(vorbis_mode));
821 821

  
822 822
    AV_DEBUG(" There are %d modes.\n", vc->mode_count);
823 823

  
824
    for(i=0;i<vc->mode_count;++i) {
825
        vorbis_mode *mode_setup=&vc->modes[i];
824
    for (i = 0; i < vc->mode_count; ++i) {
825
        vorbis_mode *mode_setup = &vc->modes[i];
826 826

  
827
        mode_setup->blockflag=get_bits1(gb);
828
        mode_setup->windowtype=get_bits(gb, 16); //FIXME check
829
        mode_setup->transformtype=get_bits(gb, 16); //FIXME check
830
        mode_setup->mapping=get_bits(gb, 8);
831
        if (mode_setup->mapping>=vc->mapping_count) {
827
        mode_setup->blockflag     = get_bits1(gb);
828
        mode_setup->windowtype    = get_bits(gb, 16); //FIXME check
829
        mode_setup->transformtype = get_bits(gb, 16); //FIXME check
830
        mode_setup->mapping       = get_bits(gb,  8);
831
        if (mode_setup->mapping >= vc->mapping_count) {
832 832
            av_log(vc->avccontext, AV_LOG_ERROR, "mode mapping value %d out of range. \n", mode_setup->mapping);
833 833
            return -1;
834 834
        }
......
842 842

  
843 843
static int vorbis_parse_setup_hdr(vorbis_context *vc)
844 844
{
845
    GetBitContext *gb=&vc->gb;
845
    GetBitContext *gb = &vc->gb;
846 846

  
847
    if ((get_bits(gb, 8)!='v') || (get_bits(gb, 8)!='o') ||
848
    (get_bits(gb, 8)!='r') || (get_bits(gb, 8)!='b') ||
849
    (get_bits(gb, 8)!='i') || (get_bits(gb, 8)!='s')) {
847
    if ((get_bits(gb, 8) != 'v') || (get_bits(gb, 8) != 'o') ||
848
        (get_bits(gb, 8) != 'r') || (get_bits(gb, 8) != 'b') ||
849
        (get_bits(gb, 8) != 'i') || (get_bits(gb, 8) != 's')) {
850 850
        av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (no vorbis signature). \n");
851 851
        return -1;
852 852
    }
......
887 887

  
888 888
static int vorbis_parse_id_hdr(vorbis_context *vc)
889 889
{
890
    GetBitContext *gb=&vc->gb;
890
    GetBitContext *gb = &vc->gb;
891 891
    uint_fast8_t bl0, bl1;
892 892

  
893
    if ((get_bits(gb, 8)!='v') || (get_bits(gb, 8)!='o') ||
894
    (get_bits(gb, 8)!='r') || (get_bits(gb, 8)!='b') ||
895
    (get_bits(gb, 8)!='i') || (get_bits(gb, 8)!='s')) {
893
    if ((get_bits(gb, 8) != 'v') || (get_bits(gb, 8) != 'o') ||
894
        (get_bits(gb, 8) != 'r') || (get_bits(gb, 8) != 'b') ||
895
        (get_bits(gb, 8) != 'i') || (get_bits(gb, 8) != 's')) {
896 896
        av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis id header packet corrupt (no vorbis signature). \n");
897 897
        return -1;
898 898
    }
899 899

  
900
    vc->version=get_bits_long(gb, 32);    //FIXME check 0
901
    vc->audio_channels=get_bits(gb, 8);
902
    if(vc->audio_channels <= 0){
900
    vc->version        = get_bits_long(gb, 32);    //FIXME check 0
901
    vc->audio_channels = get_bits(gb, 8);
902
    if (vc->audio_channels <= 0) {
903 903
        av_log(vc->avccontext, AV_LOG_ERROR, "Invalid number of channels\n");
904 904
        return -1;
905 905
    }
906
    vc->audio_samplerate=get_bits_long(gb, 32);
907
    if(vc->audio_samplerate <= 0){
906
    vc->audio_samplerate = get_bits_long(gb, 32);
907
    if (vc->audio_samplerate <= 0) {
908 908
        av_log(vc->avccontext, AV_LOG_ERROR, "Invalid samplerate\n");
909 909
        return -1;
910 910
    }
911
    vc->bitrate_maximum=get_bits_long(gb, 32);
912
    vc->bitrate_nominal=get_bits_long(gb, 32);
913
    vc->bitrate_minimum=get_bits_long(gb, 32);
914
    bl0=get_bits(gb, 4);
915
    bl1=get_bits(gb, 4);
916
    vc->blocksize[0]=(1<<bl0);
917
    vc->blocksize[1]=(1<<bl1);
918
    if (bl0>13 || bl0<6 || bl1>13 || bl1<6 || bl1<bl0) {
911
    vc->bitrate_maximum = get_bits_long(gb, 32);
912
    vc->bitrate_nominal = get_bits_long(gb, 32);
913
    vc->bitrate_minimum = get_bits_long(gb, 32);
914
    bl0 = get_bits(gb, 4);
915
    bl1 = get_bits(gb, 4);
916
    vc->blocksize[0] = (1 << bl0);
917
    vc->blocksize[1] = (1 << bl1);
918
    if (bl0 > 13 || bl0 < 6 || bl1 > 13 || bl1 < 6 || bl1 < bl0) {
919 919
        av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis id header packet corrupt (illegal blocksize). \n");
920 920
        return -3;
921 921
    }
922 922
    // output format int16
923
    if (vc->blocksize[1]/2 * vc->audio_channels * 2 >
924
                                             AVCODEC_MAX_AUDIO_FRAME_SIZE) {
923
    if (vc->blocksize[1] / 2 * vc->audio_channels * 2 > AVCODEC_MAX_AUDIO_FRAME_SIZE) {
925 924
        av_log(vc->avccontext, AV_LOG_ERROR, "Vorbis channel count makes "
926 925
               "output packets too large.\n");
927 926
        return -4;
928 927
    }
929
    vc->win[0]=ff_vorbis_vwin[bl0-6];
930
    vc->win[1]=ff_vorbis_vwin[bl1-6];
928
    vc->win[0] = ff_vorbis_vwin[bl0 - 6];
929
    vc->win[1] = ff_vorbis_vwin[bl1 - 6];
931 930

  
932 931
    if ((get_bits1(gb)) == 0) {
933 932
        av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis id header packet corrupt (framing flag not set). \n");
934 933
        return -2;
935 934
    }
936 935

  
937
    vc->channel_residues= av_malloc((vc->blocksize[1]/2)*vc->audio_channels * sizeof(float));
938
    vc->channel_floors  = av_malloc((vc->blocksize[1]/2)*vc->audio_channels * sizeof(float));
939
    vc->saved           = av_mallocz((vc->blocksize[1]/4)*vc->audio_channels * sizeof(float));
940
    vc->previous_window=0;
936
    vc->channel_residues =  av_malloc((vc->blocksize[1]  / 2) * vc->audio_channels * sizeof(float));
937
    vc->channel_floors   =  av_malloc((vc->blocksize[1]  / 2) * vc->audio_channels * sizeof(float));
938
    vc->saved            =  av_mallocz((vc->blocksize[1] / 4) * vc->audio_channels * sizeof(float));
939
    vc->previous_window  = 0;
941 940

  
942
    ff_mdct_init(&vc->mdct[0], bl0, 1, vc->exp_bias ? -(1<<15) : -1.0);
943
    ff_mdct_init(&vc->mdct[1], bl1, 1, vc->exp_bias ? -(1<<15) : -1.0);
941
    ff_mdct_init(&vc->mdct[0], bl0, 1, vc->exp_bias ? -(1 << 15) : -1.0);
942
    ff_mdct_init(&vc->mdct[1], bl1, 1, vc->exp_bias ? -(1 << 15) : -1.0);
944 943

  
945 944
    AV_DEBUG(" vorbis version %d \n audio_channels %d \n audio_samplerate %d \n bitrate_max %d \n bitrate_nom %d \n bitrate_min %d \n blk_0 %d blk_1 %d \n ",
946 945
            vc->version, vc->audio_channels, vc->audio_samplerate, vc->bitrate_maximum, vc->bitrate_nominal, vc->bitrate_minimum, vc->blocksize[0], vc->blocksize[1]);
947 946

  
948 947
/*
949
    BLK=vc->blocksize[0];
950
    for(i=0;i<BLK/2;++i) {
951
        vc->win[0][i]=sin(0.5*3.14159265358*(sin(((float)i+0.5)/(float)BLK*3.14159265358))*(sin(((float)i+0.5)/(float)BLK*3.14159265358)));
948
    BLK = vc->blocksize[0];
949
    for (i = 0; i < BLK / 2; ++i) {
950
        vc->win[0][i] = sin(0.5*3.14159265358*(sin(((float)i + 0.5) / (float)BLK*3.14159265358))*(sin(((float)i + 0.5) / (float)BLK*3.14159265358)));
952 951
    }
953 952
*/
954 953

  
......
960 959
static av_cold int vorbis_decode_init(AVCodecContext *avccontext)
961 960
{
962 961
    vorbis_context *vc = avccontext->priv_data ;
963
    uint8_t *headers = avccontext->extradata;
964
    int headers_len=avccontext->extradata_size;
962
    uint8_t *headers   = avccontext->extradata;
963
    int headers_len    = avccontext->extradata_size;
965 964
    uint8_t *header_start[3];
966 965
    int header_len[3];
967 966
    GetBitContext *gb = &(vc->gb);
......
970 969
    vc->avccontext = avccontext;
971 970
    dsputil_init(&vc->dsp, avccontext);
972 971

  
973
    if(vc->dsp.float_to_int16_interleave == ff_float_to_int16_interleave_c) {
972
    if (vc->dsp.float_to_int16_interleave == ff_float_to_int16_interleave_c) {
974 973
        vc->add_bias = 385;
975 974
        vc->exp_bias = 0;
976 975
    } else {
977 976
        vc->add_bias = 0;
978
        vc->exp_bias = 15<<23;
977
        vc->exp_bias = 15 << 23;
979 978
    }
980 979

  
981 980
    if (!headers_len) {
......
989 988
    }
990 989

  
991 990
    init_get_bits(gb, header_start[0], header_len[0]*8);
992
    hdr_type=get_bits(gb, 8);
993
    if (hdr_type!=1) {
991
    hdr_type = get_bits(gb, 8);
992
    if (hdr_type != 1) {
994 993
        av_log(avccontext, AV_LOG_ERROR, "First header is not the id header.\n");
995 994
        return -1;
996 995
    }
......
1001 1000
    }
1002 1001

  
1003 1002
    init_get_bits(gb, header_start[2], header_len[2]*8);
1004
    hdr_type=get_bits(gb, 8);
1005
    if (hdr_type!=5) {
1003
    hdr_type = get_bits(gb, 8);
1004
    if (hdr_type != 5) {
1006 1005
        av_log(avccontext, AV_LOG_ERROR, "Third header is not the setup header.\n");
1007 1006
        vorbis_free(vc);
1008 1007
        return -1;
......
1013 1012
        return -1;
1014 1013
    }
1015 1014

  
1016
    avccontext->channels = vc->audio_channels;
1015
    avccontext->channels    = vc->audio_channels;
1017 1016
    avccontext->sample_rate = vc->audio_samplerate;
1018
    avccontext->frame_size  = FFMIN(vc->blocksize[0], vc->blocksize[1])>>2;
1019
    avccontext->sample_fmt = SAMPLE_FMT_S16;
1017
    avccontext->frame_size  = FFMIN(vc->blocksize[0], vc->blocksize[1]) >> 2;
1018
    avccontext->sample_fmt  = SAMPLE_FMT_S16;
1020 1019

  
1021 1020
    return 0 ;
1022 1021
}
......
1028 1027
static uint_fast8_t vorbis_floor0_decode(vorbis_context *vc,
1029 1028
                                         vorbis_floor_data *vfu, float *vec)
1030 1029
{
1031
    vorbis_floor0 * vf=&vfu->t0;
1032
    float * lsp=vf->lsp;
1030
    vorbis_floor0 *vf = &vfu->t0;
1031
    float *lsp = vf->lsp;
1033 1032
    uint_fast32_t amplitude;
1034 1033
    uint_fast32_t book_idx;
1035
    uint_fast8_t blockflag=vc->modes[vc->mode_number].blockflag;
1034
    uint_fast8_t blockflag = vc->modes[vc->mode_number].blockflag;
1036 1035

  
1037
    amplitude=get_bits(&vc->gb, vf->amplitude_bits);
1038
    if (amplitude>0) {
1036
    amplitude = get_bits(&vc->gb, vf->amplitude_bits);
1037
    if (amplitude > 0) {
1039 1038
        float last = 0;
1040 1039
        uint_fast16_t lsp_len = 0;
1041 1040
        uint_fast16_t idx;
1042 1041
        vorbis_codebook codebook;
1043 1042

  
1044
        book_idx=get_bits(&vc->gb, ilog(vf->num_books));
1045
        if ( book_idx >= vf->num_books ) {
1046
            av_log( vc->avccontext, AV_LOG_ERROR,
1047
                    "floor0 dec: booknumber too high!\n" );
1048
            book_idx= 0;
1043
        book_idx = get_bits(&vc->gb, ilog(vf->num_books));
1044
        if (book_idx >= vf->num_books) {
1045
            av_log(vc->avccontext, AV_LOG_ERROR,
1046
                    "floor0 dec: booknumber too high!\n");
1047
            book_idx =  0;
1049 1048
            //FIXME: look above
1050 1049
        }
1051
        AV_DEBUG( "floor0 dec: booknumber: %u\n", book_idx );
1052
        codebook=vc->codebooks[vf->book_list[book_idx]];
1050
        AV_DEBUG("floor0 dec: booknumber: %u\n", book_idx);
1051
        codebook = vc->codebooks[vf->book_list[book_idx]];
1053 1052

  
1054 1053
        while (lsp_len<vf->order) {
1055 1054
            int vec_off;
1056 1055

  
1057
            AV_DEBUG( "floor0 dec: book dimension: %d\n", codebook.dimensions );
1058
            AV_DEBUG( "floor0 dec: maximum depth: %d\n", codebook.maxdepth );
1056
            AV_DEBUG("floor0 dec: book dimension: %d\n", codebook.dimensions);
1057
            AV_DEBUG("floor0 dec: maximum depth: %d\n", codebook.maxdepth);
1059 1058
            /* read temp vector */
1060
            vec_off=get_vlc2(&vc->gb,
1061
                             codebook.vlc.table,
1062
                             codebook.nb_bits,
1063
                             codebook.maxdepth ) *
1064
                             codebook.dimensions;
1065
            AV_DEBUG( "floor0 dec: vector offset: %d\n", vec_off );
1059
            vec_off = get_vlc2(&vc->gb, codebook.vlc.table,
1060
                               codebook.nb_bits, codebook.maxdepth)
1061
                      * codebook.dimensions;
1062
            AV_DEBUG("floor0 dec: vector offset: %d\n", vec_off);
1066 1063
            /* copy each vector component and add last to it */
1067
            for (idx=0; idx<codebook.dimensions; ++idx)
1068
                lsp[lsp_len+idx]=codebook.codevectors[vec_off+idx]+last;
1069
            last=lsp[lsp_len+idx-1]; /* set last to last vector component */
1064
            for (idx = 0; idx < codebook.dimensions; ++idx)
1065
                lsp[lsp_len+idx] = codebook.codevectors[vec_off+idx] + last;
1066
            last = lsp[lsp_len+idx-1]; /* set last to last vector component */
1070 1067

  
1071 1068
            lsp_len += codebook.dimensions;
1072 1069
        }
......
1074 1071
        /* DEBUG: output lsp coeffs */
1075 1072
        {
1076 1073
            int idx;
1077
            for ( idx = 0; idx < lsp_len; ++idx )
1078
                AV_DEBUG("floor0 dec: coeff at %d is %f\n", idx, lsp[idx] );
1074
            for (idx = 0; idx < lsp_len; ++idx)
1075
                AV_DEBUG("floor0 dec: coeff at %d is %f\n", idx, lsp[idx]);
1079 1076
        }
1080 1077
#endif
1081 1078

  
1082 1079
        /* synthesize floor output vector */
1083 1080
        {
1084 1081
            int i;
1085
            int order=vf->order;
1086
            float wstep=M_PI/vf->bark_map_size;
1082
            int order = vf->order;
1083
            float wstep = M_PI / vf->bark_map_size;
1087 1084

  
1088
            for(i=0;i<order;i++)
1089
                lsp[i]=2.0f*cos(lsp[i]);
1085
            for (i = 0; i < order; i++)
1086
                lsp[i] = 2.0f * cos(lsp[i]);
1090 1087

  
1091
            AV_DEBUG("floor0 synth: map_size=%d; m=%d; wstep=%f\n",
1088
            AV_DEBUG("floor0 synth: map_size = %d; m = %d; wstep = %f\n",
1092 1089
                     vf->map_size, order, wstep);
1093 1090

  
1094
            i=0;
1095
            while(i<vf->map_size[blockflag]) {
1096
                int j, iter_cond=vf->map[blockflag][i];
1097
                float p=0.5f;
1098
                float q=0.5f;
1099
                float two_cos_w=2.0f*cos(wstep*iter_cond); // needed all times
1091
            i = 0;
1092
            while (i < vf->map_size[blockflag]) {
1093
                int j, iter_cond = vf->map[blockflag][i];
1094
                float p = 0.5f;
1095
                float q = 0.5f;
1096
                float two_cos_w = 2.0f * cos(wstep * iter_cond); // needed all times
1100 1097

  
1101 1098
                /* similar part for the q and p products */
1102
                for(j=0;j+1<order;j+=2) {
1103
                    q *= lsp[j]  -two_cos_w;
1104
                    p *= lsp[j+1]-two_cos_w;
1099
                for (j = 0; j + 1 < order; j += 2) {
1100
                    q *= lsp[j]     - two_cos_w;
1101
                    p *= lsp[j + 1] - two_cos_w;
1105 1102
                }
1106
                if(j==order) { // even order
1107
                    p *= p*(2.0f-two_cos_w);
1108
                    q *= q*(2.0f+two_cos_w);
1103
                if (j == order) { // even order
1104
                    p *= p * (2.0f - two_cos_w);
1105
                    q *= q * (2.0f + two_cos_w);
1109 1106
                } else { // odd order
1110 1107
                    q *= two_cos_w-lsp[j]; // one more time for q
1111 1108

  
1112 1109
                    /* final step and square */
1113
                    p *= p*(4.f-two_cos_w*two_cos_w);
1110
                    p *= p * (4.f - two_cos_w * two_cos_w);
1114 1111
                    q *= q;
1115 1112
                }
1116 1113

  
1117 1114
                /* calculate linear floor value */
1118 1115
                {
1119
                    q=exp( (
1120
                             ( (amplitude*vf->amplitude_offset)/
1121
                               (((1<<vf->amplitude_bits)-1) * sqrt(p+q)) )
1122
                             - vf->amplitude_offset ) * .11512925f
1123
                         );
1116
                    q = exp((((amplitude*vf->amplitude_offset) /
1117
                              (((1 << vf->amplitude_bits) - 1) * sqrt(p + q)))
1118
                             - vf->amplitude_offset) * .11512925f);
1124 1119
                }
1125 1120

  
1126 1121
                /* fill vector */
1127 1122
                do {
1128
                    vec[i]=q; ++i;
1129
                } while (vf->map[blockflag][i]==iter_cond);
1123
                    vec[i] = q; ++i;
1124
                } while (vf->map[blockflag][i] == iter_cond);
1130 1125
            }
1131 1126
        }
1132 1127
    } else {
......
1142 1137
static uint_fast8_t vorbis_floor1_decode(vorbis_context *vc,
1143 1138
                                         vorbis_floor_data *vfu, float *vec)
1144 1139
{
1145
    vorbis_floor1 * vf=&vfu->t1;
1146
    GetBitContext *gb=&vc->gb;
1147
    uint_fast16_t range_v[4]={ 256, 128, 86, 64 };
1148
    uint_fast16_t range=range_v[vf->multiplier-1];
1140
    vorbis_floor1 *vf = &vfu->t1;
1141
    GetBitContext *gb = &vc->gb;
1142
    uint_fast16_t range_v[4] = { 256, 128, 86, 64 };
1143
    uint_fast16_t range = range_v[vf->multiplier-1];
1149 1144
    uint_fast16_t floor1_Y[vf->x_list_dim];
1150 1145
    uint_fast16_t floor1_Y_final[vf->x_list_dim];
1151 1146
    int floor1_flag[vf->x_list_dim];
......
1157 1152
    int_fast16_t book;
1158 1153
    uint_fast16_t offset;
1159 1154
    uint_fast16_t i,j;
1160
    /*u*/int_fast16_t adx, ady, off, predicted; // WTF ? dy/adx= (unsigned)dy/adx ?
1155
    /*u*/int_fast16_t adx, ady, off, predicted; // WTF ? dy/adx =  (unsigned)dy/adx ?
1161 1156
    int_fast16_t dy, err;
1162 1157

  
1163 1158

  
......
1166 1161

  
1167 1162
// Read values (or differences) for the floor's points
1168 1163

  
1169
    floor1_Y[0]=get_bits(gb, ilog(range-1));
1170
    floor1_Y[1]=get_bits(gb, ilog(range-1));
1164
    floor1_Y[0] = get_bits(gb, ilog(range - 1));
1165
    floor1_Y[1] = get_bits(gb, ilog(range - 1));
1171 1166

  
1172 1167
    AV_DEBUG("floor 0 Y %d floor 1 Y %d \n", floor1_Y[0], floor1_Y[1]);
1173 1168

  
1174
    offset=2;
1175
    for(i=0;i<vf->partitions;++i) {
1176
        class_=vf->partition_class[i];
1177
        cdim=vf->class_dimensions[class_];
1178
        cbits=vf->class_subclasses[class_];
1179
        csub=(1<<cbits)-1;
1180
        cval=0;
1169
    offset = 2;
1170
    for (i = 0; i < vf->partitions; ++i) {
1171
        class_ = vf->partition_class[i];
1172
        cdim   = vf->class_dimensions[class_];
1173
        cbits  = vf->class_subclasses[class_];
1174
        csub = (1 << cbits) - 1;
1175
        cval = 0;
1181 1176

  
1182 1177
        AV_DEBUG("Cbits %d \n", cbits);
1183 1178

  
1184 1179
        if (cbits) // this reads all subclasses for this partition's class
1185
            cval=get_vlc2(gb, vc->codebooks[vf->class_masterbook[class_]].vlc.table,
1186
            vc->codebooks[vf->class_masterbook[class_]].nb_bits, 3);
1180
            cval = get_vlc2(gb, vc->codebooks[vf->class_masterbook[class_]].vlc.table,
1181
                            vc->codebooks[vf->class_masterbook[class_]].nb_bits, 3);
1187 1182

  
1188
        for(j=0;j<cdim;++j) {
1189
            book=vf->subclass_books[class_][cval & csub];
1183
        for (j = 0; j < cdim; ++j) {
1184
            book = vf->subclass_books[class_][cval & csub];
1190 1185

  
1191 1186
            AV_DEBUG("book %d Cbits %d cval %d  bits:%d \n", book, cbits, cval, get_bits_count(gb));
1192 1187

  
1193
            cval=cval>>cbits;
1194
            if (book>-1) {
1195
                floor1_Y[offset+j]=get_vlc2(gb, vc->codebooks[book].vlc.table,
1188
            cval = cval >> cbits;
1189
            if (book > -1) {
1190
                floor1_Y[offset+j] = get_vlc2(gb, vc->codebooks[book].vlc.table,
1196 1191
                vc->codebooks[book].nb_bits, 3);
1197 1192
            } else {
1198
                floor1_Y[offset+j]=0;
1193
                floor1_Y[offset+j] = 0;
1199 1194
            }
1200 1195

  
1201 1196
            AV_DEBUG(" floor(%d) = %d \n", vf->list[offset+j].x, floor1_Y[offset+j]);
......
1205 1200

  
1206 1201
// Amplitude calculation from the differences
1207 1202

  
1208
    floor1_flag[0]=1;
1209
    floor1_flag[1]=1;
1210
    floor1_Y_final[0]=floor1_Y[0];
1211
    floor1_Y_final[1]=floor1_Y[1];
1203
    floor1_flag[0] = 1;
1204
    floor1_flag[1] = 1;
1205
    floor1_Y_final[0] = floor1_Y[0];
1206
    floor1_Y_final[1] = floor1_Y[1];
1212 1207

  
1213
    for(i=2;i<vf->x_list_dim;++i) {
1208
    for (i = 2; i < vf->x_list_dim; ++i) {
1214 1209
        uint_fast16_t val, highroom, lowroom, room;
1215 1210
        uint_fast16_t high_neigh_offs;
1216 1211
        uint_fast16_t low_neigh_offs;
1217 1212

  
1218
        low_neigh_offs=vf->list[i].low;
1219
        high_neigh_offs=vf->list[i].high;
1220
        dy=floor1_Y_final[high_neigh_offs]-floor1_Y_final[low_neigh_offs];  // render_point begin
1221
        adx=vf->list[high_neigh_offs].x-vf->list[low_neigh_offs].x;
1222
        ady= FFABS(dy);
1223
        err=ady*(vf->list[i].x-vf->list[low_neigh_offs].x);
1224
        off=(int16_t)err/(int16_t)adx;
1225
        if (dy<0) {
1226
            predicted=floor1_Y_final[low_neigh_offs]-off;
1213
        low_neigh_offs  = vf->list[i].low;
1214
        high_neigh_offs = vf->list[i].high;
1215
        dy  = floor1_Y_final[high_neigh_offs] - floor1_Y_final[low_neigh_offs];  // render_point begin
1216
        adx = vf->list[high_neigh_offs].x - vf->list[low_neigh_offs].x;
1217
        ady = FFABS(dy);
1218
        err = ady * (vf->list[i].x - vf->list[low_neigh_offs].x);
1219
        off = (int16_t)err / (int16_t)adx;
1220
        if (dy < 0) {
1221
            predicted = floor1_Y_final[low_neigh_offs] - off;
1227 1222
        } else {
1228
            predicted=floor1_Y_final[low_neigh_offs]+off;
1223
            predicted = floor1_Y_final[low_neigh_offs] + off;
1229 1224
        } // render_point end
1230 1225

  
1231
        val=floor1_Y[i];
1232
        highroom=range-predicted;
1233
        lowroom=predicted;
1226
        val = floor1_Y[i];
1227
        highroom = range-predicted;
1228
        lowroom  = predicted;
1234 1229
        if (highroom < lowroom) {
1235
            room=highroom*2;
1230
            room = highroom * 2;
1236 1231
        } else {
1237
            room=lowroom*2;   // SPEC mispelling
1232
            room = lowroom * 2;   // SPEC mispelling
1238 1233
        }
1239 1234
        if (val) {
1240
            floor1_flag[low_neigh_offs]=1;
1241
            floor1_flag[high_neigh_offs]=1;
1242
            floor1_flag[i]=1;
1243
            if (val>=room) {
1235
            floor1_flag[low_neigh_offs]  = 1;
1236
            floor1_flag[high_neigh_offs] = 1;
1237
            floor1_flag[i]               = 1;
1238
            if (val >= room) {
1244 1239
                if (highroom > lowroom) {
1245
                    floor1_Y_final[i]=val-lowroom+predicted;
1240
                    floor1_Y_final[i] = val - lowroom + predicted;
1246 1241
                } else {
1247
                    floor1_Y_final[i]=predicted-val+highroom-1;
1242
                    floor1_Y_final[i] = predicted - val + highroom - 1;
1248 1243
                }
1249 1244
            } else {
1250 1245
                if (val & 1) {
1251
                    floor1_Y_final[i]=predicted-(val+1)/2;
1246
                    floor1_Y_final[i] = predicted - (val + 1) / 2;
1252 1247
                } else {
1253
                    floor1_Y_final[i]=predicted+val/2;
1248
                    floor1_Y_final[i] = predicted + val / 2;
1254 1249
                }
1255 1250
            }
1256 1251
        } else {
1257
            floor1_flag[i]=0;
1258
            floor1_Y_final[i]=predicted;
1252
            floor1_flag[i]    = 0;
1253
            floor1_Y_final[i] = predicted;
1259 1254
        }
1260 1255

  
1261 1256
        AV_DEBUG(" Decoded floor(%d) = %d / val %d \n", vf->list[i].x, floor1_Y_final[i], val);
......
1277 1272
                                                           uint_fast8_t ch,
1278 1273
                                                           uint_fast8_t *do_not_decode,
1279 1274
                                                           float *vec,
1280
                                                           uint_fast16_t
1281
                                                           vlen, int vr_type)
1275
                                                           uint_fast16_t vlen,
1276
                                                           int vr_type)
1282 1277
{
1283
    GetBitContext *gb=&vc->gb;
1284
    uint_fast8_t c_p_c=vc->codebooks[vr->classbook].dimensions;
1285
    uint_fast16_t n_to_read=vr->end-vr->begin;
1286
    uint_fast16_t ptns_to_read=n_to_read/vr->partition_size;
1278
    GetBitContext *gb = &vc->gb;
1279
    uint_fast8_t c_p_c = vc->codebooks[vr->classbook].dimensions;
1280
    uint_fast16_t n_to_read = vr->end-vr->begin;
1281
    uint_fast16_t ptns_to_read = n_to_read/vr->partition_size;
1287 1282
    uint_fast8_t classifs[ptns_to_read*vc->audio_channels];
1288 1283
    uint_fast8_t pass;
1289 1284
    uint_fast8_t ch_used;
1290 1285
    uint_fast8_t i,j,l;
1291 1286
    uint_fast16_t k;
1292 1287

  
1293
    if (vr_type==2) {
1294
        for(j=1;j<ch;++j)
1295
                do_not_decode[0]&=do_not_decode[j];  // FIXME - clobbering input
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff