changeset 37:561fa061caf6

Fix the audio rendering callback function, etc.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 24 May 2010 02:18:39 +0300
parents d803c129c1e2
children 678924af9149
files pwpzax/zaxplay.c
diffstat 1 files changed, 8 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/pwpzax/zaxplay.c	Mon May 24 01:23:01 2010 +0300
+++ b/pwpzax/zaxplay.c	Mon May 24 02:18:39 2010 +0300
@@ -165,7 +165,7 @@
 void player_set_tempo(int tempo)
 {
    player.tempo = tempo;
-   player.frag = (player.freq) / 30;
+   player.frag = (player.freq * tempo) / 73;
 }
 
 void player_newnote()
@@ -200,31 +200,20 @@
    }
 }
 
-void player_tick(void)
-{
-   if (player.tick == 0)
-       player_newnote();
-
-   player.tick++;
-   if (player.tick >= player.tempo)
-       player.tick=0;
-}
-
 void player_render_cb(void *udata, Uint8 * buf, int len)
 {
     (void) udata;
     while (len > 0) {
-        if (player.curr > len) {
+        if (player.curr >= len) {
             player.curr -= len;
             gb_genwave((char *)buf, len);
             len = 0;
-            player_tick();
         } else {
             gb_genwave((char *)buf, player.curr);
             buf += player.curr;
             len -= player.curr;
             player.curr = player.frag;
-            player_tick();
+            player_newnote();
         }
     }
 }
@@ -251,8 +240,8 @@
 
    if (argc != 2)
    {
-      fprintf(stderr,"usage: %s <tunenum 0..%d>\n",
-        argv[0], ntunes - 1);
+      fprintf(stderr, "Usage: %s <tunenum 0..%d>\n",
+          argv[0], ntunes - 1);
       return 0;
    }
 
@@ -266,7 +255,7 @@
      "Channels: %d\n",
      i, tune->title, tune->tempo, tune->numchans);
 
-   if (SDL_Init(SDL_INIT_EVENTTHREAD | SDL_INIT_AUDIO) != 0)
+   if (SDL_Init(SDL_INIT_AUDIO) != 0)
    {
        fprintf(stderr, "* SDL could not be initialized.\n");
        return 1;
@@ -305,6 +294,7 @@
             break;
        }
    }
-   
+
+   sdlaudio_close();   
    return 0;
 }