Skip to content

Commit

Permalink
Merge pull request Aloshi#460 from tminit/custom-audio-rpi
Browse files Browse the repository at this point in the history
Enhanced Audio settings
  • Loading branch information
jrassa committed Aug 30, 2018
2 parents 564e9a4 + e7bc6f7 commit 811e2ce
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 19 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -15,8 +15,8 @@ EmulationStation has a few dependencies. For building, you'll need CMake, SDL2,
All of this be easily installed with apt-get:
```bash
sudo apt-get install libsdl2-dev libfreeimage-dev libfreetype6-dev libcurl4-openssl-dev \
libasound2-dev libgl1-mesa-dev build-essential cmake fonts-droid \
libvlc-dev libvlccore-dev vlc-nox
libasound2-dev libgl1-mesa-dev build-essential cmake fonts-droid-fallback libvlc-dev \
libvlccore-dev vlc-bin
```
**On Fedora:**
All of this be easily installed with dnf ( With rpmfusion activated) :
Expand Down
14 changes: 7 additions & 7 deletions es-app/src/VolumeControl.cpp
Expand Up @@ -22,7 +22,7 @@ std::weak_ptr<VolumeControl> VolumeControl::sInstance;
VolumeControl::VolumeControl()
: originalVolume(0), internalVolume(0)
#if defined (__APPLE__)
#error TODO: Not implemented for MacOS yet!!!
#error TODO: Not implemented for MacOS yet!!!
#elif defined(__linux__)
, mixerIndex(0), mixerHandle(nullptr), mixerElem(nullptr), mixerSelemId(nullptr)
#elif defined(WIN32) || defined(_WIN32)
Expand All @@ -36,9 +36,9 @@ VolumeControl::VolumeControl()
}

VolumeControl::VolumeControl(const VolumeControl & right):
originalVolume(0), internalVolume(0)
originalVolume(0), internalVolume(0)
#if defined (__APPLE__)
#error TODO: Not implemented for MacOS yet!!!
#error TODO: Not implemented for MacOS yet!!!
#elif defined(__linux__)
, mixerIndex(0), mixerHandle(nullptr), mixerElem(nullptr), mixerSelemId(nullptr)
#elif defined(WIN32) || defined(_WIN32)
Expand Down Expand Up @@ -86,9 +86,9 @@ void VolumeControl::init()
//try to open mixer device
if (mixerHandle == nullptr)
{
#ifdef _RPI_
// Allow users to override the AudioCard and MixerName in es_settings.cfg
mixerCard = Settings::getInstance()->getString("AudioCard").c_str();
mixerName = Settings::getInstance()->getString("AudioDevice").c_str();
#endif

snd_mixer_selem_id_alloca(&mixerSelemId);
//sets simple-mixer index and name
Expand Down Expand Up @@ -256,7 +256,7 @@ int VolumeControl::getVolume() const
int volume = 0;

#if defined (__APPLE__)
#error TODO: Not implemented for MacOS yet!!!
#error TODO: Not implemented for MacOS yet!!!
#elif defined(__linux__)
if (mixerElem != nullptr)
{
Expand Down Expand Up @@ -350,7 +350,7 @@ void VolumeControl::setVolume(int volume)
//store values in internal variables
internalVolume = volume;
#if defined (__APPLE__)
#error TODO: Not implemented for MacOS yet!!!
#error TODO: Not implemented for MacOS yet!!!
#elif defined(__linux__)
if (mixerElem != nullptr)
{
Expand Down
2 changes: 1 addition & 1 deletion es-app/src/VolumeControl.h
Expand Up @@ -27,7 +27,7 @@ class VolumeControl
static const char * mixerName;
static const char * mixerCard;
int mixerIndex;
snd_mixer_t* mixerHandle;
snd_mixer_t* mixerHandle;
snd_mixer_elem_t* mixerElem;
snd_mixer_selem_id_t* mixerSelemId;
#elif defined(WIN32) || defined(_WIN32)
Expand Down
60 changes: 51 additions & 9 deletions es-app/src/guis/GuiMenu.cpp
Expand Up @@ -16,6 +16,7 @@
#include "SystemData.h"
#include "VolumeControl.h"
#include <SDL_events.h>
#include <algorithm>

GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MENU"), mVersion(window)
{
Expand Down Expand Up @@ -94,13 +95,49 @@ void GuiMenu::openSoundSettings()

if (UIModeController::getInstance()->isUIModeFull())
{
#ifdef _RPI_
#if defined(__linux__)
// audio card
auto audio_card = std::make_shared< OptionListComponent<std::string> >(mWindow, "AUDIO CARD", false);
std::vector<std::string> audio_cards;
#ifdef _RPI_
// RPi Specific Audio Cards
audio_cards.push_back("local");
audio_cards.push_back("hdmi");
audio_cards.push_back("both");
#endif
audio_cards.push_back("default");
audio_cards.push_back("sysdefault");
audio_cards.push_back("dmix");
audio_cards.push_back("hw");
audio_cards.push_back("plughw");
audio_cards.push_back("null");
if (Settings::getInstance()->getString("AudioCard") != "") {
if(std::find(audio_cards.begin(), audio_cards.end(), Settings::getInstance()->getString("AudioCard")) == audio_cards.end()) {
audio_cards.push_back(Settings::getInstance()->getString("AudioCard"));
}
}
for(auto ac = audio_cards.cbegin(); ac != audio_cards.cend(); ac++)
audio_card->add(*ac, *ac, Settings::getInstance()->getString("AudioCard") == *ac);
s->addWithLabel("AUDIO CARD", audio_card);
s->addSaveFunc([audio_card] {
Settings::getInstance()->setString("AudioCard", audio_card->getSelected());
VolumeControl::getInstance()->deinit();
VolumeControl::getInstance()->init();
});

// volume control device
auto vol_dev = std::make_shared< OptionListComponent<std::string> >(mWindow, "AUDIO DEVICE", false);
std::vector<std::string> transitions;
transitions.push_back("PCM");
transitions.push_back("Speaker");
transitions.push_back("Master");
transitions.push_back("Digital");
transitions.push_back("Analogue");
if (Settings::getInstance()->getString("AudioDevice") != "") {
if(std::find(transitions.begin(), transitions.end(), Settings::getInstance()->getString("AudioDevice")) == transitions.end()) {
transitions.push_back(Settings::getInstance()->getString("AudioDevice"));
}
}
for(auto it = transitions.cbegin(); it != transitions.cend(); it++)
vol_dev->add(*it, *it, Settings::getInstance()->getString("AudioDevice") == *it);
s->addWithLabel("AUDIO DEVICE", vol_dev);
Expand Down Expand Up @@ -134,14 +171,19 @@ void GuiMenu::openSoundSettings()
#ifdef _RPI_
// OMX player Audio Device
auto omx_audio_dev = std::make_shared< OptionListComponent<std::string> >(mWindow, "OMX PLAYER AUDIO DEVICE", false);
std::vector<std::string> devices;
devices.push_back("local");
devices.push_back("hdmi");
devices.push_back("both");
// USB audio
devices.push_back("alsa:hw:0,0");
devices.push_back("alsa:hw:1,0");
for (auto it = devices.cbegin(); it != devices.cend(); it++)
std::vector<std::string> omx_cards;
// RPi Specific Audio Cards
omx_cards.push_back("local");
omx_cards.push_back("hdmi");
omx_cards.push_back("both");
omx_cards.push_back("alsa:hw:0,0");
omx_cards.push_back("alsa:hw:1,0");
if (Settings::getInstance()->getString("OMXAudioDev") != "") {
if (std::find(omx_cards.begin(), omx_cards.end(), Settings::getInstance()->getString("OMXAudioDev")) == omx_cards.end()) {
omx_cards.push_back(Settings::getInstance()->getString("OMXAudioDev"));
}
}
for (auto it = omx_cards.cbegin(); it != omx_cards.cend(); it++)
omx_audio_dev->add(*it, *it, Settings::getInstance()->getString("OMXAudioDev") == *it);
s->addWithLabel("OMX PLAYER AUDIO DEVICE", omx_audio_dev);
s->addSaveFunc([omx_audio_dev] {
Expand Down

0 comments on commit 811e2ce

Please sign in to comment.