Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

hairtunes: simplify and reorganize some floating point operations

The math operations are all equivalent, but are simplified a bit for the
benefit of processors with slower floating point performance.

* Don't use float casts when we need to eventually convert to double
  precision anyway.
* Use multiplication instead of division when possible.
  • Loading branch information...
commit fa95439b985552a134ee84274ea343baf4f9ba8e 1 parent f12f7a7
Dan McGee toofishes authored

Showing 1 changed file with 2 additions and 2 deletions. Show diff stats Hide diff stats

  1. +2 2 hairtunes.c
4 hairtunes.c
@@ -575,7 +575,7 @@ static void biquad_init(biquad_t *bq, double a[], double b[]) {
575 575 }
576 576
577 577 static void biquad_lpf(biquad_t *bq, double freq, double Q) {
578   - double w0 = 2*M_PI*freq/((float)sampling_rate/(float)frame_size);
  578 + double w0 = 2.0 * M_PI * freq * frame_size / (double)sampling_rate;
579 579 double alpha = sin(w0)/(2.0*Q);
580 580
581 581 double a_0 = 1.0 + alpha;
@@ -706,7 +706,7 @@ static int stuff_buffer(double playback_rate, short *inptr, short *outptr) {
706 706
707 707 p_stuff = 1.0 - pow(1.0 - fabs(playback_rate-1.0), frame_size);
708 708
709   - if ((float)rand()/((float)RAND_MAX) < p_stuff) {
  709 + if (rand() < p_stuff * RAND_MAX) {
710 710 stuff = playback_rate > 1.0 ? -1 : 1;
711 711 stuffsamp = rand() % (frame_size - 1);
712 712 }

0 comments on commit fa95439

Please sign in to comment.
Something went wrong with that request. Please try again.