Struct anira::HostConfig

struct HostConfig

Configuration structure for host system parameters.

The HostConfig struct encapsulates the host system’s configuration parameters that are needed for proper integration with neural network inference processing. It defines the buffer characteristics, sample rate, and processing constraints that the inference system must adapt to.

The struct provides utility methods for calculating relative buffer sizes and sample rates when working with multiple tensors that may have different processing requirements or dimensions.

Note

This struct is designed to be lightweight and suitable for frequent copying and comparison operations in real-time contexts.

Public Functions

HostConfig() = default

Default constructor that creates an empty host configuration.

Initializes all parameters to default values (zero buffer size, zero sample rate). The configuration must be properly initialized before use in audio processing.

inline HostConfig(float host_buffer_size, float host_sample_rate, bool allow_smaller_buffers = false, size_t input_tensor_index = 0)

Constructor that initializes host configuration with specified parameters.

Creates a host configuration with the specified audio system parameters. This constructor allows full customization of the audio host environment.

Parameters:
  • host_buffer_sizeBuffer size of the host

  • host_sample_rate – Sample rate of the host

  • allow_smaller_buffers – Whether to allow processing of buffers smaller than the host buffer size (default: false)

  • input_tensor_index – Index of the primary input tensor for buffer size calculations (default: 0)

inline bool operator==(const HostConfig &other) const

Equality comparison operator.

Compares two HostConfig instances for equality using appropriate tolerance for floating-point comparisons. All member variables must match within acceptable precision for the configs to be considered equal.

Note

Floating-point comparisons use a tolerance of 1e-6 to handle precision issues in floating-point arithmetic.

Parameters:

other – The HostConfig instance to compare with

Returns:

True if both configurations are equivalent, false otherwise

inline bool operator!=(const HostConfig &other) const

Inequality comparison operator.

Compares two HostConfig instances for inequality by negating the equality operator.

Parameters:

other – The HostConfig instance to compare with

Returns:

True if the configurations are different, false if they are equivalent

inline float get_relative_buffer_size(const InferenceConfig &inference_config, size_t tensor_index, bool input = true) const

Calculates the relative buffer size for a specific tensor.

Computes the appropriate buffer size for a given tensor based on the ratio between this host configuration’s buffer size and the reference tensor’s size. This is useful when working with multiple tensors that may have different dimensional requirements while maintaining proportional scaling.

The calculation uses the reference tensor (m_tensor_index) to establish a scaling ratio, then applies this ratio to the target tensor’s dimensions.

Note

The returned value maintains the proportional relationship between different tensor sizes based on the host buffer configuration.

Parameters:
  • inference_config – The inference configuration containing tensor dimension information

  • tensor_index – The index of the tensor to calculate the buffer size for

  • input – Whether to calculate for input tensors (true) or output tensors (false)

Returns:

The calculated relative buffer size for the specified tensor

inline float get_relative_sample_rate(const InferenceConfig &inference_config, size_t tensor_index, bool input = true) const

Calculates the relative sample rate for a specific tensor.

Computes the appropriate sample rate for a given tensor based on the ratio between this host configuration’s sample rate and the reference tensor’s size. This is useful when different tensors represent audio data at different effective sample rates due to processing or downsampling.

The calculation uses the reference tensor (m_tensor_index) to establish a scaling ratio, then applies this ratio to the target tensor’s dimensions to determine the effective sample rate.

Note

This method is useful for handling models that process audio at different effective sample rates or with different temporal resolutions.

Parameters:
  • inference_config – The inference configuration containing tensor dimension information

  • tensor_index – The index of the tensor to calculate the sample rate for

  • input – Whether to calculate for input tensors (true) or output tensors (false)

Returns:

The calculated relative sample rate for the specified tensor

Public Members

float m_buffer_size = 0

Maximum size of the input buffer from the host.

float m_sample_rate = 0.0

Sample rate of the host in Hz.

bool m_allow_smaller_buffers = false

Whether to allow processing of buffers smaller than the maximum size.

size_t m_tensor_index = 0

Index of the tensor used as reference for buffer size calculations.