added loopback example with adc samples and dac playback
[pcm-lib.git] / source / pcm_lib.h
blobac02914006d5735a3ef0ac13a8d8e2f7b29bdf9b
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License version 2 as
4 * published by the Free Software Foundation.
5 * pcm.c - pcm internal function
6 * <liu090@sina.com>
7 */
9 #ifndef __PCM_LIB_H__
10 #define __PCM_LIB_H__
12 /* #define __LITTLE_ENDIAN */
13 #include "os_utils.h"
15 #include "soc-codec\soc_cfg.h"
17 #define __force
19 #ifdef __LITTLE_ENDIAN
20 #define SNDRV_LITTLE_ENDIAN
21 #else
22 #ifdef __BIG_ENDIAN
23 #define SNDRV_BIG_ENDIAN
24 #else
25 #error "Unsupported endian..."
26 #endif
27 #endif
29 typedef unsigned long snd_pcm_uframes_t;
30 typedef signed long snd_pcm_sframes_t;
32 enum {
33 SNDRV_PCM_STREAM_PLAYBACK = 0,
34 SNDRV_PCM_STREAM_CAPTURE,
35 SNDRV_PCM_STREAM_LAST = SNDRV_PCM_STREAM_CAPTURE,
38 typedef int snd_pcm_state_t;
39 #define /*SNDRV_*/SNDRV_PCM_STATE_OPEN ((__force snd_pcm_state_t) 0) /* stream is open */
40 #define SNDRV_PCM_STATE_SETUP ((__force snd_pcm_state_t) 1) /* stream has a setup */
41 #define SNDRV_PCM_STATE_PREPARED ((__force snd_pcm_state_t) 2) /* stream is ready to start */
42 #define SNDRV_PCM_STATE_RUNNING ((__force snd_pcm_state_t) 3) /* stream is running */
43 #define SNDRV_PCM_STATE_XRUN ((__force snd_pcm_state_t) 4) /* stream reached an xrun */
44 #define SNDRV_PCM_STATE_DRAINING ((__force snd_pcm_state_t) 5) /* stream is draining */
45 #define SNDRV_PCM_STATE_PAUSED ((__force snd_pcm_state_t) 6) /* stream is paused */
46 #define SNDRV_PCM_STATE_SUSPENDED ((__force snd_pcm_state_t) 7) /* hardware is suspended */
47 #define SNDRV_PCM_STATE_DISCONNECTED ((__force snd_pcm_state_t) 8) /* hardware is disconnected */
48 #define SNDRV_PCM_STATE_LAST SNDRV_PCM_STATE_DISCONNECTED
50 typedef int snd_pcm_access_t;
51 #define SNDRV_PCM_ACCESS_INTERLEAVED ((__force snd_pcm_access_t) 0) /* interleaved ,only support this accesse */
52 #define SNDRV_PCM_ACCESS_NONINTERLEAVED ((__force snd_pcm_access_t) 1) /* noninterleaved */
53 #define SNDRV_PCM_ACCESS_COMPLEX ((__force snd_pcm_access_t) 2) /* complex */
54 #define SNDRV_PCM_ACCESS_LAST SNDRV_PCM_ACCESS_COMPLEX
56 /* pcm format */
57 typedef int snd_pcm_format_t;
58 #define SNDRV_PCM_FORMAT_S8 ((__force snd_pcm_format_t) 0)
59 #define SNDRV_PCM_FORMAT_U8 ((__force snd_pcm_format_t) 1)
60 #define SNDRV_PCM_FORMAT_S16_LE ((__force snd_pcm_format_t) 2)
61 #define SNDRV_PCM_FORMAT_S16_BE ((__force snd_pcm_format_t) 3)
62 #define SNDRV_PCM_FORMAT_U16_LE ((__force snd_pcm_format_t) 4)
63 #define SNDRV_PCM_FORMAT_U16_BE ((__force snd_pcm_format_t) 5)
64 #define SNDRV_PCM_FORMAT_S24_LE ((__force snd_pcm_format_t) 6) /* low three bytes */
65 #define SNDRV_PCM_FORMAT_S24_BE ((__force snd_pcm_format_t) 7) /* low three bytes */
66 #define SNDRV_PCM_FORMAT_U24_LE ((__force snd_pcm_format_t) 8) /* low three bytes */
67 #define SNDRV_PCM_FORMAT_U24_BE ((__force snd_pcm_format_t) 9) /* low three bytes */
68 #define SNDRV_PCM_FORMAT_S32_LE ((__force snd_pcm_format_t) 10)
69 #define SNDRV_PCM_FORMAT_S32_BE ((__force snd_pcm_format_t) 11)
70 #define SNDRV_PCM_FORMAT_U32_LE ((__force snd_pcm_format_t) 12)
71 #define SNDRV_PCM_FORMAT_U32_BE ((__force snd_pcm_format_t) 13)
72 #if 0
73 #define SNDRV_PCM_FORMAT_FLOAT_LE ((__force snd_pcm_format_t) 14) /* 4-byte float, IEEE-754 32-bit, range -1.0 to 1.0 */
74 #define SNDRV_PCM_FORMAT_FLOAT_BE ((__force snd_pcm_format_t) 15) /* 4-byte float, IEEE-754 32-bit, range -1.0 to 1.0 */
75 #define SNDRV_PCM_FORMAT_FLOAT64_LE ((__force snd_pcm_format_t) 16) /* 8-byte float, IEEE-754 64-bit, range -1.0 to 1.0 */
76 #define SNDRV_PCM_FORMAT_FLOAT64_BE ((__force snd_pcm_format_t) 17) /* 8-byte float, IEEE-754 64-bit, range -1.0 to 1.0 */
77 #else
78 #define SNDRV_PCM_FORMAT_S24_3LE ((__force snd_pcm_format_t) 14) /* in three bytes */
79 #define SNDRV_PCM_FORMAT_S24_3BE ((__force snd_pcm_format_t) 15) /* in three bytes */
80 #define SNDRV_PCM_FORMAT_U24_3LE ((__force snd_pcm_format_t) 16) /* in three bytes */
81 #define SNDRV_PCM_FORMAT_U24_3BE ((__force snd_pcm_format_t) 17) /* in three bytes */
82 #endif
83 #define SNDRV_PCM_FORMAT_IEC958_SUBFRAME_LE ((__force snd_pcm_format_t) 18) /* IEC-958 subframe, Little Endian */
84 #define SNDRV_PCM_FORMAT_IEC958_SUBFRAME_BE ((__force snd_pcm_format_t) 19) /* IEC-958 subframe, Big Endian */
85 #define SNDRV_PCM_FORMAT_MU_LAW ((__force snd_pcm_format_t) 20)
86 #define SNDRV_PCM_FORMAT_A_LAW ((__force snd_pcm_format_t) 21)
87 #define SNDRV_PCM_FORMAT_IMA_ADPCM ((__force snd_pcm_format_t) 22)
88 #define SNDRV_PCM_FORMAT_MPEG ((__force snd_pcm_format_t) 23)
89 #define SNDRV_PCM_FORMAT_GSM ((__force snd_pcm_format_t) 24)
90 #define SNDRV_PCM_FORMAT_SPECIAL ((__force snd_pcm_format_t) 31)
91 #if 0
92 #define SNDRV_PCM_FORMAT_S24_3LE ((__force snd_pcm_format_t) 32) /* in three bytes */
93 #define SNDRV_PCM_FORMAT_S24_3BE ((__force snd_pcm_format_t) 33) /* in three bytes */
94 #define SNDRV_PCM_FORMAT_U24_3LE ((__force snd_pcm_format_t) 34) /* in three bytes */
95 #define SNDRV_PCM_FORMAT_U24_3BE ((__force snd_pcm_format_t) 35) /* in three bytes */
96 #else
97 #define SNDRV_PCM_FORMAT_FLOAT_LE ((__force snd_pcm_format_t) 32) /* 4-byte float, IEEE-754 32-bit, range -1.0 to 1.0 */
98 #define SNDRV_PCM_FORMAT_FLOAT_BE ((__force snd_pcm_format_t) 33) /* 4-byte float, IEEE-754 32-bit, range -1.0 to 1.0 */
99 #define SNDRV_PCM_FORMAT_FLOAT64_LE ((__force snd_pcm_format_t) 34) /* 8-byte float, IEEE-754 64-bit, range -1.0 to 1.0 */
100 #define SNDRV_PCM_FORMAT_FLOAT64_BE ((__force snd_pcm_format_t) 35) /* 8-byte float, IEEE-754 64-bit, range -1.0 to 1.0 */
101 #endif
102 #define SNDRV_PCM_FORMAT_S20_3LE ((__force snd_pcm_format_t) 36) /* in three bytes */
103 #define SNDRV_PCM_FORMAT_S20_3BE ((__force snd_pcm_format_t) 37) /* in three bytes */
104 #define SNDRV_PCM_FORMAT_U20_3LE ((__force snd_pcm_format_t) 38) /* in three bytes */
105 #define SNDRV_PCM_FORMAT_U20_3BE ((__force snd_pcm_format_t) 39) /* in three bytes */
106 #define SNDRV_PCM_FORMAT_S18_3LE ((__force snd_pcm_format_t) 40) /* in three bytes */
107 #define SNDRV_PCM_FORMAT_S18_3BE ((__force snd_pcm_format_t) 41) /* in three bytes */
108 #define SNDRV_PCM_FORMAT_U18_3LE ((__force snd_pcm_format_t) 42) /* in three bytes */
109 #define SNDRV_PCM_FORMAT_U18_3BE ((__force snd_pcm_format_t) 43) /* in three bytes */
110 #define SNDRV_PCM_FORMAT_G723_24 ((__force snd_pcm_format_t) 44) /* 8 samples in 3 bytes */
111 #define SNDRV_PCM_FORMAT_G723_24_1B ((__force snd_pcm_format_t) 45) /* 1 sample in 1 byte */
112 #define SNDRV_PCM_FORMAT_G723_40 ((__force snd_pcm_format_t) 46) /* 8 Samples in 5 bytes */
113 #define SNDRV_PCM_FORMAT_G723_40_1B ((__force snd_pcm_format_t) 47) /* 1 sample in 1 byte */
114 #ifndef LIMITED_FORMATS
115 #define SNDRV_PCM_FORMAT_LAST SNDRV_PCM_FORMAT_G723_40_1B
116 #else
117 #if 0
118 #define SNDRV_PCM_FORMAT_LAST SNDRV_PCM_FORMAT_U32_BE
119 #else
120 #define SNDRV_PCM_FORMAT_LAST SNDRV_PCM_FORMAT_U24_3BE
121 #endif
122 #endif
124 #ifdef SNDRV_LITTLE_ENDIAN
125 #define SNDRV_PCM_FORMAT_S16 SNDRV_PCM_FORMAT_S16_LE
126 #define SNDRV_PCM_FORMAT_U16 SNDRV_PCM_FORMAT_U16_LE
127 #define SNDRV_PCM_FORMAT_S24 SNDRV_PCM_FORMAT_S24_LE
128 #define SNDRV_PCM_FORMAT_U24 SNDRV_PCM_FORMAT_U24_LE
129 #define SNDRV_PCM_FORMAT_S32 SNDRV_PCM_FORMAT_S32_LE
130 #define SNDRV_PCM_FORMAT_U32 SNDRV_PCM_FORMAT_U32_LE
131 #define SNDRV_PCM_FORMAT_FLOAT SNDRV_PCM_FORMAT_FLOAT_LE
132 #define SNDRV_PCM_FORMAT_FLOAT64 SNDRV_PCM_FORMAT_FLOAT64_LE
133 #define SNDRV_PCM_FORMAT_IEC958_SUBFRAME SNDRV_PCM_FORMAT_IEC958_SUBFRAME_LE
134 #endif
135 #ifdef SNDRV_BIG_ENDIAN
136 #define SNDRV_PCM_FORMAT_S16 SNDRV_PCM_FORMAT_S16_BE
137 #define SNDRV_PCM_FORMAT_U16 SNDRV_PCM_FORMAT_U16_BE
138 #define SNDRV_PCM_FORMAT_S24 SNDRV_PCM_FORMAT_S24_BE
139 #define SNDRV_PCM_FORMAT_U24 SNDRV_PCM_FORMAT_U24_BE
140 #define SNDRV_PCM_FORMAT_S32 SNDRV_PCM_FORMAT_S32_BE
141 #define SNDRV_PCM_FORMAT_U32 SNDRV_PCM_FORMAT_U32_BE
142 #define SNDRV_PCM_FORMAT_FLOAT SNDRV_PCM_FORMAT_FLOAT_BE
143 #define SNDRV_PCM_FORMAT_FLOAT64 SNDRV_PCM_FORMAT_FLOAT64_BE
144 #define SNDRV_PCM_FORMAT_IEC958_SUBFRAME SNDRV_PCM_FORMAT_IEC958_SUBFRAME_BE
145 #endif
147 /* pcm params */
148 #define SNDRV_MASK_BITS 64 /* we use so far 64bits only */
149 #define SNDRV_MASK_SIZE (SNDRV_MASK_BITS / 32)
150 #define MASK_OFS(i) ((i) >> 5)
151 #define MASK_BIT(i) (1U << ((i) & 31))
153 struct snd_pcm_params {
154 snd_pcm_access_t access; /* access mode */
155 //unsigned int fifo_bits;
157 snd_pcm_format_t format; /* SNDRV_PCM_FORMAT_* */
158 unsigned int rate; /* rate in Hz ,sample rate */
159 unsigned int channels; /* channels */
160 snd_pcm_uframes_t period_size; /* interrput period ( sample unit ) */
161 unsigned int periods; /* periods */
162 /* snd_pcm_uframes_t buffer_size; */
163 unsigned int buffer_bytes;
165 snd_pcm_uframes_t start_threshold; /* min hw_avail frames for automatic start */
166 snd_pcm_uframes_t stop_threshold; /* min avail frames for automatic stop */
167 snd_pcm_uframes_t silence_threshold; /* min distance from noise for silence filling */
168 snd_pcm_uframes_t silence_size; /* silence block size */
169 /* snd_pcm_uframes_t boundary;*/ /* pointers wrap point */
172 #define NON_BLOCK 1
173 #define RW_BLOCK 0
175 #define THRESHOLD_BOUNDARY 0xFFFFFFFF
177 extern unsigned int sys_dma_inited; /* set by other driver that already inited dma */
179 /* declare function */
180 int pcm_format_width(snd_pcm_format_t format);
181 int pcm_format_physical_width(snd_pcm_format_t format);
182 int pcm_format_little_endian(snd_pcm_format_t format);
184 /* extern function */
185 size_t u_audio_playback(void * handle, void *buf, size_t count);
186 snd_pcm_sframes_t snd_pcm_lib_write(void * handle, unsigned long data, snd_pcm_uframes_t size ,int nonblock);
187 int snd_pcm_params(void * handle, struct snd_pcm_params *params);
188 int pcm_stream_init(void ** handle , unsigned int direction,struct snd_pcm_params *params);
189 void pcm_stream_deinit(void * handle) ;
190 int pcm_stream_rate(void * handle);
191 int snd_pcm_get_avail_rate(void * handle);
192 snd_pcm_sframes_t snd_pcm_lib_read(void * handle, unsigned long data,
193 snd_pcm_uframes_t size ,int nonblock);
195 int snd_pcm_vol_ctrl(void * handle,int updown); /* 1 up , 0 down */
197 #endif // __PCM_LIB_H__