MT7687 API Reference  LinkIt SDK v4
hal_audio.h
1 /* Copyright Statement:
2  *
3  * (C) 2005-2016 MediaTek Inc. All rights reserved.
4  *
5  * This software/firmware and related documentation ("MediaTek Software") are
6  * protected under relevant copyright laws. The information contained herein
7  * is confidential and proprietary to MediaTek Inc. ("MediaTek") and/or its licensors.
8  * Without the prior written permission of MediaTek and/or its licensors,
9  * any reproduction, modification, use or disclosure of MediaTek Software,
10  * and information contained herein, in whole or in part, shall be strictly prohibited.
11  * You may only use, reproduce, modify, or distribute (as applicable) MediaTek Software
12  * if you have agreed to and been bound by the applicable license agreement with
13  * MediaTek ("License Agreement") and been granted explicit permission to do so within
14  * the License Agreement ("Permitted User"). If you are not a Permitted User,
15  * please cease any access or use of MediaTek Software immediately.
16  * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
17  * THAT MEDIATEK SOFTWARE RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES
18  * ARE PROVIDED TO RECEIVER ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL
19  * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
21  * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
22  * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
23  * SUPPLIED WITH MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
24  * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
25  * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
26  * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
27  * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
28  * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
29  * CUMULATIVE LIABILITY WITH RESPECT TO MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
30  * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE MEDIATEK SOFTWARE AT ISSUE,
31  * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
32  * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
33  */
34 
35 #ifndef __HAL_AUDIO_H__
36 #define __HAL_AUDIO_H__
37 #include "hal_platform.h"
38 
39 #ifdef HAL_AUDIO_MODULE_ENABLED
40 
181 #include <stdio.h>
182 #include <stdint.h>
183 #include <stdbool.h>
184 
185 #ifdef __cplusplus
186 extern "C" {
187 #endif
188 
189 
195 typedef enum {
196  HAL_AUDIO_STATUS_INVALID_PARAMETER = -2,
197  HAL_AUDIO_STATUS_ERROR = -1,
198  HAL_AUDIO_STATUS_OK = 0
199 } hal_audio_status_t;
200 
202 typedef enum {
203  HAL_AUDIO_EVENT_ERROR = -1,
204  HAL_AUDIO_EVENT_NONE = 0,
205  HAL_AUDIO_EVENT_UNDERFLOW = 1,
206  HAL_AUDIO_EVENT_DATA_REQUEST = 2,
207  HAL_AUDIO_EVENT_DATA_NOTIFICATION = 3
208 } hal_audio_event_t;
209 
211 typedef enum {
212  HAL_AUDIO_DEVICE_NONE = 0x0000,
213  HAL_AUDIO_DEVICE_MAIN_MIC = 0x0001,
214  HAL_AUDIO_DEVICE_HEADSET_MIC = 0x0002,
215  HAL_AUDIO_DEVICE_HANDSET = 0x0004,
216  HAL_AUDIO_DEVICE_HANDS_FREE_MONO = 0x0008,
217  HAL_AUDIO_DEVICE_HANDS_FREE_STEREO = 0x0010,
218  HAL_AUDIO_DEVICE_HEADSET = 0x0020,
219  HAL_AUDIO_DEVICE_HEADSET_MONO = 0x0040,
220  HAL_AUDIO_DEVICE_LINE_IN = 0x0080,
221  HAL_AUDIO_DEVICE_DUAL_DIGITAL_MIC = 0x0100,
222  HAL_AUDIO_DEVICE_SINGLE_DIGITAL_MIC = 0x0200
223 } hal_audio_device_t;
224 
226 typedef enum {
227  HAL_AUDIO_MUTE_MAIN_MIC = 0x0001,
228  HAL_AUDIO_MUTE_EAR_MIC = 0x0002,
229  HAL_AUDIO_MUTE_HANDSET = 0x0004,
230  HAL_AUDIO_MUTE_HANDS_FREE = 0x0008,
231  HAL_AUDIO_MUTE_HEADSET = 0x0010,
232  HAL_AUDIO_MUTE_LINE_IN = 0x0020
233 } hal_audio_mute_t;
234 
236 typedef enum {
237  HAL_AUDIO_MUTE_FUNCTION_NONE = 0,
238  HAL_AUDIO_MUTE_FUNCTION_PCM = 1
239 } hal_audio_mute_function_t;
240 
242 typedef enum {
243  HAL_AUDIO_SAMPLING_RATE_8KHZ = 0,
244  HAL_AUDIO_SAMPLING_RATE_11_025KHZ = 1,
245  HAL_AUDIO_SAMPLING_RATE_12KHZ = 2,
246  HAL_AUDIO_SAMPLING_RATE_16KHZ = 3,
247  HAL_AUDIO_SAMPLING_RATE_22_05KHZ = 4,
248  HAL_AUDIO_SAMPLING_RATE_24KHZ = 5,
249  HAL_AUDIO_SAMPLING_RATE_32KHZ = 6,
250  HAL_AUDIO_SAMPLING_RATE_44_1KHZ = 7,
251  HAL_AUDIO_SAMPLING_RATE_48KHZ = 8,
252  HAL_AUDIO_SAMPLING_RATE_96KHZ = 9
253 } hal_audio_sampling_rate_t;
254 
256 typedef enum {
257  HAL_AUDIO_BITS_PER_SAMPLING_16 = 0,
258  HAL_AUDIO_BITS_PER_SAMPLING_24 = 1
259 } hal_audio_bits_per_sample_t;
260 
262 typedef enum {
263  HAL_AUDIO_MONO = 0,
264  HAL_AUDIO_STEREO = 1,
265  HAL_AUDIO_STEREO_BOTH_L_CHANNEL = 2,
266  HAL_AUDIO_STEREO_BOTH_R_CHANNEL = 3
267 } hal_audio_channel_number_t;
268 
270 typedef enum {
271  HAL_AUDIO_PLAYBACK_MUSIC = 0,
272  HAL_AUDIO_PLAYBACK_VOICE = 1,
273  HAL_AUDIO_RECORD_VOICE = 2,
274  HAL_AUDIO_TWO_WAY_VOICE = 3,
275  HAL_AUDIO_PLAYBACK_MUSIC_RECORD_VOICE = 4
276 } hal_audio_active_type_t;
277 
278 
288 typedef struct {
289  hal_audio_sampling_rate_t stream_sampling_rate;
290  hal_audio_bits_per_sample_t stream_bit_rate;
291  hal_audio_channel_number_t stream_channel;
292  hal_audio_device_t audio_device;
293  uint32_t digital_gain_index;
294  uint32_t analog_gain_index;
295 } hal_audio_stream_mode_t;
296 
298 typedef struct {
299  hal_audio_stream_mode_t stream_in;
300  hal_audio_stream_mode_t stream_out;
301  hal_audio_active_type_t audio_path_type;
302  hal_audio_mute_t mute_device;
303  bool loopback;
304 } hal_audio_stream_t;
305 
306 
321 typedef void (*hal_audio_stream_out_callback_t)(hal_audio_event_t event, void *user_data);
322 
329 typedef void (*hal_audio_stream_in_callback_t)(hal_audio_event_t event, void *user_data);
330 
341 hal_audio_status_t hal_audio_init(void);
342 
348 hal_audio_status_t hal_audio_deinit(void);
349 
357 hal_audio_status_t hal_audio_set_stream_out_sampling_rate(hal_audio_sampling_rate_t sample_rate);
358 
364 hal_audio_status_t hal_audio_set_stream_out_channel_number(hal_audio_channel_number_t channel_number);
365 
372 hal_audio_status_t hal_audio_start_stream_out(hal_audio_active_type_t active_type);
373 
378 void hal_audio_stop_stream_out(void);
379 
386 hal_audio_status_t hal_audio_set_stream_out_volume(uint32_t digital_volume_index, uint32_t analog_volume_index);
387 
395 void hal_audio_mute_stream_out(bool mute);
396 
402 hal_audio_status_t hal_audio_set_stream_out_device(hal_audio_device_t device);
403 
411 hal_audio_status_t hal_audio_write_stream_out(const void *buffer, uint32_t size);
412 
420 hal_audio_status_t hal_audio_get_stream_out_sample_count(uint32_t *sample_count);
421 
428 hal_audio_status_t hal_audio_register_stream_out_callback(hal_audio_stream_out_callback_t callback, void *user_data);
429 
439 hal_audio_status_t hal_audio_set_stream_in_sampling_rate(hal_audio_sampling_rate_t sample_rate);
440 
449 hal_audio_status_t hal_audio_set_stream_in_channel_number(hal_audio_channel_number_t channel_number);
450 
460 hal_audio_status_t hal_audio_start_stream_in(hal_audio_active_type_t active_type);
461 
469 void hal_audio_stop_stream_in(void);
470 
477 hal_audio_status_t hal_audio_set_stream_in_volume(uint32_t digital_volume_index, uint32_t analog_volume_index);
478 
486 void hal_audio_mute_stream_in(bool mute);
487 
496 hal_audio_status_t hal_audio_set_stream_in_device(hal_audio_device_t device);
497 
505 hal_audio_status_t hal_audio_read_stream_in(void *buffer, uint32_t sample_count);
506 
514 hal_audio_status_t hal_audio_get_stream_in_sample_count(uint32_t *sample_count);
515 
525 hal_audio_status_t hal_audio_register_stream_in_callback(hal_audio_stream_in_callback_t callback, void *user_data);
526 
534 hal_audio_status_t hal_audio_get_memory_size(uint32_t *memory_size);
535 
543 hal_audio_status_t hal_audio_set_memory(void *memory);
544 
551 hal_audio_status_t hal_audio_get_audio_clock(uint32_t *sample_count);
552 
553 #ifdef __cplusplus
554 }
555 #endif
556 
561 #endif /*HAL_AUDIO_MODULE_ENABLED*/
562 #endif /*__HAL_AUDIO_H__*/