We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 1657 - More audio backends should support floating point audio
Summary: More audio backends should support floating point audio
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: audio (show other bugs)
Version: HG 2.0
Hardware: All All
: P2 enhancement
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords: target-2.0.0
Depends on:
Blocks:
 
Reported: 2012-12-05 16:05 UTC by John Chadwick
Modified: 2013-07-14 13:29 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description John Chadwick 2012-12-05 16:05:43 UTC
Currently, floating point audio support in SDL HG is rather poor. While it is indeed supported in some backends, it is not in others that very easily can support floating point output.

1. In winmm, this is achieved by setting the wFormatTag of the WAVEFORMATEX structure to WAVE_FORMAT_IEEE_FLOAT (0x0003) during initialization. Note that mingw headers do not seem to contain WAVE_FORMAT_IEEE_FLOAT, so I just use 0x0003.

Pseudo diff of SDL_winmm.c, line 262:
----------------------------------------------------------------
         case AUDIO_S32:
+        case AUDIO_F32:
             break;              /* valid. */
...
     waveformat.wBitsPerSample = SDL_AUDIO_BITSIZE(this->spec.format);

+    if(this->spec.format == AUDIO_F32)
+        waveformat.wFormatTag = 0x0003; // WAVE_FORMAT_IEEE_FLOAT

     if (this->spec.channels > 2)
----------------------------------------------------------------

2. directsound seems to support floating point through exactly the same means.

Pseudo diff of SDL_directsound.c, line 475:
----------------------------------------------------------------
         case AUDIO_S32:
+        case AUDIO_F32:
             this->spec.format = test_format;
             valid_format = 1;
...
     waveformat.wFormatTag = WAVE_FORMAT_PCM;
+    if(this->spec.format == AUDIO_F32)
+        waveformat.wFormatTag = 0x0003; // WAVE_FORMAT_IEEE_FLOAT
     waveformat.wBitsPerSample = SDL_AUDIO_BITSIZE(this->spec.format);
----------------------------------------------------------------

3. PulseAudio of course supports floating point. Bonus: it supports big endian too.

Pseudo diff of SDL_pulseaudio.c, line 343:
----------------------------------------------------------------
             break;
+        case AUDIO_F32LSB:
+            paspec.format = PA_SAMPLE_FLOAT32LE;
+            break;
+        case AUDIO_F32MSB:
+            paspec.format = PA_SAMPLE_FLOAT32BE;
+            break;
         default:
----------------------------------------------------------------

There may be more backends that could, but do not support floating point audio, but these are the ones I looked at. Thanks for reading.

P.S. sorry about the 'pseudo' diffs. I will try to get real diffs in a moment, I just wanted to demonstrate how I got floating point working in each backend.
Comment 1 Ryan C. Gordon 2013-07-12 22:15:25 UTC
(Sorry if you get a lot of copies of this email, we're touching dozens of bug reports right now.)

Tagging a bunch of bugs as target-2.0.0, Priority 2.

This means we're in the final stretch for an official SDL 2.0.0 release! These are the bugs we really want to fix before shipping if humanly possible.

That being said, we don't promise to fix them because of this tag, we just want to make sure we don't forget to deal with them before we bless a final 2.0.0 release, and generally be organized about what we're aiming to ship.

Hopefully you'll hear more about this bug soon. If you have more information (including "this got fixed at some point, nevermind"), we would love to have you come add more information to the bug report when you have a moment.

Thanks!
--ryan.
Comment 2 Ryan C. Gordon 2013-07-14 13:29:44 UTC
This was fixed for pulseaudio in Bug #1949, hg changesets 08e4eb5cea46 and 31ec14665b79.

Your changes for winmm and directsound are now hg changeset 5148cfb37948, thanks!

Resolving this bug.

--ryan.