Implement float32 support for winmm and directsound targets (Thanks, John!).
authorRyan C. Gordon <icculus@icculus.org>
Sun, 14 Jul 2013 13:27:54 -0400
changeset 7449 5148cfb37948
parent 7448 c1f9032d0634
child 7450 29654d59c439
Implement float32 support for winmm and directsound targets (Thanks, John!). Fixes Bugzilla #1657.
src/audio/directsound/SDL_directsound.c
src/audio/winmm/SDL_winmm.c
--- a/src/audio/directsound/SDL_directsound.c	Sun Jul 14 13:25:49 2013 -0400
+++ b/src/audio/directsound/SDL_directsound.c	Sun Jul 14 13:27:54 2013 -0400
@@ -30,6 +30,10 @@
 #include "../SDL_audio_c.h"
 #include "SDL_directsound.h"
 
+#ifndef WAVE_FORMAT_IEEE_FLOAT
+#define WAVE_FORMAT_IEEE_FLOAT 0x0003
+#endif
+
 /* DirectX function pointers for audio */
 static void* DSoundDLL = NULL;
 typedef HRESULT(WINAPI*fnDirectSoundCreate8)(LPGUID,LPDIRECTSOUND*,LPUNKNOWN);
@@ -466,6 +470,7 @@
         case AUDIO_U8:
         case AUDIO_S16:
         case AUDIO_S32:
+        case AUDIO_F32:
             this->spec.format = test_format;
             valid_format = 1;
             break;
@@ -479,7 +484,12 @@
     }
 
     SDL_memset(&waveformat, 0, sizeof(waveformat));
-    waveformat.wFormatTag = WAVE_FORMAT_PCM;
+
+    if (SDL_AUDIO_ISFLOAT(this->spec.format))
+        waveformat.wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
+    else
+        waveformat.wFormatTag = WAVE_FORMAT_PCM;
+
     waveformat.wBitsPerSample = SDL_AUDIO_BITSIZE(this->spec.format);
     waveformat.nChannels = this->spec.channels;
     waveformat.nSamplesPerSec = this->spec.freq;
--- a/src/audio/winmm/SDL_winmm.c	Sun Jul 14 13:25:49 2013 -0400
+++ b/src/audio/winmm/SDL_winmm.c	Sun Jul 14 13:27:54 2013 -0400
@@ -32,6 +32,10 @@
 #include "../SDL_audio_c.h"
 #include "SDL_winmm.h"
 
+#ifndef WAVE_FORMAT_IEEE_FLOAT
+#define WAVE_FORMAT_IEEE_FLOAT 0x0003
+#endif
+
 #define DETECT_DEV_IMPL(typ, capstyp) \
 static void DetectWave##typ##Devs(SDL_AddAudioDevice addfn) { \
     const UINT devcount = wave##typ##GetNumDevs(); \
@@ -257,6 +261,7 @@
         case AUDIO_U8:
         case AUDIO_S16:
         case AUDIO_S32:
+        case AUDIO_F32:
             break;              /* valid. */
 
         default:
@@ -273,7 +278,12 @@
 
     /* Set basic WAVE format parameters */
     SDL_memset(&waveformat, '\0', sizeof(waveformat));
-    waveformat.wFormatTag = WAVE_FORMAT_PCM;
+
+    if (SDL_AUDIO_ISFLOAT(this->spec.format))
+        waveformat.wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
+    else
+        waveformat.wFormatTag = WAVE_FORMAT_PCM;
+
     waveformat.wBitsPerSample = SDL_AUDIO_BITSIZE(this->spec.format);
 
     if (this->spec.channels > 2)