Conv1D API

class Conv1D

1D dilated convolution layer

Implements a 1D convolution with support for dilation and grouped convolution. Uses a ring buffer to maintain input history for efficient processing of sequential audio frames.

Public Functions

inline Conv1D()

Default constructor.

Initializes with dilation=1 and groups=1. Use set_size_() to configure.

inline Conv1D(const int in_channels, const int out_channels, const int kernel_size, const int bias, const int dilation, const int groups = 1)

Constructor.

Parameters:
  • in_channels – Number of input channels

  • out_channels – Number of output channels

  • kernel_size – Size of the convolution kernel

  • bias – Whether to use bias (1 for true, 0 for false)

  • dilation – Dilation factor for the convolution

  • groups – Number of groups for grouped convolution (default: 1)

void set_weights_(std::vector<float>::iterator &weights)

Set the parameters (weights) of this module.

Parameters:

weights – Iterator to the weights vector. Will be advanced as weights are consumed.

void set_size_(const int in_channels, const int out_channels, const int kernel_size, const bool do_bias, const int _dilation, const int groups = 1)

Set the size parameters of the convolution.

Parameters:
  • in_channels – Number of input channels

  • out_channels – Number of output channels

  • kernel_size – Size of the convolution kernel

  • do_bias – Whether to use bias

  • _dilation – Dilation factor for the convolution

  • groups – Number of groups for grouped convolution

void set_size_and_weights_(const int in_channels, const int out_channels, const int kernel_size, const int _dilation, const bool do_bias, const int groups, std::vector<float>::iterator &weights)

Set size and weights in one call.

Parameters:
  • in_channels – Number of input channels

  • out_channels – Number of output channels

  • kernel_size – Size of the convolution kernel

  • _dilation – Dilation factor for the convolution

  • do_bias – Whether to use bias

  • groups – Number of groups for grouped convolution

  • weights – Iterator to the weights vector. Will be advanced as weights are consumed.

void SetMaxBufferSize(const int maxBufferSize)

Reset the ring buffer and pre-allocate output buffer.

Parameters:

maxBufferSize – Maximum buffer size for output buffer and to size ring buffer

inline Eigen::MatrixXf &GetOutput()

Get the entire internal output buffer.

This is intended for internal wiring between layers; callers should treat the buffer as pre-allocated storage and only consider the first num_frames columns valid for a given processing call. Slice with .leftCols(num_frames) as needed.

Returns:

Reference to the output buffer

inline const Eigen::MatrixXf &GetOutput() const

Get the entire internal output buffer (const version)

Returns:

Const reference to the output buffer

void Process(const Eigen::MatrixXf &input, const int num_frames)

Process input and write to internal output buffer.

Parameters:
  • input – Input matrix (channels x num_frames)

  • num_frames – Number of frames to process

void process_(const Eigen::MatrixXf &input, Eigen::MatrixXf &output, const long i_start, const long ncols, const long j_start) const

Process from input to output (legacy method, kept for compatibility)

Rightmost indices of input go from i_start for ncols, Indices on output go from j_start (to j_start + ncols - i_start).

Parameters:
  • input – Input matrix

  • output – Output matrix

  • i_start – Starting index in input

  • ncols – Number of columns to process

  • j_start – Starting index in output

long get_in_channels() const

Get the number of input channels.

Returns:

Number of input channels

long get_kernel_size() const

Get the kernel size.

Returns:

Kernel size

long get_num_weights() const

Get the total number of weights.

Returns:

Total number of weight parameters

long get_out_channels() const

Get the number of output channels.

Returns:

Number of output channels

inline int get_dilation() const

Get the dilation factor.

Returns:

Dilation factor

inline bool has_bias() const

Check if bias is used.

Returns:

true if bias is present, false otherwise