From 5d983dbccc95325f3175e28eb2a67ae5e286be51 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Wed, 25 Dec 2024 14:35:10 +0300 Subject: [PATCH] disable several MS Visual Studio warnings and fix those ones in example programs. --- examples/playsound.c | 12 ++++++------ examples/playsound_simple.c | 5 ++--- src/SDL_sound_internal.h | 11 +++++++++++ 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/examples/playsound.c b/examples/playsound.c index 24f8132d..bb635452 100644 --- a/examples/playsound.c +++ b/examples/playsound.c @@ -208,7 +208,7 @@ static volatile playsound_global_state global_state; static Uint32 cvtMsToBytePos(Sound_AudioInfo *info, Uint32 ms) { /* "frames" == "sample frames" */ - float frames_per_ms = ((float) info->rate) / 1000.0; + float frames_per_ms = ((float) info->rate) / 1000.0f; Uint32 frame_offset = (Uint32) (frames_per_ms * ((float) ms)); Uint32 frame_size = (Uint32) ((info->format & 0xFF) / 8) * info->channels; return(frame_offset * frame_size); @@ -276,7 +276,7 @@ static int read_more_data(Sound_Sample *sample) } /* if */ if ((global_state.bytes_before_next_seek >= 0) && - (global_state.decoded_bytes > global_state.bytes_before_next_seek)) + (global_state.decoded_bytes > (Uint32)global_state.bytes_before_next_seek)) { global_state.decoded_bytes = global_state.bytes_before_next_seek; } /* if */ @@ -476,8 +476,8 @@ static void SDLCALL audio_callback(void *userdata, Uint8 *stream, int len) /* decoded_bytes and decoder_ptr are updated as necessary... */ cpysize = len - bw; - if (cpysize > global_state.decoded_bytes) - cpysize = global_state.decoded_bytes; + if (cpysize > (Sint32)global_state.decoded_bytes) + cpysize = (Sint32)global_state.decoded_bytes; if (cpysize > 0) { @@ -829,8 +829,8 @@ int main(int argc, char **argv) else if (SDL_strcmp(argv[i], "--volume") == 0 && argc > i + 1) { - global_state.volume = SDL_atof(argv[++i]); - if (global_state.volume != 1.0) + global_state.volume = (float)SDL_atof(argv[++i]); + if (global_state.volume != 1.0f) global_state.wants_volume_change = 1; } /* else if */ diff --git a/examples/playsound_simple.c b/examples/playsound_simple.c index e7200356..d8d94d54 100644 --- a/examples/playsound_simple.c +++ b/examples/playsound_simple.c @@ -78,8 +78,8 @@ static void SDLCALL audio_callback(void *userdata, Uint8 *stream, int len) /* we have data decoded and ready to write to the device... */ cpysize = len - bw; /* len - bw == amount device still wants. */ - if (cpysize > data->decoded_bytes) - cpysize = data->decoded_bytes; /* clamp to what we have left. */ + if (cpysize > (Sint32)data->decoded_bytes) + cpysize = (Sint32)data->decoded_bytes; /* clamp to what we have left. */ /* if it's 0, next iteration will decode more or decide we're done. */ if (cpysize > 0) @@ -96,7 +96,6 @@ static void SDLCALL audio_callback(void *userdata, Uint8 *stream, int len) } /* audio_callback */ - static void playOneSoundFile(const char *fname) { PlaysoundAudioCallbackData data; diff --git a/src/SDL_sound_internal.h b/src/SDL_sound_internal.h index b68d2f7f..7e4a036a 100644 --- a/src/SDL_sound_internal.h +++ b/src/SDL_sound_internal.h @@ -39,6 +39,17 @@ #define SNDDBG(x) #endif +/* disable several MS Visual Studio warnings: */ +#ifdef _MSC_VER +#pragma warning(disable:4100) /* unreferenced formal parameter */ +#pragma warning(disable:4389) /* signed/unsigned mismatch ( <, <=, >, >= ) */ +#pragma warning(disable:4018) /* signed/unsigned mismatch ( ==, != ) */ +#pragma warning(disable:4127) /* conditional expression is constant. */ +#pragma warning(disable:4761) /* integral size mismatch in argument; conversion supplied (for MSVC6 and older.) */ +#pragma warning(disable:4244) /* conversion from 'type' to 'int', possible loss of data */ +#pragma warning(disable:4267) /* conversion from 'size_t' to 'type', possible loss of data */ +#endif + #ifndef SOUND_SUPPORTS_MIDI #define SOUND_SUPPORTS_MIDI 1 #endif