-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitpack_lsb.c
131 lines (107 loc) · 2.86 KB
/
bitpack_lsb.c
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
* 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"
// LSb style functions:
extern const uint32 bp_mask[33];
uint32 bitpack_read1_lsb (BitPack_buffer *b) {
uint32 ret=0;
if (b->ptr[0]&(1 << b->endbit))
ret=1;
b->endbit++;
if (b->endbit==8) {
b->endbit=0;
b->ptr++;
b->endbyte++;
}
return (ret);
}
uint32 bitpack_read_lsb (BitPack_buffer *b, int32 bits) {
uint32 ret;
bits+=b->endbit;
ret=b->ptr[0]>>b->endbit;
if (bits>8) {
ret|=b->ptr[1]<<(8-b->endbit);
if (bits>16) {
ret|=b->ptr[2]<<(16-b->endbit);
if (bits>24) {
ret|=b->ptr[3]<<(24-b->endbit);
if (bits>32) {
ret|=b->ptr[4]<<(32-b->endbit);
}
}
}
}
ret&=bp_mask[bits];
b->ptr+=(bits >> 3);
b->endbyte+=(bits >> 3);
b->endbit=bits&7;
return (ret);
}
#if BP_WRITE_CMDS
void bitpack_write1_lsb (BitPack_buffer *b, uint32 val) {
if (val & 1) {
b->ptr[0]|=(1 << b->endbit);
} else {
b->ptr[0]&=~(1 << b->endbit);
}
b->endbit++;
if (b->endbit==8) {
b->endbit=0;
b->ptr++;
b->endbyte++;
}
}
void bitpack_write_lsb (BitPack_buffer *b, uint32 val, int32 bits) {
val&=bp_mask[bits];
bits+=b->endbit;
b->ptr[0]|=val<<b->endbit;
if (bits>=8) {
b->ptr[1]=val>>(8-b->endbit);
if (bits>=16) {
b->ptr[2]=val>>(16-b->endbit);
if (bits>=32) {
if (b->endbit)
b->ptr[4]=val>>(32-b->endbit);
else
b->ptr[4]=0;
}
}
}
b->endbyte+=(bits>>3);
b->ptr+=(bits>>3);
b->endbit=bits&7;
}
#endif
#if BP_FAST_CMDS
void bitpack_iobits_lsb (ExtBitPack_buffer *b, int32 bits) {
}
uint32 bitpack_fastread_lsb (ExtBitPack_buffer *b) {
}
#if BP_WRITE_CMDS
void bitpack_fastwrite_lsb (ExtBitPack_buffer *b, uint32 val) {
}
#endif
#endif