diff options
author | Charlie Stanton <charlie@shtanton.xyz> | 2025-04-05 23:31:34 +0100 |
---|---|---|
committer | Charlie Stanton <charlie@shtanton.xyz> | 2025-04-05 23:31:34 +0100 |
commit | fa8d5f6a922f9159f8c050ea8b7fd6070475e00d (patch) | |
tree | dc42ce86f4cc5ce68d9f4349199c35b590d5a270 /src/all.c | |
parent | b41d2ab5e44647564572c5162bf3109de4aaac82 (diff) | |
download | ldjam57-fa8d5f6a922f9159f8c050ea8b7fd6070475e00d.tar |
Add music to SDL port
Diffstat (limited to 'src/all.c')
-rw-r--r-- | src/all.c | 21 |
1 files changed, 19 insertions, 2 deletions
@@ -139,7 +139,7 @@ static DrawList *render(State *state, UI *ui, Arena *a) { .h = cellHeight, .fill = {255, 0, 0, 63}, .border = {255, 0, 0, 255}, - .image = 5, + .image = 1, }; drawList->els[drawList->len++] = (DrawElement) { @@ -229,6 +229,10 @@ typedef struct { SDL_Texture *textures[sizeof(images) / sizeof(images[0])]; +#include "../build/music.c" + +SDL_AudioStream *stream; + int main(int argc, char **argv) { (void) argc; (void) argv; @@ -252,7 +256,7 @@ int main(int argc, char **argv) { game->state.buttonStates[i] = BUTTON_STATE_IDLE; } - SDL_Init(SDL_INIT_VIDEO); + SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO); SDL_Window *w = SDL_CreateWindow( "LDJam 57", game->ui.width, @@ -282,6 +286,15 @@ int main(int argc, char **argv) { } SDL_UpdateTexture(textures[j], NULL, pixels, images[j].width * 4); } + + SDL_AudioSpec audioSpec = { + .format = SDL_AUDIO_S16LE, + .channels = 2, + .freq = 48000, + }; + stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &audioSpec, NULL, NULL); + SDL_PutAudioStreamData(stream, musicBytes, sizeof(musicBytes)); + SDL_ResumeAudioStreamDevice(stream); for (;;) { uint64_t now = SDL_GetTicks(); @@ -351,6 +364,10 @@ int main(int argc, char **argv) { update(game, now, a); + if (SDL_GetAudioStreamQueued(stream) < (int) sizeof(musicBytes) / 8) { + SDL_PutAudioStreamData(stream, musicBytes, sizeof(musicBytes)); + } + SDL_RenderPresent(r); } |