uniform sampler2D NotesData; uniform float OverallSoundPosition; uniform float ThisSoundLength; #define NOTES 36 #define BASEFREQ 40. #define FREQ 150. float saw(float time) { //works in the same time domain as GLSL sine float x = mod(time, 6.28318531) / 3.14159265; return x - 1.; } float triangle(float time) { //works in the same time domain as GLSL sine float x = mod(time, 6.28318531) / 3.14159265; float f = floor(x); x = (x*(1.-f)) + ((2.-x)*f); return (x*2.)-1.; } void main() { int i; float fvol = 0.; float TimeSample = gl_TexCoord[0].y * ThisSoundLength + OverallSoundPosition; float channel = gl_TexCoord[0].x; //this is a bad way to add voices together. it gets very loud!!!! for( i = 0; i < NOTES; i++ ) { float noteA = texture2D( NotesData, vec2( i/NOTES, 0.0 ) ).r; float noteB = texture2D( NotesData, vec2( i/NOTES, 0.5 ) ).r; float freq = pow( 2., float(i)/12. ) * BASEFREQ; fvol += sin( freq * TimeSample ); } //frequency modulation float fcar = 6.28318531 * FREQ * TimeSample; float fmod = 6.28318531 * FREQ * 1.5 * TimeSample; fvol = 1. * sin(fcar + 2.2449 *sin(fmod)); gl_FragColor = vec4( fvol ); }