home *** CD-ROM | disk | FTP | other *** search
/ Hacker 5 / HACKER05.ISO / Utils / Winamp / PowerWinAmp.exe / Plugins / DSPECHO.C < prev    next >
C/C++ Source or Header  |  1997-11-19  |  5KB  |  219 lines

  1. // Winamp test dsp library 0.7
  2. // Copyright (C) 1997, Justin Frankel/Nullsoft
  3. // Feel free to base any plugins on this "framework"...
  4.  
  5. #include <windows.h>
  6.  
  7. #include "dsp.h"
  8.  
  9. short *echo_buf, *echo_buf2;
  10.  
  11. // "member" functions
  12. winampDSPModule *getModule(int which);
  13.  
  14. void config(struct winampDSPModule *this_mod);
  15. int init(struct winampDSPModule *this_mod);
  16. int restart(struct winampDSPModule *this_mod);
  17. void quit(struct winampDSPModule *this_mod);
  18.  
  19. void modify_samples1(struct winampDSPModule *this_mod, short *samples);
  20. void modify_samples2(struct winampDSPModule *this_mod, short *samples);
  21. void modify_samples3(struct winampDSPModule *this_mod, short *samples); // empty
  22.  
  23. void modify_layer3xr(struct winampDSPModule *this_mod, float xr[2][32][18]);
  24. void modify_layer3xr2(struct winampDSPModule *this_mod, float xr[2][32][18]); // empty
  25.  
  26. void modify_layer2subband(struct winampDSPModule *this_mod, float subbands[2][32][36]);
  27. void modify_layer2subband2(struct winampDSPModule *this_mod, float subbands[2][32][36]); // empty
  28.  
  29.  
  30. // Module header, includes version, description, and address of the module retriever function
  31. winampDSPHeader hdr = { DSP_HDRVER, "Nullsoft Test DSP Library 0.7", getModule };
  32.  
  33. // first module
  34. winampDSPModule mod =
  35. {
  36.     "Test Echo/Reverb",
  37.     NULL,    // hwndParent
  38.     NULL,    // hDllInstance
  39.     0,        // sRate
  40.     0,        // nCh
  41.     0,        // blockSize
  42.     config,
  43.     init,
  44.     restart,
  45.     modify_samples1,
  46.     modify_layer3xr2,
  47.     modify_layer2subband2,
  48.     quit
  49. };
  50.  
  51.  
  52. // second module
  53. winampDSPModule mod2 =
  54. {
  55.     "Test Voice Removal (stereo only)",
  56.     NULL,    // hwndParent
  57.     NULL,    // hDllInstance
  58.     0,        // sRate
  59.     0,        // nCh
  60.     0,        // blockSize
  61.     config,
  62.     init,
  63.     restart,
  64.     modify_samples2,
  65.     modify_layer3xr2,
  66.     modify_layer2subband2,
  67.     quit
  68. };
  69.  
  70. // third module
  71. winampDSPModule mod3 =
  72. {
  73.     "Test Volume Doubler",
  74.     NULL,    // hwndParent
  75.     NULL,    // hDllInstance
  76.     0,        // sRate
  77.     0,        // nCh
  78.     0,        // blockSize
  79.     config,
  80.     init,
  81.     restart,
  82.     modify_samples3,
  83.     modify_layer3xr,
  84.     modify_layer2subband,
  85.     quit
  86. };
  87.  
  88.  
  89. #ifdef __cplusplus
  90. extern "C" {
  91. #endif
  92. // this is the only exported symbol. returns our main header.
  93. __declspec( dllexport ) winampDSPHeader *winampDSPGetHeader()
  94. {
  95.     return &hdr;
  96. }
  97. #ifdef __cplusplus
  98. }
  99. #endif
  100.  
  101. // getmodule routine from the main header. Returns NULL if an invalid module was requested,
  102. // otherwise returns either mod1 or mod2 depending on 'which'.
  103. winampDSPModule *getModule(int which)
  104. {
  105.     switch (which)
  106.     {
  107.         case 0: return &mod;
  108.         case 1: return &mod2;
  109.         case 2: return &mod3;
  110.         default:return NULL;
  111.     }
  112. }
  113.  
  114. // configuration. Passed this_mod, as a "this" parameter. Allows you to make one configuration
  115. // function that shares code for all your modules (you don't HAVE to use it though, you can make
  116. // config1(), config2(), etc...)
  117. void config(struct winampDSPModule *this_mod)
  118. {
  119.     MessageBox(this_mod->hwndParent,"This module is Copyright(C) 1997, Justin Frankel/Nullsoft",
  120.                                     "Configuration",MB_OK);
  121. }
  122.  
  123. int init(struct winampDSPModule *this_mod)
  124. {
  125.     return 0;
  126. }
  127.  
  128. int restart(struct winampDSPModule *this_mod)
  129. {
  130.     if (this_mod == &mod)
  131.     {
  132.         free(echo_buf);
  133.         free(echo_buf2);
  134.         echo_buf = calloc(this_mod->blockSize*this_mod->nCh*4,sizeof(short));
  135.         echo_buf2 = calloc(this_mod->blockSize*this_mod->nCh,sizeof(short));
  136.     }
  137.     return 0;
  138. }
  139.  
  140.  
  141. // cleanup (opposite of init()). Destroys the window, unregisters the window class
  142. void quit(struct winampDSPModule *this_mod)
  143. {
  144.     if (this_mod==&mod)
  145.     {
  146.         free(echo_buf);
  147.         free(echo_buf2);
  148.         echo_buf = echo_buf2 = 0;
  149.     }
  150. }
  151.  
  152. void modify_samples1(struct winampDSPModule *this_mod, short *samples)
  153. {
  154.     int x,s;
  155.     s = this_mod->nCh * this_mod->blockSize;
  156.     
  157.     memcpy(echo_buf2,    echo_buf,    s*2);
  158.     memcpy(echo_buf,    echo_buf+s,    s*2);
  159.     memcpy(echo_buf+s,    echo_buf+s*2, s*2);
  160.     memcpy(echo_buf+s*2,echo_buf+s*3, s*2);
  161.     memcpy(echo_buf+s*3,samples, s*2);
  162.  
  163.     for (x = 0; x < s; x ++)
  164.     {
  165.         int s = samples[x]/2+echo_buf2[x]/2;
  166.         samples[x] = (s>32767?32767:s<-32768?-32768:s);
  167.     }
  168.  
  169. }
  170.  
  171. void modify_samples2(struct winampDSPModule *this_mod, short *samples)
  172. {
  173.     int x = this_mod->blockSize;
  174.     short *a = samples;
  175.     if (this_mod->nCh == 2) while (x--)
  176.     {
  177.         int l, r;
  178.         l = a[1]-a[0];
  179.         r = a[0]-a[1];        
  180.         if (l < -32768) l = -32768;
  181.         if (l > 32767) l = 32767;
  182.         if (r < -32768) r = -32768;
  183.         if (r > 32767) r = 32767;
  184.         a[0] = l;
  185.         a[1] = r;
  186.         a+=2;
  187.     }
  188. }
  189.  
  190.  
  191.  
  192. void modify_layer3xr(struct winampDSPModule *this_mod, float xr[2][32][18])
  193. {
  194.     int ch, i;
  195.     for (ch = 0; ch < this_mod->nCh; ch ++)
  196.         for (i = 0; i < 32*18; i ++) xr[ch][0][i] *= 2.0f;
  197. }
  198.  
  199. void modify_layer2subband(struct winampDSPModule *this_mod, float subbands[2][32][36])
  200. {
  201.     int ch, i;
  202.     for (ch = 0; ch < this_mod->nCh; ch ++)
  203.         for (i = 0; i < 32*18*2; i ++) subbands[ch][0][i] *= 2.0f;
  204. }
  205.  
  206.  
  207.  
  208. void modify_samples3(struct winampDSPModule *this_mod, short *samples)
  209. {
  210. }
  211.  
  212. void modify_layer3xr2(struct winampDSPModule *this_mod, float xr[2][32][18])
  213. {
  214. }
  215.  
  216. void modify_layer2subband2(struct winampDSPModule *this_mod, float subbands[2][32][36])
  217. {
  218. }
  219.