2
* toolame - an optimized mpeg 1/2 layer 2 audio encoder
3
* Copyright (C) 2001 Michael Cheng
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
#include "availbits.h"
35
/* function returns the number of available bits */
36
int available_bits (frame_header *header, options * glopts)
40
slots.extra = 0; /* be default, no extra slots */
43
(1152.0 / s_freq[header->version][header->sampling_frequency]) *
44
((double) bitrate[header->version][header->bitrate_index] / 8.0);
46
slots.whole = (int) slots.average;
47
slots.frac = slots.average - (double) slots.whole;
49
/* never allow padding for a VBR frame.
50
Don't ask me why, I've forgotten why I set this */
51
if (slots.frac != 0 && glopts->usepadbit && glopts->vbr == FALSE) {
52
if (slots.lag > (slots.frac - 1.0)) { /* no padding for this frame */
53
slots.lag -= slots.frac;
56
} else { /* padding */
60
slots.lag += (1 - slots.frac);
64
adb = (slots.whole + slots.extra) * 8;