{ "cells": [ { "cell_type": "markdown", "id": "nb12-000", "metadata": {}, "source": [ "# 12. Dynamics: compressors and limiters\n", "\n", "Speech varies by 30 dB or more between a whispered consonant and a shouted vowel, and\n", "broadcast, telephony and hearing aids all reduce that range so the quiet parts stay audible\n", "and the loud parts do not clip. A compressor has three parts: a level detector\n", "with attack and release *ballistics*, a *static gain computer* in decibels, and a multiplier.\n", "This notebook measures each part on the library's implementation and rebuilds the whole\n", "processor in a few lines of NumPy.\n", "\n", "**Learning outcomes.** After this notebook you can\n", "\n", "- write down the hard-knee and quadratic soft-knee static curves and read\n", " `get_compression_curve`;\n", "- relate attack and release *time constants* to measurable step responses (63.2 %, and a\n", " 10-90 % rise of $\\tau \\ln 9 \\approx 2.2\\tau$);\n", "- reproduce `apply_compressor` and `apply_limiter` sample for sample in NumPy;\n", "- explain why a limiter on a smoothed envelope is not a brick wall, and how much lookahead reduces the overshoot." ] }, { "cell_type": "code", "execution_count": null, "id": "nb12-001", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import audio_samples as aus\n", "\n", "rng = np.random.default_rng(0)\n", "fs = 48_000\n", "PEAK, HARD, SOFT = aus.DynamicRangeMethod.peak, aus.KneeType.hard, aus.KneeType.soft\n", "SIDE = aus.SideChainConfig.default() # side-chain off\n", "\n", "\n", "def compressor(threshold_db=-20.0, ratio=4.0, attack_ms=5.0, release_ms=50.0, makeup_gain_db=0.0,\n", " knee_type=HARD, knee_width_db=0.0, detection_method=PEAK, lookahead_ms=0.0):\n", " return aus.CompressorConfig(\n", " threshold_db=threshold_db, ratio=ratio, attack_ms=attack_ms, release_ms=release_ms,\n", " makeup_gain_db=makeup_gain_db, knee_type=knee_type, knee_width_db=knee_width_db,\n", " detection_method=detection_method, side_chain=SIDE, lookahead_ms=lookahead_ms)\n", "\n", "\n", "def limiter(ceiling_db=-6.0, attack_ms=1.0, release_ms=100.0, knee_type=HARD, knee_width_db=0.0,\n", " detection_method=PEAK, lookahead_ms=0.0):\n", " return aus.LimiterConfig(\n", " ceiling_db=ceiling_db, attack_ms=attack_ms, release_ms=release_ms, knee_type=knee_type,\n", " knee_width_db=knee_width_db, detection_method=detection_method, side_chain=SIDE,\n", " lookahead_ms=lookahead_ms, isp_limiting=False)\n", "\n", "\n", "def mono(x, sr=fs):\n", " # new_mono may share memory with the array (in-place methods would then modify it): copy.\n", " return aus.AudioSamples.new_mono(np.array(x, dtype=float), sr)" ] }, { "cell_type": "markdown", "id": "nb12-002", "metadata": {}, "source": [ "## Concept\n", "\n", "**Detector and ballistics.** The detector turns the input $x[n]$ into a non-negative value\n", "$d[n]$: $|x[n]|$ for a peak detector, or the RMS over the last 10 ms. A one-pole smoother then\n", "produces the envelope\n", "\n", "$$e[n] = a\\, e[n-1] + (1 - a)\\, d[n], \\qquad a = e^{-1/(\\tau f_s)}$$\n", "\n", "where $f_s$ is the sample rate in Hz and $\\tau$ the time constant in seconds: the attack\n", "constant $\\tau_A$ while $d[n] > e[n-1]$ (the level is rising) and the release constant\n", "$\\tau_R$ otherwise. After a step from $d_0$ to $d_1$ the envelope follows\n", "\n", "$$e(t) = d_1 + (d_0 - d_1)\\, e^{-t/\\tau}$$\n", "\n", "so it covers $1 - e^{-1} = 63.2\\%$ of the step after one time constant, and its 10-90 % rise\n", "time is $\\tau \\ln 9 \\approx 2.2\\,\\tau$. (Manufacturers quote attack times in either convention,\n", "so numbers are not comparable across products.)\n", "\n", "**Static gain computer (dB domain).** With envelope level $L = 20\\log_{10} e$ (dBFS),\n", "threshold $T$ (dBFS), ratio $R \\ge 1$ (dimensionless) and knee width $W$ (dB), the hard-knee\n", "compressor's output level is\n", "\n", "$$Y = L \\ \\text{ for } L \\le T, \\qquad Y = T + (L - T)/R \\ \\text{ for } L > T$$\n", "\n", "so the gain reduction is $r = L - Y = (1 - 1/R)\\max(L - T, 0)$ dB. The quadratic **soft knee**\n", "(Giannoulis, Massberg and Reiss, *JAES* 2012) joins the two lines with a parabola over $[T - W/2, T + W/2]$:\n", "\n", "$$r = (1 - 1/R)\\,\\frac{(L - T + W/2)^2}{2W} \\quad \\text{for } |L - T| \\le W/2$$\n", "\n", "It has slope 1 at the lower edge and $1/R$ at the upper edge, so the curve has no corner, and\n", "at $L = T$ it already reduces by $(1 - 1/R)W/8$ dB.\n", "\n", "**Gain.** The output is $y[n] = x[n]\\, 10^{-r[n]/20}\\, 10^{M/20}$, where $M$ is the make-up\n", "gain in dB. Working in dB makes the ratio a slope and the threshold an offset.\n", "\n", "**Limiter.** The compressor with $R \\to \\infty$ and the ceiling $C$ (dBFS) in place of $T$:\n", "$r = \\max(L - C, 0)$. Because the gain follows a *smoothed* envelope, the output can still\n", "exceed $C$ at the start of a transient.\n", "\n", "**Lookahead.** Delay the audio by $N_L$ samples and apply to sample $n$ the largest reduction\n", "computed for samples $n, \\dots, n + N_L$. If the envelope starts from zero and the step is to\n", "$d_1$, the reduction applied to the first sample of the step comes from an envelope of\n", "$d_1(1 - a^{N_L + 1})$, so the overshoot is\n", "\n", "$$\\Delta = -20 \\log_{10}\\left(1 - a^{N_L + 1}\\right)\\ \\text{dB}$$\n", "\n", "(The library processes whole buffers, so it compensates the delay: output index $n$ stays\n", "aligned with input index $n$.)" ] }, { "cell_type": "markdown", "id": "nb12-003", "metadata": {}, "source": [ "## With the library\n", "\n", "`AudioSamples.get_compression_curve(config, levels_db)` returns the static output level for\n", "each input level (make-up gain included); it does not read the samples." ] }, { "cell_type": "code", "execution_count": null, "id": "nb12-004", "metadata": {}, "outputs": [], "source": [ "probe = mono(np.zeros(16)) # any signal: the curve is analytic\n", "\n", "hard = compressor(threshold_db=-20.0, ratio=4.0)\n", "# -8 dBFS is 12 dB over the threshold: the output is -20 + 12/4 = -17.\n", "assert np.allclose(probe.get_compression_curve(hard, np.array([-30.0, -20.0, -8.0])),\n", " [-30.0, -20.0, -17.0], atol=1e-12)\n", "\n", "soft = compressor(threshold_db=-20.0, ratio=4.0, knee_type=SOFT, knee_width_db=10.0)\n", "L = np.array([-25.0, -20.0, -15.0])\n", "r = L - probe.get_compression_curve(soft, L)\n", "# No reduction at T - W/2, (1 - 1/R) W / 8 = 0.9375 dB at T, back on the hard line at T + W/2.\n", "assert np.allclose(r, [0.0, 0.9375, 3.75], atol=1e-12)\n", "\n", "# Slopes of the output curve: 1 at the lower knee edge, 1/R at the upper one.\n", "d = 1e-6\n", "y = lambda l: probe.get_compression_curve(soft, np.array([l - d, l + d]))\n", "assert abs(np.diff(y(-25.0))[0] / (2 * d) - 1.0) < 1e-5\n", "assert abs(np.diff(y(-15.0))[0] / (2 * d) - 0.25) < 1e-5" ] }, { "cell_type": "code", "execution_count": null, "id": "nb12-005", "metadata": {}, "outputs": [], "source": [ "Lg = np.linspace(-40, 0, 401)\n", "fig, ax = plt.subplots(figsize=(5, 4))\n", "ax.plot(Lg, Lg, color=\"grey\", lw=0.8, ls=\":\", label=\"no compression\")\n", "ax.plot(Lg, probe.get_compression_curve(hard, Lg), label=\"hard knee\")\n", "ax.plot(Lg, probe.get_compression_curve(soft, Lg), label=\"soft knee, W = 10 dB\")\n", "ax.set(xlabel=\"Input level L (dBFS)\", ylabel=\"Output level Y (dBFS)\",\n", " title=\"Static curve, T = -20 dBFS, R = 4\", aspect=\"equal\")\n", "ax.legend(fontsize=8)\n", "plt.show()" ] }, { "cell_type": "markdown", "id": "nb12-006", "metadata": {}, "source": [ "**Ballistics.** Feed a DC level of $-40$ dBFS for 100 ms, then 0 dBFS for 200 ms (peak detector,\n", "attack 5 ms, release 50 ms, hard knee at $-20$ dBFS, 4:1), and read the per-sample reduction\n", "with `get_gain_reduction`. Above the threshold the hard-knee curve can be inverted,\n", "$L = T + r/(1 - 1/R)$, which recovers the envelope; it reaches 63.2 % of the step after\n", "$\\tau_A = 5$ ms and rises from 10 % to 90 % in $5 \\ln 9 = 10.99$ ms." ] }, { "cell_type": "code", "execution_count": null, "id": "nb12-007", "metadata": {}, "outputs": [], "source": [ "x_step = np.concatenate([np.full(4_800, 0.01), np.full(9_600, 1.0)])\n", "cfg = compressor(threshold_db=-20.0, ratio=4.0, attack_ms=5.0, release_ms=50.0)\n", "gr = np.asarray(mono(x_step).get_gain_reduction(cfg))\n", "\n", "env = 10 ** ((-20.0 + gr / 0.75) / 20) # valid where gr > 0\n", "lo, hi = 0.01, 1.0\n", "\n", "\n", "def reach(level):\n", " idx = np.flatnonzero((np.arange(len(gr)) >= 4_800) & (gr > 0) & (env >= level))\n", " return idx[0]\n", "\n", "\n", "# Sample 4800 is the first at the higher level and already one update of the recursion.\n", "t63_ms = (reach(lo + (1 - np.exp(-1)) * (hi - lo)) - 4_800 + 1) / fs * 1e3\n", "rise_ms = (reach(lo + 0.9 * (hi - lo)) - reach(lo + 0.1 * (hi - lo))) / fs * 1e3\n", "print(f\"63 % after {t63_ms:.3f} ms, 10-90 % rise {rise_ms:.3f} ms\")\n", "# One sample is 0.021 ms, so both are within 0.03 ms of theory.\n", "assert abs(t63_ms - 5.0) < 0.03\n", "assert abs(rise_ms - 5.0 * np.log(9)) < 0.03 and abs(5.0 * np.log(9) - 10.99) < 0.005\n", "# Settled: the envelope is 0 dBFS, 20 dB over the threshold, so 15 dB of reduction.\n", "assert abs(gr[14_000] - 15.0) < 1e-6\n", "\n", "fig, ax = plt.subplots(figsize=(8, 3))\n", "t_ms = (np.arange(len(gr)) - 4_800) / fs * 1e3\n", "ax.plot(t_ms, gr)\n", "ax.set(xlim=(-5, 60), xlabel=\"Time after the step (ms)\", ylabel=\"Gain reduction (dB)\",\n", " title=\"Attack: -40 -> 0 dBFS step, tau_A = 5 ms, T = -20 dBFS, 4:1\")\n", "plt.show()" ] }, { "cell_type": "markdown", "id": "nb12-008", "metadata": {}, "source": [ "The same step through `apply_compressor` settles at $-20 + 20/4 = -15$ dBFS. The\n", "`attack_decay_envelope` method exposes the envelope follower directly; its *attack* output is\n", "the envelope while it rises, so on a step from 0 to 1 it reads exactly $1 - a^k$ after $k$\n", "samples." ] }, { "cell_type": "code", "execution_count": null, "id": "nb12-009", "metadata": {}, "outputs": [], "source": [ "out = mono(x_step)\n", "out.apply_compressor(cfg) # in place\n", "assert abs(20 * np.log10(out.to_numpy()[-1]) + 15.0) < 1e-3\n", "\n", "follower = aus.EnvelopeFollower(5.0, 50.0, float(fs), PEAK)\n", "unit = mono(np.concatenate([np.zeros(10), np.ones(2_000)]))\n", "rising, _ = unit.attack_decay_envelope(follower, PEAK)\n", "a = np.exp(-1 / (0.005 * fs))\n", "k = np.arange(1, 2_001)\n", "assert np.allclose(rising[10:], 1 - a**k, atol=1e-12)\n", "assert abs(rising[10 + 240 - 1] - (1 - np.exp(-1))) < 1e-12 # 63.2 % after 240 samples = 5 ms" ] }, { "cell_type": "markdown", "id": "nb12-010", "metadata": {}, "source": [ "## How it works\n", "\n", "The whole compressor is an envelope follower, the gain computer and a multiplication. Written\n", "out in NumPy it matches `apply_compressor` sample for sample, here with a 6 dB soft knee on a\n", "step up and back down (which also exercises the release)." ] }, { "cell_type": "code", "execution_count": null, "id": "nb12-011", "metadata": {}, "outputs": [], "source": [ "def compress_numpy(x, T, R, W, attack_ms, release_ms, sr=fs):\n", " a_att, a_rel = np.exp(-1 / (attack_ms * 1e-3 * sr)), np.exp(-1 / (release_ms * 1e-3 * sr))\n", " slope = 1 - 1 / R\n", " y = np.empty_like(x)\n", " e = 0.0\n", " for n, v in enumerate(x):\n", " dv = abs(v) # peak detector\n", " a = a_att if dv > e else a_rel\n", " e = a * e + (1 - a) * dv\n", " level = 20 * np.log10(e) if e > 0 else -80.0\n", " o = level - T\n", " r = slope * (o + W / 2) ** 2 / (2 * W) if 2 * abs(o) <= W else slope * max(o, 0.0)\n", " y[n] = v * 10 ** (-r / 20)\n", " return y\n", "\n", "\n", "x3 = np.concatenate([np.full(4_800, 0.01), np.full(9_600, 1.0), np.full(14_400, 0.01)])\n", "soft6 = compressor(threshold_db=-20.0, ratio=4.0, knee_type=SOFT, knee_width_db=6.0)\n", "lib = mono(x3)\n", "lib.apply_compressor(soft6)\n", "mine = compress_numpy(x3, -20.0, 4.0, 6.0, 5.0, 50.0)\n", "# Same operations in the same order: only last-bit differences remain.\n", "assert np.max(np.abs(mine - lib.to_numpy())) < 1e-12" ] }, { "cell_type": "markdown", "id": "nb12-012", "metadata": {}, "source": [ "**A sine is not a DC level.** Through the hard-knee compressor (attack 10 ms, release 100 ms)\n", "a 0 dBFS, 1 kHz sine does *not* come out at $-15$ dBFS: the peak detector rises only near\n", "each crest and releases in between, so the envelope settles below the peak and the output\n", "peaks near $-14.1$ dBFS. The NumPy model predicts the same number." ] }, { "cell_type": "code", "execution_count": null, "id": "nb12-013", "metadata": {}, "outputs": [], "source": [ "sine = np.sin(2 * np.pi * 1_000 * np.arange(fs) / fs)\n", "c10 = compressor(threshold_db=-20.0, ratio=4.0, attack_ms=10.0, release_ms=100.0)\n", "s = mono(sine)\n", "s.apply_compressor(c10)\n", "peak_out = 20 * np.log10(np.max(np.abs(s.to_numpy()[fs // 2:])))\n", "model = compress_numpy(sine, -20.0, 4.0, 0.0, 10.0, 100.0)\n", "print(f\"output peak {peak_out:.2f} dBFS\")\n", "assert np.max(np.abs(model - s.to_numpy())) < 1e-12\n", "assert abs(peak_out + 14.13) < 0.01 # 0.87 dB above the DC prediction of -15 dBFS" ] }, { "cell_type": "markdown", "id": "nb12-014", "metadata": {}, "source": [ "**The limiter and lookahead.** A limiter with a $-6$ dBFS ceiling and a 1 ms attack, on a step\n", "from silence to 0 dBFS. Without lookahead the first sample of the step passes untouched (the\n", "envelope is still at $1 - a = 0.02$), a 6 dB overshoot. With 5 ms of lookahead\n", "($N_L = 240$ samples) the overshoot is $-20\\log_{10}(1 - a^{241}) = 0.0575$ dB. A NumPy model\n", "with a max-hold over the next $N_L$ reductions reproduces the library exactly." ] }, { "cell_type": "code", "execution_count": null, "id": "nb12-015", "metadata": {}, "outputs": [], "source": [ "x_lim = np.concatenate([np.zeros(960), np.ones(2_400)])\n", "\n", "\n", "def limit_numpy(x, C, attack_ms, release_ms, lookahead_ms, sr=fs):\n", " a_att, a_rel = np.exp(-1 / (attack_ms * 1e-3 * sr)), np.exp(-1 / (release_ms * 1e-3 * sr))\n", " D = round(lookahead_ms * 1e-3 * sr)\n", " e, r = 0.0, []\n", " for v in np.concatenate([x, np.zeros(D)]): # the detector sees zeros past the end\n", " a = a_att if abs(v) > e else a_rel\n", " e = a * e + (1 - a) * abs(v)\n", " level = 20 * np.log10(e) if e > 0 else -80.0\n", " r.append(max(level - C, 0.0))\n", " r = np.array(r)\n", " held = np.array([r[n:n + D + 1].max() for n in range(len(x))])\n", " return x * 10 ** (-held / 20)\n", "\n", "\n", "peaks = {}\n", "for la in (0.0, 5.0):\n", " y = mono(x_lim)\n", " y.apply_limiter(limiter(ceiling_db=-6.0, attack_ms=1.0, release_ms=100.0, lookahead_ms=la))\n", " assert np.max(np.abs(y.to_numpy() - limit_numpy(x_lim, -6.0, 1.0, 100.0, la))) < 1e-12\n", " peaks[la] = 20 * np.log10(np.max(np.abs(y.to_numpy())))\n", "\n", "a1 = np.exp(-1 / (0.001 * fs))\n", "predicted = -20 * np.log10(1 - a1**241)\n", "assert abs(peaks[0.0]) < 1e-9 # 0 dBFS: 6 dB over the ceiling\n", "assert abs(predicted - 0.0575) < 1e-3\n", "assert abs(peaks[5.0] - (-6.0 + predicted)) < 1e-9\n", "print({k: round(float(v), 4) for k, v in peaks.items()})" ] }, { "cell_type": "markdown", "id": "nb12-016", "metadata": {}, "source": [ "## Ask the library to explain\n", "\n", "`CompressorConfig.explain(sample_rate)` and `LimiterConfig.explain(sample_rate)` give the\n", "smoothing coefficients, the 10-90 % times, a table of the static curve, and a note when there\n", "is no lookahead." ] }, { "cell_type": "code", "execution_count": null, "id": "nb12-017", "metadata": {}, "outputs": [], "source": [ "doc = cfg.explain(48_000.0)\n", "doc" ] }, { "cell_type": "code", "execution_count": null, "id": "nb12-018", "metadata": {}, "outputs": [], "source": [ "assert abs(doc.quantity(\"Attack 10-90% rise time\") - 10.986) < 1e-3\n", "assert abs(doc.quantity(\"Attack coefficient\") - np.exp(-1 / 240)) < 1e-12\n", "assert abs(doc.quantity(\"Gain reduction at 0 dBFS\") - 15.0) < 1e-9\n", "assert doc.has_warning_containing(\"No lookahead\")\n", "\n", "lim_doc = mono(np.zeros(480)).explain(aus.LimiterConfig.transparent())\n", "assert lim_doc.quantity(\"Gain reduction for a 0 dBFS envelope\") is not None\n", "# transparent() sets isp_limiting (true-peak detection), and the explainer notes it.\n", "for w in lim_doc.warnings:\n", " print(f\"[{w['level']}] {w['message']}\")" ] }, { "cell_type": "markdown", "id": "nb12-019", "metadata": {}, "source": [ "## Exercises\n", "\n", "**1. Read the curve.** With $T = -18$ dBFS and $R = 3$ (hard knee), predict the output level for\n", "a $-2$ dBFS input, then check with `get_compression_curve`. Put it in `answer`." ] }, { "cell_type": "code", "execution_count": null, "id": "nb12-020", "metadata": {}, "outputs": [], "source": [ "answer = None # TODO" ] }, { "cell_type": "code", "execution_count": null, "id": "nb12-021", "metadata": { "tags": [ "solution" ] }, "outputs": [], "source": [ "# Solution\n", "c = compressor(threshold_db=-18.0, ratio=3.0)\n", "answer = probe.get_compression_curve(c, np.array([-2.0]))[0]\n", "# 16 dB over the threshold becomes 16/3 = 5.33 dB over it.\n", "assert abs(answer - (-18 + 16 / 3)) < 1e-12 and abs(answer + 12.67) < 0.005" ] }, { "cell_type": "markdown", "id": "nb12-022", "metadata": {}, "source": [ "**2. Knee at the threshold.** For a 6 dB soft knee and $R = 3$, predict the reduction exactly at\n", "$L = T$. Put it in `answer` (dB)." ] }, { "cell_type": "code", "execution_count": null, "id": "nb12-023", "metadata": {}, "outputs": [], "source": [ "answer = None # TODO" ] }, { "cell_type": "code", "execution_count": null, "id": "nb12-024", "metadata": { "tags": [ "solution" ] }, "outputs": [], "source": [ "# Solution\n", "c = compressor(threshold_db=-18.0, ratio=3.0, knee_type=SOFT, knee_width_db=6.0)\n", "answer = -18.0 - probe.get_compression_curve(c, np.array([-18.0]))[0]\n", "assert abs(answer - (1 - 1 / 3) * 6 / 8) < 1e-12 # 0.5 dB" ] }, { "cell_type": "markdown", "id": "nb12-025", "metadata": {}, "source": [ "**3. Attack in samples.** At 16 kHz with $\\tau_A = 10$ ms, predict $a$ and how many samples an\n", "envelope follower needs to reach 63.2 % of a step from 0 to 1. Put the number of samples in\n", "`answer`." ] }, { "cell_type": "code", "execution_count": null, "id": "nb12-026", "metadata": {}, "outputs": [], "source": [ "answer = None # TODO" ] }, { "cell_type": "code", "execution_count": null, "id": "nb12-027", "metadata": { "tags": [ "solution" ] }, "outputs": [], "source": [ "# Solution\n", "a16 = np.exp(-1 / 160)\n", "assert abs(a16 - 0.99377) < 1e-5\n", "f16 = aus.EnvelopeFollower(10.0, 100.0, 16_000.0, PEAK)\n", "env16, _ = mono(np.ones(1_000), 16_000).attack_decay_envelope(f16, PEAK)\n", "# After k updates the envelope is 1 - a^k; tiny tolerance for the comparison at k = 160.\n", "answer = int(np.argmax(env16 >= 1 - np.exp(-1) - 1e-12)) + 1\n", "assert answer == 160 # 10 ms" ] }, { "cell_type": "markdown", "id": "nb12-028", "metadata": {}, "source": [ "**4. Required lookahead.** For the limiter above (1 ms attack at 48 kHz), how much lookahead in\n", "samples keeps the overshoot below 0.01 dB? Put the smallest $N_L$ in `answer`." ] }, { "cell_type": "code", "execution_count": null, "id": "nb12-029", "metadata": {}, "outputs": [], "source": [ "answer = None # TODO" ] }, { "cell_type": "code", "execution_count": null, "id": "nb12-030", "metadata": { "tags": [ "solution" ] }, "outputs": [], "source": [ "# Solution\n", "overshoot = lambda n: -20 * np.log10(1 - a1 ** (n + 1))\n", "answer = next(n for n in range(2_000) if overshoot(n) < 0.01)\n", "# a^(N_L+1) < 1 - 10^(-0.0005) => N_L + 1 > 324.8.\n", "assert answer == 324 and overshoot(323) >= 0.01\n", "print(f\"{answer} samples = {answer / fs * 1e3:.2f} ms\")" ] }, { "cell_type": "markdown", "id": "nb12-031", "metadata": {}, "source": [ "## Common pitfalls\n", "\n", "- **Attack and release are time constants**, not \"time to full reduction\": 63.2 % after\n", " $\\tau$, 10-90 % in $2.2\\,\\tau$.\n", "- **Detector choice shifts the threshold.** An RMS detector reads a sine 3.01 dB below its\n", " peak, and a slow peak detector reads it lower still (the $-14.1$ dBFS above). The default\n", " `CompressorConfig` uses RMS.\n", "- **dB reference.** Thresholds are in dBFS of the *envelope*, not of individual samples or of\n", " loudness (LUFS).\n", "- **A limiter is not a brick wall.** The start of every transient passes; lookahead shrinks\n", " the overshoot but does not remove it. `isp_limiting` makes the detector read true\n", " (inter-sample) peaks instead of sample peaks.\n", "- **Presets are inconsistent in Python:** `CompressorConfig.vocal`, `.bus` and `.drum` are\n", " class attributes but `CompressorConfig.default()` and all `LimiterConfig` presets are\n", " methods.\n", "- **`get_gain_reduction` ignores lookahead**; `apply_compressor` applies the max-hold.\n", "- The processing methods work **in place** and return `None`.\n", "\n", "## See also\n", "\n", "- Rust guide chapter: (available from the next release; until then build the docs locally with `cargo doc --features educational,full_no_plotting --open`),\n", " the `operations::dynamic_range` module docs (full derivation), and the lab\n", " `examples/tutorial_12_dynamics.rs`.\n", "- Python API: `AudioSamples.apply_compressor`, `AudioSamples.apply_limiter`,\n", " `AudioSamples.get_compression_curve`, `AudioSamples.get_gain_reduction`,\n", " `AudioSamples.attack_decay_envelope`, `audio_samples.CompressorConfig`,\n", " `audio_samples.LimiterConfig`, `audio_samples.EnvelopeFollower`.\n", "- Previous: [11. Short-time energy, zero crossings and VAD](11_energy_vad.ipynb); next:\n", " [13. Onsets and tempo](13_onsets_tempo.ipynb)." ] }, { "cell_type": "markdown", "id": "references", "metadata": {}, "source": [ "## References\n", "\n", "* Giannoulis, D., Massberg, M. and Reiss, J. D. (2012). Digital dynamic range compressor design: a tutorial and analysis. *Journal of the Audio Engineering Society*, 60(6), 399-408." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 5 }