Skip to content

Commit

Permalink
dde_bsd: support microphone selection
Browse files Browse the repository at this point in the history
Make preferred microphone configurable when a headset is plugged in by
introducing the 'mic_priority' attribute for the <config> node. Values
can be "internal" and "external".
  • Loading branch information
ssumpf authored and chelmuth committed Dec 16, 2024
1 parent 3f2a867 commit c156c60
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
10 changes: 10 additions & 0 deletions repos/dde_bsd/README
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ Information about the available mixers and settings in general
may be obtained by setting the 'verbose' to 'yes' in the config
node.

When multiple microphones are present (e.g., internal microphone in a notebook
and a headset with a microphone), the preferred microphone can be configured
using the 'mic_priority' attribute in the '<config>' node. Valid values are
"internal" and "external" (default).

! <config mic_priority="internal"/>

The example above tells the driver to prioritize the internal microphone over a
headset.


Examples
========
Expand Down
12 changes: 11 additions & 1 deletion repos/dde_bsd/src/lib/audio/driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ static dev_t const mdev = 0xc0; /* /dev/audioctl */

static bool adev_usuable = false;

/* prioritize mic of headset if plugged in over internal mic */
static bool mic_priority_external = true;

static bool drv_loaded()
{
Expand Down Expand Up @@ -389,6 +391,11 @@ static void configure_mixer(Genode::Env &env, Mixer &mixer, Genode::Xml_node con
{
using namespace Genode;

typedef String<9> Mic_mode;

Mic_mode mode = config.attribute_value("mic_priority", Mic_mode("external"));
mic_priority_external = (mode == "internal") ? false : true;

config.for_each_sub_node("mixer", [&] (Xml_node node) {

typedef String<32> Field;
Expand Down Expand Up @@ -615,7 +622,8 @@ extern "C" void notify_record()

extern "C" void notify_hp_sense(int const sense)
{
set_mixer_value(mixer, "record.adc-0:1_source", sense ? "mic2" : "mic");
set_mixer_value(mixer, "record.adc-0:1_source",
sense && mic_priority_external ? "mic2" : "mic");

report_mixer_state(mixer, nullptr);
}
Expand All @@ -630,6 +638,8 @@ void Audio::update_config(Genode::Env &env, Genode::Xml_node config)
if (mixer.info == nullptr) { return; }

configure_mixer(env, mixer, config);

notify_hp_sense(headphone_plugged() ? 1 : 0);
}


Expand Down

0 comments on commit c156c60

Please sign in to comment.