/* scivi - visualization plugin for XMMS * Copyright (C) 2003 Vitaly V. Bursov * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include "glstuff.h" #include "wave.h" #define C(x) (dyn_data-> x) #define ONE_DIV_512 (1.0f/512.0f) static float sincos_table[512*2]; #if 1 # define SIN(i) (sincos_table[ (((i) & (512-1)) << 1) ]) # define COS(i) (sincos_table[ (((i) & (512-1)) << 1) | 1 ]) #else # define SIN(i) (sincos_table[ ((i) << 1) ]) # define COS(i) (sincos_table[ ((i) << 1) | 1 ]) #endif static void draw_waveform_1(DynamicsData *dyn_data, Gui gui, float waveform[2][512], int begin_type) { int i; float p = 0.0f; sc_glScalef(C(osc_size), 1.0f, 0.0f); sc_glBegin(begin_type); for (i=0; i<512; i+=1, p += ONE_DIV_512){ sc_glVertex2f( p-0.5f, (waveform[0][i] + waveform[1][i]) * 0.5f); } sc_glEnd(); } static void draw_waveform_2(DynamicsData *dyn_data, Gui gui, float waveform[2][512], int begin_type) { int i; float y; float invsize; sc_glScalef(C(osc_size), C(osc_size), 0.0f); sc_glBegin(begin_type); invsize = 1.0f/C(osc_size); for (i=0; i<512; i++){ y = (waveform[0][i] + waveform[1][i]) * 0.5f * invsize; sc_glVertex2f( y*SIN(i), y*COS(i)); } sc_glEnd(); } static void draw_waveform_3(DynamicsData *dyn_data, Gui gui, float waveform[2][512], int begin_type) { int i; float y; float invsize; sc_glScalef(C(osc_size), C(osc_size), 0.0f); sc_glBegin(begin_type); invsize = 1.0f/C(osc_size) * 0.5f * 0.5f; for (i=0; i<512; i++){ y = (waveform[0][i] + waveform[1][i]) * invsize; sc_glVertex2f( (y+0.5f)*SIN(i), (y+0.5f)*COS(i)); } sc_glVertex2f( 0.0f, (y+0.5f)); sc_glEnd(); } static void draw_waveform_4(DynamicsData *dyn_data, Gui gui, float waveform[2][512], int begin_type) { int i; float p = 0.0f; sc_glScalef(C(osc_size), 1.0f, 0.0f); sc_glBegin(begin_type); for (i=0; i<512; i+=1, p += ONE_DIV_512){ sc_glVertex2f( p-0.5f,-C(osc_look_param2) + waveform[0][i]); } sc_glEnd(); p = 0.0f; sc_glBegin(begin_type); for (i=0; i<512; i+=1, p += ONE_DIV_512){ sc_glVertex2f( p-0.5f, C(osc_look_param2) + waveform[1][i]); } sc_glEnd(); } static void draw_waveform_5(DynamicsData *dyn_data, Gui gui, float waveform[2][512], int begin_type) { int i; float p = 0.0f; float y; sc_glScalef(C(osc_size), C(osc_size), 0.0f); sc_glTranslatef(C(osc_look_param2)/C(osc_size), 0.0f, 0.0f); sc_glBegin(begin_type); for (i=0; i<512; i++){ y = waveform[0][i] * 0.5f; sc_glVertex2f((y+0.5f)*SIN(i), (y+0.5f)*COS(i)); } sc_glVertex2f(0.0f, (y+0.5f)); sc_glEnd(); sc_glTranslatef(-2*C(osc_look_param2)/C(osc_size), 0.0f, 0.0f); sc_glBegin(begin_type); for (i=0; i<512; i++){ y = waveform[1][i] * 0.5f; sc_glVertex2f((y+0.5f)*SIN(i), (y+0.5f)*COS(i)); } sc_glVertex2f(0.0f, (y+0.5f)); sc_glEnd(); } int scivi_waveform_init() { unsigned int i; float angle = 0.0f; float s, c, f; /* TODO: another, SIMD-frindly, interlave method */ for (i=0; i<512; i++){ sincosf(angle, &s, &c); sincos_table[i<<1] = s; sincos_table[i<<1 | 1] = c; angle += (1.0f/512.0f) * (2.0f*M_PI); } return 0; } void scivi_waveform_finit() { /* nothing to do */ } void scivi_waveform_draw(DynamicsData *dyn_data, Gui gui, float waveform[2][512]) { int i; int type; void (*waveform_drawers[])(DynamicsData *dyn_data, Gui gui, float waveform[2][512], int begin_type) = { draw_waveform_1, draw_waveform_2, draw_waveform_3, draw_waveform_4, draw_waveform_5, draw_waveform_1, draw_waveform_2, draw_waveform_3, }; if (C(osc_look)) type = GL_LINE_STRIP; else type = GL_POINTS; waveform_drawers[((int)C(osc_type)) & 7](dyn_data, gui, waveform, type); }