home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Hacker 5
/
HACKER05.ISO
/
Utils
/
Winamp
/
PowerWinAmp.exe
/
Plugins
/
DSPECHO.C
< prev
next >
Wrap
C/C++ Source or Header
|
1997-11-19
|
5KB
|
219 lines
// Winamp test dsp library 0.7
// Copyright (C) 1997, Justin Frankel/Nullsoft
// Feel free to base any plugins on this "framework"...
#include <windows.h>
#include "dsp.h"
short *echo_buf, *echo_buf2;
// "member" functions
winampDSPModule *getModule(int which);
void config(struct winampDSPModule *this_mod);
int init(struct winampDSPModule *this_mod);
int restart(struct winampDSPModule *this_mod);
void quit(struct winampDSPModule *this_mod);
void modify_samples1(struct winampDSPModule *this_mod, short *samples);
void modify_samples2(struct winampDSPModule *this_mod, short *samples);
void modify_samples3(struct winampDSPModule *this_mod, short *samples); // empty
void modify_layer3xr(struct winampDSPModule *this_mod, float xr[2][32][18]);
void modify_layer3xr2(struct winampDSPModule *this_mod, float xr[2][32][18]); // empty
void modify_layer2subband(struct winampDSPModule *this_mod, float subbands[2][32][36]);
void modify_layer2subband2(struct winampDSPModule *this_mod, float subbands[2][32][36]); // empty
// Module header, includes version, description, and address of the module retriever function
winampDSPHeader hdr = { DSP_HDRVER, "Nullsoft Test DSP Library 0.7", getModule };
// first module
winampDSPModule mod =
{
"Test Echo/Reverb",
NULL, // hwndParent
NULL, // hDllInstance
0, // sRate
0, // nCh
0, // blockSize
config,
init,
restart,
modify_samples1,
modify_layer3xr2,
modify_layer2subband2,
quit
};
// second module
winampDSPModule mod2 =
{
"Test Voice Removal (stereo only)",
NULL, // hwndParent
NULL, // hDllInstance
0, // sRate
0, // nCh
0, // blockSize
config,
init,
restart,
modify_samples2,
modify_layer3xr2,
modify_layer2subband2,
quit
};
// third module
winampDSPModule mod3 =
{
"Test Volume Doubler",
NULL, // hwndParent
NULL, // hDllInstance
0, // sRate
0, // nCh
0, // blockSize
config,
init,
restart,
modify_samples3,
modify_layer3xr,
modify_layer2subband,
quit
};
#ifdef __cplusplus
extern "C" {
#endif
// this is the only exported symbol. returns our main header.
__declspec( dllexport ) winampDSPHeader *winampDSPGetHeader()
{
return &hdr;
}
#ifdef __cplusplus
}
#endif
// getmodule routine from the main header. Returns NULL if an invalid module was requested,
// otherwise returns either mod1 or mod2 depending on 'which'.
winampDSPModule *getModule(int which)
{
switch (which)
{
case 0: return &mod;
case 1: return &mod2;
case 2: return &mod3;
default:return NULL;
}
}
// configuration. Passed this_mod, as a "this" parameter. Allows you to make one configuration
// function that shares code for all your modules (you don't HAVE to use it though, you can make
// config1(), config2(), etc...)
void config(struct winampDSPModule *this_mod)
{
MessageBox(this_mod->hwndParent,"This module is Copyright(C) 1997, Justin Frankel/Nullsoft",
"Configuration",MB_OK);
}
int init(struct winampDSPModule *this_mod)
{
return 0;
}
int restart(struct winampDSPModule *this_mod)
{
if (this_mod == &mod)
{
free(echo_buf);
free(echo_buf2);
echo_buf = calloc(this_mod->blockSize*this_mod->nCh*4,sizeof(short));
echo_buf2 = calloc(this_mod->blockSize*this_mod->nCh,sizeof(short));
}
return 0;
}
// cleanup (opposite of init()). Destroys the window, unregisters the window class
void quit(struct winampDSPModule *this_mod)
{
if (this_mod==&mod)
{
free(echo_buf);
free(echo_buf2);
echo_buf = echo_buf2 = 0;
}
}
void modify_samples1(struct winampDSPModule *this_mod, short *samples)
{
int x,s;
s = this_mod->nCh * this_mod->blockSize;
memcpy(echo_buf2, echo_buf, s*2);
memcpy(echo_buf, echo_buf+s, s*2);
memcpy(echo_buf+s, echo_buf+s*2, s*2);
memcpy(echo_buf+s*2,echo_buf+s*3, s*2);
memcpy(echo_buf+s*3,samples, s*2);
for (x = 0; x < s; x ++)
{
int s = samples[x]/2+echo_buf2[x]/2;
samples[x] = (s>32767?32767:s<-32768?-32768:s);
}
}
void modify_samples2(struct winampDSPModule *this_mod, short *samples)
{
int x = this_mod->blockSize;
short *a = samples;
if (this_mod->nCh == 2) while (x--)
{
int l, r;
l = a[1]-a[0];
r = a[0]-a[1];
if (l < -32768) l = -32768;
if (l > 32767) l = 32767;
if (r < -32768) r = -32768;
if (r > 32767) r = 32767;
a[0] = l;
a[1] = r;
a+=2;
}
}
void modify_layer3xr(struct winampDSPModule *this_mod, float xr[2][32][18])
{
int ch, i;
for (ch = 0; ch < this_mod->nCh; ch ++)
for (i = 0; i < 32*18; i ++) xr[ch][0][i] *= 2.0f;
}
void modify_layer2subband(struct winampDSPModule *this_mod, float subbands[2][32][36])
{
int ch, i;
for (ch = 0; ch < this_mod->nCh; ch ++)
for (i = 0; i < 32*18*2; i ++) subbands[ch][0][i] *= 2.0f;
}
void modify_samples3(struct winampDSPModule *this_mod, short *samples)
{
}
void modify_layer3xr2(struct winampDSPModule *this_mod, float xr[2][32][18])
{
}
void modify_layer2subband2(struct winampDSPModule *this_mod, float subbands[2][32][36])
{
}