audio tweaks so it still loads on windows w/o sdl2

This commit is contained in:
Noel Berry 2022-11-19 16:40:56 -08:00
parent c89535e328
commit 1b41632991
5 changed files with 19 additions and 9 deletions

View File

@ -45,6 +45,7 @@ if (WIN32)
endif()
option(BLAH_NO_FUNCTIONAL "Don't use std::function" OFF)
option(BLAH_NO_SHARED_PTR "Don't use std::shared_ptr for Resources" OFF)
option(BLAH_NO_THREADING "Don't use threading" OFF)
# tracks which libraries we need to link, depends on Options above
set(LIBS "")
@ -109,4 +110,7 @@ endif()
if (BLAH_NO_SHARED_PTR)
add_compile_definitions(BLAH_NO_SHARED_PTR)
endif()
if (BLAH_NO_THREADING)
add_compile_definitions(BLAH_NO_THREADING)
endif()

View File

@ -122,7 +122,7 @@ bool App::run(const Config* c)
#ifdef __EMSCRIPTEN__
more_on_emscripten = 4;
#endif
Blah::Internal::audio_is_init = Blah::Internal::audio_init(NULL, c->audio_frequency_in_Hz, 1024 * more_on_emscripten);
Blah::Internal::audio_is_init = Blah::Internal::audio_init(c->audio_frequency_in_Hz, 1024 * more_on_emscripten);
}
}

View File

@ -1,27 +1,34 @@
#include "blah_audio.h"
#include "blah_time.h"
#include "internal/blah_internal.h"
#define STB_VORBIS_HEADER_ONLY
#include "third_party/stb_vorbis.c"
#define CUTE_SOUND_IMPLEMENTATION
#ifdef BLAH_PLATFORM_SDL2
#define CUTE_SOUND_FORCE_SDL
#endif
#define CUTE_SOUND_IMPLEMENTATION
#include "third_party/cute_sound.h"
namespace Blah
{
namespace Internal
{
bool audio_init(void* os_handle, unsigned play_frequency_in_Hz, int buffered_samples)
bool audio_init(unsigned play_frequency_in_Hz, int buffered_samples)
{
cs_error_t err = cs_init(os_handle, play_frequency_in_Hz, buffered_samples, NULL);
cs_error_t err = cs_init(Internal::platform->d3d11_get_hwnd(), play_frequency_in_Hz, buffered_samples, NULL);
if (err != CUTE_SOUND_ERROR_NONE) {
Log::error(cs_error_as_string(err));
return false;
} else {
return true;
}
#ifndef BLAH_NO_THREADING
cs_spawn_mix_thread();
#endif
}
void audio_shutdown()

View File

@ -21,10 +21,9 @@ namespace Blah
void input_step_bindings();
void input_shutdown();
// Pass in NULL for `os_handle`, except for the DirectSound backend this should be hwnd.
// play_frequency_in_Hz depends on your audio file, 44100 seems to be fine.
// buffered_samples is clamped to be at least 1024.
bool audio_init(void* os_handle, unsigned play_frequency_in_Hz, int buffered_samples);
bool audio_init(unsigned play_frequency_in_Hz, int buffered_samples);
void audio_shutdown();
void audio_update();
}

View File

@ -364,7 +364,7 @@ bool Win32_Platform::init(const Config& config)
while (*end != 0) end++;
FilePath result;
result.append_utf16((u16*)path, (u16*)end);
result.append((u16*)path, (u16*)end);
user_directory = Path::join(Path::normalize(result), config.name) + "/";
}
@ -737,7 +737,7 @@ void Win32_Platform::open_url(const char* url)
void Win32_Platform::detect_joysticks()
{
auto platform = ((Win32_Platform*)App::Internal::platform);
auto platform = ((Win32_Platform*)Internal::platform);
// mark all joysticks as unnacounted for
for (int i = 0; i < Input::max_controllers; i++)
@ -806,7 +806,7 @@ void Win32_Platform::detect_joysticks()
LRESULT CALLBACK Blah::win32_window_procedure(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
auto platform = ((Win32_Platform*)App::Internal::platform);
auto platform = ((Win32_Platform*)Internal::platform);
auto input_state = platform->input_state;
switch (msg)