Lines Matching +full:capture +full:- +full:channels
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
65 * audio_init - initialize an instance of audio player
66 * @dev_name - the backend sound device used to play / capture
67 * @dir - dir = 1 for write mode, dir = 0 for read mode
92 if (nlen < sizeof(aud->dev_name)) in audio_init()
93 memcpy(aud->dev_name, dev_name, nlen + 1); in audio_init()
100 aud->dir = dir; in audio_init()
102 aud->fd = open(aud->dev_name, aud->dir ? O_WRONLY : O_RDONLY, 0); in audio_init()
103 if (aud->fd == -1) { in audio_init()
105 aud->dev_name, errno); in audio_init()
112 if (caph_rights_limit(aud->fd, &rights) == -1) in audio_init()
114 if (caph_ioctls_limit(aud->fd, cmds, nitems(cmds)) == -1) in audio_init()
122 * audio_set_params - reset the sound device and set the audio params
123 * @aud - the audio player to be configured
124 * @params - the audio parameters to be set
130 int format, channels, rate; in audio_set_params() local
139 if ((audio_fd = aud->fd) < 0) { in audio_set_params()
141 aud->dev_name); in audio_set_params()
142 return (-1); in audio_set_params()
146 if (aud->inited) { in audio_set_params()
148 if (err == -1) { in audio_set_params()
150 aud->fd, errno); in audio_set_params()
151 return (-1); in audio_set_params()
154 aud->inited = 1; in audio_set_params()
157 format = params->format; in audio_set_params()
159 if (err == -1) { in audio_set_params()
161 params->format, errno); in audio_set_params()
162 return -1; in audio_set_params()
166 if (format != params->format) { in audio_set_params()
167 DPRINTF("Mismatch format: 0x%x params->format: 0x%x", in audio_set_params()
168 format, params->format); in audio_set_params()
169 return -1; in audio_set_params()
172 /* Set the Number of Channels */ in audio_set_params()
173 channels = params->channels; in audio_set_params()
174 err = ioctl(audio_fd, SNDCTL_DSP_CHANNELS, &channels); in audio_set_params()
175 if (err == -1) { in audio_set_params()
176 DPRINTF("Fail to set channels: %d errno: %d", in audio_set_params()
177 params->channels, errno); in audio_set_params()
178 return -1; in audio_set_params()
181 /* The device does not support the requested no. of channels */ in audio_set_params()
182 if (channels != params->channels) { in audio_set_params()
183 DPRINTF("Mismatch channels: %d params->channels: %d", in audio_set_params()
184 channels, params->channels); in audio_set_params()
185 return -1; in audio_set_params()
189 rate = params->rate; in audio_set_params()
191 if (err == -1) { in audio_set_params()
193 params->rate, errno); in audio_set_params()
194 return -1; in audio_set_params()
198 if (rate != params->rate) { in audio_set_params()
199 DPRINTF("Mismatch rate: %d params->rate: %d", in audio_set_params()
200 rate, params->rate); in audio_set_params()
201 return -1; in audio_set_params()
205 err = ioctl(audio_fd, aud->dir ? SNDCTL_DSP_GETOSPACE : in audio_set_params()
207 if (err == -1) { in audio_set_params()
209 return -1; in audio_set_params()
218 * audio_playback - plays samples to the sound device using blocking operations
219 * @aud - the audio player used to play the samples
220 * @buf - the buffer containing the samples
221 * @count - the number of bytes in buffer
231 assert(aud->dir); in audio_playback()
234 audio_fd = aud->fd; in audio_playback()
235 assert(audio_fd != -1); in audio_playback()
238 len = write(audio_fd, buf + total, count - total); in audio_playback()
242 return -1; in audio_playback()
250 * audio_record - records samples from the sound device using
252 * @aud - the audio player used to capture the samples
253 * @buf - the buffer to receive the samples
254 * @count - the number of bytes to capture in buffer
255 * Returns -1 on error and 0 on success
265 assert(!aud->dir); in audio_record()
268 audio_fd = aud->fd; in audio_record()
269 assert(audio_fd != -1); in audio_record()
272 len = read(audio_fd, buf + total, count - total); in audio_record()
276 return -1; in audio_record()