2014-06-25 16:29:58 +00:00
|
|
|
#include "VolumeControl.h"
|
|
|
|
|
2017-11-13 22:16:38 +00:00
|
|
|
#include "math/Misc.h"
|
2014-06-25 16:29:58 +00:00
|
|
|
#include "Log.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "Settings.h"
|
|
|
|
#ifdef WIN32
|
|
|
|
#include <mmdeviceapi.h>
|
|
|
|
#endif
|
2014-06-25 16:29:58 +00:00
|
|
|
|
|
|
|
#if defined(__linux__)
|
Changed Audio settings to be much more flexible
Changed the selectable options for EmulationStation audio mixer
(called AudioDevice in EmulationStation) to be a greater range of
selectable options within Linux and RPi so that it is a lot more
flexible and will work with any aftermarket add-on audio cards and
RPi Audio HATs. Hopefully this gives people the flexibility that
they need in order to avoid the issues people have with unusual RPi
audio setups.
Added the ability to select the audio card as well, by surfacing
the audio card under the Audio Card setting. It was previously forced
to 'default' for all linux users, which was too restrictive in some
instances. This change now adds flexbility to support additional
Linux and RPi Audio Cards.
This option will only be available on Linux (and therefore RPi) as
Windows uses a different audio subsystem.
CHOOSING AUDIO ON LINUX AND RPi
You now select which ALSA Audio Card you want EmulationStation to use
by choosing the relevant AUDIO CARD option. If your one is not listed
then you can add a custom one in the es_settings.cfg file (see below).
You then select which ALSA Audio Mixer Control from that Audio Card
that you want EmulationStation to use, by choosing the relevant
AUDIO DEVICE option. (I kept the name AUDIO DEVICE as that what
EmulationStation previously used to describe an Audio Mixer.)
If your mixer name is not listed then you can add a custom one in
the es_settings.cfg file (see below).
ADDING A CUSTOM AUDIO CARD OR AUDIO DEVICE
In addition I added the ability to manually change the setting in
es_settings.cfg to add anything custom that you want. This will give
advanced users enough extra power that should avoid even the most
strange setups.
Step 1:
To add a custom Audio Card, edit the "AudioCard" setting and replace
the value with the name of your Audio Card. You can find this out by
opening a terminal window and running 'aplay -L'. This will generate a
list of Audio Cards similar to the one below:
pi@raspberrypi:~ $ aplay -L
null
Discard all samples (playback) or generate zero samples (capture)
default:CARD=sndrpijustboomd
snd_rpi_justboom_dac,
Default Audio Device
sysdefault:CARD=sndrpijustboomd
snd_rpi_justboom_dac,
Default Audio Device
dmix:CARD=sndrpijustboomd,DEV=0
snd_rpi_justboom_dac,
Direct sample mixing device
dsnoop:CARD=sndrpijustboomd,DEV=0
snd_rpi_justboom_dac,
Direct sample snooping device
hw:CARD=sndrpijustboomd,DEV=0
snd_rpi_justboom_dac,
Direct hardware device without any conversions
plughw:CARD=sndrpijustboomd,DEV=0
snd_rpi_justboom_dac,
Hardware device with all software conversions
Select any one of the Audio Cards listed by using the first word on
the line in your AudioCard settings in the es_settings.cfg, e.g.
<string name="AudioCard" value="default" />
NOTE: If the AudioCard value is not listed, please either close and
reopen EmulationStation (the settings is created upon close if it
doesn't exist), or add it manually to the es_settings.cfg file.
Step 2:
To add a custom Audio Device (mixer), edit the "AudioDevice" setting
and replace the value with the name of your Audio Device. You can get
a list off avilable Audio Devices on the Audio Card by opening a
terminal window and running 'amixer scontrols -D <AudioCard>', where
<AudioCard> is replaced with the name of your Audio Card that you
found in Step 1. This command will generate a list of Audio Devices
(mixers) that you can use in the AudioDevice setting in the
es_settings.cfg file, e.g.
pi@raspberrypi:~ $ amixer scontrols -D default
Simple mixer control 'DSP Program',0
Simple mixer control 'Analogue',0
Simple mixer control 'Analogue Playback Boost',0
Simple mixer control 'Auto Mute',0
Simple mixer control 'Auto Mute Mono',0
Simple mixer control 'Auto Mute Time Left',0
Simple mixer control 'Auto Mute Time Right',0
Simple mixer control 'Clock Missing Period',0
Simple mixer control 'Deemphasis',0
Simple mixer control 'Digital',0
Simple mixer control 'Max Overclock DAC',0
Simple mixer control 'Max Overclock DSP',0
Simple mixer control 'Max Overclock PLL',0
Simple mixer control 'Volume Ramp Down Emergency Rate',0
Simple mixer control 'Volume Ramp Down Emergency Step',0
Simple mixer control 'Volume Ramp Down Rate',0
Simple mixer control 'Volume Ramp Down Step',0
Simple mixer control 'Volume Ramp Up Rate',0
Simple mixer control 'Volume Ramp Up Step',0
Select any one of the Simple mixer controls listed by using the
name within the quotes within the AudioDevice setting in your
es_settings.cfg file, e.g.
<string name="AudioDevice" value="Digital" />
Using the example above, the following two settings within the
es_settings.cfg file will use the 'default' Audio Card to play
sounds, and will use the 'Digital' mixer (Audio Device) to
control the volume.
<string name="AudioCard" value="default" />
<string name="AudioDevice" value="Digital" />
NOTE: Any custom manually used settings will be overwritten if you
select any of the other options in the GUI and exit the Sound
Settings window, as the Sound Settings GUI window overwrites the
es_settings.cfg options when you exit the window.
Fix latest package renames
fonts-droid is now fonts-droid-fallback
vlc-nox is now vlc-bin
Fixed up whitespacing to project tab standard
Had not paid enough attention and had accidentally provided
whitespacing in spaces rather than the project standard of
tabs. This change fixes some additional use of spaces to
ensure all the code in the two files now uses tabs.
Vero4k autodetection and volume mixer fix
2018-07-21 09:06:20 +00:00
|
|
|
#if defined(_RPI_) || defined(_VERO4K_)
|
2014-06-25 16:29:58 +00:00
|
|
|
const char * VolumeControl::mixerName = "PCM";
|
|
|
|
#else
|
|
|
|
const char * VolumeControl::mixerName = "Master";
|
|
|
|
#endif
|
|
|
|
const char * VolumeControl::mixerCard = "default";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
std::weak_ptr<VolumeControl> VolumeControl::sInstance;
|
|
|
|
|
|
|
|
|
|
|
|
VolumeControl::VolumeControl()
|
|
|
|
: originalVolume(0), internalVolume(0)
|
|
|
|
#if defined (__APPLE__)
|
Changed Audio settings to be much more flexible
Changed the selectable options for EmulationStation audio mixer
(called AudioDevice in EmulationStation) to be a greater range of
selectable options within Linux and RPi so that it is a lot more
flexible and will work with any aftermarket add-on audio cards and
RPi Audio HATs. Hopefully this gives people the flexibility that
they need in order to avoid the issues people have with unusual RPi
audio setups.
Added the ability to select the audio card as well, by surfacing
the audio card under the Audio Card setting. It was previously forced
to 'default' for all linux users, which was too restrictive in some
instances. This change now adds flexbility to support additional
Linux and RPi Audio Cards.
This option will only be available on Linux (and therefore RPi) as
Windows uses a different audio subsystem.
CHOOSING AUDIO ON LINUX AND RPi
You now select which ALSA Audio Card you want EmulationStation to use
by choosing the relevant AUDIO CARD option. If your one is not listed
then you can add a custom one in the es_settings.cfg file (see below).
You then select which ALSA Audio Mixer Control from that Audio Card
that you want EmulationStation to use, by choosing the relevant
AUDIO DEVICE option. (I kept the name AUDIO DEVICE as that what
EmulationStation previously used to describe an Audio Mixer.)
If your mixer name is not listed then you can add a custom one in
the es_settings.cfg file (see below).
ADDING A CUSTOM AUDIO CARD OR AUDIO DEVICE
In addition I added the ability to manually change the setting in
es_settings.cfg to add anything custom that you want. This will give
advanced users enough extra power that should avoid even the most
strange setups.
Step 1:
To add a custom Audio Card, edit the "AudioCard" setting and replace
the value with the name of your Audio Card. You can find this out by
opening a terminal window and running 'aplay -L'. This will generate a
list of Audio Cards similar to the one below:
pi@raspberrypi:~ $ aplay -L
null
Discard all samples (playback) or generate zero samples (capture)
default:CARD=sndrpijustboomd
snd_rpi_justboom_dac,
Default Audio Device
sysdefault:CARD=sndrpijustboomd
snd_rpi_justboom_dac,
Default Audio Device
dmix:CARD=sndrpijustboomd,DEV=0
snd_rpi_justboom_dac,
Direct sample mixing device
dsnoop:CARD=sndrpijustboomd,DEV=0
snd_rpi_justboom_dac,
Direct sample snooping device
hw:CARD=sndrpijustboomd,DEV=0
snd_rpi_justboom_dac,
Direct hardware device without any conversions
plughw:CARD=sndrpijustboomd,DEV=0
snd_rpi_justboom_dac,
Hardware device with all software conversions
Select any one of the Audio Cards listed by using the first word on
the line in your AudioCard settings in the es_settings.cfg, e.g.
<string name="AudioCard" value="default" />
NOTE: If the AudioCard value is not listed, please either close and
reopen EmulationStation (the settings is created upon close if it
doesn't exist), or add it manually to the es_settings.cfg file.
Step 2:
To add a custom Audio Device (mixer), edit the "AudioDevice" setting
and replace the value with the name of your Audio Device. You can get
a list off avilable Audio Devices on the Audio Card by opening a
terminal window and running 'amixer scontrols -D <AudioCard>', where
<AudioCard> is replaced with the name of your Audio Card that you
found in Step 1. This command will generate a list of Audio Devices
(mixers) that you can use in the AudioDevice setting in the
es_settings.cfg file, e.g.
pi@raspberrypi:~ $ amixer scontrols -D default
Simple mixer control 'DSP Program',0
Simple mixer control 'Analogue',0
Simple mixer control 'Analogue Playback Boost',0
Simple mixer control 'Auto Mute',0
Simple mixer control 'Auto Mute Mono',0
Simple mixer control 'Auto Mute Time Left',0
Simple mixer control 'Auto Mute Time Right',0
Simple mixer control 'Clock Missing Period',0
Simple mixer control 'Deemphasis',0
Simple mixer control 'Digital',0
Simple mixer control 'Max Overclock DAC',0
Simple mixer control 'Max Overclock DSP',0
Simple mixer control 'Max Overclock PLL',0
Simple mixer control 'Volume Ramp Down Emergency Rate',0
Simple mixer control 'Volume Ramp Down Emergency Step',0
Simple mixer control 'Volume Ramp Down Rate',0
Simple mixer control 'Volume Ramp Down Step',0
Simple mixer control 'Volume Ramp Up Rate',0
Simple mixer control 'Volume Ramp Up Step',0
Select any one of the Simple mixer controls listed by using the
name within the quotes within the AudioDevice setting in your
es_settings.cfg file, e.g.
<string name="AudioDevice" value="Digital" />
Using the example above, the following two settings within the
es_settings.cfg file will use the 'default' Audio Card to play
sounds, and will use the 'Digital' mixer (Audio Device) to
control the volume.
<string name="AudioCard" value="default" />
<string name="AudioDevice" value="Digital" />
NOTE: Any custom manually used settings will be overwritten if you
select any of the other options in the GUI and exit the Sound
Settings window, as the Sound Settings GUI window overwrites the
es_settings.cfg options when you exit the window.
Fix latest package renames
fonts-droid is now fonts-droid-fallback
vlc-nox is now vlc-bin
Fixed up whitespacing to project tab standard
Had not paid enough attention and had accidentally provided
whitespacing in spaces rather than the project standard of
tabs. This change fixes some additional use of spaces to
ensure all the code in the two files now uses tabs.
Vero4k autodetection and volume mixer fix
2018-07-21 09:06:20 +00:00
|
|
|
#error TODO: Not implemented for MacOS yet!!!
|
2014-06-25 16:29:58 +00:00
|
|
|
#elif defined(__linux__)
|
2017-07-28 07:57:37 +00:00
|
|
|
, mixerIndex(0), mixerHandle(nullptr), mixerElem(nullptr), mixerSelemId(nullptr)
|
2014-06-25 16:29:58 +00:00
|
|
|
#elif defined(WIN32) || defined(_WIN32)
|
|
|
|
, mixerHandle(nullptr), endpointVolume(nullptr)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
|
|
|
|
//get original volume levels for system
|
|
|
|
originalVolume = getVolume();
|
|
|
|
}
|
|
|
|
|
2017-07-28 07:57:37 +00:00
|
|
|
VolumeControl::VolumeControl(const VolumeControl & right):
|
Changed Audio settings to be much more flexible
Changed the selectable options for EmulationStation audio mixer
(called AudioDevice in EmulationStation) to be a greater range of
selectable options within Linux and RPi so that it is a lot more
flexible and will work with any aftermarket add-on audio cards and
RPi Audio HATs. Hopefully this gives people the flexibility that
they need in order to avoid the issues people have with unusual RPi
audio setups.
Added the ability to select the audio card as well, by surfacing
the audio card under the Audio Card setting. It was previously forced
to 'default' for all linux users, which was too restrictive in some
instances. This change now adds flexbility to support additional
Linux and RPi Audio Cards.
This option will only be available on Linux (and therefore RPi) as
Windows uses a different audio subsystem.
CHOOSING AUDIO ON LINUX AND RPi
You now select which ALSA Audio Card you want EmulationStation to use
by choosing the relevant AUDIO CARD option. If your one is not listed
then you can add a custom one in the es_settings.cfg file (see below).
You then select which ALSA Audio Mixer Control from that Audio Card
that you want EmulationStation to use, by choosing the relevant
AUDIO DEVICE option. (I kept the name AUDIO DEVICE as that what
EmulationStation previously used to describe an Audio Mixer.)
If your mixer name is not listed then you can add a custom one in
the es_settings.cfg file (see below).
ADDING A CUSTOM AUDIO CARD OR AUDIO DEVICE
In addition I added the ability to manually change the setting in
es_settings.cfg to add anything custom that you want. This will give
advanced users enough extra power that should avoid even the most
strange setups.
Step 1:
To add a custom Audio Card, edit the "AudioCard" setting and replace
the value with the name of your Audio Card. You can find this out by
opening a terminal window and running 'aplay -L'. This will generate a
list of Audio Cards similar to the one below:
pi@raspberrypi:~ $ aplay -L
null
Discard all samples (playback) or generate zero samples (capture)
default:CARD=sndrpijustboomd
snd_rpi_justboom_dac,
Default Audio Device
sysdefault:CARD=sndrpijustboomd
snd_rpi_justboom_dac,
Default Audio Device
dmix:CARD=sndrpijustboomd,DEV=0
snd_rpi_justboom_dac,
Direct sample mixing device
dsnoop:CARD=sndrpijustboomd,DEV=0
snd_rpi_justboom_dac,
Direct sample snooping device
hw:CARD=sndrpijustboomd,DEV=0
snd_rpi_justboom_dac,
Direct hardware device without any conversions
plughw:CARD=sndrpijustboomd,DEV=0
snd_rpi_justboom_dac,
Hardware device with all software conversions
Select any one of the Audio Cards listed by using the first word on
the line in your AudioCard settings in the es_settings.cfg, e.g.
<string name="AudioCard" value="default" />
NOTE: If the AudioCard value is not listed, please either close and
reopen EmulationStation (the settings is created upon close if it
doesn't exist), or add it manually to the es_settings.cfg file.
Step 2:
To add a custom Audio Device (mixer), edit the "AudioDevice" setting
and replace the value with the name of your Audio Device. You can get
a list off avilable Audio Devices on the Audio Card by opening a
terminal window and running 'amixer scontrols -D <AudioCard>', where
<AudioCard> is replaced with the name of your Audio Card that you
found in Step 1. This command will generate a list of Audio Devices
(mixers) that you can use in the AudioDevice setting in the
es_settings.cfg file, e.g.
pi@raspberrypi:~ $ amixer scontrols -D default
Simple mixer control 'DSP Program',0
Simple mixer control 'Analogue',0
Simple mixer control 'Analogue Playback Boost',0
Simple mixer control 'Auto Mute',0
Simple mixer control 'Auto Mute Mono',0
Simple mixer control 'Auto Mute Time Left',0
Simple mixer control 'Auto Mute Time Right',0
Simple mixer control 'Clock Missing Period',0
Simple mixer control 'Deemphasis',0
Simple mixer control 'Digital',0
Simple mixer control 'Max Overclock DAC',0
Simple mixer control 'Max Overclock DSP',0
Simple mixer control 'Max Overclock PLL',0
Simple mixer control 'Volume Ramp Down Emergency Rate',0
Simple mixer control 'Volume Ramp Down Emergency Step',0
Simple mixer control 'Volume Ramp Down Rate',0
Simple mixer control 'Volume Ramp Down Step',0
Simple mixer control 'Volume Ramp Up Rate',0
Simple mixer control 'Volume Ramp Up Step',0
Select any one of the Simple mixer controls listed by using the
name within the quotes within the AudioDevice setting in your
es_settings.cfg file, e.g.
<string name="AudioDevice" value="Digital" />
Using the example above, the following two settings within the
es_settings.cfg file will use the 'default' Audio Card to play
sounds, and will use the 'Digital' mixer (Audio Device) to
control the volume.
<string name="AudioCard" value="default" />
<string name="AudioDevice" value="Digital" />
NOTE: Any custom manually used settings will be overwritten if you
select any of the other options in the GUI and exit the Sound
Settings window, as the Sound Settings GUI window overwrites the
es_settings.cfg options when you exit the window.
Fix latest package renames
fonts-droid is now fonts-droid-fallback
vlc-nox is now vlc-bin
Fixed up whitespacing to project tab standard
Had not paid enough attention and had accidentally provided
whitespacing in spaces rather than the project standard of
tabs. This change fixes some additional use of spaces to
ensure all the code in the two files now uses tabs.
Vero4k autodetection and volume mixer fix
2018-07-21 09:06:20 +00:00
|
|
|
originalVolume(0), internalVolume(0)
|
2017-07-28 07:57:37 +00:00
|
|
|
#if defined (__APPLE__)
|
Changed Audio settings to be much more flexible
Changed the selectable options for EmulationStation audio mixer
(called AudioDevice in EmulationStation) to be a greater range of
selectable options within Linux and RPi so that it is a lot more
flexible and will work with any aftermarket add-on audio cards and
RPi Audio HATs. Hopefully this gives people the flexibility that
they need in order to avoid the issues people have with unusual RPi
audio setups.
Added the ability to select the audio card as well, by surfacing
the audio card under the Audio Card setting. It was previously forced
to 'default' for all linux users, which was too restrictive in some
instances. This change now adds flexbility to support additional
Linux and RPi Audio Cards.
This option will only be available on Linux (and therefore RPi) as
Windows uses a different audio subsystem.
CHOOSING AUDIO ON LINUX AND RPi
You now select which ALSA Audio Card you want EmulationStation to use
by choosing the relevant AUDIO CARD option. If your one is not listed
then you can add a custom one in the es_settings.cfg file (see below).
You then select which ALSA Audio Mixer Control from that Audio Card
that you want EmulationStation to use, by choosing the relevant
AUDIO DEVICE option. (I kept the name AUDIO DEVICE as that what
EmulationStation previously used to describe an Audio Mixer.)
If your mixer name is not listed then you can add a custom one in
the es_settings.cfg file (see below).
ADDING A CUSTOM AUDIO CARD OR AUDIO DEVICE
In addition I added the ability to manually change the setting in
es_settings.cfg to add anything custom that you want. This will give
advanced users enough extra power that should avoid even the most
strange setups.
Step 1:
To add a custom Audio Card, edit the "AudioCard" setting and replace
the value with the name of your Audio Card. You can find this out by
opening a terminal window and running 'aplay -L'. This will generate a
list of Audio Cards similar to the one below:
pi@raspberrypi:~ $ aplay -L
null
Discard all samples (playback) or generate zero samples (capture)
default:CARD=sndrpijustboomd
snd_rpi_justboom_dac,
Default Audio Device
sysdefault:CARD=sndrpijustboomd
snd_rpi_justboom_dac,
Default Audio Device
dmix:CARD=sndrpijustboomd,DEV=0
snd_rpi_justboom_dac,
Direct sample mixing device
dsnoop:CARD=sndrpijustboomd,DEV=0
snd_rpi_justboom_dac,
Direct sample snooping device
hw:CARD=sndrpijustboomd,DEV=0
snd_rpi_justboom_dac,
Direct hardware device without any conversions
plughw:CARD=sndrpijustboomd,DEV=0
snd_rpi_justboom_dac,
Hardware device with all software conversions
Select any one of the Audio Cards listed by using the first word on
the line in your AudioCard settings in the es_settings.cfg, e.g.
<string name="AudioCard" value="default" />
NOTE: If the AudioCard value is not listed, please either close and
reopen EmulationStation (the settings is created upon close if it
doesn't exist), or add it manually to the es_settings.cfg file.
Step 2:
To add a custom Audio Device (mixer), edit the "AudioDevice" setting
and replace the value with the name of your Audio Device. You can get
a list off avilable Audio Devices on the Audio Card by opening a
terminal window and running 'amixer scontrols -D <AudioCard>', where
<AudioCard> is replaced with the name of your Audio Card that you
found in Step 1. This command will generate a list of Audio Devices
(mixers) that you can use in the AudioDevice setting in the
es_settings.cfg file, e.g.
pi@raspberrypi:~ $ amixer scontrols -D default
Simple mixer control 'DSP Program',0
Simple mixer control 'Analogue',0
Simple mixer control 'Analogue Playback Boost',0
Simple mixer control 'Auto Mute',0
Simple mixer control 'Auto Mute Mono',0
Simple mixer control 'Auto Mute Time Left',0
Simple mixer control 'Auto Mute Time Right',0
Simple mixer control 'Clock Missing Period',0
Simple mixer control 'Deemphasis',0
Simple mixer control 'Digital',0
Simple mixer control 'Max Overclock DAC',0
Simple mixer control 'Max Overclock DSP',0
Simple mixer control 'Max Overclock PLL',0
Simple mixer control 'Volume Ramp Down Emergency Rate',0
Simple mixer control 'Volume Ramp Down Emergency Step',0
Simple mixer control 'Volume Ramp Down Rate',0
Simple mixer control 'Volume Ramp Down Step',0
Simple mixer control 'Volume Ramp Up Rate',0
Simple mixer control 'Volume Ramp Up Step',0
Select any one of the Simple mixer controls listed by using the
name within the quotes within the AudioDevice setting in your
es_settings.cfg file, e.g.
<string name="AudioDevice" value="Digital" />
Using the example above, the following two settings within the
es_settings.cfg file will use the 'default' Audio Card to play
sounds, and will use the 'Digital' mixer (Audio Device) to
control the volume.
<string name="AudioCard" value="default" />
<string name="AudioDevice" value="Digital" />
NOTE: Any custom manually used settings will be overwritten if you
select any of the other options in the GUI and exit the Sound
Settings window, as the Sound Settings GUI window overwrites the
es_settings.cfg options when you exit the window.
Fix latest package renames
fonts-droid is now fonts-droid-fallback
vlc-nox is now vlc-bin
Fixed up whitespacing to project tab standard
Had not paid enough attention and had accidentally provided
whitespacing in spaces rather than the project standard of
tabs. This change fixes some additional use of spaces to
ensure all the code in the two files now uses tabs.
Vero4k autodetection and volume mixer fix
2018-07-21 09:06:20 +00:00
|
|
|
#error TODO: Not implemented for MacOS yet!!!
|
2017-07-28 07:57:37 +00:00
|
|
|
#elif defined(__linux__)
|
|
|
|
, mixerIndex(0), mixerHandle(nullptr), mixerElem(nullptr), mixerSelemId(nullptr)
|
|
|
|
#elif defined(WIN32) || defined(_WIN32)
|
|
|
|
, mixerHandle(nullptr), endpointVolume(nullptr)
|
|
|
|
#endif
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2017-11-17 14:58:52 +00:00
|
|
|
(void)right;
|
2014-06-25 16:29:58 +00:00
|
|
|
sInstance = right.sInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
VolumeControl & VolumeControl::operator=(const VolumeControl & right)
|
|
|
|
{
|
|
|
|
if (this != &right) {
|
|
|
|
sInstance = right.sInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
VolumeControl::~VolumeControl()
|
|
|
|
{
|
|
|
|
//set original volume levels for system
|
2014-11-23 17:10:38 +00:00
|
|
|
//setVolume(originalVolume);
|
2014-06-25 16:29:58 +00:00
|
|
|
|
|
|
|
deinit();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<VolumeControl> & VolumeControl::getInstance()
|
|
|
|
{
|
|
|
|
//check if an VolumeControl instance is already created, if not create one
|
|
|
|
static std::shared_ptr<VolumeControl> sharedInstance = sInstance.lock();
|
|
|
|
if (sharedInstance == nullptr) {
|
|
|
|
sharedInstance.reset(new VolumeControl);
|
|
|
|
sInstance = sharedInstance;
|
|
|
|
}
|
|
|
|
return sharedInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VolumeControl::init()
|
|
|
|
{
|
|
|
|
//initialize audio mixer interface
|
|
|
|
#if defined (__APPLE__)
|
|
|
|
#error TODO: Not implemented for MacOS yet!!!
|
|
|
|
#elif defined(__linux__)
|
|
|
|
//try to open mixer device
|
|
|
|
if (mixerHandle == nullptr)
|
|
|
|
{
|
Changed Audio settings to be much more flexible
Changed the selectable options for EmulationStation audio mixer
(called AudioDevice in EmulationStation) to be a greater range of
selectable options within Linux and RPi so that it is a lot more
flexible and will work with any aftermarket add-on audio cards and
RPi Audio HATs. Hopefully this gives people the flexibility that
they need in order to avoid the issues people have with unusual RPi
audio setups.
Added the ability to select the audio card as well, by surfacing
the audio card under the Audio Card setting. It was previously forced
to 'default' for all linux users, which was too restrictive in some
instances. This change now adds flexbility to support additional
Linux and RPi Audio Cards.
This option will only be available on Linux (and therefore RPi) as
Windows uses a different audio subsystem.
CHOOSING AUDIO ON LINUX AND RPi
You now select which ALSA Audio Card you want EmulationStation to use
by choosing the relevant AUDIO CARD option. If your one is not listed
then you can add a custom one in the es_settings.cfg file (see below).
You then select which ALSA Audio Mixer Control from that Audio Card
that you want EmulationStation to use, by choosing the relevant
AUDIO DEVICE option. (I kept the name AUDIO DEVICE as that what
EmulationStation previously used to describe an Audio Mixer.)
If your mixer name is not listed then you can add a custom one in
the es_settings.cfg file (see below).
ADDING A CUSTOM AUDIO CARD OR AUDIO DEVICE
In addition I added the ability to manually change the setting in
es_settings.cfg to add anything custom that you want. This will give
advanced users enough extra power that should avoid even the most
strange setups.
Step 1:
To add a custom Audio Card, edit the "AudioCard" setting and replace
the value with the name of your Audio Card. You can find this out by
opening a terminal window and running 'aplay -L'. This will generate a
list of Audio Cards similar to the one below:
pi@raspberrypi:~ $ aplay -L
null
Discard all samples (playback) or generate zero samples (capture)
default:CARD=sndrpijustboomd
snd_rpi_justboom_dac,
Default Audio Device
sysdefault:CARD=sndrpijustboomd
snd_rpi_justboom_dac,
Default Audio Device
dmix:CARD=sndrpijustboomd,DEV=0
snd_rpi_justboom_dac,
Direct sample mixing device
dsnoop:CARD=sndrpijustboomd,DEV=0
snd_rpi_justboom_dac,
Direct sample snooping device
hw:CARD=sndrpijustboomd,DEV=0
snd_rpi_justboom_dac,
Direct hardware device without any conversions
plughw:CARD=sndrpijustboomd,DEV=0
snd_rpi_justboom_dac,
Hardware device with all software conversions
Select any one of the Audio Cards listed by using the first word on
the line in your AudioCard settings in the es_settings.cfg, e.g.
<string name="AudioCard" value="default" />
NOTE: If the AudioCard value is not listed, please either close and
reopen EmulationStation (the settings is created upon close if it
doesn't exist), or add it manually to the es_settings.cfg file.
Step 2:
To add a custom Audio Device (mixer), edit the "AudioDevice" setting
and replace the value with the name of your Audio Device. You can get
a list off avilable Audio Devices on the Audio Card by opening a
terminal window and running 'amixer scontrols -D <AudioCard>', where
<AudioCard> is replaced with the name of your Audio Card that you
found in Step 1. This command will generate a list of Audio Devices
(mixers) that you can use in the AudioDevice setting in the
es_settings.cfg file, e.g.
pi@raspberrypi:~ $ amixer scontrols -D default
Simple mixer control 'DSP Program',0
Simple mixer control 'Analogue',0
Simple mixer control 'Analogue Playback Boost',0
Simple mixer control 'Auto Mute',0
Simple mixer control 'Auto Mute Mono',0
Simple mixer control 'Auto Mute Time Left',0
Simple mixer control 'Auto Mute Time Right',0
Simple mixer control 'Clock Missing Period',0
Simple mixer control 'Deemphasis',0
Simple mixer control 'Digital',0
Simple mixer control 'Max Overclock DAC',0
Simple mixer control 'Max Overclock DSP',0
Simple mixer control 'Max Overclock PLL',0
Simple mixer control 'Volume Ramp Down Emergency Rate',0
Simple mixer control 'Volume Ramp Down Emergency Step',0
Simple mixer control 'Volume Ramp Down Rate',0
Simple mixer control 'Volume Ramp Down Step',0
Simple mixer control 'Volume Ramp Up Rate',0
Simple mixer control 'Volume Ramp Up Step',0
Select any one of the Simple mixer controls listed by using the
name within the quotes within the AudioDevice setting in your
es_settings.cfg file, e.g.
<string name="AudioDevice" value="Digital" />
Using the example above, the following two settings within the
es_settings.cfg file will use the 'default' Audio Card to play
sounds, and will use the 'Digital' mixer (Audio Device) to
control the volume.
<string name="AudioCard" value="default" />
<string name="AudioDevice" value="Digital" />
NOTE: Any custom manually used settings will be overwritten if you
select any of the other options in the GUI and exit the Sound
Settings window, as the Sound Settings GUI window overwrites the
es_settings.cfg options when you exit the window.
Fix latest package renames
fonts-droid is now fonts-droid-fallback
vlc-nox is now vlc-bin
Fixed up whitespacing to project tab standard
Had not paid enough attention and had accidentally provided
whitespacing in spaces rather than the project standard of
tabs. This change fixes some additional use of spaces to
ensure all the code in the two files now uses tabs.
Vero4k autodetection and volume mixer fix
2018-07-21 09:06:20 +00:00
|
|
|
// Allow users to override the AudioCard and MixerName in es_settings.cfg
|
|
|
|
mixerCard = Settings::getInstance()->getString("AudioCard").c_str();
|
2017-06-02 15:58:44 +00:00
|
|
|
mixerName = Settings::getInstance()->getString("AudioDevice").c_str();
|
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
snd_mixer_selem_id_alloca(&mixerSelemId);
|
|
|
|
//sets simple-mixer index and name
|
|
|
|
snd_mixer_selem_id_set_index(mixerSelemId, mixerIndex);
|
|
|
|
snd_mixer_selem_id_set_name(mixerSelemId, mixerName);
|
|
|
|
//open mixer
|
|
|
|
if (snd_mixer_open(&mixerHandle, 0) >= 0)
|
|
|
|
{
|
|
|
|
LOG(LogDebug) << "VolumeControl::init() - Opened ALSA mixer";
|
|
|
|
//ok. attach to defualt card
|
|
|
|
if (snd_mixer_attach(mixerHandle, mixerCard) >= 0)
|
|
|
|
{
|
|
|
|
LOG(LogDebug) << "VolumeControl::init() - Attached to default card";
|
|
|
|
//ok. register simple element class
|
|
|
|
if (snd_mixer_selem_register(mixerHandle, NULL, NULL) >= 0)
|
|
|
|
{
|
|
|
|
LOG(LogDebug) << "VolumeControl::init() - Registered simple element class";
|
|
|
|
//ok. load registered elements
|
|
|
|
if (snd_mixer_load(mixerHandle) >= 0)
|
|
|
|
{
|
|
|
|
LOG(LogDebug) << "VolumeControl::init() - Loaded mixer elements";
|
|
|
|
//ok. find elements now
|
|
|
|
mixerElem = snd_mixer_find_selem(mixerHandle, mixerSelemId);
|
|
|
|
if (mixerElem != nullptr)
|
|
|
|
{
|
|
|
|
//wohoo. good to go...
|
|
|
|
LOG(LogDebug) << "VolumeControl::init() - Mixer initialized";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG(LogError) << "VolumeControl::init() - Failed to find mixer elements!";
|
|
|
|
snd_mixer_close(mixerHandle);
|
|
|
|
mixerHandle = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG(LogError) << "VolumeControl::init() - Failed to load mixer elements!";
|
|
|
|
snd_mixer_close(mixerHandle);
|
|
|
|
mixerHandle = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG(LogError) << "VolumeControl::init() - Failed to register simple element class!";
|
|
|
|
snd_mixer_close(mixerHandle);
|
|
|
|
mixerHandle = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG(LogError) << "VolumeControl::init() - Failed to attach to default card!";
|
|
|
|
snd_mixer_close(mixerHandle);
|
|
|
|
mixerHandle = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG(LogError) << "VolumeControl::init() - Failed to open ALSA mixer!";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#elif defined(WIN32) || defined(_WIN32)
|
|
|
|
//get windows version information
|
|
|
|
OSVERSIONINFOEXA osVer = {sizeof(OSVERSIONINFO)};
|
|
|
|
::GetVersionExA(reinterpret_cast<LPOSVERSIONINFOA>(&osVer));
|
|
|
|
//check windows version
|
|
|
|
if(osVer.dwMajorVersion < 6)
|
|
|
|
{
|
|
|
|
//Windows older than Vista. use mixer API. open default mixer
|
|
|
|
if (mixerHandle == nullptr)
|
|
|
|
{
|
|
|
|
if (mixerOpen(&mixerHandle, 0, NULL, 0, 0) == MMSYSERR_NOERROR)
|
|
|
|
{
|
|
|
|
//retrieve info on the volume slider control for the "Speaker Out" line
|
|
|
|
MIXERLINECONTROLS mixerLineControls;
|
|
|
|
mixerLineControls.cbStruct = sizeof(MIXERLINECONTROLS);
|
|
|
|
mixerLineControls.dwLineID = 0xFFFF0000; //Id of "Speaker Out" line
|
|
|
|
mixerLineControls.cControls = 1;
|
|
|
|
//mixerLineControls.dwControlID = 0x00000000; //Id of "Speaker Out" line's volume slider
|
|
|
|
mixerLineControls.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME; //Get volume control
|
|
|
|
mixerLineControls.pamxctrl = &mixerControl;
|
|
|
|
mixerLineControls.cbmxctrl = sizeof(MIXERCONTROL);
|
|
|
|
if (mixerGetLineControls((HMIXEROBJ)mixerHandle, &mixerLineControls, MIXER_GETLINECONTROLSF_ONEBYTYPE) != MMSYSERR_NOERROR)
|
|
|
|
{
|
|
|
|
LOG(LogError) << "VolumeControl::getVolume() - Failed to get mixer volume control!";
|
|
|
|
mixerClose(mixerHandle);
|
|
|
|
mixerHandle = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG(LogError) << "VolumeControl::init() - Failed to open mixer!";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//Windows Vista or above. use EndpointVolume API. get device enumerator
|
|
|
|
if (endpointVolume == nullptr)
|
|
|
|
{
|
|
|
|
CoInitialize(nullptr);
|
|
|
|
IMMDeviceEnumerator * deviceEnumerator = nullptr;
|
|
|
|
CoCreateInstance(__uuidof(MMDeviceEnumerator), nullptr, CLSCTX_INPROC_SERVER, __uuidof(IMMDeviceEnumerator), (LPVOID *)&deviceEnumerator);
|
|
|
|
if (deviceEnumerator != nullptr)
|
|
|
|
{
|
|
|
|
//get default endpoint
|
|
|
|
IMMDevice * defaultDevice = nullptr;
|
|
|
|
deviceEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &defaultDevice);
|
|
|
|
if (defaultDevice != nullptr)
|
|
|
|
{
|
|
|
|
//retrieve endpoint volume
|
|
|
|
defaultDevice->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_INPROC_SERVER, nullptr, (LPVOID *)&endpointVolume);
|
|
|
|
if (endpointVolume == nullptr)
|
|
|
|
{
|
|
|
|
LOG(LogError) << "VolumeControl::init() - Failed to get default audio endpoint volume!";
|
|
|
|
}
|
|
|
|
//release default device. we don't need it anymore
|
|
|
|
defaultDevice->Release();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG(LogError) << "VolumeControl::init() - Failed to get default audio endpoint!";
|
|
|
|
}
|
|
|
|
//release device enumerator. we don't need it anymore
|
|
|
|
deviceEnumerator->Release();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG(LogError) << "VolumeControl::init() - Failed to get audio endpoint enumerator!";
|
|
|
|
CoUninitialize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void VolumeControl::deinit()
|
|
|
|
{
|
|
|
|
//deinitialize audio mixer interface
|
|
|
|
#if defined (__APPLE__)
|
|
|
|
#error TODO: Not implemented for MacOS yet!!!
|
|
|
|
#elif defined(__linux__)
|
|
|
|
if (mixerHandle != nullptr) {
|
|
|
|
snd_mixer_detach(mixerHandle, mixerCard);
|
|
|
|
snd_mixer_free(mixerHandle);
|
|
|
|
snd_mixer_close(mixerHandle);
|
|
|
|
mixerHandle = nullptr;
|
|
|
|
mixerElem = nullptr;
|
|
|
|
}
|
|
|
|
#elif defined(WIN32) || defined(_WIN32)
|
|
|
|
if (mixerHandle != nullptr) {
|
|
|
|
mixerClose(mixerHandle);
|
|
|
|
mixerHandle = nullptr;
|
|
|
|
}
|
|
|
|
else if (endpointVolume != nullptr) {
|
|
|
|
endpointVolume->Release();
|
|
|
|
endpointVolume = nullptr;
|
|
|
|
CoUninitialize();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int VolumeControl::getVolume() const
|
|
|
|
{
|
|
|
|
int volume = 0;
|
|
|
|
|
|
|
|
#if defined (__APPLE__)
|
Changed Audio settings to be much more flexible
Changed the selectable options for EmulationStation audio mixer
(called AudioDevice in EmulationStation) to be a greater range of
selectable options within Linux and RPi so that it is a lot more
flexible and will work with any aftermarket add-on audio cards and
RPi Audio HATs. Hopefully this gives people the flexibility that
they need in order to avoid the issues people have with unusual RPi
audio setups.
Added the ability to select the audio card as well, by surfacing
the audio card under the Audio Card setting. It was previously forced
to 'default' for all linux users, which was too restrictive in some
instances. This change now adds flexbility to support additional
Linux and RPi Audio Cards.
This option will only be available on Linux (and therefore RPi) as
Windows uses a different audio subsystem.
CHOOSING AUDIO ON LINUX AND RPi
You now select which ALSA Audio Card you want EmulationStation to use
by choosing the relevant AUDIO CARD option. If your one is not listed
then you can add a custom one in the es_settings.cfg file (see below).
You then select which ALSA Audio Mixer Control from that Audio Card
that you want EmulationStation to use, by choosing the relevant
AUDIO DEVICE option. (I kept the name AUDIO DEVICE as that what
EmulationStation previously used to describe an Audio Mixer.)
If your mixer name is not listed then you can add a custom one in
the es_settings.cfg file (see below).
ADDING A CUSTOM AUDIO CARD OR AUDIO DEVICE
In addition I added the ability to manually change the setting in
es_settings.cfg to add anything custom that you want. This will give
advanced users enough extra power that should avoid even the most
strange setups.
Step 1:
To add a custom Audio Card, edit the "AudioCard" setting and replace
the value with the name of your Audio Card. You can find this out by
opening a terminal window and running 'aplay -L'. This will generate a
list of Audio Cards similar to the one below:
pi@raspberrypi:~ $ aplay -L
null
Discard all samples (playback) or generate zero samples (capture)
default:CARD=sndrpijustboomd
snd_rpi_justboom_dac,
Default Audio Device
sysdefault:CARD=sndrpijustboomd
snd_rpi_justboom_dac,
Default Audio Device
dmix:CARD=sndrpijustboomd,DEV=0
snd_rpi_justboom_dac,
Direct sample mixing device
dsnoop:CARD=sndrpijustboomd,DEV=0
snd_rpi_justboom_dac,
Direct sample snooping device
hw:CARD=sndrpijustboomd,DEV=0
snd_rpi_justboom_dac,
Direct hardware device without any conversions
plughw:CARD=sndrpijustboomd,DEV=0
snd_rpi_justboom_dac,
Hardware device with all software conversions
Select any one of the Audio Cards listed by using the first word on
the line in your AudioCard settings in the es_settings.cfg, e.g.
<string name="AudioCard" value="default" />
NOTE: If the AudioCard value is not listed, please either close and
reopen EmulationStation (the settings is created upon close if it
doesn't exist), or add it manually to the es_settings.cfg file.
Step 2:
To add a custom Audio Device (mixer), edit the "AudioDevice" setting
and replace the value with the name of your Audio Device. You can get
a list off avilable Audio Devices on the Audio Card by opening a
terminal window and running 'amixer scontrols -D <AudioCard>', where
<AudioCard> is replaced with the name of your Audio Card that you
found in Step 1. This command will generate a list of Audio Devices
(mixers) that you can use in the AudioDevice setting in the
es_settings.cfg file, e.g.
pi@raspberrypi:~ $ amixer scontrols -D default
Simple mixer control 'DSP Program',0
Simple mixer control 'Analogue',0
Simple mixer control 'Analogue Playback Boost',0
Simple mixer control 'Auto Mute',0
Simple mixer control 'Auto Mute Mono',0
Simple mixer control 'Auto Mute Time Left',0
Simple mixer control 'Auto Mute Time Right',0
Simple mixer control 'Clock Missing Period',0
Simple mixer control 'Deemphasis',0
Simple mixer control 'Digital',0
Simple mixer control 'Max Overclock DAC',0
Simple mixer control 'Max Overclock DSP',0
Simple mixer control 'Max Overclock PLL',0
Simple mixer control 'Volume Ramp Down Emergency Rate',0
Simple mixer control 'Volume Ramp Down Emergency Step',0
Simple mixer control 'Volume Ramp Down Rate',0
Simple mixer control 'Volume Ramp Down Step',0
Simple mixer control 'Volume Ramp Up Rate',0
Simple mixer control 'Volume Ramp Up Step',0
Select any one of the Simple mixer controls listed by using the
name within the quotes within the AudioDevice setting in your
es_settings.cfg file, e.g.
<string name="AudioDevice" value="Digital" />
Using the example above, the following two settings within the
es_settings.cfg file will use the 'default' Audio Card to play
sounds, and will use the 'Digital' mixer (Audio Device) to
control the volume.
<string name="AudioCard" value="default" />
<string name="AudioDevice" value="Digital" />
NOTE: Any custom manually used settings will be overwritten if you
select any of the other options in the GUI and exit the Sound
Settings window, as the Sound Settings GUI window overwrites the
es_settings.cfg options when you exit the window.
Fix latest package renames
fonts-droid is now fonts-droid-fallback
vlc-nox is now vlc-bin
Fixed up whitespacing to project tab standard
Had not paid enough attention and had accidentally provided
whitespacing in spaces rather than the project standard of
tabs. This change fixes some additional use of spaces to
ensure all the code in the two files now uses tabs.
Vero4k autodetection and volume mixer fix
2018-07-21 09:06:20 +00:00
|
|
|
#error TODO: Not implemented for MacOS yet!!!
|
2014-06-25 16:29:58 +00:00
|
|
|
#elif defined(__linux__)
|
|
|
|
if (mixerElem != nullptr)
|
|
|
|
{
|
|
|
|
//get volume range
|
|
|
|
long minVolume;
|
|
|
|
long maxVolume;
|
|
|
|
if (snd_mixer_selem_get_playback_volume_range(mixerElem, &minVolume, &maxVolume) == 0)
|
|
|
|
{
|
|
|
|
//ok. now get volume
|
|
|
|
long rawVolume;
|
|
|
|
if (snd_mixer_selem_get_playback_volume(mixerElem, SND_MIXER_SCHN_MONO, &rawVolume) == 0)
|
|
|
|
{
|
|
|
|
//worked. bring into range 0-100
|
|
|
|
rawVolume -= minVolume;
|
|
|
|
if (rawVolume > 0)
|
|
|
|
{
|
2019-02-17 20:13:10 +00:00
|
|
|
volume = (rawVolume * 100.0) / (maxVolume - minVolume) + 0.5;
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
//else volume = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG(LogError) << "VolumeControl::getVolume() - Failed to get mixer volume!";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG(LogError) << "VolumeControl::getVolume() - Failed to get volume range!";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#elif defined(WIN32) || defined(_WIN32)
|
|
|
|
if (mixerHandle != nullptr)
|
|
|
|
{
|
|
|
|
//Windows older than Vista. use mixer API. get volume from line control
|
|
|
|
MIXERCONTROLDETAILS_UNSIGNED value;
|
|
|
|
MIXERCONTROLDETAILS mixerControlDetails;
|
|
|
|
mixerControlDetails.cbStruct = sizeof(MIXERCONTROLDETAILS);
|
|
|
|
mixerControlDetails.dwControlID = mixerControl.dwControlID;
|
|
|
|
mixerControlDetails.cChannels = 1; //always 1 for a MIXERCONTROL_CONTROLF_UNIFORM control
|
|
|
|
mixerControlDetails.cMultipleItems = 0; //always 0 except for a MIXERCONTROL_CONTROLF_MULTIPLE control
|
|
|
|
mixerControlDetails.paDetails = &value;
|
|
|
|
mixerControlDetails.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED);
|
|
|
|
if (mixerGetControlDetails((HMIXEROBJ)mixerHandle, &mixerControlDetails, MIXER_GETCONTROLDETAILSF_VALUE) == MMSYSERR_NOERROR)
|
|
|
|
{
|
2017-11-17 14:58:52 +00:00
|
|
|
volume = (int)Math::round((value.dwValue * 100) / 65535.0f);
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG(LogError) << "VolumeControl::getVolume() - Failed to get mixer volume!";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (endpointVolume != nullptr)
|
|
|
|
{
|
|
|
|
//Windows Vista or above. use EndpointVolume API
|
|
|
|
float floatVolume = 0.0f; //0-1
|
|
|
|
if (endpointVolume->GetMasterVolumeLevelScalar(&floatVolume) == S_OK)
|
|
|
|
{
|
2017-11-17 14:58:52 +00:00
|
|
|
volume = (int)Math::round(floatVolume * 100.0f);
|
2014-07-09 21:17:59 +00:00
|
|
|
LOG(LogInfo) << " getting volume as " << volume << " ( from float " << floatVolume << ")";
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG(LogError) << "VolumeControl::getVolume() - Failed to get master volume!";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
//clamp to 0-100 range
|
|
|
|
if (volume < 0)
|
|
|
|
{
|
|
|
|
volume = 0;
|
|
|
|
}
|
|
|
|
if (volume > 100)
|
|
|
|
{
|
|
|
|
volume = 100;
|
|
|
|
}
|
|
|
|
return volume;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VolumeControl::setVolume(int volume)
|
|
|
|
{
|
|
|
|
//clamp to 0-100 range
|
|
|
|
if (volume < 0)
|
|
|
|
{
|
|
|
|
volume = 0;
|
|
|
|
}
|
|
|
|
if (volume > 100)
|
|
|
|
{
|
|
|
|
volume = 100;
|
|
|
|
}
|
|
|
|
//store values in internal variables
|
|
|
|
internalVolume = volume;
|
|
|
|
#if defined (__APPLE__)
|
Changed Audio settings to be much more flexible
Changed the selectable options for EmulationStation audio mixer
(called AudioDevice in EmulationStation) to be a greater range of
selectable options within Linux and RPi so that it is a lot more
flexible and will work with any aftermarket add-on audio cards and
RPi Audio HATs. Hopefully this gives people the flexibility that
they need in order to avoid the issues people have with unusual RPi
audio setups.
Added the ability to select the audio card as well, by surfacing
the audio card under the Audio Card setting. It was previously forced
to 'default' for all linux users, which was too restrictive in some
instances. This change now adds flexbility to support additional
Linux and RPi Audio Cards.
This option will only be available on Linux (and therefore RPi) as
Windows uses a different audio subsystem.
CHOOSING AUDIO ON LINUX AND RPi
You now select which ALSA Audio Card you want EmulationStation to use
by choosing the relevant AUDIO CARD option. If your one is not listed
then you can add a custom one in the es_settings.cfg file (see below).
You then select which ALSA Audio Mixer Control from that Audio Card
that you want EmulationStation to use, by choosing the relevant
AUDIO DEVICE option. (I kept the name AUDIO DEVICE as that what
EmulationStation previously used to describe an Audio Mixer.)
If your mixer name is not listed then you can add a custom one in
the es_settings.cfg file (see below).
ADDING A CUSTOM AUDIO CARD OR AUDIO DEVICE
In addition I added the ability to manually change the setting in
es_settings.cfg to add anything custom that you want. This will give
advanced users enough extra power that should avoid even the most
strange setups.
Step 1:
To add a custom Audio Card, edit the "AudioCard" setting and replace
the value with the name of your Audio Card. You can find this out by
opening a terminal window and running 'aplay -L'. This will generate a
list of Audio Cards similar to the one below:
pi@raspberrypi:~ $ aplay -L
null
Discard all samples (playback) or generate zero samples (capture)
default:CARD=sndrpijustboomd
snd_rpi_justboom_dac,
Default Audio Device
sysdefault:CARD=sndrpijustboomd
snd_rpi_justboom_dac,
Default Audio Device
dmix:CARD=sndrpijustboomd,DEV=0
snd_rpi_justboom_dac,
Direct sample mixing device
dsnoop:CARD=sndrpijustboomd,DEV=0
snd_rpi_justboom_dac,
Direct sample snooping device
hw:CARD=sndrpijustboomd,DEV=0
snd_rpi_justboom_dac,
Direct hardware device without any conversions
plughw:CARD=sndrpijustboomd,DEV=0
snd_rpi_justboom_dac,
Hardware device with all software conversions
Select any one of the Audio Cards listed by using the first word on
the line in your AudioCard settings in the es_settings.cfg, e.g.
<string name="AudioCard" value="default" />
NOTE: If the AudioCard value is not listed, please either close and
reopen EmulationStation (the settings is created upon close if it
doesn't exist), or add it manually to the es_settings.cfg file.
Step 2:
To add a custom Audio Device (mixer), edit the "AudioDevice" setting
and replace the value with the name of your Audio Device. You can get
a list off avilable Audio Devices on the Audio Card by opening a
terminal window and running 'amixer scontrols -D <AudioCard>', where
<AudioCard> is replaced with the name of your Audio Card that you
found in Step 1. This command will generate a list of Audio Devices
(mixers) that you can use in the AudioDevice setting in the
es_settings.cfg file, e.g.
pi@raspberrypi:~ $ amixer scontrols -D default
Simple mixer control 'DSP Program',0
Simple mixer control 'Analogue',0
Simple mixer control 'Analogue Playback Boost',0
Simple mixer control 'Auto Mute',0
Simple mixer control 'Auto Mute Mono',0
Simple mixer control 'Auto Mute Time Left',0
Simple mixer control 'Auto Mute Time Right',0
Simple mixer control 'Clock Missing Period',0
Simple mixer control 'Deemphasis',0
Simple mixer control 'Digital',0
Simple mixer control 'Max Overclock DAC',0
Simple mixer control 'Max Overclock DSP',0
Simple mixer control 'Max Overclock PLL',0
Simple mixer control 'Volume Ramp Down Emergency Rate',0
Simple mixer control 'Volume Ramp Down Emergency Step',0
Simple mixer control 'Volume Ramp Down Rate',0
Simple mixer control 'Volume Ramp Down Step',0
Simple mixer control 'Volume Ramp Up Rate',0
Simple mixer control 'Volume Ramp Up Step',0
Select any one of the Simple mixer controls listed by using the
name within the quotes within the AudioDevice setting in your
es_settings.cfg file, e.g.
<string name="AudioDevice" value="Digital" />
Using the example above, the following two settings within the
es_settings.cfg file will use the 'default' Audio Card to play
sounds, and will use the 'Digital' mixer (Audio Device) to
control the volume.
<string name="AudioCard" value="default" />
<string name="AudioDevice" value="Digital" />
NOTE: Any custom manually used settings will be overwritten if you
select any of the other options in the GUI and exit the Sound
Settings window, as the Sound Settings GUI window overwrites the
es_settings.cfg options when you exit the window.
Fix latest package renames
fonts-droid is now fonts-droid-fallback
vlc-nox is now vlc-bin
Fixed up whitespacing to project tab standard
Had not paid enough attention and had accidentally provided
whitespacing in spaces rather than the project standard of
tabs. This change fixes some additional use of spaces to
ensure all the code in the two files now uses tabs.
Vero4k autodetection and volume mixer fix
2018-07-21 09:06:20 +00:00
|
|
|
#error TODO: Not implemented for MacOS yet!!!
|
2014-06-25 16:29:58 +00:00
|
|
|
#elif defined(__linux__)
|
|
|
|
if (mixerElem != nullptr)
|
|
|
|
{
|
|
|
|
//get volume range
|
|
|
|
long minVolume;
|
|
|
|
long maxVolume;
|
|
|
|
if (snd_mixer_selem_get_playback_volume_range(mixerElem, &minVolume, &maxVolume) == 0)
|
|
|
|
{
|
|
|
|
//ok. bring into minVolume-maxVolume range and set
|
|
|
|
long rawVolume = (volume * (maxVolume - minVolume) / 100) + minVolume;
|
|
|
|
if (snd_mixer_selem_set_playback_volume(mixerElem, SND_MIXER_SCHN_FRONT_LEFT, rawVolume) < 0
|
|
|
|
|| snd_mixer_selem_set_playback_volume(mixerElem, SND_MIXER_SCHN_FRONT_RIGHT, rawVolume) < 0)
|
|
|
|
{
|
|
|
|
LOG(LogError) << "VolumeControl::getVolume() - Failed to set mixer volume!";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG(LogError) << "VolumeControl::getVolume() - Failed to get volume range!";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#elif defined(WIN32) || defined(_WIN32)
|
|
|
|
if (mixerHandle != nullptr)
|
|
|
|
{
|
|
|
|
//Windows older than Vista. use mixer API. get volume from line control
|
|
|
|
MIXERCONTROLDETAILS_UNSIGNED value;
|
|
|
|
value.dwValue = (volume * 65535) / 100;
|
|
|
|
MIXERCONTROLDETAILS mixerControlDetails;
|
|
|
|
mixerControlDetails.cbStruct = sizeof(MIXERCONTROLDETAILS);
|
|
|
|
mixerControlDetails.dwControlID = mixerControl.dwControlID;
|
|
|
|
mixerControlDetails.cChannels = 1; //always 1 for a MIXERCONTROL_CONTROLF_UNIFORM control
|
|
|
|
mixerControlDetails.cMultipleItems = 0; //always 0 except for a MIXERCONTROL_CONTROLF_MULTIPLE control
|
|
|
|
mixerControlDetails.paDetails = &value;
|
|
|
|
mixerControlDetails.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED);
|
|
|
|
if (mixerSetControlDetails((HMIXEROBJ)mixerHandle, &mixerControlDetails, MIXER_SETCONTROLDETAILSF_VALUE) != MMSYSERR_NOERROR)
|
|
|
|
{
|
|
|
|
LOG(LogError) << "VolumeControl::setVolume() - Failed to set mixer volume!";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (endpointVolume != nullptr)
|
|
|
|
{
|
|
|
|
//Windows Vista or above. use EndpointVolume API
|
|
|
|
float floatVolume = 0.0f; //0-1
|
|
|
|
if (volume > 0) {
|
|
|
|
floatVolume = (float)volume / 100.0f;
|
|
|
|
}
|
|
|
|
if (endpointVolume->SetMasterVolumeLevelScalar(floatVolume, nullptr) != S_OK)
|
|
|
|
{
|
|
|
|
LOG(LogError) << "VolumeControl::setVolume() - Failed to set master volume!";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2014-11-23 17:10:38 +00:00
|
|
|
}
|