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

КОМЕНТАРІ • 43

  • @erc0re526
    @erc0re526 2 роки тому +10

    Love this! I feel like we're going to discover a lot of little SDL tricks. Didn't know about the zero macro. Thanks!

  • @user-tt4dy1ti5v
    @user-tt4dy1ti5v 2 роки тому +7

    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

  • @spjewkes
    @spjewkes 4 місяці тому

    Thank you for this. A great tutorial. Nice, short and clear.

  • @AcceleratingUniverse
    @AcceleratingUniverse Місяць тому

    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

  • @Cheeseness
    @Cheeseness 2 роки тому +3

    This was fun to watch - it's always a cool feeling when the core of something coalesces quickly. Looking forward to seeing more :)

  • @fabriziotobia9646
    @fabriziotobia9646 2 роки тому +3

    Nice, thank you! It was really cool, I hope you continue this series :)

  • @gr1iev3r10
    @gr1iev3r10 2 роки тому +2

    hes back !! :)

  • @RyanMcQuen
    @RyanMcQuen Рік тому +1

    "Don't ask me about this text editor, it's weird, I know, that's just how life is." 🤣🤣🤣

  • @JohnneyleeRollins
    @JohnneyleeRollins 2 роки тому +1

    This was definitely worth the watch. Hoping for more. 🙂

  • @BeyondImaginationzz
    @BeyondImaginationzz 2 роки тому +3

    that editor is sick

  • @Johnny-ww9ks
    @Johnny-ww9ks 2 роки тому +2

    Thanks for this, hope you do more like it.

  • @victornoagbodji
    @victornoagbodji 2 роки тому +1

    Thanks for sharing this with us 😊 🙏

  • @kotrin
    @kotrin 2 роки тому

    Thanks for sharing 👍I'm excited to dig into all the parts. Cheers!

  • @kazriko
    @kazriko 2 роки тому +2

    FTE! I remember using that on OS/2.

    • @RyanGordon
      @RyanGordon  2 роки тому +1

      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!

    • @kazriko
      @kazriko 2 роки тому +2

      @@RyanGordon Nice, that seems like some useful enhancements.

  • @wizofssp
    @wizofssp 2 роки тому +1

    Fun video, love it.

  • @dominikdalek
    @dominikdalek 2 роки тому +2

    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.

    • @RyanGordon
      @RyanGordon  2 роки тому +1

      It’s just processing memory buffers! It can be useful even if you don’t plan to play the sound at all. :)

  • @pixelfl00d
    @pixelfl00d 2 роки тому +2

    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

  • @halemm
    @halemm 2 роки тому +1

    very cool stuff indeed!

  • @jim0_o
    @jim0_o 2 роки тому +1

    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. :)

  • @cprn.
    @cprn. 2 роки тому +2

    Unfortunately rather unwatchable on mobile so I'm liking this blind 😆 keep up the good work!

    • @RyanGordon
      @RyanGordon  2 роки тому +1

      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. :)

    • @cprn.
      @cprn. 2 роки тому

      @@RyanGordon Thank you!

  • @mohdhamzaghyas4328
    @mohdhamzaghyas4328 2 місяці тому

    thanks

  • @greob
    @greob 2 роки тому +1

    Cool!

  • @swinki33
    @swinki33 2 роки тому +2

    What is this beautiful font?

    • @RyanGordon
      @RyanGordon  2 роки тому +1

      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. :)

  • @per_vognsen
    @per_vognsen 9 місяців тому

    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? :)

    • @RyanGordon
      @RyanGordon  9 місяців тому

      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.

  • @woobilicious.
    @woobilicious. 11 місяців тому

    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.

    • @RyanGordon
      @RyanGordon  11 місяців тому

      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!

  • @DaVince21
    @DaVince21 2 роки тому

    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.

    • @RyanGordon
      @RyanGordon  2 роки тому +1

      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).

  • @Seegras
    @Seegras 2 роки тому +3

    Love it, but your keyboard is making an awful racket.

    • @RyanGordon
      @RyanGordon  2 роки тому +2

      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!

    • @dpanterdpanter
      @dpanterdpanter 2 роки тому +1

      Sounds like the mic is picking up impact vibrations, should consider better mic suspension or noise reduction software. :)

    • @RyanGordon
      @RyanGordon  2 роки тому +1

      @@dpanterdpanter I'd be lying if I said this was a professional production. :)

    • @WOFall
      @WOFall 2 роки тому +3

      Still, you might be misjudging how easy "noise suppression for voice" is to set up! ... :)

    • @RyanMcQuen
      @RyanMcQuen Рік тому

      I like the keyboard sounds!

  • @RyanMcQuen
    @RyanMcQuen Рік тому

    Is this Ubuntu 22.04?

    • @RyanGordon
      @RyanGordon  Рік тому +1

      I can't remember exactly what version, but it _was_ Ubuntu of some sort!