1 /* 2 ** Copyright 2010, The Android Open-Source Project 3 ** 4 ** Licensed under the Apache License, Version 2.0 (the "License"); 5 ** you may not use this file except in compliance with the License. 6 ** You may obtain a copy of the License at 7 ** 8 ** http://www.apache.org/licenses/LICENSE-2.0 9 ** 10 ** Unless required by applicable law or agreed to in writing, software 11 ** distributed under the License is distributed on an "AS IS" BASIS, 12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 ** See the License for the specific language governing permissions and 14 ** limitations under the License. 15 */ 16 17 #ifndef _AUDIO_H_ 18 #define _AUDIO_H_ 19 20 struct pcm; 21 22 #define PCM_OUT 0x00000000 23 #define PCM_IN 0x10000000 24 25 #define PCM_STEREO 0x00000000 26 #define PCM_MONO 0x01000000 27 28 #define PCM_44100HZ 0x00000000 29 #define PCM_48000HZ 0x00100000 30 #define PCM_8000HZ 0x00200000 31 #define PCM_RATE_MASK 0x00F00000 32 33 #define PCM_PERIOD_CNT_MIN 2 34 #define PCM_PERIOD_CNT_SHIFT 16 35 #define PCM_PERIOD_CNT_MASK (0xF << PCM_PERIOD_CNT_SHIFT) 36 #define PCM_PERIOD_SZ_MIN 128 37 #define PCM_PERIOD_SZ_SHIFT 12 38 #define PCM_PERIOD_SZ_MASK (0xF << PCM_PERIOD_SZ_SHIFT) 39 40 /* Acquire/release a pcm channel. 41 * Returns non-zero on error 42 */ 43 struct pcm *pcm_open(unsigned flags); 44 int pcm_close(struct pcm *pcm); 45 int pcm_ready(struct pcm *pcm); 46 47 /* Returns a human readable reason for the last error. */ 48 const char *pcm_error(struct pcm *pcm); 49 50 /* Returns the buffer size (int bytes) that should be used for pcm_write. 51 * This will be 1/2 of the actual fifo size. 52 */ 53 unsigned pcm_buffer_size(struct pcm *pcm); 54 55 /* Write data to the fifo. 56 * Will start playback on the first write or on a write that 57 * occurs after a fifo underrun. 58 */ 59 int pcm_write(struct pcm *pcm, void *data, unsigned count); 60 int pcm_read(struct pcm *pcm, void *data, unsigned count); 61 62 struct mixer; 63 struct mixer_ctl; 64 65 struct mixer *mixer_open(void); 66 void mixer_close(struct mixer *mixer); 67 void mixer_dump(struct mixer *mixer); 68 69 struct mixer_ctl *mixer_get_control(struct mixer *mixer, 70 const char *name, unsigned index); 71 struct mixer_ctl *mixer_get_nth_control(struct mixer *mixer, unsigned n); 72 73 int mixer_ctl_set(struct mixer_ctl *ctl, unsigned percent); 74 int mixer_ctl_select(struct mixer_ctl *ctl, const char *value); 75 void mixer_ctl_print(struct mixer_ctl *ctl); 76 77 #endif 78