Fix mp3 playback not being properly terminated

This commit is contained in:
Joel16 2019-05-21 00:16:39 -04:00
parent 51b53f8189
commit 1e35b40b4b

View File

@ -31,7 +31,7 @@ struct genre genreList[] = {
}; };
static mpg123_handle *mp3; static mpg123_handle *mp3;
static SceUInt64 frames_read = 0, total_samples = 0; static off_t frames_read = 0, total_samples = 0;
static long sample_rate = 0; static long sample_rate = 0;
static int channels = 0; static int channels = 0;
@ -175,7 +175,6 @@ int MP3_Init(const char *path) {
mpg123_getformat(mp3, &sample_rate, &channels, NULL); mpg123_getformat(mp3, &sample_rate, &channels, NULL);
mpg123_format_none(mp3); mpg123_format_none(mp3);
mpg123_format(mp3, 44100, channels, MPG123_ENC_SIGNED_16); mpg123_format(mp3, 44100, channels, MPG123_ENC_SIGNED_16);
total_samples = mpg123_length(mp3); total_samples = mpg123_length(mp3);
return 0; return 0;
} }
@ -189,11 +188,13 @@ SceUInt8 MP3_GetChannels(void) {
} }
void MP3_Decode(void *buf, unsigned int length, void *userdata) { void MP3_Decode(void *buf, unsigned int length, void *userdata) {
int ret = 0;
size_t done = 0; size_t done = 0;
mpg123_read(mp3, buf, length * (sizeof(SceInt16) * 2), &done);
frames_read += done/(sizeof(SceInt16) * 2);
if (frames_read >= total_samples) ret = mpg123_read(mp3, buf, length * (sizeof(SceInt16) * 2), &done);
frames_read = mpg123_tell(mp3);
if (frames_read >= total_samples || ret == MPG123_DONE)
playing = SCE_FALSE; playing = SCE_FALSE;
} }