Added audio playback
Playing music
This commit is contained in:
33
code/first.c
33
code/first.c
@@ -25,6 +25,8 @@
|
||||
#include "game/impl/npc.c"
|
||||
#include "game/impl/bandit.c"
|
||||
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
(void) argc;
|
||||
@@ -43,30 +45,6 @@ int main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
SDL_AudioStream *austream;
|
||||
Str8 audio_data;
|
||||
M_TempScope(0, 0) {
|
||||
SDL_AudioSpec spec;
|
||||
spec.format = SDL_AUDIO_S16LE;
|
||||
spec.channels = 2;
|
||||
spec.freq = 44100;
|
||||
|
||||
austream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &spec, 0, 0);
|
||||
|
||||
if (!austream) {
|
||||
printf("Failed to open audio stream (%s)\n", SDL_GetError());
|
||||
}
|
||||
|
||||
Str8 exec = FS_SystemPath(temp.arena, FS_SYSTEM_PATH_EXE);
|
||||
Str8 path = Sf(temp.arena, "%.*s/assets/outside_ambience.wav", Sv(exec));
|
||||
|
||||
SDL_AudioSpec wav_spec;
|
||||
U32 count;
|
||||
|
||||
SDL_LoadWAV((const char *) path.data, &wav_spec, &audio_data.data, &count);
|
||||
audio_data.count = count;
|
||||
}
|
||||
|
||||
Vk_Setup(window);
|
||||
|
||||
G_State *game = 0;
|
||||
@@ -83,6 +61,13 @@ int main(int argc, char **argv)
|
||||
G_PipelinesLoad(game);
|
||||
G_AudioLoad(game);
|
||||
|
||||
Audio_Context *audio = M_ArenaPush(game->arena, Audio_Context);
|
||||
Audio_Init(game->arena, audio, 0.15f);
|
||||
|
||||
Audio_Play(audio, 1);
|
||||
|
||||
SDL_ResumeAudioStreamDevice(audio->stream);
|
||||
|
||||
G_Camera *camera = &game->camera;
|
||||
|
||||
camera->x = V3F(1, 0, 0);
|
||||
|
||||
Reference in New Issue
Block a user