204 lines
5.7 KiB
C
204 lines
5.7 KiB
C
|
#ifndef _AUDIO_SCENE_H
|
||
|
#define _AUDIO_SCENE_H
|
||
|
|
||
|
#include <stdint.h>
|
||
|
|
||
|
#include "FreeRTOS.h"
|
||
|
#include "task.h"
|
||
|
|
||
|
#include "audio_common.h"
|
||
|
#include "audio_hw.h"
|
||
|
#include "audio_decoder.h"
|
||
|
#include "audio_encoder.h"
|
||
|
#include "voice_recognize.h"
|
||
|
|
||
|
typedef void (*audio_sence_report_encoded_frame)(void *arg, uint8_t *data, uint16_t length);
|
||
|
|
||
|
typedef enum {
|
||
|
AUDIO_SCENE_TYPE_LOCAL_PLAYBACK,
|
||
|
AUDIO_SCENE_TYPE_A2DP_SOURCE,
|
||
|
AUDIO_SCENE_TYPE_A2DP_SINK,
|
||
|
AUDIO_SCENE_TYPE_SCO,
|
||
|
AUDIO_SCENE_TYPE_TONE,
|
||
|
AUDIO_SCENE_TYPE_RECODER,
|
||
|
AUDIO_SCENE_TYPE_VOICE_RECOGNIZE,
|
||
|
} audio_scene_type_t;
|
||
|
|
||
|
typedef enum {
|
||
|
AUDIO_SCENE_EVT_TYPE_CREATE,
|
||
|
AUDIO_SCENE_EVT_TYPE_DESTROY,
|
||
|
AUDIO_SCENE_EVT_TYPE_RECV_RAW_DATA,
|
||
|
AUDIO_SCENE_EVT_TYPE_REQ_RAW_DATA,
|
||
|
AUDIO_SCENE_EVT_TYPE_DECODER_ADD,
|
||
|
AUDIO_SCENE_EVT_TYPE_DECODER_REMOVE,
|
||
|
AUDIO_SCENE_EVT_TYPE_TONE_ADD,
|
||
|
AUDIO_SCENE_EVT_TYPE_TONE_REMOVE,
|
||
|
AUDIO_SCENE_EVT_TYPE_DO_ENCODE,
|
||
|
AUDIO_SCENE_EVT_TYPE_ADC_NEW_SAMPLES,
|
||
|
} audio_scene_evt_type_t;
|
||
|
|
||
|
typedef struct {
|
||
|
uint32_t sample_rate;
|
||
|
uint8_t channels;
|
||
|
audio_hw_type_t hw_type;
|
||
|
uint32_t hw_base_addr;
|
||
|
void (*req_dec_cb)(audio_decoder_t *);
|
||
|
} audio_scene_param_local_playback_t;
|
||
|
|
||
|
typedef struct {
|
||
|
uint32_t sample_rate;
|
||
|
uint8_t channels;
|
||
|
audio_type_t audio_type;
|
||
|
audio_hw_type_t hw_type;
|
||
|
uint32_t hw_base_addr;
|
||
|
void (*req_dec_cb)(audio_decoder_t *);
|
||
|
} audio_scene_param_a2dp_sink_t;
|
||
|
|
||
|
typedef struct {
|
||
|
uint32_t sample_rate;
|
||
|
uint8_t channels;
|
||
|
audio_type_t audio_type;
|
||
|
void (*req_dec_cb)(audio_decoder_t *);
|
||
|
} audio_scene_param_a2dp_source_t;
|
||
|
|
||
|
typedef struct {
|
||
|
audio_type_t audio_type;
|
||
|
audio_hw_type_t hw_type;
|
||
|
uint32_t sample_rate;
|
||
|
uint32_t hw_base_addr;
|
||
|
void (*req_dec_cb)(audio_decoder_t *);
|
||
|
audio_sence_report_encoded_frame report_enc_cb;
|
||
|
void *report_enc_arg;
|
||
|
} audio_scene_param_sco_t;
|
||
|
|
||
|
typedef struct {
|
||
|
audio_type_t audio_type;
|
||
|
audio_hw_type_t hw_type;
|
||
|
uint32_t hw_base_addr;
|
||
|
void (*req_dec_cb)(audio_decoder_t *);
|
||
|
} audio_scene_param_tone_t;
|
||
|
|
||
|
typedef struct {
|
||
|
audio_scene_type_t type;
|
||
|
|
||
|
union {
|
||
|
audio_scene_param_local_playback_t local_playback;
|
||
|
audio_scene_param_a2dp_sink_t a2dp_sink;
|
||
|
audio_scene_param_a2dp_source_t a2dp_source;
|
||
|
audio_scene_param_sco_t sco;
|
||
|
audio_scene_param_voice_recognize_t voice_recognize;
|
||
|
} param;
|
||
|
|
||
|
audio_scene_param_tone_t tone;
|
||
|
} audio_scene_t;
|
||
|
|
||
|
typedef struct {
|
||
|
struct co_list_hdr hdr;
|
||
|
|
||
|
audio_scene_evt_type_t type;
|
||
|
union {
|
||
|
/* used to create, delete scene */
|
||
|
audio_scene_t *scene;
|
||
|
/* used to append raw data */
|
||
|
audio_data_element_t *raw_data;
|
||
|
/* used for remove a decoder or request new data */
|
||
|
audio_decoder_t *decoder;
|
||
|
/* used for encoder */
|
||
|
uint32_t encode_samples;
|
||
|
/* used for tone decoder */
|
||
|
struct {
|
||
|
audio_type_t type;
|
||
|
void (*req_dec_cb)(audio_decoder_t *);
|
||
|
} tone_add;
|
||
|
/* used for sco */
|
||
|
uint32_t adc_new_samples;
|
||
|
} p;
|
||
|
} audio_scene_evt_t;
|
||
|
|
||
|
typedef struct {
|
||
|
audio_decoder_t *decoder;
|
||
|
audio_decoder_output_t *decoder_to_hw;
|
||
|
audio_hw_t *audio_hw;
|
||
|
} local_playback_env_t;
|
||
|
|
||
|
typedef struct {
|
||
|
audio_decoder_t *decoder;
|
||
|
audio_decoder_output_t *decoder_to_hw;
|
||
|
audio_hw_t *audio_hw;
|
||
|
|
||
|
struct co_list a2dp_data_list;
|
||
|
uint32_t a2dp_data_counter;
|
||
|
uint8_t start_thd;
|
||
|
} a2dp_sink_env_t;
|
||
|
|
||
|
typedef struct {
|
||
|
audio_decoder_t *decoder;
|
||
|
audio_decoder_output_t *decoder_to_encoder;
|
||
|
audio_encoder_t *encoder;
|
||
|
|
||
|
uint8_t *buffer;
|
||
|
uint32_t offset; // unit is sample
|
||
|
} a2dp_source_env_t;
|
||
|
|
||
|
typedef struct {
|
||
|
audio_decoder_t *decoder; // for sco data decoder, PLC is included
|
||
|
audio_decoder_output_t *decoder_to_algo; // decoded data routed to algorithm
|
||
|
audio_decoder_output_t *decoder_to_hw; // decoded data routed to DAC
|
||
|
audio_encoder_t *encoder; // for sco data encoder, input data is output of AEC
|
||
|
audio_hw_t *audio_hw;
|
||
|
audio_hw_output_t *audio_hw_output; // used to receive ADC data
|
||
|
void *audio_algo_handle;
|
||
|
|
||
|
struct co_list sco_data_list;
|
||
|
uint16_t sco_data_counter;
|
||
|
uint8_t start_thd;
|
||
|
|
||
|
uint32_t algo_frame_size; // unit is sample
|
||
|
|
||
|
int16_t *decoder_output; // next step is algorithm, size is algo_frame_size
|
||
|
uint32_t decoder_output_wr_ptr; // unit is sample
|
||
|
|
||
|
int16_t *adc_input; // next step is algorithm, size is adc_input_size = N * algo_frame_size
|
||
|
uint32_t adc_input_size; // unit is sample
|
||
|
uint32_t adc_input_wr_ptr; // unit is sample
|
||
|
uint32_t adc_input_rd_ptr; // unit is sample
|
||
|
} sco_env_t;
|
||
|
|
||
|
typedef struct {
|
||
|
audio_decoder_t *decoder;
|
||
|
audio_decoder_output_t *decoder_to_hw;
|
||
|
audio_hw_t *audio_hw;
|
||
|
|
||
|
void (*req_dec_cb)(audio_decoder_t *);
|
||
|
} tone_env_t;
|
||
|
|
||
|
typedef struct {
|
||
|
audio_scene_t *scene;
|
||
|
|
||
|
union {
|
||
|
local_playback_env_t local_playback;
|
||
|
a2dp_sink_env_t a2dp_sink;
|
||
|
a2dp_source_env_t a2dp_source;
|
||
|
sco_env_t sco;
|
||
|
voice_recognize_env_t voice_recognize;
|
||
|
} env;
|
||
|
|
||
|
tone_env_t tone;
|
||
|
|
||
|
TaskHandle_t audio_task_handle;
|
||
|
struct co_list evt_list;
|
||
|
} audio_scene_env_t;
|
||
|
|
||
|
void audio_scene_init(uint32_t stack_size, uint8_t priority);
|
||
|
|
||
|
audio_scene_t *audio_scene_create(audio_scene_type_t type, void *param);
|
||
|
void audio_scene_destroy(audio_scene_t *scene);
|
||
|
|
||
|
/* used for a2dp_sink, sco when received new data frome remote side */
|
||
|
void audio_scene_recv_raw_data(audio_scene_t *scene, bool valid, uint8_t *buffer, uint32_t length);
|
||
|
|
||
|
/* used to check wheter PA can be enabled, eliminate POP noise */
|
||
|
bool audio_scene_dac_is_ready(audio_scene_t *scene);
|
||
|
|
||
|
#endif // _AUDIO_SCENE_H
|