diff dmsimple.c @ 786:bc95f8a6d89c

Add audio sample size information into the engine structure.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 04 Aug 2013 11:31:53 +0300
parents dbf5772690a8
children e8153e8a948e
line wrap: on
line diff
--- a/dmsimple.c	Sat Aug 03 23:48:46 2013 +0300
+++ b/dmsimple.c	Sun Aug 04 11:31:53 2013 +0300
@@ -722,24 +722,22 @@
     engine.audioStatus      = SDL_AUDIO_STOPPED;
     engine.optAfmt.callback = engineAudioCallback;
     engine.audioStreamMutex = dmCreateMutex();
+
+    engine.audioSampleSize  = engine.optAfmt.channels;
+    switch (engine.optAfmt.format)
+    {
+        case AUDIO_S16SYS:
+        case AUDIO_U16SYS: engine.audioSampleSize *= 2; break;
+    }
     
     if (SDL_OpenAudio(&engine.optAfmt, NULL) < 0)
     {
-        int sampleSize;
-
         // We'll let this pass, as we want to support no-sound.
         dmError("Couldn't open SDL audio, falling back to no sound: %s\n", SDL_GetError());
 
         // Set up simulated audio thread
-        sampleSize = engine.optAfmt.channels;
-        switch (engine.optAfmt.format)
-        {
-            case AUDIO_S16SYS:
-            case AUDIO_U16SYS: sampleSize *= 2; break;
-        }
-
-        engine.audioSimDelay   = 1000 / 50;
-        engine.audioSimBufSize = (engine.optAfmt.freq / 50) * sampleSize;
+        engine.audioSimDelay   = 1000 / 45;
+        engine.audioSimBufSize = (engine.optAfmt.freq / 45) * engine.audioSampleSize;
         engine.audioSimBuf     = dmMalloc(engine.audioSimBufSize);
         engine.audioSimDone    = FALSE;
         engine.audioSimThread  = SDL_CreateThread(engineAudioThreadFunc, NULL);