Mp3_audio_sink: add equalizer and volume control
Thirty-two equalizer bands may be adjusted using positive and negative real numbers. The volume may also be be adjusted linearly using a positive real number relative to 1.0. The volume adjustment is made in the processing chain and the output is floating-point, so it is not recommended to adjust the volume here but at the mixer. <config> <volume linear="0.5"/> <!-- default, half volume --> <eq band="14" value="-0.2"/> <eq band="15" value="-0.1"/> <eq band="16" value="0.0"/> <!-- default, no adjustment --> <eq band="17" value="0.1"/> <eq band="18" value="0.2"/> </config>
This commit is contained in:
@@ -1 +1 @@
|
||||
2018-03-24 44b1460890c468d2aca6be56caf0faf075df29d4
|
||||
2018-05-24 15d7bc2940af4abfbea3229d4e2fd84981ac9962
|
||||
|
||||
@@ -1 +1 @@
|
||||
2018-03-24 fe37ac4217462df71d74721c1ac22f7158ef210d
|
||||
2018-05-24 7f16584ef3bc7e7700adc9048f7c64efd0bf6a3e
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <libc/component.h>
|
||||
#include <audio_out_session/connection.h>
|
||||
#include <terminal_session/connection.h>
|
||||
#include <base/attached_rom_dataspace.h>
|
||||
#include <base/attached_ram_dataspace.h>
|
||||
#include <base/sleep.h>
|
||||
|
||||
@@ -65,6 +66,8 @@ struct Mp3_audio_sink::Decoder
|
||||
|
||||
Genode::Env &_env;
|
||||
|
||||
Attached_rom_dataspace _config_rom { _env, "config" };
|
||||
|
||||
Audio_out::Connection _out_left { _env, "left", true, true };
|
||||
Audio_out::Connection _out_right { _env, "right", false, false };
|
||||
Audio_out::Connection *_out[NUM_CHANNELS];
|
||||
@@ -187,11 +190,39 @@ struct Mp3_audio_sink::Decoder
|
||||
Io_signal_handler<Decoder> _progress_handler {
|
||||
_env.ep(), *this, &Decoder::submit_audio };
|
||||
|
||||
Signal_handler<Decoder> _config_handler {
|
||||
_env.ep(), *this, &Decoder::_handle_config };
|
||||
|
||||
void _handle_config()
|
||||
{
|
||||
_config_rom.update();
|
||||
Xml_node const config = _config_rom.xml();
|
||||
|
||||
enum { EQ_COUNT = 32 };
|
||||
|
||||
mpg123_reset_eq(_mh);
|
||||
config.for_each_sub_node("eq", [&] (Xml_node const &node) {
|
||||
unsigned band = node.attribute_value("band", 32U);
|
||||
double value = node.attribute_value("value", 0.0);
|
||||
if (band < EQ_COUNT && value != 0.0) {
|
||||
mpg123_eq(_mh, MPG123_LR , band, value);
|
||||
log("EQ ", band, ": ", mpg123_geteq(_mh, MPG123_LR , band));
|
||||
}
|
||||
});
|
||||
|
||||
double volume = 0.5;
|
||||
config.for_each_sub_node("volume", [&] (Xml_node const &node) {
|
||||
volume = node.attribute_value("linear", volume); });
|
||||
mpg123_volume(_mh, 0.5);
|
||||
}
|
||||
|
||||
Decoder(Genode::Env &env) : _env(env)
|
||||
{
|
||||
_out[LEFT] = &_out_left;
|
||||
_out[RIGHT] = &_out_right;
|
||||
_out_left.progress_sigh(_progress_handler);
|
||||
_config_rom.sigh(_config_handler);
|
||||
_handle_config();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user