mirror of
https://github.com/FunKey-Project/RetroFE.git
synced 2025-12-12 09:48:51 +01:00
Starting audio Amp only when playing sounds, stopping otherwise
This commit is contained in:
parent
343f64f6b8
commit
d07ca9c5e7
@ -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());
|
||||
|
||||
@ -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_);
|
||||
}
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <SDL/SDL_mixer.h>
|
||||
#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_;
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user