PulseAudio overuses 'Boost' control of microphone input producing bad audio quality

Bug #1085402 reported by Alexander Mescheryakov
34
This bug affects 7 people
Affects Status Importance Assigned to Milestone
pulseaudio (Ubuntu)
Undecided
Unassigned

Bug Description

Om my notebook PulseAudio detects 2 ports on embedded sound card:
1) analog-input-microphone-internal
2) analog-input-microphone

PulseAudio module "module-switch-on-port-available" chooses as default port #2 after external microphone is attached and switches back to port #1 after external mike removal.

This behavior seems right.

However, if I record sound with auto selected port, audio quality is very poor. There is loud noise in background. But if I switch to "wrong" port audio quality becomes great. E.g. I have to manually select "analog-input-microphone-internal" port when I attach external mike and vice versa.

Example of record:
http://self-perfection.homeip.net/files/2012/external_ru.flac (652 KiB)
This record is made via headset microphone. During first half of record source port analog-input-microphone was selected then i switched to port analog-input-microphone-internal.

ProblemType: Bug
DistroRelease: Ubuntu 12.10
Package: pulseaudio 1:2.1-0ubuntu4
ProcVersionSignature: Ubuntu 3.5.0-18.29-generic 3.5.7
Uname: Linux 3.5.0-18-generic x86_64
ApportVersion: 2.6.1-0ubuntu6
Architecture: amd64
AudioDevicesInUse:
 USER PID ACCESS COMMAND
 /dev/snd/controlC0: self 2150 F.... pulseaudio
                      self 2255 F.... xfce4-volumed
Date: Sat Dec 1 16:34:31 2012
InstallationDate: Installed on 2012-07-01 (152 days ago)
InstallationMedia: Xubuntu 12.04 LTS "Precise Pangolin" - Release amd64 (20120425)
MarkForUpload: True
SourcePackage: pulseaudio
UpgradeStatus: Upgraded to quantal on 2012-10-21 (40 days ago)
dmi.bios.date: 04/03/2012
dmi.bios.vendor: Phoenix Technologies Ltd.
dmi.bios.version: 06QB
dmi.board.asset.tag: Base Board Asset Tag
dmi.board.name: 300E4Z/300E5Z/300E7Z
dmi.board.vendor: SAMSUNG ELECTRONICS CO., LTD.
dmi.board.version: FAB1
dmi.chassis.asset.tag: Asset Tag
dmi.chassis.type: 9
dmi.chassis.vendor: SAMSUNG ELECTRONICS CO., LTD.
dmi.chassis.version: 0.1
dmi.modalias: dmi:bvnPhoenixTechnologiesLtd.:bvr06QB:bd04/03/2012:svnSAMSUNGELECTRONICSCO.,LTD.:pn300E4Z/300E5Z/300E7Z:pvr0.1:rvnSAMSUNGELECTRONICSCO.,LTD.:rn300E4Z/300E5Z/300E7Z:rvrFAB1:cvnSAMSUNGELECTRONICSCO.,LTD.:ct9:cvr0.1:
dmi.product.name: 300E4Z/300E5Z/300E7Z
dmi.product.version: 0.1
dmi.sys.vendor: SAMSUNG ELECTRONICS CO., LTD.

Revision history for this message
Alexander Mescheryakov (alexander-s-m) wrote :
Revision history for this message
Raymond (superquad-vortex2) wrote :

post the pulseaudio verbose log when you plug and unplug the mic

did pulseaudio retain the total dB (Capture Volume + Boost) ?

Simple mixer control 'Mic Boost',0
  Capabilities: volume penum
  Playback channels: Front Left - Front Right
  Capture channels: Front Left - Front Right
  Limits: 0 - 3
  Front Left: 0 [0%] [0.00dB]
  Front Right: 0 [0%] [0.00dB]

Simple mixer control 'Internal Mic Boost',0
  Capabilities: volume penum
  Playback channels: Front Left - Front Right
  Capture channels: Front Left - Front Right
  Limits: 0 - 3
  Front Left: 3 [100%] [36.00dB]
  Front Right: 3 [100%] [36.00dB]

Revision history for this message
Alexander Mescheryakov (alexander-s-m) wrote :
Revision history for this message
Alexander Mescheryakov (alexander-s-m) wrote :
Revision history for this message
Alexander Mescheryakov (alexander-s-m) wrote :

Raymond, I have attached verbose PA log of microphone plugging/unplugging. It does not seem to contain valuable info though.

Checking volume levels with alsamixer lead to interesting results. It turns out that I have common 'Capture' control for both source ports and separate controls 'Internal Mic Boost' and 'Mic Boost'. Source volume is a sum of 'Capture' and corresponding 'Boost'.

PA prefers increasing boost volume when it sets source volume, so boost goes up to 100% even at 28% source volume.

So I ended up with one of the boost controls maximized when I was making my records. By switching to 'wrong' port I have moved boost to wrong control, leaving current port without boost and thus without noise.

To illustrate this behavior a dumped amixer control levels for source volumes from 1% to 102% with following script

for v in {1..102}; do
    echo "Setting volume=$v%"
    pactl set-source-volume 1 $v%
    amixer scontents | sed -n "/'Capture'\|'Internal Mic Boost'/,/^ Front Right/p"
    echo
done > volume_amixer.log

You can check log of PulseAudio (volume_pulse.log) while performing this test as well.

--------------------------
Finally:
It seems wrong, that PulseAudio prefers to increase 'Boost' control over 'Capture' control. 'Boost' should not be increased from zero value if increasing 'Capture' control is enough to get overall requested volume.

Revision history for this message
Alexander Mescheryakov (alexander-s-m) wrote :

1) I have found discussions regarding this problem
https://lists.ubuntu.com/archives/ubuntu-studio-devel/2011-December/003768.html
2) As a temporary solution I have changed in conf files in
/usr/share/pulseaudio/alsa-mixer/paths
in all sections regarding boost 'volume = merge' to 'volume = zero'.

I would like to find solution that will not break after PulseAudio package upgrade.

summary: - Wrong auto selection of microphone input
+ PulseAudio overuses 'Boost' control of microphone input producing bad
+ audio quality
Revision history for this message
Raymond (superquad-vortex2) wrote :

the amp-in at audio input has a 30dB gain

  Node 0x08 [Audio Input] wcaps 0x10011b: Stereo Amp-In
  Control: name="Capture Switch", index=0, device=0
  Control: name="Capture Volume", index=0, device=0
  Device: name="ALC269VB Analog", type="Audio", device=0
  Amp-In caps: ofs=0x0b, nsteps=0x1f, stepsize=0x05, mute=1
  Amp-In vals: [0x1e 0x1e]
  Converter: stream=0, channel=0
  SDI-Select: 0
  PCM:
    rates [0x560]: 44100 48000 96000 192000
    bits [0xe]: 16 20 24
    formats [0x1]: PCM
  Connection: 1
     0x23

control.10 {
  iface MIXER
  name 'Mic Boost Volume'
  value.0 0
  value.1 0
  comment {
   access 'read write'
   type INTEGER
   count 2
   range '0 - 3'
   dbmin 0
   dbmax 3600
   dbvalue.0 0
   dbvalue.1 0
  }
 }
 control.11 {
  iface MIXER
  name 'Internal Mic Boost Volume'
  value.0 3
  value.1 3
  comment {
   access 'read write'
   type INTEGER
   count 2
   range '0 - 3'
   dbmin 0
   dbmax 3600
   dbvalue.0 3600
   dbvalue.1 3600
  }
 }
 control.12 {
  iface MIXER
  name 'Capture Switch'
  value.0 true
  value.1 true
  comment {
   access 'read write'
   type BOOLEAN
   count 2
  }
 }
 control.13 {
  iface MIXER
  name 'Capture Volume'
  value.0 30
  value.1 30
  comment {
   access 'read write'
   type INTEGER
   count 2
   range '0 - 31'
   dbmin -1650
   dbmax 3000
   dbvalue.0 2850
   dbvalue.1 2850
  }
 }

Changed in pulseaudio (Ubuntu):
status: New → Confirmed
Revision history for this message
Luke Marsden (v-luke) wrote :

This was also affecting me, causing very loud hissing on Skype calls.

The change in https://bugs.launchpad.net/ubuntu/+source/pulseaudio/+bug/1085402/comments/6 fixes it for me, that is, in /usr/share/pulseaudio/alsa-mixer/paths/analog-input-mic.conf in the "[Element Mic Boost]" section, change "volume = merge" to "volume = zero" and restart Pulseaudio ("sudo pkill pulseaudio") then restart Skype.

I also had to manually set the Mic Boost values to zero in alsamixer (F6, change card, "HDA Intel PCH").

Revision history for this message
David Henningsson (diwic) wrote :

I did a small test on two machines I have here, one ALC888 + front mic and one IDT92xx + internal mic. I tested recording with Capture at +30 dB and Mic Boost at 0 dB, then I tested recording with Capture at 0 dB and Mic Boost at +30 dB.

For both machines, there was no significant difference in quality.

So, this is very hardware dependent. We could flip it so that we raise Capture first and then Mic Boost, which would help here, so I'm seriously considering that - but the question is if this has negative effect on other hardware, maybe it's the other way around w r t to quality on other machines?

Revision history for this message
David Henningsson (diwic) wrote : [PATCH] alsa-mixer: Prefer moving "Capture" before moving boosts
Download full text (8.1 KiB)

Some HD-audio codecs (at least ALC269VB and ALC283) become quite noisy on
high Mic Boost levels. So e g, if there is a "Mic Boost" and a "Capture"
control, both ranging from 0 dB to +30 dB, you get better quality if
"Mic Boost" is 0 dB and "Capture" is +30 dB, than the other way around.

By changing the order in the configuration files, this patch makes us prefer
leaving "Mic Boost" low and "Capture" high if the user selects a medium gain.

(This is based on limited experience, and there is no guarantee that there are
no sound cards that work the other way around, and therefore this patch could
potentially regress quality on those machines. Hopefully those are fewer, so
this is what we should default to.)

BugLink: https://bugs.launchpad.net/1085402
Signed-off-by: David Henningsson <email address hidden>
---
 .../alsa/mixer/paths/analog-input-dock-mic.conf | 12 ++++++------
 .../alsa/mixer/paths/analog-input-front-mic.conf | 12 ++++++------
 .../mixer/paths/analog-input-headphone-mic.conf | 12 ++++++------
 .../alsa/mixer/paths/analog-input-headset-mic.conf | 12 ++++++------
 .../paths/analog-input-internal-mic-always.conf | 13 ++++++-------
 .../mixer/paths/analog-input-internal-mic.conf | 13 ++++++-------
 src/modules/alsa/mixer/paths/analog-input-mic.conf | 12 ++++++------
 .../alsa/mixer/paths/analog-input-rear-mic.conf | 12 ++++++------
 8 files changed, 48 insertions(+), 50 deletions(-)

diff --git a/src/modules/alsa/mixer/paths/analog-input-dock-mic.conf b/src/modules/alsa/mixer/paths/analog-input-dock-mic.conf
index 9334d45..85a8658 100644
--- a/src/modules/alsa/mixer/paths/analog-input-dock-mic.conf
+++ b/src/modules/alsa/mixer/paths/analog-input-dock-mic.conf
@@ -30,6 +30,12 @@ state.plugged = unknown
 state.unplugged = unknown
 required-any = any

+[Element Capture]
+switch = mute
+volume = merge
+override-map.1 = all
+override-map.2 = all-left,all-right
+
 [Element Dock Mic Boost]
 required-any = any
 switch = select
@@ -50,12 +56,6 @@ volume = merge
 override-map.1 = all
 override-map.2 = all-left,all-right

-[Element Capture]
-switch = mute
-volume = merge
-override-map.1 = all
-override-map.2 = all-left,all-right
-
 [Element Input Source]
 enumeration = select

diff --git a/src/modules/alsa/mixer/paths/analog-input-front-mic.conf b/src/modules/alsa/mixer/paths/analog-input-front-mic.conf
index 3fb5f5e..5265e5b 100644
--- a/src/modules/alsa/mixer/paths/analog-input-front-mic.conf
+++ b/src/modules/alsa/mixer/paths/analog-input-front-mic.conf
@@ -30,6 +30,12 @@ required-any = any
 state.plugged = unknown
 state.unplugged = unknown

+[Element Capture]
+switch = mute
+volume = merge
+override-map.1 = all
+override-map.2 = all-left,all-right
+
 [Element Front Mic Boost]
 required-any = any
 switch = select
@@ -50,12 +56,6 @@ volume = merge
 override-map.1 = all
 override-map.2 = all-left,all-right

-[Element Capture]
-switch = mute
-volume = merge
-override-map.1 = all
-override-map.2 = all-left,all-right
-
 [Element Input Source]
 enumeration = select

diff --git a/src/modules/alsa/mixer/paths/analog-input-headphone-mic.conf b/src/modules/alsa/mixer/paths/analog-input-headphone-mic...

Read more...

Changed in pulseaudio (Ubuntu):
status: Confirmed → Triaged
Revision history for this message
David Henningsson (diwic) wrote :
Download full text (4.7 KiB)

On 08/02/2013 03:34 PM, Arun Raghavan wrote:
> On Fri, 2013-08-02 at 15:19 +0200, David Henningsson wrote:
>> Some HD-audio codecs (at least ALC269VB and ALC283) become quite noisy on
>> high Mic Boost levels. So e g, if there is a "Mic Boost" and a "Capture"
>> control, both ranging from 0 dB to +30 dB, you get better quality if
>> "Mic Boost" is 0 dB and "Capture" is +30 dB, than the other way around.
>>
>> By changing the order in the configuration files, this patch makes us prefer
>> leaving "Mic Boost" low and "Capture" high if the user selects a medium gain.
>>
>> (This is based on limited experience, and there is no guarantee that there are
>> no sound cards that work the other way around, and therefore this patch could
>> potentially regress quality on those machines. Hopefully those are fewer, so
>> this is what we should default to.)
> [...]
>> diff --git a/src/modules/alsa/mixer/paths/analog-input-headphone-mic.conf b/src/modules/alsa/mixer/paths/analog-input-headphone-mic.conf
>> index 688b8ac..3a19e01 100644
>> --- a/src/modules/alsa/mixer/paths/analog-input-headphone-mic.conf
>> +++ b/src/modules/alsa/mixer/paths/analog-input-headphone-mic.conf
>> @@ -27,21 +27,21 @@ description-key = analog-input-microphone
>> required-any = any
>> state.plugged = unknown
>>
>> -[Element Headphone Mic Boost]
>> -required-any = any
>> -switch = select
>> +[Element Capture]
>> +switch = mute
>> volume = merge
>> override-map.1 = all
>> override-map.2 = all-left,all-right
>>
>> -[Element Headphone Mic]
>> +[Element Headphone Mic Boost]
>
> If we're doing this, might as well prefer Headphone Mic over Headphone
> Mic Boost?

We could, but I'd rather have some sort of evidence/indication that this
will actually make a difference first. For starters, it's unusual to
have both "Headphone Mic" and "Headphone Mic Boost" on the same sound card.

Also, we're moving this around because we have empirical experience that
hardware behaves this way, not because it is logical for hardware to do
so. Hence I'd refrain from extending the same logic to other controls.

Btw, the reason I'm moving "Capture" rather than the Mic Boosts is that
I remember sometimes boosts are labelled "xx Mic" instead "xx Mic
Boost", even though they are boosts and could potentially work the same
way (become noisy at high levels).

>> required-any = any
>> -switch = mute
>> +switch = select
>> volume = merge
>> override-map.1 = all
>> override-map.2 = all-left,all-right
>>
>> -[Element Capture]
>> +[Element Headphone Mic]
>> +required-any = any
>> switch = mute
>> volume = merge
>> override-map.1 = all
> [...]
>> diff --git a/src/modules/alsa/mixer/paths/analog-input-internal-mic-always.conf b/src/modules/alsa/mixer/paths/analog-input-internal-mic-always.conf
>> index cd08531..e9c288e 100644
>> --- a/src/modules/alsa/mixer/paths/analog-input-internal-mic-always.conf
>> +++ b/src/modules/alsa/mixer/paths/analog-input-internal-mic-always.conf
>> @@ -39,6 +39,12 @@ state.unplugged = unknown
>> state.plugged = no
>> state.unplugged = unknown
>>
>> +[Element Capture]
>> +switch = mute
>> +volume = merge
>> +override-map.1 = all
>> +override-map.2 = all-left,all-right
>>...

Read more...

Revision history for this message
David Henningsson (diwic) wrote :
Changed in pulseaudio (Ubuntu):
status: Triaged → Fix Committed
Changed in pulseaudio (Ubuntu):
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers