Tizen RT Public API  v1.1 D4
tinyalsa.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright 2017 Samsung Electronics All Rights Reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing,
12  * software distributed under the License is distributed on an
13  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14  * either express or implied. See the License for the specific
15  * language governing permissions and limitations under the License.
16  *
17  ****************************************************************************/
18 
19 /* tinyalsa.h
20 **
21 ** Copyright 2011, The Android Open Source Project
22 **
23 ** Redistribution and use in source and binary forms, with or without
24 ** modification, are permitted provided that the following conditions are met:
25 ** * Redistributions of source code must retain the above copyright
26 ** notice, this list of conditions and the following disclaimer.
27 ** * Redistributions in binary form must reproduce the above copyright
28 ** notice, this list of conditions and the following disclaimer in the
29 ** documentation and/or other materials provided with the distribution.
30 ** * Neither the name of The Android Open Source Project nor the names of
31 ** its contributors may be used to endorse or promote products derived
32 ** from this software without specific prior written permission.
33 **
34 ** THIS SOFTWARE IS PROVIDED BY The Android Open Source Project ``AS IS'' AND
35 ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37 ** ARE DISCLAIMED. IN NO EVENT SHALL The Android Open Source Project BE LIABLE
38 ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39 ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
40 ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
41 ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42 ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
43 ** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
44 ** DAMAGE.
45 */
46 
59 #ifndef __AUDIO_TINYALSA_H
60 #define __AUDIO_TINYALSA_H
61 
62 #include <sys/time.h>
63 #include <stddef.h>
64 
65 #if defined(__cplusplus)
66 extern "C" {
67 #endif
68 
74 #define PCM_OUT 0x00000000
75 
81 #define PCM_IN 0x10000000
82 
87 #define PCM_MMAP 0x00000001
88 
94 #define PCM_NOIRQ 0x00000002
95 
107 #define PCM_NORESTART 0x00000004
108 
113 #define PCM_MONOTONIC 0x00000008
114 
119 #define PCM_STATE_RUNNING 0x03
120 
124 #define PCM_STATE_XRUN 0x04
125 
129 #define PCM_STATE_DRAINING 0x05
130 
134 #define PCM_STATE_SUSPENDED 0x07
135 
139 #define PCM_STATE_DISCONNECTED 0x08
140 
175 };
176 
180 struct pcm_mask {
182  unsigned int bits[32 / sizeof(unsigned int)];
183 };
184 
189 struct pcm_config {
191  unsigned int channels;
193  unsigned int rate;
195  unsigned int period_size;
197  unsigned int period_count;
200  /* Values to use for the ALSA start, stop and silence thresholds. Setting
201  * any one of these values to 0 will cause the default tinyalsa values to be
202  * used instead. Tinyalsa defaults are as follows.
203  *
204  * start_threshold : period_count * period_size
205  * stop_threshold : period_count * period_size
206  * silence_threshold : 0
207  */
209  unsigned int start_threshold;
211  unsigned int stop_threshold;
213  unsigned int silence_threshold;
214 };
215 
221 enum pcm_param {
236  PCM_PARAM_PERIOD_TIME,
243  PCM_PARAM_BUFFER_TIME,
244  PCM_PARAM_BUFFER_SIZE,
245  PCM_PARAM_BUFFER_BYTES,
246  PCM_PARAM_TICK_TIME,
247 }; /* enum pcm_param */
248 
249 struct pcm;
250 
262 struct pcm *pcm_open(unsigned int card, unsigned int device, unsigned int flags, const struct pcm_config *config);
263 
274 struct pcm *pcm_open_by_name(const char *name, unsigned int flags, const struct pcm_config *config);
275 
284 int pcm_close(struct pcm *pcm);
285 
294 int pcm_is_ready(const struct pcm *pcm);
295 
304 unsigned int pcm_get_channels(const struct pcm *pcm);
305 
314 const struct pcm_config *pcm_get_config(const struct pcm *pcm);
315 
324 unsigned int pcm_get_rate(const struct pcm *pcm);
325 
334 enum pcm_format pcm_get_format(const struct pcm *pcm);
335 
344 int pcm_get_file_descriptor(const struct pcm *pcm);
345 
354 const char *pcm_get_error(const struct pcm *pcm);
355 
364 unsigned int pcm_get_buffer_size(const struct pcm *pcm);
365 
375 unsigned int pcm_frames_to_bytes(const struct pcm *pcm, unsigned int frames);
376 
386 unsigned int pcm_bytes_to_frames(const struct pcm *pcm, unsigned int bytes);
387 
396 unsigned int pcm_get_subdevice(const struct pcm *pcm);
397 
408 int pcm_writei(struct pcm *pcm, const void *data, unsigned int frame_count);
409 
420 int pcm_readi(struct pcm *pcm, void *data, unsigned int frame_count);
421 
430 int pcm_prepare(struct pcm *pcm);
431 
440 unsigned int pcm_format_to_bits(enum pcm_format format);
441 
442 #if defined(__cplusplus)
443 } /* extern "C" */
444 #endif
445 // end of TinyAlsa group
446 #endif
int pcm_writei(struct pcm *pcm, const void *data, unsigned int frame_count)
Writes audio samples to PCM.
struct pcm * pcm_open(unsigned int card, unsigned int device, unsigned int flags, const struct pcm_config *config)
Opens a PCM for playback or recording.
unsigned int pcm_get_channels(const struct pcm *pcm)
Gets the channel count of the PCM.
const char * pcm_get_error(const struct pcm *pcm)
Gets the error message for the last error that occured.
unsigned int pcm_format_to_bits(enum pcm_format format)
Determines the number of bits occupied by a pcm_format.
const struct pcm_config * pcm_get_config(const struct pcm *pcm)
Gets the PCM configuration.
unsigned int stop_threshold
Definition: tinyalsa.h:211
enum pcm_format pcm_get_format(const struct pcm *pcm)
Gets the format of the PCM.
Encapsulates the hardware and software parameters of a PCM.
Definition: tinyalsa.h:189
unsigned int channels
Definition: tinyalsa.h:191
A bit mask of 256 bits (32 bytes) that describes some hardware parameters of a PCM.
Definition: tinyalsa.h:180
unsigned int pcm_get_buffer_size(const struct pcm *pcm)
Gets the buffer size of the PCM.
unsigned int bits[32/sizeof(unsigned int)]
Definition: tinyalsa.h:182
int pcm_readi(struct pcm *pcm, void *data, unsigned int frame_count)
Reads audio samples from PCM.
pcm_format
Audio sample format of a PCM.
Definition: tinyalsa.h:152
unsigned int start_threshold
Definition: tinyalsa.h:209
int pcm_close(struct pcm *pcm)
Closes a PCM returned by pcm_open.
int pcm_prepare(struct pcm *pcm)
Prepares a PCM, if it has not been prepared already.
unsigned int silence_threshold
Definition: tinyalsa.h:213
int pcm_get_file_descriptor(const struct pcm *pcm)
Gets the file descriptor of the PCM.
struct pcm * pcm_open_by_name(const char *name, unsigned int flags, const struct pcm_config *config)
Opens a PCM by it&#39;s name.
int pcm_is_ready(const struct pcm *pcm)
Checks if a PCM file has been opened without error.
unsigned int rate
Definition: tinyalsa.h:193
unsigned int pcm_frames_to_bytes(const struct pcm *pcm, unsigned int frames)
Determines how many bytes are occupied by a number of frames of a PCM.
unsigned int pcm_get_rate(const struct pcm *pcm)
Gets the sample rate of the PCM.
unsigned int pcm_bytes_to_frames(const struct pcm *pcm, unsigned int bytes)
Determines how many frames of a PCM can fit into a number of bytes.
pcm_param
Enumeration of a PCM&#39;s hardware parameters.
Definition: tinyalsa.h:221
unsigned int pcm_get_subdevice(const struct pcm *pcm)
Gets the subdevice on which the pcm has been opened.
unsigned int period_count
Definition: tinyalsa.h:197
unsigned int period_size
Definition: tinyalsa.h:195
enum pcm_format format
Definition: tinyalsa.h:199