Writing a simple media player with SDL, part 1.
Вставка
- Опубліковано 27 сер 2024
- I can't sleep so this is some basic first steps on writing a media player with SDL.
This assumes you know some C (but nothing too extreme) and doesn't spend time on setting up a build environment. Go ask someone.
Make sure you set this thing to 1080p quality and put it fullscreen, so the text is actually legible.
I'll try to get the video to encode better next time, too!
The code at the end of the video, all 30 lines of it:
github.com/icc...
(The music is The Living Proof by Will Provost, my poor brain at midnight.)
Think this is interesting? Let me know if I should keep building this in future videos. Think i'm interesting? Contribute to my Patreon:
/ icculus
Love this! I feel like we're going to discover a lot of little SDL tricks. Didn't know about the zero macro. Thanks!
00:00 Intro
00:10 Ryan's tweet about writing a WinAmp in SDL + SDL_sound
00:34 Creation of GitHub repo for project
01:00 "...never add the README file at the beginning [of repo creation]..."
01:13 "...you cannot do it [add the README file] before you're ready to ship something..."
01:37 [start FTE text editor]
01:40 Coding starts
01:41 #include "SDL.h"
02:07 int main(int argc, char **argv)
02:35 SDL initialization & deinitialization
02:36 // !!! FIXME: error checking!
02:42 SDL_Init()
03:04 SDL_Quit()
03:14 SDL audio device
03:25 "...expect me to lookup SDL headers alot..."
03:46 SDL_OpenAudioDevice()
03:56 [on global variables]
06:01 SDL_AudioSpec desired;
09:13 // !!! FIXME: error checking!
09:30 SDL_PauseAudioDevice()
10:02 SDL audio data
10:30 SDL_LoadWAV() macro
11:16 SDL_AudioSpec wavspec;
14:06 SDL_CloseAudioDevice()
15:40 SDL_QueueAudio()
16:24 SDL_FreeWAV()
16:35 Review & Loose Ends
17:10 [do not forget to add SQL_Quit() & return to all control paths.]
17:20 SDL_Delay()
17:52 [try to compile]
17:53 LANG=C gcc -o sdlamp -Wall -O0 -ggdb3 sdlamp.c `sdl2-config --cflags --libs`
18:48 [try to execute - error, couldn't open music.wav]
18:55 [get sample SDL song]
19:15 [on the name of sample SDL song]
20:20 Successful Program Execution!
20:45 Wrap up
Thank you for this. A great tutorial. Nice, short and clear.
The fact that the lead programmer of SDL doesn't have any of the API memorized really puts into perspective how much time I wasted trying to memorize lazyfoo tutorials line by line when I was 13
This was fun to watch - it's always a cool feeling when the core of something coalesces quickly. Looking forward to seeing more :)
Nice, thank you! It was really cool, I hope you continue this series :)
hes back !! :)
"Don't ask me about this text editor, it's weird, I know, that's just how life is." 🤣🤣🤣
This was definitely worth the watch. Hoping for more. 🙂
that editor is sick
Thanks for this, hope you do more like it.
Thanks for sharing this with us 😊 🙏
Thanks for sharing 👍I'm excited to dig into all the parts. Cheers!
FTE! I remember using that on OS/2.
That's why I started using it; it had OS/2 support. :) Plus the key bindings worked with my muscle-memory for MS-DOS's EDIT command. I just...never stopped using it. My branch of FTE actually uses SDL and renders through OpenGL in modern times, so it's gotten a few upgrades over time!
@@RyanGordon Nice, that seems like some useful enhancements.
Fun video, love it.
It was surprising that WAV loading works w/o device initialization. It's just parsing header and loading data into memory, but still I'd expect stricter requirements just because.
It’s just processing memory buffers! It can be useful even if you don’t plan to play the sound at all. :)
Regarding the global variable advice: I wouldn‘t even regard this as a global one. Just file scope „global“ - but putting them in headers and using them across many files can really get out of hand
very cool stuff indeed!
ref. feedback request, yes, please continue. (I know you have 4 more and they're up next, but then it'll just be 2hours and 10minutes later and I would have wished I asked for more video earlier.)
PS: My first or second GeoCities site was just hosting old versions of WinAmp (I read somewhere that it was legal to share them) it had one of those unsecured HTML visitors-note-book/page(I forgot what we called it) and I still remember the guy that was so thankful for the site because he updated his girlfriend's Winamp version and she didn't like the new one. :)
Unfortunately rather unwatchable on mobile so I'm liking this blind 😆 keep up the good work!
The text is bigger in all the later videos, if you want to skip ahead. We only got through like 30 lines of code in part 1. :)
@@RyanGordon Thank you!
thanks
Cool!
What is this beautiful font?
In the text editor? Believe it or not, it's 9x15.bcf, and an extremely old bitmap font from XFree86 in the mid-1990's. :)
Regarding using static variables, while there are good reasons for avoiding them in many cases, I've found that converting them to TLS statics (if needed later) overcomes most of the issues in practice. And with the static TLS implementation on x86 that just turns into fs/gs-based addressing, which is like one extra cycle of latency per access, so fs/gs effectively become implicit register arguments to every function and it can be a minor perf win over passing context pointers as explicit arguments, especially on argument-register-starved ABIs like win64. Hey, it's good to have a list of prepared excuses when someone criticizes your life choice of using statics, right? :)
These are excellent points, but mostly what I’m trying to express is that a global/static is treated as terrible awful no good hackery because this is what every high school programming class teaches as dogma. And sure, it can get unwieldy-as all code can-but good programming involves knowing when to break rules, and knowing when the rules were wrong in the first place.
Is the builtin audio resampler any good? Infinite Wave doesn't seem to have it in their database, so I do wonder if there's quality loss over using something like Xiph/speex's resampler that's like the gold standard.
The audio resampler in SDL2 is not super-great, but an enormous amount of development work later, the one in SDL3 is pretty good!
The Speex resampler is using the same algorithm as SDL, afaik, except with a cubic interpolator instead of linear (speed over quality, but it's not dramatically different) ... the whitepaper we both built our implementations from is here: ccrma.stanford.edu/~jos/resample/
SDL2 and SDL3 both use this algorithm, but there's a ton of subtle bugs and design flaws in the SDL2 implementation that are gone in SDL3, SDL3 can use SSE2 instructions to accelerate things, etc. It's be interesting to see how it compares against other Infinite Wave entries!
Can't sleep, drinks more coffee. Dude. Well, at least we got an interesting little project out of it. :P Curious to see how it grows.
Just a request: could you zoom in or use a somewhat lower resolution when recording these? It's a little tough to see on the TV or phone.
To follow up: the later parts are recorded at 720p instead of 1080p, and it seems to make a dramatic difference (I can read the text on my phone, etc).
Love it, but your keyboard is making an awful racket.
You can tell how serious I am by how hard I’m smacking the keys. :)
At least I didn’t bring out the actual clicky keyboard!
Sounds like the mic is picking up impact vibrations, should consider better mic suspension or noise reduction software. :)
@@dpanterdpanter I'd be lying if I said this was a professional production. :)
Still, you might be misjudging how easy "noise suppression for voice" is to set up! ... :)
I like the keyboard sounds!
Is this Ubuntu 22.04?
I can't remember exactly what version, but it _was_ Ubuntu of some sort!