xeye_ atsu
/
RiceGolombDPCM_Player
For BU9480F D-A Conv.
_bitio.cpp
- Committer:
- lynxeyed_atsu
- Date:
- 2010-09-11
- Revision:
- 3:64c3ed0fc4b4
- Parent:
- 1:02bfb013660c
File content as of revision 3:64c3ed0fc4b4:
#include "mbed.h" #include "string" #include "_bitio.h" FILE *infp, *outfp; int getcount, putcount; Uint bitbuf; void init_bit_o(void) { putcount = 8; bitbuf = 0; } void init_bit_i(void) { getcount = 0; bitbuf = 0; } Uint getbit(void) { int flag; if (--getcount >= 0) return (bitbuf >> getcount) & 1U; getcount = 7; if((flag = fgetc(infp))==EOF)return OVERRUN; else bitbuf = flag; return (bitbuf >> 7) & 1U; } Uint getbits(int n) { Uint x = 0; if (n < 1 || 25 < n) return 0; while (n > getcount) { n -= getcount; x |= rightbits(getcount, bitbuf) << n; bitbuf = fgetc(infp); getcount = 8; } getcount -= n; return x | rightbits(n, bitbuf >> getcount); } void putbit(Uint bit) { putcount--; if (bit != 0) bitbuf |= (1 << putcount); if (putcount == 0) { if (fputc(bitbuf, outfp) == EOF) error("can't write\r\n"); bitbuf = 0; putcount = 8; } } void putbits(int n, Uint x) { if (n < 1 || 25 < n) return; while (n >= putcount) { n -= putcount; bitbuf |= rightbits(putcount, x >> n); if (fputc(bitbuf, outfp) == EOF) error("cant write\r\n"); bitbuf = 0U; putcount = 8; } putcount -= n; bitbuf |= rightbits(n, x) << putcount; }