Import the current wip animation datatype and subclasses. further development will...
[AROS.git] / workbench / classes / datatypes / wav / bitpack_lsb.c
blob4bbbffb698ce727a35d3be190b9e7ae2fc467324
1 /*
2 * wave.datatype
3 * (c) Fredrik Wikstrom
4 */
6 #include <exec/types.h>
7 #include <dos/dos.h>
9 #include "endian.h"
10 #include "bitpack.h"
12 // LSb style functions:
14 extern const ULONG bp_mask[33];
16 ULONG bitpack_read1_lsb (BitPack_buffer *b) {
17 ULONG ret=0;
18 if (b->ptr[0]&(1 << b->endbit))
19 ret=1;
20 b->endbit++;
21 if (b->endbit==8) {
22 b->endbit=0;
23 b->ptr++;
24 b->endbyte++;
26 return (ret);
29 ULONG bitpack_read_lsb (BitPack_buffer *b, LONG bits) {
30 ULONG ret;
32 bits+=b->endbit;
34 ret=b->ptr[0]>>b->endbit;
35 if (bits>8) {
36 ret|=b->ptr[1]<<(8-b->endbit);
37 if (bits>16) {
38 ret|=b->ptr[2]<<(16-b->endbit);
39 if (bits>24) {
40 ret|=b->ptr[3]<<(24-b->endbit);
41 if (bits>32) {
42 ret|=b->ptr[4]<<(32-b->endbit);
47 ret&=bp_mask[bits];
49 b->ptr+=(bits >> 3);
50 b->endbyte+=(bits >> 3);
51 b->endbit=bits&7;
53 return (ret);
56 #if BP_WRITE_CMDS
58 void bitpack_write1_lsb (BitPack_buffer *b, ULONG val) {
59 if (val & 1) {
60 b->ptr[0]|=(1 << b->endbit);
61 } else {
62 b->ptr[0]&=~(1 << b->endbit);
64 b->endbit++;
65 if (b->endbit==8) {
66 b->endbit=0;
67 b->ptr++;
68 b->endbyte++;
72 void bitpack_write_lsb (BitPack_buffer *b, ULONG val, LONG bits) {
73 val&=bp_mask[bits];
74 bits+=b->endbit;
76 b->ptr[0]|=val<<b->endbit;
77 if (bits>=8) {
78 b->ptr[1]=val>>(8-b->endbit);
79 if (bits>=16) {
80 b->ptr[2]=val>>(16-b->endbit);
81 if (bits>=32) {
82 if (b->endbit)
83 b->ptr[4]=val>>(32-b->endbit);
84 else
85 b->ptr[4]=0;
90 b->endbyte+=(bits>>3);
91 b->ptr+=(bits>>3);
92 b->endbit=bits&7;
95 #endif
97 #if BP_FAST_CMDS
99 void bitpack_iobits_lsb (ExtBitPack_buffer *b, LONG bits) {
102 ULONG bitpack_fastread_lsb (ExtBitPack_buffer *b) {
105 #if BP_WRITE_CMDS
107 void bitpack_fastwrite_lsb (ExtBitPack_buffer *b, ULONG val) {
110 #endif
112 #endif