sac_utils.h
Utility functions for the SPARK Audio Core.
- Copyright
Copyright (C) 2023 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).
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.