Skip to content

Commit e92d096

Browse files
authored
Merge pull request #148 from singalsu/volume_zipper_fix_proposal
Volume: Mitigate zipper noise by adjusting gain ramp parameters
2 parents 4547b0b + 05a8574 commit e92d096

1 file changed

Lines changed: 24 additions & 9 deletions

File tree

src/audio/volume.h

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,34 @@
6464
/** \brief Volume trace error function. */
6565
#define trace_volume_error(__e) trace_error(TRACE_CLASS_VOLUME, __e)
6666

67+
//** \brief Volume gain Qx.y integer x number of bits including sign bit. */
68+
#define VOL_QXY_X 2
69+
70+
//** \brief Volume gain Qx.y fractional y number of bits. */
71+
#define VOL_QXY_Y 16
72+
6773
/**
68-
* \brief Volume ramp time in microseconds.
69-
*
70-
* This should ramp from 0dB to mute in 64ms.
71-
* i.e. 2^16 -> 0 in 32 * 2048 steps each lasting 2ms.
74+
* \brief Volume ramp update rate in microseconds.
75+
* Update volume gain value every 1 ms.
7276
*/
73-
#define VOL_RAMP_US 2000
77+
#define VOL_RAMP_US 1000
7478

75-
/** \brief Volume ramp step. */
76-
#define VOL_RAMP_STEP (1 << 11)
79+
/**
80+
* \brief Volume linear ramp length in milliseconds.
81+
* Use linear ramp length of 250 ms from mute to unity gain. The linear ramp
82+
* step in Q1.16 to use in vol_work function is computed from the length.
83+
*/
84+
#define VOL_RAMP_LENGTH_MS 250
85+
#define VOL_RAMP_STEP Q_CONVERT_FLOAT(1.0 / 1000 * \
86+
VOL_RAMP_US / VOL_RAMP_LENGTH_MS, \
87+
VOL_QXY_Y)
7788

78-
/** \brief Volume maximum value. */
79-
#define VOL_MAX (1 << 16)
89+
/**
90+
* \brief Volume maximum value.
91+
* TODO: This should be 1 << (VOL_QX_BITS + VOL_QY_BITS - 1) - 1 but
92+
* the current volume code cannot handle the full Q1.16 range correctly.
93+
*/
94+
#define VOL_MAX (1 << VOL_QXY_Y)
8095

8196
/** \brief Volume minimum value. */
8297
#define VOL_MIN 0

0 commit comments

Comments
 (0)