1 /*
2  * Copyright (C) 2015-2020 Alibaba Group Holding Limited
3  */
4 #ifndef AUDIO_FLINGER_H
5 #define AUDIO_FLINGER_H
6 
7 #include "plat_types.h"
8 #include "stdbool.h"
9 #include "hal_aud.h"
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15 typedef uint32_t (*AF_STREAM_HANDLER_T)(uint8_t *buf, uint32_t len);
16 typedef void (*AF_IRQ_NOTIFICATION_T)(enum AUD_STREAM_ID_T id, enum AUD_STREAM_T stream);
17 typedef void (*AF_CODEC_PLAYBACK_POST_HANDLER_T)(uint8_t *buf, uint32_t len, void *cfg);
18 
19 //pingpong machine
20 enum AF_PP_T{
21     PP_PING = 0,
22     PP_PANG = 1
23 };
24 
25 typedef enum  {
26     AF_USER_AI,
27     AF_USER_THIRDPART,
28     AF_USER_AUDIO,
29     AF_USER_SBC,
30     AF_USER_SCO,
31     AF_USER_TEST,
32     AF_USER_NUM
33 } AF_USER_E;
34 
35 struct AF_STREAM_CONFIG_T {
36     enum AUD_BITS_T bits;
37     enum AUD_SAMPRATE_T sample_rate;
38     enum AUD_CHANNEL_NUM_T channel_num;
39     enum AUD_CHANNEL_MAP_T channel_map;
40     enum AUD_STREAM_USE_DEVICE_T device;
41     enum AUD_IO_PATH_T io_path;
42     bool chan_sep_buf;
43     bool i2s_master_clk_wait;
44     uint8_t slot_cycles;
45     uint16_t fs_cycles;
46     AF_STREAM_HANDLER_T handler;
47 
48     uint8_t *data_ptr;
49     uint32_t data_size;
50 
51     //should define type
52     uint8_t vol;
53 };
54 
55 //Should define return status
56 uint32_t af_open(void);
57 void *af_thread_tid_get(void);
58 uint32_t af_stream_open(enum AUD_STREAM_ID_T id, enum AUD_STREAM_T stream, const struct AF_STREAM_CONFIG_T *cfg);
59 uint32_t af_stream_setup(enum AUD_STREAM_ID_T id, enum AUD_STREAM_T stream, const struct AF_STREAM_CONFIG_T *cfg);
60 uint32_t af_stream_mute(enum AUD_STREAM_ID_T id, enum AUD_STREAM_T stream, bool mute);
61 uint32_t af_stream_set_chan_vol(enum AUD_STREAM_ID_T id, enum AUD_STREAM_T stream, enum AUD_CHANNEL_MAP_T ch_map, uint8_t vol);
62 uint32_t af_stream_restore_chan_vol(enum AUD_STREAM_ID_T id, enum AUD_STREAM_T stream);
63 uint32_t af_stream_get_cfg(enum AUD_STREAM_ID_T id, enum AUD_STREAM_T stream, struct AF_STREAM_CONFIG_T **cfg, bool needlock);
64 uint32_t af_stream_start(enum AUD_STREAM_ID_T id, enum AUD_STREAM_T stream);
65 uint32_t af_stream_stop(enum AUD_STREAM_ID_T id, enum AUD_STREAM_T stream);
66 uint32_t af_stream_pause(enum AUD_STREAM_ID_T id, enum AUD_STREAM_T stream);
67 uint32_t af_stream_restart(enum AUD_STREAM_ID_T id, enum AUD_STREAM_T stream);
68 uint32_t af_stream_close(enum AUD_STREAM_ID_T id, enum AUD_STREAM_T stream);
69 uint32_t af_close(void);
70 uint32_t af_stream_get_cur_dma_addr(enum AUD_STREAM_ID_T id, enum AUD_STREAM_T stream);
71 int af_stream_get_cur_dma_pos(enum AUD_STREAM_ID_T id, enum AUD_STREAM_T stream);
72 int af_stream_buffer_error(enum AUD_STREAM_ID_T id, enum AUD_STREAM_T stream);
73 uint32_t af_stream_dma_tc_irq_enable(enum AUD_STREAM_ID_T id, enum AUD_STREAM_T stream);
74 uint32_t af_stream_dma_tc_irq_disable(enum AUD_STREAM_ID_T id, enum AUD_STREAM_T stream);
75 void af_set_irq_notification(AF_IRQ_NOTIFICATION_T notif);
76 
77 void af_lock_thread(void);
78 void af_unlock_thread(void);
79 void af_set_priority(AF_USER_E user, int priority);
80 int af_get_priority(void);
81 int af_get_default_priority(void);
82 void af_reset_priority(void);
83 
84 void af_codec_tune_resample_rate(enum AUD_STREAM_T stream, float ratio);
85 void af_codec_direct_tune_resample_rate(enum AUD_STREAM_T stream, float ratio);
86 void af_codec_tune_both_resample_rate(float ratio);
87 void af_codec_tune_pll(float ratio);
88 void af_codec_tune_xtal(float ratio);
89 void af_codec_tune(enum AUD_STREAM_T stream, float ratio);
90 void af_codec_direct_tune(enum AUD_STREAM_T stream, float ratio);
91 
92 void af_codec_set_perf_test_power(int type);
93 void af_codec_set_noise_reduction(bool enable);
94 void af_codec_swap_output(bool swap);
95 
96 enum AF_CODEC_SYNC_TYPE_T {
97     AF_CODEC_SYNC_TYPE_NONE,
98     AF_CODEC_SYNC_TYPE_GPIO,
99     AF_CODEC_SYNC_TYPE_BT,
100     AF_CODEC_SYNC_TYPE_WIFI,
101 };
102 
103 void af_codec_sync_config(enum AUD_STREAM_T stream, enum AF_CODEC_SYNC_TYPE_T type, bool enable);
104 void af_codec_sync_resample_rate_config(enum AUD_STREAM_T stream, enum AF_CODEC_SYNC_TYPE_T type, bool enable);
105 void af_codec_sync_gain_config(enum AUD_STREAM_T stream, enum AF_CODEC_SYNC_TYPE_T type, bool enable);
106 
107 typedef void (*AF_ANC_HANDLER)(enum AUD_STREAM_T stream, enum AUD_SAMPRATE_T rate, enum AUD_SAMPRATE_T *new_play, enum AUD_SAMPRATE_T *new_cap);
108 
109 int af_anc_open(enum ANC_TYPE_T type, enum AUD_SAMPRATE_T play_rate, enum AUD_SAMPRATE_T capture_rate, AF_ANC_HANDLER handler);
110 int af_anc_close(enum ANC_TYPE_T type);
111 
112 int af_vad_open(const struct AUD_VAD_CONFIG_T *cfg);
113 int af_vad_close(void);
114 int af_vad_start(void);
115 int af_vad_stop(void);
116 uint32_t af_vad_get_data(uint8_t *buf, uint32_t len);
117 
118 void af_dsd_enable(void);
119 void af_dsd_disable(void);
120 
121 typedef void (*AF_CODEC_BT_TRIGGER_CALLBACK)(void);
122 void af_codec_bt_trigger_config(bool en, AF_CODEC_BT_TRIGGER_CALLBACK callback);
123 
124 #ifdef AUDIO_OUTPUT_SW_GAIN
125 #ifndef AUDIO_OUTPUT_SW_LIMITER
126 typedef struct {
127     float coefs_b[3];
128     float coefs_a[3];
129     float history_x[2];
130     float history_y[2];
131 }SW_GAIN_IIR_T;
132 
133 void af_codec_get_current_sw_gain_filter(SW_GAIN_IIR_T *filter);
134 void af_code_sw_gain_sample_24bit(int32_t * sample);
135 void af_code_sw_gain_sample_16bit(int16_t * sample);
136 #endif
137 #endif
138 
139 
140 #ifdef __cplusplus
141 }
142 #endif
143 
144 #endif /* AUDIO_FLINGER_H */
145