Platform-independent Sound Output
?
?

Keyboard Navigation

Global Keys

[, < / ], > Jump to previous / next episode
W, K, P / S, J, N Jump to previous / next marker
t / T Toggle theatre / SUPERtheatre mode
z Toggle filter mode V Revert filter to original state

Menu toggling

q Quotes r References f Filter c Credits

In-Menu Movement

a
w
s
d
h j k l


Quotes and References Menus

Enter Jump to timecode

Quotes, References and Credits Menus

o Open URL (in new tab)

Filter Menu

x, Space Toggle category and focus next
X, ShiftSpace Toggle category and focus previous
v Invert topics / media as per focus

Credits Menu

Enter Open URL (in new tab)
0:57Review basics of platform API design
0:57Review basics of platform API design
0:57Review basics of platform API design
3:54What the API needs to support
3:54What the API needs to support
3:54What the API needs to support
4:53Starting with moving sound across the API boundary
4:53Starting with moving sound across the API boundary
4:53Starting with moving sound across the API boundary
10:30How most games deal with time (poorly)
10:30How most games deal with time (poorly)
10:30How most games deal with time (poorly)
11:06What we are going to do
11:06What we are going to do
11:06What we are going to do
14:55Moving sound generation across the boundary
14:55Moving sound generation across the boundary
14:55Moving sound generation across the boundary
19:30Finding the seams
19:30Finding the seams
19:30Finding the seams
22:49Dealing with sound buffers abstractly
22:49Dealing with sound buffers abstractly
22:49Dealing with sound buffers abstractly
25:50Allocating a game sound buffer
25:50Allocating a game sound buffer
25:50Allocating a game sound buffer
29:33Tangent: buffer overruns and how the debugger helps
29:33Tangent: buffer overruns and how the debugger helps
29:33Tangent: buffer overruns and how the debugger helps
31:09Actually using the game-generated sound
31:09Actually using the game-generated sound
31:09Actually using the game-generated sound
37:01Cleaning up the old stuff
37:01Cleaning up the old stuff
37:01Cleaning up the old stuff
42:16A step back
42:16A step back
42:16A step back
43:30Tangent: memory management & alloca
43:30Tangent: memory management & alloca
43:30Tangent: memory management & alloca
47:57Nevermind, we'll put it on the heap
47:57Nevermind, we'll put it on the heap
47:57Nevermind, we'll put it on the heap
50:57Review
50:57Review
50:57Review
53:54The remaining jank
53:54The remaining jank
53:54The remaining jank
57:27Tweak the build.bat
57:27Tweak the build.bat
57:27Tweak the build.bat
58:47Final Thoughts
58:47Final Thoughts
58:47Final Thoughts
59:30Q&A
🗩
59:30Q&A
🗩
59:30Q&A
🗩
1:00:16Will we use alloca to store pointers to game objects that are local to the player?
1:00:16Will we use alloca to store pointers to game objects that are local to the player?
1:00:16Will we use alloca to store pointers to game objects that are local to the player?
1:04:29If the DirectSound Lock fails, you'll pass garbage pointers to the game logic.
1:04:29If the DirectSound Lock fails, you'll pass garbage pointers to the game logic.
1:04:29If the DirectSound Lock fails, you'll pass garbage pointers to the game logic.
1:05:31When you say 60fps may not be feasible do you mean on non-PC platforms?
1:05:31When you say 60fps may not be feasible do you mean on non-PC platforms?
1:05:31When you say 60fps may not be feasible do you mean on non-PC platforms?
1:07:50Are we not worried about clean builds?
1:07:50Are we not worried about clean builds?
1:07:50Are we not worried about clean builds?
1:08:37Allocating every frame was your bug with alloca. You were calling it in a loop.
1:08:37Allocating every frame was your bug with alloca. You were calling it in a loop.
1:08:37Allocating every frame was your bug with alloca. You were calling it in a loop.
1:12:26Can you explain again why our current sound buffer fill is problematic?
1:12:26Can you explain again why our current sound buffer fill is problematic?
1:12:26Can you explain again why our current sound buffer fill is problematic?
1:15:43Wouldn't updating graphics and sound on the same frame cause audio lag?
1:15:43Wouldn't updating graphics and sound on the same frame cause audio lag?
1:15:43Wouldn't updating graphics and sound on the same frame cause audio lag?
1:17:08Since alloca is just a function call, how does the compiler know to free the memory?
1:17:08Since alloca is just a function call, how does the compiler know to free the memory?
1:17:08Since alloca is just a function call, how does the compiler know to free the memory?
1:17:44Will we spilt game sound update out of GameUpdateAndRender so we can use it as a callback or on a different thread?
1:17:44Will we spilt game sound update out of GameUpdateAndRender so we can use it as a callback or on a different thread?
1:17:44Will we spilt game sound update out of GameUpdateAndRender so we can use it as a callback or on a different thread?
1:18:16alloca is deprecated, we should use malloca.
1:18:16alloca is deprecated, we should use malloca.
1:18:16alloca is deprecated, we should use malloca.
1:20:17can you provide a log of the chat on the website?
1:20:17can you provide a log of the chat on the website?
1:20:17can you provide a log of the chat on the website?
1:20:43malloca allocs on the stack if less than 1kB and malloc's if greater.
1:20:43malloca allocs on the stack if less than 1kB and malloc's if greater.
1:20:43malloca allocs on the stack if less than 1kB and malloc's if greater.
1:21:33How can you safely predict where the flip happens so you can write sound there?
1:21:33How can you safely predict where the flip happens so you can write sound there?
1:21:33How can you safely predict where the flip happens so you can write sound there?
1:24:54We know that you can't go below 30fps for 'smooth' video. Is there a similar rule of thumb for audio?
1:24:54We know that you can't go below 30fps for 'smooth' video. Is there a similar rule of thumb for audio?
1:24:54We know that you can't go below 30fps for 'smooth' video. Is there a similar rule of thumb for audio?
1:26:29alloca is deprecated because.... [There are better options.]
1:26:29alloca is deprecated because.... [There are better options.]
1:26:29alloca is deprecated because.... [There are better options.]
1:30:49How do you do 2 voices in 1 buffer?
1:30:49How do you do 2 voices in 1 buffer?
1:30:49How do you do 2 voices in 1 buffer?
1:30:58When will the first sprite be displayed in animation?
1:30:58When will the first sprite be displayed in animation?
1:30:58When will the first sprite be displayed in animation?
1:31:11I've heard the brain treats sounds within 10ms as in-sync?
1:31:11I've heard the brain treats sounds within 10ms as in-sync?
1:31:11I've heard the brain treats sounds within 10ms as in-sync?
1:31:39When you work with temporary memory are there dangers? How do we protect against them?
1:31:39When you work with temporary memory are there dangers? How do we protect against them?
1:31:39When you work with temporary memory are there dangers? How do we protect against them?
1:33:21As a rhythm game player, I can notice audio sync off as little as 10ms...
1:33:21As a rhythm game player, I can notice audio sync off as little as 10ms...
1:33:21As a rhythm game player, I can notice audio sync off as little as 10ms...
1:35:03Sign Off
🗩
1:35:03Sign Off
🗩
1:35:03Sign Off
🗩

Platform-independent Sound Output

Key ideas:

  • Sound is necessarily temporal. You can drop a frame of video and the user probably won't notice, but if your audio drops out, they probably will notice.
  • Sound bufers are small, and not all platforms will require us to deal with circular buffers. So one option is to do a buffer copy per frame and present the game with a contiguous block of memory. This should be cheap enough.
  • Much like the bitmap, allocate plenty of space for a sound buffer at startup, and reuse it each frame.

C features

alloca

alloca is a compiler feature that allows for dynamic allocation on the stack. Much was learned and discussed, but it should be noted that the function is deprecated and probably shouldn't be used in shipping code.