home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Multimed / Multimed.zip / rxwavsrc.zip / RxWavSeek.c < prev    next >
C/C++ Source or Header  |  2000-03-06  |  2KB  |  85 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. Seek/find
  30. Vuole il puntatore ad una traccia e la soglia da trovare
  31. restituisce l'offset del primo campione superiore alla soglia
  32. ***********************************************************************/
  33. ULONG
  34. WavSeek (PCSZ name, LONG argc, const RXSTRING * argv,
  35.      PCSZ queuename, PRXSTRING retstr)
  36. {
  37.   PSHORT pCh = NULL;
  38.   ULONG nCamp, i;
  39.   SHORT c;
  40.   double max;
  41.   APIRET rc;
  42.  
  43.   if (argc != 3)
  44.     {
  45.       SendMsg (FUNC_SEEK, ERR_NUMERO_PARAMETRI);
  46.       return INVALID_ROUTINE;
  47.     }
  48.  
  49.   if (!sscanf (argv[0].strptr, "%d", &pCh))
  50.     {
  51.       SendMsg (FUNC_SEEK, ERR_PUNTATORE_ERRATO);
  52.       return INVALID_ROUTINE;
  53.     }
  54.  
  55.   nCamp = atol (argv[1].strptr);
  56.   if (nCamp < 1)
  57.     {
  58.       SendMsg (FUNC_SEEK, ERR_VALORE_INVALIDO);
  59.       return INVALID_ROUTINE;
  60.     }
  61.  
  62.   max = atof (argv[2].strptr);
  63.   if ((max < -1) | (max > 1))
  64.     {
  65.       SendMsg (FUNC_SEEK, ERR_VALORE_INVALIDO);
  66.       return INVALID_ROUTINE;
  67.     }
  68.  
  69.   pCh = AllineaCh (pCh, nCamp, FUNC_SEEK);
  70.   if (!pCh)
  71.     return INVALID_ROUTINE;
  72.  
  73.   c = max * MAX_CAMPIONE;
  74.   for (i = 0; i < nCamp; i++)
  75.     {
  76.       if (abs (*pCh) > c)
  77.     i = nCamp;
  78.       pCh++;
  79.     }
  80.  
  81.   sprintf (retstr->strptr, "%d", ((long) pCh / 2));
  82.   retstr->strlength = strlen (retstr->strptr);
  83.   return VALID_ROUTINE;
  84. }
  85.