home *** CD-ROM | disk | FTP | other *** search
/ Da Capo / da_capo_vol1.bin / programs / amiga / edit / amisox3.3 / dist / dyn.c < prev    next >
C/C++ Source or Header  |  1994-01-23  |  2KB  |  119 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 dynamic compander effect file.
  13.  *
  14.  * Compresses or expands dynamic range, i.e. range between
  15.  * soft and loud sounds.  U-law compression basically does this.
  16.  *
  17.  * Doesn't work.  Giving up for now.
  18.  */
  19.  
  20. #include "st.h"
  21. #include <math.h>
  22.  
  23. /* Private data for DYN.C file */
  24. typedef struct dyn{
  25.     int    rest;            /* bytes remaining in current block */
  26. } *dyn_t;
  27.  
  28. /*
  29.  * Process options
  30.  */
  31. dyn_getopts(effp, n, argv) 
  32. eff_t effp;
  33. int n;
  34. char **argv;
  35. {
  36.     if (n)
  37.         fail("Copy effect takes no options.");
  38. }
  39.  
  40. /*
  41.  * Prepare processing.
  42.  */
  43. dyn_start(effp)
  44. eff_t effp;
  45. {
  46.     /* nothing to do */
  47.     /* stuff data into delaying effects here */
  48. }
  49.  
  50. /*
  51.  * Processed signed long samples from ibuf to obuf.
  52.  * Return number of samples processed.
  53.  */
  54.  
  55. dyn_flow(effp, ibuf, obuf, isamp, osamp)
  56. eff_t effp;
  57. long *ibuf, *obuf;
  58. int *isamp, *osamp;
  59. {
  60.     dyn_t dyn = (dyn_t) effp->priv;
  61.     int len, done;
  62.     
  63.     char c;
  64.     unsigned char uc;
  65.     short s;
  66.     unsigned short us;
  67.     long l;
  68.     unsigned long ul;
  69.     float f;
  70.     double d, tmp;
  71.     int sign;
  72.  
  73. #define NORMIT (65536.0)
  74.  
  75.     len = ((*isamp > *osamp) ? *osamp : *isamp);
  76.     for(done = 0; done < len; done++) {
  77.  
  78.         d = *ibuf++;
  79.         if (d == 0.0)
  80.             l = 0;
  81.         else {
  82.             if (d < 0.0) {
  83.                 d *= -1.0;
  84.                 sign = -1;
  85.             } else
  86.                 sign = 1;
  87.             d /= NORMIT;
  88.             tmp = log10(d);
  89.             tmp = pow(8.0, tmp);
  90.             tmp = tmp * NORMIT;
  91.             l = tmp * sign;
  92.         }
  93.         *obuf++ = l;
  94.     }
  95. }
  96.  
  97. /*
  98.  * Drain out remaining samples if the effect generates any.
  99.  */
  100.  
  101. dyn_drain(effp, obuf, osamp)
  102. long *obuf;
  103. int *osamp;
  104. {
  105.     *osamp = 0;
  106. }
  107.  
  108. /*
  109.  * Do anything required when you stop reading samples.  
  110.  *    (free allocated memory, etc.)
  111.  */
  112. dyn_stop(effp)
  113. eff_t effp;
  114. {
  115.     /* nothing to do */
  116. }
  117.  
  118.  
  119.