88
99#include < SDL3/SDL.h>
1010
11- #include < string >
11+ #include < cstring >
1212
1313// The only supported audio format
1414constexpr const SDL_AudioSpec sound_spec = { SDL_AUDIO_S16 , 2 , 44100 };
@@ -41,8 +41,8 @@ bool Sound::initialize()
4141 // load wave files
4242 if (!load (APP_DATADIR )) {
4343 // try portable variant
44- std::string path (SDL_GetBasePath ());
45- path + = " data" ;
44+ std::filesystem::path path (SDL_GetBasePath ());
45+ path / = " data" ;
4646 if (!load (path.c_str ())) {
4747 return false ;
4848 }
@@ -59,32 +59,32 @@ void Sound::play(Sound::Type type)
5959 }
6060}
6161
62- bool Sound::load (const char * dir)
62+ bool Sound::load (const std::filesystem::path& dir)
6363{
64- memset (waves, 0 , sizeof (waves));
65-
6664 for (size_t i = 0 ; i < sizeof (waves) / sizeof (waves[0 ]); ++i) {
6765 SDL_AudioSpec spec;
68- std::string file = dir;
66+ std::filesystem::path file = dir;
6967 switch (i) {
7068 case Clatz:
71- file + = " clatz.wav" ;
69+ file / = " clatz.wav" ;
7270 break ;
7371 case Complete:
74- file + = " complete.wav" ;
72+ file / = " complete.wav" ;
7573 break ;
7674 }
77- if (!SDL_LoadWAV (file.c_str (), &spec, &waves[i].data , &waves[i].size )) {
75+ const std::string wav_path = file.string ();
76+ if (!SDL_LoadWAV (wav_path.c_str (), &spec, &waves[i].data ,
77+ &waves[i].size )) {
7878 SDL_LogError (SDL_LOG_CATEGORY_AUDIO , " Error loading wav %s: %s" ,
79- file .c_str (), SDL_GetError ());
79+ wav_path .c_str (), SDL_GetError ());
8080 break ;
8181 }
8282 if (spec.format != sound_spec.format ||
8383 spec.channels != sound_spec.channels ||
8484 spec.freq != sound_spec.freq ) {
8585 SDL_LogError (SDL_LOG_CATEGORY_AUDIO ,
8686 " Error loading wav %s: unsupported format" ,
87- file .c_str ());
87+ wav_path .c_str ());
8888 break ;
8989 }
9090 }
@@ -93,7 +93,8 @@ bool Sound::load(const char* dir)
9393 SDL_free (waves[Clatz].data );
9494 SDL_free (waves[Complete].data );
9595 memset (waves, 0 , sizeof (waves));
96+ return false ;
9697 }
9798
98- return waves[Clatz]. data && waves[Complete]. data ;
99+ return true ;
99100}
0 commit comments