sac_utils.h
Utility functions for the SPARK Audio Core.
- Copyright
Copyright (C) 2026 SPARK Microsystems International Inc. All rights reserved.
- License
This source code is proprietary and subject to the SPARK Microsystems Software EULA found in this package in file EULA.txt.
- Author
SPARK FW Team.
Defines
-
SAC_SYSTEM_LATENCY_PKT 3
SAC system latency in number of packets. 1 for DMA transfer, 2 for wireless queue.
-
SAC_CHECK_STATUS(cond, status_ptr, status_code, ret)
do { \
if (cond) { \
*(status_ptr) = (status_code); \
ret; \
} \
} while (0)
-
SAC_CALCULATE_PAYLOAD_SIZE(samp_nb_per_ch, ch_nb, bits) (((samp_nb_per_ch) * (ch_nb) * (bits) + 7) / 8)
Calculate the audio payload size based on the audio sample settings.
-
SAC_CALCULATE_LATENCY_QUEUE_SIZE(target_ms, periph_latency_ms, nb_samp_per_ch, samp_rate_hz) ((((samp_rate_hz) * ((target_ms) - (periph_latency_ms))) / ((nb_samp_per_ch) * 1000)) - SAC_SYSTEM_LATENCY_PKT)
Calculate the audio payload size based on the number of samples per channel per packet, the sample rate and the audio peripheral latency (ADC, DAC, USB, etc).
-
SAC_CALCULATE_SAMPLE_COUNT(nb_byte, nb_ch, bytes_per_samp) ((nb_byte) / ((nb_ch) * (bytes_per_samp)))
Calculate the number of samples per channel contained in a packet.
Functions
-
uint8_t sac_get_sample_size_from_format(sac_sample_format_t sample_format)
Get the number of bits used to store a sample of a given format.
- Parameters:
sample_format – [in] Sample format.
- Returns:
The number of bits required to store a single sample.
-
uint16_t sac_get_nb_packets_in_x_ms(uint16_t ms, uint16_t audio_payload_size, uint8_t nb_channel, sac_sample_format_t sample_format, uint32_t sampling_rate)
Get the number of audio packets in a given amount of milliseconds.
- Parameters:
ms – [in] The number of milliseconds.
audio_payload_size – [in] The size of the audio payload in bytes.
nb_channel – [in] The number of audio channels.
sample_format – [in] The format of the samples in the audio payload.
sampling_rate – [in] The sampling rate of the samples in the audio payload in Hz.
- Returns:
Number of audio packets, rounded down.
-
uint16_t sac_get_ms_in_x_packets(uint16_t nb_packet, uint16_t audio_payload_size, uint8_t nb_channel, sac_sample_format_t sample_format, uint32_t sampling_rate)
Get the number of milliseconds in a given number of audio packets.
- Parameters:
nb_packet – [in] The number of packets.
audio_payload_size – [in] The size of the audio payload in bytes.
nb_channel – [in] The number of audio channels.
sample_format – [in] The format of the samples in the audio payload.
sampling_rate – [in] The sampling rate of the samples in the audio payload in Hz.
- Returns:
Number of milliseconds, rounded down.
-
bool sac_configure_packing(sac_packing_instance_t *instance, sac_sample_format_t producer_format, sac_sample_format_t consumer_format, sac_status_t *status)
Configure a packing instance based on producer and consumer sample formats.
Note
Determines the appropriate packing mode for converting between the producer and consumer sample formats. Handles all combinations of pack (unpacked to packed), unpack (packed to unpacked), and scale (packed to packed) operations.
- Parameters:
instance – [out] Packing instance to configure.
producer_format – [in] Sample format of the audio producer.
consumer_format – [in] Sample format of the audio consumer.
status – [out] SAC status code. Set to SAC_ERR_BIT_DEPTH on unsupported combination.
- Return values:
true – Packing is required; instance has been configured.
false – No packing required (formats are compatible) or unsupported (check status).