sac_api.hο
SPARK Audio Core Application Programming Interface.
- Copyright
Copyright (C) 2021 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_MAX_CHANNEL_COUNT 2ο
Maximum of audio channels supported in audio core.
-
SAC_NO_ARG 0ο
Placeholder to be used in a
sac_processing_ctrlfunction call when no arguments are required.
-
SAC_NODE_PAYLOAD_SIZE_OFFSET 0ο
Position of the audio payload in the audio packet.
-
SAC_NODE_PAYLOAD_SIZE_VAR_SIZE sizeof(uint16_t)ο
Size of the audio payload variable.
-
SAC_PACKET_HEADER_OFFSET (SAC_NODE_PAYLOAD_SIZE_OFFSET + SAC_NODE_PAYLOAD_SIZE_VAR_SIZE)ο
Position of the audio header in the audio packet.
-
SAC_PACKET_DATA_OFFSET (SAC_PACKET_HEADER_OFFSET + sizeof(sac_header_t))ο
Position of the packet data in the audio packet.
-
SAC_MIN_PRODUCER_QUEUE_SIZE 3ο
Minimum queue size to use when initializing a producer audio endpoint.
-
sac_node_get_payload_size(node) (*((uint16_t *)(queue_get_data_ptr(node, SAC_NODE_PAYLOAD_SIZE_OFFSET))))ο
Get the audio payload size in the audio packet.
-
sac_node_set_payload_size(node, payload_size) ((*((uint16_t *)(queue_get_data_ptr(node, SAC_NODE_PAYLOAD_SIZE_OFFSET)))) = (payload_size))ο
Set the audio payload size in the audio packet.
-
sac_node_get_header(node) ((sac_header_t *)(queue_get_data_ptr(node, SAC_PACKET_HEADER_OFFSET)))ο
Get a pointer to the audio header in the audio packet.
-
sac_node_get_data(node) ((uint8_t *)(queue_get_data_ptr(node, SAC_PACKET_DATA_OFFSET)))ο
Get a pointer to the packet data in the audio packet.
-
sac_align_data_size(current_size, type_to_align) (sizeof(type_to_align) - ((current_size) % sizeof(type_to_align)))ο
Return an array size aligned on a specific type.
Typedefs
-
typedef struct sac_pipeline sac_pipeline_tο
Audio Core Pipeline.
-
typedef enum sac_bit_depth sac_bit_depth_tο
Audio Core Bit Depth.
-
typedef enum sac_word_size sac_word_size_tο
Audio Core Word Size.
-
typedef struct sac_header sac_header_tο
Audio Core Header.
-
typedef struct sac_processing_interface sac_processing_interface_tο
Processing Interface.
-
typedef struct sac_processing sac_processing_tο
Audio Core Processing.
-
typedef struct sac_endpoint_interface sac_endpoint_interface_tο
Endpoint Interface.
-
typedef struct sac_mixer_option sac_mixer_option_tο
Add Audio Core Mixerβs specific options when using pipelines to mix packets.
-
typedef struct sac_endpoint_cfg sac_endpoint_cfg_tο
Audio Core Endpoint Configuration.
-
typedef struct sac_endpoint sac_endpoint_tο
Audio Core Endpoint.
-
typedef struct sac_pipeline_cfg sac_pipeline_cfg_tο
Audio Core Pipeline Configuration.
-
typedef struct sac_statistics sac_statistics_tο
Audio Core Statistics.
-
typedef struct sac_fallback_module_cfg sac_fallback_module_cfg_tο
Forward declaration of the fallback module configuration structure.
Enums
-
enum sac_bit_depthο
Audio Core Bit Depth.
Values:
-
enumerator SAC_16BITS = 16ο
16-bit PCM samples.
-
enumerator SAC_18BITS = 18ο
18-bit PCM samples.
-
enumerator SAC_20BITS = 20ο
20-bit PCM samples.
-
enumerator SAC_24BITS = 24ο
24-bit PCM samples.
-
enumerator SAC_32BITS = 32ο
32-bit PCM samples.
-
enumerator SAC_16BITS = 16ο
-
enum sac_word_sizeο
Audio Core Word Size.
Values:
-
enumerator SAC_16BITS_BYTE = 2ο
2-byte word for 16-bit PCM samples.
-
enumerator SAC_18BITS_BYTE = 4ο
4-byte word for 18-bit PCM samples.
-
enumerator SAC_20BITS_BYTE = 4ο
4-byte word for 20-bit PCM samples.
-
enumerator SAC_24BITS_BYTE = 4ο
4-byte word for 24-bit PCM samples.
-
enumerator SAC_32BITS_BYTE = 4ο
4-byte word for 32-bit PCM samples.
-
enumerator SAC_16BITS_BYTE = 2ο
Functions
-
void sac_init(sac_cfg_t cfg, sac_hal_t *hal, sac_error_t *err)ο
Initialize the Audio Core.
- Parameters:
cfg β [in] Audio Core configuration.
hal β [in] Board specific functions.
err β [out] Error code.
-
void sac_mixer_init(sac_mixer_module_cfg_t cfg, sac_error_t *err)ο
Initialize the SAC Mixer Module.
Note
Only call this initialization when the Mixer Module is needed.
- Parameters:
cfg β [in] Configuration of the SAC Mixer Module.
err β [out] Error code.
-
void sac_fallback_init(sac_fallback_module_cfg_t *cfg, sac_error_t *err)ο
Initialize the SAC Fallback Module using the SAC mem_pool.
Note
Only call this initialization when the Fallback Module is needed.
- Parameters:
cfg β [in] Pointer to the configuration of the module.
err β [out] Error code.
-
sac_pipeline_t *sac_pipeline_init(const char *name, sac_endpoint_t *producer, sac_pipeline_cfg_t cfg, sac_endpoint_t *consumer, sac_error_t *err)ο
Initialize a SAC pipeline.
- Parameters:
name β [in] Name of the pipeline.
producer β [in] Producer endpoint.
cfg β [in] Pipeline configuration.
consumer β [in] Consumer endpoint.
err β [out] Error code.
- Returns:
Reference to the initialized SAC pipeline.
-
sac_endpoint_t *sac_endpoint_init(void *instance, const char *name, sac_endpoint_interface_t iface, sac_endpoint_cfg_t cfg, sac_error_t *err)ο
Initialize an Audio Core endpoint.
- Parameters:
instance β [in] Endpoint instance.
name β [in] Name of the endpoint.
iface β [in] Interface of the endpoint.
cfg β [in] Endpoint configuration.
err β [out] Error code.
- Returns:
Reference to the initialized endpoint.
-
void sac_endpoint_link(sac_endpoint_t *consumer, sac_endpoint_t *producer, sac_error_t *err)ο
Link the queue of a consumer endpoint with a producer endpoint.
Note
This feature is used for audio mixing.
- Parameters:
consumer β [in] Consumer endpoint instance to be linked.
producer β [in] Producer endpoint instance to be linked.
err β [out] Error code.
-
sac_processing_t *sac_processing_stage_init(void *instance, const char *name, sac_processing_interface_t iface, sac_error_t *err)ο
Initialize an Audio Core processing stage.
- Parameters:
instance β [in] Processing stage instance.
name β [in] Name of the processing stage.
iface β [in] Interface of the processing stage.
err β [out] Error code.
- Returns:
Reference to the initialized processing stage.
-
void sac_pipeline_add_processing(sac_pipeline_t *pipeline, sac_processing_t *process, sac_error_t *err)ο
Add a processing stage to the pipeline.
- Parameters:
pipeline β [in] Pipeline instance.
process β [in] Pointer to processing structure.
err β [out] Error code.
-
void sac_pipeline_add_extra_consumer(sac_pipeline_t *pipeline, sac_endpoint_t *next_consumer, sac_error_t *err)ο
Add an extra consumer endpoint to the pipeline.
- Parameters:
pipeline β [in] Pipeline instance.
next_consumer β [in] Extra consumer endpoint.
err β [out] Error code.
-
void sac_pipeline_add_extra_producer(sac_pipeline_t *pipeline, sac_endpoint_t *next_producer, sac_error_t *err)ο
Add an extra producer endpoint to the pipeline.
Note
This feature is used for Audio Mixing.
- Parameters:
pipeline β [in] Pipeline instance.
next_producer β [in] Extra producer endpoint.
err β [out] Error code.
-
void sac_pipeline_add_input_pipeline(sac_pipeline_t *pipeline, sac_pipeline_t *input_pipeline, sac_error_t *err)ο
Add an input pipeline to a pipeline doing audio mixing.
- Parameters:
pipeline β [in] Pipeline instance.
input_pipeline β [in] Input pipeline instance.
err β [out] Error code.
-
void sac_pipeline_setup(sac_pipeline_t *pipeline, sac_error_t *err)ο
Setup the Audio Core pipeline.
This makes the pipeline ready to use. It must be called last, after every other initialization functions.
- Parameters:
pipeline β [in] Pipeline instance.
err β [out] Error code.
-
void sac_pipeline_start(sac_pipeline_t *pipeline, sac_error_t *err)ο
Start the Audio Core pipeline.
- Parameters:
pipeline β [in] Pipeline instance.
err β [out] Error code.
-
void sac_pipeline_stop(sac_pipeline_t *pipeline, sac_error_t *err)ο
Stop the Audio Core pipeline.
- Parameters:
pipeline β [in] Pipeline instance.
err β [out] Error code.
-
uint32_t sac_processing_ctrl(sac_processing_t *sac_processing, sac_pipeline_t *pipeline, uint8_t cmd, uint32_t arg, sac_error_t *err)ο
Execute process specific control.
- Parameters:
sac_processing β SAC processing structure.
pipeline β [in] Pipeline instance.
cmd β [in] Command specific to the processing stage.
arg β [in] Argument specific to the processing stage.
err β [out] Error code.
- Returns:
A value specific to the control function.
-
void sac_pipeline_process(sac_pipeline_t *pipeline, sac_error_t *err)ο
Execute the Audio Core processing stages.
- Parameters:
pipeline β [in] Pipeline instance.
err β [out] Error code.
-
void sac_pipeline_produce(sac_pipeline_t *pipeline, sac_error_t *err)ο
Execute the produce endpoint.
- Parameters:
pipeline β [in] Pipeline instance.
err β [out] Error code.
-
void sac_pipeline_consume(sac_pipeline_t *pipeline, sac_error_t *err)ο
Execute the consumer endpoint(s).
- Parameters:
pipeline β [in] Pipeline instance.
err β [out] Error code.
-
void sac_pipeline_consume_all(sac_pipeline_t *pipeline, sac_error_t *err)ο
Execute all the consume endpoints that contain data in their queue.
- Parameters:
pipeline β [in] Pipeline instance.
err β [out] Error code.
-
uint32_t sac_get_allocated_bytes(void)ο
Get the number of bytes allocated in the memory pool.
- Returns:
Number of bytes allocated in the memory pool.
-
struct sac_cfgο
- #include <sac_api.h>
Audio Core Configuration.
-
struct sac_halο
- #include <sac_api.h>
Audio Core Hardware Abstraction Layer.
-
struct sac_headerο
- #include <sac_api.h>
Audio Core Header.
Public Members
-
uint8_t tx_queue_level_highο
For clock drift compensation. Used by the recorder to notify the player that its TX audio buffer is filling up.
-
uint8_t fallbackο
Indicates a fallback packet.
-
uint8_t reservedο
Reserved for future use.
-
uint8_t crc4ο
CRC4 of the header.
-
uint8_t payload_sizeο
Size of the payload (audio samples) expressed in bytes.
-
uint8_t tx_queue_level_highο
-
struct sac_processing_interfaceο
- #include <sac_api.h>
Processing Interface.
Public Members
-
void (*init)(void *instance, sac_pipeline_t *pipeline, mem_pool_t *mem_pool, sac_error_t *err)ο
Function the audio core uses to execute any processing stage initialization sequence.
-
uint32_t (*ctrl)(void *instance, sac_pipeline_t *pipeline, uint8_t cmd, uint32_t args, sac_error_t *err)ο
Function the audio application uses to interact with the processing stage.
-
uint16_t (*process)(void *instance, sac_pipeline_t *pipeline, sac_header_t *header, uint8_t *data_in, uint16_t size, uint8_t *data_out, sac_error_t *err)ο
Function the audio core uses to do processing on audio samples.
-
bool (*gate)(void *instance, sac_pipeline_t *pipeline, sac_header_t *header, uint8_t *data_in, uint16_t size, sac_error_t *err)ο
Function called by process_samples prior to process to determine if process will be executed or not.
-
void (*init)(void *instance, sac_pipeline_t *pipeline, mem_pool_t *mem_pool, sac_error_t *err)ο
-
struct sac_processingο
- #include <sac_api.h>
Audio Core Processing.
Public Members
-
void *instanceο
Pointer to the processing stageβs specific instance.
-
const char *nameο
Character string describing the processing stage.
-
sac_processing_interface_t ifaceο
Interface the processing stage must comply to.
-
struct sac_processing *next_processο
Pointer to the next processing state.
-
void *instanceο
-
struct sac_endpoint_interfaceο
- #include <sac_api.h>
Endpoint Interface.
Public Members
-
uint16_t (*action)(void *instance, uint8_t *samples, uint16_t size)ο
Function the audio core uses to send or receive audio samples depending if the endpoint produces or consumes.
-
void (*start)(void *instance)ο
Function the audio core uses to execute any endpoint startup sequence.
-
void (*stop)(void *instance)ο
Function the audio core uses to stop any endpoint operations.
-
uint16_t (*action)(void *instance, uint8_t *samples, uint16_t size)ο
-
struct sac_mixer_optionο
- #include <sac_api.h>
Add Audio Core Mixerβs specific options when using pipelines to mix packets.
-
struct sac_endpoint_cfgο
- #include <sac_api.h>
Audio Core Endpoint Configuration.
Public Members
-
bool use_encapsulationο
True if the endpoint produces or consumes audio packets (SAC header + audio payload), False for only audio payloads (audio samples).
-
bool delayed_actionο
True if the endpoint requires a complete cycle to produce or consume data. False if the endpoint produces or consumes instantly.
-
uint8_t channel_countο
1 if the endpoint produces or consumes mono audio payloads and 2 for interleaved stereo.
-
sac_bit_depth_t bit_depthο
Bit depth of samples the endpoint produces or consumes.
-
uint16_t audio_payload_sizeο
Size in bytes of the audio payload.
-
uint8_t queue_sizeο
Size in number of audio packets the endpointβs queue can contain.
-
bool use_encapsulationο
-
struct sac_endpointο
- #include <sac_api.h>
Audio Core Endpoint.
Public Members
-
void *instanceο
Pointer to endpointβs specific instance.
-
const char *nameο
Character string describing the endpoint.
-
sac_endpoint_interface_t ifaceο
Interface the endpoint must comply to.
-
sac_endpoint_cfg_t cfgο
SAC endpoint configuration.
-
struct sac_endpoint *next_endpointο
Pointer to the next endpoint.
-
queue_t *queueο
Internal: queue the endpoint will use to store or retrieve audio packets.
-
queue_t *free_queueο
Internal: Pointer to the free queue the endpoint will retrieve free nodes from.
-
queue_node_t *current_nodeο
Internal: pointer to the queue node the endpoint is working with at the moment.
-
bool buffering_completeο
Internal: Whether or not the initial audio buffering has been completed.
-
struct sac_endpoint::[anonymous] _internalο
-
void *instanceο
-
struct sac_pipeline_cfgο
- #include <sac_api.h>
Audio Core Pipeline Configuration.
Public Members
-
bool cdc_enableο
Set to true if an audio clock drift compensation processing stage will be added to this pipeline.
-
bool do_initial_bufferingο
Wait for the consumer queue (TX audio buffer) to be full before starting to consume.
-
sac_mixer_option_t mixer_optionο
Configure the pipeline with mixerβs specific options.
-
bool cdc_enableο
-
struct sac_statisticsο
- #include <sac_api.h>
Audio Core Statistics.
Public Members
-
uint32_t producer_buffer_loadο
Number of audio packets currently in the producer queue.
-
uint16_t producer_buffer_sizeο
Maximum number of audio packets the producer queue can hold.
-
uint32_t producer_buffer_overflow_countο
Number of times the producer queue has overflowed.
-
uint32_t producer_packets_corrupted_countο
Number of corrupted packets received from the coord.
-
uint32_t consumer_buffer_loadο
Number of audio packets currently in the consumer queue.
-
uint16_t consumer_buffer_sizeο
Maximum number of audio packets the consumer queue can hold.
-
uint32_t consumer_buffer_overflow_countο
Number of times the consumer queue has overflowed.
-
uint32_t consumer_buffer_underflow_countο
Number of times the consumer queue has underflowed.
-
uint32_t consumer_queue_peak_buffer_loadο
Consumer queue peak load.
-
uint32_t consumer_link_margin_min_peakο
Consumer link margin min.
-
uint32_t consumer_cca_fail_count_peakο
Consumer CCA count peak.
-
uint32_t cdc_inflated_packets_countο
Number of packets inflated by the CDC.
-
uint32_t cdc_deflated_packets_countο
Number of packets deflated by the CDC.
-
uint32_t producer_buffer_loadο
-
struct sac_pipelineο
- #include <sac_api.h>
Audio Core Pipeline.
Public Members
-
const char *nameο
Name of the pipeline.
-
sac_pipeline_t *input_pipeline[MAX_NB_OF_INPUTS]ο
Pipeline inputting audio samples when doing audio mixing.
-
sac_endpoint_t *producerο
Pointer to the SAC endpoint that will produce audio samples to this SAC pipeline.
-
sac_processing_t *processο
List of processing stages that will sequentially be produced samples before they are consumed.
-
sac_endpoint_t *consumerο
Pointer to the SAC endpoint that will consume audio samples from this SAC pipeline.
-
sac_pipeline_cfg_t cfgο
SAC pipeline configuration.
-
sac_statistics_t _statisticsο
SAC pipeline statistics.
-
uint8_t buffering_thresholdο
Internal: The number of audio packets to buffer before considering the initial buffering complete.
-
uint32_t samples_buffered_sizeο
Internal: Size in bytes of samples produced but not yet consumed.
-
struct sac_pipeline::[anonymous] _internalο
-
const char *nameο