~ubuntu-branches/ubuntu/hardy/avidemux/hardy

« back to all changes in this revision

Viewing changes to avidemux/ADM_libraries/ADM_libtwolame/bitbuffer.c

  • Committer: Bazaar Package Importer
  • Author(s): Matvey Kozhev
  • Date: 2007-12-18 13:53:04 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20071218135304-cdqec2lg2bglyz15
Tags: 1:2.4~preview3-0.0ubuntu1
* Upload to Ubuntu. (LP: #163287, LP: #126572)
* debian/changelog: re-added Ubuntu releases.
* debian/control:
  - Require debhelper >= 5.0.51 (for dh_icons) and imagemagick.
  - Build-depend on libsdl1.2-dev instead of libsdl-dev.
  - Build against newer libx264-dev. (LP: #138854)
  - Removed libamrnb-dev, not in Ubuntu yet.
* debian/rules:
  - Install all icon sizes, using convert (upstream installs none).
  - Added missing calls to dh_installmenu, dh_installman, dh_icons and
    dh_desktop.
* debian/menu, debian/avidemux-qt.menu:
  - Corrected package and executable names.
* debian/avidemux-common.install: Install icons.
* debian/avidemux.common.manpages: Install man/avidemux.1.
* debian/links, debian/avidemux-cli.links, debian/avidemux-gtk.links:
  - Link manpages to avidemux.1.gz.
* debian/install, debian/avidemux-qt.install, debian/avidemux-gtk.desktop,
  debian/avidemux-qt.desktop: Install desktop files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  TwoLAME: an optimized MPEG Audio Layer Two encoder
 
3
 *
 
4
 *  Copyright (C) 2001-2004 Michael Cheng
 
5
 *  Copyright (C) 2004-2005 The TwoLAME Project
 
6
 *
 
7
 *  This library is free software; you can redistribute it and/or
 
8
 *  modify it under the terms of the GNU Lesser General Public
 
9
 *  License as published by the Free Software Foundation; either
 
10
 *  version 2.1 of the License, or (at your option) any later version.
 
11
 *
 
12
 *  This library is distributed in the hope that it will be useful,
 
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
 *  Lesser General Public License for more details.
 
16
 *
 
17
 *  You should have received a copy of the GNU Lesser General Public
 
18
 *  License along with this library; if not, write to the Free Software
 
19
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
20
 *  
 
21
 */
 
22
 
 
23
 
 
24
#include <stdio.h>
 
25
#include <stdlib.h>
 
26
 
 
27
#include "twolame.h"
 
28
#include "common.h"
 
29
#include "bitbuffer.h"
 
30
#include "mem.h"
 
31
 
 
32
 
 
33
/*create bit buffer*/
 
34
bit_stream* buffer_init( unsigned char *buffer, int buffer_size )
 
35
{
 
36
        bit_stream* bs = (bit_stream *)twolame_malloc(sizeof(bit_stream),"bit_stream");
 
37
        
 
38
        bs->buf = buffer;
 
39
        bs->buf_size = buffer_size;
 
40
        bs->buf_byte_idx = 0;
 
41
        bs->buf_bit_idx = 8;
 
42
        bs->totbit = 0;
 
43
        bs->eob = FALSE;
 
44
        bs->eobs = FALSE;
 
45
        
 
46
        return bs;
 
47
}
 
48
 
 
49
/* Dellocate bit buffer */
 
50
void buffer_deinit( bit_stream ** bs )
 
51
{
 
52
        twolame_free( (void**)bs );
 
53
}
 
54
 
 
55
 
 
56
/*write 1 bit from the bit stream */
 
57
void buffer_put1bit (bit_stream * bs, int bit)
 
58
{
 
59
        bs->totbit++;
 
60
        
 
61
        bs->buf[bs->buf_byte_idx] |= (bit & 0x1) << (bs->buf_bit_idx - 1);
 
62
        bs->buf_bit_idx--;
 
63
        if (!bs->buf_bit_idx) {
 
64
                bs->buf_bit_idx = 8;
 
65
                bs->buf_byte_idx++;
 
66
                if (bs->buf_byte_idx >= bs->buf_size) {
 
67
                        //empty_buffer (bs, minimum);
 
68
                        fprintf(stdout,"buffer_put1bit: error. bit_stream buffer needs to be bigger\n");
 
69
                        exit(99);
 
70
                }
 
71
                bs->buf[bs->buf_byte_idx] = 0;
 
72
        }
 
73
}
 
74
 
 
75
/*write N bits into the bit stream */
 
76
inline void buffer_putbits (bit_stream * bs, unsigned int val, int N)
 
77
{
 
78
        static const int putmask[9] = { 0x0, 0x1, 0x3, 0x7, 0xf, 0x1f, 0x3f, 0x7f, 0xff };
 
79
        register int j = N;
 
80
        register int k, tmp;
 
81
        
 
82
        bs->totbit += N;
 
83
        while (j > 0) {
 
84
                k = MIN (j, bs->buf_bit_idx);
 
85
                tmp = val >> (j - k);
 
86
                bs->buf[bs->buf_byte_idx] |= (tmp & putmask[k]) << (bs->buf_bit_idx - k);
 
87
                bs->buf_bit_idx -= k;
 
88
                if (!bs->buf_bit_idx) {
 
89
                        bs->buf_bit_idx = 8;
 
90
                        bs->buf_byte_idx++;
 
91
                        if (bs->buf_byte_idx >= bs->buf_size) {
 
92
                                //empty_buffer (bs, minimum);
 
93
                                fprintf(stdout,"buffer_putbits: error. bit_stream buffer needs to be bigger\n");
 
94
                                exit(99);       
 
95
                        }
 
96
                        bs->buf[bs->buf_byte_idx] = 0;
 
97
                }
 
98
                j -= k;
 
99
        }
 
100
}
 
101
 
 
102
/*return the current bit stream length (in bits)*/
 
103
unsigned long buffer_sstell (bit_stream * bs)
 
104
{
 
105
        return (bs->totbit);
 
106
}
 
107