Skip to content

Commit

Permalink
fix audio loss
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseAaronLopezGarcia committed Dec 1, 2023
1 parent 5269b41 commit 0093534
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion common/include/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

/*
Expand Down
2 changes: 1 addition & 1 deletion extras/menus/arkMenu/include/music_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class MusicPlayer : public OptionsMenu{
int control();

static void pauseResume();
static void stopPlayList();
static bool isPlaying();
static void fullStop();

};

Expand Down
8 changes: 3 additions & 5 deletions extras/menus/arkMenu/src/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -272,6 +268,8 @@ bool Entry::pmfPrompt(){
bool ret;

SystemMgr::pauseDraw();

MusicPlayer::fullStop();

animAppear();

Expand Down
24 changes: 13 additions & 11 deletions extras/menus/arkMenu/src/multimedia/mp3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -93,7 +93,7 @@ void playMP3File(char* filename, void* buffer, int buffer_size)
{

if (filename == NULL && buffer == NULL){
running = 0;
running = false;
return;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -155,14 +155,15 @@ void playMP3File(char* filename, void* buffer, int buffer_size)
}

if (!running)
running = 1;
running = true;

sceMp3SetLoopNum(mp3_handle, 0);

samplingRate = sceMp3GetSamplingRate(mp3_handle);
numChannels = sceMp3GetMp3ChannelNum(mp3_handle);
max_sample = sceMp3GetMaxOutputSample(mp3_handle);

sceAudioSRCChRelease();
channel = sceAudioSRCChReserve(max_sample, samplingRate, numChannels);

if (channel < 0) goto mp3_terminate;
Expand All @@ -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);

Expand All @@ -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 );
Expand All @@ -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);
}
Expand Down
14 changes: 10 additions & 4 deletions extras/menus/arkMenu/src/music_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 0093534

Please sign in to comment.