123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 |
- /*
- * Copyright (c) 2020, Actions Semi Co., Inc.
- *
- * SPDX-License-Identifier: Apache-2.0
- */
- /**
- * @file Audio processor interface
- */
- #ifndef __AUDIO_PROCESSOR_H__
- #define __AUDIO_PROCESSOR_H__
- #include <zephyr.h>
- #include <acts_ringbuf.h>
- /**
- * @brief Audio processor APIs
- * @defgroup audio_processor_apis Audio Processor APIs
- * @ingroup media_system_apis
- * @{
- */
- #ifdef __cplusplus
- extern "C" {
- #endif
- #define MAKE_AUDIO_PROCESSOR_MODULE_ID(A, B, C, D) \
- (((uint32_t)(A) << 24) | ((uint32_t)(B) << 16) | ((uint32_t)(C) << 8) | (D))
- #define MAKE_AUDIO_PROCESSOR_VERSION(major, minor, patchlevel) \
- (((uint32_t)((major) && 0xFF) << 24) | ((uint32_t)((minor) && 0xFF) << 16) | ((uint32_t)((patchlevel) && 0xFF) << 8))
- #define AUDIO_PROCESSOR_VER_MAJOR(ver) ((ver >> 24) & 0xFF)
- #define AUDIO_PROCESSOR_VER_MINOR(ver) ((ver >> 16) & 0xFF)
- #define AUDIO_PROCESSOR_VER_PATCHLEVEL(ver) ((ver >> 8) & 0xFF)
- #define MAX_AUDIO_CHANNELS (2)
- typedef enum {
- BTCALL_PREPROCESSOR_MODULE_ID = MAKE_AUDIO_PROCESSOR_MODULE_ID('B', 'T', 'C', 'R'),
- BTCALL_POSTPROCESSOR_MODULE_ID = MAKE_AUDIO_PROCESSOR_MODULE_ID('B', 'T', 'C', 'O'),
- MUSIC_POSTPROCESSOR_MODULE_ID = MAKE_AUDIO_PROCESSOR_MODULE_ID('M', 'U', 'S', 'O'),
- } audio_processor_module_id_e;
- /** audio preprocessor init param */
- typedef struct audio_preprocessor_init_param {
- /* audio_stream_type_e, see audio_system.h */
- uint8_t stream_type; /* stream type of the media */
- uint8_t stream_effect; /* stream type of the effect applied on the media */
- uint8_t sample_rate; /* kHz */
- uint8_t sample_bits; /* bits per sample, 16/24/32 */
- uint8_t frac_bits; /* fractional bits, 0 for integral samples */
- uint8_t channels; /* channels of in/output pcms */
- uint8_t format; /* media_type_e */
- /* input pcm, separated channels */
- struct acts_ringbuf *inbufs[MAX_AUDIO_CHANNELS];
- /* input ref pcm as required, single channel in most cases */
- struct acts_ringbuf *refbuf;
- /* output pcm, separated channels */
- struct acts_ringbuf *outbufs[MAX_AUDIO_CHANNELS];
- /* processor specific params */
- void *ext_param;
- } audio_preprocessor_init_param_t;
- /** audio postprocessor init param */
- typedef struct audio_postprocessor_init_param {
- /* audio_stream_type_e, see audio_system.h */
- uint8_t stream_type; /* stream type of the media */
- uint8_t stream_effect; /* stream type of the effect applied on the media */
- uint8_t sample_rate; /* kHz */
- uint8_t sample_bits; /* bits per sample, 16/24/32 */
- uint8_t frac_bits; /* fractional bits, 0 for integral samples */
- uint8_t channels; /* channels of in/output pcm */
- uint8_t format; /* media_type_e */
- /* input pcm, separated channels */
- struct acts_ringbuf *inbufs[MAX_AUDIO_CHANNELS];
- /* output ref pcm as required, single channel in most cases */
- struct acts_ringbuf *refbuf;
- /* output pcm, interweaved channels */
- struct acts_ringbuf *outbuf;
- /* processor specific params */
- void *ext_param;
- } audio_postprocessor_init_param_t;
- struct audio_processor_module;
- typedef struct audio_processor {
- const struct audio_processor_module *module;
- void *priv; /* private data */
- } audio_processor_t;
- /** audio pre/postprocessor module */
- typedef struct audio_processor_module {
- /** Identifier of module */
- uint32_t id;
- /** Version of the implemented module */
- uint32_t version;
- /** Name of this module */
- const char *name;
- /** Module ops: initialize a processor, return 0 if succeed */
- int (*initialize)(audio_processor_t *handle, void *init_param);
- /** Module ops: destroy a processor, return 0 if succeed */
- int (*destroy)(audio_processor_t *handle);
- /** Module ops: run a processor, return number of sample (pair) successfully processed */
- int (*process)(audio_processor_t *handle);
- /** Module ops: flush a processor, return number of sample (pair) successfully flushed */
- int (*flush)(audio_processor_t *handle);
- /** Module ops: get parameters of a processor, return 0 if succeed */
- int (*get_parameter)(audio_processor_t *handle, int pname, void *param, unsigned int psize);
- /** Module ops: set parameters of a processor, return 0 if succeed */
- int (*set_parameter)(audio_processor_t *handle, int pname, void *param, unsigned int psize);
- /** Module ops: debug a processor, return 0 if succeed */
- int (*dump)(audio_processor_t *handle, int data_tag, struct acts_ringbuf *data_buf);
- /** The following ops are mostly used to send control commands in dsp implemented processors */
- #ifdef CONFIG_DSP
- /** Module ops: enable a processor (may cause re-initialization), return 0 if succeed */
- int (*enable)(audio_processor_t *handle);
- /** Module ops: disable a processor, return 0 if succeed */
- int (*disable)(audio_processor_t *handle);
- /** Module ops: pause a processor, return 0 if succeed */
- int (*pause)(audio_processor_t *handle);
- /** Module ops: resum a processor, return 0 if succeed */
- int (*resume)(audio_processor_t *handle);
- #endif /* CONFIG_DSP */
- } audio_processor_module_t;
- /**
- * @brief Open a audio preprocessor.
- *
- * This routine open a audio preprocessor.
- *
- * @param init_param Address of preprocessor init param
- *
- * @return handle of preprocessor
- */
- void *audio_preprocessor_open(audio_preprocessor_init_param_t *init_param);
- /**
- * @brief Open a audio postprocessor.
- *
- * This routine open a audio postprocessor.
- *
- * @param init_param Address of postprocessor init param
- *
- * @return handle of postprocessor
- */
- void *audio_postprocessor_open(audio_postprocessor_init_param_t *init_param);
- /**
- * @brief Close a audio pre/postprocessor.
- *
- * This routine close a audio pre/postprocessor.
- *
- * @param handle Handle of pre/postprocessor.
- *
- * @return 0 if succeed; non-zero if fail.
- */
- int audio_processor_close(void *handle);
- /**
- * @brief Enable a audio pre/postprocessor.
- *
- * This routine enable a audio pre/postprocessor.
- *
- * @param handle Handle of pre/postprocessor.
- *
- * @return 0 if succeed; non-zero if fail.
- */
- int audio_processor_enable(void *handle);
- /**
- * @brief Disable a audio pre/postprocessor.
- *
- * This routine disable a audio pre/postprocessor.
- *
- * @param handle Handle of pre/postprocessor.
- *
- * @return 0 if succeed; non-zero if fail.
- */
- int audio_processor_disable(void *handle);
- /**
- * @brief Pause a audio pre/postprocessor.
- *
- * This routine pause a audio pre/postprocessor.
- *
- * @param handle Handle of pre/postprocessor.
- *
- * @return 0 if succeed; non-zero if fail.
- */
- int audio_processor_pause(void *handle);
- /**
- * @brief Resume a audio pre/postprocessor.
- *
- * This routine resume a audio pre/postprocessor.
- *
- * @param handle Handle of pre/postprocessor.
- *
- * @return 0 if succeed; non-zero if fail.
- */
- int audio_processor_resume(void *handle);
- /**
- * @brief Run a audio pre/postprocessor to process data.
- *
- * This routine run a audio pre/postprocessor to process data.
- *
- * @param handle Handle of pre/postprocessor.
- *
- * @return number of samples processed.
- */
- int audio_processor_process(void *handle);
- /**
- * @brief Flush the remain data of a audio pre/postprocessor.
- *
- * This routine flush the remain data of a audio pre/postprocessor.
- *
- * @param handle Handle of pre/postprocessor.
- *
- * @return number of samples processed.
- */
- int audio_processor_flush(void *handle);
- /**
- * @brief Get parameter of a audio pre/postprocessor.
- *
- * This routine get parameter of a audio pre/postprocessor.
- *
- * @param handle Handle of pre/postprocessor.
- * @param pname Parameter name.
- * @param param Address of parameter.
- * @param psize Size of parameter.
- *
- * @return 0 if succeed; non-zero if fail.
- */
- int audio_processor_get_parameter(void *handle, int pname, void *param, unsigned int psize);
- /**
- * @brief Set parameter of a audio pre/postprocessor.
- *
- * This routine set parameter of a audio pre/postprocessor.
- *
- * @param handle Handle of pre/postprocessor.
- * @param pname Parameter name.
- * @param param Address of parameter.
- * @param psize Size of parameter.
- *
- * @return 0 if succeed; non-zero if fail.
- */
- int audio_processor_set_parameter(void *handle, int pname, void *param, unsigned int psize);
- /**
- * @brief Dump a audio pre/postprocessor
- *
- * This routine debug a audio pre/postprocessor.
- *
- * @param handle Handle of pre/postprocessor.
- * @param data_tag tag of dumpable data, see enum media_dump_data_tag_e in media_service.h
- * @param data_buf buffer to store dumpable data
- *
- * @return 0 if succeed; non-zero if fail.
- */
- int audio_processor_dump(void *handle, int data_tag, struct acts_ringbuf *data_buf);
- /**
- * @brief Register a audio preprocessor.
- *
- * This routine register a audio preprocessor to process data of specific stream_type.
- *
- * @param module Address of preprocessor module
- * @param stream_type type of audio stream, see audio_stream_type_e.
- *
- * @return 0 if succeed; non-zero if fail.
- */
- int audio_preprocessor_register(audio_processor_module_t *module, uint8_t stream_type);
- /**
- * @brief Unregister a audio preprocessor.
- *
- * This routine unregister a audio preprocessor which process data of specific stream_type.
- *
- * @param module Address of preprocessor module
- * @param stream_type type of audio stream, see audio_stream_type_e.
- *
- * @return 0 if succeed; non-zero if fail.
- */
- int audio_preprocessor_unregister(audio_processor_module_t *module, uint8_t stream_type);
- /**
- * @brief Register a audio postprocessor.
- *
- * This routine register a audio postprocessor to process data of specific stream_type.
- *
- * @param module Address of postprocessor module
- * @param stream_type type of audio stream, see audio_stream_type_e.
- *
- * @return 0 if succeed; non-zero if fail.
- */
- int audio_postprocessor_register(audio_processor_module_t *module, uint8_t stream_type);
- /**
- * @brief Unregister a audio postprocessor.
- *
- * This routine unregister a audio postprocessor which process data of specific stream_type.
- *
- * @param module Address of postprocessor module
- * @param stream_type type of audio stream, see audio_stream_type_e.
- *
- * @return 0 if succeed; non-zero if fail.
- */
- int audio_postprocessor_unregister(audio_processor_module_t *module, uint8_t stream_type);
- #ifdef __cplusplus
- }
- #endif
- /**
- * @}
- */
- #endif /* __AUDIO_PROCESSOR_H__ */
|