home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / ste / wave_20 / dsp.c next >
C/C++ Source or Header  |  1993-07-30  |  3KB  |  111 lines

  1. /*
  2.    This function performs resampling of 8 bit monoral
  3.    PCM samples. The result is placed into the destination
  4.    pointer. The pointer is returned to allow it to be used to
  5.    concatinate multiple segments of data from the same, and or
  6.    different PCM samples. The routine assumes that the 8 bit source
  7.    samples are in MicroSoft Corporation (MSC), unsigned char, 
  8.    WAVE format. And the destination of in Atari, signed char,
  9.    PCM format.
  10.  
  11.   Change History:
  12.  
  13.   11/25/92    Changed floating point to fixed point
  14.   07/30/93  Corrected calculation of "delta" to be cast
  15.             to a fixed point number.
  16. */
  17.  
  18. #include "riff.h"
  19. #include "fixed.h"
  20.  
  21. void Resample8bitMono(PCM_Samples *Dest,
  22.                       PCM_Samples *Src,
  23.                       unsigned long Dest_Sample_Rate,
  24.                       unsigned long Src_Sample_Rate)
  25. {
  26. Fixed         delta ;
  27. Fixed         offset ;
  28.  
  29.   delta = fl_fp((double)Src_Sample_Rate/(double)Dest_Sample_Rate) ;
  30.   offset = 0 ;
  31.   while (Dest_Sample_Rate--)
  32.   {
  33.     *Dest->Mono8++ = (unsigned char)((char)Src->Mono8[fp_long(offset)] - 128 ) ;
  34.     offset += delta ;
  35.   }
  36.   return ;
  37. }
  38.  
  39. void Resample16bitMono(PCM_Samples *Dest,
  40.                        PCM_Samples *Src,
  41.                        unsigned long Dest_Sample_Rate,
  42.                        unsigned long Src_Sample_Rate)
  43. {
  44. Fixed         delta ;
  45. Fixed         offset ;
  46.  
  47.   offset = 0 ;
  48. /* 
  49.  *  adjust for bytes per sample 
  50.  */
  51.   Src_Sample_Rate = Src_Sample_Rate / 2l ;
  52.  
  53.   delta = fl_fp((double)Src_Sample_Rate/(double)Dest_Sample_Rate) ;
  54.   while (Dest_Sample_Rate--)
  55.   {
  56.     *Dest->Mono8++ = Src->Mono16[fp_long(offset)].upper ;
  57.     offset += delta ;
  58.   }
  59.   return ;
  60. }
  61.  
  62. void Resample8bitStereo(PCM_Samples *Dest,
  63.                         PCM_Samples *Src,
  64.                         unsigned long Dest_Sample_Rate,
  65.                         unsigned long Src_Sample_Rate)
  66. {
  67. Fixed         delta ;
  68. Fixed         offset ;
  69.  
  70.   offset = 0 ;
  71.   delta = fl_fp((double)Src_Sample_Rate/(double)Dest_Sample_Rate) ;
  72. /* 
  73.  *  adjust for stereo sample 
  74.  */
  75.   Dest_Sample_Rate = Dest_Sample_Rate / 2l ;
  76.   while (Dest_Sample_Rate--)
  77.   {
  78.     (*Dest->Stereo8).left  = (unsigned char)((char)Src->Stereo8[fp_long(offset)].left - 128 ) ;
  79.     (*Dest->Stereo8).right = (unsigned char)((char)Src->Stereo8[fp_long(offset)].right - 128 ) ;
  80.     offset += delta ;
  81.     Dest->Stereo8++ ;
  82.   }
  83.   return ;
  84. }
  85.  
  86. void Resample16bitStereo(PCM_Samples *Dest,
  87.                          PCM_Samples *Src,
  88.                          unsigned long Dest_Sample_Rate,
  89.                          unsigned long Src_Sample_Rate)
  90. {
  91. Fixed         delta ;
  92. Fixed         offset ;
  93.  
  94.   offset = 0 ;
  95. /* 
  96.  *  adjust for bytes per sample 
  97.  */
  98.   Src_Sample_Rate = Src_Sample_Rate / 2l ;
  99.  
  100.   delta = fl_fp((double)Src_Sample_Rate/(double)Dest_Sample_Rate) ;
  101.   while (Dest_Sample_Rate--)
  102.   {
  103.     (*Dest->Stereo8).left  = Src->Stereo16[fp_long(offset)].left.upper ;
  104.     (*Dest->Stereo8).right = Src->Stereo16[fp_long(offset)].right.upper ;
  105.     offset += delta ;
  106.     Dest->Stereo8++ ;
  107.   }
  108.   return ;
  109. }
  110.  
  111.