diff --git a/RetroFE/Source/Execute/Launcher.cpp b/RetroFE/Source/Execute/Launcher.cpp index 6c8d203..aa17b73 100755 --- a/RetroFE/Source/Execute/Launcher.cpp +++ b/RetroFE/Source/Execute/Launcher.cpp @@ -119,12 +119,19 @@ bool Launcher::run(std::string collection, Item *collectionItem) selectedItemsDirectory, collection); + /* Restart audio amp */ + popen(SHELL_CMD_TURN_AMPLI_ON, "r"); + + /* Execute game */ if(!execute(executablePath, args, currentDirectory)) { Logger::write(Logger::ZONE_ERROR, "Launcher", "Failed to launch."); res = false; } + /* Stop audio amp */ + popen(SHELL_CMD_TURN_AMPLI_OFF, "r"); + /* Restore stored PID */ char shellCmd[20]; sprintf(shellCmd, "%s %d", SHELL_CMD_RECORD_PID, getpid()); diff --git a/RetroFE/Source/Sound/Sound.cpp b/RetroFE/Source/Sound/Sound.cpp index 41fc1f1..a576a91 100755 --- a/RetroFE/Source/Sound/Sound.cpp +++ b/RetroFE/Source/Sound/Sound.cpp @@ -17,6 +17,10 @@ #include "Sound.h" #include "../Utility/Log.h" +#include "../Utility/Utils.h" + +SDL_TimerID Sound::idTimer = 0; +int Sound::ampliStarted = 0; Sound::Sound(std::string file, std::string altfile) : file_(file) @@ -44,14 +48,40 @@ Sound::~Sound() void Sound::play() { + //printf("%s\n", __func__); + SDL_RemoveTimer(idTimer); + if(!ampliStarted){ + popen(SHELL_CMD_TURN_AMPLI_ON, "r"); + ampliStarted = 1; + } + if(chunk_) { channel_ = Mix_PlayChannel(-1, chunk_, 0); + Mix_ChannelFinished(finished); + } +} + +uint32_t Sound::turnOffAmpli(uint32_t interval, void *param) +{ + //printf("%s\n", __func__); + popen(SHELL_CMD_TURN_AMPLI_OFF, "r"); + ampliStarted = 0; + return 0; +} + +void Sound::finished(int channel) +{ + //printf("%s\n", __func__); + if((channel == -1) || !Mix_Playing(channel)){ + SDL_RemoveTimer(idTimer); + idTimer = SDL_AddTimer(500, turnOffAmpli, NULL); } } bool Sound::free() { + //printf("%s\n", __func__); if(chunk_) { Mix_FreeChunk(chunk_); @@ -64,6 +94,7 @@ bool Sound::free() bool Sound::allocate() { + //printf("%s\n", __func__); if(!chunk_) { chunk_ = Mix_LoadWAV(file_.c_str()); @@ -75,5 +106,6 @@ bool Sound::allocate() bool Sound::isPlaying() { + //printf("%s\n", __func__); return (channel_ != -1) && Mix_Playing(channel_); } diff --git a/RetroFE/Source/Sound/Sound.h b/RetroFE/Source/Sound/Sound.h index 57e3eb5..492c5b7 100755 --- a/RetroFE/Source/Sound/Sound.h +++ b/RetroFE/Source/Sound/Sound.h @@ -17,6 +17,7 @@ #include #include +#include "SDL.h" class Sound { public: @@ -27,6 +28,10 @@ public: bool free(); bool isPlaying(); private: + static void finished(int channel); + static uint32_t turnOffAmpli(uint32_t interval, void *param); + static int ampliStarted; + static SDL_TimerID idTimer; std::string file_; Mix_Chunk *chunk_; int channel_; diff --git a/RetroFE/Source/Utility/Utils.h b/RetroFE/Source/Utility/Utils.h index 68a1c86..2b80728 100755 --- a/RetroFE/Source/Utility/Utils.h +++ b/RetroFE/Source/Utility/Utils.h @@ -23,6 +23,8 @@ #define SHELL_CMD_ROOTFS_RW "rw" #define SHELL_CMD_ROOTFS_RO "ro" #define SHELL_CMD_RECORD_PID "record_pid" +#define SHELL_CMD_TURN_AMPLI_ON "start_audio_amp 1" +#define SHELL_CMD_TURN_AMPLI_OFF "start_audio_amp 0" class Utils {