Tone Generator (Tone) Architecture & Signal Engine#

Sound Open Firmware (SOF) provides an integrated, mathematically rigorous signal synthesis engine known as the Tone Generator (src/audio/tone/, COMP_TONE, UUID tone_uuid). Unlike standard audio processing components that manipulate existing PCM streams captured from microphones or decoded from host applications, the Tone component is capable of operating as an autonomous, hostless sound source.

In embedded audio development, bare-metal hardware bringup, manufacturing diagnostic stations, and high-precision acoustic calibration pipelines, having an autonomous DSP-native signal generator is indispensable. Tone enables engineers to inject bit-exact, mathematically pure reference waveforms (single-frequency sinusoids, anti-click windowed tone bursts, logarithmic frequency chirps, and stepped amplitude test sweeps) directly into the downstream DSP pipeline and output DAIs (I2S, SoundWire, HDA, PDM). Because Tone can synthesize audio without requiring an active host streaming application or PCIe/USB interconnect traffic, it serves as the ultimate diagnostic baseline to isolate hardware driver faults, platform clock jitter, amplifier non-linearities, and acoustic transducer distortion.

Furthermore, Tone features a dynamic multi-mode architecture: beyond standalone tone generation, it functions as a zero-overhead stream passthrough bridge and an Acoustic Echo Cancellation (AEC) reference channel fallback generator that produces mathematical zero-energy silence when capture pipelines operate without playback streams.

High-level architectural block diagram showing the Tone component synthesis core, temporal control, multi-channel state, and operational modes.

Figure 161 SOF Tone Subsystem Architecture: Synthesis Engine, Modes & Pipeline Integration#

Role of Embedded Tone Synthesis in Audio DSP & Hardware Bringup#

In production firmware engineering, validating audio hardware involves complex interactions between operating system kernels, userspace audio servers (ALSA, PulseAudio, PipeWire), bus drivers (PCIe, SoundWire, I2C/I2S), and mixed-signal audio codecs. When an audio pipeline fails to produce sound or exhibits distortion, isolating the failure domain is notoriously difficult:

  • Did the host userspace application underrun the DMA ring buffer?

  • Did the kernel ASoC machine driver configure incorrect DAI clock dividers or time-slot allocation (TDM)?

  • Did the DSP operating system miss real-time deadlines, corrupting PCM circular pointers?

  • Did the external audio codec or smart amplifier enter thermal shutdown, DC protection, or experience analog clipping?

The SOF Tone component eliminates these variables by embedding signal synthesis directly into the DSP execution graph. Operating at the boundary of the DSP and digital audio interfaces, Tone provides an authoritative reference standard for hardware characterization.

Key Architectural Use Cases#

Table 15 Core Use Cases for SOF Tone Generator#

Application Domain

Operating Configuration

Technical Function & Diagnostic Value

Hostless Hardware Bringup

Standalone playback pipeline without host stream

Generates clean 997 Hz / -20 dBFS sine waves directly to digital audio interfaces (I2S, SoundWire, HDA). Verifies BCLK, WCLK, MCLK, and frame sync timing on oscilloscope/logic analyzer without host driver dependencies.

THD+N & Linearity Calibration

Single-frequency pure sinusoid at varying amplitudes

Supplies bit-exact test signals to external Audio Precision or host loopback bridges (ESP32-P4 / Teensy 4.1) to measure Total Harmonic Distortion plus Noise (THD+N), dynamic range, and DAC linearity.

Acoustic Transducer Profiling

Logarithmic stepped chirp sweeps

Sweeps across audible frequencies (\(20\text{ Hz} \dots 20\text{ kHz}\)) to measure micro-speaker resonant frequencies (\(f_0\)), acoustic enclosure frequency responses, and passive radiator impedance.

AEC Reference Fallback

TONE_MODE_SILENCE

Provides a synchronized, zero-energy reference channel for Acoustic Echo Cancellation (AEC) algorithms when capture streams run without active media playback, preventing division-by-zero filter instabilities.

Manufacturing Line Functional Testing

Automated multi-tone burst sequences

Executes rapid acoustic pass/fail screening on assembly lines, confirming speaker voice-coil continuity and microphone array sensitivity in under 500 ms.

Mathematical Foundations: Fixed-Point CORDIC Sine & Phase Accumulation#

Generating pure trigonometric waveforms in an embedded audio DSP requires high mathematical precision, deterministic execution timing, and zero reliance on high-latency software floating-point emulation. The SOF Tone generator implements a 32-bit fixed-point synthesis architecture utilizing a Phase Accumulator coupled with a Coordinate Rotation Digital Computer (CORDIC) algorithm.

Phase Accumulator Mechanics#

A continuous sinusoidal signal of frequency \(f\) sampled at frequency \(f_s\) is defined mathematically as:

\[y(n) = A \cdot \sin(\omega_n) = A \cdot \sin\left(2\pi \frac{f}{f_s} \cdot n + \phi_0\right)\]

In digital signal processing, the instantaneous angular phase \(\omega_n\) is computed recursively by a phase accumulator:

\[\omega_{n} = (\omega_{n-1} + \Delta \omega) \pmod{2\pi}\]

where the angular step \(\Delta \omega\) represents the phase advance per discrete sample:

\[\Delta \omega = 2\pi \frac{f}{f_s}\]

Fixed-Point Number Representations#

To preserve dynamic range and phase accuracy while avoiding integer overflow, Tone utilizes three specialized fixed-point Q-formats:

  1. Angular Phase (\(\omega\)) and Step (\(\Delta \omega\)): Represented in Q4.28 format (4 integer bits including sign, 28 fractional bits). In this format, one radian is represented as \(2^{28} = 268{,}435{,}456\). The circular modulus \(2\pi\) is represented exactly by the constant:

    \[2\pi_{\text{Q4.28}} = \text{round}(2\pi \times 2^{28}) = 1{,}686{,}629{,}713 \quad (\text{hex: } \mathtt{0x6487ED51})\]

    and \(\pi_{\text{Q4.28}} = 843{,}314{,}857\) (\(\mathtt{0x3243F6A9}\)).

  2. Oscillator Frequency (\(f\)): Represented in Q16.16 format (16 integer bits, 16 fractional bits), allowing frequency precision of \(1/65536 \approx 15.26\text{ }\mu\text{Hz}\) with a maximum frequency of 32,767.99 Hz.

  3. Sample Rate Coefficient (\(c = 2\pi / f_s\)): Represented in Q1.31 format (1 sign bit, 31 fractional bits). Pre-computed lookup tables store \(c\) for 13 standard sample rates (from 8 kHz to 192 kHz), avoiding expensive run-time divisions:

Table 16 Pre-computed Angular Step Coefficients (\(c = 2\pi / f_s\)) in Q1.31 Format#

Sample Rate (\(f_s\))

Mathematical Value (\(2\pi / f_s\))

Q1.31 Integer Value

Hexadecimal Value

8,000 Hz

\(0.000785398\)

1,686,630

0x0019BC66

16,000 Hz

\(0.000392699\)

843,315

0x000CDE33

44,100 Hz

\(0.000142476\)

305,965

0x0004AB2D

48,000 Hz

\(0.000130900\)

281,105

0x00044A11

96,000 Hz

\(0.000065450\)

140,552

0x00022508

192,000 Hz

\(0.000032725\)

70,276

0x00011284

The angular phase step \(\Delta \omega\) is computed via fixed-point multiplication:

\[\Delta \omega_{\text{Q4.28}} = \frac{f_{\text{Q16.16}} \times c_{\text{Q1.31}}}{2^{19}}\]

which maps directly to the SOF math utility:

w_tmp = q_multsr_32x32(sg->f, sg->c, Q_SHIFT_BITS_64(16, 31, 28));

Nyquist Limiting & Phase Accumulation#

To eliminate aliasing, the requested frequency is hard-clamped to the platform Nyquist threshold (\(f \le f_s / 2\)):

\[f_{\text{clamped}} = \min\left(f, \frac{f_s}{2}\right), \quad \Delta \omega_{\text{clamped}} = \min(\Delta \omega, \pi_{\text{Q4.28}})\]

On each sample cycle, the phase accumulator advances:

\[\begin{split}\omega_{n} = \begin{cases} \omega_{n-1} + \Delta \omega - 2\pi_{\text{Q4.28}}, & \text{if } (\omega_{n-1} + \Delta \omega) > 2\pi_{\text{Q4.28}} \\ \omega_{n-1} + \Delta \omega, & \text{otherwise} \end{cases}\end{split}\]

Detailed mathematical dataflow of the fixed-point phase accumulator, angular modulo, CORDIC vector rotation, and amplitude scaling.

Figure 162 Mathematical Foundations: Phase Accumulator & 31-bit CORDIC Trigonometric Engine#

31-bit CORDIC Sine Engine (sin_fixed_32b)#

Rather than maintaining massive sine lookup tables in precious DSP cache or incurring non-linear interpolation distortion, SOF evaluates the sine function using the CORDIC algorithm (src/math/trig.c).

CORDIC operates by executing iterative vector micro-rotations using only bit-shifts and additions:

\[x_{i+1} = x_i - d_i \cdot y_i \cdot 2^{-i}\]
\[y_{i+1} = y_i + d_i \cdot x_i \cdot 2^{-i}\]
\[z_{i+1} = z_i - d_i \cdot \alpha_i\]

where \(d_i = \text{sgn}(z_i)\) and \(\alpha_i = \arctan(2^{-i})\). Over 31 iterations, the residual angle \(z\) converges to zero, and the vector coordinates \((x, y)\) converge to \(K \cdot (\cos \omega, \sin \omega)\) where \(K \approx 1.646760258\) is the known CORDIC scaling gain.

The result is a mathematically pure sinusoid with an Spurious-Free Dynamic Range (SFDR) exceeding 110 dB and total harmonic distortion below \(-105\text{ dB}\), surpassing the noise floor of commercial 24-bit audio converters.

Temporal Enveloping, Anti-Click Phase Alignment & Linear Ramping#

In audio synthesis, abruptly switching on or cutting off a sine wave introduces severe high-frequency spectral splatter, perceived acoustically as an audible “click” or “pop”:

\[x(t) = A \sin(\omega t) \cdot u(t) \quad \xrightarrow{\mathcal{F}} \quad X(j\Omega) = \frac{A\omega}{\omega_0^2 - \Omega^2} + \frac{\pi A}{2j}[\delta(\Omega - \omega_0) - \delta(\Omega + \omega_0)]\]

The step discontinuity \(u(t)\) scatters energy across the entire audio spectrum. To guarantee pristine acoustic transients, the SOF Tone generator implements a dedicated temporal control subsystem (tonegen_control).

125 Microsecond Sub-Block Quantization#

Temporal envelope modifications (ramping, sweeping, state transitions) are evaluated in standardized sub-blocks of 125 microseconds (\(\Delta t_{\text{block}} = 125\text{ }\mu\text{s}\)), corresponding to an update frequency of 8,000 Hz. The number of audio samples per 125 \(\mu\)s block is:

\[\begin{split}N_{\text{samples\_in\_block}} = \text{round}\left(f_s \times 125 \times 10^{-6}\right) = \begin{cases} 1, & \text{if } f_s = 8000\text{ Hz} \\ 2, & \text{if } f_s = 16000\text{ Hz} \\ 6, & \text{if } f_s = 48000\text{ Hz} \\ 12, & \text{if } f_s = 96000\text{ Hz} \end{cases}\end{split}\]

Evaluating envelope parameters at 125 \(\mu\)s intervals decouples envelope timing from audio pipeline period sizes (e.g. 1 ms or 4 ms) while dramatically reducing DSP instruction overhead compared to per-sample evaluation.

Anti-Click Phase Reset#

When a tone burst is initiated from complete silence (\(a = 0\)), Tone automatically forces the phase accumulator to zero:

if (sg->a == 0)
    sg->w = 0; /* Reset phase to have less clicky ramp */

Starting synthesis at \(\omega = 0\) guarantees that the waveform commences precisely at its mathematical zero-crossing (\(\sin(0) = 0\)), eliminating phase discontinuity transients.

Three-Phase Envelope Trajectory#

The temporal envelope of a tone burst is partitioned into three chronological phases:

  1. Attack Phase (Fade-In Ramp) (\(0 \le t_{\text{block}} < t_{\text{length}}\)): The instantaneous amplitude \(a\) advances toward the target amplitude \(a_{\text{target}}\) in linear steps:

    \[a_{m} = \min(a_{m-1} + \Delta a_{\text{ramp}}, a_{\text{target}})\]

    where \(\Delta a_{\text{ramp}}\) is the configured ramp_step in Q1.31 format.

  2. Sustain Phase (\(a = a_{\text{target}}\)): The tone maintains steady-state amplitude for the remainder of the active duration (\(\text{tone\_length}\)).

  3. Decay Phase (Fade-Out Ramp) (\(t_{\text{length}} \le t_{\text{block}} < t_{\text{period}}\)): Once \(t_{\text{block}}\) exceeds tone_length, the amplitude ramps linearly back to zero:

    \[a_{m} = \max(a_{m-1} - \Delta a_{\text{ramp}}, 0)\]

Timing waveform showing anti-click phase zero-crossing, linear attack ramp, active sustain window, and linear decay ramp.

Figure 163 Temporal Enveloping: Linear Attack, Sustain, Decay & Anti-Click Phase Alignment#

Chirp Synthesis, Logarithmic Sweeps & Multi-Tone Stepping#

In acoustic engineering, single fixed-frequency tones provide limited diagnostic visibility. To measure the full frequency response, resonant modes, and acoustic distortion of a loudspeaker or audio pipeline, automated frequency chirps and amplitude sweeps are required.

The Tone generator incorporates a built-in logarithmic sweep engine capable of executing stepped multi-tone chirps without requiring external host scripting.

Mathematical Formulation of Logarithmic Sweeps#

Upon completion of each active period (\(\text{block\_count} > \text{tone\_period}\)), if the repetition counter has not reached the configured limit (sg->repeat_count + 1 < sg->repeats), Tone updates its synthesis parameters for the subsequent burst:

  1. Logarithmic Frequency Progression: The frequency \(f_{k+1}\) of the \((k+1)\)-th burst is derived from the previous frequency \(f_k\) via multiplication by a frequency coefficient \(\beta_f\) (sg->freq_coef) represented in Q2.30 format:

    \[f_{k+1} = f_k \times \beta_f\]

    where:

    \[\beta_f = \frac{\text{freq\_coef}}{2^{30}}\]
    • If \(\beta_f > 1.0\) (e.g. freq_coef = 1181116006 \(\approx 1.10\)), the frequency increases exponentially on each step (ascending chirp).

    • If \(\beta_f < 1.0\) (e.g. freq_coef = 966367641 \(\approx 0.90\)), the frequency decreases exponentially (descending chirp).

    • If \(\beta_f = 1.0\) (ONE_Q2_30 = 1073741824), the frequency remains constant.

    The calculation executes with rounding in 64-bit precision:

    p = q_multsr_32x32(sg->f, sg->freq_coef, Q_SHIFT_BITS_64(16, 30, 16));
    tonegen_update_f(sg, (int32_t)p);
    
  2. Logarithmic Amplitude Progression: Similarly, the target amplitude \(a_{k+1}\) scales on each burst via an amplitude multiplier \(\beta_a\) (sg->ampl_coef in Q2.30):

    \[a_{k+1} = \text{sat}_{31}\left(a_k \times \beta_a\right)\]

    This enables automated linearity tests, sweeping signal amplitude from \(-60\text{ dBFS}\) to \(0\text{ dBFS}\) in discrete steps to locate amplifier compression thresholds and speaker voice-coil rubbing.

Architectural diagram of the multi-burst chirp synthesis engine showing frequency multiplication, amplitude scaling, and repeat tracking.

Figure 164 Logarithmic Sweep & Chirp Engine (Frequency Multiplication, Stepping & Repeats)#

Operational Modes & Multi-Channel Architecture#

The SOF Tone component features a versatile tri-mode operational crossbar (cd->mode) that adapts dynamically depending on pipeline binding and hardware configuration:

  1. Autonomous Tone Generation Mode (``TONE_MODE_TONEGEN = 0``): Default operating state when Tone is instantiated without active upstream source components (e.g. nb_input_pins == 0). Tone acts as an autonomous data producer, writing synthesized sine waveforms into its downstream sink buffer on every pipeline period tick.

  2. Stream Passthrough Mode (``TONE_MODE_PASSTHROUGH = 1``): Activated automatically in modular IPC4 topologies when an upstream source module binds to Tone (tone_bind()). In this mode, Tone suspends signal synthesis and transparently forwards incoming PCM samples from source to sink with zero latency and full circular buffer boundary wrapping. This allows Tone to remain embedded in production topologies as an on-demand diagnostic probe without requiring topology rebuilds.

  3. Pure Silence Generation Mode (``TONE_MODE_SILENCE = 2``): Activated when Tone is bound to capture pipelines as an echo reference fallback (e.g. nb_input_pins > 0 in capture direction) or when explicitly uncoupled. Writes mathematical zero values (*output_pos = 0), ensuring that downstream Acoustic Echo Cancellation (AEC) or matrix mixers receive a valid, clean zero-energy reference stream.

Diagram illustrating the three operational execution modes of the Tone component: autonomous generation, passthrough forwarding, and silence generation.

Figure 165 Tri-Mode Execution Crossbar: ToneGen, Passthrough & Silence Modes#

Multi-Channel Architecture#

The Tone component supports multi-channel stream topologies up to PLATFORM_MAX_CHANNELS (typically 8 channels). Each channel maintains an completely independent state structure (struct tone_state sg[i]).

This multi-channel independence enables advanced acoustic test configurations:

  • Independent Channel Frequencies: Generating 1 kHz on Channel 0 (Left) and 2 kHz on Channel 1 (Right) to verify stereo separation and detect inter-channel crosstalk.

  • Phase-Inversion Testing: Configuring opposite phase angles (\(\Delta \phi = \pi\)) between stereo channels to test differential amplifier performance or verify acoustic phase cancellation in noise-canceling headsets.

  • Selective Channel Muting: Muting individual channels (tonegen_mute(&cd->sg[i])) while maintaining active generation on adjacent channels to detect hardware trace leakage.

Runtime Control, ALSA Mixers & IPC3/IPC4 Parameter Delivery#

The Tone generator provides comprehensive runtime control across both legacy IPC3 and modern IPC4 architectures:

IPC3 Control Interface (SOF_CTRL_CMD_ENUM)#

Under IPC3, Tone exposes eight control indices mapped through the standard ALSA mixer enumerated control interface:

Table 17 IPC3 Tone Control Indices (user/tone.h)#

Control Index

Value

Functional Parameter & Format

SOF_TONE_IDX_FREQUENCY

0

Oscillation frequency in Hertz represented in Q16.16 format.

SOF_TONE_IDX_AMPLITUDE

1

Target sine wave peak amplitude represented in Q1.31 format.

SOF_TONE_IDX_FREQ_MULT

2

Step frequency multiplier for logarithmic chirps in Q2.30 format.

SOF_TONE_IDX_AMPL_MULT

3

Step amplitude multiplier for stepped sweeps in Q2.30 format.

SOF_TONE_IDX_LENGTH

4

Active tone burst duration in units of 125 \(\mu\)s blocks.

SOF_TONE_IDX_PERIOD

5

Total cycle period (active duration + idle pause) in 125 \(\mu\)s blocks.

SOF_TONE_IDX_REPEATS

6

Total number of sweep burst repetitions.

SOF_TONE_IDX_LIN_RAMP_STEP

7

Linear amplitude modification step per 125 \(\mu\)s block in Q1.31 format.

Diagram comparing IPC3 enumerated ALSA mixer control dispatch with IPC4 base module configuration and dynamic binding.

Figure 166 Runtime Parameter Delivery & ALSA Control Topology (IPC3 vs IPC4)#

IPC4 Modular Adapter & LLEXT Packaging#

In IPC4 environments, the Tone generator is implemented as a standardized processing module (src/audio/tone/tone-ipc4.c) conforming to the SOF Module Adapter API:

static const struct module_interface tone_interface = {
    .init     = tone_init,
    .prepare  = tone_prepare,
    .process  = tone_process,
    .reset    = tone_reset,
    .free     = tone_free,
    .bind     = tone_bind,
    .unbind   = tone_unbind,
};

Tone is declared with Loadable Linkable Extension (LLEXT) metadata:

static const struct sof_man_module_manifest mod_manifest[] __section(".module") __used = {
    SOF_LLEXT_MODULE_MANIFEST("TONE", &tone_interface, 1, SOF_REG_UUID(tone), 30),
};

This enables Tone to be built either as an embedded static component within the base firmware image or packaged as a standalone, dynamically loadable ELF module (.llext) deployed on demand.

Hostless Playback, Factory Loopback & Diagnostics Runbook#

The ability to operate without an active host PCM audio stream makes Tone the foundational component for automated manufacturing line tests and hardware diagnostic testbenches.

Hostless Test Pipeline Topology#

Figure 208 illustrates an end-to-end hostless audio verification pipeline configured in Sound Open Firmware:

Full system audio topology connecting the autonomous Tone generator to Volume control, DAI output, external hardware loopback, and analysis instruments.

Figure 167 End-to-End Bringup Audio Pipeline: Hostless Tone Generator to DAI Output & Closed-Loop Testbench#

Topology 1 M4 Declaration#

In legacy and test topologies (tools/topology/topology1/m4/tone.m4), the Tone component is declared with its buffer properties:

# Tone component definition
# W_TONE(name, format, periods_sink, periods_source, core, kcontrols)
W_TONE(Tone 1, 32, 2, 0, 0, LIST(`           ', `TONE_IN_CONTROLS'))

Automated Verification Runbook#

To execute a closed-loop audio quality verification test using the embedded Tone generator:

  1. Deploy Hostless Tone Topology: Deploy a topology containing the autonomous Tone pipeline connected directly to the target DAI (e.g. test-tone-playback.m4):

    sof-ctl -Dhw:0 -c name='Tone 1 Tone Freq' -v 997
    sof-ctl -Dhw:0 -c name='Tone 1 Tone Amplitude' -v 214748364
    
  2. Trigger Pipeline Playback: Start the pipeline trigger using the SOF testbench or ALSA control utilities:

    alsactl -f /var/lib/alsa/asound.state restore
    
  3. Capture via External Bridge: Record the digital stream on an external loopback card (e.g. ESP32-P4 or Teensy 4.1):

    arecord -Dhw:CARD=Bridge,DEV=0 -r 48000 -c 2 -f S32_LE -d 5 /tmp/tone_capture.wav
    
  4. Verify Harmonic Distortion: Execute automated FFT spectral analysis on the recorded WAV file to confirm that the fundamental peak is exactly 997.0 Hz and that spurious harmonics satisfy \(\text{THD+N} < -90\text{ dBFS}\).