Hot Code Reloading in C

  Рет қаралды 58,182

Tsoding Daily

Tsoding Daily

9 ай бұрын

Previous Episodes: • Music Visualizer
References:
- Music: / @nu11_ft
- Note Frequency Math: pages.mtu.edu/~suits/NoteFreq...
- Flyway (Database Migration Libray): flywaydb.org/

Пікірлер: 124
@dancinglazer1628
@dancinglazer1628 9 ай бұрын
I loved when zozi said it’s zozin time and zozied all over
@distant6606
@distant6606 9 ай бұрын
🤣
@maxmster55
@maxmster55 9 ай бұрын
My favorite part
@waxlbloh6450
@waxlbloh6450 9 ай бұрын
😳
@adr420
@adr420 9 ай бұрын
@tekno679
@tekno679 9 ай бұрын
I once attempted to write a music visualizer in python and failed horribly. This man did it in C and made it hot-swappable. Respect.
@contentprogramming
@contentprogramming 5 ай бұрын
try it again to prove to yourself that youre improving ;)
@tekno679
@tekno679 5 ай бұрын
@@contentprogramming Sadly I don't think I'll have time for that, but I think I did improve, because now I'm doing an image->sound conversion program for my bachelor's thesis 😎
@austinhutchen
@austinhutchen 5 ай бұрын
@@tekno679Making some sound out of a FFT transformation of the discrete information present in the image, I presume? It sounds like an interesting project!
@tekno679
@tekno679 5 ай бұрын
@@austinhutchen I'm planning on it being a modular program where you can select the exact algorithm you want to use for the conversion. Currently I have an algorithm that does straightening of the image by a space-filling curve and mapping to frequencies and some other basic ones. I did think about adding a DCT too, but the most challenging thing about this is that it increases the space to 3D essentially and you want to output a "1D" sound that somehow corresponds to the input.
@vitfirringur
@vitfirringur 9 ай бұрын
In my late teens I wrote an irc bot in C which used hot reloading to support plugins. I did this by parsing the the shared objects manually and looking for exported functions that were prefixed by IRC commands and an underscore: PRIVMSG_foo, etc. Probably the coolest, most advanced thing I had built at that point. This sort of reminds me of that.
@RobertFletcherOBE
@RobertFletcherOBE 4 ай бұрын
No lies from the artists, Once you get good at drawing you don't need smoothing (though they do still use it when they don't need control). The reason your line is jittery is your drawing from your wrist, and your drawing short strokes, digital artists zoom in so that they can do long fluent strokes from the elbow and shoulder (broader radius). (source: classically trained animator who now develops tools for creatives). Also I hope it goes without saying. Awesome stream :)
@TsodingDaily
@TsodingDaily 4 ай бұрын
Oh! I see what you mean! Thanks! I'll practice that.
@user-ng6jb5jh5r
@user-ng6jb5jh5r 9 ай бұрын
The math as to which frequencies you get from the FFT is a bit more complicated than you used here. There are two issues, because of reasons the top half of your FFT (for example elements 128-255 if N = 256) will mirror the bottom half and doesn't give you any more information, you might as well throw it away. The highest frequency you get will always be half of the sampling frequency (for example 22.05 kHz if you use 44.1 kHz audio). You can't change this even by increasing N and it will be the middle (emph. middle) element of your FFT vector. Your value of N will determine the lowest frequency you can resolve, it will be 44.1 kHz (again assuming 44.1 kHz audio) divided by the number of samples. Say you choose N = 2048 then the FFT[0] will be your zero hertz amplitude then FFT[1] will be 44.1 kHz / 2048 = 21.53 Hz and FFT[2] will be 43.06 Hz. This will continue until FFT[1024] which will give the amplitude at half the sampling rate, i.e. 22.05 kHz. You can throw away everything after this because it will just mirror the first half (blame Nyquist). Also it's customary to view both the amplitude and the frequency logarithmically in which case your amplitude is essentially in dB (human's also perceive amplitude logarithmically). Also you'll want to sum over the bins if you view the frequencies logarithmically instead of average.
@ade5324
@ade5324 9 ай бұрын
yepieee!!! Thats the think I'm interested rn, interactive programming, jit compilers, hot reloading, things like that. this video is just in time!!!
@flyLeonardofly
@flyLeonardofly 9 ай бұрын
1:26:58 Dap, dap technology from the 70ies😂😂😂😂
@JonnyDeRico
@JonnyDeRico 9 ай бұрын
you could use a sine wave sweep to check for correct working fft
@lifeng8403
@lifeng8403 8 ай бұрын
Respect and thanks the remarkable work.
@steled03
@steled03 9 ай бұрын
Its always possible to implement a raylib callback handler inside the program, which calls the callback in the plu gin with some data argument!
@zombozer6333
@zombozer6333 9 ай бұрын
For the macro around 2:04:44 you can use the # symbol to turn symbols like 'plug_hello' into strings. #define PLUG_HOOK(f_name, libplug) \ do { \ f_name = dlsym(libplug, #f_name); \ if (f_name== NULL) { \ fprint(stderr, "ERROR: could not find %s symbol in %s: %s", \ #f_name, libplug_file_name, dlerror()); \ return false; \ } \ while(1) \ You could use it like this: PLUG_HOOK(plug_hello, libplug); I haven't tested this though. You still need to declare all the global variables and repeat this macro for every function but it's a pretty simple solution for what it does.
@mohammedalhaddar2182
@mohammedalhaddar2182 5 ай бұрын
Why is it enclosed in an infinite loop?
@IGrizzllyGuy
@IGrizzllyGuy 5 ай бұрын
@@mohammedalhaddar2182 I think he wanted to say while(0);
@robsokolowski9015
@robsokolowski9015 9 ай бұрын
Flyway reminds me a bit of Lamdera, a "full stack Elm" that has type safe migrations for the stateful backend.
@bobby9568
@bobby9568 9 ай бұрын
The King is back! 🎉
@zombozer6333
@zombozer6333 9 ай бұрын
Padding samples with zeros caused smoothing around 1:38:12 also the range of frequencies you get from the fft depends only on the sample rate not the number of samples. The number of samples only effects the precision of the frequencies you get back.
@arcxm
@arcxm 9 ай бұрын
23:13 "reload this hot library" ^^, 1:26:56 xD
@francklenormand2680
@francklenormand2680 9 ай бұрын
The technic to clean all the symbols resolution is to resolve only 1: a structure containing all the pointers on functions. The struct must be defined in the plugin and retrieved by main app
@TECHN01200
@TECHN01200 9 ай бұрын
I love the message of programming is universal. I am entirely with you on this point, it disappoints me that there are hardly any low level jobs anymore for anyone with fewer than 5 years of C experience.
@kibels894
@kibels894 9 ай бұрын
If you're skilled enough in C to work in low level then put it on your resume. If you have the skills there's no reason to let your resume be the reason they reject you.
@OxAA00
@OxAA00 4 ай бұрын
Great channel and great video!
@ryonagana
@ryonagana 9 ай бұрын
this was perfectly done by Id Software,, used in Quake 2 Engine, when you enter in a server it hot loads the server dynamic library of the game, doesnt matter if the server is running on windows or linux, it just take cares of the loading and endianess
@awesomeguy11000
@awesomeguy11000 9 ай бұрын
If I could make a stream request: try to program anything without warnings using clang -Weverything and clang static analyzer
@zombozer6333
@zombozer6333 9 ай бұрын
The high frequencies seem to be shown to be very low. Maybe you could sum them instead of taking the average. That would also make more sence to me because it preserves the area under the curve (sort of like the energy in the sound).
@ferasboulala6220
@ferasboulala6220 9 ай бұрын
This is exactly what should have been done with a log scale on top for visualization, if needed.
@parallel4344
@parallel4344 9 ай бұрын
I have also done something like this for my visualizers.
@enc6428
@enc6428 9 ай бұрын
js hot reloading is just reading a js file as a string and passing it to eval()
@brd5548
@brd5548 4 ай бұрын
Very entertaining and educational demonstration! Python dev here😝, but we do have dll hot reloading functionality within python since very early days. For dlopen/dlclose/dlsym calls, they exist under the standard lib ctypes, whose signatures are pretty much the same with the posix ones if I remember. The whole CPython interpreter itself is just basically a huge C virtual machine, so it's pretty easy for cpython to interop with c code. For JavaScript, I do believe the node.js runtime has similar functionalities, but I'm not sure if it's a js language standard feature or just a node.js thing.
@shrddr
@shrddr 4 ай бұрын
since fft() has no time scale reference, it doesn't produce frequencies in Hz, but in multiples of (1/windowsize). the window size was 0.1sec iirc so it returns multiples of 10Hz and when you start drawing at f=20.0 that's actually 200Hz
@SimGunther
@SimGunther 9 ай бұрын
Virgin VM image vs Chad hot reloaded .so file 😎
@DanelonNicolas
@DanelonNicolas 9 ай бұрын
I love this man... ❤ the moment when hot realoading works was EPIC!!!! how about that!!!
@byterbrodTV
@byterbrodTV 9 ай бұрын
Thank you for video. Interesting project. I guess after watching this video we all doesn't need java or c# with their "VM hotswap thingy" anymore. Will put my little thoughts below. 1:03:00 - I suppose guy from chat means the case when you press R and hold it. I wonder, will it reload plugin every frame? I don't know how exactly KeyPressed() works, but in that cases something like KeyReleased() might be better, because it would called once when you release your R button. 1:35:47 - As a little bit of music making person i would say that normal people can't hear frequences after about 15-16k, it's just a high pitch noise, so 2^14 is enough for EQ. Keep this project up, we waiting for the moment when we could drag and drop music into player by hand :>
@nilsnilss
@nilsnilss 9 ай бұрын
you can use multiple compilation buffers by renaming the compilation buffer and then switiching the buffer and then start a new compilation
@Celicaw8
@Celicaw8 9 ай бұрын
1:06:39 Couldn't you make a wrapper function with the same signature, where the bufferData is a structure with the bufferdata and the userdata, then pass this wrapper to the function you registered the callback with?
@johnhammer8668
@johnhammer8668 7 ай бұрын
How did you find static linking was the cause for crash? Why does dynamically linked library does not crash?
@wrnlb666
@wrnlb666 9 ай бұрын
libdl has a windows wrapper. I think it is crossplatform enough?
@maximeetienne2601
@maximeetienne2601 3 ай бұрын
Great video, very informative. Could someone explain why did he was forced to link dynamically raylib to make the hot reloading work ?
@not_just_burnt
@not_just_burnt 9 ай бұрын
i love myself some fearofdark music too!!
@LogicEu
@LogicEu 9 ай бұрын
Very cool stuff
@somecretin
@somecretin 7 ай бұрын
the pervasive self-absorbed narcissism is such a turn-off
@slendi9623
@slendi9623 9 ай бұрын
This is really cool, I tried doing the same thing but with getting the .so file's mtime and doing a compare on that `if (get_modification_date() > prev_modification_date)`, however it likes to bus error and segfault for some reason. But when I do IsKeyPressed, it just werks. Weird.
@slendi9623
@slendi9623 9 ай бұрын
Its because I recompiled main
@portersky
@portersky 9 ай бұрын
Bro just made ringbuffer like I did in my DSP lab 😂
@mightyhelper8336
@mightyhelper8336 9 ай бұрын
Maybe you could run some pure sine waves to test it
@parlor3115
@parlor3115 9 ай бұрын
Oh yeah!
@mason-pe5lk
@mason-pe5lk 9 ай бұрын
Sounds complicated. I would've just piped the music to my headset and to the visualizer.
@anotherlevelofselfawareness
@anotherlevelofselfawareness 8 ай бұрын
Tsoding, was you ever try to write AGI?
@eazypeazy8559
@eazypeazy8559 9 ай бұрын
so fcking cool. I watch your streams as entertainment random CS course....
@TankorSmash
@TankorSmash 9 ай бұрын
1:27:00 Python does have hotreloading, basically built in. Javascript absolutely has hot reloading if you use a build tool. It absolutely wasn't your point but in case anyone is curious, it's very common!
@haakonness
@haakonness 9 ай бұрын
In the start of the stream he said that it is possible in python, js and even java. So he is aware, he was just hyping :P
@gaweqqwgfas9980
@gaweqqwgfas9980 9 ай бұрын
you're doing cool stuff while i struggle to install a c compiler ffs
@TsodingDaily
@TsodingDaily 9 ай бұрын
You can do it! I believe in you!
@gameofpj3286
@gameofpj3286 9 ай бұрын
Maybe smooth the fft by using 50% of the previous fft and 50% of the new calculated one :D I think it's called exponential smoothing or something like that.
@jamesbarret4240
@jamesbarret4240 8 ай бұрын
afaik it's called temporal smoothing, similar algorithms are used in anti-aliasing (TAA). good idea
@gameofpj3286
@gameofpj3286 8 ай бұрын
@@jamesbarret4240 Yea it's exponential smoothing. Probably a good idea to have it just smoothed when it goes down tho.
@SimonBuchanNz
@SimonBuchanNz 9 ай бұрын
One really annoying thing with trying to do this especially in other languages is if you use global init code or thread locals or the like, it just stops working because apparently that's just too hard for glibc to figure out. Ugh. A more reliable and buzzword friendly approach is to use WASM, but now you have the mess of interop.
@exciting-burp6613
@exciting-burp6613 9 ай бұрын
Hot teloading is a big deal in JS bevause everything is unnecessarily complicated in JS.
@flleaf
@flleaf 8 ай бұрын
1:12:18 two weeks? isn't there only one video on youtube on this?
@ShowierData9978
@ShowierData9978 9 ай бұрын
you can use a callback within the main program; then call the dll callback
@bloomingvision
@bloomingvision 9 ай бұрын
Thats the point of all this though - its about not doing the short cuts. "just use a this and this is all unnecessary" . T's "Programming is Universal" speech captures the essence of it. There is a fundamental universality that we should know. LINKERS AND LOADERS - A beautiful are. We should all know it. My Book coming out: Computer Science in Rust :) Will re-deliver these arts. Soding.... this goes down in my book as the Traders equivalent of Gecko's Greed is Good speech -- PROGRAMMING IS UNIVERSAL.
@MrDujmanu
@MrDujmanu 9 ай бұрын
What font(s) do you use?
@RagePower2000
@RagePower2000 9 ай бұрын
What font do you use?
@SebastianSipos
@SebastianSipos 9 ай бұрын
dll is dynamic link library.
@phill13able
@phill13able 3 ай бұрын
How to confirm neovim like yours?
@deathvall3y
@deathvall3y 9 ай бұрын
0:03:0 why does it say porn folder 7.6 GiB in the tray 🤔
@postmodernist1848
@postmodernist1848 9 ай бұрын
The standard library has an M_PI #define. GNU extension has M_PIf. Also why not just cast M_PI to float?
@dancinglazer1628
@dancinglazer1628 9 ай бұрын
apparently M_PI is non standard
@aciddev_
@aciddev_ 9 ай бұрын
zozi bought new camera! yay
@desertfish74
@desertfish74 9 ай бұрын
Rezozing ze code
@azir8930
@azir8930 9 ай бұрын
@bd3670
@bd3670 8 ай бұрын
Am I the only one who noticed: "Porn Folder" in his terminal?
@png261
@png261 8 ай бұрын
what software does he use to zoom in out and dim screen ?
@flleaf
@flleaf 8 ай бұрын
boomer (on his github)
@png261
@png261 8 ай бұрын
​@@flleaf thanks a lot, such a useful tool
@rogerbusquetsduran5596
@rogerbusquetsduran5596 3 ай бұрын
How were you anble to build the shared lib while having it opened by your application?
@ClickHappyGames
@ClickHappyGames Ай бұрын
readonly does not lock files, so read+write succeeds.
@zombozer6333
@zombozer6333 9 ай бұрын
I think it's crashing because you are passing a callback to instruction in the SO. Then when the SO is closed the callback is called and it segfaults. I gues when the code barely changed the new version gets loaded into the same memory? That seems weird though because I would expect the memory layout to be randomized through ASLR although I'm not an expert on that. To fix this you could place the callback function in the static file. This can then call into the updated version of the SO. Otherwise you would have to somehow pause the audio so the callback doesn't get called. (Edit): I didn't see the extra section at the end. You already solved it so nvm.
@user-oe4id9eu4v
@user-oe4id9eu4v 9 ай бұрын
ASLR is something to do with kernel loading process into memory with exec* syscalls. Dynamic linking using dl* functions is resolved by dynamic linker, which is part of libc. So address of each functions will change every time program is reloaded, but not when simply shared object is reloaded.
@bibliusz777
@bibliusz777 7 ай бұрын
What is wrong with Nix?
@filipbook5605
@filipbook5605 9 ай бұрын
Does anyone here have a license for a switch case developer??? I'm looking for one
@vividimagination2044
@vividimagination2044 9 ай бұрын
If you want to get around these annoying "accept our cookies or else" prompts without accepting anything then you can just open your browsers console, find the modal and elegantly slam that delete button with fervor
@lazarstanojevic7841
@lazarstanojevic7841 9 ай бұрын
is there a video where he talks about his setup (editor, os and stuff like that)?
@Stroopwafe1
@Stroopwafe1 9 ай бұрын
Editor: Emacs OS: Debian Keyboard: Yes /j He has some videos where he talks about that it doesn't matter what he uses, just use what works best for you
@varshneydevansh
@varshneydevansh 9 ай бұрын
Woah in just 2 mins
@tauraamui
@tauraamui 9 ай бұрын
you should use Excalidraw instead of trying to handwrite text with a mouse.
@paco3447
@paco3447 9 ай бұрын
Regarding this, a whatever’s Erlang project could be a next and funny try.
@glorioussir9673
@glorioussir9673 9 ай бұрын
You can use "x macro" for function loading deduplication, quite handy technic en.wikipedia.org/wiki/X_macro
@Shonicheck
@Shonicheck 9 ай бұрын
12:57 The --cake-- smooth line is a lie!
@andrewlamichhane1090
@andrewlamichhane1090 9 ай бұрын
Is that a new zozing place ?
@rakaboy1619
@rakaboy1619 9 ай бұрын
its like i cant build a http server and this man out here casually makes a hot code reloading in C in a time it takes me to make a class. trutly a tsoding moment
@heyyouhere
@heyyouhere 9 ай бұрын
todays session is hot omgggg
@TurokroIV
@TurokroIV 9 ай бұрын
Sometimes I wish I was a C programmer up in the sky, I wouldn't mind debugging if my loop could fly But I'll be a Pyhonista until the day I die with ten years to go in the big data mine
@user-bn4wn7ll3e
@user-bn4wn7ll3e 9 ай бұрын
"Can your python and javascript do that??!" Python and javascript don't segfault lol
@ryonagana
@ryonagana 9 ай бұрын
imp library, now importlib in Python 3
@Isaac-zy5do
@Isaac-zy5do 9 ай бұрын
Just give you NaNs instead lol
@bonniesimon14
@bonniesimon14 9 ай бұрын
Love the video without it, but still would be awesome to have timestamps.
@Gordonfreems
@Gordonfreems 9 ай бұрын
This was a vibe, amazing stream
@begga9682
@begga9682 9 ай бұрын
1:26:58 Python goobers got owned lmao
@Narblo
@Narblo 9 ай бұрын
why dont you use pragma once?
@aviationbutterr
@aviationbutterr 9 ай бұрын
pragma once is a non-standard directive. header guards will always work on any standard-compliant compiler
@AbelShields
@AbelShields 9 ай бұрын
2:10:43 hypocracy, you can't do fft on 32k frames because "computers slow", but you'll do a memmove of 8k (or however much it ended up) in a hot loop in the callback because "computers fast"? :P Hey, thanks for recognising me though, really enjoyed seeing the logarithms come to life tsodingHeart the end result looks great!
@AbelShields
@AbelShields 9 ай бұрын
@@tripplefives1402 copying bytes takes time too!
@zombozer6333
@zombozer6333 9 ай бұрын
@@tripplefives1402 Big O notation isn't everything but still, fft is O(n log n) while the copying he was doing was O(n^2).
@gameofpj3286
@gameofpj3286 9 ай бұрын
Also I really love how you can see the melody playing at 2:13:07 :o
@titaniumtomato7247
@titaniumtomato7247 9 ай бұрын
So is this how a shell is made, or does the shell just have its own interpreter?
@TehFuckingDoctor
@TehFuckingDoctor 9 ай бұрын
Why don't you use VIM?
@sinamobasheri
@sinamobasheri 9 ай бұрын
This is not hot I wanna hot
@dryoldcrabman6890
@dryoldcrabman6890 4 ай бұрын
1:11:46 kek
@enclave2k1
@enclave2k1 9 ай бұрын
if code_is_working { self.is_twerking = true; }
@monprenometmonnom5518
@monprenometmonnom5518 9 ай бұрын
en.wikipedia.org/wiki/Tiny_C_Compiler : TinyC Compiler able to compile C string code inside EXE
@flleaf
@flleaf 8 ай бұрын
interesting, didn't know youtube doesn't delete comments with wikipedia links
My Own 3b1b Animation Engine but in C
2:06:44
Tsoding Daily
Рет қаралды 14 М.
the cleanest feature in C that you've probably never heard of
8:13
Low Level Learning
Рет қаралды 116 М.
Что будет с кроссовком?
00:35
Аришнев
Рет қаралды 1,9 МЛН
Суд над Бишимбаевым. 2 мая | ОНЛАЙН
7:14:30
AKIpress news
Рет қаралды 575 М.
Айттыңба - істе ! | Synyptas 3 | 7 серия
21:55
kak budto
Рет қаралды 1,3 МЛН
Weird Parts of C you probably never heard of...
38:06
Tsoding Daily
Рет қаралды 53 М.
Will Ada Replace C/C++?
44:57
Tsoding
Рет қаралды 62 М.
Compiling MS-DOS 4.0 using DOSbox & Qemu
17:59
Neozeed
Рет қаралды 1,7 М.
I regret doing this...
1:20:07
Tsoding Daily
Рет қаралды 59 М.
Wait, but Who's Debugging the Debugger?!
59:53
Tsoding Daily
Рет қаралды 33 М.
I Coded in a Random Programming Language Everyday, For Science
17:17
Low Level Learning
Рет қаралды 67 М.
I spent six months rewriting everything in Rust
15:11
chris biscardi
Рет қаралды 372 М.
Master Pointers in C:  10X Your C Coding!
14:12
Dave's Garage
Рет қаралды 257 М.
My 2 Year Journey of Learning C, in 9 minutes
8:42
VoxelRifts
Рет қаралды 520 М.
Arenas, strings and Scuffed Templates in C
12:28
VoxelRifts
Рет қаралды 70 М.
Распаковка айфона в воде😱 #shorts
0:25
Mevaza
Рет қаралды 1,1 МЛН
Интел подвинься, ARM уже в ПК!
14:06
PRO Hi-Tech
Рет қаралды 157 М.
Нужен ли робот пылесос?
0:54
Катя и Лайфхаки
Рет қаралды 852 М.
Какой Смартфон Купить в 2024 Году? Выбор бюджетного телефона
14:21
Thebox - о технике и гаджетах
Рет қаралды 268 М.
Такого вы точно не видели #SonyEricsson #MPF10 #K700
0:19
BenJi Mobile Channel
Рет қаралды 1,9 МЛН
🤯Самая КРУТАЯ Функция #shorts
0:58
YOLODROID
Рет қаралды 1,9 МЛН