home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the DOOM Programming Gurus / Tricks_of_the_Doom_Programming_Gurus.iso / bonus / linux / dm2au / snd2au.c < prev   
Encoding:
Text File  |  1994-06-25  |  2.8 KB  |  73 lines

  1. /************************************************************************/
  2. /*      Copyright 1989 by Rich Gopstein and Harris Corporation          */
  3. /*                                                                      */
  4. /*      Permission to use, copy, modify, and distribute this software   */
  5. /*      and its documentation for any purpose and without fee is        */
  6. /*      hereby granted, provided that the above copyright notice        */
  7. /*      appears in all copies and that both that copyright notice and   */
  8. /*      this permission notice appear in supporting documentation, and  */
  9. /*      that the name of Rich Gopstein and Harris Corporation not be    */
  10. /*      used in advertising or publicity pertaining to distribution     */
  11. /*      of the software without specific, written prior permission.     */
  12. /*      Rich Gopstein and Harris Corporation make no representations    */
  13. /*      about the suitability of this software for any purpose.  It     */
  14. /*      provided "as is" without express or implied warranty.           */
  15. /************************************************************************/
  16.  
  17. /************************************************************************/
  18. /* sound2sun.c - Convert sampled audio files into uLAW format for the   */
  19. /*               Sparcstation 1.                                        */
  20. /*               Send comments to ..!rutgers!soleil!gopstein            */
  21. /************************************************************************/
  22. /*                                    */
  23. /*  Modified November 27, 1989 to convert to 8000 samples/sec           */
  24. /*   (contrary to man page)                                             */
  25. /*                                    */
  26. /*  Fixed Bug with converting slow sample speeds            */
  27. /*                                    */
  28. /************************************************************************/
  29. /*                                    */
  30. /*  Modified 11/1991                            */
  31. /*  By nevs@opal.cs.tu-berlin.de                    */
  32. /*   (contrary to man page)                                             */
  33. /*                                    */
  34. /*                                    */
  35. /************************************************************************/
  36.  
  37. /* convert two's complement ch into uLAW format */
  38.  
  39. unsigned int sample_cvt(ch)
  40. int ch;
  41. {
  42.  
  43.   int mask;
  44.  
  45.   if (ch < 0) {
  46.     ch = -ch;
  47.     mask = 0x7f;
  48.   } else {
  49.     mask = 0xff;
  50.   }
  51.  
  52.   if (ch < 32) {
  53.     ch = 0xF0 | 15 - (ch / 2);
  54.   } else if (ch < 96) {
  55.     ch = 0xE0 | 15 - (ch - 32) / 4;
  56.   } else if (ch < 224) {
  57.     ch = 0xD0 | 15 - (ch - 96) / 8;
  58.   } else if (ch < 480) {
  59.     ch = 0xC0 | 15 - (ch - 224) / 16;
  60.   } else if (ch < 992) {
  61.     ch = 0xB0 | 15 - (ch - 480) / 32;
  62.   } else if (ch < 2016) {
  63.     ch = 0xA0 | 15 - (ch - 992) / 64;
  64.   } else if (ch < 4064) {
  65.     ch = 0x90 | 15 - (ch - 2016) / 128;
  66.   } else if (ch < 8160) {
  67.     ch = 0x80 | 15 - (ch - 4064) /  256;
  68.   } else {
  69.     ch = 0x80;
  70.   }
  71. return (mask & ch);
  72. }
  73.