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_END = 4
209 } hal_audio_event_t;
210 
212 typedef enum {
213  HAL_AUDIO_DEVICE_NONE = 0x0000,
214  HAL_AUDIO_DEVICE_MAIN_MIC = 0x0001,
215  HAL_AUDIO_DEVICE_HEADSET_MIC = 0x0002,
216  HAL_AUDIO_DEVICE_HANDSET = 0x0004,
217  HAL_AUDIO_DEVICE_HANDS_FREE_MONO = 0x0008,
218  HAL_AUDIO_DEVICE_HANDS_FREE_STEREO = 0x0010,
219  HAL_AUDIO_DEVICE_HEADSET = 0x0020,
220  HAL_AUDIO_DEVICE_HEADSET_MONO = 0x0040,
221  HAL_AUDIO_DEVICE_LINE_IN = 0x0080,
222  HAL_AUDIO_DEVICE_DUAL_DIGITAL_MIC = 0x0100,
223  HAL_AUDIO_DEVICE_SINGLE_DIGITAL_MIC = 0x0200
224 } hal_audio_device_t;
225 
227 typedef enum {
228  HAL_AUDIO_MUTE_MAIN_MIC = 0x0001,
229  HAL_AUDIO_MUTE_EAR_MIC = 0x0002,
230  HAL_AUDIO_MUTE_HANDSET = 0x0004,
231  HAL_AUDIO_MUTE_HANDS_FREE = 0x0008,
232  HAL_AUDIO_MUTE_HEADSET = 0x0010,
233  HAL_AUDIO_MUTE_LINE_IN = 0x0020
234 } hal_audio_mute_t;
235 
237 typedef enum {
238  HAL_AUDIO_MUTE_FUNCTION_NONE = 0,
239  HAL_AUDIO_MUTE_FUNCTION_PCM = 1
240 } hal_audio_mute_function_t;
241 
243 typedef enum {
244  HAL_AUDIO_SAMPLING_RATE_8KHZ = 0,
245  HAL_AUDIO_SAMPLING_RATE_11_025KHZ = 1,
246  HAL_AUDIO_SAMPLING_RATE_12KHZ = 2,
247  HAL_AUDIO_SAMPLING_RATE_16KHZ = 3,
248  HAL_AUDIO_SAMPLING_RATE_22_05KHZ = 4,
249  HAL_AUDIO_SAMPLING_RATE_24KHZ = 5,
250  HAL_AUDIO_SAMPLING_RATE_32KHZ = 6,
251  HAL_AUDIO_SAMPLING_RATE_44_1KHZ = 7,
252  HAL_AUDIO_SAMPLING_RATE_48KHZ = 8,
253  HAL_AUDIO_SAMPLING_RATE_96KHZ = 9
254 } hal_audio_sampling_rate_t;
255 
257 typedef enum {
258  HAL_AUDIO_BITS_PER_SAMPLING_16 = 0,
259  HAL_AUDIO_BITS_PER_SAMPLING_24 = 1
260 } hal_audio_bits_per_sample_t;
261 
263 typedef enum {
264  HAL_AUDIO_MONO = 0,
265  HAL_AUDIO_STEREO = 1,
266  HAL_AUDIO_STEREO_BOTH_L_CHANNEL = 2,
267  HAL_AUDIO_STEREO_BOTH_R_CHANNEL = 3,
268  HAL_AUDIO_STEREO_BOTH_L_R_SWAP = 4
269 } hal_audio_channel_number_t;
270 
272 typedef enum {
273  HAL_AUDIO_PLAYBACK_MUSIC = 0,
274  HAL_AUDIO_PLAYBACK_VOICE = 1,
275  HAL_AUDIO_RECORD_VOICE = 2,
276  HAL_AUDIO_TWO_WAY_VOICE = 3,
277  HAL_AUDIO_PLAYBACK_MUSIC_RECORD_VOICE = 4
278 } hal_audio_active_type_t;
279 
280 
290 typedef struct {
291  hal_audio_sampling_rate_t stream_sampling_rate;
292  hal_audio_bits_per_sample_t stream_bit_rate;
293  hal_audio_channel_number_t stream_channel;
294  hal_audio_device_t audio_device;
295  uint32_t digital_gain_index;
296  uint32_t analog_gain_index;
297 } hal_audio_stream_mode_t;
298 
300 typedef struct {
301  hal_audio_stream_mode_t stream_in;
302  hal_audio_stream_mode_t stream_out;
303  hal_audio_active_type_t audio_path_type;
304  hal_audio_mute_t mute_device;
305  bool loopback;
306 } hal_audio_stream_t;
307 
308 
310 typedef struct {
311  void* user_data;
312  uint8_t *buffer;
313  uint32_t buffer_size;
314  uint32_t sample_rate;
315  uint32_t channel;
316 } hal_audio_copy_stream_t;
317 
332 typedef void (*hal_audio_stream_out_callback_t)(hal_audio_event_t event, void *user_data);
333 
340 typedef void (*hal_audio_stream_in_callback_t)(hal_audio_event_t event, void *user_data);
341 
348 typedef void (*hal_audio_stream_copy_callback_t)(hal_audio_event_t event, hal_audio_copy_stream_t *user_data);
349 
360 hal_audio_status_t hal_audio_init(void);
361 
367 hal_audio_status_t hal_audio_deinit(void);
368 
375 hal_audio_status_t hal_audio_register_copied_stream_out_callback(hal_audio_stream_copy_callback_t callback, void *user_data);
376 
384 hal_audio_status_t hal_audio_set_stream_out_sampling_rate(hal_audio_sampling_rate_t sample_rate);
385 
391 hal_audio_status_t hal_audio_set_stream_out_channel_number(hal_audio_channel_number_t channel_number);
392 
399 hal_audio_status_t hal_audio_start_stream_out(hal_audio_active_type_t active_type);
400 
405 void hal_audio_stop_stream_out(void);
406 
413 hal_audio_status_t hal_audio_set_stream_out_volume(uint32_t digital_volume_index, uint32_t analog_volume_index);
414 
422 void hal_audio_mute_stream_out(bool mute);
423 
429 hal_audio_status_t hal_audio_set_stream_out_device(hal_audio_device_t device);
430 
438 hal_audio_status_t hal_audio_write_stream_out(const void *buffer, uint32_t size);
439 
447 hal_audio_status_t hal_audio_get_stream_out_sample_count(uint32_t *sample_count);
448 
455 hal_audio_status_t hal_audio_register_stream_out_callback(hal_audio_stream_out_callback_t callback, void *user_data);
456 
466 hal_audio_status_t hal_audio_set_stream_in_sampling_rate(hal_audio_sampling_rate_t sample_rate);
467 
476 hal_audio_status_t hal_audio_set_stream_in_channel_number(hal_audio_channel_number_t channel_number);
477 
487 hal_audio_status_t hal_audio_start_stream_in(hal_audio_active_type_t active_type);
488 
496 void hal_audio_stop_stream_in(void);
497 
504 hal_audio_status_t hal_audio_set_stream_in_volume(uint32_t digital_volume_index, uint32_t analog_volume_index);
505 
513 void hal_audio_mute_stream_in(bool mute);
514 
523 hal_audio_status_t hal_audio_set_stream_in_device(hal_audio_device_t device);
524 
532 hal_audio_status_t hal_audio_read_stream_in(void *buffer, uint32_t sample_count);
533 
541 hal_audio_status_t hal_audio_get_stream_in_sample_count(uint32_t *sample_count);
542 
552 hal_audio_status_t hal_audio_register_stream_in_callback(hal_audio_stream_in_callback_t callback, void *user_data);
553 
561 hal_audio_status_t hal_audio_get_memory_size(uint32_t *memory_size);
562 
570 hal_audio_status_t hal_audio_set_memory(void *memory);
571 
578 hal_audio_status_t hal_audio_get_audio_clock(uint32_t *sample_count);
579 
580 #ifdef __cplusplus
581 }
582 #endif
583 
588 #endif /*HAL_AUDIO_MODULE_ENABLED*/
589 #endif /*__HAL_AUDIO_H__*/