home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Multimed / Multimed.zip / rxwavsrc.zip / RxWavMain.c < prev    next >
C/C++ Source or Header  |  2000-03-06  |  6KB  |  231 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 "RxWav.h"
  25.  
  26. static void
  27. regfun (PCSZ name)
  28. {
  29.   RexxRegisterFunctionDll (name, "RxWav", name);
  30. }
  31.  
  32. static void
  33. deregfun (PCSZ name)
  34. {
  35.   RexxDeregisterFunction (name);
  36. }
  37.  
  38.  
  39. ULONG
  40. WavLoadFuncs (PCSZ name, LONG argc, const RXSTRING * argv,
  41.           PCSZ queuename, PRXSTRING retstr)
  42. {
  43.   INT entries;
  44.   INT j;
  45.   retstr->strlength = 0;
  46.   if (argc != 0)
  47.     {
  48.       SendMsg (FUNC_LOAD_FUNCS, ERR_NUMERO_PARAMETRI);
  49.       return INVALID_ROUTINE;
  50.     }
  51.  
  52.   printf ("RxWav. 6 Marzo 2000.        [beta 0.09]\n");
  53.   printf ("       http://www.geocities.com/katobleto\n");
  54.   printf ("       mailto:katobleto@geocities.com\n");
  55.  
  56.   entries = sizeof (RxWavFunc) / sizeof (PSZ);
  57.  
  58.   for (j = 0; j < entries; j++)
  59.     regfun (RxWavFunc[j]);
  60.  
  61.   return 0;
  62. }
  63.  
  64. ULONG
  65. WavDropFuncs (PCSZ name, LONG argc, const RXSTRING * argv,
  66.           PCSZ queuename, PRXSTRING retstr)
  67. {
  68.   INT entries;
  69.   INT j;
  70.  
  71.   retstr->strlength = 0;
  72.   if (argc != 0)
  73.     return 1;
  74.  
  75.   entries = sizeof (RxWavFunc) / sizeof (PSZ);
  76.  
  77.   for (j = 0; j < entries; j++)
  78.     deregfun (RxWavFunc[j]);
  79.  
  80.   printf ("RxWav.  drop!\n");
  81.   return 0;
  82. }
  83.  
  84.  
  85. void
  86. regerror (const char *s)
  87. {
  88. }
  89.  
  90. /***********************************************************************
  91. Alloca una traccia di lavoro in memoria.
  92. Richiede in input il numero di campioni a 16 bit e restituisce il
  93. puntatore all'area nel formato "puntatore"
  94. ***********************************************************************/
  95. ULONG
  96. WavAllocTrac (PCSZ name, LONG argc, const RXSTRING * argv,
  97.           PCSZ queuename, PRXSTRING retstr)
  98. {
  99.   LONG nCampioni;
  100.   PVOID pCh = NULL;
  101.   APIRET ulrc;
  102.  
  103.   if (argc != 1)
  104.     {
  105.       SendMsg (FUNC_ALLOC_TRAC, ERR_NUMERO_PARAMETRI);
  106.       return INVALID_ROUTINE;
  107.     }
  108.  
  109.   if (!string2long (argv[0].strptr, &nCampioni) || nCampioni < 0)
  110.     {
  111.       SendMsg (FUNC_ALLOC_TRAC, ERR_NUMERO_CAMPIONI);
  112.       return INVALID_ROUTINE;
  113.     }
  114.  
  115.   nCampioni = nCampioni * 2 + 32768;
  116.   ulrc = DosAllocMem (&pCh, nCampioni, PAG_COMMIT | PAG_WRITE);
  117.   if (ulrc)
  118.     {
  119.       SendMsg (FUNC_ALLOC_TRAC, ERR_DOSALLOCMEM);
  120.       printf ("       rc:%d\n", ulrc);
  121.       return INVALID_ROUTINE;
  122.     }
  123.  
  124.   sprintf (retstr->strptr, "%d", ((long) pCh / 2));
  125.   retstr->strlength = strlen (retstr->strptr);
  126.   return VALID_ROUTINE;
  127. }
  128.  
  129.  
  130. /***********************************************************************
  131. Libera dalla memoria una traccia di lavoro.
  132. Richiede in input il puntatore all'area da rilasciare.
  133. Funziona?
  134. ***********************************************************************/
  135. ULONG
  136. WavDropTrac (PCSZ name, LONG argc, const RXSTRING * argv,
  137.          PCSZ queuename, PRXSTRING retstr)
  138. {
  139.   PVOID pCh = NULL;
  140.   APIRET ulrc;
  141.  
  142.   if (argc != 1)
  143.     {
  144.       SendMsg (FUNC_DROP_TRAC, ERR_NUMERO_PARAMETRI);
  145.       return INVALID_ROUTINE;
  146.     }
  147.  
  148.   if (!sscanf (argv[0].strptr, "%d", &pCh))
  149.     {
  150.       SendMsg (FUNC_DROP_TRAC, ERR_PUNTATORE_ERRATO);
  151.       return INVALID_ROUTINE;
  152.     }
  153.  
  154.   pCh = AllineaCh (pCh, (ULONG) 2, FUNC_DROP_TRAC);
  155.   ulrc = DosFreeMem (pCh);
  156.   if (ulrc)
  157.     {
  158.       SendMsg (FUNC_DROP_TRAC, ERR_DOSFREEMEM);
  159.       printf ("%d\n", ulrc);
  160.       return INVALID_ROUTINE;
  161.     }
  162.  
  163.   sprintf (retstr->strptr, "%d", ((long) pCh / 2));
  164.   retstr->strlength = strlen (retstr->strptr);
  165.   return VALID_ROUTINE;
  166. }
  167.  
  168.  
  169. /***********************************************************************
  170. Aquisisce le informazioni sul file wav.
  171. Se il file e' nel formato corretto restituisce:
  172. - numero di canali
  173. - frequenza di campionamento
  174. - risoluzione in bit
  175. - numero di campioni
  176. altrimenti "NOWAV"
  177. ***********************************************************************/
  178. ULONG
  179. WavQueryFile (PCSZ name, LONG argc, const RXSTRING * argv,
  180.           PCSZ queuename, PRXSTRING retstr)
  181. {
  182.   FILE *StereoFile;
  183.   UCHAR NomeFile[256];
  184.   struct wav DatiWAV;
  185.   APIRET rc;
  186.  
  187.   if (argc != 1)
  188.     {
  189.       SendMsg (FUNC_QUERY_FILE, ERR_NUMERO_PARAMETRI);
  190.       return INVALID_ROUTINE;
  191.     }
  192.  
  193.   strcpy (NomeFile, argv[0].strptr);
  194.  
  195.   if ((StereoFile = fopen (NomeFile, "rb")) == NULL)
  196.     {
  197.       SendMsg (FUNC_QUERY_FILE, ERR_OPEN_FILE);
  198.       sprintf (retstr->strptr, "%i", ERR_OPEN_FILE);
  199.       retstr->strlength = strlen (retstr->strptr);
  200.       return VALID_ROUTINE;
  201.     }
  202.  
  203.   if (!(fread (&DatiWAV, sizeof (struct wav), 1, StereoFile)))
  204.     {
  205.       SendMsg (FUNC_QUERY_FILE, ERR_READ_WAV_STRUCT);
  206.       sprintf (retstr->strptr, "%i", ERR_READ_WAV_STRUCT);
  207.       retstr->strlength = strlen (retstr->strptr);
  208.       return VALID_ROUTINE;
  209.     }
  210.  
  211.   rc = fclose (StereoFile);
  212.   if (rc)
  213.     {
  214.       SendMsg (FUNC_QUERY_FILE, ERR_CLOSE_FILE);
  215.       return INVALID_ROUTINE;
  216.     }
  217.  
  218.   if (strncmp (DatiWAV.w_riff, "RIFF", 4) & strncmp (DatiWAV.w_wave, "WAVE", 4))
  219.     sprintf (retstr->strptr, "%s", "NOWAV");
  220.   else
  221.     sprintf (retstr->strptr, "%d %d %d %d",
  222.          DatiWAV.w_stereo,
  223.          DatiWAV.w_freq_camp,
  224.          DatiWAV.w_bit_camp,
  225.          DatiWAV.w_len_data / (DatiWAV.w_bit_camp / 8) / DatiWAV.w_stereo
  226.       );
  227.  
  228.   retstr->strlength = strlen (retstr->strptr);
  229.   return VALID_ROUTINE;
  230. }
  231.