Skip to content

Commit

Permalink
update SDL_sound_mp3.c after drmp3 api changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
sezero committed Mar 7, 2025
1 parent 05bc91c commit 0af406e
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/SDL_sound_mp3.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,33 @@ static size_t mp3_read(void* pUserData, void* pBufferOut, size_t bytesToRead)

static drmp3_bool32 mp3_seek(void* pUserData, int offset, drmp3_seek_origin origin)
{
const int whence = (origin == drmp3_seek_origin_start) ? SDL_IO_SEEK_SET : SDL_IO_SEEK_CUR;
Sound_Sample *sample = (Sound_Sample *) pUserData;
Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
int whence;
switch (origin) {
case drmp3_seek_origin_start:
whence = SDL_IO_SEEK_SET;
break;
case drmp3_seek_origin_current:
whence = SDL_IO_SEEK_CUR;
break;
case drmp3_seek_origin_end:
whence = SDL_IO_SEEK_END;
break;
default:
return DRMP3_FALSE;
}
return (SDL_SeekIO(internal->rw, offset, whence) != -1) ? DRMP3_TRUE : DRMP3_FALSE;
} /* mp3_seek */

static drmp3_bool32 mp3_tell(void* pUserData, drmp3_int64* pCursor)
{
Sound_Sample *sample = (Sound_Sample *) pUserData;
Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
*pCursor = SDL_TellIO(internal->rw);
return (*pCursor != -1) ? DRMP3_TRUE : DRMP3_FALSE;
} /* mp3_tell */


static bool MP3_init(void)
{
Expand All @@ -80,7 +101,7 @@ static int MP3_open(Sound_Sample *sample, const char *ext)
Uint64 frames;

BAIL_IF_MACRO(!dr, ERR_OUT_OF_MEMORY, 0);
if (drmp3_init(dr, mp3_read, mp3_seek, sample, NULL) != DRMP3_TRUE)
if (drmp3_init(dr, mp3_read, mp3_seek, mp3_tell, NULL, sample, NULL) != DRMP3_TRUE)
{
SDL_free(dr);
BAIL_IF_MACRO(sample->flags & SOUND_SAMPLEFLAG_ERROR, ERR_IO_ERROR, 0);
Expand Down

0 comments on commit 0af406e

Please sign in to comment.