home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 Secrets / Secrets2.iso / Audio / WAV / MaplayP / _SETUP.1 / synfilt.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-21  |  2.5 KB  |  85 lines

  1. /*
  2.  *  @(#) synthesis_filter.h 1.8, last edit: 6/15/94 16:52:00
  3.  *  @(#) Copyright (C) 1993, 1994 Tobias Bading (bading@cs.tu-berlin.de)
  4.  *  @(#) Berlin University of Technology
  5.  *
  6.  *  This program is free software; you can redistribute it and/or modify
  7.  *  it under the terms of the GNU General Public License as published by
  8.  *  the Free Software Foundation; either version 2 of the License, or
  9.  *  (at your option) any later version.
  10.  *
  11.  *  This program is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  *  GNU General Public License for more details.
  15.  *
  16.  *  You should have received a copy of the GNU General Public License
  17.  *  along with this program; if not, write to the Free Software
  18.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. #ifndef SYNTHESIS_FILTER_H
  22. #define SYNTHESIS_FILTER_H
  23.  
  24. #include "all.h"
  25. #include "obuffer.h"
  26.  
  27.  
  28. // A class for the synthesis filter bank:
  29. // This class does a fast downsampling from 32, 44.1 or 48 kHz to 8 kHz, if ULAW is defined.
  30. // Frequencies above 4 kHz are removed by ignoring higher subbands.
  31. class SynthesisFilter
  32. {
  33.   static const real d[512];
  34.   real v1[512], v2[512];
  35.   real *actual_v;            // v1 or v2
  36.   uint32 actual_write_pos;        // 0-15
  37.  
  38.   real    samples[32];            // 32 new subband samples
  39.  
  40.   uint32 channel;
  41.   real    scalefactor;
  42.  
  43.   void compute_new_v();
  44.   void compute_pcm_samples(Obuffer *buffer);
  45.  
  46.   // Clips the pcm sample so it will fit in 16 bits
  47. #ifdef TRUNC_ROUNDING
  48.  
  49.   inline int16 clip(real sample)
  50.   {
  51.       return ((sample > 32767.0f) ? 32767 :
  52.            ((sample < -32768.0f) ? -32768 :
  53.            ((sample < 0.0f) ? -((int16) (-sample + 0.5f))
  54.                                    :   (int16) ( sample + 0.5f)) ));
  55.   }
  56.  
  57. #else
  58.  
  59.   inline int16 clip(real sample)
  60.   {
  61.       return ((sample > 32767.0f) ? 32767 :
  62.            ((sample < -32768.0f) ? -32768 :
  63.               (int16) sample));
  64.   }
  65. #endif // TRUNC_ROUNDING
  66.  
  67. public:
  68.   SynthesisFilter(uint32 channelnumber, real scalefactor = 32768.0);
  69.       // the scalefactor scales the calculated float pcm samples to short values
  70.       // (raw pcm samples are in [-1.0, 1.0], if no violations occur)
  71.  
  72.   void    input_sample(real sample, uint32 subbandnumber)
  73.   {
  74.      samples[subbandnumber] = sample;
  75.   };
  76.  
  77.   void    calculate_pcm_samples(Obuffer *buffer);
  78.     // calculate 32 PCM samples and put the into the Obuffer-object
  79.  
  80.   void   reset();
  81.   // reset the synthesis filter
  82. };
  83.  
  84. #endif
  85.