home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Multimed / Multimed.zip / rxwavsrc.zip / RxWavDyn.c < prev    next >
C/C++ Source or Header  |  2000-03-06  |  3KB  |  108 lines

  1. /*  RxWav
  2.    Copyright (C) 1999 2000  Giorgio Vicario
  3.  
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 2 of the License, or
  7.    (at your option) any later version.
  8.  
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA     */
  17.  
  18. #define INCL_REXXSAA
  19. #include <os2emx.h>
  20. #include <stdlib.h>
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include <regexp.h>
  24. #include <math.h>
  25. #include <float.h>
  26. #include "RxWav.h"
  27.  
  28. /***********************************************************************
  29. Dyn (compressore/espansore di dinamica)
  30. Vuole il puntatore ad un campione in una traccia gia' allocata, il
  31. numero di campioni da elaborare, e il fattore di espansione/compressione
  32. ***********************************************************************/
  33. ULONG
  34. WavDyn (PCSZ name, LONG argc, const RXSTRING * argv,
  35.         PCSZ queuename, PRXSTRING retstr)
  36. {
  37.   PSHORT pCh = NULL;
  38.   ULONG nCampioni, i, j;
  39.   float dinamica;
  40.   APIRET rc;
  41.   double kz, t, d, max;
  42.  
  43.   if (argc != 3)
  44.     {
  45.       SendMsg (FUNC_DYN, ERR_NUMERO_PARAMETRI);
  46.       return INVALID_ROUTINE;
  47.     }
  48.  
  49.   if (!sscanf (argv[0].strptr, "%d", &pCh))
  50.     {
  51.       SendMsg (FUNC_DYN, ERR_PUNTATORE_ERRATO);
  52.       return INVALID_ROUTINE;
  53.     }
  54.  
  55.   nCampioni = atol (argv[1].strptr);
  56.   if (nCampioni < 1)
  57.     {
  58.       SendMsg (FUNC_DYN, ERR_NUMERO_CAMPIONI);
  59.       return INVALID_ROUTINE;
  60.     }
  61.  
  62.   pCh = AllineaCh (pCh, nCampioni, FUNC_DYN);
  63.   if (!pCh)
  64.     return INVALID_ROUTINE;
  65.  
  66.   dinamica = atof (argv[2].strptr);
  67.   if ((dinamica < 0.01) | (dinamica > 9))
  68.     {
  69.       SendMsg (FUNC_DYN, ERR_VALORE_INVALIDO);
  70.       return INVALID_ROUTINE;
  71.     }
  72.  
  73.   kz = exp (1) * dinamica;
  74.   max = MAX_CAMPIONE;
  75.  
  76.   for (i = nCampioni; i != 0; i--)
  77.     {
  78.       if (*pCh < 0)
  79.         {
  80.           for (j = 0; (*pCh < 0) & (j < i); j++)
  81.             d = d + (double) *pCh++;
  82.           d = (d / (double) j) / -max;
  83.           t = pow (kz, log (d)) / d;
  84.           pCh = pCh - j;
  85.           i = i - j;
  86.           for (; j != 0; j--)
  87.             *pCh++ = (USHORT) (((double) *pCh * t));
  88.         }
  89.       else if (*pCh > 0)
  90.         {
  91.           for (j = 0; (*pCh > 0) & (j < i); j++)
  92.             d = d + (double) *pCh++;
  93.           d = (d / (double) j) / max;
  94.           t = pow (kz, log (d)) / d;
  95.           pCh = pCh - j;
  96.           i = i - j;
  97.           for (; j != 0; j--)
  98.             *pCh++ = (USHORT) (((double) *pCh * t));
  99.         }
  100.       pCh++;
  101.     }
  102.  
  103.  
  104.   sprintf (retstr->strptr, "%i", *pCh);
  105.   retstr->strlength = strlen (retstr->strptr);
  106.   return VALID_ROUTINE;
  107. }
  108.