home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Sound / SoX / Source / mask.c < prev    next >
C/C++ Source or Header  |  1999-07-18  |  2KB  |  101 lines

  1.  
  2. /*
  3.  * July 5, 1991
  4.  * Copyright 1991 Lance Norskog And Sundry Contributors
  5.  * This source code is freely redistributable and may be used for
  6.  * any purpose.  This copyright notice must be maintained. 
  7.  * Lance Norskog And Sundry Contributors are not responsible for 
  8.  * the consequences of using this software.
  9.  */
  10.  
  11. /*
  12.  * Sound Tools masking noise effect file.
  13.  */
  14.  
  15. #include <math.h>
  16. #include "st.h"
  17.  
  18. #define HALFABIT 1.44            /* square root of 2 */
  19.  
  20. void newrand15();
  21. ULONG rand15();
  22.  
  23. /*
  24.  * Problems:
  25.  *     1) doesn't allow specification of noise depth
  26.  *    2) does triangular noise, could do local shaping
  27.  *    3) can run over 32 bits.
  28.  */
  29.  
  30. /*
  31.  * Process options
  32.  */
  33. void mask_getopts(effp, n, argv) 
  34. eff_t effp;
  35. int n;
  36. char **argv;
  37. {
  38.     if (n)
  39.         fail("Mask effect takes no options.");
  40.     /* should take # of bits */
  41.  
  42.     newrand15();
  43. }
  44.  
  45. /*
  46.  * Processed signed long samples from ibuf to obuf.
  47.  * Return number of samples processed.
  48.  */
  49.  
  50. void mask_flow(effp, ibuf, obuf, isamp, osamp)
  51. eff_t effp;
  52. LONG *ibuf, *obuf;
  53. int *isamp, *osamp;
  54. {
  55.     int len, done;
  56.     
  57.     LONG l;
  58.     LONG tri16;    /* 16 signed bits of triangular noise */
  59.  
  60.     len = ((*isamp > *osamp) ? *osamp : *isamp);
  61.     switch (effp->outinfo.style) {
  62.         case ULAW:
  63.         case ALAW:
  64.             for(done = 0; done < len; done++) {
  65.                 tri16 = (rand15() + rand15()) - 32767;
  66.  
  67.                 l = *ibuf++ + tri16*16*HALFABIT;  /* 2^4.5 */
  68.                 *obuf++ = l;
  69.             }
  70.             break;
  71.         default:
  72.         switch (effp->outinfo.size) {
  73.             case BYTE:
  74.             for(done = 0; done < len; done++) {
  75.                 tri16 = (rand15() + rand15()) - 32767;
  76.  
  77.                 l = *ibuf++ + tri16*256*HALFABIT;  /* 2^8.5 */
  78.                 *obuf++ = l;
  79.             }
  80.             break;
  81.             case WORD:
  82.             for(done = 0; done < len; done++) {
  83.                 tri16 = (rand15() + rand15()) - 32767;
  84.  
  85.                 l = *ibuf++ + tri16*HALFABIT;  /* 2^.5 */
  86.                 *obuf++ = l;
  87.             }
  88.             break;
  89.             default:
  90.             for(done = 0; done < len; done++) {
  91.                 *obuf++ = *ibuf++;
  92.             }
  93.             break;
  94.         }
  95.     }
  96.  
  97.     *isamp = done;
  98.     *osamp = done;
  99. }
  100.  
  101.