Skip to content

py2sdr/pcmpower

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 

Repository files navigation

Screenshot_2025-12-28_16-18-22

pcmpwr

A real-time PCM audio power monitor that calculates and displays the power level of audio data in decibels.

Description

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.

Features

  • 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

Mathematical Foundation

For a discrete buffer of $N$ samples, the power is calculated as:

$$P_{dB} = 10 \cdot \log_{10} \left( \frac{1}{N} \sum_{i=1}^{N} s_i^2 \right)$$

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$.

Compiling

To compile the program, use the following command:

gcc -Wall -Wextra -std=c11 -O2 pcmpwr.c -o pcmpwr -lm

Installation

sudo cp pcmpwr /usr/local/bin

Usage

Using a file with samples in int16_t:

pcmpwr < audio_input.raw

Or in a pipeline:

sdr_audio_source | pcmpwr

Notes

Block Size

The default block size is 8192 samples. You can adjust this by changing the BLOCK_SIZE definition at the top of the source file.

Input Format

  • Sample format: 16-bit signed integer (int16_t)
  • Byte order: Native system endianness
  • Channels: Mono only

Output Format

Each line of output follows this format:

YYYY-MM-DD HH:MM:SS.D -- XX.X dB

Where:

  • YYYY = Four-digit year
  • MM = 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

License

MIT License

About

PCM audio power monitor implemented in C

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages