Advertisement
image28

Wave file compressor

May 7th, 2016
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.85 KB | None | 0 0
  1. #include "defines.h"
  2. #include "bitfile-0.4\bitfile.h"
  3.  
  4. MAIN;
  5.     ARG_CHECK(1);
  6.  
  7.     INPUT_FILE;
  8.     OUTFILE(".wave");
  9. //  FILES;
  10.     UINT inbyte=0;
  11.     UINT outbyte=0;
  12.  
  13.     bit_file_t *output;
  14.     UINT amount=0;
  15.  
  16.     FOI(argv[1]);
  17.     output=BitFileOpen(outfile,BF_WRITE);
  18.  
  19.     while ( ! feof(input) )
  20.     {
  21.         READ;
  22.         outbyte=inbyte;
  23.  
  24.     // WAVE AND COMPRESS
  25.         if      ( inbyte < 2 )    {amount=0; outbyte=inbyte;   printf("INPUT:\tCOUNT\tOUTBYTE\n%d\t%d\t%d\n", inbyte,amount,outbyte);  outbyte <<= 7; }
  26.         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; }
  27.         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; }
  28.         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; }
  29.         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; }
  30.         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; }
  31.         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; }
  32.         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; }
  33.  
  34.    
  35.         // write 3 bit header
  36.         amount <<= 5;
  37.         BitFilePutBits(output, &amount, 3);
  38.         amount >>= 5;
  39.  
  40.         // convert data to bins
  41.         if ( amount > 0 )
  42.         {
  43.             // write amount bits
  44.             BitFilePutBits(output, &outbyte, amount);
  45.         }else{
  46.             // write one bit
  47.             BitFilePutBits(output, &outbyte, 1);
  48.         }
  49.     END;
  50.  
  51.     CLOSE(input);
  52.     BitFileClose(output);
  53.  
  54.     RET;
  55. END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement