1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
| //+--------------------------------------------------------------------------+
//| |
//| Woofer |
//| BassBox OpenGL plugin |
//| |
//+--------------------------------------------------------------------------+
#include <windows.h>
#include "..\TCLib\math.h"
#include "..\TCLib\Strings.cpp"
#include <gl/GL.h>
#include <gl/GLU.h>
#include "gl2.h"
typedef ULONGLONG QWORD;
#include "BBplugin.h"
#define ExportC extern "C" _declspec (dllexport)
DWORD g_color[34];
float gsR[32], gsG[32], gsB[32];
void bbp_ColorInit() {
g_color[0] = 0;
g_color[1] = bbpARGB(255, 32,32,32);
g_color[2] = bbpARGB(255, 0,44,233);
g_color[3] = bbpARGB(255, 0,67,210);
g_color[4] = bbpARGB(255, 0,89,187);
g_color[5] = bbpARGB(255, 0,112,164);
g_color[6] = bbpARGB(255, 0,135,142);
g_color[7] = bbpARGB(255, 0,159,117);
g_color[8] = bbpARGB(255, 0,183,88);
g_color[9] = bbpARGB(255, 0,207,58);
g_color[10] = bbpARGB(255, 0,231,29);
g_color[11] = bbpARGB(255, 26,234,26);
g_color[12] = bbpARGB(255, 52,237,23);
g_color[13] = bbpARGB(255, 79,240,20);
g_color[14] = bbpARGB(255, 105,243,17);
g_color[15] = bbpARGB(255, 126,245,14);
g_color[16] = bbpARGB(255, 147,248,11);
g_color[17] = bbpARGB(255, 168,250,8);
g_color[18] = bbpARGB(255, 189,253,5);
g_color[19] = bbpARGB(255, 210,255,2);
g_color[20] = bbpARGB(255, 233,255,0);
g_color[21] = bbpARGB(255, 255,255,0);
g_color[22] = bbpARGB(255, 255,251,0);
g_color[23] = bbpARGB(255, 255,235,0);
g_color[24] = bbpARGB(255, 255,215,0);
g_color[25] = bbpARGB(255, 255,196,0);
g_color[26] = bbpARGB(255, 255,176,0);
g_color[27] = bbpARGB(255, 255,156,0);
g_color[28] = bbpARGB(255, 253,137,0);
g_color[29] = bbpARGB(255, 255,117,0);
g_color[30] = bbpARGB(255, 255,97,0);
g_color[31] = bbpARGB(255, 255,78,0);
g_color[32] = bbpARGB(255, 255,58,0);
g_color[33] = bbpARGB(255, 255,0,0);
}
void MakeColorLUT() {
COLORBYTES bytestruct;
for (long K = 0; K < 34; K++) {
MoveMemory(&bytestruct, &g_color[K], sizeof(COLORBYTES));
gsR[K] = (float)(bytestruct.R / 255.0f);
gsG[K] = (float)(bytestruct.G / 255.0f);
gsB[K] = (float)(bytestruct.B / 255.0f);
}
}
ExportC long BBProc (OUT BBPLUGIN &BBP) {
long K, KK, nRet = BBP_SUCCESS;
const float SmoothValue = 0.8f, Cx = -600.0f, Cy = -900.0f, Cz = -150.0f;
float fft[256], SoundBuffer[256], pulse, rAspect;
static BBPTEXTURE mt;
switch (BBP.msg) {
case BBP_RENDER:
pulse = (float) max(BBP.lpeak / 700, BBP.rpeak / 700) / 14.0f;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f, -0.0f, Cz);
glRotatef(Cx, 1.0f, 0.0f, 0.0f);
glRotatef(Cy, 0.0f, 1.0f, 0.0f);
// This is where the magic happens:
// BBP.fftdata returns a pointer to an area of memory containing an array of 256 singles.
MoveMemory(&fft[0], BBP.fftdata, 256 * sizeof(float));
// Try and smooth out the buffer by averaging the last results:
for (K = 0; K < 256; K++) {
// We use SQR to bring out the midtone of the music, otherwise the spectrum is very flat.
SoundBuffer[K] = (float) (sqrt(sqrt(fft[K]) * 2));
}
for (long Direction = -1; Direction < 2; Direction++) {
if (Direction) {
for (KK = 0; KK < 3; KK++) {
K = KK * 16;
if (KK == 0) { K = 2; }
glPushMatrix();
// The iterator K goes from 0 (deepest bass) to 255 (highest treble pitch)
// Ax is the distance from the center. Ay & By are width and height of the flares.
float Ax = (KK * 16) / 128.0f * 125.0f * Direction * pulse;
float Ay = 2 + SoundBuffer[K] * (50.0f + K / 255.0f * 70.0f); // As K increases, the relative size of the signal
float By = 2 + SoundBuffer[K] * (50.0f + K / 255.0f * 70.0f); // drops, so the (K / 255 * 20) compensates by boosting the signal at higher frequencies.
glColor4f(gsR[K] * SoundBuffer[K], gsG[K] * SoundBuffer[K], gsB[K] * SoundBuffer[K] + 0.1f, 0.7f);
glTranslatef(Ax, 0.0f, 0.0f);
glRotatef(Cx, 1.0f, 0.0f, 0.0f);
glRotatef(Cy, 0.0f, 1.0f, 0.0f);
glBegin(GL_QUADS);
glTexCoord2f(0.0f,0.0f); glVertex3f(-By , Ay, 0.0f);
glTexCoord2f(1.0f,0.0f); glVertex3f( By , Ay, 0.0f);
glTexCoord2f(1.0f,1.0f); glVertex3f( By ,-Ay, 0.0f);
glTexCoord2f(0.0f,1.0f); glVertex3f(-By ,-Ay, 0.0f);
glEnd();
glPopMatrix();
}
}
}
// Very important we must reassign BBP.RC to the new BBP.DC
// Note: don't use permanent DC, this produce better and smoother display
wglMakeCurrent(BBP.dc, BBP.rc);
break;
case BBP_CREATE:
// Retrieve plugin details
strcpy(BBP.title, "Woofer");
strcpy(BBP.author, "Patrice Terrier");
BBP.version = MAKEWORD(2, 0); // Version 2.0"
BBP.renderto = BBP_OPENGL; // or BBP_GDIPLUS, or BBP_DIRECTX
break;
case BBP_INIT:
bbp_ColorInit();
glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading
glClearDepth(1.0f); // Depth Buffer Setup
glDisable(GL_DEPTH_TEST); // Disable Depth Buffer
glBlendFunc(GL_ONE, GL_ONE);
glDepthFunc(GL_LESS); // The Type Of Depth Test To Do
glDisable(GL_LIGHTING);
glEnable(GL_BLEND);
glAlphaFunc(GL_GREATER, 0.01f);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glEnable(GL_TEXTURE_2D);
Path_Combine(mt.FullName, TexturePath(), L"boomer.png"); mt.ID = 1; mt.Square = 3;
MakeMultipleTexture(&mt, 1);
MakeColorLUT();
break;
case BBP_SIZE:
// The size of the view port has changed.
RECT rc; GetClientRect(BBP.parent, &rc);
glViewport(0, 0, Width(rc), Height(rc));
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
rAspect = 0.0f;
if (Height(rc)) { rAspect = (float) Width(rc) / (float) Height(rc); }
gluPerspective(50.0f, rAspect, 0.01f, 5000.0f);
glMatrixMode(GL_MODELVIEW);
break;
case BBP_DESTROY:
// Free up your resources there
DestroyTexture (&mt, 1);
break;
default:
nRet = BBP_ERROR;
break;
}
return nRet;
}
BOOL WINAPI DllMain (HINSTANCE hinstDLL, IN DWORD fdwReason, IN LPVOID lpvReserved) {
switch (fdwReason) {
case DLL_PROCESS_ATTACH:
break;
case DLL_PROCESS_DETACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
return TRUE;
} |
Partager