[video member=cmuratori stream_platform=twitch stream_username=handmade_hero project=code title="Implemented a Sound Mixer" vod_platform=youtube id=UuqcgQxpfO8 annotator=Miblo] [1:26][Recap and set the stage for the day] [4:24][handmade.h: Introduce playing_sound and add a pointer to it in game_state] [7:55][handmade.cpp: Setup the PlayingSound loop] [10:12][Blackboard: Working in a 32-bit depth mixing buffer] [11:43][handmade.cpp: Introduce RealChannel0 and RealChannel1] [12:56][handmade_asset.h: Introduce loaded_sound] [13:22][handmade.cpp: Call loaded_sound and sum the Samples in our loop] [18:32][handmade.cpp: Loop over the summed sounds, read out of them and write them to the SampleOut buffer] [22:21][handmade.cpp: Introduce SamplesToMix and SamplesRemainingInSound to handle the finite nature of the audio] [25:28][handmade.h: Add playing_sound *FirstFreePlayingSound to game_state] [25:51][handmade.cpp: Use that FirstFreePlayingSound in the PlayingSound loop] [26:23][handmade.cpp: Snap the Next pointer earlier in order to protect against the act of having it freed screw up our iteration] [28:00][handmade.h: Introduce the concept of a MetaArena] [31:11][handmade_asset.h: Add audio assets to asset_type_id] [32:10][handmade_asset.cpp: Extend the asset loading to handle audio] [34:27][handmade_asset.cpp: Introduce AddSoundAsset] [36:26][handmade.cpp: Make the new system emulate what we had at the start of the stream] [39:01][handmade_asset.cpp: Introduce GetFirstSlotID and various Get functions for Bitmaps and Sound] [45:31][Debugger: Step through the asset loading code] [45:51][handmade_asset.cpp: Set the SoundCount to be 256 * Asset_Count] [46:11][Debugger: Inspect GameState->FirstPlayingSound] [46:35][handmade_asset.cpp: Turn it up to full blast] [47:04][Debugger: Step into LoadedSound] [48:27][build.bat: Switch to -O2 and run the game] [50:13][handmade.cpp: Introduce PlaySound] [53:40][Run the game and hear our sound] [53:45][handmade.cpp: Call PlaySound upon triggering the Sword] [55:09][handmade.h: Add random_series GeneralEntropy to game_state] [56:36][Run the game and find that it almost works] [56:55][handmade.cpp: Investigate the bug] [57:34][Blackboard: Linked list] [58:14][handmade.cpp: Correctly construct this linked list] [1:01:28][Debugger: Step through the playing_sound linked list] [1:04:44][handmade.cpp: Reset SamplesPlayed to 0 in PlaySound] [1:05:33][Run the game and hear our sound] [1:06:20][Q&A][:speech] [1:07:33][@robrobby][s the sound buffer logarithmic or linear (decibel or linear values) and do we (have to) account for that in building the sums for the buffer?] [1:08:04][@allgamesnetworkvideo][Do you already have someone composing the soundtrack?] [1:09:52][@tfnw][A reminder about the parameter order in InterlockedIncrement and the bug it covers up] [1:10:41][handmade_asset.cpp: Handle the case when BeginTaskWithMemory in LoadBitmap fails] [1:12:04][@flaturated][When mixing a mono sound to stereo, volume of each channel should be 50% for center panned] [1:13:32][@soysaucethekid][Will this audio code allow you to play the same sound simultaneously (i.e. if you start the same sound before it finishes the first time)?] [1:13:53][@tfnw][The second and third parameters in the compare and swap] [1:14:39][handmade_intrinsics.h: Swap those parameters in AtomicCompareExchangeUInt32 and then swap them back and instead change the funtions where it's called] [1:16:54][@soysaucethekid][The audio seems to be frame rate dependent at the moment. Could putting it in a separate thread or using interrupts (if you can), make it not frame rate dependent?] [1:18:35][@tfnw][Would you mind adding a __sync_val_compare_and_swap(Value, Expected, New) for gcc / clang] [1:18:55][handmade_intrinsics.h: Add tfnw's suggestion] [1:20:50][handmade.cpp: Play the music instead of the bloop, to demonstrate playing the same sound simultaneously] [1:22:14][@robrobby][So why does it work?] [1:22:54][Blackboard: Separating asset data from instance data] [1:24:35][@cubercaleb][Why use a linked list as opposed to another data structure like a vector?] [1:25:52][@waterlimon][But can you take the output of the sound summer mechanism and play that?] [1:26:08][Go ahead and call it][:speech] [/video]