changeset 21:19fccd4a7404

Now works (or at least sounds like it sounds like it should sound like) :D .. not sure about stability yet.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 15 Mar 2013 20:45:50 +0200
parents 2ac93f2b93ae
children c57df9d21007
files 3x666.c
diffstat 1 files changed, 16 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/3x666.c	Fri Mar 15 20:31:22 2013 +0200
+++ b/3x666.c	Fri Mar 15 20:45:50 2013 +0200
@@ -30,7 +30,7 @@
     BOOL exitFlag;
 
     int mixFill, mixBufSize;
-    Sint16 *mixBuf;
+    Sint32 *mixBuf;
 
     int optVFlags;
     SDL_Surface *screen;
@@ -466,13 +466,13 @@
 }
 
 
-static int engineRenderAudio(Sint16 *stream)
+static int engineRenderAudio(Sint32 *stream)
 {
     static int rowno = 0;
     static signed int delta = -5;
     static char ismelody = 0, silend = 0;
     int i, rowlgt = engine.tickLen * SET_ROWTIX;
-    Sint16 *d = stream, note;
+    Sint32 *d = stream, note;
 
     /* BASS (sawtooth ofcoz) */
     note = basstrak[(rowno >> 1) & 31];
@@ -493,7 +493,7 @@
         dps = ((noterate[note] << 10) / SET_AUDIO_FREQ);
         for (i = rowlgt; i; i--)
         {
-            *d++ = dmClamp(ps, -32767, 32767);
+            *d++ = ps;
             ps = (ps + dps) & 32767;
         }
     }
@@ -504,12 +504,11 @@
     }
 
     /* MELODY (sawtooth as well :) */
-
     if (!(silend && ((rowno & 63) > 47)))
     {
         if (ismelody)
         {
-            d = (Sint16 *) stream;
+            d = stream;
             if (rowno & 1)
                 note = 0;
             else
@@ -521,7 +520,7 @@
                 dps = ((noterate[note] << 12) / engine.optAfmt.freq);
                 for (i = rowlgt; i; i--)
                 {
-                    *d++ = dmClamp(ps, -32767, 32767);
+                    *d++ += ps;
                     ps = (ps + dps) & 32767;
                 }
             }
@@ -530,7 +529,7 @@
         /* DRUMS (rave on!!!) */
         {
             int *s = drum1;
-            d = (Sint16 *) stream;
+            d = stream;
             if (rowno & 4)
                 s = drum0;
             s += (rowno & 3) * rowlgt;
@@ -539,8 +538,8 @@
                 *d++ += *s++;
         }
     }
+
     /* PATTERN SHIFT */
-
     rowno++;
 
     /* no switch+case? just check out how gcc handles them!
@@ -576,7 +575,7 @@
     (void) userdata;
     // We inherently assume mono here, as the audio code is not
     // capable of producing stereo anyway (for now, at least.)
-    int need = len / sizeof(Sint16);
+    int i, need = len / sizeof(Sint16);
 
     // The audio rendering handling is a bit silly due to the way
     // the original code works (assumes that it can always render
@@ -588,11 +587,15 @@
         engine.mixFill += got;
     }
 
-    memcpy(stream, engine.mixBuf, len);
+    Sint16 *dp = (Sint16 *) stream;
+    Sint32 *sp = engine.mixBuf;
+    for (i = 0; i < need; i++)
+        *dp++ = dmClamp(*sp++, -32767, 32767);
+
     engine.mixFill -= need;
     if (engine.mixFill > 0)
     {
-        memmove(engine.mixBuf, engine.mixBuf + need, engine.mixFill * sizeof(Sint16));
+        memmove(engine.mixBuf, engine.mixBuf + need, engine.mixFill * sizeof(Sint32));
     }
 }
 
@@ -957,7 +960,7 @@
     audio_precalcs();
     setpal();
 
-    engine.mixBufSize = (32 + SET_MAXROWLGT) * sizeof(Sint16);
+    engine.mixBufSize = (16 + SET_MAXROWLGT) * sizeof(Sint32);
     engine.mixBuf = malloc(engine.mixBufSize);
 
     // Start audio, enter main loop