1515#include <unistd.h>
1616
1717#include <SDL.h>
18+ #if RV32_HAS (SDL_MIXER )
1819#include <SDL_mixer.h>
20+ #endif
1921
2022#include "riscv.h"
2123#include "riscv_private.h"
@@ -92,6 +94,7 @@ typedef struct sound {
9294} sound_t ;
9395
9496/* SDL-mixer-related and music-related variables */
97+ #if RV32_HAS (SDL_MIXER )
9598static pthread_t music_thread ;
9699static uint8_t * music_midi_data ;
97100static Mix_Music * mid ;
@@ -107,6 +110,7 @@ static int chan;
107110static bool audio_init = false;
108111static bool sfx_thread_init = false;
109112static bool music_thread_init = false;
113+ #endif
110114
111115typedef struct {
112116 void * data ;
@@ -718,6 +722,7 @@ uint8_t *mus2midi(uint8_t *data, int *length)
718722 return midi_data ;
719723}
720724
725+ #if RV32_HAS (SDL_MIXER )
721726static void * sfx_handler (void * arg )
722727{
723728 sound_t * sfx = (sound_t * ) arg ;
@@ -916,7 +921,9 @@ static void set_music_volume(riscv_t *rv)
916921 /* multiplied by 8 because volume's max is 15 */
917922 Mix_VolumeMusic (volume * 8 );
918923}
924+ #endif /* RV32_HAS(SDL_MIXER) */
919925
926+ #if RV32_HAS (SDL_MIXER )
920927static void init_audio (void )
921928{
922929 if (!(SDL_WasInit (-1 ) & SDL_INIT_AUDIO )) {
@@ -977,13 +984,16 @@ static void shutdown_audio()
977984
978985 audio_init = sfx_thread_init = music_thread_init = false;
979986}
987+ #endif
980988
981989void sdl_video_audio_cleanup ()
982990{
983991 if (window ) {
984992 SDL_DestroyWindow (window );
985993 window = NULL ;
986994 }
995+
996+ #if RV32_HAS (SDL_MIXER )
987997 /*
988998 * The sfx_or_music_thread_init flag might not be set if a quick ctrl-c
989999 * occurs while the audio configuration is being initialized. Therefore,
@@ -992,6 +1002,7 @@ void sdl_video_audio_cleanup()
9921002 bool sfx_or_music_thread_init = sfx_thread_init | music_thread_init ;
9931003 if (sfx_or_music_thread_init || (!sfx_or_music_thread_init && audio_init ))
9941004 shutdown_audio ();
1005+ #endif
9951006 SDL_Quit ();
9961007}
9971008
@@ -1002,10 +1013,14 @@ void syscall_setup_audio(riscv_t *rv)
10021013
10031014 switch (request ) {
10041015 case INIT_AUDIO :
1016+ #if RV32_HAS (SDL_MIXER )
10051017 init_audio ();
1018+ #endif
10061019 break ;
10071020 case SHUTDOWN_AUDIO :
1021+ #if RV32_HAS (SDL_MIXER )
10081022 shutdown_audio ();
1023+ #endif
10091024 break ;
10101025 default :
10111026 rv_log_error ("Unknown sound request: %d" , request );
@@ -1020,16 +1035,24 @@ void syscall_control_audio(riscv_t *rv)
10201035
10211036 switch (request ) {
10221037 case PLAY_MUSIC :
1038+ #if RV32_HAS (SDL_MIXER )
10231039 play_music (rv );
1040+ #endif
10241041 break ;
10251042 case PLAY_SFX :
1043+ #if RV32_HAS (SDL_MIXER )
10261044 play_sfx (rv );
1045+ #endif
10271046 break ;
10281047 case SET_MUSIC_VOLUME :
1048+ #if RV32_HAS (SDL_MIXER )
10291049 set_music_volume (rv );
1050+ #endif
10301051 break ;
10311052 case STOP_MUSIC :
1053+ #if RV32_HAS (SDL_MIXER )
10321054 stop_music ();
1055+ #endif
10331056 break ;
10341057 default :
10351058 rv_log_error ("Unknown sound control request: %d" , request );
0 commit comments