-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbitpack.c
More file actions
92 lines (76 loc) · 2.28 KB
/
bitpack.c
File metadata and controls
92 lines (76 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
* AmiSoundED - Sound Editor
* Copyright (C) 2008-2009 Fredrik Wikstrom <fredrik@a500.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/*
* wave.datatype
* (c) Fredrik Wikstrom
*/
#include <exec/types.h>
#include <dos/dos.h>
#include "endian.h"
#include "bitpack.h"
// Generic BitPack stuff:
void bitpack_init (BitPack_buffer *b, void *ptr, int32 size) {
b->buffer=b->ptr=ptr;
b->size=size;
b->endbyte=0;
b->endbit=0;
}
const uint32 bp_mask[33]={
0x00000000, 0x00000001, 0x00000003, 0x00000007,
0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f,
0x000000ff, 0x000001ff, 0x000003ff, 0x000007ff,
0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff,
0x0000ffff, 0x0001ffff, 0x0003ffff, 0x0007ffff,
0x000fffff, 0x001fffff, 0x003fffff, 0x007fffff,
0x00ffffff, 0x01ffffff, 0x03ffffff, 0x07ffffff,
0x0fffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff,
0xffffffff
};
int32 bitpack_seek (BitPack_buffer *b, int32 offs, int32 type) {
int32 oldoffset;
oldoffset=(b->endbyte<<3)+b->endbit;
switch (type) {
case OFFSET_CURRENT:
offs+=oldoffset;
break;
case OFFSET_END:
offs+=(b->size<<3);
break;
}
b->endbyte=offs>>3;
b->endbit=offs&7;
b->ptr=b->buffer+b->endbyte;
return (oldoffset);
}
void * bitpack_align (BitPack_buffer *b) {
if (b->endbit) {
b->endbit=0;
b->endbyte++;
b->ptr++;
}
return (b->ptr);
}
void * bitpack_align_even (BitPack_buffer *b) {
bitpack_align_lsb(b);
if (b->endbyte&1) {
b->endbyte++;
b->ptr++;
}
return (b->ptr);
}