small size optimization in play.c
authorslack <slack@codemaniacs.com>
Mon, 15 Jun 2009 15:42:22 +0000 (17:42 +0200)
committerslack <slack@codemaniacs.com>
Mon, 15 Jun 2009 15:51:10 +0000 (17:51 +0200)
play.c

diff --git a/play.c b/play.c
index 3431837f2c3ce6d65632e8d234f842ad9076ad7f..21acb61a55958ab8ea86a96b127f3d76cb04b1a8 100644 (file)
--- a/play.c
+++ b/play.c
@@ -8,7 +8,7 @@
 
 #define NUM_VOICES 1 
 
-float row_duration=60.0/360.0; // denominator == RPM
+float row_duration=60.0f/360.0f; // denominator == RPM
 Voice voices[NUM_VOICES];
 float mix_buf[BUFFER_SIZE]={0};
 uint8  last_voice_used=0;
@@ -27,15 +27,15 @@ void play(void *s, uint8 *stream, int len)
 
     memset(mix_buf, 0, BUFFER_SIZE*sizeof(float));
 
-    if ((current_time - rows_played * row_duration) > row_duration ) {
+    float time_since_last_row_played = current_time - rows_played * row_duration;
+    if (time_since_last_row_played > row_duration ) {
         ++rows_played;
-        ++cur_row;
-        int buf_start = ((current_time - rows_played * row_duration)*SAMPLE_RATE)-num_samples;
+        cur_row = (cur_row+1)%TRACK_LENGTH;
+        if (!cur_row) ++cur_pos;
+
+        int buf_start = ((time_since_last_row_played+row_duration)*SAMPLE_RATE)-num_samples;
+
 
-        if (cur_row == TRACK_LENGTH) { // end of track
-            cur_row=0;
-            ++cur_pos;
-        }
         if (song->playlist[cur_pos]==255) { // loop at end of song
             cur_pos=0;
         }