From 0093534eb3e527ff58ec2deae4af1fb3e78f8b28 Mon Sep 17 00:00:00 2001 From: JoseAaronLopezGarcia Date: Fri, 1 Dec 2023 03:17:52 +0100 Subject: [PATCH] fix audio loss --- common/include/globals.h | 2 +- extras/menus/arkMenu/include/music_player.h | 2 +- extras/menus/arkMenu/src/entry.cpp | 8 +++---- extras/menus/arkMenu/src/multimedia/mp3.cpp | 24 +++++++++++---------- extras/menus/arkMenu/src/music_player.cpp | 14 ++++++++---- 5 files changed, 28 insertions(+), 22 deletions(-) diff --git a/common/include/globals.h b/common/include/globals.h index 31b543dff..e54fd1c15 100644 --- a/common/include/globals.h +++ b/common/include/globals.h @@ -74,7 +74,7 @@ #define ARK_MAJOR_VERSION 4 #define ARK_MINOR_VERSION 20 #define ARK_MICRO_VERSION 66 -#define ARK_REVISION 6 +#define ARK_REVISION 7 #define MAX_FLASH0_SIZE 0x32000 /* diff --git a/extras/menus/arkMenu/include/music_player.h b/extras/menus/arkMenu/include/music_player.h index feb321b14..75e4a9542 100644 --- a/extras/menus/arkMenu/include/music_player.h +++ b/extras/menus/arkMenu/include/music_player.h @@ -21,8 +21,8 @@ class MusicPlayer : public OptionsMenu{ int control(); static void pauseResume(); - static void stopPlayList(); static bool isPlaying(); + static void fullStop(); }; diff --git a/extras/menus/arkMenu/src/entry.cpp b/extras/menus/arkMenu/src/entry.cpp index 0b646fea8..212718bc3 100644 --- a/extras/menus/arkMenu/src/entry.cpp +++ b/extras/menus/arkMenu/src/entry.cpp @@ -122,11 +122,7 @@ void Entry::gameBoot(){ if (common::getConf()->fast_gameboot) return; - while (MP3::isPlaying()){ - MusicPlayer::stopPlayList(); - MP3::fullStop(); - sceKernelDelayThread(1000); - } + MusicPlayer::fullStop(); SystemMgr::pauseDraw(); @@ -272,6 +268,8 @@ bool Entry::pmfPrompt(){ bool ret; SystemMgr::pauseDraw(); + + MusicPlayer::fullStop(); animAppear(); diff --git a/extras/menus/arkMenu/src/multimedia/mp3.cpp b/extras/menus/arkMenu/src/multimedia/mp3.cpp index 91b93e6b3..8ce39fd54 100644 --- a/extras/menus/arkMenu/src/multimedia/mp3.cpp +++ b/extras/menus/arkMenu/src/multimedia/mp3.cpp @@ -8,11 +8,11 @@ //static char mp3Buf[MP3BUF_SIZE] __attribute__((aligned(64))); //static short pcmBuf[PCMBUF_SIZE] __attribute__((aligned(64))); -static int running = 0; -static int eof = 0; +static bool running = false; +static bool eof = false; static SceUID mp3Thread = -1; static SceUID mp3_mutex = sceKernelCreateSema("mp3_mutex", 0, 1, 1, 0); -static int paused = 0; +static bool paused = false; bool fillStreamBuffer(int fd, int handle, void* buffer, int buffer_size) @@ -93,7 +93,7 @@ void playMP3File(char* filename, void* buffer, int buffer_size) { if (filename == NULL && buffer == NULL){ - running = 0; + running = false; return; } @@ -107,14 +107,14 @@ void playMP3File(char* filename, void* buffer, int buffer_size) if (filename != NULL){ file_handle = sceIoOpen(filename, PSP_O_RDONLY, 0777 ); if(file_handle < 0) { - running = 0; + running = false; return; } } status = sceMp3InitResource(); if(status < 0) { - running = 0; + running = false; return; } @@ -155,7 +155,7 @@ void playMP3File(char* filename, void* buffer, int buffer_size) } if (!running) - running = 1; + running = true; sceMp3SetLoopNum(mp3_handle, 0); @@ -163,6 +163,7 @@ void playMP3File(char* filename, void* buffer, int buffer_size) numChannels = sceMp3GetMp3ChannelNum(mp3_handle); max_sample = sceMp3GetMaxOutputSample(mp3_handle); + sceAudioSRCChRelease(); channel = sceAudioSRCChReserve(max_sample, samplingRate, numChannels); if (channel < 0) goto mp3_terminate; @@ -184,7 +185,6 @@ void playMP3File(char* filename, void* buffer, int buffer_size) // Decode some samples short* buf; unsigned int bytesDecoded; - int retries = 0; bytesDecoded = sceMp3Decode(mp3_handle, &buf); @@ -202,8 +202,10 @@ void playMP3File(char* filename, void* buffer, int buffer_size) mp3_terminate: // Cleanup time... - while (sceAudioSRCChRelease() < 0){ // wait for the audio to be outputted - sceKernelDelayThread(100); + if (channel >= 0){ + while (sceAudioSRCChRelease() < 0){ // wait for the audio to be outputted + sceKernelDelayThread(100); + } } status = sceMp3ReleaseMp3Handle( mp3_handle ); @@ -215,7 +217,7 @@ void playMP3File(char* filename, void* buffer, int buffer_size) file_handle = -1; mp3_handle = -1; - running = 0; + running = false; free(mp3Buf); free(pcmBuf); } diff --git a/extras/menus/arkMenu/src/music_player.cpp b/extras/menus/arkMenu/src/music_player.cpp index f7e902433..e6adf50e7 100644 --- a/extras/menus/arkMenu/src/music_player.cpp +++ b/extras/menus/arkMenu/src/music_player.cpp @@ -90,6 +90,8 @@ int MusicPlayer::control(){ SystemMgr::enterFullScreen(); + MP3::fullStop(); + if (current_song != NULL && this->path != current_song->getFilename() && playlist.size() == 0){ delete current_song; current_song = NULL; @@ -145,10 +147,14 @@ void MusicPlayer::pauseResume(){ if (current_song != NULL) current_song->pauseResume(); } -void MusicPlayer::stopPlayList(){ - if (current_song) current_song->on_music_end = NULL; -} - bool MusicPlayer::isPlaying(){ return (current_song != NULL && current_song->isPlaying() && !current_song->isPaused()); +} + +void MusicPlayer::fullStop(){ + if (current_song) current_song->on_music_end = NULL; + while (MP3::isPlaying()){ + MP3::fullStop(); + sceKernelDelayThread(1000); + } } \ No newline at end of file