home *** CD-ROM | disk | FTP | other *** search
/ Cubase Magazine 30 / Issue #30.iso / pc / 2-SOFTWARE / RTEQ 3.0 / SRC / FDT.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  2000-12-08  |  3.9 KB  |  126 lines

  1. /**********************************************************************************
  2. *                                                                                 *
  3. *    FDT.CPP: Transforms the input data into the frequency domain and vice versa  *
  4. *                                                                                 *
  5. *    Copyright (C) 2000  Andrei Grecu                                             *
  6. *                                                                                 *
  7. *    This program is free software; you can redistribute it and/or modify         *
  8. *    it under the terms of the GNU General Public License as published by         *
  9. *    the Free Software Foundation; either version 2 of the License, or            *
  10. *    (at your option) any later version.                                          *
  11. *                                                                                 *
  12. *    This program is distributed in the hope that it will be useful,              *
  13. *    but WITHOUT ANY WARRANTY; without even the implied warranty of               *
  14. *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                *
  15. *    GNU General Public License for more details.                                 *
  16. *                                                                                 *
  17. *    You should have received a copy of the GNU General Public License            *
  18. *    along with this program; if not, write to the Free Software                  *
  19. *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA    *
  20. *                                                                                 *
  21. *    If you have questions, bug reports regarding my code please contact me at:   *
  22. *    andrei.grecu@aon.at                                                          *
  23. *                                                                                 *
  24. *    Home page:                                                                   *
  25. *    http://members.aon.at/grxpage/index.htm                                      *
  26. *                                                                                 *
  27. **********************************************************************************/
  28.  
  29. #include "precomp.h"
  30. #include <windows.h>
  31. #include <math.h>
  32. #include <stdio.h>
  33. #include <rfftw.h>
  34.  
  35. #include "misc.h"
  36. #include "fdt.h"
  37. #include "fftsg.h"
  38.  
  39. ULONG maxn, buflen;
  40.  
  41. HGLOBAL ht, hip, hw;
  42. LPINT ip;
  43. LPDOUBLE t, w;
  44.  
  45. void FDT(const LPSHORT src, const LPCOEF dest) {
  46.     
  47.     ULONG k;
  48.  
  49.     for(k = 0; k < buflen; k++) { 
  50.         dest[k] = src[k];
  51.     }
  52.  
  53.     dest[0] *= 0.5;
  54.  
  55.     //rdft(buflen, 1, dest, ip, w);
  56.     ddct(buflen, -1, dest, ip, w);
  57.  
  58. }
  59.  
  60. void IFDT(const LPCOEF src, const LPSHORT dest) {
  61.  
  62.     ULONG k;
  63.  
  64.     src[0] *= 0.5;
  65.  
  66.     //rdft(buflen, -1, src, ip, w);
  67.     ddct(buflen, 1, src, ip, w);
  68.  
  69.     for(k = 0; k < buflen; k++) { 
  70.         src[k] *= (COEF)2 / buflen;
  71.         if(src[k] > 32767) dest[k] = 32767; 
  72.         else if(src[k] < -32767) dest[k] = -32768;
  73.         else dest[k] = (SHORT) round((FLOAT)src[k]);
  74.     }
  75.  
  76. }
  77.  
  78. // Initializes the DCT matrix
  79. void gen_DCTmatrix(ULONG dwbuflen) {
  80.  
  81.     maxn = (DWORD)(log(buflen) / log(2));
  82.     buflen = dwbuflen;
  83.  
  84.     if(hip) {
  85.         GlobalUnlock(ht);
  86.         GlobalFree(ht);
  87.  
  88.         GlobalUnlock(hip);
  89.         GlobalFree(hip);
  90.  
  91.         GlobalUnlock(hw);
  92.         GlobalFree(hw);
  93.         hip = 0;
  94.     }
  95.  
  96.     ht = GlobalAlloc(GHND, 2*(buflen/2+1) * sizeof(DOUBLE));
  97.     t = (LPDOUBLE) GlobalLock(ht);
  98.  
  99.     hip = GlobalAlloc(GHND, 2+(1<<(int)(log(buflen+0.5)/log(2))/2) * sizeof(INT));
  100.     ip = (LPINT) GlobalLock(hip);
  101.  
  102.     ip[0] = 0;
  103.  
  104.     hw = GlobalAlloc(GHND, buflen*5/4 * sizeof(DOUBLE));
  105.     w = (LPDOUBLE) GlobalLock(hw);
  106.  
  107. }
  108.  
  109. // Destroys the DCT matrix
  110. void destr_DCTmatrix(void) {
  111.  
  112.     if(hip) {
  113.         GlobalUnlock(ht);
  114.         GlobalFree(ht);
  115.  
  116.         GlobalUnlock(hip);
  117.         GlobalFree(hip);
  118.  
  119.         GlobalUnlock(hw);
  120.         GlobalFree(hw);
  121.         hip = 0;
  122.     }
  123.  
  124. }
  125.  
  126.