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

  1. /*  RxWav
  2.    Copyright (C) 1999  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. Riverbero:
  30. Vuole il puntatore ad una traccia gia' allocate, la durata in campioni,
  31. due stem con i ritardi in campioni e l'ampiezza da 0 a 1
  32. ***********************************************************************/
  33. ULONG
  34. WavReverb (PCSZ name, LONG argc, const RXSTRING * argv,
  35.        PCSZ queuename, PRXSTRING retstr)
  36. {
  37.   PSHORT pCh = NULL, pChR = NULL, rit[MAX];
  38.   ULONG nCamp, componenti, max_rit, k;
  39.   float tmp = 0, liv[MAX];
  40.   RXSTEMDATA ritardo, livello;
  41.   INT i, j;
  42.   APIRET rc;
  43.  
  44.   if (argc != 4)
  45.     {
  46.       SendMsg (FUNC_REVERB, ERR_NUMERO_PARAMETRI);
  47.       return INVALID_ROUTINE;
  48.     }
  49.  
  50.   if (!sscanf (argv[0].strptr, "%d", &pCh))
  51.     {
  52.       SendMsg (FUNC_REVERB, ERR_PUNTATORE_ERRATO);
  53.       return INVALID_ROUTINE;
  54.     }
  55.  
  56.   nCamp = atol (argv[1].strptr);
  57.   if (!nCamp)
  58.     {
  59.       SendMsg (FUNC_REVERB, ERR_NUMERO_CAMPIONI);
  60.       return INVALID_ROUTINE;
  61.     }
  62.  
  63.   ritardo.count = 0;
  64.   strcpy (ritardo.varname, argv[2].strptr);
  65.   ritardo.stemlen = argv[2].strlength;
  66.   strupr (ritardo.varname);
  67.   if (ritardo.varname[ritardo.stemlen - 1] != '.')
  68.     ritardo.varname[ritardo.stemlen++] = '.';
  69.   if (FetchStem (ritardo, &tmp))
  70.     {
  71.       SendMsg (FUNC_REVERB, ERR_LETTURA_STEM);
  72.       printf ("       RexxVariablePool rc:%i\n", ritardo.shvb.shvret);
  73.       return INVALID_ROUTINE;
  74.     }
  75.   else
  76.     ritardo.count = tmp;
  77.  
  78.  
  79.   livello.count = 0;
  80.   strcpy (livello.varname, argv[3].strptr);
  81.   livello.stemlen = argv[3].strlength;
  82.   strupr (livello.varname);
  83.   if (livello.varname[livello.stemlen - 1] != '.')
  84.     livello.varname[livello.stemlen++] = '.';
  85.   if (FetchStem (livello, &tmp))
  86.     {
  87.       SendMsg (FUNC_REVERB, ERR_LETTURA_STEM);
  88.       printf ("       RexxVariablePool rc:%i\n", livello.shvb.shvret);
  89.       return INVALID_ROUTINE;
  90.     }
  91.   else
  92.     livello.count = tmp;
  93.  
  94.   if (livello.count != ritardo.count)
  95.     {
  96.       SendMsg (FUNC_REVERB, ERR_STEM_DIVERSI);
  97.       return INVALID_ROUTINE;
  98.     }
  99.  
  100.   if ((livello.count > MAX) | (ritardo.count > MAX))
  101.     {
  102.       SendMsg (FUNC_REVERB, ERR_STEM_MASSIMO);
  103.       return INVALID_ROUTINE;
  104.     }
  105.  
  106.   componenti = ritardo.count;
  107.   max_rit = 0;
  108.   ritardo.count = 0;
  109.   livello.count = 0;
  110.   pCh = AllineaCh (pCh, nCamp, FUNC_REVERB);
  111.   if (!pCh)
  112.     return INVALID_ROUTINE;
  113.   pChR = pCh + nCamp;
  114.  
  115.   for (i = 0; i < componenti; i++)
  116.     {
  117.       ritardo.count++;
  118.       livello.count++;
  119.       if (FetchStem (livello, &liv[i]))
  120.     {
  121.       SendMsg (FUNC_REVERB, ERR_LETTURA_STEM);
  122.       printf ("       RexxVariablePool rc:%i\n", livello.shvb.shvret);
  123.       return INVALID_ROUTINE;
  124.     }
  125.  
  126.       if (FetchStem (ritardo, &tmp))
  127.     {
  128.       SendMsg (FUNC_REVERB, ERR_LETTURA_STEM);
  129.       printf ("       RexxVariablePool rc:%i\n", ritardo.shvb.shvret);
  130.       return INVALID_ROUTINE;
  131.     }
  132.       if (tmp > max_rit)
  133.     max_rit = tmp;
  134.       rit[i] = pChR - (SHORT) tmp;
  135.     }
  136.  
  137.   if (max_rit > nCamp)
  138.     {
  139.       SendMsg (FUNC_REVERB, ERR_RITARDO_REVERB);
  140.       return INVALID_ROUTINE;
  141.     }
  142.  
  143.   componenti--;
  144.  
  145.   for (i = (nCamp - max_rit); i != 0; i--)
  146.     {
  147.       for (j = componenti; j != 0; j--)
  148.     {
  149.       *pChR = *pChR + *rit[j] * liv[j];
  150.       rit[j]--;
  151.     }
  152.       pChR--;
  153.     }
  154.  
  155.   for (i = max_rit; i != 0; i--)
  156.     {
  157.       for (j = componenti; j != 0; j--)
  158.     {
  159.       if (pCh < rit[j])
  160.         {
  161.           *pChR = *pChR + *rit[j] * liv[j];
  162.           rit[j]--;
  163.         }
  164.     }
  165.       pChR--;
  166.     }
  167.  
  168.  
  169.   sprintf (retstr->strptr, "%i", ERR_OK);
  170.   retstr->strlength = strlen (retstr->strptr);
  171.   return VALID_ROUTINE;
  172. }
  173.  
  174.  
  175.  
  176.  
  177. /***********************************************************************
  178. Revert: inverte (in senso temporale) una traccia
  179. Vuole il puntatore ad una traccia gia' allocate e la durata in campioni
  180. ***********************************************************************/
  181. ULONG
  182. WavRevert (PCSZ name, LONG argc, const RXSTRING * argv,
  183.        PCSZ queuename, PRXSTRING retstr)
  184. {
  185.   PSHORT pCh = NULL, pChR = NULL;
  186.   SHORT swap;
  187.   ULONG nCamp;
  188.   INT i, j;
  189.   APIRET rc;
  190.  
  191.   if (argc != 2)
  192.     {
  193.       SendMsg (FUNC_REVERT, ERR_NUMERO_PARAMETRI);
  194.       return INVALID_ROUTINE;
  195.     }
  196.  
  197.   if (!sscanf (argv[0].strptr, "%d", &pCh))
  198.     {
  199.       SendMsg (FUNC_REVERT, ERR_PUNTATORE_ERRATO);
  200.       return INVALID_ROUTINE;
  201.     }
  202.  
  203.   nCamp = atol (argv[1].strptr);
  204.   if (!nCamp)
  205.     {
  206.       SendMsg (FUNC_REVERT, ERR_NUMERO_CAMPIONI);
  207.       return INVALID_ROUTINE;
  208.     }
  209.  
  210.   pCh = AllineaCh (pCh, nCamp, FUNC_REVERT);
  211.   if (!pCh)
  212.     return INVALID_ROUTINE;
  213.   pChR = pCh + nCamp;
  214.  
  215.   for (i = (nCamp - 1) / 2; i != 0; i--)
  216.     {
  217.       swap = *pChR;
  218.       *pChR-- = *pCh;
  219.       *pCh++ = swap;
  220.     }
  221.  
  222.  
  223.   sprintf (retstr->strptr, "%i", ERR_OK);
  224.   retstr->strlength = strlen (retstr->strptr);
  225.   return VALID_ROUTINE;
  226. }
  227.  
  228.  
  229.  
  230. /***********************************************************************
  231. Eco:
  232. Vuole il puntatore ad una traccia gia' allocate, la durata in campioni,
  233. il ritardo (in campioni) ed il livello della prima riflessione
  234. ***********************************************************************/
  235. ULONG
  236. WavEco (PCSZ name, LONG argc, const RXSTRING * argv,
  237.     PCSZ queuename, PRXSTRING retstr)
  238. {
  239.   PSHORT pCh, pChR;
  240.   ULONG nCamp, nCampR;
  241.   double livello;
  242.   INT i, j;
  243.   APIRET rc;
  244.  
  245.   if (argc != 4)
  246.     {
  247.       SendMsg (FUNC_ECO, ERR_NUMERO_PARAMETRI);
  248.       return INVALID_ROUTINE;
  249.     }
  250.  
  251.   if (!sscanf (argv[0].strptr, "%d", &pCh))
  252.     {
  253.       SendMsg (FUNC_ECO, ERR_PUNTATORE_ERRATO);
  254.       return INVALID_ROUTINE;
  255.     }
  256.  
  257.   nCamp = atol (argv[1].strptr);
  258.   if (!nCamp)
  259.     {
  260.       SendMsg (FUNC_ECO, ERR_NUMERO_CAMPIONI);
  261.       return INVALID_ROUTINE;
  262.     }
  263.  
  264.   nCampR = atol (argv[2].strptr);
  265.   if (!nCampR)
  266.     {
  267.       SendMsg (FUNC_ECO, ERR_RITARDO_REVERB);
  268.       return INVALID_ROUTINE;
  269.     }
  270.  
  271.   livello = atof (argv[3].strptr);
  272.   if (!nCamp)
  273.     {
  274.       SendMsg (FUNC_ECO, ERR_AMPIEZZA);
  275.       return INVALID_ROUTINE;
  276.     }
  277.  
  278.   pCh = AllineaCh (pCh, nCamp, FUNC_ECO);
  279.   if (!pCh)
  280.     return INVALID_ROUTINE;
  281.   pChR = pCh + nCampR;
  282.  
  283.   for (i = (nCamp - nCampR); i != 0; i--)
  284.     {
  285.       *pChR++ = *pCh++ * livello;
  286.     }
  287.  
  288.  
  289.   sprintf (retstr->strptr, "%i", ERR_OK);
  290.   retstr->strlength = strlen (retstr->strptr);
  291.   return VALID_ROUTINE;
  292. }
  293.