]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android-sdk/platform-external-tinyalsa.git/blob - include/tinyalsa/asoundlib.h
2e8c3e054c3061d5d12d5d53218f15112f5ddd8c
[android-sdk/platform-external-tinyalsa.git] / include / tinyalsa / asoundlib.h
1 /* asoundlib.h
2 **
3 ** Copyright 2011, The Android Open Source Project
4 **
5 ** Redistribution and use in source and binary forms, with or without
6 ** modification, are permitted provided that the following conditions are met:
7 **     * Redistributions of source code must retain the above copyright
8 **       notice, this list of conditions and the following disclaimer.
9 **     * Redistributions in binary form must reproduce the above copyright
10 **       notice, this list of conditions and the following disclaimer in the
11 **       documentation and/or other materials provided with the distribution.
12 **     * Neither the name of The Android Open Source Project nor the names of
13 **       its contributors may be used to endorse or promote products derived
14 **       from this software without specific prior written permission.
15 **
16 ** THIS SOFTWARE IS PROVIDED BY The Android Open Source Project ``AS IS'' AND
17 ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 ** ARE DISCLAIMED. IN NO EVENT SHALL The Android Open Source Project BE LIABLE
20 ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 ** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
26 ** DAMAGE.
27 */
29 #ifndef ASOUNDLIB_H
30 #define ASOUNDLIB_H
32 #include <sys/time.h>
34 #if defined(__cplusplus)
35 extern "C" {
36 #endif
38 /*
39  * PCM API
40  */
42 struct pcm;
44 #define PCM_OUT        0x00000000
45 #define PCM_IN         0x10000000
47 /* Bit formats */
48 enum pcm_format {
49     PCM_FORMAT_S16_LE = 0,
50     PCM_FORMAT_S32_LE,
52     PCM_FORMAT_MAX,
53 };
55 /* Configuration for a stream */
56 struct pcm_config {
57     unsigned int channels;
58     unsigned int rate;
59     unsigned int period_size;
60     unsigned int period_count;
61     enum pcm_format format;
63     /* Values to use for the ALSA start, stop and silence thresholds.  Setting
64      * any one of these values to 0 will cause the default tinyalsa values to be
65      * used instead.  Tinyalsa defaults are as follows.
66      *
67      * start_threshold   : period_count * period_size
68      * stop_threshold    : period_count * period_size
69      * silence_threshold : 0
70      */
71     unsigned int start_threshold;
72     unsigned int stop_threshold;
73     unsigned int silence_threshold;
74 };
76 /* Mixer control types */
77 enum mixer_ctl_type {
78     MIXER_CTL_TYPE_BOOL,
79     MIXER_CTL_TYPE_INT,
80     MIXER_CTL_TYPE_ENUM,
81     MIXER_CTL_TYPE_BYTE,
82     MIXER_CTL_TYPE_IEC958,
83     MIXER_CTL_TYPE_INT64,
84     MIXER_CTL_TYPE_UNKNOWN,
86     MIXER_CTL_TYPE_MAX,
87 };
89 /* Open and close a stream */
90 struct pcm *pcm_open(unsigned int card, unsigned int device,
91                      unsigned int flags, struct pcm_config *config);
92 int pcm_close(struct pcm *pcm);
93 int pcm_is_ready(struct pcm *pcm);
95 /* Set and get config */
96 int pcm_get_config(struct pcm *pcm, struct pcm_config *config);
97 int pcm_set_config(struct pcm *pcm, struct pcm_config *config);
99 /* Returns a human readable reason for the last error */
100 const char *pcm_get_error(struct pcm *pcm);
102 /* Returns the buffer size (int bytes) that should be used for pcm_write.
103  * This will be 1/2 of the actual fifo size.
104  */
105 unsigned int pcm_get_buffer_size(struct pcm *pcm);
107 /* Returns the pcm latency in ms */
108 unsigned int pcm_get_latency(struct pcm *pcm);
110 /* Returns available frames in pcm buffer and corresponding time stamp.
111  * For an input stream, frames available are frames ready for the
112  * application to read.
113  * For an output stream, frames available are the number of empty frames available
114  * for the application to write.
115  */
116 int pcm_get_htimestamp(struct pcm *pcm, unsigned int *avail,
117                        struct timespec *tstamp);
119 /* Write data to the fifo.
120  * Will start playback on the first write or on a write that
121  * occurs after a fifo underrun.
122  */
123 int pcm_write(struct pcm *pcm, void *data, unsigned int count);
124 int pcm_read(struct pcm *pcm, void *data, unsigned int count);
126 /* Start and stop a PCM channel that doesn't transfer data */
127 int pcm_start(struct pcm *pcm);
128 int pcm_stop(struct pcm *pcm);
131 /*
132  * MIXER API
133  */
135 struct mixer;
136 struct mixer_ctl;
138 /* Open and close a mixer */
139 struct mixer *mixer_open(unsigned int card);
140 void mixer_close(struct mixer *mixer);
142 /* Obtain mixer controls */
143 unsigned int mixer_get_num_ctls(struct mixer *mixer);
144 struct mixer_ctl *mixer_get_ctl(struct mixer *mixer, unsigned int id);
145 struct mixer_ctl *mixer_get_ctl_by_name(struct mixer *mixer, const char *name);
147 /* Get info about mixer controls */
148 int mixer_ctl_get_name(struct mixer_ctl *ctl, char *name, unsigned int size);
149 enum mixer_ctl_type mixer_ctl_get_type(struct mixer_ctl *ctl);
150 const char *mixer_ctl_get_type_string(struct mixer_ctl *ctl);
151 unsigned int mixer_ctl_get_num_values(struct mixer_ctl *ctl);
152 unsigned int mixer_ctl_get_num_enums(struct mixer_ctl *ctl);
153 int mixer_ctl_get_enum_string(struct mixer_ctl *ctl, unsigned int enum_id,
154                               char *string, unsigned int size);
156 /* Set and get mixer controls */
157 int mixer_ctl_get_percent(struct mixer_ctl *ctl, unsigned int id);
158 int mixer_ctl_set_percent(struct mixer_ctl *ctl, unsigned int id, int percent);
160 int mixer_ctl_get_value(struct mixer_ctl *ctl, unsigned int id);
161 int mixer_ctl_set_value(struct mixer_ctl *ctl, unsigned int id, int value);
162 int mixer_ctl_set_enum_by_string(struct mixer_ctl *ctl, const char *string);
164 /* Determe range of integer mixer controls */
165 int mixer_ctl_get_range_min(struct mixer_ctl *ctl);
166 int mixer_ctl_get_range_max(struct mixer_ctl *ctl);
168 #if defined(__cplusplus)
169 }  /* extern "C" */
170 #endif
172 #endif