TizenRT Public API  v2.0 M2
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 0x00000010
75 
81 #define PCM_IN 0x00000020
82 
87 #define PCM_MMAP 0x00000001
88 
94 #define PCM_NOIRQ 0x00000002
95 
107 #define PCM_NORESTART 0x00000004
108 
113 #define PCM_STATE_RUNNING 0x03
114 
118 #define PCM_STATE_XRUN 0x04
119 
123 #define PCM_STATE_DRAINING 0x05
124 
128 #define PCM_STATE_SUSPENDED 0x07
129 
133 #define PCM_STATE_DISCONNECTED 0x08
134 
169 };
170 
175 struct pcm_config {
177  unsigned int channels;
179  unsigned int rate;
183  unsigned int period_size;
185  unsigned int period_count;
186 };
187 
188 struct pcm;
189 
201 struct pcm *pcm_open(unsigned int card, unsigned int device, unsigned int flags, const struct pcm_config *config);
202 
213 struct pcm *pcm_open_by_name(const char *name, unsigned int flags, const struct pcm_config *config);
214 
223 int pcm_close(struct pcm *pcm);
224 
233 int pcm_is_ready(const struct pcm *pcm);
234 
243 unsigned int pcm_get_channels(const struct pcm *pcm);
244 
253 const struct pcm_config *pcm_get_config(const struct pcm *pcm);
254 
263 unsigned int pcm_get_rate(const struct pcm *pcm);
264 
273 enum pcm_format pcm_get_format(const struct pcm *pcm);
274 
283 int pcm_get_file_descriptor(const struct pcm *pcm);
284 
293 const char *pcm_get_error(const struct pcm *pcm);
294 
303 unsigned int pcm_get_buffer_size(const struct pcm *pcm);
304 
314 unsigned int pcm_frames_to_bytes(const struct pcm *pcm, unsigned int frames);
315 
325 unsigned int pcm_bytes_to_frames(const struct pcm *pcm, unsigned int bytes);
326 
337 int pcm_writei(struct pcm *pcm, const void *data, unsigned int frame_count);
338 
349 int pcm_readi(struct pcm *pcm, void *data, unsigned int frame_count);
350 
359 int pcm_drop(struct pcm *pcm);
360 
369 int pcm_drain(struct pcm *pcm);
370 
379 int pcm_prepare(struct pcm *pcm);
380 
389 unsigned int pcm_format_to_bits(enum pcm_format format);
390 
399 unsigned int pcm_get_subdevice(const struct pcm *pcm);
400 
411 int pcm_mmap_write(struct pcm *pcm, const void *data, unsigned int count);
412 
423 int pcm_mmap_read(struct pcm *pcm, void *data, unsigned int count);
424 
436 int pcm_mmap_begin(struct pcm *pcm, void **areas, unsigned int *offset, unsigned int *frames);
437 
448 int pcm_mmap_commit(struct pcm *pcm, unsigned int offset, unsigned int frames);
449 
459 int pcm_wait(struct pcm *pcm, int timeout);
460 
469 int pcm_avail_update(struct pcm *pcm);
470 #if defined(__cplusplus)
471 } /* extern "C" */
472 #endif
473 // end of TinyAlsa group
474 #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.
int pcm_mmap_begin(struct pcm *pcm, void **areas, unsigned int *offset, unsigned int *frames)
Application request to access a portion of direct (mmap) area.
unsigned int pcm_get_channels(const struct pcm *pcm)
Gets the channel count of the PCM.
int pcm_mmap_read(struct pcm *pcm, void *data, unsigned int count)
Reads audio samples from the PCM using the mmap buffer.
int pcm_avail_update(struct pcm *pcm)
Returns the number of frames ready to be written or read.
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.
int pcm_drain(struct pcm *pcm)
Stop a PCM preserving pending frames.
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:175
unsigned int channels
Definition: tinyalsa.h:177
unsigned int pcm_get_buffer_size(const struct pcm *pcm)
Gets the buffer size of the PCM.
int pcm_readi(struct pcm *pcm, void *data, unsigned int frame_count)
Reads audio samples from PCM.
int pcm_drop(struct pcm *pcm)
Stops a PCM. Any data present in the buffers will be dropped.
pcm_format
Audio sample format of a PCM.
Definition: tinyalsa.h:146
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.
int pcm_mmap_write(struct pcm *pcm, const void *data, unsigned int count)
Writes audio samples to the PCM using the mmap buffer.
int pcm_get_file_descriptor(const struct pcm *pcm)
Gets the file descriptor of the PCM.
int pcm_wait(struct pcm *pcm, int timeout)
Waits for buffer to become available for mmap access.
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:179
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.
int pcm_mmap_commit(struct pcm *pcm, unsigned int offset, unsigned int frames)
Application has completed the access to area requested with pcm_mmap_begin.
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:185
unsigned int period_size
Definition: tinyalsa.h:183
enum pcm_format format
Definition: tinyalsa.h:181