Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "defines.h"
- #include "bitfile-0.4\bitfile.h"
- MAIN;
- ARG_CHECK(1);
- INPUT_FILE;
- OUTFILE(".wave");
- // FILES;
- UINT inbyte=0;
- UINT outbyte=0;
- bit_file_t *output;
- UINT amount=0;
- FOI(argv[1]);
- output=BitFileOpen(outfile,BF_WRITE);
- while ( ! feof(input) )
- {
- READ;
- outbyte=inbyte;
- // WAVE AND COMPRESS
- if ( inbyte < 2 ) {amount=0; outbyte=inbyte; printf("INPUT:\tCOUNT\tOUTBYTE\n%d\t%d\t%d\n", inbyte,amount,outbyte); outbyte <<= 7; }
- else if ( inbyte < 4 ) {amount=1; outbyte=inbyte-2; printf("INPUT:\tCOUNT\tOUTBYTE\n%d\t%d\t%d\n", inbyte,amount,outbyte); outbyte <<= 7; }
- else if ( inbyte < 8 ) {amount=2; outbyte=inbyte-4; printf("INPUT:\tCOUNT\tOUTBYTE\n%d\t%d\t%d\n", inbyte,amount,outbyte); outbyte <<= 6; }
- else if ( inbyte < 16 ) {amount=3; outbyte=inbyte-8; printf("INPUT:\tCOUNT\tOUTBYTE\n%d\t%d\t%d\n", inbyte,amount,outbyte); outbyte <<= 5; }
- else if ( inbyte < 32 ) {amount=4; outbyte=inbyte-16;printf("INPUT:\tCOUNT\tOUTBYTE\n%d\t%d\t%d\n", inbyte,amount,outbyte); outbyte <<= 4; }
- else if ( inbyte < 64 ) {amount=5; outbyte=inbyte-32;printf("INPUT:\tCOUNT\tOUTBYTE\n%d\t%d\t%d\n", inbyte,amount,outbyte); outbyte <<= 3; }
- else if ( inbyte < 128 ) {amount=6; outbyte=inbyte-64;printf("INPUT:\tCOUNT\tOUTBYTE\n%d\t%d\t%d\n", inbyte,amount,outbyte); outbyte <<= 2; }
- else if ( inbyte <= 255 ) {amount=7; outbyte=inbyte-128;printf("INPUT:\tCOUNT\tOUTBYTE\n%d\t%d\t%d\n", inbyte,amount,outbyte); outbyte <<= 1; }
- // write 3 bit header
- amount <<= 5;
- BitFilePutBits(output, &amount, 3);
- amount >>= 5;
- // convert data to bins
- if ( amount > 0 )
- {
- // write amount bits
- BitFilePutBits(output, &outbyte, amount);
- }else{
- // write one bit
- BitFilePutBits(output, &outbyte, 1);
- }
- END;
- CLOSE(input);
- BitFileClose(output);
- RET;
- END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement