A real-time PCM audio power monitor that calculates and displays the power level of audio data in decibels.
pcmpwr reads 16-bit signed PCM audio data from standard input, processes it in blocks, and outputs timestamped power measurements in decibels. This tool is useful for monitoring audio signal strength in real-time processing pipelines.
- Reads 16-bit signed integer PCM audio data
- Calculates power in decibels
- Outputs measurements with sub-second precision timestamps
- Configurable timestamp format (deciseconds or milliseconds)
- Processes audio in efficient 8192-sample blocks
For a discrete buffer of
Where:
-
$s_i$ is the individual 16-bit signed PCM sample. -
$s_i^2$ represents the instantaneous power of that sample. -
$\frac{1}{N} \sum s_i^2$ is the average power (Mean Square) over the window$N$ .
To compile the program, use the following command:
gcc -Wall -Wextra -std=c11 -O2 pcmpwr.c -o pcmpwr -lmsudo cp pcmpwr /usr/local/binUsing a file with samples in int16_t:
pcmpwr < audio_input.rawOr in a pipeline:
sdr_audio_source | pcmpwrThe default block size is 8192 samples. You can adjust this by changing the BLOCK_SIZE definition at the top of the source file.
- Sample format: 16-bit signed integer (int16_t)
- Byte order: Native system endianness
- Channels: Mono only
Each line of output follows this format:
YYYY-MM-DD HH:MM:SS.D -- XX.X dB
Where:
YYYY= Four-digit yearMM= Month (01-12)DD= Day (01-31)HH= Hour in 24-hour format (00-23)MM= Minute (00-59)SS= Second (00-59)D= Millisecond (000-999)XX.X= Power level in decibels
Example:
2025-12-28 14:23:45.267 -- -12.2 dB
2025-12-28 14:23:45.427 -- -15.2 dB