SampleCounter
Overview
Sample-exact counter with optional runtime wrap control.
Discussion
This module counts up from 0, incrementing once every incTime input samples. Unlike the Counter module, counting is sample-exact: the process function loops over each audio sample within the block, so incTime can be any integer number of samples regardless of block size.
The incTime parameter is specified directly in samples (not milliseconds). No internal conversion is needed, so a change to incTime takes effect immediately.
The blockSize and sampleRate constructor arguments define the audio clock domain. When left empty they are resolved from the connected target at build time.
When wrapPin = 1, an integer scalar input pin is exposed. The single sample value on this pin overrides the wrap parameter at the start of each block, allowing runtime control of the wrap boundary. When wrapPin = 0, no input pin is present and wrap is a static tunable parameter.
The wrap variable controls circular wrapping: If wrap = 0, no wrapping is performed (free-running). If wrap = N, the module counts 0, 1, ..., N-1, 0, 1, ..., N-1, etc.
When muted the module outputs all zeros. When bypassed the module continues to run.
Module Pack
Standard
ClassID
classID = 259
Type Definition
typedef struct _ModuleSampleCounter
{
ModuleInstanceDescriptor instance; // Common Audio Weaver module instance structure
UINT32 incTime; // Number of samples between count increments
UINT32 wrap; // Counting is performed modulo this value (0 = no wrap)
UINT32 count; // Current counter value
UINT32 sampleCounter; // Samples elapsed within the current period
INT32 wrapPin; // Enables input pin for runtime wrap control
} ModuleSampleCounterClass;
Variables
Properties
| Name | Type | Usage | isHidden | Default Value | Range | Units |
|---|---|---|---|---|---|---|
| incTime | uint | parameter | 0 | 48000 | 1:1:4800000 | samples |
| wrap | uint | parameter | 0 | 5 | Unrestricted | |
| count | uint | state | 0 | 0 | Unrestricted | |
| sampleCounter | uint | state | 1 | 0 | Unrestricted | |
| wrapPin | int | const | 1 | 0 | Unrestricted |
Pins
Input Pins
| Name | wrapIn |
| Description | Runtime wrap value per sample |
| Data type | int |
| Channel range | 1 |
| Block size range | Unrestricted |
| Sample rate range | Unrestricted |
| Complex support | Real |
Note: Input pin wrapIn is only present when the wrapPin constructor argument is 1.
Output Pins
| Name | count |
| Description | Count value per sample |
| Data Type | int |
Matlab Usage
File Name: sample_counter_module.m
M = sample_counter_module(NAME, BLOCKSIZE, SAMPLERATE, WRAPPIN)
Audio Weaver module which counts up sample-exactly and wraps around at a
specified period given in samples. The count value is output on a pin.
Arguments:
NAME - name of the module
BLOCKSIZE - audio block size used for sample-exact counting.
By default, BLOCKSIZE is taken from the connected target.
SAMPLERATE - system sample rate in Hz.
By default, SAMPLERATE is taken from the connected target.
WRAPPIN - Boolean that determines whether the module exposes an input
pin that allows the wrap value to be controlled at runtime.
Default is 1 (pin present).
Copyright (c) 2026 DSP Concepts, Inc.