Index: apps/pcmbuf.c
===================================================================
--- apps/pcmbuf.c (revision 22783)
+++ apps/pcmbuf.c (working copy)
@@ -1170,30 +1170,30 @@
* Commit any remaining samples in the PCM buffer for playback. */
void pcmbuf_play_remainder(void)
{
- pcmbuf_flush_limiter_buffer();
+ pcmbuf_flush_compressor_buffer();
if (audiobuffer_fillpos)
pcmbuf_flush_fillpos();
}
-/** FLUSH LIMITER BUFFER
- * Empty the limiter buffer and commit its contents
+/** FLUSH COMPRESSOR BUFFER
+ * Empty the compressor buffer and commit its contents
* to the PCM buffer for playback. */
-void pcmbuf_flush_limiter_buffer(void)
+void pcmbuf_flush_compressor_buffer(void)
{
char *dest;
- int out_count = LIMITER_BUFFER_SIZE;
+ int out_count = COMPRESSOR_BUFFER_SIZE;
/* create room at the end of the PCM buffer for any
- samples that may be held back in the limiter buffer */
+ samples that may be held back in the compressor buffer */
while ((dest = pcmbuf_request_buffer(&out_count)) == NULL)
{
cancel_cpu_boost();
sleep(1);
}
- /* flush the limiter buffer into the PCM buffer */
- out_count = dsp_flush_limiter_buffer(dest);
+ /* flush the compressor buffer into the PCM buffer */
+ out_count = dsp_flush_compressor_buffer(dest);
if (out_count > 0)
pcmbuf_write_complete(out_count);
}
Index: apps/pcmbuf.h
===================================================================
--- apps/pcmbuf.h (revision 22783)
+++ apps/pcmbuf.h (working copy)
@@ -76,6 +76,6 @@
int pcmbuf_used_descs(void);
int pcmbuf_descs(void);
void pcmbuf_play_remainder(void);
-void pcmbuf_flush_limiter_buffer(void);
+void pcmbuf_flush_compressor_buffer(void);
#endif
Index: apps/settings.c
===================================================================
--- apps/settings.c (revision 22783)
+++ apps/settings.c (working copy)
@@ -956,7 +956,14 @@
dsp_dither_enable(global_settings.dithering_enabled);
dsp_timestretch_enable(global_settings.timestretch_enabled);
- dsp_set_limiter(global_settings.limiter_level);
+ dsp_set_compressor(global_settings.compressor_threshold,
+ global_settings.compressor_ratio,
+ global_settings.compressor_makeup_gain,
+ global_settings.compressor_knee,
+ global_settings.compressor_attack_time,
+ global_settings.compressor_release_time,
+ /* global_settings.compressor_mode, */
+ global_settings.compressor_auto_peak);
#endif
#ifdef HAVE_SPDIF_POWER
Index: apps/plugins/test_codec.c
===================================================================
--- apps/plugins/test_codec.c (revision 22783)
+++ apps/plugins/test_codec.c (working copy)
@@ -812,7 +812,7 @@
}
/* process last samples */
if (use_dsp)
- rb->dsp_flush_limiter_buffer(dspbuffer);
+ rb->dsp_flush_compressor_buffer(dspbuffer);
} else {
/* Just test the file */
res = test_track(parameter);
@@ -821,7 +821,7 @@
if (use_dsp)
{
int channels = (wavinfo.stereomode == STEREO_MONO) ? 1 : 2;
- int count = rb->dsp_flush_limiter_buffer(dspbuffer);
+ int count = rb->dsp_flush_compressor_buffer(dspbuffer);
if (channels == 1)
{
unsigned char *s = dspbuffer, *d = dspbuffer;
Index: apps/lang/polski.lang
===================================================================
--- apps/lang/polski.lang (revision 22783)
+++ apps/lang/polski.lang (working copy)
@@ -12644,15 +12644,15 @@
user: core
*: none
- swcodec: "Limiter Preamp"
+ swcodec: "Compressor"
*: none
- swcodec: "Wzmacnianie cichych fragmentów"
+ swcodec: "Compressor"
*: none
- swcodec: "Wzmacnianie cichych fragmentów"
+ swcodec: "Compressor"
Index: apps/lang/svenska.lang
===================================================================
--- apps/lang/svenska.lang (revision 22783)
+++ apps/lang/svenska.lang (working copy)
@@ -12637,14 +12637,14 @@
user: core
*: none
- swcodec: "Limiter Preamp"
+ swcodec: "Compressor"
*: none
- swcodec: "Limiter-förförstärkning"
+ swcodec: "Compressor"
*: none
- swcodec: "Limiter-förförstärkning"
+ swcodec: "Compressor"
Index: apps/lang/francais.lang
===================================================================
--- apps/lang/francais.lang (revision 22783)
+++ apps/lang/francais.lang (working copy)
@@ -12663,15 +12663,15 @@
user: core
*: none
- swcodec: "Limiter Preamp"
+ swcodec: "Compressor"
*: none
- swcodec: "Limiteur préampli."
+ swcodec: "Compressor"
*: none
- swcodec: "Limiteur préampli"
+ swcodec: "Compressor"
Index: apps/lang/english.lang
===================================================================
--- apps/lang/english.lang (revision 22783)
+++ apps/lang/english.lang (working copy)
@@ -12707,15 +12707,15 @@
user: core
*: none
- swcodec: "Limiter Preamp"
+ swcodec: "Compressor"
*: none
- swcodec: "Limiter Preamp"
+ swcodec: "Compressor"
*: none
- swcodec: "Limiter Preamp"
+ swcodec: "Compressor"
@@ -12735,3 +12735,292 @@
quickscreen: "Set as Top Quickscreen Item"
+
+ id: LANG_COMPRESSOR_THRESHOLD
+ desc: in sound settings
+ user: core
+
+ *: none
+ swcodec: "Threshold"
+
+
+ *: none
+ swcodec: "Threshold"
+
+
+ *: none
+ swcodec: "Threshold"
+
+
+
+ id: LANG_COMPRESSOR_RATIO
+ desc: in sound settings
+ user: core
+
+ *: none
+ swcodec: "Ratio"
+
+
+ *: none
+ swcodec: "Ratio"
+
+
+ *: none
+ swcodec: "Ratio"
+
+
+
+ id: LANG_COMPRESSOR_RATIO_2
+ desc: in sound settings
+ user: core
+
+ *: none
+ swcodec: "2:1"
+
+
+ *: none
+ swcodec: "2:1"
+
+
+ *: none
+ swcodec: "2 to 1"
+
+
+
+ id: LANG_COMPRESSOR_RATIO_4
+ desc: in sound settings
+ user: core
+
+ *: none
+ swcodec: "4:1"
+
+
+ *: none
+ swcodec: "4:1"
+
+
+ *: none
+ swcodec: "4 to 1"
+
+
+
+ id: LANG_COMPRESSOR_RATIO_10
+ desc: in sound settings
+ user: core
+
+ *: none
+ swcodec: "10:1"
+
+
+ *: none
+ swcodec: "10:1"
+
+
+ *: none
+ swcodec: "10 to 1"
+
+
+
+ id: LANG_COMPRESSOR_RATIO_20
+ desc: in sound settings
+ user: core
+
+ *: none
+ swcodec: "20:1"
+
+
+ *: none
+ swcodec: "20:1"
+
+
+ *: none
+ swcodec: "20 to 1"
+
+
+
+ id: LANG_COMPRESSOR_RATIO_60
+ desc: in sound settings
+ user: core
+
+ *: none
+ swcodec: "60:1"
+
+
+ *: none
+ swcodec: "60:1"
+
+
+ *: none
+ swcodec: "60 to 1"
+
+
+
+ id: LANG_COMPRESSOR_GAIN
+ desc: in sound settings
+ user: core
+
+ *: none
+ swcodec: "Makeup Gain"
+
+
+ *: none
+ swcodec: "Makeup Gain"
+
+
+ *: none
+ swcodec: "Makeup Gain"
+
+
+
+ id: LANG_COMPRESSOR_KNEE
+ desc: in sound settings
+ user: core
+
+ *: none
+ swcodec: "Knee"
+
+
+ *: none
+ swcodec: "Knee"
+
+
+ *: none
+ swcodec: "Knee"
+
+
+
+ id: LANG_COMPRESSOR_HARD_KNEE
+ desc: in sound settings
+ user: core
+
+ *: none
+ swcodec: "Hard Knee"
+
+
+ *: none
+ swcodec: "Hard Knee"
+
+
+ *: none
+ swcodec: "Hard Knee"
+
+
+
+ id: LANG_COMPRESSOR_SOFT_KNEE
+ desc: in sound settings
+ user: core
+
+ *: none
+ swcodec: "Soft Knee"
+
+
+ *: none
+ swcodec: "Soft Knee"
+
+
+ *: none
+ swcodec: "Soft Knee"
+
+
+
+ id: LANG_COMPRESSOR_ATTACK
+ desc: in sound settings
+ user: core
+
+ *: none
+ swcodec: "Attack Time"
+
+
+ *: none
+ swcodec: "Attack Time"
+
+
+ *: none
+ swcodec: "Attack Time"
+
+
+
+ id: LANG_COMPRESSOR_RELEASE
+ desc: in sound settings
+ user: core
+
+ *: none
+ swcodec: "Release Time"
+
+
+ *: none
+ swcodec: "Release Time"
+
+
+ *: none
+ swcodec: "Release Time"
+
+
+
+ id: LANG_COMPRESSOR_AUTO_PEAK
+ desc: in sound settings
+ user: core
+
+ *: none
+ swcodec: "Auto Peak"
+
+
+ *: none
+ swcodec: "Auto Peak"
+
+
+ *: none
+ swcodec: "Auto Peak"
+
+
+#
+# id: LANG_COMPRESSOR_MODE
+# desc: in sound settings
+# user: core
+#
+# *: none
+# swcodec: "Mode"
+#
+#
+# *: none
+# swcodec: "Mode"
+#
+#
+# *: none
+# swcodec: "Mode"
+#
+#
+#
+# id: LANG_COMPRESSOR_PEAK
+# desc: in sound settings
+# user: core
+#
+# *: none
+# swcodec: "Peak"
+#
+#
+# *: none
+# swcodec: "Peak"
+#
+#
+# *: none
+# swcodec: "Peak"
+#
+#
+#
+# id: LANG_COMPRESSOR_RMS
+# desc: in sound settings
+# user: core
+#
+# *: none
+# swcodec: "RMS"
+#
+#
+# *: none
+# swcodec: "RMS"
+#
+#
+# *: none
+# swcodec: "RMS"
+#
+#
Index: apps/lang/italiano.lang
===================================================================
--- apps/lang/italiano.lang (revision 22783)
+++ apps/lang/italiano.lang (working copy)
@@ -12636,15 +12636,15 @@
user: core
*: none
- swcodec: "Limiter Preamp"
+ swcodec: "Compressor"
*: none
- swcodec: "Limitatore Preamp"
+ swcodec: "Compressor"
*: none
- swcodec: "Limitatore Preamp"
+ swcodec: "Compressor"
Index: apps/lang/tagalog.lang
===================================================================
--- apps/lang/tagalog.lang (revision 22783)
+++ apps/lang/tagalog.lang (working copy)
@@ -12445,15 +12445,15 @@
user: core
*: none
- swcodec: "Limiter Preamp"
+ swcodec: "Compressor"
*: none
- swcodec: "Limiter Preamp"
+ swcodec: "Compressor"
*: none
- swcodec: "Limiter Preamp"
+ swcodec: "Compressor"
Index: apps/settings.h
===================================================================
--- apps/settings.h (revision 22783)
+++ apps/settings.h (working copy)
@@ -777,7 +777,14 @@
#endif
#if CONFIG_CODEC == SWCODEC
- int limiter_level;
+ int compressor_threshold;
+ int compressor_ratio;
+ int compressor_makeup_gain;
+ int compressor_knee;
+ int compressor_attack_time;
+ int compressor_release_time;
+ bool compressor_auto_peak;
+ /* int compressor_mode; */
#endif
};
Index: apps/menus/sound_menu.c
===================================================================
--- apps/menus/sound_menu.c (revision 22783)
+++ apps/menus/sound_menu.c (working copy)
@@ -105,8 +105,28 @@
&global_settings.timestretch_enabled, timestretch_callback);
MENUITEM_SETTING(dithering_enabled,
&global_settings.dithering_enabled, lowlatency_callback);
- MENUITEM_SETTING(limiter_level,
- &global_settings.limiter_level, lowlatency_callback);
+
+ /* compressor submenu */
+ MENUITEM_SETTING(compressor_threshold,
+ &global_settings.compressor_threshold, lowlatency_callback);
+ MENUITEM_SETTING(compressor_ratio,
+ &global_settings.compressor_ratio, lowlatency_callback);
+ MENUITEM_SETTING(compressor_gain,
+ &global_settings.compressor_makeup_gain, lowlatency_callback);
+ MENUITEM_SETTING(compressor_knee,
+ &global_settings.compressor_knee, lowlatency_callback);
+ MENUITEM_SETTING(compressor_attack,
+ &global_settings.compressor_attack_time, lowlatency_callback);
+ MENUITEM_SETTING(compressor_release,
+ &global_settings.compressor_release_time, lowlatency_callback);
+ /* MENUITEM_SETTING(compressor_mode,
+ &global_settings.compressor_mode, lowlatency_callback); */
+ MENUITEM_SETTING(compressor_auto_peak,
+ &global_settings.compressor_auto_peak, lowlatency_callback);
+ MAKE_MENU(compressor_menu,ID2P(LANG_COMPRESSOR), NULL, Icon_NOICON,
+ &compressor_threshold, &compressor_ratio, &compressor_gain,
+ &compressor_knee, &compressor_attack, &compressor_release,
+ /* &compressor_mode, */ &compressor_auto_peak);
#endif
#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
@@ -140,7 +160,7 @@
#if CONFIG_CODEC == SWCODEC
,&crossfeed_menu, &equalizer_menu, &dithering_enabled
,×tretch_enabled
- ,&limiter_level
+ ,&compressor_menu
#endif
#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
,&loudness,&avc,&superbass,&mdb_enable,&mdb_strength
Index: apps/fixedpoint.h
===================================================================
--- apps/fixedpoint.h (revision 22783)
+++ apps/fixedpoint.h (working copy)
@@ -61,7 +61,7 @@
#define FP_NEGINF -(0x7fffffff)
/* fracbits in range 12 - 22 work well. Higher is better for
- * calculating dB, lower is better for calculating ratio.
+ * calculating dB, lower is better for calculating factor.
*/
/* long fp_decibels(unsigned long factor, unsigned int fracbits); */
long fp_factor(long decibels, unsigned int fracbits);
Index: apps/dsp.c
===================================================================
--- apps/dsp.c (revision 22783)
+++ apps/dsp.c (working copy)
@@ -137,6 +137,18 @@
/* 10ch */
};
+struct compressor_menu
+{
+ int threshold; /* dB - from menu */
+ int ratio; /* from menu */
+ int gain; /* dB - from menu */
+ bool soft_knee; /* 0 = hard knee, 1 = soft knee */
+ int attack; /* samples - from menu */
+ int release; /* samples - from menu */
+ /* bool rms; */ /* 0 = peak, 1 = RMS */
+ bool auto_peak; /* from menu */
+};
+
/* Include header with defines which functions are implemented in assembly
code for the target */
#include
@@ -171,7 +183,6 @@
int32_t tdspeed_percent; /* Speed% * PITCH_SPEED_PRECISION */
bool tdspeed_active; /* Timestretch is in use */
int frac_bits;
- long limiter_preamp; /* limiter amp gain in S7.24 format */
#ifdef HAVE_SW_TONE_CONTROLS
/* Filter struct for software bass/treble controls */
struct eqfilter tone_filter;
@@ -187,7 +198,7 @@
channels_process_fn_type apply_crossfeed;
channels_process_fn_type eq_process;
channels_process_fn_type channels_process;
- return_fn_type limiter_process;
+ return_fn_type compressor_process;
};
/* General DSP config */
@@ -253,60 +264,33 @@
#define RESAMPLE_BUF_LEFT_CHANNEL 0
#define RESAMPLE_BUF_RIGHT_CHANNEL (sample_buf_count/2 * RESAMPLE_RATIO)
-/* limiter */
-/* MAX_COUNT is largest possible sample count in limiter_process. This is
- needed in case time stretch makes the count in dsp_process larger than
- the limiter buffer. */
-#define MAX_COUNT MAX(SMALL_SAMPLE_BUF_COUNT * RESAMPLE_RATIO / 2, LIMITER_BUFFER_SIZE)
+/* compressor */
+/* MAX_COUNT is largest possible sample count in compressor_process */
+#define MAX_COUNT MAX(SMALL_SAMPLE_BUF_COUNT * RESAMPLE_RATIO / 2, COMPRESSOR_BUFFER_SIZE)
+static struct compressor_menu c_menu;
+static int32_t comp_att_slope; /* S7.24 format */
+static int32_t comp_rel_slope; /* S7.24 format */
+static int32_t comp_makeup_gain; /* S7.24 format */
+static int32_t comp_curve[65]; /* S7.24 format */
+static int32_t gain_buffer[MAX_COUNT] IBSS_ATTR;
+static int32_t attack_gain;
+static int32_t release_gain;
+
+/* compressor buffer */
static int count_adjust;
-static bool limiter_buffer_active;
-static bool limiter_buffer_full;
-static bool limiter_buffer_emptying;
-static int32_t limiter_buffer[2][LIMITER_BUFFER_SIZE] IBSS_ATTR;
-static int32_t *start_lim_buf[2] IBSS_ATTR,
- *end_lim_buf[2] IBSS_ATTR;
-static uint16_t lim_buf_peak[LIMITER_BUFFER_SIZE] IBSS_ATTR;
-static uint16_t *start_peak IBSS_ATTR,
- *end_peak IBSS_ATTR;
-static uint16_t out_buf_peak[MAX_COUNT];
-static uint16_t *out_buf_peak_index IBSS_ATTR;
-static uint16_t release_peak IBSS_ATTR;
-static int32_t in_samp IBSS_ATTR,
- samp0 IBSS_ATTR;
+static bool compressor_buffer_active;
+static bool compressor_buffer_full;
+static bool compressor_buffer_emptying;
+static int32_t attack_buffer[2][COMPRESSOR_BUFFER_SIZE];
+static int32_t *start_att_buf[2],
+ *end_att_buf[2];
-static void reset_limiter_buffer(struct dsp_config *dsp);
-static int limiter_buffer_count(bool buf_count);
-static int limiter_process(int count, int32_t *buf[]);
-static uint16_t get_peak_value(int32_t sample);
+static void reset_compressor(struct dsp_config *dsp);
+static int compressor_buffer_count(bool buf_count);
+static int compressor_process(int count, int32_t *buf[]);
+static int32_t get_compression_gain(int32_t sample);
- /* The clip_steps array essentially stores the results of fp_factor from
- * 0 to 12 dB, in 48 equal steps, in S3.28 format. */
-const long clip_steps[49] ICONST_ATTR = { 0x10000000,
- 0x10779AFA, 0x10F2B409, 0x1171654C, 0x11F3C9A0, 0x1279FCAD,
- 0x13041AE9, 0x139241A2, 0x14248EF9, 0x14BB21F9, 0x15561A92,
- 0x15F599A0, 0x1699C0F9, 0x1742B36B, 0x17F094CE, 0x18A38A01,
- 0x195BB8F9, 0x1A1948C5, 0x1ADC619B, 0x1BA52CDC, 0x1C73D51D,
- 0x1D488632, 0x1E236D3A, 0x1F04B8A1, 0x1FEC982C, 0x20DB3D0E,
- 0x21D0D9E2, 0x22CDA2BE, 0x23D1CD41, 0x24DD9099, 0x25F12590,
- 0x270CC693, 0x2830AFD3, 0x295D1F37, 0x2A925471, 0x2BD0911F,
- 0x2D1818B3, 0x2E6930AD, 0x2FC42095, 0x312931EC, 0x3298B072,
- 0x3412EA24, 0x35982F3A, 0x3728D22E, 0x38C52808, 0x3A6D8847,
- 0x3C224CD9, 0x3DE3D264, 0x3FB2783F};
-/* The gain_steps array essentially stores the results of fp_factor from
- * 0 to -12 dB, in 48 equal steps, in S3.28 format. */
-const long gain_steps[49] ICONST_ATTR = { 0x10000000,
- 0xF8BC9C0, 0xF1ADF94, 0xEAD2988, 0xE429058, 0xDDAFD68,
- 0xD765AC1, 0xD149309, 0xCB59186, 0xC594210, 0xBFF9112,
- 0xBA86B88, 0xB53BEF5, 0xB017965, 0xAB18964, 0xA63DDFE,
- 0xA1866BA, 0x9CF1397, 0x987D507, 0x9429BEE, 0x8FF599E,
- 0x8BDFFD3, 0x87E80B0, 0x840CEBE, 0x804DCE8, 0x7CA9E76,
- 0x792070E, 0x75B0AB0, 0x7259DB2, 0x6F1B4BF, 0x6BF44D5,
- 0x68E4342, 0x65EA5A0, 0x63061D6, 0x6036E15, 0x5D7C0D3,
- 0x5AD50CE, 0x5841505, 0x55C04B8, 0x535176A, 0x50F44D9,
- 0x4EA84FE, 0x4C6D00E, 0x4A41E78, 0x48268DF, 0x461A81C,
- 0x441D53E, 0x422E985, 0x404DE62};
-
/* Clip sample to signed 16 bit range */
static inline int32_t clip_sample_16(int32_t sample)
{
@@ -944,13 +928,6 @@
dsp->data.gain = fp_mul(dsp->data.gain, eq_precut, 24);
}
- /* only preamp for the limiter if limiter is active and sample depth
- * allows safe pre-amping (12 dB is OK with 29 or less frac bits) */
- if ((dsp->limiter_preamp) && (dsp->frac_bits <= 29))
- {
- dsp->data.gain = fp_mul(dsp->data.gain, dsp->limiter_preamp, 24);
- }
-
#ifdef HAVE_SW_VOLUME_CONTROL
if (global_settings.volume < SW_VOLUME_MAX ||
global_settings.volume > SW_VOLUME_MIN)
@@ -1308,8 +1285,8 @@
if (dsp->channels_process)
dsp->channels_process(chunk, t2);
- if (dsp->limiter_process)
- chunk = dsp->limiter_process(chunk, t2);
+ if (dsp->compressor_process)
+ chunk = dsp->compressor_process(chunk, t2);
dsp->output_samples(chunk, &dsp->data, (const int32_t **)t2, (int16_t *)dst);
@@ -1358,11 +1335,11 @@
if (count > RESAMPLE_BUF_RIGHT_CHANNEL)
count = RESAMPLE_BUF_RIGHT_CHANNEL;
- /* If the limiter buffer is filling, some or all samples will
+ /* If the attack buffer is filling, some or all samples will
* be captured by it, so expect fewer samples coming out. */
- if (limiter_buffer_active && !limiter_buffer_full)
+ if (compressor_buffer_active && !compressor_buffer_full)
{
- int empty_space = limiter_buffer_count(false);
+ int empty_space = compressor_buffer_count(false);
count_adjust = MIN(empty_space, count);
count -= count_adjust;
}
@@ -1375,11 +1352,11 @@
*/
int dsp_input_count(struct dsp_config *dsp, int count)
{
- /* If the limiter buffer is filling, the output count was
+ /* If the attack buffer is filling, the output count was
* adjusted downward. This adjusts it back so that input
* count is not affected.
*/
- if (limiter_buffer_active && !limiter_buffer_full)
+ if (compressor_buffer_active && !compressor_buffer_full)
count += count_adjust;
/* count is now the number of resampled input samples. Convert to
@@ -1499,7 +1476,7 @@
dsp_update_functions(dsp);
resampler_new_delta(dsp);
tdspeed_setup(dsp);
- reset_limiter_buffer(dsp);
+ reset_compressor(dsp);
break;
case DSP_FLUSH:
@@ -1508,7 +1485,7 @@
resampler_new_delta(dsp);
dither_init(dsp);
tdspeed_setup(dsp);
- reset_limiter_buffer(dsp);
+ reset_compressor(dsp);
break;
case DSP_SET_TRACK_GAIN:
@@ -1588,68 +1565,69 @@
set_gain(&AUDIO_DSP);
}
-/** RESET THE LIMITER BUFFER
- * Force the limiter buffer to its initial state and discard
- * any samples held there. */
-static void reset_limiter_buffer(struct dsp_config *dsp)
+/** GET COMPRESSION GAIN
+ * Returns the required gain factor in S7.24 format in order to compress the
+ * sample in accordance with the compression curve. Always 1 or less.
+ */
+static int32_t get_compression_gain(int32_t sample)
{
- if (dsp == &AUDIO_DSP)
- {
- int i;
- logf(" reset_limiter_buffer");
- for (i = 0; i < 2; i++)
- start_lim_buf[i] = end_lim_buf[i] = limiter_buffer[i];
- start_peak = end_peak = lim_buf_peak;
- limiter_buffer_full = false;
- limiter_buffer_emptying = false;
- release_peak = 0;
- }
+ const int frac_bits = AUDIO_DSP.frac_bits;
+
+ /* sample must be positive */
+ if (sample < 0)
+ sample = -sample - 1;
+
+ /* shift sample into 22 frac bit range */
+ if (frac_bits > 22)
+ sample >>= (frac_bits - 22);
+ if (frac_bits < 22)
+ sample <<= (22 - frac_bits);
+
+ /* index is 6 MSB, rem is 16 LSB */
+ int index = sample >> 16;
+ int rem = sample & 0xFFFF;
+
+ /* interpolate from the compression curve */
+ return comp_curve[index] + (int32_t)fp_mul((comp_curve[index + 1]
+ - comp_curve[index]), rem, 16);
}
-/** OPERATE THE LIMITER BUFFER
- * Handle all samples entering or exiting the limiter buffer. */
-static inline int set_limiter_buffer(int count, int32_t *buf[])
+/** OPERATE THE COMPRESSOR BUFFER
+ * Handle all samples entering or exiting the attack buffer */
+static inline int operate_compressor_buffer(int count, int32_t *buf[])
{
int32_t *in_buf[] = {buf[0], buf[1]},
- *out_buf[] = {buf[0], buf[1]};
- int empty_space, i, out_count;
- const long clip_max = AUDIO_DSP.data.clip_max;
+ *out_buf[] = {buf[0], buf[1]},
+ in_samp;
+ int empty_space, out_count, i;
const int ch = AUDIO_DSP.data.num_channels - 1;
- out_buf_peak_index = out_buf_peak;
- if (limiter_buffer_emptying)
+ if (compressor_buffer_emptying)
/** EMPTY THE BUFFER
* since the empty flag has been set, assume no inbound samples and
- return all samples in the limiter buffer to the outbound buffer */
+ return all samples in the attack buffer to the outbound buffer */
{
- count = limiter_buffer_count(true);
+ count = compressor_buffer_count(true);
out_count = count;
- logf(" Emptying limiter buffer: %d", count);
+ logf(" Emptying attack buffer: %d", count);
while (count-- > 0)
{
for (i = 0; i <= ch; i++)
{
- /* move samples in limiter buffer to output buffer */
- *out_buf[i]++ = *start_lim_buf[i]++;
- if (start_lim_buf[i] == &limiter_buffer[i][LIMITER_BUFFER_SIZE])
- start_lim_buf[i] = limiter_buffer[i];
- /* move limiter buffer peak values to output peak values */
- if (i == 0)
- {
- *out_buf_peak_index++ = *start_peak++;
- if (start_peak == &lim_buf_peak[LIMITER_BUFFER_SIZE])
- start_peak = lim_buf_peak;
- }
+ /* move samples in attack buffer to output buffer */
+ *out_buf[i]++ = *start_att_buf[i]++;
+ if (start_att_buf[i] == &attack_buffer[i][c_menu.attack])
+ start_att_buf[i] = attack_buffer[i];
}
}
- limiter_buffer_full = false;
- limiter_buffer_emptying = false;
+ compressor_buffer_full = false;
+ compressor_buffer_emptying = false;
}
- else /* limiter buffer NOT emptying */
+ else /* attack buffer NOT emptying */
{
if (count <= 0) return 0;
- empty_space = limiter_buffer_count(false);
+ empty_space = compressor_buffer_count(false);
if (empty_space > 0)
/** FILL BUFFER
@@ -1658,41 +1636,27 @@
/* don't try to fill with more samples than available */
if (empty_space > count)
empty_space = count;
- logf(" Filling limiter buffer: %d", empty_space);
+ logf(" Filling attack buffer: %d", empty_space);
while (empty_space-- > 0)
{
for (i = 0; i <= ch; i++)
{
- /* put inbound samples in the limiter buffer */
+ /* put inbound samples in the attack buffer */
in_samp = *in_buf[i]++;
- *end_lim_buf[i]++ = in_samp;
- if (end_lim_buf[i] == &limiter_buffer[i][LIMITER_BUFFER_SIZE])
- end_lim_buf[i] = limiter_buffer[i];
- if (in_samp < 0) /* make positive for comparison */
- in_samp = -in_samp - 1;
- if (in_samp <= clip_max)
- in_samp = 0; /* disregard if not clipped */
- if (i == 0)
- samp0 = in_samp;
- if (i == ch)
- {
- /* assign peak value for each inbound sample pair */
- *end_peak++ = ((samp0 > 0) || (in_samp > 0)) ?
- get_peak_value(MAX(samp0, in_samp)) : 0;
- if (end_peak == &lim_buf_peak[LIMITER_BUFFER_SIZE])
- end_peak = lim_buf_peak;
- }
+ *end_att_buf[i]++ = in_samp;
+ if (end_att_buf[i] == &attack_buffer[i][c_menu.attack])
+ end_att_buf[i] = attack_buffer[i];
}
count--;
}
/* after buffer fills, the remaining inbound samples are cycled */
}
- limiter_buffer_full = (end_lim_buf[0] == start_lim_buf[0]);
+ compressor_buffer_full = (end_att_buf[0] == start_att_buf[0]);
out_count = count;
/** CYCLE BUFFER
- * return buffered samples and backfill limiter buffer with new ones.
+ * return buffered samples and backfill attack buffer with new ones.
* The buffer is always full when cycling. */
while (count-- > 0)
{
@@ -1700,35 +1664,15 @@
{
/* copy incoming sample */
in_samp = *in_buf[i]++;
- /* put limiter buffer sample into outbound buffer */
- *out_buf[i]++ = *start_lim_buf[i]++;
- /* put incoming sample on the end of the limiter buffer */
- *end_lim_buf[i]++ = in_samp;
+ /* put attack buffer sample into outbound buffer */
+ *out_buf[i]++ = *start_att_buf[i]++;
+ /* put incoming sample on the end of the attack buffer */
+ *end_att_buf[i]++ = in_samp;
/* ring buffer pointer wrap */
- if (start_lim_buf[i] == &limiter_buffer[i][LIMITER_BUFFER_SIZE])
- start_lim_buf[i] = limiter_buffer[i];
- if (end_lim_buf[i] == &limiter_buffer[i][LIMITER_BUFFER_SIZE])
- end_lim_buf[i] = limiter_buffer[i];
- if (in_samp < 0) /* make positive for comparison */
- in_samp = -in_samp - 1;
- if (in_samp <= clip_max)
- in_samp = 0; /* disregard if not clipped */
- if (i == 0)
- {
- samp0 = in_samp;
- /* assign outgoing sample its associated peak value */
- *out_buf_peak_index++ = *start_peak++;
- if (start_peak == &lim_buf_peak[LIMITER_BUFFER_SIZE])
- start_peak = lim_buf_peak;
- }
- if (i == ch)
- {
- /* assign peak value for each inbound sample pair */
- *end_peak++ = ((samp0 > 0) || (in_samp > 0)) ?
- get_peak_value(MAX(samp0, in_samp)) : 0;
- if (end_peak == &lim_buf_peak[LIMITER_BUFFER_SIZE])
- end_peak = lim_buf_peak;
- }
+ if (start_att_buf[i] == &attack_buffer[i][c_menu.attack])
+ start_att_buf[i] = attack_buffer[i];
+ if (end_att_buf[i] == &attack_buffer[i][c_menu.attack])
+ end_att_buf[i] = attack_buffer[i];
}
}
}
@@ -1736,221 +1680,352 @@
return out_count;
}
-/** RETURN LIMITER BUFFER COUNT
+/** RETURN ATTACK BUFFER COUNT
* If argument is true, returns number of samples in the buffer,
* otherwise, returns empty space remaining */
-static int limiter_buffer_count(bool buf_count)
+static int compressor_buffer_count(bool buf_count)
{
int count;
- if (limiter_buffer_full)
- count = LIMITER_BUFFER_SIZE;
- else if (end_lim_buf[0] >= start_lim_buf[0])
- count = (end_lim_buf[0] - start_lim_buf[0]);
+ if (compressor_buffer_full)
+ count = c_menu.attack;
+ else if (end_att_buf[0] >= start_att_buf[0])
+ count = (end_att_buf[0] - start_att_buf[0]);
else
- count = (end_lim_buf[0] - start_lim_buf[0]) + LIMITER_BUFFER_SIZE;
- return buf_count ? count : (LIMITER_BUFFER_SIZE - count);
+ count = (end_att_buf[0] - start_att_buf[0]) + c_menu.attack;
+ return buf_count ? count : (c_menu.attack - count);
}
-/** FLUSH THE LIMITER BUFFER
- * Empties the limiter buffer into the buffer pointed to by the argument
+/** FLUSH THE COMPRESSOR BUFFER
+ * Empties the attack buffer into the buffer pointed to by the argument
* and returns the number of samples in that buffer */
-int dsp_flush_limiter_buffer(char *dest)
+int dsp_flush_compressor_buffer(char *dest)
{
- if ((!limiter_buffer_active) || (limiter_buffer_count(true) <= 0))
+ if ((!compressor_buffer_active) || (compressor_buffer_count(true) <= 0))
return 0;
- logf(" dsp_flush_limiter_buffer");
- int32_t flush_buf[2][LIMITER_BUFFER_SIZE];
+ logf(" dsp_flush_compressor_buffer");
+ int32_t flush_buf[2][COMPRESSOR_BUFFER_SIZE];
int32_t *src[2] = {flush_buf[0], flush_buf[1]};
- limiter_buffer_emptying = true;
- int count = limiter_process(0, src);
+ compressor_buffer_emptying = true;
+ int count = compressor_process(0, src);
AUDIO_DSP.output_samples(count, &AUDIO_DSP.data,
(const int32_t **)src, (int16_t *)dest);
return count;
}
-/** GET PEAK VALUE
- * Return a small value representing how much the sample is clipped. This
- * should only be called if a sample is actually clipped. Sample is a
- * positive value.
- */
-static uint16_t get_peak_value(int32_t sample)
+/** SET COMPRESSOR
+ * Called by the menu system to configure the compressor process */
+void dsp_set_compressor(int c_threshold, int c_ratio, int c_gain,
+ int c_knee, int c_attack, int c_release,
+ /* int c_rms, */ bool c_auto_peak)
{
- const int frac_bits = AUDIO_DSP.frac_bits;
- int mid,
- hi = 48,
- lo = 0;
+ /* save the compressor state but disable it while we're configuring */
+ bool active = compressor_buffer_active;
+ compressor_buffer_active = false;
- /* shift sample into 28 frac bit range for comparison */
- if (frac_bits > 28)
- sample >>= (frac_bits - 28);
- if (frac_bits < 28)
- sample <<= (28 - frac_bits);
+ bool changed = false;
+ const int comp_ratio[] = {2, 4, 10, 20, 60};
+ int new_ratio = comp_ratio[c_ratio];
+ bool new_knee = (c_knee == 1);
+ int new_attack = c_attack * NATIVE_FREQUENCY / 10000;
+ int new_release = c_release * NATIVE_FREQUENCY / 1000;
+ /* bool new_rms = (c_rms == 1); */
- /* if clipped out of range, return maximum value */
- if (sample >= clip_steps[48])
- return 48 * 90;
-
- /* find amount of sample clipping on the table */
- do
+ if (c_menu.threshold != c_threshold)
{
- mid = (hi + lo) / 2;
- if (sample < clip_steps[mid])
- hi = mid;
- else if (sample > clip_steps[mid])
- lo = mid;
- else
- return mid * 90;
+ changed = true;
+ c_menu.threshold = c_threshold;
+ active = (c_menu.threshold < 0);
+ logf(" Compressor Threshold: %d dB\tEnabled: %s",
+ c_menu.threshold, active ? "Yes" : "No");
}
- while (hi > (lo + 1));
-
- /* interpolate linearly between steps (less accurate but faster) */
- return ((hi-1) * 90) + (((sample - clip_steps[hi-1]) * 90) /
- (clip_steps[hi] - clip_steps[hi-1]));
-}
-/** SET LIMITER
- * Called by the menu system to configure the limiter process */
-void dsp_set_limiter(int limiter_level)
-{
- if (limiter_level > 0)
+ if (c_menu.ratio != new_ratio)
{
- if (!limiter_buffer_active)
+ changed = true;
+ c_menu.ratio = new_ratio;
+ logf(" Compressor Ratio: %d:1", c_menu.ratio);
+ }
+ if (c_menu.gain != c_gain)
+ {
+ changed = true;
+ c_menu.gain = c_gain;
+ logf(" Compressor Gain: %d dB", c_menu.gain);
+ }
+ if (c_menu.soft_knee != new_knee)
+ {
+ changed = true;
+ c_menu.soft_knee = new_knee;
+ logf(" Compressor Knee: %s", c_menu.soft_knee==1?"Soft":"Hard");
+ }
+ if (c_menu.attack != new_attack)
+ {
+ changed = true;
+ c_menu.attack = new_attack;
+ logf(" Compressor Attack: %d", c_menu.attack);
+ }
+ if (c_menu.release != new_release)
+ {
+ changed = true;
+ c_menu.release = new_release;
+ logf(" Compressor Release: %d", c_menu.release);
+ }
+ /* if (c_menu.rms != new_rms)
+ {
+ changed = true;
+ c_menu.rms = new_rms;
+ logf(" Compressor Sense Mode: %s", c_menu.rms==1?"RMS":"Peak");
+ } */
+ if (c_menu.auto_peak != c_auto_peak)
+ {
+ changed = true;
+ c_menu.auto_peak = c_auto_peak;
+ logf(" Compressor Auto Peak: %s", c_menu.auto_peak ? "Yes" : "No");
+ }
+
+ if (changed && active)
+ {
+ /* configure variables for compressor operation */
+ int i;
+ const int32_t db[] ={0x000000, /* positive db equivalents in S15.16 format */
+ 0x241FA4, 0x1E1A5E, 0x1A94C8, 0x181518, 0x1624EA, 0x148F82, 0x1338BD, 0x120FD2,
+ 0x1109EB, 0x101FA4, 0x0F4BB6, 0x0E8A3C, 0x0DD840, 0x0D3377, 0x0C9A0E, 0x0C0A8C,
+ 0x0B83BE, 0x0B04A5, 0x0A8C6C, 0x0A1A5E, 0x09ADE1, 0x094670, 0x08E398, 0x0884F6,
+ 0x082A30, 0x07D2FA, 0x077F0F, 0x072E31, 0x06E02A, 0x0694C8, 0x064BDF, 0x060546,
+ 0x05C0DA, 0x057E78, 0x053E03, 0x04FF5F, 0x04C273, 0x048726, 0x044D64, 0x041518,
+ 0x03DE30, 0x03A89B, 0x037448, 0x03412A, 0x030F32, 0x02DE52, 0x02AE80, 0x027FB0,
+ 0x0251D6, 0x0224EA, 0x01F8E2, 0x01CDB4, 0x01A359, 0x0179C9, 0x0150FC, 0x0128EB,
+ 0x010190, 0x00DAE4, 0x00B4E1, 0x008F82, 0x006AC1, 0x004699, 0x002305};
+
+ struct curve_point
{
- /* enable limiter process */
- AUDIO_DSP.limiter_process = limiter_process;
- limiter_buffer_active = true;
+ int32_t db; /* S15.16 format */
+ int32_t offset; /* S15.16 format */
+ } db_curve[4];
+
+ /** Set up the shape of the compression curve first as decibel values*/
+ /* db_curve[0] = bottom of knee
+ [1] = threshold
+ [2] = top of knee
+ [3] = 0 db input */
+ db_curve[1].db = c_menu.threshold << 16;
+ db_curve[1].offset = 0;
+ if (c_menu.soft_knee)
+ {
+ /* bottom of knee is 3dB below the threshold for soft knee*/
+ db_curve[0].db = db_curve[1].db - (3 << 16);
+ db_curve[0].offset = 0;
+ /* top of knee is 3dB above the threshold for soft knee */
+ db_curve[2].db = db_curve[1].db + (3 << 16);
+ db_curve[2].offset = (int32_t)((long long)(-3 << 16)
+ * (c_menu.ratio - 1) / c_menu.ratio);
}
- /* limiter preamp is a gain factor in S7.24 format */
- long old_preamp = AUDIO_DSP.limiter_preamp;
- long new_preamp = fp_factor((((long)limiter_level << 24) / 10), 24);
- if (old_preamp != new_preamp)
+ else
{
- AUDIO_DSP.limiter_preamp = new_preamp;
- set_gain(&AUDIO_DSP);
- logf(" Limiter enable: Yes\tLimiter amp: %.8f",
- (float)AUDIO_DSP.limiter_preamp / (1 << 24));
+ /* bottom of knee is at the threshold for hard knee */
+ db_curve[0].db = c_menu.threshold << 16;
+ db_curve[0].offset = 0;
+ /* top of knee is at the threshold for hard knee */
+ db_curve[2].db = c_menu.threshold << 16;
+ db_curve[2].offset = 0;
}
- }
- else
- {
- /* disable limiter process*/
- if (limiter_buffer_active)
+ /* 0db input is also max offset point (most compression) */
+ db_curve[3].db = 0;
+ db_curve[3].offset = (int32_t)((long long)(c_menu.threshold << 16)
+ * (c_menu.ratio - 1) / c_menu.ratio);
+
+ /* Now set up the comp_curve table with compression offsets in the form
+ of gain factors in S7.24 format */
+ comp_curve[0] = (1 << 24);
+ comp_curve[64] = fp_factor(db_curve[3].offset, 16) << 8;
+ for (i = 1; i < 64; i++)
{
- AUDIO_DSP.limiter_preamp = (1 << 24);
- set_gain(&AUDIO_DSP);
- /* pcmbuf_flush_limiter_buffer(); */
- limiter_buffer_active = false;
- AUDIO_DSP.limiter_process = NULL;
- reset_limiter_buffer(&AUDIO_DSP);
- logf(" Limiter enable: No\tLimiter amp: %.8f",
- (float)AUDIO_DSP.limiter_preamp / (1 << 24));
+ int32_t this_db = -db[i];
+ /* no compression below the knee */
+ if (this_db <= db_curve[0].db)
+ comp_curve[i] = (1 << 24);
+
+ /* if soft knee and below top of knee, interpolate along soft knee slope */
+ else if (c_menu.soft_knee && (this_db <= db_curve[2].db))
+ comp_curve[i] = fp_factor(fp_mul(((this_db - db_curve[0].db) / 6),
+ db_curve[2].offset, 16), 16) << 8;
+
+ /* interpolate along ratio slope above the knee */
+ else
+ comp_curve[i] = fp_factor(fp_mul(fp_div((this_db - db_curve[1].db),
+ -db_curve[1].db, 16), db_curve[3].offset, 16), 16) << 8;
}
+
+ for (i = 0; i <= 3; i++)
+ {
+ logf("Curve[%d]: db: %.1f\toffset: %.4f", i, (float)db_curve[i].db / (1 << 16),
+ (float)db_curve[i].offset / (1 << 16));
+ }
+
+ logf("\nOffsets:");
+ for (i = 1; i <= 64; i++)
+ {
+ debugf("%02d: %.6f ", i, (float)comp_curve[i] / (1 << 24));
+ if (i % 4 == 0) debugf("\n");
+ }
+
+ /* calculate per-sample offsets in S7.24 format */
+ comp_att_slope = ((1 << 24) - comp_curve[64]) / c_menu.attack;
+ logf("Attack slope: %.4f", (float)comp_att_slope / (1 << 24));
+ comp_rel_slope = ((1 << 24) - comp_curve[64]) / c_menu.release;
+ logf("Release slope: %.4f", (float)comp_rel_slope / (1 << 24));
+
+ /* if using auto peak, then makeup gain is max offset - .1dB headroom */
+ int32_t db_makeup = c_menu.auto_peak ?
+ -(db_curve[3].offset) - 0x199A : c_menu.gain << 16;
+ comp_makeup_gain = fp_factor(db_makeup, 16) << 8;
+ logf("Makeup gain: %.4f", (float)comp_makeup_gain / (1 << 24));
+
+ reset_compressor(&AUDIO_DSP);
}
+
+ /* enable/disable the compressor */
+ AUDIO_DSP.compressor_process = active ? compressor_process : NULL;
+ compressor_buffer_active = active;
}
-/** LIMITER PROCESS
- * Checks pre-amplified signal for clipped samples and smoothly reduces gain
- * around the clipped samples using a preset attack/release schedule.
+/** RESET THE COMPRESSOR
+ * Reset compressor buffer to its initial state
*/
-static int limiter_process(int count, int32_t *buf[])
+static void reset_compressor(struct dsp_config *dsp)
{
- /* Limiter process passes through if limiter buffer isn't active, or the
- * sample depth is too large for safe pre-amping */
- if ((!limiter_buffer_active) || (AUDIO_DSP.frac_bits > 29))
+ if (dsp == &AUDIO_DSP)
+ {
+ logf(" reset_compressor");
+
+ int i;
+ for (i = 0; i < 2; i++)
+ start_att_buf[i] = end_att_buf[i] = attack_buffer[i];
+ compressor_buffer_full = false;
+ compressor_buffer_emptying = false;
+ release_gain = (1 << 24);
+ }
+}
+
+/** COMPRESSOR PROCESS
+ * Changes the gain of the samples according to the compressor curve
+ */
+static int compressor_process(int count, int32_t *buf[])
+{
+ /* Compressor process passes through if attack buffer isn't active */
+ if (!compressor_buffer_active)
return count;
- count = set_limiter_buffer(count, buf);
+ count = operate_compressor_buffer(count, buf);
if (count <= 0)
return 0;
+
+ const int buffer_count = compressor_buffer_count(true);
+ const int num_chan = AUDIO_DSP.data.num_channels;
+ const int32_t fp_one = (1 << 24);
- const int attack_slope = 15; /* 15:1 ratio between attack and release */
- const int buffer_count = limiter_buffer_count(true);
-
+ int32_t sample_gain, /* S7.24 format */
+ this_gain; /* S7.24 format */
int i, ch;
- uint16_t max_peak = 0,
- gain_peak,
- gain_rem;
- long gain;
- /* step through limiter buffer in reverse order, in order to find the
- * appropriate max_peak for modifying the output buffer */
+ /* step through attack buffer in reverse order, in order to find the
+ * appropriate attack value for modifying the output buffer */
for (i = buffer_count - 1; i >= 0; i--)
{
- const uint16_t peak_i = lim_buf_peak[(start_peak - lim_buf_peak + i) %
- LIMITER_BUFFER_SIZE];
- /* if no attack slope, nothing to do */
- if ((peak_i == 0) && (max_peak == 0)) continue;
- /* if new peak, start attack slope */
- if (peak_i >= max_peak)
+ /* find required compression for each sample */
+ sample_gain = fp_one;
+ for (ch = 0; ch < num_chan; ch++)
{
- max_peak = peak_i;
+ const int index = (start_att_buf[ch] - attack_buffer[ch] + i)
+ % c_menu.attack;
+ this_gain = get_compression_gain(attack_buffer[ch][index]);
+ if (this_gain < sample_gain)
+ sample_gain = this_gain;
}
- /* keep sloping */
- else
+ /* if no attack slope, nothing to do */
+ if (!((sample_gain == fp_one) && (attack_gain == fp_one)))
{
- if (max_peak > attack_slope)
- max_peak -= attack_slope;
- else
- max_peak = 0;
+ /* if larger offset, start attack slope */
+ if (sample_gain <= attack_gain)
+ attack_gain = sample_gain;
+ else /* keep sloping */
+ {
+ if (attack_gain < (fp_one - comp_att_slope))
+ attack_gain += comp_att_slope;
+ else
+ attack_gain = fp_one;
+ }
}
}
- /* step through output buffer the same way, but this time modifying peak
+
+ /* step through output buffer the same way, but this time modifying offset
* values to create a smooth attack slope. */
for (i = count - 1; i >= 0; i--)
{
- /* if no attack slope, nothing to do */
- if ((out_buf_peak[i] == 0) && (max_peak == 0)) continue;
- /* if new peak, start attack slope */
- if (out_buf_peak[i] >= max_peak)
+ /* find required compression for each sample */
+ sample_gain = fp_one;
+ for (ch = 0; ch < num_chan; ch++)
{
- max_peak = out_buf_peak[i];
+ this_gain = get_compression_gain(buf[ch][i]);
+ if (this_gain < sample_gain)
+ sample_gain = this_gain;
}
- /* keep sloping */
+ /* if no attack slope, nothing to do */
+ if ((sample_gain == fp_one) && (attack_gain == fp_one))
+ gain_buffer[i] = fp_one;
else
{
- if (max_peak > attack_slope)
- max_peak -= attack_slope;
- else
- max_peak = 0;
- out_buf_peak[i] = max_peak;
+ /* if larger offset, start attack slope */
+ if (sample_gain <= attack_gain)
+ attack_gain = sample_gain;
+ else /* keep sloping */
+ {
+ if (attack_gain < (fp_one - comp_att_slope))
+ attack_gain += comp_att_slope;
+ else
+ attack_gain = fp_one;
+ }
+ gain_buffer[i] = attack_gain;
}
}
- /* Now step forward through the output buffer, and modify the peak values
+
+ /* now step forward through the output buffer, and modify the offset values
* to establish a smooth, slow release slope.*/
for (i = 0; i < count; i++)
{
- /* if no release slope, nothing to do */
- if ((out_buf_peak[i] == 0) && (release_peak == 0)) continue;
- /* if new peak, start release slope */
- if (out_buf_peak[i] >= release_peak)
- {
- release_peak = out_buf_peak[i];
- }
- /* keep sloping */
+ sample_gain = gain_buffer[i];
+ /* if no release slope, only apply makeup gain */
+ if ((sample_gain == fp_one) && (release_gain == fp_one))
+ gain_buffer[i] = comp_makeup_gain;
else
{
- release_peak--;
- out_buf_peak[i] = release_peak;
+ /* if larger offset, start release slope */
+ if (sample_gain <= release_gain)
+ release_gain = sample_gain;
+ else /* keep sloping */
+ {
+ if (release_gain < (fp_one - comp_rel_slope))
+ release_gain += comp_rel_slope;
+ else
+ release_gain = fp_one;
+ }
+ /* store offset with release and also apply makeup gain */
+ gain_buffer[i] = FRACMUL_SHL(release_gain, comp_makeup_gain, 7);
}
}
- /* Implement the limiter: adjust gain of the outbound samples by the gain
- * amounts in the gain steps array corresponding to the peak values. */
+
+ /* Implement the compressor: apply those gain factors to the output
+ * buffer samples */
+
for (i = 0; i < count; i++)
{
- if (out_buf_peak[i] > 0)
+ if (gain_buffer[i] != fp_one)
{
- gain_peak = (out_buf_peak[i] + 1) / 90;
- gain_rem = (out_buf_peak[i] + 1) % 90;
- gain = gain_steps[gain_peak];
- if ((gain_peak < 48) && (gain_rem > 0))
- gain -= gain_rem * ((gain_steps[gain_peak] -
- gain_steps[gain_peak + 1]) / 90);
- for (ch = 0; ch < AUDIO_DSP.data.num_channels; ch++)
- buf[ch][i] = FRACMUL_SHL(buf[ch][i], gain, 3);
+ for (ch = 0; ch < num_chan; ch++)
+ buf[ch][i] = FRACMUL_SHL(buf[ch][i], gain_buffer[i], 7);
}
}
return count;
-}
+}
Index: apps/settings_list.c
===================================================================
--- apps/settings_list.c (revision 22783)
+++ apps/settings_list.c (working copy)
@@ -356,6 +356,25 @@
global_settings.crossfeed_hf_cutoff);
}
+static void compressor_set(int val)
+{
+ (void)val;
+ dsp_set_compressor(global_settings.compressor_threshold,
+ global_settings.compressor_ratio,
+ global_settings.compressor_makeup_gain,
+ global_settings.compressor_knee,
+ global_settings.compressor_attack_time,
+ global_settings.compressor_release_time,
+ /* global_settings.compressor_mode, */
+ global_settings.compressor_auto_peak);
+}
+
+static void compressor_set1(bool val)
+{
+ (void)val;
+ compressor_set(0);
+}
+
static const char* db_format(char* buffer, size_t buffer_size, int value,
const char* unit)
{
@@ -1256,11 +1275,39 @@
OFFON_SETTING(F_SOUNDSETTING, timestretch_enabled, LANG_TIMESTRETCH, false,
"timestretch enabled", dsp_timestretch_enable),
- /* limiter */
- INT_SETTING_NOWRAP(F_SOUNDSETTING, limiter_level,
- LANG_COMPRESSOR, 0,
- "limiter level", UNIT_DB, 0, MAX_LIMITER_GAIN,
- 5, db_format, get_dec_talkid, dsp_set_limiter),
+ /* compressor */
+ INT_SETTING_NOWRAP(F_SOUNDSETTING, compressor_threshold,
+ LANG_COMPRESSOR_THRESHOLD, 0,
+ "compressor threshold", UNIT_DB, 0, -30,
+ -3, formatter_unit_0_is_off, getlang_unit_0_is_off, compressor_set),
+ CHOICE_SETTING(F_SOUNDSETTING|F_NO_WRAP, compressor_ratio,
+ LANG_COMPRESSOR_RATIO, 2, "compressor ratio",
+ "2:1,4:1,10:1,20:1,60:1", compressor_set, 5,
+ ID2P(LANG_COMPRESSOR_RATIO_2), ID2P(LANG_COMPRESSOR_RATIO_4),
+ ID2P(LANG_COMPRESSOR_RATIO_10), ID2P(LANG_COMPRESSOR_RATIO_20),
+ ID2P(LANG_COMPRESSOR_RATIO_60)),
+ INT_SETTING_NOWRAP(F_SOUNDSETTING, compressor_makeup_gain,
+ LANG_COMPRESSOR_GAIN, 0,
+ "compressor makeup gain", UNIT_DB, 0, 20,
+ 1, NULL, NULL, compressor_set),
+ CHOICE_SETTING(F_SOUNDSETTING|F_NO_WRAP, compressor_knee,
+ LANG_COMPRESSOR_KNEE, 1, "compressor knee",
+ "hard knee,soft knee", compressor_set, 2,
+ ID2P(LANG_COMPRESSOR_HARD_KNEE), ID2P(LANG_COMPRESSOR_SOFT_KNEE)),
+ INT_SETTING_NOWRAP(F_SOUNDSETTING, compressor_attack_time,
+ LANG_COMPRESSOR_ATTACK, 60,
+ "compressor attack time", UNIT_MS, 20, MAX_COMPRESSOR_ATTACK,
+ 5, db_format, get_dec_talkid, compressor_set),
+ INT_SETTING_NOWRAP(F_SOUNDSETTING, compressor_release_time,
+ LANG_COMPRESSOR_RELEASE, 100,
+ "compressor release time", UNIT_MS, 20, 200,
+ 10, NULL, NULL, compressor_set),
+ /* CHOICE_SETTING(F_SOUNDSETTING|F_NO_WRAP, compressor_mode,
+ LANG_COMPRESSOR_MODE, 0, "compressor mode",
+ "peak,rms", compressor_set, 2,
+ ID2P(LANG_COMPRESSOR_PEAK), ID2P(LANG_COMPRESSOR_RMS)), */
+ OFFON_SETTING(F_SOUNDSETTING, compressor_auto_peak, LANG_COMPRESSOR_AUTO_PEAK, true,
+ "compressor auto peak", compressor_set1),
#endif
#ifdef HAVE_WM8758
SOUND_SETTING(F_NO_WRAP, bass_cutoff, LANG_BASS_CUTOFF,
Index: apps/dsp.h
===================================================================
--- apps/dsp.h (revision 22783)
+++ apps/dsp.h (working copy)
@@ -26,8 +26,11 @@
#include
#define NATIVE_FREQUENCY 44100
-#define LIMITER_BUFFER_SIZE 288 /* ~6.5 ms */
-#define MAX_LIMITER_GAIN 80 /* 8 dB */
+
+/* compressor */
+#define MAX_COMPRESSOR_ATTACK 65 /* 6.5 ms */
+#define COMPRESSOR_BUFFER_SIZE (MAX_COMPRESSOR_ATTACK * NATIVE_FREQUENCY / 10000)
+
enum
{
STEREO_INTERLEAVED = 0,
@@ -82,7 +85,8 @@
void dsp_set_timestretch(int32_t percent);
int32_t dsp_get_timestretch(void);
int dsp_callback(int msg, intptr_t param);
-int dsp_flush_limiter_buffer(char *dest);
-void dsp_set_limiter(int limiter_level);
-
+int dsp_flush_compressor_buffer(char *dest);
+void dsp_set_compressor(int c_threshold, int c_ratio, int c_gain,
+ int c_knee, int c_attack, int c_release,
+ /* int c_rms, */ bool c_auto_peak);
#endif
Index: apps/plugin.c
===================================================================
--- apps/plugin.c (revision 22783)
+++ apps/plugin.c (working copy)
@@ -467,7 +467,7 @@
dsp_process,
dsp_input_count,
dsp_output_count,
- dsp_flush_limiter_buffer,
+ dsp_flush_compressor_buffer,
#endif /* CONFIG_CODEC == SWCODEC */
/* playback control */
Index: apps/plugin.h
===================================================================
--- apps/plugin.h (revision 22783)
+++ apps/plugin.h (working copy)
@@ -596,7 +596,7 @@
const char *src[], int count);
int (*dsp_input_count)(struct dsp_config *dsp, int count);
int (*dsp_output_count)(struct dsp_config *dsp, int count);
- int (*dsp_flush_limiter_buffer)(char *dest);
+ int (*dsp_flush_compressor_buffer)(char *dest);
#endif /* CONFIG_CODEC == SWCODC */
/* playback control */