Home Creators Posts Import Register Favorites Logout

Content

Been crunching for months on a bunch of projects, which I'll give the rundown on in a different post soon, but we're about to merge the redesigned SDL3 audio system, so I made a little demo video about it!

I can't wait to see what people do with this; not only does it solve a lot of the little aggravations of the SDL2 audio API, but it's also more powerful, easier, and cooler, too.

Files

The SDL3 Audio Subsystem!

Here's a quick rundown of the new SDL3 Audio Subsystem! Want you name in lights? Or at least in my YouTube videos? https://patreon.com/icculus or https://github.com/sponsors/icculus Icons created by AlexAngry: https://linktr.ee/AlexDraw Sounds in this video: splash.wav: SPLASH.wav by petenice Original: https://freesound.org/s/9508/ License: https://creativecommons.org/publicdomain/zero/1.0/ spring.wav: Game Over Arcade.wav by myfox14 (We converted this to mono output.) Original: https://freesound.org/s/382310/ License: https://creativecommons.org/publicdomain/zero/1.0/ Music in today's video is from Kevin Hartnell, of Overlook Hotel Records, under a CC BY-SA 4.0 license. I got it from Bandcamp, but his main website with all the links is https://www.kevinhartnell.com/ Creative Commons is a force for good and lets this music show up in this video, but you should still throw a few bucks at Kevin, because publishing under the CC should be rewarded. Kevin Hartnell - "CC BY-SA 4.0" Overlook Hotel Records R237-0CC

Comments

stsp

If I generate the sound based on some system clock and feed it to SDL3 when I have some, then what happens in the case the sound card clocks have a slightly different freq than the clocks I use? I suppose such approach will then give the periodic overruns/underruns?

Ryan C. Gordon

Generally this will work if you’re producing enough audio to play in real time. The usual worse case here is we end up feeding the device silence on the first buffer before any audio is generated, which might introduce an imperceptible latency, but nothing serious. Latency, imperceptible or not, is preferable to underflows. But we’ll know more as we start to build things on top of the new API.

stsp

Yes, I do generate in real time. But I don't think the initial delay will compensate the clock skew on the long run. The de-sync accumulates, so any initial delay is enough only for some limited period of time. I do think that SDL3 should know my view of the timing, and it should be able to resample the audio chunks based on a clock mismatches. For example, we both (SDL3 and my code) can measure the time since the stream output was started on sdl. Then with every new chunk of the sound, I should also tell "please start playing this right after the prev chunk (no delay insertion is allowed), and on my clock that should be started on second 15 since the stream start". Then SDL3 looks at its buffer and see that the prev chunk would end on second 14, not 15! So there is a risk of an underflow. It then resamples the remained chunk to end at exactly sec 15, and also calculates the overall clock mismatch, and uses that to resample the new chunks. What do you think, can something like this work for the clock syncing?

Dominik Reichardt

Looking forward to see how our ancient Exult will hold up when porting to SDL3 🤩

Ryan C. Gordon

Honestly, we don't have that tight of control over the timing of audio hardware in a cross-platform manner. Some APIs are more powerful for this sort of thing (Apple's CoreAudio, for example) and most are not (just about everything else). For now I would say "we'll have to see what happens when we try it, and figure out whether to adjust the app or SDL" ... but in most non-realtime platforms, less strict timing and more-cautious buffering is usually a good idea, whether using SDL or not.

Ryan C. Gordon

I can't wait to see! We have a few more mountains to climb before SDL3 is considered ready for a feature-complete, stable release, but when we get there, let's try and upgrade Exult over a weekend and see what happens!

stsp

Non-realtime case: what would be the best strategy here? Feed the data to sdl3 until it says "enough, all buffers full", then sleep a bit and try feeding again? Realtime case: I am doing quite advanced buffering, yes. With sdl call-back I was able to partially see the sdl's view of timing. If the call-back drains my buffers too much, I could generate a bit more. But without any knowledge of each other's timing view, what would be the best strategy here? Any clock mismatch accumulates, so I think buffering alone is not helping. Something else is needed too. What is the strategy you propose? I admit that callback is far from the handy solution here, but at least it kinda helps estimating the sdl's view of the timing.

Ryan C. Gordon

The callback is still an option, to be clear: audiostreams can fire one whenever something requests data from it, giving you a chance to fill it right as the data is requested. More or less, this works like SDL2. Without a callback, you can always ask an audiostream how much is still buffered and decide if you want to add more.

Scaine

That little testaudio app looks lovely! Is that something that's already out there, or did you write it to help visualise your work in SDL3?

Scaine

Amazing! Love that you casually fire out a slick app for testing that far, far surpasses anything I could have written given a couple of years! Haha!

BJ

I can't wait to play with this.. Ryan you rockstar ...

stsp

> Without a callback, you can always ask an > audiostream how much is still buffered and > decide if you want to add more Should work for non-realtime case, thanks for the info. IMHO the realtime case requires the entirely separate APIs. The ones like "play this audio chunk starting from time-point X", some API for SDL3 to figure out my view of the time, on-fly resampling capabilities, and so on. I appreciate the desire to get rid of a call-back, but for the realtime case its an exceptionally difficult task, and I hope you'll solve it the best possible way. :) My code would benefit a lot if I stop to care about an SDL timing, but for the SDL itself it might be a very large chunk of the tricky code with complex APIs. Thanks for doing that work!

Dominik Reichardt

I've lost sight of the feature I'm looking for the most, implementation of mojoshader (or similar). Do I remember correctly that this was planned and if so, is it still planned?

Merlyn Morgan-Graham

saw your twitter post. I have an IP block on that site or I'd reply there. hoping you laughed it off, since it is indeed laughable. if not, then - imagine having the audacity to be that much of a turd to a legend like icculus, the patron saint of linux gaming. can't say thank you enough. peace and love, man.

Josh 'Cheeseness' Bush

This is very cool! I guess I won't be using SDL_Mixer in my future SDL projects! I love that you were able to put together a nice little tool to visualise what's going on it. Great work on both fronts. My thanks to all contributors!