1 /*
2  * Copyright (C) 2015-2020 Alibaba Group Holding Limited
3  */
4 
5 #ifndef __UVOICE_AUDIO_H__
6 #define __UVOICE_AUDIO_H__
7 
8 
9 #define VOLUME_LEVEL_MIN    0
10 #define VOLUME_LEVEL_MAX    10
11 
12 typedef enum {
13     SND_DEVICE_NONE = 0,
14     SND_DEVICE_MIN = SND_DEVICE_NONE,
15     SND_DEVICE_OUT_BEGIN,
16     SND_DEVICE_OUT_SPEAKER = SND_DEVICE_OUT_BEGIN,
17     SND_DEVICE_OUT_HEADPHONE,
18     SND_DEVICE_OUT_RECEIVER,
19     SND_DEVICE_OUT_HEADSET,
20     SND_DEVICE_OUT_SPEAKER_AND_HEADPHONE,
21     SND_DEVICE_OUT_SPEAKER_AND_HEADSET,
22     SND_DEVICE_OUT_RECEIVER_AND_HEADPHONE,
23     SND_DEVICE_OUT_RECEIVER_AND_HEADSET,
24     SND_DEVICE_OUT_END = SND_DEVICE_OUT_RECEIVER_AND_HEADSET,
25     SND_DEVICE_IN_BEGIN,
26     SND_DEVICE_IN_PRIMARY_MIC = SND_DEVICE_IN_BEGIN,
27     SND_DEVICE_IN_SECONDARY_MIC,
28     SND_DEVICE_IN_TERTIARY_MIC,
29     SND_DEVICE_IN_QUATERNARY_MIC,
30     SND_DEVICE_IN_QUINARY_MIC,
31     SND_DEVICE_IN_HEADSET_MIC,
32     SND_DEVICE_IN_END = SND_DEVICE_IN_HEADSET_MIC,
33     SND_DEVICE_MAX = SND_DEVICE_IN_END,
34 } snd_device_t;
35 
36 typedef enum {
37     PCM_MSG_TX_WAITING = 0,
38     PCM_MSG_RX_WAITING,
39     PCM_MSG_WRITE_DONE, /* write buffer copied */
40     PCM_MSG_READ_DONE, /* read buffer filled */
41     PCM_MSG_TX_UNDERRUN,
42     PCM_MSG_TX_OVERRUN,
43     PCM_MSG_RX_UNDERRUN,
44     PCM_MSG_RX_OVERRUN,
45 } pcm_message_t;
46 
47 enum {
48     PCM_STATE_CLOSED = 0,
49     PCM_STATE_SETUP,
50     PCM_STATE_OPEN,
51     PCM_STATE_RUNNING,
52     PCM_STATE_STANDBY,
53 };
54 
55 #ifdef UVOICE_ON_XR871
56 #include "audio/pcm/audio_pcm.h"
57 #include "audio/manager/audio_manager.h"
58 #else
59 #define PCM_OUT        0
60 #define PCM_IN        1
61 
62 enum pcm_format {
63     PCM_FORMAT_INVALID = -1,
64     PCM_FORMAT_S16_LE = 0,  /* 16-bit signed */
65     PCM_FORMAT_S32_LE,      /* 32-bit signed */
66     PCM_FORMAT_S8,          /* 8-bit signed */
67     PCM_FORMAT_S24_LE,      /* 24-bits in 4-bytes */
68     PCM_FORMAT_S24_3LE,     /* 24-bits in 3-bytes */
69 
70     PCM_FORMAT_MAX,
71 };
72 
73 struct pcm_config {
74     int rate;
75     int channels;
76     int period_size;
77     int period_count;
78     enum pcm_format format;
79 };
80 #endif
81 
82 struct pcm_device {
83     struct pcm_config config;
84     uint8_t dir:1;
85     uint8_t card:2;
86     uint8_t state:3;
87     void *private_data;
88 };
89 
90 struct external_pa_info {
91     int used;
92     int active_high;
93     int pin;
94     int delay_ms;
95 };
96 
97 int audio_pcm_notify(pcm_message_t msg);
98 
99 #ifdef UVOICE_BUILD_RELEASE
100 #define snd_debug(fmt, ...)
101 #define snd_info(fmt, ...)
102 #else
103 #define snd_debug(fmt, ...)        printf(fmt, ##__VA_ARGS__)
104 #define snd_info(fmt, ...)        printf(fmt, ##__VA_ARGS__)
105 #endif
106 #define snd_warn(fmt, ...)        printf(fmt, ##__VA_ARGS__)
107 #define snd_err(fmt, ...)        printf(fmt, ##__VA_ARGS__)
108 
109 
110 #endif /* __UVOICE_AUDIO_H__ */
111