From 01a61a33f87d54f2b4e2b15fcc1cb4c0b0f212c5 Mon Sep 17 00:00:00 2001 From: krcroft Date: Mon, 2 Dec 2019 19:10:58 -0800 Subject: [PATCH] Remove ineffective consts and indicate unused variables --- src/libs/decoders/flac.c | 1 + src/libs/decoders/mp3.cpp | 11 +++++----- src/libs/decoders/mp3_seek_table.cpp | 31 ++++++++++++++-------------- src/libs/decoders/mp3_seek_table.h | 2 +- src/libs/decoders/opus.c | 5 +++++ src/libs/decoders/vorbis.c | 1 + src/libs/decoders/wav.c | 1 + 7 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/libs/decoders/flac.c b/src/libs/decoders/flac.c index f309272f..a0df9273 100644 --- a/src/libs/decoders/flac.c +++ b/src/libs/decoders/flac.c @@ -91,6 +91,7 @@ static void FLAC_quit(void) static int FLAC_open(Sound_Sample *sample, const char *ext) { + (void) ext; // deliberately unused, but present for API compliance Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; drflac *dr = drflac_open(flac_read, flac_seek, sample, NULL); diff --git a/src/libs/decoders/mp3.cpp b/src/libs/decoders/mp3.cpp index 7a9d9c1b..2f6568d9 100644 --- a/src/libs/decoders/mp3.cpp +++ b/src/libs/decoders/mp3.cpp @@ -47,7 +47,7 @@ static size_t mp3_read(void* const pUserData, void* const pBufferOut, const size_t bytesToRead) { Uint8* ptr = static_cast(pBufferOut); - Sound_Sample* const sample = static_cast(pUserData); + Sound_Sample* const sample = static_cast(pUserData); const Sound_SampleInternal* const internal = static_cast(sample->opaque); SDL_RWops* rwops = internal->rw; size_t retval = 0; @@ -88,7 +88,7 @@ static void MP3_quit(void) static void MP3_close(Sound_Sample* const sample) { - Sound_SampleInternal* const internal = static_cast(sample->opaque); + Sound_SampleInternal* const internal = static_cast(sample->opaque); mp3_t* p_mp3 = static_cast(internal->decoder_private); if (p_mp3 != nullptr) { if (p_mp3->p_dr != nullptr) { @@ -103,7 +103,7 @@ static void MP3_close(Sound_Sample* const sample) static Uint32 MP3_read(Sound_Sample* const sample, void* buffer, Uint32 desired_frames) { - Sound_SampleInternal* const internal = static_cast(sample->opaque); + Sound_SampleInternal* const internal = static_cast(sample->opaque); mp3_t* p_mp3 = static_cast(internal->decoder_private); // LOG_MSG("read-while: num_frames: %u", num_frames); @@ -114,6 +114,7 @@ static Uint32 MP3_read(Sound_Sample* const sample, void* buffer, Uint32 desired_ static Sint32 MP3_open(Sound_Sample* const sample, const char* const ext) { + (void) ext; // deliberately unused Sound_SampleInternal* const internal = static_cast(sample->opaque); Sint32 result(0); // assume failure until proven otherwise mp3_t* p_mp3 = (mp3_t*) SDL_calloc(1, sizeof (mp3_t)); @@ -148,7 +149,7 @@ static Sint32 MP3_open(Sound_Sample* const sample, const char* const ext) MP3_close(sample); } - return static_cast(result); + return result; } /* MP3_open */ static Sint32 MP3_rewind(Sound_Sample* const sample) @@ -160,7 +161,7 @@ static Sint32 MP3_rewind(Sound_Sample* const sample) static Sint32 MP3_seek(Sound_Sample* const sample, const Uint32 ms) { - Sound_SampleInternal* const internal = static_cast(sample->opaque); + Sound_SampleInternal* const internal = static_cast(sample->opaque); mp3_t* p_mp3 = static_cast(internal->decoder_private); const float frames_per_ms = sample->actual.rate / 1000.0f; const drmp3_uint64 frame_offset = static_cast(frames_per_ms) * ms; diff --git a/src/libs/decoders/mp3_seek_table.cpp b/src/libs/decoders/mp3_seek_table.cpp index 84fa7191..a2606655 100644 --- a/src/libs/decoders/mp3_seek_table.cpp +++ b/src/libs/decoders/mp3_seek_table.cpp @@ -102,7 +102,7 @@ using std::ofstream; #define FRAMES_PER_SEEK_POINT 7 // Returns the size of a file in bytes (if valid), otherwise 0 -const size_t get_file_size(const char* filename) { +size_t get_file_size(const char* filename) { struct stat stat_buf; int rc = stat(filename, &stat_buf); return rc == 0 ? stat_buf.st_size : -1; @@ -119,15 +119,14 @@ const size_t get_file_size(const char* filename) { // 1. ID3 tag filler content, which might be boiler plate or all empty // 2. Trailing silence or similar zero-PCM content // -const Uint64 calculate_stream_hash(struct SDL_RWops* const context) { - +Uint64 calculate_stream_hash(struct SDL_RWops* const context) { // Save the current stream position, so we can restore it at the end of the function. const Sint64 original_pos = SDL_RWtell(context); // Seek to the end of the file so we can calculate the stream size. SDL_RWseek(context, 0, RW_SEEK_END); - const Sint32 stream_size = (Sint32) SDL_RWtell(context); + const Sint32 stream_size = SDL_RWtell(context); if (stream_size <= 0) { // LOG_MSG("MP3: get_stream_size returned %d, but should be positive", stream_size); return 0; @@ -175,12 +174,12 @@ const Uint64 calculate_stream_hash(struct SDL_RWops* const context) { // This function generates a new seek-table for a given mp3 stream and writes // the data to the fast-seek file. // -const Uint64 generate_new_seek_points(const char* filename, - const Uint64& stream_hash, - drmp3* const p_dr, - map >& seek_points_table, - map& pcm_frame_count_table, - vector& seek_points_vector) { +Uint64 generate_new_seek_points(const char* filename, + const Uint64& stream_hash, + drmp3* const p_dr, + map >& seek_points_table, + map& pcm_frame_count_table, + vector& seek_points_vector) { // Initialize our frame counters with zeros. drmp3_uint64 mp3_frame_count(0); @@ -244,11 +243,11 @@ const Uint64 generate_new_seek_points(const char* filename, // This function attempts to fetch a seek-table for a given mp3 stream from the fast-seek file. // If anything is amiss then this function fails. // -const Uint64 load_existing_seek_points(const char* filename, - const Uint64& stream_hash, - map >& seek_points_table, - map& pcm_frame_count_table, - vector& seek_points) { +Uint64 load_existing_seek_points(const char* filename, + const Uint64& stream_hash, + map >& seek_points_table, + map& pcm_frame_count_table, + vector& seek_points) { // The below sentinals sanity check and read the incoming // file one-by-one until all the data can be trusted. @@ -301,7 +300,7 @@ const Uint64 load_existing_seek_points(const char* filename, // attempting to read it from the fast-seek file and (if it can't be read for any reason), it // calculates new data. It makes use of the above two functions. // -const Uint64 populate_seek_points(struct SDL_RWops* const context, mp3_t* p_mp3, const char* seektable_filename) { +Uint64 populate_seek_points(struct SDL_RWops* const context, mp3_t* p_mp3, const char* seektable_filename) { // Calculate the stream's xxHash value. Uint64 stream_hash = calculate_stream_hash(context); diff --git a/src/libs/decoders/mp3_seek_table.h b/src/libs/decoders/mp3_seek_table.h index 52f5e3a4..16a8f89e 100644 --- a/src/libs/decoders/mp3_seek_table.h +++ b/src/libs/decoders/mp3_seek_table.h @@ -54,4 +54,4 @@ struct mp3_t { std::vector seek_points_vector; }; -const Uint64 populate_seek_points(struct SDL_RWops* const context, mp3_t* p_mp3, const char* seektable_filename); +Uint64 populate_seek_points(struct SDL_RWops* const context, mp3_t* p_mp3, const char* seektable_filename); diff --git a/src/libs/decoders/opus.c b/src/libs/decoders/opus.c index ae41e140..77233b66 100644 --- a/src/libs/decoders/opus.c +++ b/src/libs/decoders/opus.c @@ -140,6 +140,7 @@ static Sint32 RWops_opus_seek(void* stream, const opus_int64 offset, const Sint3 */ static Sint32 RWops_opus_close(void* stream) { + (void) stream; // deliberately unused, but present for API compliance /* SDL closes this for us */ // return SDL_RWclose((SDL_RWops*)stream); return 0; @@ -188,6 +189,9 @@ static __inline__ void output_opus_info(const OggOpusFile* of, const OpusHead* o SNDDBG(("Opus: user comment: '%s'\n", ot->user_comments[i])); } } +#else + (void) of; // unused if DEBUG_CHATTER not defined + (void) oh; // unused if DEBUG_CHATTER not defined #endif } /* output_opus_comments */ @@ -199,6 +203,7 @@ static __inline__ void output_opus_info(const OggOpusFile* of, const OpusHead* o */ static Sint32 opus_open(Sound_Sample* sample, const char* ext) { + (void) ext; // deliberately unused, but present for API compliance Sint32 rcode; Sound_SampleInternal* internal = (Sound_SampleInternal*)sample->opaque; OggOpusFile* of = op_open_callbacks(internal->rw, &RWops_opus_callbacks, NULL, 0, &rcode); diff --git a/src/libs/decoders/vorbis.c b/src/libs/decoders/vorbis.c index ca545a6f..771b0d5c 100644 --- a/src/libs/decoders/vorbis.c +++ b/src/libs/decoders/vorbis.c @@ -115,6 +115,7 @@ static void VORBIS_quit(void) static int VORBIS_open(Sound_Sample *sample, const char *ext) { + (void) ext; // deliberately unused, but present for API compliance Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; SDL_RWops *rw = internal->rw; int err = 0; diff --git a/src/libs/decoders/wav.c b/src/libs/decoders/wav.c index 3ad1e0a0..b01974df 100644 --- a/src/libs/decoders/wav.c +++ b/src/libs/decoders/wav.c @@ -89,6 +89,7 @@ static void WAV_close(Sound_Sample *sample) static int WAV_open(Sound_Sample *sample, const char *ext) { + (void) ext; // deliberately unused, but present for API compliance Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; drwav* dr = SDL_malloc(sizeof(drwav)); drwav_result result = drwav_init_ex(dr, wav_read, wav_seek, NULL, sample, NULL, 0, NULL);