-//#define RANDOM_BIRD
-//#define SINE_ACCURATE
-
-#ifdef SINE_ACCURATE
-static float sine_44100_1( int o )
-{
- float t = (float)o*(1.0f/44100.0f);
- return sinf(t*6.28318530717958647692528676655900576);
-}
-
-static void sine_44100_4( int o[4], float v[4] )
-{
- v[0] = sine_44100_1( o[0] );
- v[1] = sine_44100_1( o[1] );
- v[2] = sine_44100_1( o[2] );
- v[3] = sine_44100_1( o[3] );
-}
-#else
-
-/* sine functions over the range [0, 44100] : [-pi, pi].
- * Not accurate! */
-
-static float sine_44100_1( int o )
-{
- float s = (o<22050)?-1.0f:1.0f;
- float t = ((float)o*(1.0f/22050.0f))-1.0f - s*0.5f;
- float t2 = t*t;
- float t4 = t2*t2;
- return s*(5.0f*t2-4.0f*t4-1.0f);
-}
-
-static void sine_44100_4( int o[4], float v[4] )
-{
- float s[4],t[4],t2[4],t4[4];
- s[0] = (o[0]<22050)?-1.0f:1.0f;
- s[1] = (o[1]<22050)?-1.0f:1.0f;
- s[2] = (o[2]<22050)?-1.0f:1.0f;
- s[3] = (o[3]<22050)?-1.0f:1.0f;
-
- t[0] = ((float)o[0]*(1.0f/22050.0f))-1.0f - s[0]*0.5f;
- t[1] = ((float)o[1]*(1.0f/22050.0f))-1.0f - s[1]*0.5f;
- t[2] = ((float)o[2]*(1.0f/22050.0f))-1.0f - s[2]*0.5f;
- t[3] = ((float)o[3]*(1.0f/22050.0f))-1.0f - s[3]*0.5f;
-
- t2[0] = t[0]*t[0];
- t2[1] = t[1]*t[1];
- t2[2] = t[2]*t[2];
- t2[3] = t[3]*t[3];
-
- t4[0] = t2[0]*t2[0];
- t4[1] = t2[1]*t2[1];
- t4[2] = t2[2]*t2[2];
- t4[3] = t2[3]*t2[3];
-
- v[0] = s[0]*(5.0f*t2[0]-4.0f*t4[0]-1.0f);
- v[1] = s[1]*(5.0f*t2[1]-4.0f*t4[1]-1.0f);
- v[2] = s[2]*(5.0f*t2[2]-4.0f*t4[2]-1.0f);
- v[3] = s[3]*(5.0f*t2[3]-4.0f*t4[3]-1.0f);
-}
-#endif
-
-static float saw_44100_1( int o )
-{
- float t = ((float)o*(1.0f/22050.0f))-1.0f,
- tt = t*t,
- ttt = tt*t;
-
- return -2.5f*ttt+2.5f*t;
-}
-
-static double rand_float( double min, double max )
-{
- double r = (double)(rand()&(4096-1))*(1.0/4096.0);
- return min + r*(max-min);
-}
-
-static int rand_seconds( double min, double max )
-{
- return rand_float( min*44100.0, max*44100.0 );
-}
-