Source browser
examples/shaders/signal_fir.cpp
Read the complete file below or download its original bytes. Line numbers provide stable links to a declaration or processing step.
File fingerprint
1// Causal FIR over independent channel-major samples, with zero-prefix batch history.
2#ifdef __cplusplus // Enable this block only for the indicated compilation environment.
3#include "shdr.h" // Use the same header for CPU and GPU resource wiring.
4#endif // Finish the conditional compilation block.
5layout(local_size_x = 64) in; // Process up to 64 independent invocations in each work group.
6layout(std430, binding = 0) readonly buffer Inputs { // Read channel-major input samples through this storage binding.
7 float input_values[]; // Store input samples in channel-major order.
8}; // Finish this shader storage declaration.
9layout(std430, binding = 1) writeonly buffer Outputs { // Write one filtered sample to the matching output position.
10 float output_values[]; // Store filtered samples in matching channel-major order.
11}; // Finish this shader storage declaration.
12layout(std430, binding = 2) readonly buffer Coefficients { // Read the shared filter coefficients from this storage binding.
13 float coefficients[]; // Store the finite filter coefficients.
14}; // Finish this shader storage declaration.
15uniform uint count; // Receive the sample count for each channel in this block.
16uniform uint channels; // Receive the number of independent signal channels.
17uniform uint taps; // Receive the causal FIR coefficient count.
18void main() { // Filter the single causal output sample assigned to this invocation.
19 uint index = gl_GlobalInvocationID.x; // Find the sample handled by this invocation.
20 if (index >= count * channels) // Ignore unused invocations outside the sample buffer.
21 return; // Finish invocations beyond the configured signal range.
22 uint position = index % count; // Find the sample position within its channel.
23 float value = 0.0; // Start the scalar accumulator at zero.
24 for (uint tap = 0u; tap < taps && tap <= position; ++tap) // Use only causal taps that lie inside this batch.
25 value += coefficients[tap] * input_values[index - tap]; // Accumulate the next available causal FIR tap.
26 output_values[index] = value; // Store the result at the matching sample position.
27} // Finish the main operation.