Skip to content

Counter

Overview

Counter module with optional wrap around

Discussion

This module counts up starting from 0 at a specified rate in milliseconds. The count value is output as an integer value on the output pin. The module has an input pin whose only purpose is to get the current sample rate and blockSize. This information is used to determine the time base for the processing. The sample rate of the output pin equals the sample rate of the input divided by the input block size.

The module determine time by counting input samples. The hidden variable .sampleCounterPeriod equals the number of samples which most closely approximates .incTime.

The module variable .wrap can be used to implement circular wrapping. If .wrap = 0, then no wrapping is performed. If .wrap = N, then the module counts up to N-1 and then wraps to 0.

The internal module counter is initialized to 0 and the module outputs the sequence 0, 1, 2, ..., N-1, 0, 1, 2, ..., N-1, 0, etc.

When muted the module outputs all zeros. When bypassed the module continues to run.

Module Pack

Standard

ClassID

classID = 92

Type Definition

typedef struct _ModuleCounter
{
ModuleInstanceDescriptor instance;            // Common Audio Weaver module instance structure
FLOAT32 incTime;                              // Time in msec to wait between increments
UINT32 wrap;                                  // Counting is performed modulo this value
UINT32 count;                                 // Current counter value
UINT32 sampleCounter;                         // Internal variable used to maintain time
UINT32 sampleCounterPeriod;                   // Number of samples corresponding to incTime
} ModuleCounterClass;

Variables

Properties

Name Type Usage isHidden Default Value Range Units
incTime float parameter 0 1000 0:10000 msec
wrap uint parameter 0 5 Unrestricted
count uint state 0 0 Unrestricted
sampleCounter uint state 1 0 Unrestricted
sampleCounterPeriod uint state 1 48000 Unrestricted

Pins

Input Pins

Name in
Description Ignored input
Data type {float, int, fract32}
Channel range Unrestricted
Block size range Unrestricted
Sample rate range Unrestricted
Complex support Real

Output Pins

Name count
Description Count value
Data Type int

Matlab Usage

File Name: counter_module.m 
 M = counter_module(NAME) 
 Audio Weaver module which counts up, and wraps around, at a specified 
 rate.  The count value is output on a pin.  Arguments: 
    NAME - name of the module 

Copyright (c) 2026 DSP Concepts, Inc.