Skip to content

Commit

Permalink
player: change long types to size_t or uint32_t
Browse files Browse the repository at this point in the history
changed to size_t for sizes of memory chunks.
changed to uint32_t for counts, time durations, and sample rates.
also changed sssize_t to the more widely supported ptrdiff_t
  • Loading branch information
myQwil committed Feb 26, 2025
1 parent 012c573 commit 5049952
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion player/Archive_Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ gme_err_t Zip_Reader::open( const char* path )

gme_err_t Zip_Reader::next( void* buf_ptr, arc_entry_t* entry )
{
ssize_t res;
ptrdiff_t res;
if ( (res = archive_read_next_header( zip, &head )) != ARCHIVE_OK )
return (res == ARCHIVE_EOF) ? arc_eof : archive_error_string( zip );

Expand Down
4 changes: 2 additions & 2 deletions player/Archive_Reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ struct arc_entry_t {
class Archive_Reader {
protected:
int count_ = 0;
long size_ = 0;
size_t size_ = 0;
public:
int count() const { return count_; }
long size() const { return size_; }
size_t size() const { return size_; }
virtual gme_err_t open( const char* path ) = 0;
virtual gme_err_t next( void* buf_ptr, arc_entry_t* entry ) = 0;
virtual ~Archive_Reader() { }
Expand Down
6 changes: 3 additions & 3 deletions player/Audio_Scope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ std::string Audio_Scope::init( int width, int height )
return std::string(); // success
}

const char* Audio_Scope::draw( const short* in, long count, int step )
const char* Audio_Scope::draw( const short* in, uint32_t count, int step )
{
if ( count >= buf_size )
{
Expand All @@ -141,9 +141,9 @@ const char* Audio_Scope::draw( const short* in, long count, int step )
return 0; // success
}

void Audio_Scope::render( short const* in, long count, int step )
void Audio_Scope::render( short const* in, uint32_t count, int step )
{
for( long i = 0; i < count; i++ )
for( uint32_t i = 0; i < count; i++ )
{
// Average left, right channels
int sample = (0x7FFF * 2 - in [i * step] - in [i * step + 1]) >> sample_shift;
Expand Down
6 changes: 3 additions & 3 deletions player/Audio_Scope.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Audio_Scope {
// Draw at most 'count' samples from 'in', skipping 'step' samples after
// each sample drawn. Step should be 2 but wouldn't be hard to adapt
// to be 1.
gme_err_t draw( const short* in, long count, int step = 2 );
gme_err_t draw( const short* in, uint32_t count, int step = 2 );

Audio_Scope();
~Audio_Scope();
Expand All @@ -29,12 +29,12 @@ class Audio_Scope {
SDL_Window* window;
SDL_Renderer* window_renderer;
SDL_Point* scope_lines = nullptr; // lines to be drawn each frame
int buf_size;
unsigned int buf_size;
int scope_height;
int sample_shift;
int v_offset;

void render( short const* in, long count, int step );
void render( short const* in, uint32_t count, int step );
};

#endif
8 changes: 4 additions & 4 deletions player/Music_Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static const int fill_rate = 80;

// Simple sound driver using SDL
typedef void (*sound_callback_t)( void* data, short* out, int count );
static const char* sound_init( long sample_rate, int buf_size, sound_callback_t, void* data );
static const char* sound_init( uint32_t sample_rate, int buf_size, sound_callback_t, void* data );
static void sound_start();
static void sound_stop();
static void sound_cleanup();
Expand Down Expand Up @@ -65,7 +65,7 @@ Music_Player::Music_Player()
track_info_ = nullptr;
}

gme_err_t Music_Player::init( long rate )
gme_err_t Music_Player::init( uint32_t rate )
{
sample_rate = rate;

Expand Down Expand Up @@ -225,7 +225,7 @@ gme_err_t Music_Player::start_track( int track )
track_info_->loop_length * 2;

if ( track_info_->length <= 0 )
track_info_->length = (long) (2.5 * 60 * 1000);
track_info_->length = (uint32_t) (2.5 * 60 * 1000);
gme_set_fade_msecs( emu_, track_info_->length, 8000 );

paused = false;
Expand Down Expand Up @@ -344,7 +344,7 @@ static void sdl_callback( void* /* data */, Uint8* out, int count )
sound_callback( sound_callback_data, (short*) out, count / 2 );
}

static const char* sound_init( long sample_rate, int buf_size,
static const char* sound_init( uint32_t sample_rate, int buf_size,
sound_callback_t cb, void* data )
{
sound_callback = cb;
Expand Down
5 changes: 3 additions & 2 deletions player/Music_Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
#define MUSIC_PLAYER_H

#include "gme/gme.h"
#include <cstdint>

class Music_Player {
public:
// Initialize player and set sample rate
gme_err_t init( long sample_rate = 44100 );
gme_err_t init( uint32_t sample_rate = 44100 );

// Load game music file. NULL on success, otherwise error string.
gme_err_t load_file( const char* path, bool by_mem );
Expand Down Expand Up @@ -72,7 +73,7 @@ class Music_Player {
private:
Music_Emu* emu_;
sample_t* scope_buf;
long sample_rate;
uint32_t sample_rate;
int scope_buf_size;
bool paused;
gme_info_t* track_info_;
Expand Down
4 changes: 2 additions & 2 deletions player/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static void start_track( int track, const char* path )

// update window title with track info

long seconds = player->track_info().length / 1000;
uint32_t seconds = player->track_info().length / 1000;
const char* game = player->track_info().game;
if ( !*game )
{
Expand All @@ -95,7 +95,7 @@ static void start_track( int track, const char* path )
}

char title [512];
if ( 0 < snprintf( title, sizeof title, "%s: %d/%d %s (%ld:%02ld)",
if ( 0 < snprintf( title, sizeof title, "%s: %d/%d %s (%d:%02d)",
game, track, player->track_count(), player->track_info().song,
seconds / 60, seconds % 60 ) )
{
Expand Down

0 comments on commit 5049952

Please sign in to comment.