5 * \author Jaroslav Kysela <perex@perex.cz>
6 * \author Abramo Bagnara <abramo@alsa-project.org>
9 * PCM Interface is designed to write or read digital audio frames. A
10 * frame is the data unit converted into/from sound in one time unit
11 * (1/rate seconds), by example if you set your playback PCM rate to
12 * 44100 you'll hear 44100 frames per second. The size in bytes of a
13 * frame may be obtained from bits needed to store a sample and
16 * See the \ref pcm page for more details.
19 * PCM Interface - main file
20 * Copyright (c) 1998 by Jaroslav Kysela <perex@perex.cz>
21 * Copyright (c) 2000 by Abramo Bagnara <abramo@alsa-project.org>
23 * This library is free software; you can redistribute it and/or modify
24 * it under the terms of the GNU Lesser General Public License as
25 * published by the Free Software Foundation; either version 2.1 of
26 * the License, or (at your option) any later version.
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU Lesser General Public License for more details.
33 * You should have received a copy of the GNU Lesser General Public
34 * License along with this library; if not, write to the Free Software
35 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
39 /*! \page pcm PCM (digital audio) interface
41 <P>Although abbreviation PCM stands for Pulse Code Modulation, we are
42 understanding it as general digital audio processing with volume samples
43 generated in continuous time periods.</P>
45 <P>The analog signal is recorded via analog to digital converters (ADC).
46 The digital value (de-facto a volume at a specific time) obtained
47 from ADC can be further processed. The following picture shows a perfect
53 <P>Next image shows digitized representation:</P>
58 <P>As you may see, the quality of digital audio signal depends on the time
59 (recording rate) and voltage resolution (usually in an linear integer
60 representation with basic unit one bit).</P>
62 <P>The stored digital signal can be converted back to voltage (analog)
63 representation via digital to analog converters (DAC).</P>
65 <P>One digital value is called sample. More samples are collected to frames
66 (frame is terminology for ALSA) depending on count of converters used at one
67 specific time. One frame might contain one sample (when only one converter is
68 used - mono) or more samples (for example: stereo has signals from two converters
69 recorded at same time). Digital audio stream contains collection of frames
70 recorded at boundaries of continuous time periods.</P>
72 \section pcm_general_overview General overview
74 ALSA uses the ring buffer to store outgoing (playback) and incoming (capture,
75 record) samples. There are two pointers being maintained to allow
76 a precise communication between application and device pointing to current
77 processed sample by hardware and last processed sample by application.
78 The modern audio chips allow to program the transfer time periods.
79 It means that the stream of samples is divided to small chunks. Device
80 acknowledges to application when the transfer of a chunk is complete.
82 \section pcm_transfer Transfer methods in UNIX environments
84 In the UNIX environment, data chunk acknowledges are received via standard I/O
85 calls or event waiting routines (poll or select function). To accomplish
86 this list, the asynchronous notification of acknowledges should be listed
87 here. The ALSA implementation for these methods is described in
88 the \ref alsa_transfers section.
90 \subsection pcm_transfer_io Standard I/O transfers
92 The standard I/O transfers are using the read (see 'man 2 read') and write
93 (see 'man 2 write') C functions. There are two basic behaviours of these
94 functions - blocked and non-blocked (see the O_NONBLOCK flag for the
95 standard C open function - see 'man 2 open'). In non-blocked behaviour,
96 these I/O functions never stops, they return -EAGAIN error code, when no
97 data can be transferred (the ring buffer is full in our case). In blocked
98 behaviour, these I/O functions stop and wait until there is a room in the
99 ring buffer (playback) or until there are a new samples (capture). The ALSA
100 implementation can be found in the \ref alsa_pcm_rw section.
102 \subsection pcm_transfer_event Event waiting routines
104 The poll or select functions (see 'man 2 poll' or 'man 2 select' for further
105 details) allows to receive requests/events from the device while
106 an application is waiting on events from other sources (like keyboard, screen,
107 network etc.), too. \ref snd_pcm_poll_descriptors can be used to get a file
108 descriptor to poll or select on. The implemented
109 transfer routines can be found in the \ref alsa_transfers section.
111 \subsection pcm_transfer_async Asynchronous notification
113 ALSA driver and library knows to handle the asynchronous notifications over
114 the SIGIO signal. This signal allows to interrupt application and transfer
115 data in the signal handler. For further details see the sigaction function
116 ('man 2 sigaction'). The section \ref pcm_async describes the ALSA API for
117 this extension. The implemented transfer routines can be found in the
118 \ref alsa_transfers section.
120 \section pcm_open_behaviour Blocked and non-blocked open
122 The ALSA PCM API uses a different behaviour when the device is opened
123 with blocked or non-blocked mode. The mode can be specified with
124 \a mode argument in #snd_pcm_open() function.
125 The blocked mode is the default (without #SND_PCM_NONBLOCK mode).
126 In this mode, the behaviour is that if the resources have already used
127 with another application, then it blocks the caller, until resources are
128 free. The non-blocked behaviour (with #SND_PCM_NONBLOCK)
129 doesn't block the caller in any way and returns -EBUSY error when the
130 resources are not available. Note that the mode also determines the
131 behaviour of standard I/O calls, returning -EAGAIN when non-blocked mode is
132 used and the ring buffer is full (playback) or empty (capture).
133 The operation mode for I/O calls can be changed later with
134 the #snd_pcm_nonblock() function.
136 \section pcm_async Asynchronous mode
138 There is also possibility to receive asynchronous notification after
139 specified time periods. You may see the #SND_PCM_ASYNC
140 mode for #snd_pcm_open() function and
141 #snd_async_add_pcm_handler() function for further details.
143 \section pcm_handshake Handshake between application and library
145 The ALSA PCM API design uses the states to determine the communication
146 phase between application and library. The actual state can be determined
147 using #snd_pcm_state() call. There are these states:
149 \par SND_PCM_STATE_OPEN
150 The PCM device is in the open state. After the #snd_pcm_open() open call,
151 the device is in this state. Also, when #snd_pcm_hw_params() call fails,
152 then this state is entered to force application calling
153 #snd_pcm_hw_params() function to set right communication
156 \par SND_PCM_STATE_SETUP
157 The PCM device has accepted communication parameters and it is waiting
158 for #snd_pcm_prepare() call to prepare the hardware for
159 selected operation (playback or capture).
161 \par SND_PCM_STATE_PREPARE
162 The PCM device is prepared for operation. Application can use
163 #snd_pcm_start() call, write or read data to start
166 \par SND_PCM_STATE_RUNNING
167 The PCM device is running. It processes the samples. The stream can
168 be stopped using the #snd_pcm_drop() or
169 #snd_pcm_drain calls.
171 \par SND_PCM_STATE_XRUN
172 The PCM device reached overrun (capture) or underrun (playback).
173 You can use the -EPIPE return code from I/O functions
174 (#snd_pcm_writei(), #snd_pcm_writen(), #snd_pcm_readi(), #snd_pcm_readn())
175 to determine this state without checking
176 the actual state via #snd_pcm_state() call. You can recover from
177 this state with #snd_pcm_prepare(),
178 #snd_pcm_drop() or #snd_pcm_drain() calls.
180 \par SND_PCM_STATE_DRAINING
181 The device is in this state when application using the capture mode
182 called #snd_pcm_drain() function. Until all data are
183 read from the internal ring buffer using I/O routines
184 (#snd_pcm_readi(), #snd_pcm_readn()),
185 then the device stays in this state.
187 \par SND_PCM_STATE_PAUSED
188 The device is in this state when application called
189 the #snd_pcm_pause() function until the pause is released.
190 Not all hardware supports this feature. Application should check the
191 capability with the #snd_pcm_hw_params_can_pause().
193 \par SND_PCM_STATE_SUSPENDED
194 The device is in the suspend state provoked with the power management
195 system. The stream can be resumed using #snd_pcm_resume()
196 call, but not all hardware supports this feature. Application should check
197 the capability with the #snd_pcm_hw_params_can_resume().
198 In other case, the calls #snd_pcm_prepare(),
199 #snd_pcm_drop(), #snd_pcm_drain() can be used
202 \par SND_PCM_STATE_DISCONNECTED
203 The device is physicaly disconnected. It does not accept any I/O calls in this state.
205 \section pcm_formats PCM formats
207 The full list of formats present the #snd_pcm_format_t type.
208 The 24-bit linear samples uses 32-bit physical space, but the sample is
209 stored in low three bits. Some hardware does not support processing of full
210 range, thus you may get the significant bits for linear samples via
211 #snd_pcm_hw_params_get_sbits() function. The example: ICE1712
212 chips support 32-bit sample processing, but low byte is ignored (playback)
213 or zero (capture). The function snd_pcm_hw_params_get_sbits()
214 returns 24 in the case.
216 \section alsa_transfers ALSA transfers
218 There are two methods to transfer samples in application. The first method
219 is the standard read / write one. The second method, uses the direct audio
220 buffer to communicate with the device while ALSA library manages this space
221 itself. You can find examples of all communication schemes for playback
222 in \ref example_test_pcm "Sine-wave generator example". To complete the
223 list, we should note that #snd_pcm_wait() function contains
224 embedded poll waiting implementation.
226 \subsection alsa_pcm_rw Read / Write transfer
228 There are two versions of read / write routines. The first expects the
229 interleaved samples at input (#SND_PCM_ACCESS_RW_INTERLEAVED access method),
230 and the second one expects non-interleaved (samples in separated buffers -
231 #SND_PCM_ACCESS_RW_NONINTERLEAVED access method) at input. There are these
232 functions for interleaved transfers: #snd_pcm_writei()
233 #snd_pcm_readi(). For non-interleaved transfers, there are
234 these functions: #snd_pcm_writen() and #snd_pcm_readn().
236 \subsection alsa_mmap_rw Direct Read / Write transfer (via mmap'ed areas)
238 Three kinds of organization of ring buffer memory areas exist in ALSA API.
239 Access #SND_PCM_ACCESS_MMAP_INTERLEAVED has interleaved samples. Access
240 #SND_PCM_ACCESS_MMAP_NONINTERLEAVED expects continous sample areas for
241 one channel. Access #SND_PCM_ACCESS_MMAP_COMPLEX does not fit to interleaved
242 and non-interleaved ring buffer organization.
244 There are two functions for this kind of transfer. Application can get an
245 access to memory areas via #snd_pcm_mmap_begin() function.
246 This function returns the areas (single area is equal to a channel)
247 containing the direct pointers to memory and sample position description
248 in #snd_pcm_channel_area_t structure. After application
249 transfers the data in the memory areas, then it must be acknowledged
250 the end of transfer via #snd_pcm_mmap_commit() function
251 to allow the ALSA library update the pointers to ring buffer. This kind of
252 communication is also called "zero-copy", because the device does not require
253 to copy the samples from application to another place in system memory.
255 If you like to use the compatibility functions in mmap mode, there are
256 read / write routines equaling to standard read / write transfers. Using
257 these functions discards the benefits of direct access to memory region.
258 See the #snd_pcm_mmap_readi(),
259 #snd_pcm_writei(), #snd_pcm_readn()
260 and #snd_pcm_writen() functions.
262 \section pcm_errors Error codes
266 This error means xrun (underrun for playback or overrun for capture).
267 The underrun can happen when an application does not feed new samples
268 in time to alsa-lib (due CPU usage). The overrun can happen when
269 an application does not take new captured samples in time from alsa-lib.
273 This error means that system has suspended drivers. The application
274 should wait in loop when snd_pcm_resume() != -EAGAIN and then
275 call snd_pcm_prepare() when snd_pcm_resume() return an error code.
276 If snd_pcm_resume() does not fail (a zero value is returned), driver
277 supports resume and the snd_pcm_prepare() call can be ommited.
281 This error means that the device is in a bad state. It means that
282 the handskahe between application and alsa-lib is corrupted.
284 \par -ENOTTY, -ENODEV
286 This error can happen when device is physically removed (for example
287 some hotplug devices like USB or PCMCIA, CardBus or ExpressCard
288 can be removed on the fly).
290 \section pcm_params Managing parameters
292 The ALSA PCM device uses two groups of PCM related parameters. The hardware
293 parameters contains the stream description like format, rate, count of
294 channels, ring buffer size etc. The software parameters contains the
295 software (driver) related parameters. The communication behaviour can be
296 controlled via these parameters, like automatic start, automatic stop,
297 interrupting (chunk acknowledge) etc. The software parameters can be
298 modified at any time (when valid hardware parameters are set). It includes
299 the running state as well.
301 \subsection pcm_hw_params Hardware related parameters
303 The ALSA PCM devices use the parameter refining system for hardware
304 parameters - #snd_pcm_hw_params_t. It means, that
305 application choose the full-range of configurations at first and then
306 application sets single parameters until all parameters are elementary
311 ALSA knows about five access modes. The first three can be used for direct
312 communication. The access mode #SND_PCM_ACCESS_MMAP_INTERLEAVED
313 determines the direct memory area and interleaved sample organization.
314 Interleaved organization means, that samples from channels are mixed together.
315 The access mode #SND_PCM_ACCESS_MMAP_NONINTERLEAVED
316 determines the direct memory area and non-interleaved sample organization.
317 Each channel has a separate buffer in the case. The complex direct memory
318 organization represents the #SND_PCM_ACCESS_MMAP_COMPLEX
319 access mode. The sample organization does not fit the interleaved or
320 non-interleaved access modes in the case. The last two access modes
321 describes the read / write access methods.
322 The #SND_PCM_ACCESS_RW_INTERLEAVED access represents the read /
323 write interleaved access and the #SND_PCM_ACCESS_RW_NONINTERLEAVED
324 represents the non-interleaved access.
328 The full list of formats is available in #snd_pcm_format_t
331 \subsection pcm_sw_params Software related parameters
333 These parameters - #snd_pcm_sw_params_t can be modified at
334 any time including the running state.
336 \par Minimum available count of samples
338 This parameter controls the wakeup point. If the count of available samples
339 is equal or greater than this value, then application will be activated.
343 The timestamp mode specifies, if timestamps are activated. Currently, only
344 #SND_PCM_TSTAMP_NONE and #SND_PCM_TSTAMP_MMAP
345 modes are known. The mmap mode means that timestamp is taken
346 on every period time boundary.
350 This parameters means the minimum of ticks to sleep using a standalone
351 timer (usually the system timer). The tick resolution can be obtained
352 via the function #snd_pcm_hw_params_get_tick_time(). This
353 function can be used to fine-tune the transfer acknowledge process. It could
354 be useful especially when some hardware does not support small transfer
359 The read / write transfers can be aligned to this sample count. The modulo
360 is ignored by device. Usually, this value is set to one (no align).
364 The start threshold parameter is used to determine the start point in
365 stream. For playback, if samples in ring buffer is equal or greater than
366 the start threshold parameters and the stream is not running, the stream will
367 be started automatically from the device. For capture, if the application wants
368 to read count of samples equal or greater then the stream will be started.
369 If you want to use explicit start (#snd_pcm_start), you can
370 set this value greater than ring buffer size (in samples), but use the
371 constant MAXINT is not a bad idea.
375 Similarly, the stop threshold parameter is used to automatically stop
376 the running stream, when the available samples crosses this boundary.
377 It means, for playback, the empty samples in ring buffer and for capture,
378 the filled (used) samples in ring buffer.
380 \par Silence threshold
382 The silence threshold specifies count of samples filled with silence
383 ahead of the current application pointer for playback. It is usable
384 for applications when an overrun is possible (like tasks depending on
385 network I/O etc.). If application wants to manage the ahead samples itself,
386 the #snd_pcm_rewind() function allows to forget the last
387 samples in the stream.
389 \section pcm_status Obtaining stream status
391 The stream status is stored in #snd_pcm_status_t structure.
392 These parameters can be obtained: the current stream state -
393 #snd_pcm_status_get_state(), timestamp of trigger -
394 #snd_pcm_status_get_trigger_tstamp(), timestamp of last
395 update #snd_pcm_status_get_tstamp(), delay in samples -
396 #snd_pcm_status_get_delay(), available count in samples -
397 #snd_pcm_status_get_avail(), maximum available samples -
398 #snd_pcm_status_get_avail_max(), ADC over-range count in
399 samples - #snd_pcm_status_get_overrange(). The last two
400 parameters - avail_max and overrange are reset to zero after the status
403 \subsection pcm_status_fast Obtaining stream state fast and update r/w pointer
405 The function #snd_pcm_avail_update() updates the current
406 available count of samples for writing (playback) or filled samples for
407 reading (capture). This call is mandatory for updating actual r/w pointer.
408 Using standalone, it is a light method to obtain current stream position,
409 because it does not require the user <-> kernel context switch, but the value
410 is less accurate, because ring buffer pointers are updated in kernel drivers
411 only when an interrupt occurs. If you want to get accurate stream state,
412 use functions #snd_pcm_hwsync() or #snd_pcm_delay().
413 Note that both of these functions do not update the current r/w pointer
414 for applications, so the function #snd_pcm_avail_update() must
415 be called afterwards before any read/write begin+commit operations.
417 The function #snd_pcm_hwsync() reads the current hardware pointer
418 in the ring buffer from hardware. Note that this function does not update the current
419 r/w pointer for applications, so the function #snd_pcm_avail_update()
420 must be called afterwards before any read/write/begin+commit operations.
422 The function #snd_pcm_delay() returns the delay in samples.
423 For playback, it means count of samples in the ring buffer before
424 the next sample will be sent to DAC. For capture, it means count of samples
425 in the ring buffer before the next sample will be captured from ADC. It works
426 only when the stream is in the running or draining (playback only) state.
427 Note that this function does not update the current r/w pointer for applications,
428 so the function #snd_pcm_avail_update() must be called afterwards
429 before any read/write begin+commit operations.
431 \section pcm_action Managing the stream state
433 The following functions directly and indirectly affect the stream state:
435 \par snd_pcm_hw_params
436 The #snd_pcm_hw_params() function brings the stream state
437 to #SND_PCM_STATE_SETUP
438 if successfully finishes, otherwise the state #SND_PCM_STATE_OPEN
440 When it is brought to SETUP state, this function automatically
441 calls #snd_pcm_prepare() function to bring to the PREPARE state
445 The #snd_pcm_prepare() function enters from #SND_PCM_STATE_SETUP
446 to the #SND_PCM_STATE_PREPARED after a successful finish.
449 The #snd_pcm_start() function enters
450 the #SND_PCM_STATE_RUNNING after a successful finish.
453 The #snd_pcm_drop() function enters the
454 #SND_PCM_STATE_SETUP state.
457 The #snd_pcm_drain() function enters the
458 #SND_PCM_STATE_DRAINING, if
459 the capture device has some samples in the ring buffer otherwise
460 #SND_PCM_STATE_SETUP state is entered.
463 The #snd_pcm_pause() function enters the
464 #SND_PCM_STATE_PAUSED or #SND_PCM_STATE_RUNNING.
466 \par snd_pcm_writei, snd_pcm_writen
467 The #snd_pcm_writei() and #snd_pcm_writen()
468 functions can conditionally start the stream -
469 #SND_PCM_STATE_RUNNING. They depend on the start threshold
472 \par snd_pcm_readi, snd_pcm_readn
473 The #snd_pcm_readi() and #snd_pcm_readn()
474 functions can conditionally start the stream -
475 #SND_PCM_STATE_RUNNING. They depend on the start threshold
478 \section pcm_sync Streams synchronization
480 There are two functions allowing link multiple streams together. In the
481 case, the linking means that all operations are synchronized. Because the
482 drivers cannot guarantee the synchronization (sample resolution) on hardware
483 lacking this feature, the #snd_pcm_info_get_sync() function
484 returns synchronization ID - #snd_pcm_sync_id_t, which is equal
485 for hardware synchronized streams. When the #snd_pcm_link()
486 function is called, all operations managing the stream state for these two
487 streams are joined. The opposite function is #snd_pcm_unlink().
489 \section pcm_dev_names PCM naming conventions
491 The ALSA library uses a generic string representation for names of devices.
492 The devices might be virtual, physical or a mix of both. The generic string
493 is passed to #snd_pcm_open() or #snd_pcm_open_lconf().
494 It contains two parts: device name and arguments. Devices and arguments are described
495 in configuration files. The usual place for default definitions is at /usr/share/alsa/alsa.conf.
496 For detailed descriptions about integrated PCM plugins look to \ref pcm_plugins.
498 \subsection pcm_dev_names_default Default device
500 The default device is equal to plug plugin with hw plugin as slave. The defaults are
505 defaults.pcm.device 0
506 defaults.pcm.subdevice -1
509 These defaults can be freely overwritten in local configuration files.
517 \subsection pcm_dev_names_hw HW device
519 The hw device description uses the hw plugin. The three arguments (in order: CARD,DEV,SUBDEV)
520 specify card number or identifier, device number and subdevice number (-1 means any).
530 hw:DEV=1,CARD=soundwave,SUBDEV=2
533 \subsection pcm_dev_names_plughw Plug->HW device
535 The plughw device description uses the plug plugin and hw plugin as slave. The arguments
536 are same as for hw device.
546 plughw:DEV=1,CARD=soundwave,SUBDEV=2
549 \subsection pcm_dev_names_plug Plug device
551 The plug device uses the plug plugin. The one SLAVE argument specifies the slave plugin.
562 \subsection pcm_dev_names_shm Shared memory device
564 The shm device uses the shm plugin. The two arguments (in order: SOCKET,PCM) specify
565 UNIX socket name (for example /tmp/alsa.socket) for server communication and server's PCM name.
570 shm:'/tmp/alsa.sock',default
571 shm:SOCKET='/tmp/alsa.sock',PCM=default
574 \subsection pcm_dev_names_tee Tee device
576 The tee device stores contents of a stream to given file plus transfers it to given slave plugin.
577 The three arguments (in order: SLAVE,FILE,FORMAT) specify slave plugin, filename and file format.
582 tee:hw,'/tmp/out.raw',raw
585 \subsection pcm_dev_names_file File device
587 The file device is file plugin with null plugin as slave. The arguments (in order: FILE,FORMAT)
588 specify filename and file format.
593 file:'/tmp/out.raw',raw
596 \subsection pcm_dev_names_null Null device
598 The null device is null plugin. This device has not any arguments.
601 \section pcm_examples Examples
603 The full featured examples with cross-links can be found in Examples section
606 \anchor example_test_pcm
607 \par Sine-wave generator
609 alsa-lib/test/pcm.c example shows various transfer methods for the playback direction.
611 \par Minimalistic PCM playback code
613 alsa-lib/test/pcm_min.c example shows the minimal code to produce a sound.
615 \par Latency measuring tool
617 alsa-lib/test/latency.c example shows the measuring of minimal latency between capture and
623 \example ../../test/pcm.c
626 \example ../../test/pcm_min.c
629 \example ../../test/latency.c
637 #include <sys/poll.h>
639 #include <sys/mman.h>
641 #include "pcm_local.h"
644 * \brief get identifier of PCM handle
645 * \param pcm PCM handle
646 * \return ascii identifier of PCM handle
648 * Returns the ASCII identifier of given PCM handle. It's the same
649 * identifier specified in snd_pcm_open().
651 const char *snd_pcm_name(snd_pcm_t *pcm)
658 * \brief get type of PCM handle
659 * \param pcm PCM handle
660 * \return type of PCM handle
662 * Returns the type #snd_pcm_type_t of given PCM handle.
664 snd_pcm_type_t snd_pcm_type(snd_pcm_t *pcm)
671 * \brief get stream for a PCM handle
672 * \param pcm PCM handle
673 * \return stream of PCM handle
675 * Returns the type #snd_pcm_stream_t of given PCM handle.
677 snd_pcm_stream_t snd_pcm_stream(snd_pcm_t *pcm)
684 * \brief close PCM handle
685 * \param pcm PCM handle
686 * \return 0 on success otherwise a negative error code
688 * Closes the specified PCM handle and frees all associated
691 int snd_pcm_close(snd_pcm_t *pcm)
695 if (pcm->setup && !pcm->donot_close) {
697 err = snd_pcm_hw_free(pcm);
701 if (pcm->mmap_channels)
703 while (!list_empty(&pcm->async_handlers)) {
704 snd_async_handler_t *h = list_entry(pcm->async_handlers.next, snd_async_handler_t, hlist);
705 snd_async_del_handler(h);
707 err = pcm->ops->close(pcm->op_arg);
710 err = snd_pcm_free(pcm);
717 * \brief set nonblock mode
718 * \param pcm PCM handle
719 * \param nonblock 0 = block, 1 = nonblock mode
720 * \return 0 on success otherwise a negative error code
722 int snd_pcm_nonblock(snd_pcm_t *pcm, int nonblock)
726 if ((err = pcm->ops->nonblock(pcm->op_arg, nonblock)) < 0)
729 pcm->mode |= SND_PCM_NONBLOCK;
731 pcm->mode &= ~SND_PCM_NONBLOCK;
737 * \brief set async mode
738 * \param pcm PCM handle
739 * \param sig Signal to raise: < 0 disable, 0 default (SIGIO)
740 * \param pid Process ID to signal: 0 current
741 * \return 0 on success otherwise a negative error code
743 * A signal is raised every period.
745 int snd_pcm_async(snd_pcm_t *pcm, int sig, pid_t pid)
752 return pcm->ops->async(pcm->op_arg, sig, pid);
757 * \brief Obtain general (static) information for PCM handle
758 * \param pcm PCM handle
759 * \param info Information container
760 * \return 0 on success otherwise a negative error code
762 int snd_pcm_info(snd_pcm_t *pcm, snd_pcm_info_t *info)
765 return pcm->ops->info(pcm->op_arg, info);
768 /** \brief Retreive current PCM hardware configuration chosen with #snd_pcm_hw_params
769 * \param pcm PCM handle
770 * \param params Configuration space definition container
771 * \return 0 on success otherwise a negative error code
773 int snd_pcm_hw_params_current(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
775 unsigned int frame_bits;
777 assert(pcm && params);
780 memset(params, 0, snd_pcm_hw_params_sizeof());
781 params->flags = pcm->hw_flags;
782 snd_mask_set(¶ms->masks[SND_PCM_HW_PARAM_ACCESS - SND_PCM_HW_PARAM_FIRST_MASK], pcm->access);
783 snd_mask_set(¶ms->masks[SND_PCM_HW_PARAM_FORMAT - SND_PCM_HW_PARAM_FIRST_MASK], pcm->format);
784 snd_mask_set(¶ms->masks[SND_PCM_HW_PARAM_SUBFORMAT - SND_PCM_HW_PARAM_FIRST_MASK], pcm->subformat);
785 frame_bits = snd_pcm_format_physical_width(pcm->format) * pcm->channels;
786 snd_interval_set_value(¶ms->intervals[SND_PCM_HW_PARAM_FRAME_BITS - SND_PCM_HW_PARAM_FIRST_INTERVAL], frame_bits);
787 snd_interval_set_value(¶ms->intervals[SND_PCM_HW_PARAM_CHANNELS - SND_PCM_HW_PARAM_FIRST_INTERVAL], pcm->channels);
788 snd_interval_set_value(¶ms->intervals[SND_PCM_HW_PARAM_RATE - SND_PCM_HW_PARAM_FIRST_INTERVAL], pcm->rate);
789 snd_interval_set_value(¶ms->intervals[SND_PCM_HW_PARAM_PERIOD_TIME - SND_PCM_HW_PARAM_FIRST_INTERVAL], pcm->period_time);
790 snd_interval_set_value(¶ms->intervals[SND_PCM_HW_PARAM_PERIOD_SIZE - SND_PCM_HW_PARAM_FIRST_INTERVAL], pcm->period_size);
791 snd_interval_copy(¶ms->intervals[SND_PCM_HW_PARAM_PERIODS - SND_PCM_HW_PARAM_FIRST_INTERVAL], &pcm->periods);
792 snd_interval_copy(¶ms->intervals[SND_PCM_HW_PARAM_BUFFER_TIME - SND_PCM_HW_PARAM_FIRST_INTERVAL], &pcm->buffer_time);
793 snd_interval_set_value(¶ms->intervals[SND_PCM_HW_PARAM_BUFFER_SIZE - SND_PCM_HW_PARAM_FIRST_INTERVAL], pcm->buffer_size);
794 snd_interval_set_value(¶ms->intervals[SND_PCM_HW_PARAM_BUFFER_BYTES - SND_PCM_HW_PARAM_FIRST_INTERVAL], (pcm->buffer_size * frame_bits) / 8);
795 snd_interval_set_value(¶ms->intervals[SND_PCM_HW_PARAM_TICK_TIME - SND_PCM_HW_PARAM_FIRST_INTERVAL], pcm->tick_time);
796 params->info = pcm->info;
797 params->msbits = pcm->msbits;
798 params->rate_num = pcm->rate_num;
799 params->rate_den = pcm->rate_den;
800 params->fifo_size = pcm->fifo_size;
804 /** \brief Install one PCM hardware configuration chosen from a configuration space and #snd_pcm_prepare it
805 * \param pcm PCM handle
806 * \param params Configuration space definition container
807 * \return 0 on success otherwise a negative error code
809 * The configuration is chosen fixing single parameters in this order:
810 * first access, first format, first subformat, min channels, min rate,
811 * min period time, max buffer size, min tick time
813 * After this call, #snd_pcm_prepare() is called automatically and
814 * the stream is brought to \c #SND_PCM_STATE_PREPARED state.
816 * The hardware parameters cannot be changed when the stream is
817 * running (active). The software parameters can be changed
820 int snd_pcm_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
823 assert(pcm && params);
824 err = _snd_pcm_hw_params(pcm, params);
827 err = snd_pcm_prepare(pcm);
831 /** \brief Remove PCM hardware configuration and free associated resources
832 * \param pcm PCM handle
833 * \return 0 on success otherwise a negative error code
835 int snd_pcm_hw_free(snd_pcm_t *pcm)
840 if (pcm->mmap_channels) {
841 err = snd_pcm_munmap(pcm);
845 // assert(snd_pcm_state(pcm) == SND_PCM_STATE_SETUP ||
846 // snd_pcm_state(pcm) == SND_PCM_STATE_PREPARED);
847 err = pcm->ops->hw_free(pcm->op_arg);
854 /** \brief Install PCM software configuration defined by params
855 * \param pcm PCM handle
856 * \param params Configuration container
857 * \return 0 on success otherwise a negative error code
859 * The software parameters can be changed at any time.
860 * The hardware parameters cannot be changed when the stream is
863 int snd_pcm_sw_params(snd_pcm_t *pcm, snd_pcm_sw_params_t *params)
866 /* the hw_params must be set at first!!! */
867 if (CHECK_SANITY(! pcm->setup)) {
868 SNDMSG("PCM not set up");
871 if (! params->avail_min) {
872 SNDMSG("params->avail_min is 0");
875 if (! params->xfer_align) {
876 SNDMSG("params->xfer_align is 0");
880 /* disable the check below - it looks too restrictive
881 * (start_threshold is basically independent from avail_min)
883 if (params->start_threshold <= pcm->buffer_size &&
884 params->start_threshold > (pcm->buffer_size / params->avail_min) * params->avail_min) {
885 SNDMSG("params->avail_min problem for start_threshold");
889 if (params->start_threshold <= pcm->buffer_size &&
890 params->start_threshold > (pcm->buffer_size / params->xfer_align) * params->xfer_align) {
891 SNDMSG("params->xfer_align problem for start_threshold");
894 err = pcm->ops->sw_params(pcm->op_arg, params);
897 pcm->tstamp_mode = params->tstamp_mode;
898 pcm->period_step = params->period_step;
899 pcm->sleep_min = params->sleep_min;
900 pcm->avail_min = params->avail_min;
901 pcm->xfer_align = params->xfer_align;
902 pcm->start_threshold = params->start_threshold;
903 pcm->stop_threshold = params->stop_threshold;
904 pcm->silence_threshold = params->silence_threshold;
905 pcm->silence_size = params->silence_size;
906 pcm->boundary = params->boundary;
911 * \brief Obtain status (runtime) information for PCM handle
912 * \param pcm PCM handle
913 * \param status Status container
914 * \return 0 on success otherwise a negative error code
916 int snd_pcm_status(snd_pcm_t *pcm, snd_pcm_status_t *status)
918 assert(pcm && status);
919 return pcm->fast_ops->status(pcm->fast_op_arg, status);
923 * \brief Return PCM state
924 * \param pcm PCM handle
925 * \return PCM state #snd_pcm_state_t of given PCM handle
927 * This is a faster way to obtain only the PCM state without calling
928 * \link ::snd_pcm_status() \endlink.
930 snd_pcm_state_t snd_pcm_state(snd_pcm_t *pcm)
933 return pcm->fast_ops->state(pcm->fast_op_arg);
937 * \brief Synchronize stream position with hardware
938 * \param pcm PCM handle
939 * \return 0 on success otherwise a negative error code
941 * Note this function does not update the actual r/w pointer
942 * for applications. The function #snd_pcm_avail_update()
943 * have to be called before any mmap begin+commit operation.
945 int snd_pcm_hwsync(snd_pcm_t *pcm)
948 if (CHECK_SANITY(! pcm->setup)) {
949 SNDMSG("PCM not set up");
952 return pcm->fast_ops->hwsync(pcm->fast_op_arg);
956 * \brief Obtain delay for a running PCM handle
957 * \param pcm PCM handle
958 * \param delayp Returned delay in frames
959 * \return 0 on success otherwise a negative error code
961 * Delay is distance between current application frame position and
962 * sound frame position.
963 * It's positive and less than buffer size in normal situation,
964 * negative on playback underrun and greater than buffer size on
967 * Note this function does not update the actual r/w pointer
968 * for applications. The function #snd_pcm_avail_update()
969 * have to be called before any begin+commit operation.
971 int snd_pcm_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp)
974 if (CHECK_SANITY(! pcm->setup)) {
975 SNDMSG("PCM not set up");
978 return pcm->fast_ops->delay(pcm->fast_op_arg, delayp);
982 * \brief Resume from suspend, no samples are lost
983 * \param pcm PCM handle
984 * \return 0 on success otherwise a negative error code
985 * \retval -EAGAIN resume can't be proceed immediately (audio hardware is probably still suspended)
986 * \retval -ENOSYS hardware doesn't support this feature
988 * This function can be used when the stream is in the suspend state
989 * to do the fine resume from this state. Not all hardware supports
990 * this feature, when an -ENOSYS error is returned, use the \link ::snd_pcm_prepare() \endlink
991 * function to recovery.
993 int snd_pcm_resume(snd_pcm_t *pcm)
996 if (CHECK_SANITY(! pcm->setup)) {
997 SNDMSG("PCM not set up");
1000 return pcm->fast_ops->resume(pcm->fast_op_arg);
1004 * \brief Prepare PCM for use
1005 * \param pcm PCM handle
1006 * \return 0 on success otherwise a negative error code
1008 int snd_pcm_prepare(snd_pcm_t *pcm)
1011 if (CHECK_SANITY(! pcm->setup)) {
1012 SNDMSG("PCM not set up");
1015 return pcm->fast_ops->prepare(pcm->fast_op_arg);
1019 * \brief Reset PCM position
1020 * \param pcm PCM handle
1021 * \return 0 on success otherwise a negative error code
1023 * Reduce PCM delay to 0.
1025 int snd_pcm_reset(snd_pcm_t *pcm)
1028 if (CHECK_SANITY(! pcm->setup)) {
1029 SNDMSG("PCM not set up");
1032 return pcm->fast_ops->reset(pcm->fast_op_arg);
1036 * \brief Start a PCM
1037 * \param pcm PCM handle
1038 * \return 0 on success otherwise a negative error code
1040 int snd_pcm_start(snd_pcm_t *pcm)
1043 if (CHECK_SANITY(! pcm->setup)) {
1044 SNDMSG("PCM not set up");
1047 return pcm->fast_ops->start(pcm->fast_op_arg);
1051 * \brief Stop a PCM dropping pending frames
1052 * \param pcm PCM handle
1053 * \return 0 on success otherwise a negative error code
1055 * This function stops the PCM <i>immediately</i>.
1056 * The pending samples on the buffer are ignored.
1058 * For processing all pending samples, use \link ::snd_pcm_drain() \endlink
1061 int snd_pcm_drop(snd_pcm_t *pcm)
1064 if (CHECK_SANITY(! pcm->setup)) {
1065 SNDMSG("PCM not set up");
1068 return pcm->fast_ops->drop(pcm->fast_op_arg);
1072 * \brief Stop a PCM preserving pending frames
1073 * \param pcm PCM handle
1074 * \return 0 on success otherwise a negative error code
1075 * \retval -ESTRPIPE a suspend event occurred
1077 * For playback wait for all pending frames to be played and then stop
1079 * For capture stop PCM permitting to retrieve residual frames.
1081 * For stopping the PCM stream immediately, use \link ::snd_pcm_drop() \endlink
1084 int snd_pcm_drain(snd_pcm_t *pcm)
1087 if (CHECK_SANITY(! pcm->setup)) {
1088 SNDMSG("PCM not set up");
1091 return pcm->fast_ops->drain(pcm->fast_op_arg);
1095 * \brief Pause/resume PCM
1096 * \param pcm PCM handle
1097 * \param enable 0 = resume, 1 = pause
1098 * \return 0 on success otherwise a negative error code
1100 * Note that this function works only on the hardware which supports
1101 * pause feature. You can check it via \link ::snd_pcm_hw_params_can_pause() \endlink
1104 int snd_pcm_pause(snd_pcm_t *pcm, int enable)
1107 if (CHECK_SANITY(! pcm->setup)) {
1108 SNDMSG("PCM not set up");
1111 return pcm->fast_ops->pause(pcm->fast_op_arg, enable);
1115 * \brief Move application frame position backward
1116 * \param pcm PCM handle
1117 * \param frames wanted displacement in frames
1118 * \return a positive number for actual displacement otherwise a
1119 * negative error code
1121 snd_pcm_sframes_t snd_pcm_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
1124 if (CHECK_SANITY(! pcm->setup)) {
1125 SNDMSG("PCM not set up");
1130 return pcm->fast_ops->rewind(pcm->fast_op_arg, frames);
1134 * \brief Move application frame position forward
1135 * \param pcm PCM handle
1136 * \param frames wanted skip in frames
1137 * \return a positive number for actual skip otherwise a negative error code
1138 * \retval 0 means no action
1141 snd_pcm_sframes_t INTERNAL(snd_pcm_forward)(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
1143 snd_pcm_sframes_t snd_pcm_forward(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
1147 if (CHECK_SANITY(! pcm->setup)) {
1148 SNDMSG("PCM not set up");
1153 return pcm->fast_ops->forward(pcm->fast_op_arg, frames);
1155 use_default_symbol_version(__snd_pcm_forward, snd_pcm_forward, ALSA_0.9.0rc8);
1158 * \brief Write interleaved frames to a PCM
1159 * \param pcm PCM handle
1160 * \param buffer frames containing buffer
1161 * \param size frames to be written
1162 * \return a positive number of frames actually written otherwise a
1163 * negative error code
1164 * \retval -EBADFD PCM is not in the right state (#SND_PCM_STATE_PREPARED or #SND_PCM_STATE_RUNNING)
1165 * \retval -EPIPE an underrun occurred
1166 * \retval -ESTRPIPE a suspend event occurred (stream is suspended and waiting for an application recovery)
1168 * If the blocking behaviour is selected, then routine waits until
1169 * all requested bytes are played or put to the playback ring buffer.
1170 * The count of bytes can be less only if a signal or underrun occurred.
1172 * If the non-blocking behaviour is selected, then routine doesn't wait at all.
1174 snd_pcm_sframes_t snd_pcm_writei(snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size)
1177 assert(size == 0 || buffer);
1178 if (CHECK_SANITY(! pcm->setup)) {
1179 SNDMSG("PCM not set up");
1182 if (pcm->access != SND_PCM_ACCESS_RW_INTERLEAVED) {
1183 SNDMSG("invalid access type %s", snd_pcm_access_name(pcm->access));
1186 return _snd_pcm_writei(pcm, buffer, size);
1190 * \brief Write non interleaved frames to a PCM
1191 * \param pcm PCM handle
1192 * \param bufs frames containing buffers (one for each channel)
1193 * \param size frames to be written
1194 * \return a positive number of frames actually written otherwise a
1195 * negative error code
1196 * \retval -EBADFD PCM is not in the right state (#SND_PCM_STATE_PREPARED or #SND_PCM_STATE_RUNNING)
1197 * \retval -EPIPE an underrun occurred
1198 * \retval -ESTRPIPE a suspend event occurred (stream is suspended and waiting for an application recovery)
1200 * If the blocking behaviour is selected, then routine waits until
1201 * all requested bytes are played or put to the playback ring buffer.
1202 * The count of bytes can be less only if a signal or underrun occurred.
1204 * If the non-blocking behaviour is selected, then routine doesn't wait at all.
1206 snd_pcm_sframes_t snd_pcm_writen(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size)
1209 assert(size == 0 || bufs);
1210 if (CHECK_SANITY(! pcm->setup)) {
1211 SNDMSG("PCM not set up");
1214 if (pcm->access != SND_PCM_ACCESS_RW_NONINTERLEAVED) {
1215 SNDMSG("invalid access type %s", snd_pcm_access_name(pcm->access));
1218 return _snd_pcm_writen(pcm, bufs, size);
1222 * \brief Read interleaved frames from a PCM
1223 * \param pcm PCM handle
1224 * \param buffer frames containing buffer
1225 * \param size frames to be written
1226 * \return a positive number of frames actually read otherwise a
1227 * negative error code
1228 * \retval -EBADFD PCM is not in the right state (#SND_PCM_STATE_PREPARED or #SND_PCM_STATE_RUNNING)
1229 * \retval -EPIPE an overrun occurred
1230 * \retval -ESTRPIPE a suspend event occurred (stream is suspended and waiting for an application recovery)
1232 * If the blocking behaviour was selected, then routine waits until
1233 * all requested bytes are filled. The count of bytes can be less only
1234 * if a signal or underrun occurred.
1236 * If the non-blocking behaviour is selected, then routine doesn't wait at all.
1238 snd_pcm_sframes_t snd_pcm_readi(snd_pcm_t *pcm, void *buffer, snd_pcm_uframes_t size)
1241 assert(size == 0 || buffer);
1242 if (CHECK_SANITY(! pcm->setup)) {
1243 SNDMSG("PCM not set up");
1246 if (pcm->access != SND_PCM_ACCESS_RW_INTERLEAVED) {
1247 SNDMSG("invalid access type %s", snd_pcm_access_name(pcm->access));
1250 return _snd_pcm_readi(pcm, buffer, size);
1254 * \brief Read non interleaved frames to a PCM
1255 * \param pcm PCM handle
1256 * \param bufs frames containing buffers (one for each channel)
1257 * \param size frames to be written
1258 * \return a positive number of frames actually read otherwise a
1259 * negative error code
1260 * \retval -EBADFD PCM is not in the right state (#SND_PCM_STATE_PREPARED or #SND_PCM_STATE_RUNNING)
1261 * \retval -EPIPE an overrun occurred
1262 * \retval -ESTRPIPE a suspend event occurred (stream is suspended and waiting for an application recovery)
1264 * If the blocking behaviour was selected, then routine waits until
1265 * all requested bytes are filled. The count of bytes can be less only
1266 * if a signal or underrun occurred.
1268 * If the non-blocking behaviour is selected, then routine doesn't wait at all.
1270 snd_pcm_sframes_t snd_pcm_readn(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size)
1273 assert(size == 0 || bufs);
1274 if (CHECK_SANITY(! pcm->setup)) {
1275 SNDMSG("PCM not set up");
1278 if (pcm->access != SND_PCM_ACCESS_RW_NONINTERLEAVED) {
1279 SNDMSG("invalid access type %s", snd_pcm_access_name(pcm->access));
1282 return _snd_pcm_readn(pcm, bufs, size);
1286 * \brief Link two PCMs
1287 * \param pcm1 first PCM handle
1288 * \param pcm2 first PCM handle
1289 * \return 0 on success otherwise a negative error code
1291 * The two PCMs will start/stop/prepare in sync.
1293 int snd_pcm_link(snd_pcm_t *pcm1, snd_pcm_t *pcm2)
1297 if (pcm1->fast_ops->link)
1298 return pcm1->fast_ops->link(pcm1, pcm2);
1303 * \brief Remove a PCM from a linked group
1304 * \param pcm PCM handle
1305 * \return 0 on success otherwise a negative error code
1307 int snd_pcm_unlink(snd_pcm_t *pcm)
1310 if (pcm->fast_ops->unlink)
1311 return pcm->fast_ops->unlink(pcm);
1316 * \brief get count of poll descriptors for PCM handle
1317 * \param pcm PCM handle
1318 * \return count of poll descriptors
1320 int snd_pcm_poll_descriptors_count(snd_pcm_t *pcm)
1323 if (pcm->fast_ops->poll_descriptors_count)
1324 return pcm->fast_ops->poll_descriptors_count(pcm->fast_op_arg);
1325 return pcm->poll_fd_count;
1330 * \brief get poll descriptors
1331 * \param pcm PCM handle
1332 * \param pfds array of poll descriptors
1333 * \param space space in the poll descriptor array
1334 * \return count of filled descriptors
1336 * This function fills the given poll descriptor structs for the specified
1337 * PCM handle. The poll desctiptor array should have the size returned by
1338 * \link ::snd_pcm_poll_descriptors_count() \endlink function.
1340 * The result is intended for direct use with the poll() syscall.
1342 * For reading the returned events of poll descriptor after poll() system
1343 * call, use \link ::snd_pcm_poll_descriptors_revents() \endlink function.
1344 * The field values in pollfd structs may be bogus regarding the stream
1345 * direction from the application perspective (POLLIN might not imply read
1346 * direction and POLLOUT might not imply write), but
1347 * the \link ::snd_pcm_poll_descriptors_revents() \endlink function
1348 * does the right "demangling".
1350 * You can use output from this function as arguments for the select()
1353 int snd_pcm_poll_descriptors(snd_pcm_t *pcm, struct pollfd *pfds, unsigned int space)
1355 assert(pcm && pfds);
1356 if (pcm->fast_ops->poll_descriptors)
1357 return pcm->fast_ops->poll_descriptors(pcm->fast_op_arg, pfds, space);
1358 if (pcm->poll_fd < 0) {
1359 SNDMSG("poll_fd < 0");
1362 if (space >= 1 && pfds) {
1363 pfds->fd = pcm->poll_fd;
1364 pfds->events = pcm->poll_events | POLLERR | POLLNVAL;
1372 * \brief get returned events from poll descriptors
1373 * \param pcm PCM handle
1374 * \param pfds array of poll descriptors
1375 * \param nfds count of poll descriptors
1376 * \param revents returned events
1377 * \return zero if success, otherwise a negative error code
1379 * This function does "demangling" of the revents mask returned from
1380 * the poll() syscall to correct semantics (POLLIN = read, POLLOUT = write).
1382 * Note: The null event also exists. Even if poll() or select()
1383 * syscall returned that some events are waiting, this function might
1384 * return empty set of events. In this case, application should
1385 * do next event waiting using poll() or select().
1387 int snd_pcm_poll_descriptors_revents(snd_pcm_t *pcm, struct pollfd *pfds, unsigned int nfds, unsigned short *revents)
1389 assert(pcm && pfds && revents);
1390 if (pcm->fast_ops->poll_revents)
1391 return pcm->fast_ops->poll_revents(pcm->fast_op_arg, pfds, nfds, revents);
1393 *revents = pfds->revents;
1400 #define PCMTYPE(v) [SND_PCM_TYPE_##v] = #v
1401 #define STATE(v) [SND_PCM_STATE_##v] = #v
1402 #define STREAM(v) [SND_PCM_STREAM_##v] = #v
1403 #define READY(v) [SND_PCM_READY_##v] = #v
1404 #define XRUN(v) [SND_PCM_XRUN_##v] = #v
1405 #define SILENCE(v) [SND_PCM_SILENCE_##v] = #v
1406 #define TSTAMP(v) [SND_PCM_TSTAMP_##v] = #v
1407 #define ACCESS(v) [SND_PCM_ACCESS_##v] = #v
1408 #define START(v) [SND_PCM_START_##v] = #v
1409 #define HW_PARAM(v) [SND_PCM_HW_PARAM_##v] = #v
1410 #define SW_PARAM(v) [SND_PCM_SW_PARAM_##v] = #v
1411 #define FORMAT(v) [SND_PCM_FORMAT_##v] = #v
1412 #define SUBFORMAT(v) [SND_PCM_SUBFORMAT_##v] = #v
1414 #define FORMATD(v, d) [SND_PCM_FORMAT_##v] = d
1415 #define SUBFORMATD(v, d) [SND_PCM_SUBFORMAT_##v] = d
1418 static const char *snd_pcm_stream_names[] = {
1423 static const char *snd_pcm_state_names[] = {
1432 STATE(DISCONNECTED),
1435 static const char *snd_pcm_access_names[] = {
1436 ACCESS(MMAP_INTERLEAVED),
1437 ACCESS(MMAP_NONINTERLEAVED),
1438 ACCESS(MMAP_COMPLEX),
1439 ACCESS(RW_INTERLEAVED),
1440 ACCESS(RW_NONINTERLEAVED),
1443 static const char *snd_pcm_format_names[] = {
1462 FORMAT(IEC958_SUBFRAME_LE),
1463 FORMAT(IEC958_SUBFRAME_BE),
1484 static const char *snd_pcm_format_aliases[SND_PCM_FORMAT_LAST+1] = {
1493 FORMAT(IEC958_SUBFRAME),
1496 static const char *snd_pcm_format_descriptions[] = {
1497 FORMATD(S8, "Signed 8 bit"),
1498 FORMATD(U8, "Unsigned 8 bit"),
1499 FORMATD(S16_LE, "Signed 16 bit Little Endian"),
1500 FORMATD(S16_BE, "Signed 16 bit Big Endian"),
1501 FORMATD(U16_LE, "Unsigned 16 bit Little Endian"),
1502 FORMATD(U16_BE, "Unsigned 16 bit Big Endian"),
1503 FORMATD(S24_LE, "Signed 24 bit Little Endian"),
1504 FORMATD(S24_BE, "Signed 24 bit Big Endian"),
1505 FORMATD(U24_LE, "Unsigned 24 bit Little Endian"),
1506 FORMATD(U24_BE, "Unsigned 24 bit Big Endian"),
1507 FORMATD(S32_LE, "Signed 32 bit Little Endian"),
1508 FORMATD(S32_BE, "Signed 32 bit Big Endian"),
1509 FORMATD(U32_LE, "Unsigned 32 bit Little Endian"),
1510 FORMATD(U32_BE, "Unsigned 32 bit Big Endian"),
1511 FORMATD(FLOAT_LE, "Float 32 bit Little Endian"),
1512 FORMATD(FLOAT_BE, "Float 32 bit Big Endian"),
1513 FORMATD(FLOAT64_LE, "Float 64 bit Little Endian"),
1514 FORMATD(FLOAT64_BE, "Float 64 bit Big Endian"),
1515 FORMATD(IEC958_SUBFRAME_LE, "IEC-958 Little Endian"),
1516 FORMATD(IEC958_SUBFRAME_BE, "IEC-958 Big Endian"),
1517 FORMATD(MU_LAW, "Mu-Law"),
1518 FORMATD(A_LAW, "A-Law"),
1519 FORMATD(IMA_ADPCM, "Ima-ADPCM"),
1520 FORMATD(MPEG, "MPEG"),
1521 FORMATD(GSM, "GSM"),
1522 FORMATD(SPECIAL, "Special"),
1523 FORMATD(S24_3LE, "Signed 24 bit Little Endian in 3bytes"),
1524 FORMATD(S24_3BE, "Signed 24 bit Big Endian in 3bytes"),
1525 FORMATD(U24_3LE, "Unsigned 24 bit Little Endian in 3bytes"),
1526 FORMATD(U24_3BE, "Unsigned 24 bit Big Endian in 3bytes"),
1527 FORMATD(S20_3LE, "Signed 20 bit Little Endian in 3bytes"),
1528 FORMATD(S20_3BE, "Signed 20 bit Big Endian in 3bytes"),
1529 FORMATD(U20_3LE, "Unsigned 20 bit Little Endian in 3bytes"),
1530 FORMATD(U20_3BE, "Unsigned 20 bit Big Endian in 3bytes"),
1531 FORMATD(S18_3LE, "Signed 18 bit Little Endian in 3bytes"),
1532 FORMATD(S18_3BE, "Signed 18 bit Big Endian in 3bytes"),
1533 FORMATD(U18_3LE, "Unsigned 18 bit Little Endian in 3bytes"),
1534 FORMATD(U18_3BE, "Unsigned 18 bit Big Endian in 3bytes"),
1537 static const char *snd_pcm_type_names[] = {
1558 PCMTYPE(LINEAR_FLOAT),
1569 static const char *snd_pcm_subformat_names[] = {
1573 static const char *snd_pcm_subformat_descriptions[] = {
1574 SUBFORMATD(STD, "Standard"),
1577 static const char *snd_pcm_start_mode_names[] = {
1582 static const char *snd_pcm_xrun_mode_names[] = {
1587 static const char *snd_pcm_tstamp_mode_names[] = {
1594 * \brief get name of PCM stream type
1595 * \param stream PCM stream type
1596 * \return ascii name of PCM stream type
1598 const char *snd_pcm_stream_name(snd_pcm_stream_t stream)
1600 if (stream > SND_PCM_STREAM_LAST)
1602 return snd_pcm_stream_names[stream];
1606 * \brief get name of PCM access type
1607 * \param acc PCM access type
1608 * \return ascii name of PCM access type
1610 const char *snd_pcm_access_name(snd_pcm_access_t acc)
1612 if (acc > SND_PCM_ACCESS_LAST)
1614 return snd_pcm_access_names[acc];
1618 * \brief get name of PCM sample format
1619 * \param format PCM sample format
1620 * \return ascii name of PCM sample format
1622 const char *snd_pcm_format_name(snd_pcm_format_t format)
1624 if (format > SND_PCM_FORMAT_LAST)
1626 return snd_pcm_format_names[format];
1630 * \brief get description of PCM sample format
1631 * \param format PCM sample format
1632 * \return ascii description of PCM sample format
1634 const char *snd_pcm_format_description(snd_pcm_format_t format)
1636 if (format > SND_PCM_FORMAT_LAST)
1638 return snd_pcm_format_descriptions[format];
1642 * \brief get PCM sample format from name
1643 * \param name PCM sample format name (case insensitive)
1644 * \return PCM sample format
1646 snd_pcm_format_t snd_pcm_format_value(const char* name)
1648 snd_pcm_format_t format;
1649 for (format = 0; format <= SND_PCM_FORMAT_LAST; format++) {
1650 if (snd_pcm_format_names[format] &&
1651 strcasecmp(name, snd_pcm_format_names[format]) == 0) {
1654 if (snd_pcm_format_aliases[format] &&
1655 strcasecmp(name, snd_pcm_format_aliases[format]) == 0) {
1659 for (format = 0; format <= SND_PCM_FORMAT_LAST; format++) {
1660 if (snd_pcm_format_descriptions[format] &&
1661 strcasecmp(name, snd_pcm_format_descriptions[format]) == 0) {
1665 return SND_PCM_FORMAT_UNKNOWN;
1669 * \brief get name of PCM sample subformat
1670 * \param subformat PCM sample subformat
1671 * \return ascii name of PCM sample subformat
1673 const char *snd_pcm_subformat_name(snd_pcm_subformat_t subformat)
1675 if (subformat > SND_PCM_SUBFORMAT_LAST)
1677 return snd_pcm_subformat_names[subformat];
1681 * \brief get description of PCM sample subformat
1682 * \param subformat PCM sample subformat
1683 * \return ascii description of PCM sample subformat
1685 const char *snd_pcm_subformat_description(snd_pcm_subformat_t subformat)
1687 if (subformat > SND_PCM_SUBFORMAT_LAST)
1689 return snd_pcm_subformat_descriptions[subformat];
1693 * \brief (DEPRECATED) get name of PCM start mode setting
1694 * \param mode PCM start mode
1695 * \return ascii name of PCM start mode setting
1697 const char *snd_pcm_start_mode_name(snd_pcm_start_t mode)
1699 if (mode > SND_PCM_START_LAST)
1701 return snd_pcm_start_mode_names[mode];
1705 link_warning(snd_pcm_start_mode_name, "Warning: start_mode is deprecated, consider to use start_threshold");
1709 * \brief (DEPRECATED) get name of PCM xrun mode setting
1710 * \param mode PCM xrun mode
1711 * \return ascii name of PCM xrun mode setting
1713 const char *snd_pcm_xrun_mode_name(snd_pcm_xrun_t mode)
1715 if (mode > SND_PCM_XRUN_LAST)
1717 return snd_pcm_xrun_mode_names[mode];
1721 link_warning(snd_pcm_xrun_mode_name, "Warning: xrun_mode is deprecated, consider to use stop_threshold");
1725 * \brief get name of PCM tstamp mode setting
1726 * \param mode PCM tstamp mode
1727 * \return ascii name of PCM tstamp mode setting
1729 const char *snd_pcm_tstamp_mode_name(snd_pcm_tstamp_t mode)
1731 if (mode > SND_PCM_TSTAMP_LAST)
1733 return snd_pcm_tstamp_mode_names[mode];
1737 * \brief get name of PCM state
1738 * \param state PCM state
1739 * \return ascii name of PCM state
1741 const char *snd_pcm_state_name(snd_pcm_state_t state)
1743 if (state > SND_PCM_STATE_LAST)
1745 return snd_pcm_state_names[state];
1749 * \brief get name of PCM type
1750 * \param type PCM type
1751 * \return ascii name of PCM type
1754 const char *INTERNAL(snd_pcm_type_name)(snd_pcm_type_t type)
1756 const char *snd_pcm_type_name(snd_pcm_type_t type)
1759 if (type > SND_PCM_TYPE_LAST)
1761 return snd_pcm_type_names[type];
1763 use_default_symbol_version(__snd_pcm_type_name, snd_pcm_type_name, ALSA_0.9.0);
1766 * \brief Dump current hardware setup for PCM
1767 * \param pcm PCM handle
1768 * \param out Output handle
1769 * \return 0 on success otherwise a negative error code
1771 int snd_pcm_dump_hw_setup(snd_pcm_t *pcm, snd_output_t *out)
1775 if (CHECK_SANITY(! pcm->setup)) {
1776 SNDMSG("PCM not set up");
1779 snd_output_printf(out, " stream : %s\n", snd_pcm_stream_name(pcm->stream));
1780 snd_output_printf(out, " access : %s\n", snd_pcm_access_name(pcm->access));
1781 snd_output_printf(out, " format : %s\n", snd_pcm_format_name(pcm->format));
1782 snd_output_printf(out, " subformat : %s\n", snd_pcm_subformat_name(pcm->subformat));
1783 snd_output_printf(out, " channels : %u\n", pcm->channels);
1784 snd_output_printf(out, " rate : %u\n", pcm->rate);
1785 snd_output_printf(out, " exact rate : %g (%u/%u)\n",
1786 (pcm->rate_den ? ((double) pcm->rate_num / pcm->rate_den) : 0.0),
1787 pcm->rate_num, pcm->rate_den);
1788 snd_output_printf(out, " msbits : %u\n", pcm->msbits);
1789 snd_output_printf(out, " buffer_size : %lu\n", pcm->buffer_size);
1790 snd_output_printf(out, " period_size : %lu\n", pcm->period_size);
1791 snd_output_printf(out, " period_time : %u\n", pcm->period_time);
1792 snd_output_printf(out, " tick_time : %u\n", pcm->tick_time);
1797 * \brief Dump current software setup for PCM
1798 * \param pcm PCM handle
1799 * \param out Output handle
1800 * \return 0 on success otherwise a negative error code
1802 int snd_pcm_dump_sw_setup(snd_pcm_t *pcm, snd_output_t *out)
1806 if (CHECK_SANITY(! pcm->setup)) {
1807 SNDMSG("PCM not set up");
1810 snd_output_printf(out, " tstamp_mode : %s\n", snd_pcm_tstamp_mode_name(pcm->tstamp_mode));
1811 snd_output_printf(out, " period_step : %d\n", pcm->period_step);
1812 snd_output_printf(out, " sleep_min : %d\n", pcm->sleep_min);
1813 snd_output_printf(out, " avail_min : %ld\n", pcm->avail_min);
1814 snd_output_printf(out, " xfer_align : %ld\n", pcm->xfer_align);
1815 snd_output_printf(out, " start_threshold : %ld\n", pcm->start_threshold);
1816 snd_output_printf(out, " stop_threshold : %ld\n", pcm->stop_threshold);
1817 snd_output_printf(out, " silence_threshold: %ld\n", pcm->silence_threshold);
1818 snd_output_printf(out, " silence_size : %ld\n", pcm->silence_size);
1819 snd_output_printf(out, " boundary : %ld\n", pcm->boundary);
1824 * \brief Dump current setup (hardware and software) for PCM
1825 * \param pcm PCM handle
1826 * \param out Output handle
1827 * \return 0 on success otherwise a negative error code
1829 int snd_pcm_dump_setup(snd_pcm_t *pcm, snd_output_t *out)
1831 snd_pcm_dump_hw_setup(pcm, out);
1832 snd_pcm_dump_sw_setup(pcm, out);
1837 * \brief Dump status
1838 * \param status Status container
1839 * \param out Output handle
1840 * \return 0 on success otherwise a negative error code
1842 int snd_pcm_status_dump(snd_pcm_status_t *status, snd_output_t *out)
1845 snd_output_printf(out, " state : %s\n", snd_pcm_state_name((snd_pcm_state_t) status->state));
1846 snd_output_printf(out, " trigger_time: %ld.%06ld\n",
1847 status->trigger_tstamp.tv_sec, status->trigger_tstamp.tv_nsec);
1848 snd_output_printf(out, " tstamp : %ld.%06ld\n",
1849 status->tstamp.tv_sec, status->tstamp.tv_nsec);
1850 snd_output_printf(out, " delay : %ld\n", (long)status->delay);
1851 snd_output_printf(out, " avail : %ld\n", (long)status->avail);
1852 snd_output_printf(out, " avail_max : %ld\n", (long)status->avail_max);
1857 * \brief Dump PCM info
1858 * \param pcm PCM handle
1859 * \param out Output handle
1860 * \return 0 on success otherwise a negative error code
1862 int snd_pcm_dump(snd_pcm_t *pcm, snd_output_t *out)
1866 pcm->ops->dump(pcm->op_arg, out);
1871 * \brief Convert bytes in frames for a PCM
1872 * \param pcm PCM handle
1873 * \param bytes quantity in bytes
1874 * \return quantity expressed in frames
1876 snd_pcm_sframes_t snd_pcm_bytes_to_frames(snd_pcm_t *pcm, ssize_t bytes)
1879 if (CHECK_SANITY(! pcm->setup)) {
1880 SNDMSG("PCM not set up");
1883 return bytes * 8 / pcm->frame_bits;
1887 * \brief Convert frames in bytes for a PCM
1888 * \param pcm PCM handle
1889 * \param frames quantity in frames
1890 * \return quantity expressed in bytes
1892 ssize_t snd_pcm_frames_to_bytes(snd_pcm_t *pcm, snd_pcm_sframes_t frames)
1895 if (CHECK_SANITY(! pcm->setup)) {
1896 SNDMSG("PCM not set up");
1899 return frames * pcm->frame_bits / 8;
1903 * \brief Convert bytes in samples for a PCM
1904 * \param pcm PCM handle
1905 * \param bytes quantity in bytes
1906 * \return quantity expressed in samples
1908 long snd_pcm_bytes_to_samples(snd_pcm_t *pcm, ssize_t bytes)
1911 if (CHECK_SANITY(! pcm->setup)) {
1912 SNDMSG("PCM not set up");
1915 return bytes * 8 / pcm->sample_bits;
1919 * \brief Convert samples in bytes for a PCM
1920 * \param pcm PCM handle
1921 * \param samples quantity in samples
1922 * \return quantity expressed in bytes
1924 ssize_t snd_pcm_samples_to_bytes(snd_pcm_t *pcm, long samples)
1927 if (CHECK_SANITY(! pcm->setup)) {
1928 SNDMSG("PCM not set up");
1931 return samples * pcm->sample_bits / 8;
1935 * \brief Add an async handler for a PCM
1936 * \param handler Returned handler handle
1937 * \param pcm PCM handle
1938 * \param callback Callback function
1939 * \param private_data Callback private data
1940 * \return 0 otherwise a negative error code on failure
1942 * The asynchronous callback is called when period boundary elapses.
1944 int snd_async_add_pcm_handler(snd_async_handler_t **handler, snd_pcm_t *pcm,
1945 snd_async_callback_t callback, void *private_data)
1949 snd_async_handler_t *h;
1950 err = snd_async_add_handler(&h, _snd_pcm_async_descriptor(pcm),
1951 callback, private_data);
1954 h->type = SND_ASYNC_HANDLER_PCM;
1956 was_empty = list_empty(&pcm->async_handlers);
1957 list_add_tail(&h->hlist, &pcm->async_handlers);
1959 err = snd_pcm_async(pcm, snd_async_handler_get_signo(h), getpid());
1961 snd_async_del_handler(h);
1970 * \brief Return PCM handle related to an async handler
1971 * \param handler Async handler handle
1972 * \return PCM handle
1974 snd_pcm_t *snd_async_handler_get_pcm(snd_async_handler_t *handler)
1976 if (handler->type != SND_ASYNC_HANDLER_PCM) {
1977 SNDMSG("invalid handler type %d", handler->type);
1980 return handler->u.pcm;
1983 static char *build_in_pcms[] = {
1984 "adpcm", "alaw", "copy", "dmix", "file", "hooks", "hw", "ladspa", "lfloat",
1985 "linear", "meter", "mulaw", "multi", "null", "empty", "plug", "rate", "route", "share",
1986 "shm", "dsnoop", "dshare", "asym", "iec958", "softvol", "mmap_emul",
1990 static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name,
1991 snd_config_t *pcm_root, snd_config_t *pcm_conf,
1992 snd_pcm_stream_t stream, int mode)
1995 char *buf = NULL, *buf1 = NULL;
1997 snd_config_t *conf, *type_conf = NULL;
1998 snd_config_iterator_t i, next;
2000 const char *lib = NULL, *open_name = NULL;
2001 int (*open_func)(snd_pcm_t **, const char *,
2002 snd_config_t *, snd_config_t *,
2003 snd_pcm_stream_t, int) = NULL;
2005 extern void *snd_pcm_open_symbols(void);
2008 if (snd_config_get_type(pcm_conf) != SND_CONFIG_TYPE_COMPOUND) {
2011 snd_config_get_id(pcm_conf, &id);
2013 snd_config_get_ascii(pcm_conf, &val);
2014 SNDERR("Invalid type for PCM %s%sdefinition (id: %s, value: %s)", name ? name : "", name ? " " : "", id, val);
2018 err = snd_config_search(pcm_conf, "type", &conf);
2020 SNDERR("type is not defined");
2023 err = snd_config_get_id(conf, &id);
2025 SNDERR("unable to get id");
2028 err = snd_config_get_string(conf, &str);
2030 SNDERR("Invalid type for %s", id);
2033 err = snd_config_search_definition(pcm_root, "pcm_type", str, &type_conf);
2035 if (snd_config_get_type(type_conf) != SND_CONFIG_TYPE_COMPOUND) {
2036 SNDERR("Invalid type for PCM type %s definition", str);
2039 snd_config_for_each(i, next, type_conf) {
2040 snd_config_t *n = snd_config_iterator_entry(i);
2042 if (snd_config_get_id(n, &id) < 0)
2044 if (strcmp(id, "comment") == 0)
2046 if (strcmp(id, "lib") == 0) {
2047 err = snd_config_get_string(n, &lib);
2049 SNDERR("Invalid type for %s", id);
2054 if (strcmp(id, "open") == 0) {
2055 err = snd_config_get_string(n, &open_name);
2057 SNDERR("Invalid type for %s", id);
2062 SNDERR("Unknown field %s", id);
2068 buf = malloc(strlen(str) + 32);
2074 sprintf(buf, "_snd_pcm_%s_open", str);
2077 char **build_in = build_in_pcms;
2079 if (!strcmp(*build_in, str))
2083 if (*build_in == NULL) {
2084 buf1 = malloc(strlen(str) + sizeof(ALSA_PLUGIN_DIR) + 32);
2090 sprintf(buf1, "%s/libasound_module_pcm_%s.so", ALSA_PLUGIN_DIR, str);
2094 snd_pcm_open_symbols(); /* this call is for static linking only */
2096 open_func = snd_dlobj_cache_lookup(open_name);
2101 h = snd_dlopen(lib, RTLD_NOW);
2103 open_func = snd_dlsym(h, open_name, SND_DLSYM_VERSION(SND_PCM_DLSYM_VERSION));
2106 SNDERR("Cannot open shared library %s", lib);
2108 } else if (!open_func) {
2109 SNDERR("symbol %s is not defined inside %s", open_name, lib);
2115 err = open_func(pcmp, name, pcm_root, pcm_conf, stream, mode);
2117 if (h /*&& (mode & SND_PCM_KEEP_ALIVE)*/) {
2118 snd_dlobj_cache_add(open_name, h, open_func);
2121 (*pcmp)->dl_handle = h;
2129 snd_config_delete(type_conf);
2135 static int snd_pcm_open_noupdate(snd_pcm_t **pcmp, snd_config_t *root,
2136 const char *name, snd_pcm_stream_t stream,
2140 snd_config_t *pcm_conf;
2143 err = snd_config_search_definition(root, "pcm", name, &pcm_conf);
2145 SNDERR("Unknown PCM %s", name);
2148 if (snd_config_get_string(pcm_conf, &str) >= 0)
2149 err = snd_pcm_open_noupdate(pcmp, root, str, stream, mode,
2152 snd_config_set_hop(pcm_conf, hop);
2153 err = snd_pcm_open_conf(pcmp, name, root, pcm_conf, stream, mode);
2155 snd_config_delete(pcm_conf);
2160 * \brief Opens a PCM
2161 * \param pcmp Returned PCM handle
2162 * \param name ASCII identifier of the PCM handle
2163 * \param stream Wanted stream
2164 * \param mode Open mode (see #SND_PCM_NONBLOCK, #SND_PCM_ASYNC)
2165 * \return 0 on success otherwise a negative error code
2167 int snd_pcm_open(snd_pcm_t **pcmp, const char *name,
2168 snd_pcm_stream_t stream, int mode)
2171 assert(pcmp && name);
2172 err = snd_config_update();
2175 return snd_pcm_open_noupdate(pcmp, snd_config, name, stream, mode, 0);
2179 * \brief Opens a PCM using local configuration
2180 * \param pcmp Returned PCM handle
2181 * \param name ASCII identifier of the PCM handle
2182 * \param stream Wanted stream
2183 * \param mode Open mode (see #SND_PCM_NONBLOCK, #SND_PCM_ASYNC)
2184 * \param lconf Local configuration
2185 * \return 0 on success otherwise a negative error code
2187 int snd_pcm_open_lconf(snd_pcm_t **pcmp, const char *name,
2188 snd_pcm_stream_t stream, int mode,
2189 snd_config_t *lconf)
2191 assert(pcmp && name && lconf);
2192 return snd_pcm_open_noupdate(pcmp, lconf, name, stream, mode, 0);
2196 int snd_pcm_new(snd_pcm_t **pcmp, snd_pcm_type_t type, const char *name,
2197 snd_pcm_stream_t stream, int mode)
2200 pcm = calloc(1, sizeof(*pcm));
2205 pcm->name = strdup(name);
2206 pcm->stream = stream;
2208 pcm->poll_fd_count = 1;
2211 pcm->fast_op_arg = pcm;
2212 INIT_LIST_HEAD(&pcm->async_handlers);
2217 int snd_pcm_free(snd_pcm_t *pcm)
2221 free(pcm->hw.link_dst);
2222 free(pcm->appl.link_dst);
2224 snd_dlclose(pcm->dl_handle);
2229 int snd_pcm_open_slave(snd_pcm_t **pcmp, snd_config_t *root,
2230 snd_config_t *conf, snd_pcm_stream_t stream,
2231 int mode, snd_config_t *parent_conf)
2236 if ((hop = snd_config_check_hop(parent_conf)) < 0)
2238 if (snd_config_get_string(conf, &str) >= 0)
2239 return snd_pcm_open_noupdate(pcmp, root, str, stream, mode,
2241 return snd_pcm_open_conf(pcmp, NULL, root, conf, stream, mode);
2246 * \brief Wait for a PCM to become ready
2247 * \param pcm PCM handle
2248 * \param timeout maximum time in milliseconds to wait,
2249 * a negative value means infinity
2250 * \return a positive value on success otherwise a negative error code
2251 * (-EPIPE for the xrun and -ESTRPIPE for the suspended status,
2252 * others for general errors)
2253 * \retval 0 timeout occurred
2254 * \retval 1 PCM stream is ready for I/O
2256 int snd_pcm_wait(snd_pcm_t *pcm, int timeout)
2258 if (snd_pcm_mmap_avail(pcm) >= pcm->avail_min) {
2259 /* check more precisely */
2260 switch (snd_pcm_state(pcm)) {
2261 case SND_PCM_STATE_XRUN:
2263 case SND_PCM_STATE_SUSPENDED:
2265 case SND_PCM_STATE_DISCONNECTED:
2271 return snd_pcm_wait_nocheck(pcm, timeout);
2276 * like snd_pcm_wait() but doesn't check mmap_avail before calling poll()
2278 * used in drain code in some plugins
2280 int snd_pcm_wait_nocheck(snd_pcm_t *pcm, int timeout)
2283 unsigned short *revents;
2284 int i, npfds, pollio, err, err_poll;
2286 npfds = snd_pcm_poll_descriptors_count(pcm);
2287 if (npfds <= 0 || npfds >= 16) {
2288 SNDERR("Invalid poll_fds %d\n", npfds);
2291 pfd = alloca(sizeof(*pfd) * npfds);
2292 revents = alloca(sizeof(*revents) * npfds);
2293 err = snd_pcm_poll_descriptors(pcm, pfd, npfds);
2297 SNDMSG("invalid poll descriptors %d\n", err);
2302 err_poll = poll(pfd, npfds, timeout);
2310 err = snd_pcm_poll_descriptors_revents(pcm, pfd, npfds, revents);
2313 for (i = 0; i < npfds; i++) {
2314 if (revents[i] & (POLLERR | POLLNVAL)) {
2315 /* check more precisely */
2316 switch (snd_pcm_state(pcm)) {
2317 case SND_PCM_STATE_XRUN:
2319 case SND_PCM_STATE_SUSPENDED:
2321 case SND_PCM_STATE_DISCONNECTED:
2327 if ((revents[i] & (POLLIN | POLLOUT)) == 0)
2332 #if 0 /* very useful code to test poll related problems */
2334 snd_pcm_sframes_t avail_update;
2335 snd_pcm_hwsync(pcm);
2336 avail_update = snd_pcm_avail_update(pcm);
2337 if (avail_update < (snd_pcm_sframes_t)pcm->avail_min) {
2338 printf("*** snd_pcm_wait() FATAL ERROR!!!\n");
2339 printf("avail_min = %li, avail_update = %li\n", pcm->avail_min, avail_update);
2343 return err_poll > 0 ? 1 : 0;
2348 * \brief Return number of frames ready to be read/written
2349 * \param pcm PCM handle
2350 * \return a positive number of frames ready otherwise a negative
2353 * On capture does all the actions needed to transport to application
2354 * level all the ready frames across underlying layers.
2356 * Using of this function is useless for the standard read/write
2357 * operations. Use it only for mmap access. See to #snd_pcm_delay.
2359 snd_pcm_sframes_t snd_pcm_avail_update(snd_pcm_t *pcm)
2361 return pcm->fast_ops->avail_update(pcm->fast_op_arg);
2365 * \brief Silence an area
2366 * \param dst_area area specification
2367 * \param dst_offset offset in frames inside area
2368 * \param samples samples to silence
2369 * \param format PCM sample format
2370 * \return 0 on success otherwise a negative error code
2372 int snd_pcm_area_silence(const snd_pcm_channel_area_t *dst_area, snd_pcm_uframes_t dst_offset,
2373 unsigned int samples, snd_pcm_format_t format)
2375 /* FIXME: sub byte resolution and odd dst_offset */
2377 unsigned int dst_step;
2380 if (!dst_area->addr)
2382 dst = snd_pcm_channel_area_addr(dst_area, dst_offset);
2383 width = snd_pcm_format_physical_width(format);
2384 silence = snd_pcm_format_silence_64(format);
2385 if (dst_area->step == (unsigned int) width) {
2386 unsigned int dwords = samples * width / 64;
2387 u_int64_t *dstp = (u_int64_t *)dst;
2388 samples -= dwords * 64 / width;
2389 while (dwords-- > 0)
2394 dst_step = dst_area->step / 8;
2397 u_int8_t s0 = silence & 0xf0;
2398 u_int8_t s1 = silence & 0x0f;
2399 int dstbit = dst_area->first % 8;
2400 int dstbit_step = dst_area->step % 8;
2401 while (samples-- > 0) {
2410 dstbit += dstbit_step;
2419 u_int8_t sil = silence;
2420 while (samples-- > 0) {
2427 u_int16_t sil = silence;
2428 while (samples-- > 0) {
2429 *(u_int16_t*)dst = sil;
2435 #ifdef SNDRV_LITTLE_ENDIAN
2436 *(dst + 0) = silence >> 0;
2437 *(dst + 1) = silence >> 8;
2438 *(dst + 2) = silence >> 16;
2440 *(dst + 2) = silence >> 0;
2441 *(dst + 1) = silence >> 8;
2442 *(dst + 0) = silence >> 16;
2446 u_int32_t sil = silence;
2447 while (samples-- > 0) {
2448 *(u_int32_t*)dst = sil;
2454 while (samples-- > 0) {
2455 *(u_int64_t*)dst = silence;
2461 SNDMSG("invalid format width %d", width);
2468 * \brief Silence one or more areas
2469 * \param dst_areas areas specification (one for each channel)
2470 * \param dst_offset offset in frames inside area
2471 * \param channels channels count
2472 * \param frames frames to silence
2473 * \param format PCM sample format
2474 * \return 0 on success otherwise a negative error code
2476 int snd_pcm_areas_silence(const snd_pcm_channel_area_t *dst_areas, snd_pcm_uframes_t dst_offset,
2477 unsigned int channels, snd_pcm_uframes_t frames, snd_pcm_format_t format)
2479 int width = snd_pcm_format_physical_width(format);
2480 while (channels > 0) {
2481 void *addr = dst_areas->addr;
2482 unsigned int step = dst_areas->step;
2483 const snd_pcm_channel_area_t *begin = dst_areas;
2484 int channels1 = channels;
2485 unsigned int chns = 0;
2491 if (channels1 == 0 ||
2492 dst_areas->addr != addr ||
2493 dst_areas->step != step ||
2494 dst_areas->first != dst_areas[-1].first + width)
2497 if (chns > 1 && chns * width == step) {
2498 /* Collapse the areas */
2499 snd_pcm_channel_area_t d;
2500 d.addr = begin->addr;
2501 d.first = begin->first;
2503 err = snd_pcm_area_silence(&d, dst_offset * chns, frames * chns, format);
2506 err = snd_pcm_area_silence(begin, dst_offset, frames, format);
2507 dst_areas = begin + 1;
2518 * \brief Copy an area
2519 * \param dst_area destination area specification
2520 * \param dst_offset offset in frames inside destination area
2521 * \param src_area source area specification
2522 * \param src_offset offset in frames inside source area
2523 * \param samples samples to copy
2524 * \param format PCM sample format
2525 * \return 0 on success otherwise a negative error code
2527 int snd_pcm_area_copy(const snd_pcm_channel_area_t *dst_area, snd_pcm_uframes_t dst_offset,
2528 const snd_pcm_channel_area_t *src_area, snd_pcm_uframes_t src_offset,
2529 unsigned int samples, snd_pcm_format_t format)
2531 /* FIXME: sub byte resolution and odd dst_offset */
2535 int src_step, dst_step;
2536 if (dst_area == src_area && dst_offset == src_offset)
2538 if (!src_area->addr)
2539 return snd_pcm_area_silence(dst_area, dst_offset, samples, format);
2540 src = snd_pcm_channel_area_addr(src_area, src_offset);
2541 if (!dst_area->addr)
2543 dst = snd_pcm_channel_area_addr(dst_area, dst_offset);
2544 width = snd_pcm_format_physical_width(format);
2545 if (src_area->step == (unsigned int) width &&
2546 dst_area->step == (unsigned int) width) {
2547 size_t bytes = samples * width / 8;
2548 samples -= bytes * 8 / width;
2549 memcpy(dst, src, bytes);
2553 src_step = src_area->step / 8;
2554 dst_step = dst_area->step / 8;
2557 int srcbit = src_area->first % 8;
2558 int srcbit_step = src_area->step % 8;
2559 int dstbit = dst_area->first % 8;
2560 int dstbit_step = dst_area->step % 8;
2561 while (samples-- > 0) {
2562 unsigned char srcval;
2564 srcval = *src & 0x0f;
2566 srcval = *src & 0xf0;
2573 srcbit += srcbit_step;
2579 dstbit += dstbit_step;
2588 while (samples-- > 0) {
2596 while (samples-- > 0) {
2597 *(u_int16_t*)dst = *(const u_int16_t*)src;
2604 while (samples-- > 0) {
2605 *(dst + 0) = *(src + 0);
2606 *(dst + 1) = *(src + 1);
2607 *(dst + 2) = *(src + 2);
2613 while (samples-- > 0) {
2614 *(u_int32_t*)dst = *(const u_int32_t*)src;
2621 while (samples-- > 0) {
2622 *(u_int64_t*)dst = *(const u_int64_t*)src;
2629 SNDMSG("invalid format width %d", width);
2636 * \brief Copy one or more areas
2637 * \param dst_areas destination areas specification (one for each channel)
2638 * \param dst_offset offset in frames inside destination area
2639 * \param src_areas source areas specification (one for each channel)
2640 * \param src_offset offset in frames inside source area
2641 * \param channels channels count
2642 * \param frames frames to copy
2643 * \param format PCM sample format
2644 * \return 0 on success otherwise a negative error code
2646 int snd_pcm_areas_copy(const snd_pcm_channel_area_t *dst_areas, snd_pcm_uframes_t dst_offset,
2647 const snd_pcm_channel_area_t *src_areas, snd_pcm_uframes_t src_offset,
2648 unsigned int channels, snd_pcm_uframes_t frames, snd_pcm_format_t format)
2650 int width = snd_pcm_format_physical_width(format);
2654 SNDMSG("invalid channels %d", channels);
2658 SNDMSG("invalid frames %ld", frames);
2661 while (channels > 0) {
2662 unsigned int step = src_areas->step;
2663 void *src_addr = src_areas->addr;
2664 const snd_pcm_channel_area_t *src_start = src_areas;
2665 void *dst_addr = dst_areas->addr;
2666 const snd_pcm_channel_area_t *dst_start = dst_areas;
2667 int channels1 = channels;
2668 unsigned int chns = 0;
2669 while (dst_areas->step == step) {
2674 if (channels1 == 0 ||
2675 src_areas->step != step ||
2676 src_areas->addr != src_addr ||
2677 dst_areas->addr != dst_addr ||
2678 src_areas->first != src_areas[-1].first + width ||
2679 dst_areas->first != dst_areas[-1].first + width)
2682 if (chns > 1 && chns * width == step) {
2683 /* Collapse the areas */
2684 snd_pcm_channel_area_t s, d;
2685 s.addr = src_start->addr;
2686 s.first = src_start->first;
2688 d.addr = dst_start->addr;
2689 d.first = dst_start->first;
2691 snd_pcm_area_copy(&d, dst_offset * chns,
2692 &s, src_offset * chns,
2693 frames * chns, format);
2696 snd_pcm_area_copy(dst_start, dst_offset,
2697 src_start, src_offset,
2699 src_areas = src_start + 1;
2700 dst_areas = dst_start + 1;
2707 static void dump_one_param(snd_pcm_hw_params_t *params, unsigned int k, snd_output_t *out)
2709 snd_output_printf(out, "%s: ", snd_pcm_hw_param_name(k));
2710 snd_pcm_hw_param_dump(params, k, out);
2711 snd_output_putc(out, '\n');
2715 * \brief Dump a PCM hardware configuration space
2716 * \param params Configuration space
2717 * \param out Output handle
2718 * \return 0 on success otherwise a negative error code
2720 int snd_pcm_hw_params_dump(snd_pcm_hw_params_t *params, snd_output_t *out)
2723 for (k = SND_PCM_HW_PARAM_FIRST_MASK; k <= SND_PCM_HW_PARAM_LAST_MASK; k++)
2724 dump_one_param(params, k, out);
2725 for (k = SND_PCM_HW_PARAM_FIRST_INTERVAL; k <= SND_PCM_HW_PARAM_LAST_INTERVAL; k++)
2726 dump_one_param(params, k, out);
2731 * \brief Check, if hardware supports sample-resolution mmap for given configuration
2732 * \param params Configuration space
2733 * \return Boolean value
2734 * \retval 0 Hardware doesn't support sample-resolution mmap
2735 * \retval 1 Hardware supports sample-resolution mmap
2737 * The return value is always one when given configuration is not exactly one.
2738 * Usually, #snd_pcm_hw_params() function chooses one configuration
2739 * from the configuration space.
2741 int snd_pcm_hw_params_can_mmap_sample_resolution(const snd_pcm_hw_params_t *params)
2744 if (CHECK_SANITY(params->info == ~0U)) {
2745 SNDMSG("invalid PCM info field");
2746 return 0; /* FIXME: should be a negative error? */
2748 return !!(params->info & SNDRV_PCM_INFO_MMAP_VALID);
2752 * \brief Check, if hardware does double buffering for start/stop for given configuration
2753 * \param params Configuration space
2754 * \return Boolean value
2755 * \retval 0 Hardware doesn't do double buffering for start/stop
2756 * \retval 1 Hardware does double buffering for start/stop
2758 * It is not allowed to call this function when given configuration is not exactly one.
2759 * Usually, #snd_pcm_hw_params() function chooses one configuration
2760 * from the configuration space.
2762 int snd_pcm_hw_params_is_double(const snd_pcm_hw_params_t *params)
2765 if (CHECK_SANITY(params->info == ~0U)) {
2766 SNDMSG("invalid PCM info field");
2767 return 0; /* FIXME: should be a negative error? */
2769 return !!(params->info & SNDRV_PCM_INFO_DOUBLE);
2773 * \brief Check, if hardware does double buffering for data transfers for given configuration
2774 * \param params Configuration space
2775 * \return Boolean value
2776 * \retval 0 Hardware doesn't do double buffering for data transfers
2777 * \retval 1 Hardware does double buffering for data transfers
2779 * It is not allowed to call this function when given configuration is not exactly one.
2780 * Usually, #snd_pcm_hw_params() function chooses one configuration
2781 * from the configuration space.
2783 int snd_pcm_hw_params_is_batch(const snd_pcm_hw_params_t *params)
2786 if (CHECK_SANITY(params->info == ~0U)) {
2787 SNDMSG("invalid PCM info field");
2788 return 0; /* FIXME: should be a negative error? */
2790 return !!(params->info & SNDRV_PCM_INFO_BATCH);
2794 * \brief Check, if hardware does block transfers for samples for given configuration
2795 * \param params Configuration space
2796 * \return Boolean value
2797 * \retval 0 Hardware doesn't block transfers
2798 * \retval 1 Hardware does block transfers
2800 * It is not allowed to call this function when given configuration is not exactly one.
2801 * Usually, #snd_pcm_hw_params() function chooses one configuration
2802 * from the configuration space.
2804 int snd_pcm_hw_params_is_block_transfer(const snd_pcm_hw_params_t *params)
2807 if (CHECK_SANITY(params->info == ~0U)) {
2808 SNDMSG("invalid PCM info field");
2809 return 0; /* FIXME: should be a negative error? */
2811 return !!(params->info & SNDRV_PCM_INFO_BLOCK_TRANSFER);
2815 * \brief Check, if hardware supports overrange detection
2816 * \param params Configuration space
2817 * \return Boolean value
2818 * \retval 0 Hardware doesn't support overrange detection
2819 * \retval 1 Hardware supports overrange detection
2821 * It is not allowed to call this function when given configuration is not exactly one.
2822 * Usually, #snd_pcm_hw_params() function chooses one configuration
2823 * from the configuration space.
2825 int snd_pcm_hw_params_can_overrange(const snd_pcm_hw_params_t *params)
2828 if (CHECK_SANITY(params->info == ~0U)) {
2829 SNDMSG("invalid PCM info field");
2830 return 0; /* FIXME: should be a negative error? */
2832 return !!(params->info & SNDRV_PCM_INFO_OVERRANGE);
2836 * \brief Check, if hardware supports pause
2837 * \param params Configuration space
2838 * \return Boolean value
2839 * \retval 0 Hardware doesn't support pause
2840 * \retval 1 Hardware supports pause
2842 * It is not allowed to call this function when given configuration is not exactly one.
2843 * Usually, #snd_pcm_hw_params() function chooses one configuration
2844 * from the configuration space.
2846 int snd_pcm_hw_params_can_pause(const snd_pcm_hw_params_t *params)
2849 if (CHECK_SANITY(params->info == ~0U)) {
2850 SNDMSG("invalid PCM info field");
2851 return 0; /* FIXME: should be a negative error? */
2853 return !!(params->info & SNDRV_PCM_INFO_PAUSE);
2857 * \brief Check, if hardware supports resume
2858 * \param params Configuration space
2859 * \return Boolean value
2860 * \retval 0 Hardware doesn't support resume
2861 * \retval 1 Hardware supports resume
2863 * It is not allowed to call this function when given configuration is not exactly one.
2864 * Usually, #snd_pcm_hw_params() function chooses one configuration
2865 * from the configuration space.
2867 int snd_pcm_hw_params_can_resume(const snd_pcm_hw_params_t *params)
2870 if (CHECK_SANITY(params->info == ~0U)) {
2871 SNDMSG("invalid PCM info field");
2872 return 0; /* FIXME: should be a negative error? */
2874 return !!(params->info & SNDRV_PCM_INFO_RESUME);
2878 * \brief Check, if hardware does half-duplex only
2879 * \param params Configuration space
2880 * \return Boolean value
2881 * \retval 0 Hardware doesn't do half-duplex
2882 * \retval 1 Hardware does half-duplex
2884 * It is not allowed to call this function when given configuration is not exactly one.
2885 * Usually, #snd_pcm_hw_params() function chooses one configuration
2886 * from the configuration space.
2888 int snd_pcm_hw_params_is_half_duplex(const snd_pcm_hw_params_t *params)
2891 if (CHECK_SANITY(params->info == ~0U)) {
2892 SNDMSG("invalid PCM info field");
2893 return 0; /* FIXME: should be a negative error? */
2895 return !!(params->info & SNDRV_PCM_INFO_HALF_DUPLEX);
2899 * \brief Check, if hardware does joint-duplex (playback and capture are somewhat correlated)
2900 * \param params Configuration space
2901 * \return Boolean value
2902 * \retval 0 Hardware doesn't do joint-duplex
2903 * \retval 1 Hardware does joint-duplex
2905 * It is not allowed to call this function when given configuration is not exactly one.
2906 * Usually, #snd_pcm_hw_params() function chooses one configuration
2907 * from the configuration space.
2909 int snd_pcm_hw_params_is_joint_duplex(const snd_pcm_hw_params_t *params)
2912 if (CHECK_SANITY(params->info == ~0U)) {
2913 SNDMSG("invalid PCM info field");
2914 return 0; /* FIXME: should be a negative error? */
2916 return !!(params->info & SNDRV_PCM_INFO_JOINT_DUPLEX);
2920 * \brief Check, if hardware supports synchronized start with sample resolution
2921 * \param params Configuration space
2922 * \return Boolean value
2923 * \retval 0 Hardware doesn't support synchronized start
2924 * \retval 1 Hardware supports synchronized start
2926 * It is not allowed to call this function when given configuration is not exactly one.
2927 * Usually, #snd_pcm_hw_params() function chooses one configuration
2928 * from the configuration space.
2930 int snd_pcm_hw_params_can_sync_start(const snd_pcm_hw_params_t *params)
2933 if (CHECK_SANITY(params->info == ~0U)) {
2934 SNDMSG("invalid PCM info field");
2935 return 0; /* FIXME: should be a negative error? */
2937 return !!(params->info & SNDRV_PCM_INFO_SYNC_START);
2941 * \brief Get rate exact info from a configuration space
2942 * \param params Configuration space
2943 * \param rate_num Pointer to returned rate numerator
2944 * \param rate_den Pointer to returned rate denominator
2945 * \return 0 otherwise a negative error code if the info is not available
2947 * It is not allowed to call this function when given configuration is not exactly one.
2948 * Usually, #snd_pcm_hw_params() function chooses one configuration
2949 * from the configuration space.
2951 int snd_pcm_hw_params_get_rate_numden(const snd_pcm_hw_params_t *params,
2952 unsigned int *rate_num, unsigned int *rate_den)
2955 if (CHECK_SANITY(params->rate_den == 0)) {
2956 SNDMSG("invalid rate_den value");
2959 *rate_num = params->rate_num;
2960 *rate_den = params->rate_den;
2965 * \brief Get sample resolution info from a configuration space
2966 * \param params Configuration space
2967 * \return signification bits in sample otherwise a negative error code if the info is not available
2969 * It is not allowed to call this function when given configuration is not exactly one.
2970 * Usually, #snd_pcm_hw_params() function chooses one configuration
2971 * from the configuration space.
2973 int snd_pcm_hw_params_get_sbits(const snd_pcm_hw_params_t *params)
2976 if (CHECK_SANITY(params->msbits == 0)) {
2977 SNDMSG("invalid msbits value");
2980 return params->msbits;
2984 * \brief Get hard are FIFO size info from a configuration space
2985 * \param params Configuration space
2986 * \return FIFO size in frames otherwise a negative error code if the info is not available
2988 * It is not allowed to call this function when given configuration is not exactly one.
2989 * Usually, #snd_pcm_hw_params() function chooses one configuration
2990 * from the configuration space.
2992 int snd_pcm_hw_params_get_fifo_size(const snd_pcm_hw_params_t *params)
2995 if (CHECK_SANITY(params->info == ~0U)) {
2996 SNDMSG("invalid PCM info field");
2999 return params->fifo_size;
3003 * \brief Fill params with a full configuration space for a PCM
3004 * \param pcm PCM handle
3005 * \param params Configuration space
3007 int snd_pcm_hw_params_any(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
3009 _snd_pcm_hw_params_any(params);
3010 return snd_pcm_hw_refine(pcm, params);
3014 * \brief get size of #snd_pcm_access_mask_t
3015 * \return size in bytes
3017 size_t snd_pcm_access_mask_sizeof()
3019 return sizeof(snd_pcm_access_mask_t);
3023 * \brief allocate an empty #snd_pcm_access_mask_t using standard malloc
3024 * \param ptr returned pointer
3025 * \return 0 on success otherwise negative error code
3027 int snd_pcm_access_mask_malloc(snd_pcm_access_mask_t **ptr)
3030 *ptr = calloc(1, sizeof(snd_pcm_access_mask_t));
3037 * \brief frees a previously allocated #snd_pcm_access_mask_t
3038 * \param obj pointer to object to free
3040 void snd_pcm_access_mask_free(snd_pcm_access_mask_t *obj)
3046 * \brief copy one #snd_pcm_access_mask_t to another
3047 * \param dst pointer to destination
3048 * \param src pointer to source
3050 void snd_pcm_access_mask_copy(snd_pcm_access_mask_t *dst, const snd_pcm_access_mask_t *src)
3057 * \brief reset all bits in a #snd_pcm_access_mask_t
3058 * \param mask pointer to mask
3060 void snd_pcm_access_mask_none(snd_pcm_access_mask_t *mask)
3062 snd_mask_none((snd_mask_t *) mask);
3066 * \brief set all bits in a #snd_pcm_access_mask_t
3067 * \param mask pointer to mask
3069 void snd_pcm_access_mask_any(snd_pcm_access_mask_t *mask)
3071 snd_mask_any((snd_mask_t *) mask);
3075 * \brief test the presence of an access type in a #snd_pcm_access_mask_t
3076 * \param mask pointer to mask
3077 * \param val access type
3079 int snd_pcm_access_mask_test(const snd_pcm_access_mask_t *mask, snd_pcm_access_t val)
3081 return snd_mask_test((const snd_mask_t *) mask, (unsigned long) val);
3085 * \brief test, if given a #snd_pcm_access_mask_t is empty
3086 * \param mask pointer to mask
3087 * \retval 0 not empty
3090 int snd_pcm_access_mask_empty(const snd_pcm_access_mask_t *mask)
3092 return snd_mask_empty((const snd_mask_t *) mask);
3096 * \brief make an access type present in a #snd_pcm_access_mask_t
3097 * \param mask pointer to mask
3098 * \param val access type
3100 void snd_pcm_access_mask_set(snd_pcm_access_mask_t *mask, snd_pcm_access_t val)
3102 snd_mask_set((snd_mask_t *) mask, (unsigned long) val);
3106 * \brief make an access type missing from a #snd_pcm_access_mask_t
3107 * \param mask pointer to mask
3108 * \param val access type
3110 void snd_pcm_access_mask_reset(snd_pcm_access_mask_t *mask, snd_pcm_access_t val)
3112 snd_mask_reset((snd_mask_t *) mask, (unsigned long) val);
3116 * \brief get size of #snd_pcm_format_mask_t
3117 * \return size in bytes
3119 size_t snd_pcm_format_mask_sizeof()
3121 return sizeof(snd_pcm_format_mask_t);
3125 * \brief allocate an empty #snd_pcm_format_mask_t using standard malloc
3126 * \param ptr returned pointer
3127 * \return 0 on success otherwise negative error code
3129 int snd_pcm_format_mask_malloc(snd_pcm_format_mask_t **ptr)
3132 *ptr = calloc(1, sizeof(snd_pcm_format_mask_t));
3139 * \brief frees a previously allocated #snd_pcm_format_mask_t
3140 * \param obj pointer to object to free
3142 void snd_pcm_format_mask_free(snd_pcm_format_mask_t *obj)
3148 * \brief copy one #snd_pcm_format_mask_t to another
3149 * \param dst pointer to destination
3150 * \param src pointer to source
3152 void snd_pcm_format_mask_copy(snd_pcm_format_mask_t *dst, const snd_pcm_format_mask_t *src)
3159 * \brief reset all bits in a #snd_pcm_format_mask_t
3160 * \param mask pointer to mask
3162 void snd_pcm_format_mask_none(snd_pcm_format_mask_t *mask)
3164 snd_mask_none((snd_mask_t *) mask);
3168 * \brief set all bits in a #snd_pcm_format_mask_t
3169 * \param mask pointer to mask
3171 void snd_pcm_format_mask_any(snd_pcm_format_mask_t *mask)
3173 snd_mask_any((snd_mask_t *) mask);
3177 * \brief test the presence of a format in a #snd_pcm_format_mask_t
3178 * \param mask pointer to mask
3181 int snd_pcm_format_mask_test(const snd_pcm_format_mask_t *mask, snd_pcm_format_t val)
3183 return snd_mask_test((const snd_mask_t *) mask, (unsigned long) val);
3187 * \brief test, if given a #snd_pcm_format_mask_t is empty
3188 * \param mask pointer to mask
3189 * \retval 0 not empty
3192 int snd_pcm_format_mask_empty(const snd_pcm_format_mask_t *mask)
3194 return snd_mask_empty((const snd_mask_t *) mask);
3198 * \brief make a format present in a #snd_pcm_format_mask_t
3199 * \param mask pointer to mask
3202 void snd_pcm_format_mask_set(snd_pcm_format_mask_t *mask, snd_pcm_format_t val)
3204 snd_mask_set((snd_mask_t *) mask, (unsigned long) val);
3208 * \brief make a format missing from a #snd_pcm_format_mask_t
3209 * \param mask pointer to mask
3212 void snd_pcm_format_mask_reset(snd_pcm_format_mask_t *mask, snd_pcm_format_t val)
3214 snd_mask_reset((snd_mask_t *) mask, (unsigned long) val);
3219 * \brief get size of #snd_pcm_subformat_mask_t
3220 * \return size in bytes
3222 size_t snd_pcm_subformat_mask_sizeof()
3224 return sizeof(snd_pcm_subformat_mask_t);
3228 * \brief allocate an empty #snd_pcm_subformat_mask_t using standard malloc
3229 * \param ptr returned pointer
3230 * \return 0 on success otherwise negative error code
3232 int snd_pcm_subformat_mask_malloc(snd_pcm_subformat_mask_t **ptr)
3235 *ptr = calloc(1, sizeof(snd_pcm_subformat_mask_t));
3242 * \brief frees a previously allocated #snd_pcm_subformat_mask_t
3243 * \param obj pointer to object to free
3245 void snd_pcm_subformat_mask_free(snd_pcm_subformat_mask_t *obj)
3251 * \brief copy one #snd_pcm_subformat_mask_t to another
3252 * \param dst pointer to destination
3253 * \param src pointer to source
3255 void snd_pcm_subformat_mask_copy(snd_pcm_subformat_mask_t *dst, const snd_pcm_subformat_mask_t *src)
3262 * \brief reset all bits in a #snd_pcm_subformat_mask_t
3263 * \param mask pointer to mask
3265 void snd_pcm_subformat_mask_none(snd_pcm_subformat_mask_t *mask)
3267 snd_mask_none((snd_mask_t *) mask);
3271 * \brief set all bits in a #snd_pcm_subformat_mask_t
3272 * \param mask pointer to mask
3274 void snd_pcm_subformat_mask_any(snd_pcm_subformat_mask_t *mask)
3276 snd_mask_any((snd_mask_t *) mask);
3280 * \brief test the presence of a subformat in a #snd_pcm_subformat_mask_t
3281 * \param mask pointer to mask
3282 * \param val subformat
3284 int snd_pcm_subformat_mask_test(const snd_pcm_subformat_mask_t *mask, snd_pcm_subformat_t val)
3286 return snd_mask_test((const snd_mask_t *) mask, (unsigned long) val);
3290 * \brief test, if given a #snd_pcm_subformat_mask_t is empty
3291 * \param mask pointer to mask
3292 * \retval 0 not empty
3295 int snd_pcm_subformat_mask_empty(const snd_pcm_subformat_mask_t *mask)
3297 return snd_mask_empty((const snd_mask_t *) mask);
3301 * \brief make a subformat present in a #snd_pcm_subformat_mask_t
3302 * \param mask pointer to mask
3303 * \param val subformat
3305 void snd_pcm_subformat_mask_set(snd_pcm_subformat_mask_t *mask, snd_pcm_subformat_t val)
3307 snd_mask_set((snd_mask_t *) mask, (unsigned long) val);
3311 * \brief make a subformat missing from a #snd_pcm_subformat_mask_t
3312 * \param mask pointer to mask
3313 * \param val subformat
3315 void snd_pcm_subformat_mask_reset(snd_pcm_subformat_mask_t *mask, snd_pcm_subformat_t val)
3317 snd_mask_reset((snd_mask_t *) mask, (unsigned long) val);
3322 * \brief get size of #snd_pcm_hw_params_t
3323 * \return size in bytes
3325 size_t snd_pcm_hw_params_sizeof()
3327 return sizeof(snd_pcm_hw_params_t);
3331 * \brief allocate an invalid #snd_pcm_hw_params_t using standard malloc
3332 * \param ptr returned pointer
3333 * \return 0 on success otherwise negative error code
3335 int snd_pcm_hw_params_malloc(snd_pcm_hw_params_t **ptr)
3338 *ptr = calloc(1, sizeof(snd_pcm_hw_params_t));
3345 * \brief frees a previously allocated #snd_pcm_hw_params_t
3346 * \param obj pointer to object to free
3348 void snd_pcm_hw_params_free(snd_pcm_hw_params_t *obj)
3354 * \brief copy one #snd_pcm_hw_params_t to another
3355 * \param dst pointer to destination
3356 * \param src pointer to source
3358 void snd_pcm_hw_params_copy(snd_pcm_hw_params_t *dst, const snd_pcm_hw_params_t *src)
3366 * \brief Extract access type from a configuration space
3367 * \param params Configuration space
3368 * \param access Returned value
3369 * \return access type otherwise a negative error code if not exactly one is present
3372 int INTERNAL(snd_pcm_hw_params_get_access)(const snd_pcm_hw_params_t *params, snd_pcm_access_t *access)
3374 int snd_pcm_hw_params_get_access(const snd_pcm_hw_params_t *params, snd_pcm_access_t *access)
3378 int err = snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_ACCESS, &_val, NULL);
3385 * \brief Verify if an access type is available inside a configuration space for a PCM
3386 * \param pcm PCM handle
3387 * \param params Configuration space
3388 * \param access access type
3389 * \return 0 if available a negative error code otherwise
3391 int snd_pcm_hw_params_test_access(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t access)
3393 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_ACCESS, access, 0);
3397 * \brief Restrict a configuration space to contain only one access type
3398 * \param pcm PCM handle
3399 * \param params Configuration space
3400 * \param access access type
3401 * \return 0 otherwise a negative error code if configuration space would become empty
3403 int snd_pcm_hw_params_set_access(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t access)
3405 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_ACCESS, access, 0);
3409 * \brief Restrict a configuration space to contain only its first access type
3410 * \param pcm PCM handle
3411 * \param params Configuration space
3412 * \param access Returned first access type
3413 * \return 0 otherwise a negative error code
3416 int INTERNAL(snd_pcm_hw_params_set_access_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t *access)
3418 int snd_pcm_hw_params_set_access_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t *access)
3421 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_ACCESS, access, NULL);
3425 * \brief Restrict a configuration space to contain only its last access type
3426 * \param pcm PCM handle
3427 * \param params Configuration space
3428 * \param access Returned last access type
3429 * \return 0 otherwise a negative error code
3432 int INTERNAL(snd_pcm_hw_params_set_access_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t *access)
3434 int snd_pcm_hw_params_set_access_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t *access)
3437 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_ACCESS, access, NULL);
3441 * \brief Restrict a configuration space to contain only a set of access types
3442 * \param pcm PCM handle
3443 * \param params Configuration space
3444 * \param mask Access mask
3445 * \return 0 otherwise a negative error code
3447 int snd_pcm_hw_params_set_access_mask(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_mask_t *mask)
3449 return snd_pcm_hw_param_set_mask(pcm, params, SND_TRY, SND_PCM_HW_PARAM_ACCESS, (snd_mask_t *) mask);
3453 * \brief Get access mask from a configuration space
3454 * \param params Configuration space
3455 * \param mask Returned Access mask
3457 int snd_pcm_hw_params_get_access_mask(snd_pcm_hw_params_t *params, snd_pcm_access_mask_t *mask)
3459 if (params == NULL || mask == NULL)
3461 snd_pcm_access_mask_copy(mask, snd_pcm_hw_param_get_mask(params, SND_PCM_HW_PARAM_ACCESS));
3467 * \brief Extract format from a configuration space
3468 * \param params Configuration space
3469 * \param format returned format
3470 * \return format otherwise a negative error code if not exactly one is present
3473 int INTERNAL(snd_pcm_hw_params_get_format)(const snd_pcm_hw_params_t *params, snd_pcm_format_t *format)
3475 int snd_pcm_hw_params_get_format(const snd_pcm_hw_params_t *params, snd_pcm_format_t *format)
3478 return snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_FORMAT, (unsigned int *)format, NULL);
3482 * \brief Verify if a format is available inside a configuration space for a PCM
3483 * \param pcm PCM handle
3484 * \param params Configuration space
3485 * \param format format
3486 * \return 0 if available a negative error code otherwise
3488 int snd_pcm_hw_params_test_format(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t format)
3490 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_FORMAT, format, 0);
3494 * \brief Restrict a configuration space to contain only one format
3495 * \param pcm PCM handle
3496 * \param params Configuration space
3497 * \param format format
3498 * \return 0 otherwise a negative error code
3500 int snd_pcm_hw_params_set_format(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t format)
3502 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_FORMAT, format, 0);
3506 * \brief Restrict a configuration space to contain only its first format
3507 * \param pcm PCM handle
3508 * \param params Configuration space
3509 * \param format Returned first format
3510 * \return 0 otherwise a negative error code
3513 int INTERNAL(snd_pcm_hw_params_set_format_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t *format)
3515 int snd_pcm_hw_params_set_format_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t *format)
3518 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_FORMAT, (unsigned int *)format, NULL);
3522 * \brief Restrict a configuration space to contain only its last format
3523 * \param pcm PCM handle
3524 * \param params Configuration space
3525 * \param format Returned last format
3526 * \return 0 otherwise a negative error code
3529 int INTERNAL(snd_pcm_hw_params_set_format_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t *format)
3531 int snd_pcm_hw_params_set_format_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t *format)
3534 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_FORMAT, (unsigned int *)format, NULL);
3538 * \brief Restrict a configuration space to contain only a set of formats
3539 * \param pcm PCM handle
3540 * \param params Configuration space
3541 * \param mask Format mask
3542 * \return 0 otherwise a negative error code
3544 int snd_pcm_hw_params_set_format_mask(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_mask_t *mask)
3546 return snd_pcm_hw_param_set_mask(pcm, params, SND_TRY, SND_PCM_HW_PARAM_FORMAT, (snd_mask_t *) mask);
3550 * \brief Get format mask from a configuration space
3551 * \param params Configuration space
3552 * \param mask Returned Format mask
3554 void snd_pcm_hw_params_get_format_mask(snd_pcm_hw_params_t *params, snd_pcm_format_mask_t *mask)
3556 snd_pcm_format_mask_copy(mask, snd_pcm_hw_param_get_mask(params, SND_PCM_HW_PARAM_FORMAT));
3561 * \brief Extract subformat from a configuration space
3562 * \param params Configuration space
3563 * \param subformat Returned subformat value
3564 * \return subformat otherwise a negative error code if not exactly one is present
3567 int INTERNAL(snd_pcm_hw_params_get_subformat)(const snd_pcm_hw_params_t *params, snd_pcm_subformat_t *subformat)
3569 int snd_pcm_hw_params_get_subformat(const snd_pcm_hw_params_t *params, snd_pcm_subformat_t *subformat)
3572 return snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_SUBFORMAT, subformat, NULL);
3576 * \brief Verify if a subformat is available inside a configuration space for a PCM
3577 * \param pcm PCM handle
3578 * \param params Configuration space
3579 * \param subformat subformat value
3580 * \return 0 if available a negative error code otherwise
3582 int snd_pcm_hw_params_test_subformat(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t subformat)
3584 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_SUBFORMAT, subformat, 0);
3588 * \brief Restrict a configuration space to contain only one subformat
3589 * \param pcm PCM handle
3590 * \param params Configuration space
3591 * \param subformat subformat value
3592 * \return 0 otherwise a negative error code if configuration space would become empty
3594 int snd_pcm_hw_params_set_subformat(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t subformat)
3596 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_SUBFORMAT, subformat, 0);
3600 * \brief Restrict a configuration space to contain only its first subformat
3601 * \param pcm PCM handle
3602 * \param params Configuration space
3603 * \param subformat Returned subformat
3604 * \return 0 otherwise a negative error code
3607 int INTERNAL(snd_pcm_hw_params_set_subformat_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t *subformat)
3609 int snd_pcm_hw_params_set_subformat_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t *subformat)
3612 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_SUBFORMAT, subformat, NULL);
3616 * \brief Restrict a configuration space to contain only its last subformat
3617 * \param pcm PCM handle
3618 * \param params Configuration space
3619 * \param subformat Returned subformat
3620 * \return 0 otherwise a negative error code
3623 int INTERNAL(snd_pcm_hw_params_set_subformat_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t *subformat)
3625 int snd_pcm_hw_params_set_subformat_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t *subformat)
3628 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_SUBFORMAT, subformat, NULL);
3632 * \brief Restrict a configuration space to contain only a set of subformats
3633 * \param pcm PCM handle
3634 * \param params Configuration space
3635 * \param mask Subformat mask
3636 * \return 0 otherwise a negative error code
3638 int snd_pcm_hw_params_set_subformat_mask(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_mask_t *mask)
3640 return snd_pcm_hw_param_set_mask(pcm, params, SND_TRY, SND_PCM_HW_PARAM_SUBFORMAT, (snd_mask_t *) mask);
3644 * \brief Get subformat mask from a configuration space
3645 * \param params Configuration space
3646 * \param mask Returned Subformat mask
3648 void snd_pcm_hw_params_get_subformat_mask(snd_pcm_hw_params_t *params, snd_pcm_subformat_mask_t *mask)
3650 snd_pcm_subformat_mask_copy(mask, snd_pcm_hw_param_get_mask(params, SND_PCM_HW_PARAM_SUBFORMAT));
3655 * \brief Extract channels from a configuration space
3656 * \param params Configuration space
3657 * \param val Returned channels count
3658 * \return 0 otherwise a negative error code if not exactly one is present
3661 int INTERNAL(snd_pcm_hw_params_get_channels)(const snd_pcm_hw_params_t *params, unsigned int *val)
3663 int snd_pcm_hw_params_get_channels(const snd_pcm_hw_params_t *params, unsigned int *val)
3666 return snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
3670 * \brief Extract minimum channels count from a configuration space
3671 * \param params Configuration space
3672 * \param val minimum channels count
3673 * \return 0 otherwise a negative error code
3676 int INTERNAL(snd_pcm_hw_params_get_channels_min)(const snd_pcm_hw_params_t *params, unsigned int *val)
3678 int snd_pcm_hw_params_get_channels_min(const snd_pcm_hw_params_t *params, unsigned int *val)
3681 return snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
3685 * \brief Extract maximum channels count from a configuration space
3686 * \param params Configuration space
3687 * \param val maximum channels count
3688 * \return 0 otherwise a negative error code
3691 int INTERNAL(snd_pcm_hw_params_get_channels_max)(const snd_pcm_hw_params_t *params, unsigned int *val)
3693 int snd_pcm_hw_params_get_channels_max(const snd_pcm_hw_params_t *params, unsigned int *val)
3696 return snd_pcm_hw_param_get_max(params, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
3700 * \brief Verify if a channels count is available inside a configuration space for a PCM
3701 * \param pcm PCM handle
3702 * \param params Configuration space
3703 * \param val channels count
3704 * \return 0 if available a negative error code otherwise
3706 int snd_pcm_hw_params_test_channels(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val)
3708 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_CHANNELS, val, 0);
3712 * \brief Restrict a configuration space to contain only one channels count
3713 * \param pcm PCM handle
3714 * \param params Configuration space
3715 * \param val channels count
3716 * \return 0 otherwise a negative error code if configuration space would become empty
3718 int snd_pcm_hw_params_set_channels(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val)
3720 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_CHANNELS, val, 0);
3724 * \brief Restrict a configuration space with a minimum channels count
3725 * \param pcm PCM handle
3726 * \param params Configuration space
3727 * \param val minimum channels count (on return filled with actual minimum)
3728 * \return 0 otherwise a negative error code if configuration space would become empty
3730 int snd_pcm_hw_params_set_channels_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
3732 return snd_pcm_hw_param_set_min(pcm, params, SND_TRY, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
3736 * \brief Restrict a configuration space with a maximum channels count
3737 * \param pcm PCM handle
3738 * \param params Configuration space
3739 * \param val maximum channels count (on return filled with actual maximum)
3740 * \return 0 otherwise a negative error code if configuration space would become empty
3742 int snd_pcm_hw_params_set_channels_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
3744 return snd_pcm_hw_param_set_max(pcm, params, SND_TRY, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
3748 * \brief Restrict a configuration space to have channels counts in a given range
3749 * \param pcm PCM handle
3750 * \param params Configuration space
3751 * \param min minimum channels count (on return filled with actual minimum)
3752 * \param max maximum channels count (on return filled with actual maximum)
3753 * \return 0 otherwise a negative error code if configuration space would become empty
3755 int snd_pcm_hw_params_set_channels_minmax(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *min, unsigned int *max)
3757 return snd_pcm_hw_param_set_minmax(pcm, params, SND_TRY, SND_PCM_HW_PARAM_CHANNELS, min, NULL, max, NULL);
3761 * \brief Restrict a configuration space to have channels count nearest to a target
3762 * \param pcm PCM handle
3763 * \param params Configuration space
3764 * \param val target channels count, returned chosen channels count
3765 * \return 0 otherwise a negative error code if configuration space is empty
3768 int INTERNAL(snd_pcm_hw_params_set_channels_near)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
3770 int snd_pcm_hw_params_set_channels_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
3773 return snd_pcm_hw_param_set_near(pcm, params, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
3777 * \brief Restrict a configuration space to contain only its minimum channels count
3778 * \param pcm PCM handle
3779 * \param params Configuration space
3780 * \param val minimum channels count
3781 * \return 0 otherwise a negative error code
3784 int INTERNAL(snd_pcm_hw_params_set_channels_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
3786 int snd_pcm_hw_params_set_channels_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
3789 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
3793 * \brief Restrict a configuration space to contain only its maximum channels count
3794 * \param pcm PCM handle
3795 * \param params Configuration space
3796 * \param val maximum channels count
3797 * \return 0 otherwise a negative error code
3800 int INTERNAL(snd_pcm_hw_params_set_channels_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
3802 int snd_pcm_hw_params_set_channels_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
3805 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
3810 * \brief Extract rate from a configuration space
3811 * \param params Configuration space
3812 * \param val Returned approximate rate
3813 * \param dir Sub unit direction
3814 * \return 0 otherwise a negative error code if not exactly one is present
3816 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
3819 int INTERNAL(snd_pcm_hw_params_get_rate)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
3821 int snd_pcm_hw_params_get_rate(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
3824 return snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_RATE, val, dir);
3828 * \brief Extract minimum rate from a configuration space
3829 * \param params Configuration space
3830 * \param val Returned approximate minimum rate
3831 * \param dir Sub unit direction
3832 * \return 0 otherwise a negative error code
3834 * Exact value is <,=,> the returned one following dir (-1,0,1)
3837 int INTERNAL(snd_pcm_hw_params_get_rate_min)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
3839 int snd_pcm_hw_params_get_rate_min(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
3842 return snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_RATE, val, dir);
3846 * \brief Extract maximum rate from a configuration space
3847 * \param params Configuration space
3848 * \param val Returned approximate maximum rate
3849 * \param dir Sub unit direction
3850 * \return 0 otherwise a negative error code
3852 * Exact value is <,=,> the returned one following dir (-1,0,1)
3855 int INTERNAL(snd_pcm_hw_params_get_rate_max)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
3857 int snd_pcm_hw_params_get_rate_max(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
3860 return snd_pcm_hw_param_get_max(params, SND_PCM_HW_PARAM_RATE, val, dir);
3864 * \brief Verify if a rate is available inside a configuration space for a PCM
3865 * \param pcm PCM handle
3866 * \param params Configuration space
3867 * \param val approximate rate
3868 * \param dir Sub unit direction
3869 * \return 0 if available a negative error code otherwise
3871 * Wanted exact value is <,=,> val following dir (-1,0,1)
3873 int snd_pcm_hw_params_test_rate(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
3875 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_RATE, val, dir);
3879 * \brief Restrict a configuration space to contain only one rate
3880 * \param pcm PCM handle
3881 * \param params Configuration space
3882 * \param val approximate rate
3883 * \param dir Sub unit direction
3884 * \return 0 otherwise a negative error code if configuration space would become empty
3886 * Wanted exact value is <,=,> val following dir (-1,0,1)
3888 int snd_pcm_hw_params_set_rate(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
3890 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_RATE, val, dir);
3894 * \brief Restrict a configuration space with a minimum rate
3895 * \param pcm PCM handle
3896 * \param params Configuration space
3897 * \param val approximate minimum rate (on return filled with actual minimum)
3898 * \param dir Sub unit direction (on return filled with actual direction)
3899 * \return 0 otherwise a negative error code if configuration space would become empty
3901 * Wanted/actual exact minimum is <,=,> val following dir (-1,0,1)
3903 int snd_pcm_hw_params_set_rate_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
3905 return snd_pcm_hw_param_set_min(pcm, params, SND_TRY, SND_PCM_HW_PARAM_RATE, val, dir);
3909 * \brief Restrict a configuration space with a maximum rate
3910 * \param pcm PCM handle
3911 * \param params Configuration space
3912 * \param val approximate maximum rate (on return filled with actual maximum)
3913 * \param dir Sub unit direction (on return filled with actual direction)
3914 * \return 0 otherwise a negative error code if configuration space would become empty
3916 * Wanted/actual exact maximum is <,=,> val following dir (-1,0,1)
3918 int snd_pcm_hw_params_set_rate_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
3920 return snd_pcm_hw_param_set_max(pcm, params, SND_TRY, SND_PCM_HW_PARAM_RATE, val, dir);
3924 * \brief Restrict a configuration space to have rates in a given range
3925 * \param pcm PCM handle
3926 * \param params Configuration space
3927 * \param min approximate minimum rate (on return filled with actual minimum)
3928 * \param mindir Sub unit direction for minimum (on return filled with actual direction)
3929 * \param max approximate maximum rate (on return filled with actual maximum)
3930 * \param maxdir Sub unit direction for maximum (on return filled with actual direction)
3931 * \return 0 otherwise a negative error code if configuration space would become empty
3933 * Wanted/actual exact min/max is <,=,> val following dir (-1,0,1)
3935 int snd_pcm_hw_params_set_rate_minmax(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *min, int *mindir, unsigned int *max, int *maxdir)
3937 return snd_pcm_hw_param_set_minmax(pcm, params, SND_TRY, SND_PCM_HW_PARAM_RATE, min, mindir, max, maxdir);
3941 * \brief Restrict a configuration space to have rate nearest to a target
3942 * \param pcm PCM handle
3943 * \param params Configuration space
3944 * \param val approximate target rate / returned approximate set rate
3945 * \param dir Sub unit direction
3946 * \return 0 otherwise a negative error code if configuration space is empty
3948 * target/chosen exact value is <,=,> val following dir (-1,0,1)
3951 int INTERNAL(snd_pcm_hw_params_set_rate_near)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
3953 int snd_pcm_hw_params_set_rate_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
3956 return snd_pcm_hw_param_set_near(pcm, params, SND_PCM_HW_PARAM_RATE, val, dir);
3960 * \brief Restrict a configuration space to contain only its minimum rate
3961 * \param pcm PCM handle
3962 * \param params Configuration space
3963 * \param val Returned minimum approximate rate
3964 * \param dir Sub unit direction
3965 * \return 0 otherwise a negative error code
3967 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
3970 int INTERNAL(snd_pcm_hw_params_set_rate_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
3972 int snd_pcm_hw_params_set_rate_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
3975 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_RATE, val, dir);
3979 * \brief Restrict a configuration space to contain only its maximum rate
3980 * \param pcm PCM handle
3981 * \param params Configuration space
3982 * \param val Returned maximum approximate rate
3983 * \param dir Sub unit direction
3984 * \return 0 otherwise a negative error code
3986 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
3989 int INTERNAL(snd_pcm_hw_params_set_rate_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
3991 int snd_pcm_hw_params_set_rate_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
3994 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_RATE, val, dir);
3998 * \brief Restrict a configuration space to contain only real hardware rates
3999 * \param pcm PCM handle
4000 * \param params Configuration space
4001 * \param val 0 = disable, 1 = enable (default) rate resampling
4002 * \return 0 otherwise a negative error code
4004 int snd_pcm_hw_params_set_rate_resample(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val)
4006 assert(pcm && params);
4008 params->flags |= SND_PCM_HW_PARAMS_NORESAMPLE;
4010 params->flags &= ~SND_PCM_HW_PARAMS_NORESAMPLE;
4011 return snd_pcm_hw_refine(pcm, params);
4015 * \brief Extract resample state from a configuration space
4016 * \param pcm PCM handle
4017 * \param params Configuration space
4018 * \param val 0 = disable, 1 = enable rate resampling
4019 * \return 0 otherwise a negative error code
4021 int snd_pcm_hw_params_get_rate_resample(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4023 assert(pcm && params && val);
4024 *val = params->flags & SND_PCM_HW_PARAMS_NORESAMPLE ? 0 : 1;
4029 * \brief Restrict a configuration space to allow the buffer accessible from outside
4030 * \param pcm PCM handle
4031 * \param params Configuration space
4032 * \param val 0 = disable, 1 = enable (default) exporting buffer
4033 * \return 0 otherwise a negative error code
4035 int snd_pcm_hw_params_set_export_buffer(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val)
4037 assert(pcm && params);
4039 params->flags |= SND_PCM_HW_PARAMS_EXPORT_BUFFER;
4041 params->flags &= ~SND_PCM_HW_PARAMS_EXPORT_BUFFER;
4042 return snd_pcm_hw_refine(pcm, params);
4046 * \brief Extract buffer accessibility from a configuration space
4047 * \param pcm PCM handle
4048 * \param params Configuration space
4049 * \param val 0 = disable, 1 = enable exporting buffer
4050 * \return 0 otherwise a negative error code
4052 int snd_pcm_hw_params_get_export_buffer(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4054 assert(pcm && params && val);
4055 *val = params->flags & SND_PCM_HW_PARAMS_EXPORT_BUFFER ? 1 : 0;
4060 * \brief Extract period time from a configuration space
4061 * \param params Configuration space
4062 * \param val Returned approximate period duration in us
4063 * \param dir Sub unit direction
4064 * \return 0 otherwise a negative error code if not exactly one is present
4066 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
4069 int INTERNAL(snd_pcm_hw_params_get_period_time)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4071 int snd_pcm_hw_params_get_period_time(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4074 return snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
4078 * \brief Extract minimum period time from a configuration space
4079 * \param params Configuration space
4080 * \param val approximate minimum period duration in us
4081 * \param dir Sub unit direction
4082 * \return 0 otherwise a negative error code
4084 * Exact value is <,=,> the returned one following dir (-1,0,1)
4087 int INTERNAL(snd_pcm_hw_params_get_period_time_min)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4089 int snd_pcm_hw_params_get_period_time_min(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4092 return snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
4096 * \brief Extract maximum period time from a configuration space
4097 * \param params Configuration space
4098 * \param val approximate maximum period duration in us
4099 * \param dir Sub unit direction
4100 * \return 0 otherwise a negative error code
4102 * Exact value is <,=,> the returned one following dir (-1,0,1)
4105 int INTERNAL(snd_pcm_hw_params_get_period_time_max)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4107 int snd_pcm_hw_params_get_period_time_max(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4110 return snd_pcm_hw_param_get_max(params, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
4114 * \brief Verify if a period time is available inside a configuration space for a PCM
4115 * \param pcm PCM handle
4116 * \param params Configuration space
4117 * \param val approximate period duration in us
4118 * \param dir Sub unit direction
4119 * \return 0 if available a negative error code otherwise
4121 * Wanted exact value is <,=,> val following dir (-1,0,1)
4123 int snd_pcm_hw_params_test_period_time(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
4125 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
4129 * \brief Restrict a configuration space to contain only one period time
4130 * \param pcm PCM handle
4131 * \param params Configuration space
4132 * \param val approximate period duration in us
4133 * \param dir Sub unit direction
4134 * \return 0 otherwise a negative error code if configuration space would become empty
4136 * Wanted exact value is <,=,> val following dir (-1,0,1)
4138 int snd_pcm_hw_params_set_period_time(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
4140 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
4145 * \brief Restrict a configuration space with a minimum period time
4146 * \param pcm PCM handle
4147 * \param params Configuration space
4148 * \param val approximate minimum period duration in us (on return filled with actual minimum)
4149 * \param dir Sub unit direction (on return filled with actual direction)
4150 * \return 0 otherwise a negative error code if configuration space would become empty
4152 * Wanted/actual exact minimum is <,=,> val following dir (-1,0,1)
4154 int snd_pcm_hw_params_set_period_time_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4156 return snd_pcm_hw_param_set_min(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
4160 * \brief Restrict a configuration space with a maximum period time
4161 * \param pcm PCM handle
4162 * \param params Configuration space
4163 * \param val approximate maximum period duration in us (on return filled with actual maximum)
4164 * \param dir Sub unit direction (on return filled with actual direction)
4165 * \return 0 otherwise a negative error code if configuration space would become empty
4167 * Wanted/actual exact maximum is <,=,> val following dir (-1,0,1)
4169 int snd_pcm_hw_params_set_period_time_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4171 return snd_pcm_hw_param_set_max(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
4175 * \brief Restrict a configuration space to have period times in a given range
4176 * \param pcm PCM handle
4177 * \param params Configuration space
4178 * \param min approximate minimum period duration in us (on return filled with actual minimum)
4179 * \param mindir Sub unit direction for minimum (on return filled with actual direction)
4180 * \param max approximate maximum period duration in us (on return filled with actual maximum)
4181 * \param maxdir Sub unit direction for maximum (on return filled with actual direction)
4182 * \return 0 otherwise a negative error code if configuration space would become empty
4184 * Wanted/actual exact min/max is <,=,> val following dir (-1,0,1)
4186 int snd_pcm_hw_params_set_period_time_minmax(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *min, int *mindir, unsigned int *max, int *maxdir)
4188 return snd_pcm_hw_param_set_minmax(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_TIME, min, mindir, max, maxdir);
4192 * \brief Restrict a configuration space to have period time nearest to a target
4193 * \param pcm PCM handle
4194 * \param params Configuration space
4195 * \param val approximate target period duration in us / returned chosen approximate target period duration
4196 * \param dir Sub unit direction
4197 * \return 0 otherwise a negative error code if configuration space is empty
4199 * target/chosen exact value is <,=,> val following dir (-1,0,1)
4202 int INTERNAL(snd_pcm_hw_params_set_period_time_near)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4204 int snd_pcm_hw_params_set_period_time_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4207 return snd_pcm_hw_param_set_near(pcm, params, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
4211 * \brief Restrict a configuration space to contain only its minimum period time
4212 * \param pcm PCM handle
4213 * \param params Configuration space
4214 * \param val Returned approximate period duration in us
4215 * \param dir Sub unit direction
4216 * \return 0 otherwise a negative error code
4218 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
4221 int INTERNAL(snd_pcm_hw_params_set_period_time_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4223 int snd_pcm_hw_params_set_period_time_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4226 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
4230 * \brief Restrict a configuration space to contain only its maximum period time
4231 * \param pcm PCM handle
4232 * \param params Configuration space
4233 * \param val Returned maximum approximate period time
4234 * \param dir Sub unit direction
4235 * \return approximate period duration in us
4238 int INTERNAL(snd_pcm_hw_params_set_period_time_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4240 int snd_pcm_hw_params_set_period_time_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4243 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
4248 * \brief Extract period size from a configuration space
4249 * \param params Configuration space
4250 * \param val Returned approximate period size in frames
4251 * \param dir Sub unit direction
4252 * \return 0 otherwise a negative error code if not exactly one is present
4254 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
4257 int INTERNAL(snd_pcm_hw_params_get_period_size)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
4259 int snd_pcm_hw_params_get_period_size(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
4263 int err = snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
4270 * \brief Extract minimum period size from a configuration space
4271 * \param params Configuration space
4272 * \param val approximate minimum period size in frames
4273 * \param dir Sub unit direction
4274 * \return 0 otherwise a negative error code
4276 * Exact value is <,=,> the returned one following dir (-1,0,1)
4279 int INTERNAL(snd_pcm_hw_params_get_period_size_min)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
4281 int snd_pcm_hw_params_get_period_size_min(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
4284 unsigned int _val = *val;
4285 int err = snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
4292 * \brief Extract maximum period size from a configuration space
4293 * \param params Configuration space
4294 * \param val approximate minimum period size in frames
4295 * \param dir Sub unit direction
4296 * \return 0 otherwise a negative error code
4298 * Exact value is <,=,> the returned one following dir (-1,0,1)
4301 int INTERNAL(snd_pcm_hw_params_get_period_size_max)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
4303 int snd_pcm_hw_params_get_period_size_max(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
4306 unsigned int _val = *val;
4307 int err = snd_pcm_hw_param_get_max(params, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
4314 * \brief Verify if a period size is available inside a configuration space for a PCM
4315 * \param pcm PCM handle
4316 * \param params Configuration space
4317 * \param val approximate period size in frames
4318 * \param dir Sub unit direction
4319 * \return 0 if available a negative error code otherwise
4321 * Wanted exact value is <,=,> val following dir (-1,0,1)
4323 int snd_pcm_hw_params_test_period_size(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t val, int dir)
4325 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_PERIOD_SIZE, val, dir);
4329 * \brief Restrict a configuration space to contain only one period size
4330 * \param pcm PCM handle
4331 * \param params Configuration space
4332 * \param val approximate period size in frames
4333 * \param dir Sub unit direction
4334 * \return 0 otherwise a negative error code if configuration space would become empty
4336 * Wanted exact value is <,=,> val following dir (-1,0,1)
4338 int snd_pcm_hw_params_set_period_size(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t val, int dir)
4340 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_SIZE, val, dir);
4344 * \brief Restrict a configuration space with a minimum period size
4345 * \param pcm PCM handle
4346 * \param params Configuration space
4347 * \param val approximate minimum period size in frames (on return filled with actual minimum)
4348 * \param dir Sub unit direction (on return filled with actual direction)
4349 * \return 0 otherwise a negative error code if configuration space would become empty
4351 * Wanted/actual exact minimum is <,=,> val following dir (-1,0,1)
4353 int snd_pcm_hw_params_set_period_size_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
4355 unsigned int _val = *val;
4356 int err = snd_pcm_hw_param_set_min(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
4363 * \brief Restrict a configuration space with a maximum period size
4364 * \param pcm PCM handle
4365 * \param params Configuration space
4366 * \param val approximate maximum period size in frames (on return filled with actual maximum)
4367 * \param dir Sub unit direction (on return filled with actual direction)
4368 * \return 0 otherwise a negative error code if configuration space would become empty
4370 * Wanted/actual exact minimum is <,=,> val following dir (-1,0,1)
4372 int snd_pcm_hw_params_set_period_size_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
4374 unsigned int _val = *val;
4375 int err = snd_pcm_hw_param_set_max(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
4382 * \brief Restrict a configuration space to have period sizes in a given range
4383 * \param pcm PCM handle
4384 * \param params Configuration space
4385 * \param min approximate minimum period size in frames (on return filled with actual minimum)
4386 * \param mindir Sub unit direction for minimum (on return filled with actual direction)
4387 * \param max approximate maximum period size in frames (on return filled with actual maximum)
4388 * \param maxdir Sub unit direction for maximum (on return filled with actual direction)
4389 * \return 0 otherwise a negative error code if configuration space would become empty
4391 * Wanted/actual exact min/max is <,=,> val following dir (-1,0,1)
4393 int snd_pcm_hw_params_set_period_size_minmax(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *min, int *mindir, snd_pcm_uframes_t *max, int *maxdir)
4395 unsigned int _min = *min;
4396 unsigned int _max = *max;
4397 int err = snd_pcm_hw_param_set_minmax(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_SIZE, &_min, mindir, &_max, maxdir);
4404 * \brief Restrict a configuration space to have period size nearest to a target
4405 * \param pcm PCM handle
4406 * \param params Configuration space
4407 * \param val approximate target period size in frames / returned chosen approximate target period size
4408 * \param dir Sub unit direction
4409 * \return 0 otherwise a negative error code if configuration space is empty
4411 * target/chosen exact value is <,=,> val following dir (-1,0,1)
4414 int INTERNAL(snd_pcm_hw_params_set_period_size_near)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
4416 int snd_pcm_hw_params_set_period_size_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
4419 unsigned int _val = *val;
4420 int err = snd_pcm_hw_param_set_near(pcm, params, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
4427 * \brief Restrict a configuration space to contain only its minimum period size
4428 * \param pcm PCM handle
4429 * \param params Configuration space
4430 * \param val Returned maximum approximate period size in frames
4431 * \param dir Sub unit direction
4432 * \return 0 otherwise a negative error code
4434 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
4437 int INTERNAL(snd_pcm_hw_params_set_period_size_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
4439 int snd_pcm_hw_params_set_period_size_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
4443 int err = snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
4450 * \brief Restrict a configuration space to contain only its maximum period size
4451 * \param pcm PCM handle
4452 * \param params Configuration space
4453 * \param val Returned maximum approximate period size in frames
4454 * \param dir Sub unit direction
4455 * \return 0 otherwise a negative error code
4457 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
4460 int INTERNAL(snd_pcm_hw_params_set_period_size_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
4462 int snd_pcm_hw_params_set_period_size_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
4466 int err = snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
4473 * \brief Restrict a configuration space to contain only integer period sizes
4474 * \param pcm PCM handle
4475 * \param params Configuration space
4476 * \return 0 otherwise a negative error code if configuration space would become empty
4478 int snd_pcm_hw_params_set_period_size_integer(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
4480 return snd_pcm_hw_param_set_integer(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_SIZE);
4485 * \brief Extract periods from a configuration space
4486 * \param params Configuration space
4487 * \param val approximate periods per buffer
4488 * \param dir Sub unit direction
4489 * \return 0 otherwise a negative error code if not exactly one is present
4491 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
4494 int INTERNAL(snd_pcm_hw_params_get_periods)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4496 int snd_pcm_hw_params_get_periods(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4499 return snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_PERIODS, val, dir);
4503 * \brief Extract minimum periods count from a configuration space
4504 * \param params Configuration space
4505 * \param val approximate minimum periods per buffer
4506 * \param dir Sub unit direction
4507 * \return 0 otherwise a negative error code
4509 * Exact value is <,=,> the returned one following dir (-1,0,1)
4512 int INTERNAL(snd_pcm_hw_params_get_periods_min)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4514 int snd_pcm_hw_params_get_periods_min(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4517 return snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_PERIODS, val, dir);
4521 * \brief Extract maximum periods count from a configuration space
4522 * \param params Configuration space
4523 * \param val approximate maximum periods per buffer
4524 * \param dir Sub unit direction
4525 * \return 0 otherwise a negative error code
4527 * Exact value is <,=,> the returned one following dir (-1,0,1)
4530 int INTERNAL(snd_pcm_hw_params_get_periods_max)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4532 int snd_pcm_hw_params_get_periods_max(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4535 return snd_pcm_hw_param_get_max(params, SND_PCM_HW_PARAM_PERIODS, val, dir);
4539 * \brief Verify if a periods count is available inside a configuration space for a PCM
4540 * \param pcm PCM handle
4541 * \param params Configuration space
4542 * \param val approximate periods per buffer
4543 * \param dir Sub unit direction
4544 * \return 0 if available a negative error code otherwise
4546 * Wanted exact value is <,=,> val following dir (-1,0,1)
4548 int snd_pcm_hw_params_test_periods(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
4550 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_PERIODS, val, dir);
4554 * \brief Restrict a configuration space to contain only one periods count
4555 * \param pcm PCM handle
4556 * \param params Configuration space
4557 * \param val approximate periods per buffer
4558 * \param dir Sub unit direction
4559 * \return 0 otherwise a negative error code if configuration space would become empty
4561 * Wanted exact value is <,=,> val following dir (-1,0,1)
4563 int snd_pcm_hw_params_set_periods(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
4565 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIODS, val, dir);
4569 * \brief Restrict a configuration space with a minimum periods count
4570 * \param pcm PCM handle
4571 * \param params Configuration space
4572 * \param val approximate minimum periods per buffer (on return filled with actual minimum)
4573 * \param dir Sub unit direction (on return filled with actual direction)
4574 * \return 0 otherwise a negative error code if configuration space would become empty
4576 * Wanted/actual exact minimum is <,=,> val following dir (-1,0,1)
4578 int snd_pcm_hw_params_set_periods_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4580 return snd_pcm_hw_param_set_min(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIODS, val, dir);
4584 * \brief Restrict a configuration space with a maximum periods count
4585 * \param pcm PCM handle
4586 * \param params Configuration space
4587 * \param val approximate maximum periods per buffer (on return filled with actual maximum)
4588 * \param dir Sub unit direction (on return filled with actual direction)
4589 * \return 0 otherwise a negative error code if configuration space would become empty
4591 * Wanted/actual exact maximum is <,=,> val following dir (-1,0,1)
4593 int snd_pcm_hw_params_set_periods_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4595 return snd_pcm_hw_param_set_max(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIODS, val, dir);
4599 * \brief Restrict a configuration space to have periods counts in a given range
4600 * \param pcm PCM handle
4601 * \param params Configuration space
4602 * \param min approximate minimum periods per buffer (on return filled with actual minimum)
4603 * \param mindir Sub unit direction for minimum (on return filled with actual direction)
4604 * \param max approximate maximum periods per buffer (on return filled with actual maximum)
4605 * \param maxdir Sub unit direction for maximum (on return filled with actual direction)
4606 * \return 0 otherwise a negative error code if configuration space would become empty
4608 * Wanted/actual exact min/max is <,=,> val following dir (-1,0,1)
4610 int snd_pcm_hw_params_set_periods_minmax(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *min, int *mindir, unsigned int *max, int *maxdir)
4612 return snd_pcm_hw_param_set_minmax(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIODS, min, mindir, max, maxdir);
4616 * \brief Restrict a configuration space to have periods count nearest to a target
4617 * \param pcm PCM handle
4618 * \param params Configuration space
4619 * \param val approximate target periods per buffer / returned chosen approximate target periods per buffer
4620 * \param dir Sub unit direction
4621 * \return 0 otherwise a negative error code if configuration space is empty
4623 * target/chosen exact value is <,=,> val following dir (-1,0,1)
4626 int INTERNAL(snd_pcm_hw_params_set_periods_near)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4628 int snd_pcm_hw_params_set_periods_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4631 return snd_pcm_hw_param_set_near(pcm, params, SND_PCM_HW_PARAM_PERIODS, val, dir);
4635 * \brief Restrict a configuration space to contain only its minimum periods count
4636 * \param pcm PCM handle
4637 * \param params Configuration space
4638 * \param val Returned approximate minimum periods per buffer
4639 * \param dir Sub unit direction
4640 * \return 0 otherwise a negative error code
4642 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
4645 int INTERNAL(snd_pcm_hw_params_set_periods_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4647 int snd_pcm_hw_params_set_periods_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4650 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_PERIODS, val, dir);
4654 * \brief Restrict a configuration space to contain only its maximum periods count
4655 * \param pcm PCM handle
4656 * \param params Configuration space
4657 * \param val Returned approximate maximum periods per buffer
4658 * \param dir Sub unit direction
4659 * \return 0 otherwise a negative error code
4661 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
4664 int INTERNAL(snd_pcm_hw_params_set_periods_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4666 int snd_pcm_hw_params_set_periods_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4669 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_PERIODS, val, dir);
4673 * \brief Restrict a configuration space to contain only integer periods counts
4674 * \param pcm PCM handle
4675 * \param params Configuration space
4676 * \return 0 otherwise a negative error code if configuration space would become empty
4678 int snd_pcm_hw_params_set_periods_integer(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
4680 return snd_pcm_hw_param_set_integer(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIODS);
4685 * \brief Extract buffer time from a configuration space
4686 * \param params Configuration space
4687 * \param val Returned buffer time in us
4688 * \param dir Sub unit direction
4689 * \return 0 otherwise a negative error code if not exactly one is present
4691 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
4694 int INTERNAL(snd_pcm_hw_params_get_buffer_time)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4696 int snd_pcm_hw_params_get_buffer_time(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4699 return snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
4703 * \brief Extract minimum buffer time from a configuration space
4704 * \param params Configuration space
4705 * \param val approximate minimum buffer duration in us
4706 * \param dir Sub unit direction
4707 * \return 0 otherwise a negative error code
4709 * Exact value is <,=,> the returned one following dir (-1,0,1)
4712 int INTERNAL(snd_pcm_hw_params_get_buffer_time_min)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4714 int snd_pcm_hw_params_get_buffer_time_min(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4717 return snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
4721 * \brief Extract maximum buffer time from a configuration space
4722 * \param params Configuration space
4723 * \param val approximate maximum buffer duration in us
4724 * \param dir Sub unit direction
4725 * \return 0 otherwise a negative error code
4727 * Exact value is <,=,> the returned one following dir (-1,0,1)
4730 int INTERNAL(snd_pcm_hw_params_get_buffer_time_max)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4732 int snd_pcm_hw_params_get_buffer_time_max(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4735 return snd_pcm_hw_param_get_max(params, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
4739 * \brief Verify if a buffer time is available inside a configuration space for a PCM
4740 * \param pcm PCM handle
4741 * \param params Configuration space
4742 * \param val approximate buffer duration in us
4743 * \param dir Sub unit direction
4744 * \return 0 if available a negative error code otherwise
4746 * Wanted exact value is <,=,> val following dir (-1,0,1)
4748 int snd_pcm_hw_params_test_buffer_time(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
4750 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
4754 * \brief Restrict a configuration space to contain only one buffer time
4755 * \param pcm PCM handle
4756 * \param params Configuration space
4757 * \param val approximate buffer duration in us
4758 * \param dir Sub unit direction
4759 * \return 0 otherwise a negative error code if configuration space would become empty
4761 * Wanted exact value is <,=,> val following dir (-1,0,1)
4763 int snd_pcm_hw_params_set_buffer_time(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
4765 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
4769 * \brief Restrict a configuration space with a minimum buffer time
4770 * \param pcm PCM handle
4771 * \param params Configuration space
4772 * \param val approximate minimum buffer duration in us (on return filled with actual minimum)
4773 * \param dir Sub unit direction (on return filled with actual direction)
4774 * \return 0 otherwise a negative error code if configuration space would become empty
4776 * Wanted/actual exact minimum is <,=,> val following dir (-1,0,1)
4778 int snd_pcm_hw_params_set_buffer_time_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4780 return snd_pcm_hw_param_set_min(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
4784 * \brief Restrict a configuration space with a maximum buffer time
4785 * \param pcm PCM handle
4786 * \param params Configuration space
4787 * \param val approximate maximum buffer duration in us (on return filled with actual maximum)
4788 * \param dir Sub unit direction (on return filled with actual direction)
4789 * \return 0 otherwise a negative error code if configuration space would become empty
4791 * Wanted/actual exact maximum is <,=,> val following dir (-1,0,1)
4793 int snd_pcm_hw_params_set_buffer_time_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4795 return snd_pcm_hw_param_set_max(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
4799 * \brief Restrict a configuration space to have buffer times in a given range
4800 * \param pcm PCM handle
4801 * \param params Configuration space
4802 * \param min approximate minimum buffer duration in us (on return filled with actual minimum)
4803 * \param mindir Sub unit direction for minimum (on return filled with actual direction)
4804 * \param max approximate maximum buffer duration in us (on return filled with actual maximum)
4805 * \param maxdir Sub unit direction for maximum (on return filled with actual direction)
4806 * \return 0 otherwise a negative error code if configuration space would become empty
4808 * Wanted/actual exact min/max is <,=,> val following dir (-1,0,1)
4810 int snd_pcm_hw_params_set_buffer_time_minmax(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *min, int *mindir, unsigned int *max, int *maxdir)
4812 return snd_pcm_hw_param_set_minmax(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_TIME, min, mindir, max, maxdir);
4816 * \brief Restrict a configuration space to have buffer time nearest to a target
4817 * \param pcm PCM handle
4818 * \param params Configuration space
4819 * \param val approximate target buffer duration in us / returned chosen approximate target buffer duration
4820 * \param dir Sub unit direction
4821 * \return 0 otherwise a negative error code if configuration space is empty
4823 * target/chosen exact value is <,=,> val following dir (-1,0,1)
4826 int INTERNAL(snd_pcm_hw_params_set_buffer_time_near)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4828 int snd_pcm_hw_params_set_buffer_time_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4831 return snd_pcm_hw_param_set_near(pcm, params, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
4835 * \brief Restrict a configuration space to contain only its minimum buffer time
4836 * \param pcm PCM handle
4837 * \param params Configuration space
4838 * \param val Returned approximate minimum buffer duration in us
4839 * \param dir Sub unit direction
4840 * \return 0 otherwise a negative error code
4842 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
4845 int INTERNAL(snd_pcm_hw_params_set_buffer_time_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4847 int snd_pcm_hw_params_set_buffer_time_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4850 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
4854 * \brief Restrict a configuration space to contain only its maximum buffered time
4855 * \param pcm PCM handle
4856 * \param params Configuration space
4857 * \param val Returned approximate maximum buffer duration in us
4858 * \param dir Sub unit direction
4859 * \return 0 otherwise a negative error code
4861 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
4864 int INTERNAL(snd_pcm_hw_params_set_buffer_time_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4866 int snd_pcm_hw_params_set_buffer_time_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4869 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
4874 * \brief Extract buffer size from a configuration space
4875 * \param params Configuration space
4876 * \param val Returned buffer size in frames
4877 * \return 0 otherwise a negative error code if not exactly one is present
4880 int INTERNAL(snd_pcm_hw_params_get_buffer_size)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
4882 int snd_pcm_hw_params_get_buffer_size(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
4886 int err = snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
4893 * \brief Extract minimum buffer size from a configuration space
4894 * \param params Configuration space
4895 * \param val Returned approximate minimum buffer size in frames
4896 * \return 0 otherwise a negative error code
4899 int INTERNAL(snd_pcm_hw_params_get_buffer_size_min)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
4901 int snd_pcm_hw_params_get_buffer_size_min(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
4905 int err = snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
4912 * \brief Extract maximum buffer size from a configuration space
4913 * \param params Configuration space
4914 * \param val Returned approximate maximum buffer size in frames
4915 * \return 0 otherwise a negative error code
4917 * Exact value is <,=,> the returned one following dir (-1,0,1)
4920 int INTERNAL(snd_pcm_hw_params_get_buffer_size_max)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
4922 int snd_pcm_hw_params_get_buffer_size_max(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
4926 int err = snd_pcm_hw_param_get_max(params, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
4933 * \brief Verify if a buffer size is available inside a configuration space for a PCM
4934 * \param pcm PCM handle
4935 * \param params Configuration space
4936 * \param val buffer size in frames
4937 * \return 0 if available a negative error code otherwise
4939 * Wanted exact value is <,=,> val following dir (-1,0,1)
4941 int snd_pcm_hw_params_test_buffer_size(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t val)
4943 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_BUFFER_SIZE, val, 0);
4947 * \brief Restrict a configuration space to contain only one buffer size
4948 * \param pcm PCM handle
4949 * \param params Configuration space
4950 * \param val buffer size in frames
4951 * \return 0 otherwise a negative error code if configuration space would become empty
4953 * Wanted exact value is <,=,> val following dir (-1,0,1)
4955 int snd_pcm_hw_params_set_buffer_size(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t val)
4957 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_SIZE, val, 0);
4961 * \brief Restrict a configuration space with a minimum buffer size
4962 * \param pcm PCM handle
4963 * \param params Configuration space
4964 * \param val approximate minimum buffer size in frames (on return filled with actual minimum)
4965 * \return 0 otherwise a negative error code if configuration space would become empty
4967 int snd_pcm_hw_params_set_buffer_size_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
4969 unsigned int _val = *val;
4970 int err = snd_pcm_hw_param_set_min(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
4977 * \brief Restrict a configuration space with a maximum buffer size
4978 * \param pcm PCM handle
4979 * \param params Configuration space
4980 * \param val approximate maximum buffer size in frames (on return filled with actual maximum)
4981 * \return 0 otherwise a negative error code if configuration space would become empty
4983 int snd_pcm_hw_params_set_buffer_size_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
4985 unsigned int _val = *val;
4986 int err = snd_pcm_hw_param_set_max(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
4993 * \brief Restrict a configuration space to have buffer sizes in a given range
4994 * \param pcm PCM handle
4995 * \param params Configuration space
4996 * \param min approximate minimum buffer size in frames (on return filled with actual minimum)
4997 * \param max approximate maximum buffer size in frames (on return filled with actual maximum)
4998 * \return 0 otherwise a negative error code if configuration space would become empty
5000 int snd_pcm_hw_params_set_buffer_size_minmax(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *min, snd_pcm_uframes_t *max)
5002 unsigned int _min = *min;
5003 unsigned int _max = *max;
5004 int err = snd_pcm_hw_param_set_minmax(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_SIZE, &_min, NULL, &_max, NULL);
5011 * \brief Restrict a configuration space to have buffer size nearest to a target
5012 * \param pcm PCM handle
5013 * \param params Configuration space
5014 * \param val approximate target buffer size in frames / returned chosen approximate target buffer size in frames
5015 * \return 0 otherwise a negative error code if configuration space is empty
5018 int INTERNAL(snd_pcm_hw_params_set_buffer_size_near)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5020 int snd_pcm_hw_params_set_buffer_size_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5023 unsigned int _val = *val;
5024 int err = snd_pcm_hw_param_set_near(pcm, params, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
5031 * \brief Restrict a configuration space to contain only its minimum buffer size
5032 * \param pcm PCM handle
5033 * \param params Configuration space
5034 * \param val Returned minimum buffer size in frames
5035 * \return buffer size in frames
5038 int INTERNAL(snd_pcm_hw_params_set_buffer_size_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5040 int snd_pcm_hw_params_set_buffer_size_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5044 int err = snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
5051 * \brief Restrict a configuration space to contain only its maximum buffer size
5052 * \param pcm PCM handle
5053 * \param params Configuration space
5054 * \param val Returned maximum buffer size in frames
5055 * \return 0 otherwise a negative error code
5058 int INTERNAL(snd_pcm_hw_params_set_buffer_size_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5060 int snd_pcm_hw_params_set_buffer_size_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5064 int err = snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
5072 * \brief Extract tick time from a configuration space
5073 * \param params Configuration space
5074 * \param val Returned approximate tick duration in us
5075 * \param dir Sub unit direction
5076 * \return 0 otherwise a negative error code if not exactly one is present
5078 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5081 int INTERNAL(snd_pcm_hw_params_get_tick_time)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5083 int snd_pcm_hw_params_get_tick_time(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5086 return snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_TICK_TIME, val, dir);
5090 * \brief Extract minimum tick time from a configuration space
5091 * \param params Configuration space
5092 * \param val Returned approximate minimum tick duration in us
5093 * \param dir Sub unit direction
5094 * \return 0 otherwise a negative error code
5096 * Exact value is <,=,> the returned one following dir (-1,0,1)
5099 int INTERNAL(snd_pcm_hw_params_get_tick_time_min)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5101 int snd_pcm_hw_params_get_tick_time_min(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5104 return snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_TICK_TIME, val, dir);
5108 * \brief Extract maximum tick time from a configuration space
5109 * \param params Configuration space
5110 * \param val Returned approximate maximum tick duration in us
5111 * \param dir Sub unit direction
5112 * \return 0 otherwise a negative error code
5114 * Exact value is <,=,> the returned one following dir (-1,0,1)
5117 int INTERNAL(snd_pcm_hw_params_get_tick_time_max)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5119 int snd_pcm_hw_params_get_tick_time_max(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5122 return snd_pcm_hw_param_get_max(params, SND_PCM_HW_PARAM_TICK_TIME, val, dir);
5126 * \brief Verify if a tick time is available inside a configuration space for a PCM
5127 * \param pcm PCM handle
5128 * \param params Configuration space
5129 * \param val approximate tick duration in us
5130 * \param dir Sub unit direction
5131 * \return 0 if available a negative error code otherwise
5133 * Wanted exact value is <,=,> val following dir (-1,0,1)
5135 int snd_pcm_hw_params_test_tick_time(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
5137 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_TICK_TIME, val, dir);
5141 * \brief Restrict a configuration space to contain only one tick time
5142 * \param pcm PCM handle
5143 * \param params Configuration space
5144 * \param val approximate tick duration in us
5145 * \param dir Sub unit direction
5146 * \return 0 otherwise a negative error code if configuration space would become empty
5148 * Wanted exact value is <,=,> val following dir (-1,0,1)
5150 int snd_pcm_hw_params_set_tick_time(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
5152 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_TICK_TIME, val, dir);
5156 * \brief Restrict a configuration space with a minimum tick time
5157 * \param pcm PCM handle
5158 * \param params Configuration space
5159 * \param val approximate minimum tick duration in us (on return filled with actual minimum)
5160 * \param dir Sub unit direction (on return filled with actual direction)
5161 * \return 0 otherwise a negative error code if configuration space would become empty
5163 * Wanted/actual exact minimum is <,=,> val following dir (-1,0,1)
5165 int snd_pcm_hw_params_set_tick_time_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5167 return snd_pcm_hw_param_set_min(pcm, params, SND_TRY, SND_PCM_HW_PARAM_TICK_TIME, val, dir);
5171 * \brief Restrict a configuration space with a maximum tick time
5172 * \param pcm PCM handle
5173 * \param params Configuration space
5174 * \param val approximate maximum tick duration in us (on return filled with actual maximum)
5175 * \param dir Sub unit direction (on return filled with actual direction)
5176 * \return 0 otherwise a negative error code if configuration space would become empty
5178 * Wanted/actual exact maximum is <,=,> val following dir (-1,0,1)
5180 int snd_pcm_hw_params_set_tick_time_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5182 return snd_pcm_hw_param_set_max(pcm, params, SND_TRY, SND_PCM_HW_PARAM_TICK_TIME, val, dir);
5186 * \brief Restrict a configuration space to have tick times in a given range
5187 * \param pcm PCM handle
5188 * \param params Configuration space
5189 * \param min approximate minimum tick duration in us (on return filled with actual minimum)
5190 * \param mindir Sub unit direction for minimum (on return filled with actual direction)
5191 * \param max approximate maximum tick duration in us (on return filled with actual maximum)
5192 * \param maxdir Sub unit direction for maximum (on return filled with actual direction)
5193 * \return 0 otherwise a negative error code if configuration space would become empty
5195 * Wanted/actual exact min/max is <,=,> val following dir (-1,0,1)
5197 int snd_pcm_hw_params_set_tick_time_minmax(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *min, int *mindir, unsigned int *max, int *maxdir)
5199 return snd_pcm_hw_param_set_minmax(pcm, params, SND_TRY, SND_PCM_HW_PARAM_TICK_TIME, min, mindir, max, maxdir);
5203 * \brief Restrict a configuration space to have tick time nearest to a target
5204 * \param pcm PCM handle
5205 * \param params Configuration space
5206 * \param val approximate target tick duration in us / returned chosen approximate target tick duration in us
5207 * \param dir Sub unit direction
5208 * \return 0 otherwise a negative error code if configuration space is empty
5210 * target/chosen exact value is <,=,> val following dir (-1,0,1)
5213 int INTERNAL(snd_pcm_hw_params_set_tick_time_near)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5215 int snd_pcm_hw_params_set_tick_time_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5218 return snd_pcm_hw_param_set_near(pcm, params, SND_PCM_HW_PARAM_TICK_TIME, val, dir);
5222 * \brief Restrict a configuration space to contain only its minimum tick time
5223 * \param pcm PCM handle
5224 * \param params Configuration space
5225 * \param val Returned approximate minimum tick duration in us
5226 * \param dir Sub unit direction
5227 * \return 0 otherwise a negative error code
5229 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5232 int INTERNAL(snd_pcm_hw_params_set_tick_time_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5234 int snd_pcm_hw_params_set_tick_time_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5237 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_TICK_TIME, val, dir);
5241 * \brief Restrict a configuration space to contain only its maximum tick time
5242 * \param pcm PCM handle
5243 * \param params Configuration space
5244 * \param val Returned approximate maximum tick duration in us
5245 * \param dir Sub unit direction
5246 * \return 0 otherwise a negative error code
5248 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5251 int INTERNAL(snd_pcm_hw_params_set_tick_time_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5253 int snd_pcm_hw_params_set_tick_time_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5256 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_TICK_TIME, val, dir);
5260 * \brief Get the minimum transfer align value in samples
5261 * \param params Configuration space
5262 * \param val Returned minimum align value
5263 * \return 0 otherwise a negative error code if not exactly one is present
5265 int snd_pcm_hw_params_get_min_align(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5267 unsigned int format, channels, fb, min_align;
5270 err = snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_FORMAT, &format, NULL);
5273 err = snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_CHANNELS, &channels, NULL);
5276 // compute frame bits
5277 fb = snd_pcm_format_physical_width((snd_pcm_format_t)format) * channels;
5289 * \brief Return current software configuration for a PCM
5290 * \param pcm PCM handle
5291 * \param params Software configuration container
5292 * \return 0 on success otherwise a negative error code
5294 int snd_pcm_sw_params_current(snd_pcm_t *pcm, snd_pcm_sw_params_t *params)
5296 assert(pcm && params);
5297 if (CHECK_SANITY(! pcm->setup)) {
5298 SNDMSG("PCM not set up");
5301 params->tstamp_mode = pcm->tstamp_mode;
5302 params->period_step = pcm->period_step;
5303 params->sleep_min = pcm->sleep_min;
5304 params->avail_min = pcm->avail_min;
5305 params->xfer_align = pcm->xfer_align;
5306 params->start_threshold = pcm->start_threshold;
5307 params->stop_threshold = pcm->stop_threshold;
5308 params->silence_threshold = pcm->silence_threshold;
5309 params->silence_size = pcm->silence_size;
5310 params->boundary = pcm->boundary;
5315 * \brief Dump a software configuration
5316 * \param params Software configuration container
5317 * \param out Output handle
5318 * \return 0 on success otherwise a negative error code
5320 int snd_pcm_sw_params_dump(snd_pcm_sw_params_t *params, snd_output_t *out)
5322 snd_output_printf(out, "start_mode: %s\n", snd_pcm_start_mode_name(snd_pcm_sw_params_get_start_mode(params)));
5323 snd_output_printf(out, "xrun_mode: %s\n", snd_pcm_xrun_mode_name(snd_pcm_sw_params_get_xrun_mode(params)));
5324 snd_output_printf(out, "tstamp_mode: %s\n", snd_pcm_tstamp_mode_name(params->tstamp_mode));
5325 snd_output_printf(out, "period_step: %u\n", params->period_step);
5326 snd_output_printf(out, "sleep_min: %u\n", params->sleep_min);
5327 snd_output_printf(out, "avail_min: %lu\n", params->avail_min);
5328 snd_output_printf(out, "xfer_align: %lu\n", params->xfer_align);
5329 snd_output_printf(out, "silence_threshold: %lu\n", params->silence_threshold);
5330 snd_output_printf(out, "silence_size: %lu\n", params->silence_size);
5331 snd_output_printf(out, "boundary: %lu\n", params->boundary);
5336 * \brief get size of #snd_pcm_sw_params_t
5337 * \return size in bytes
5339 size_t snd_pcm_sw_params_sizeof()
5341 return sizeof(snd_pcm_sw_params_t);
5345 * \brief allocate an invalid #snd_pcm_sw_params_t using standard malloc
5346 * \param ptr returned pointer
5347 * \return 0 on success otherwise negative error code
5349 int snd_pcm_sw_params_malloc(snd_pcm_sw_params_t **ptr)
5352 *ptr = calloc(1, sizeof(snd_pcm_sw_params_t));
5359 * \brief frees a previously allocated #snd_pcm_sw_params_t
5360 * \param obj pointer to object to free
5362 void snd_pcm_sw_params_free(snd_pcm_sw_params_t *obj)
5368 * \brief copy one #snd_pcm_sw_params_t to another
5369 * \param dst pointer to destination
5370 * \param src pointer to source
5372 void snd_pcm_sw_params_copy(snd_pcm_sw_params_t *dst, const snd_pcm_sw_params_t *src)
5379 * \brief Get boundary for ring pointers from a software configuration container
5380 * \param params Software configuration container
5381 * \param val Returned boundary in frames
5382 * \return 0 otherwise a negative error code
5384 int snd_pcm_sw_params_get_boundary(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
5387 *val = params->boundary;
5392 * \brief (DEPRECATED) Set start mode inside a software configuration container
5393 * \param pcm PCM handle
5394 * \param params Software configuration container
5395 * \param val Start mode
5396 * \return 0 otherwise a negative error code
5398 int snd_pcm_sw_params_set_start_mode(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_start_t val)
5400 assert(pcm && params);
5402 case SND_PCM_START_DATA:
5403 params->start_threshold = 1;
5405 case SND_PCM_START_EXPLICIT:
5406 params->start_threshold = pcm->boundary;
5409 SNDMSG("invalid start mode value %d\n", val);
5416 link_warning(snd_pcm_sw_params_set_start_mode, "Warning: start_mode is deprecated, consider to use start_threshold");
5420 * \brief (DEPRECATED) Get start mode from a software configuration container
5421 * \param params Software configuration container
5422 * \return start mode
5424 snd_pcm_start_t snd_pcm_sw_params_get_start_mode(const snd_pcm_sw_params_t *params)
5428 return params->start_threshold > 1024 * 1024 ? SND_PCM_START_EXPLICIT : SND_PCM_START_DATA;
5432 link_warning(snd_pcm_sw_params_get_start_mode, "Warning: start_mode is deprecated, consider to use start_threshold");
5436 * \brief (DEPRECATED) Set xrun mode inside a software configuration container
5437 * \param pcm PCM handle
5438 * \param params Software configuration container
5439 * \param val Xrun mode
5440 * \return 0 otherwise a negative error code
5443 int snd_pcm_sw_params_set_xrun_mode(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_sw_params_t *params, snd_pcm_xrun_t val)
5445 int snd_pcm_sw_params_set_xrun_mode(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_xrun_t val)
5448 assert(pcm && params);
5450 case SND_PCM_XRUN_STOP:
5451 params->stop_threshold = pcm->buffer_size;
5453 case SND_PCM_XRUN_NONE:
5454 params->stop_threshold = pcm->boundary;
5457 SNDMSG("invalid xrun mode value %d\n", val);
5464 link_warning(snd_pcm_sw_params_set_xrun_mode, "Warning: xrun_mode is deprecated, consider to use stop_threshold");
5468 * \brief (DEPRECATED) Get xrun mode from a software configuration container
5469 * \param params Software configuration container
5472 snd_pcm_xrun_t snd_pcm_sw_params_get_xrun_mode(const snd_pcm_sw_params_t *params)
5476 return params->stop_threshold > 1024 * 1024 ? SND_PCM_XRUN_NONE : SND_PCM_XRUN_STOP;
5480 link_warning(snd_pcm_sw_params_get_xrun_mode, "Warning: xrun_mode is deprecated, consider to use stop_threshold");
5484 * \brief Set timestamp mode inside a software configuration container
5485 * \param pcm PCM handle
5486 * \param params Software configuration container
5487 * \param val Timestamp mode
5488 * \return 0 otherwise a negative error code
5491 int snd_pcm_sw_params_set_tstamp_mode(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_sw_params_t *params, snd_pcm_tstamp_t val)
5493 int snd_pcm_sw_params_set_tstamp_mode(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_tstamp_t val)
5496 assert(pcm && params);
5497 if (CHECK_SANITY(val > SND_PCM_TSTAMP_LAST)) {
5498 SNDMSG("invalid tstamp_mode value %d", val);
5501 params->tstamp_mode = val;
5506 * \brief Get timestamp mode from a software configuration container
5507 * \param params Software configuration container
5508 * \param val Returned timestamp
5509 * \return 0 otherwise a negative error code
5512 int INTERNAL(snd_pcm_sw_params_get_tstamp_mode)(const snd_pcm_sw_params_t *params, snd_pcm_tstamp_t *val)
5514 int snd_pcm_sw_params_get_tstamp_mode(const snd_pcm_sw_params_t *params, snd_pcm_tstamp_t *val)
5517 assert(params && val);
5518 *val = params->tstamp_mode;
5523 * \brief Set minimum number of ticks to sleep inside a software configuration container
5524 * \param pcm PCM handle
5525 * \param params Software configuration container
5526 * \param val Minimum ticks to sleep or 0 to disable the use of tick timer
5527 * \return 0 otherwise a negative error code
5530 int snd_pcm_sw_params_set_sleep_min(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_sw_params_t *params, unsigned int val)
5532 int snd_pcm_sw_params_set_sleep_min(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, unsigned int val)
5535 assert(pcm && params);
5536 params->sleep_min = val;
5541 * \brief Get minimum numbers of ticks to sleep from a software configuration container
5542 * \param params Software configuration container
5543 * \param val returned minimum number of ticks to sleep or 0 if tick timer is disabled
5544 * \return 0 otherwise a negative error code
5547 int INTERNAL(snd_pcm_sw_params_get_sleep_min)(const snd_pcm_sw_params_t *params, unsigned int *val)
5549 int snd_pcm_sw_params_get_sleep_min(const snd_pcm_sw_params_t *params, unsigned int *val)
5552 assert(params && val);
5553 *val = params->sleep_min;
5558 * \brief Set avail min inside a software configuration container
5559 * \param pcm PCM handle
5560 * \param params Software configuration container
5561 * \param val Minimum avail frames to consider PCM ready
5562 * \return 0 otherwise a negative error code
5564 * Note: This is similar to setting an OSS wakeup point. The valid
5565 * values for 'val' are determined by the specific hardware. Most PC
5566 * sound cards can only accept power of 2 frame counts (i.e. 512,
5567 * 1024, 2048). You cannot use this as a high resolution timer - it
5568 * is limited to how often the sound card hardware raises an
5569 * interrupt. Note that you can greatly improve the reponses using
5570 * \ref snd_pcm_sw_params_set_sleep_min where another timing source
5574 int snd_pcm_sw_params_set_avail_min(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
5576 int snd_pcm_sw_params_set_avail_min(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
5579 assert(pcm && params);
5580 params->avail_min = val;
5585 * \brief Get avail min from a software configuration container
5586 * \param params Software configuration container
5587 * \param val returned minimum available frames to consider PCM ready
5588 * \return 0 otherwise a negative error code
5591 int INTERNAL(snd_pcm_sw_params_get_avail_min)(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
5593 int snd_pcm_sw_params_get_avail_min(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
5596 assert(params && val);
5597 *val = params->avail_min;
5603 * \brief Set xfer align inside a software configuration container
5604 * \param pcm PCM handle
5605 * \param params Software configuration container
5606 * \param val Chunk size (frames are attempted to be transferred in chunks)
5607 * \return 0 otherwise a negative error code
5610 int snd_pcm_sw_params_set_xfer_align(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
5612 int snd_pcm_sw_params_set_xfer_align(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
5615 assert(pcm && params);
5616 if (CHECK_SANITY(val % pcm->min_align)) {
5617 SNDMSG("xfer_align (%ld) is not aligned to min_align (%ld)", val, pcm->min_align);
5620 params->xfer_align = val;
5625 * \brief Get xfer align from a software configuration container
5626 * \param params Software configuration container
5627 * \param val returned chunk size (frames are attempted to be transferred in chunks)
5628 * \return 0 otherwise a negative error code
5631 int INTERNAL(snd_pcm_sw_params_get_xfer_align)(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
5633 int snd_pcm_sw_params_get_xfer_align(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
5636 assert(params && val);
5637 *val = params->xfer_align;
5643 * \brief Set start threshold inside a software configuration container
5644 * \param pcm PCM handle
5645 * \param params Software configuration container
5646 * \param val Start threshold in frames
5647 * \return 0 otherwise a negative error code
5649 * PCM is automatically started when playback frames available to PCM
5650 * are >= threshold or when requested capture frames are >= threshold
5653 int snd_pcm_sw_params_set_start_threshold(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
5655 int snd_pcm_sw_params_set_start_threshold(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
5658 assert(pcm && params);
5659 params->start_threshold = val;
5664 * \brief Get start threshold from a software configuration container
5665 * \param params Software configuration container
5666 * \param val Returned start threshold in frames
5667 * \return 0 otherwise a negative error code
5669 * PCM is automatically started when playback frames available to PCM
5670 * are >= threshold or when requested capture frames are >= threshold
5673 int INTERNAL(snd_pcm_sw_params_get_start_threshold)(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
5675 int snd_pcm_sw_params_get_start_threshold(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
5679 *val = params->start_threshold;
5685 * \brief Set stop threshold inside a software configuration container
5686 * \param pcm PCM handle
5687 * \param params Software configuration container
5688 * \param val Stop threshold in frames
5689 * \return 0 otherwise a negative error code
5691 * PCM is automatically stopped in #SND_PCM_STATE_XRUN state when available
5692 * frames is >= threshold. If the stop threshold is equal to boundary (also
5693 * software parameter - sw_param) then automatic stop will be disabled
5694 * (thus device will do the endless loop in the ring buffer).
5697 int snd_pcm_sw_params_set_stop_threshold(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
5699 int snd_pcm_sw_params_set_stop_threshold(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
5702 assert(pcm && params);
5703 params->stop_threshold = val;
5708 * \brief Get stop threshold from a software configuration container
5709 * \param params Software configuration container
5710 * \param val Returned stop threshold in frames
5711 * \return 0 otherwise a negative error code
5713 * PCM is automatically stopped in #SND_PCM_STATE_XRUN state when available
5714 * frames is >= threshold. If the stop threshold is equal to boundary (also
5715 * software parameter - sw_param) then automatic stop will be disabled
5716 * (thus device will do the endless loop in the ring buffer).
5719 int INTERNAL(snd_pcm_sw_params_get_stop_threshold)(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
5721 int snd_pcm_sw_params_get_stop_threshold(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
5725 *val = params->stop_threshold;
5731 * \brief Set silence threshold inside a software configuration container
5732 * \param pcm PCM handle
5733 * \param params Software configuration container
5734 * \param val Silence threshold in frames
5735 * \return 0 otherwise a negative error code
5737 * A portion of playback buffer is overwritten with silence (see
5738 * #snd_pcm_sw_params_set_silence_size) when playback underrun is nearer
5739 * than silence threshold.
5742 int snd_pcm_sw_params_set_silence_threshold(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
5744 int snd_pcm_sw_params_set_silence_threshold(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
5747 assert(pcm && params);
5748 if (CHECK_SANITY(val >= pcm->buffer_size)) {
5749 SNDMSG("invalid silent_threshold value %ld (buffer_size = %ld)",
5750 val, pcm->buffer_size);
5753 params->silence_threshold = val;
5758 * \brief Get silence threshold from a software configuration container
5759 * \param params Software configuration container
5760 * \param val Returned silence threshold in frames
5761 * \return 0 otherwise a negative error value
5763 * A portion of playback buffer is overwritten with silence (see
5764 * #snd_pcm_sw_params_set_silence_size) when playback underrun is nearer
5765 * than silence threshold.
5768 int INTERNAL(snd_pcm_sw_params_get_silence_threshold)(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
5770 int snd_pcm_sw_params_get_silence_threshold(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
5773 assert(params && val);
5774 *val = params->silence_threshold;
5780 * \brief Set silence size inside a software configuration container
5781 * \param pcm PCM handle
5782 * \param params Software configuration container
5783 * \param val Silence size in frames (0 for disabled)
5784 * \return 0 otherwise a negative error code
5786 * A portion of playback buffer is overwritten with silence when playback
5787 * underrun is nearer than silence threshold (see
5788 * #snd_pcm_sw_params_set_silence_threshold)
5790 * The special case is when silence size value is equal or greater than
5791 * boundary. The unused portion of the ring buffer (initial written samples
5792 * are untouched) is filled with silence at start. Later, only just processed
5793 * sample area is filled with silence. Note: silence_threshold must be set to zero.
5796 int snd_pcm_sw_params_set_silence_size(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
5798 int snd_pcm_sw_params_set_silence_size(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
5801 assert(pcm && params);
5802 if (CHECK_SANITY(val < pcm->boundary && val > pcm->buffer_size)) {
5803 SNDMSG("invalid silence_size %ld (boundary %ld, buffer_size %ld)",
5804 val, pcm->boundary, pcm->buffer_size);
5807 params->silence_size = val;
5812 * \brief Get silence size from a software configuration container
5813 * \param params Software configuration container
5814 * \param val Returned silence size in frames (0 for disabled)
5815 * \return 0 otherwise a negative error code
5817 * A portion of playback buffer is overwritten with silence when playback
5818 * underrun is nearer than silence threshold (see
5819 * #snd_pcm_sw_params_set_silence_threshold)
5822 int INTERNAL(snd_pcm_sw_params_get_silence_size)(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
5824 int snd_pcm_sw_params_get_silence_size(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
5828 *val = params->silence_size;
5834 * \brief get size of #snd_pcm_status_t
5835 * \return size in bytes
5837 size_t snd_pcm_status_sizeof()
5839 return sizeof(snd_pcm_status_t);
5843 * \brief allocate an invalid #snd_pcm_status_t using standard malloc
5844 * \param ptr returned pointer
5845 * \return 0 on success otherwise negative error code
5847 int snd_pcm_status_malloc(snd_pcm_status_t **ptr)
5850 *ptr = calloc(1, sizeof(snd_pcm_status_t));
5857 * \brief frees a previously allocated #snd_pcm_status_t
5858 * \param obj pointer to object to free
5860 void snd_pcm_status_free(snd_pcm_status_t *obj)
5866 * \brief copy one #snd_pcm_status_t to another
5867 * \param dst pointer to destination
5868 * \param src pointer to source
5870 void snd_pcm_status_copy(snd_pcm_status_t *dst, const snd_pcm_status_t *src)
5877 * \brief Get state from a PCM status container (see #snd_pcm_state)
5878 * \param obj #snd_pcm_status_t pointer
5881 snd_pcm_state_t snd_pcm_status_get_state(const snd_pcm_status_t *obj)
5888 * \brief Get trigger timestamp from a PCM status container
5889 * \param obj #snd_pcm_status_t pointer
5890 * \param ptr Pointer to returned timestamp
5892 void snd_pcm_status_get_trigger_tstamp(const snd_pcm_status_t *obj, snd_timestamp_t *ptr)
5895 ptr->tv_sec = obj->trigger_tstamp.tv_sec;
5896 ptr->tv_usec = obj->trigger_tstamp.tv_nsec / 1000L;
5900 * \brief Get trigger hi-res timestamp from a PCM status container
5901 * \param obj #snd_pcm_status_t pointer
5902 * \param ptr Pointer to returned timestamp
5905 void INTERNAL(snd_pcm_status_get_trigger_htstamp)(const snd_pcm_status_t *obj, snd_htimestamp_t *ptr)
5907 void snd_pcm_status_get_trigger_htstamp(const snd_pcm_status_t *obj, snd_htimestamp_t *ptr)
5911 *ptr = obj->trigger_tstamp;
5913 use_default_symbol_version(__snd_pcm_status_get_trigger_htstamp, snd_pcm_status_get_trigger_htstamp, ALSA_0.9.0rc8);
5916 * \brief Get "now" timestamp from a PCM status container
5917 * \param obj #snd_pcm_status_t pointer
5918 * \param ptr Pointer to returned timestamp
5920 void snd_pcm_status_get_tstamp(const snd_pcm_status_t *obj, snd_timestamp_t *ptr)
5923 ptr->tv_sec = obj->tstamp.tv_sec;
5924 ptr->tv_usec = obj->tstamp.tv_nsec / 1000L;
5928 * \brief Get "now" hi-res timestamp from a PCM status container
5929 * \param obj pointer to #snd_pcm_status_t
5930 * \param ptr Pointer to returned timestamp
5933 void INTERNAL(snd_pcm_status_get_htstamp)(const snd_pcm_status_t *obj, snd_htimestamp_t *ptr)
5935 void snd_pcm_status_get_htstamp(const snd_pcm_status_t *obj, snd_htimestamp_t *ptr)
5941 use_default_symbol_version(__snd_pcm_status_get_htstamp, snd_pcm_status_get_htstamp, ALSA_0.9.0rc8);
5944 * \brief Get delay from a PCM status container (see #snd_pcm_delay)
5945 * \return Delay in frames
5947 * Delay is distance between current application frame position and
5948 * sound frame position.
5949 * It's positive and less than buffer size in normal situation,
5950 * negative on playback underrun and greater than buffer size on
5953 snd_pcm_sframes_t snd_pcm_status_get_delay(const snd_pcm_status_t *obj)
5960 * \brief Get number of frames available from a PCM status container (see #snd_pcm_avail_update)
5961 * \return Number of frames ready to be read/written
5963 snd_pcm_uframes_t snd_pcm_status_get_avail(const snd_pcm_status_t *obj)
5970 * \brief Get maximum number of frames available from a PCM status container after last #snd_pcm_status call
5971 * \return Maximum number of frames ready to be read/written
5973 snd_pcm_uframes_t snd_pcm_status_get_avail_max(const snd_pcm_status_t *obj)
5976 return obj->avail_max;
5980 * \brief Get count of ADC overrange detections since last call
5981 * \return Count of ADC overrange detections
5983 snd_pcm_uframes_t snd_pcm_status_get_overrange(const snd_pcm_status_t *obj)
5986 return obj->overrange;
5990 * \brief get size of #snd_pcm_info_t
5991 * \return size in bytes
5993 size_t snd_pcm_info_sizeof()
5995 return sizeof(snd_pcm_info_t);
5999 * \brief allocate an invalid #snd_pcm_info_t using standard malloc
6000 * \param ptr returned pointer
6001 * \return 0 on success otherwise negative error code
6003 int snd_pcm_info_malloc(snd_pcm_info_t **ptr)
6006 *ptr = calloc(1, sizeof(snd_pcm_info_t));
6013 * \brief frees a previously allocated #snd_pcm_info_t
6014 * \param obj pointer to object to free
6016 void snd_pcm_info_free(snd_pcm_info_t *obj)
6022 * \brief copy one #snd_pcm_info_t to another
6023 * \param dst pointer to destination
6024 * \param src pointer to source
6026 void snd_pcm_info_copy(snd_pcm_info_t *dst, const snd_pcm_info_t *src)
6033 * \brief Get device from a PCM info container
6034 * \param obj PCM info container
6035 * \return device number
6037 unsigned int snd_pcm_info_get_device(const snd_pcm_info_t *obj)
6044 * \brief Get subdevice from a PCM info container
6045 * \param obj PCM info container
6046 * \return subdevice number
6048 unsigned int snd_pcm_info_get_subdevice(const snd_pcm_info_t *obj)
6051 return obj->subdevice;
6055 * \brief Get stream (direction) from a PCM info container
6056 * \param obj PCM info container
6059 snd_pcm_stream_t snd_pcm_info_get_stream(const snd_pcm_info_t *obj)
6066 * \brief Get card from a PCM info container
6067 * \param obj PCM info container
6068 * \return card number otherwise a negative error code if not associable to a card
6070 int snd_pcm_info_get_card(const snd_pcm_info_t *obj)
6077 * \brief Get id from a PCM info container
6078 * \param obj PCM info container
6079 * \return short id of PCM
6081 const char *snd_pcm_info_get_id(const snd_pcm_info_t *obj)
6084 return (const char *)obj->id;
6088 * \brief Get name from a PCM info container
6089 * \param obj PCM info container
6090 * \return name of PCM
6092 const char *snd_pcm_info_get_name(const snd_pcm_info_t *obj)
6095 return (const char *)obj->name;
6099 * \brief Get subdevice name from a PCM info container
6100 * \param obj PCM info container
6101 * \return name of used PCM subdevice
6103 const char *snd_pcm_info_get_subdevice_name(const snd_pcm_info_t *obj)
6106 return (const char *)obj->subname;
6110 * \brief Get class from a PCM info container
6111 * \param obj PCM info container
6112 * \return class of PCM
6114 snd_pcm_class_t snd_pcm_info_get_class(const snd_pcm_info_t *obj)
6117 return obj->dev_class;
6121 * \brief Get subclass from a PCM info container
6122 * \param obj PCM info container
6123 * \return subclass of PCM
6125 snd_pcm_subclass_t snd_pcm_info_get_subclass(const snd_pcm_info_t *obj)
6128 return obj->dev_subclass;
6132 * \brief Get subdevices count from a PCM info container
6133 * \param obj PCM info container
6134 * \return subdevices total count of PCM
6136 unsigned int snd_pcm_info_get_subdevices_count(const snd_pcm_info_t *obj)
6139 return obj->subdevices_count;
6143 * \brief Get available subdevices count from a PCM info container
6144 * \param obj PCM info container
6145 * \return available subdevices count of PCM
6147 unsigned int snd_pcm_info_get_subdevices_avail(const snd_pcm_info_t *obj)
6150 return obj->subdevices_avail;
6154 * \brief Get hardware synchronization ID from a PCM info container
6155 * \param obj PCM info container
6156 * \return hardware synchronization ID
6158 snd_pcm_sync_id_t snd_pcm_info_get_sync(const snd_pcm_info_t *obj)
6160 snd_pcm_sync_id_t res;
6162 memcpy(&res, &obj->sync, sizeof(res));
6167 * \brief Set wanted device inside a PCM info container (see #snd_ctl_pcm_info)
6168 * \param obj PCM info container
6169 * \param val Device number
6171 void snd_pcm_info_set_device(snd_pcm_info_t *obj, unsigned int val)
6178 * \brief Set wanted subdevice inside a PCM info container (see #snd_ctl_pcm_info)
6179 * \param obj PCM info container
6180 * \param val Subdevice number
6182 void snd_pcm_info_set_subdevice(snd_pcm_info_t *obj, unsigned int val)
6185 obj->subdevice = val;
6189 * \brief Set wanted stream inside a PCM info container (see #snd_ctl_pcm_info)
6190 * \param obj PCM info container
6193 void snd_pcm_info_set_stream(snd_pcm_info_t *obj, snd_pcm_stream_t val)
6200 * \brief Application request to access a portion of direct (mmap) area
6201 * \param pcm PCM handle
6202 * \param areas Returned mmap channel areas
6203 * \param offset Returned mmap area offset in area steps (== frames)
6204 * \param frames mmap area portion size in frames (wanted on entry, contiguous available on exit)
6205 * \return 0 on success otherwise a negative error code
6207 * It is necessary to call the snd_pcm_avail_update() function directly before
6208 * this call. Otherwise, this function can return a wrong count of available frames.
6210 * The function should be called before a sample-direct area can be accessed.
6211 * The resulting size parameter is always less or equal to the input count of frames
6212 * and can be zero, if no frames can be processed (the ring buffer is full).
6214 * See the snd_pcm_mmap_commit() function to finish the frame processing in
6217 int snd_pcm_mmap_begin(snd_pcm_t *pcm,
6218 const snd_pcm_channel_area_t **areas,
6219 snd_pcm_uframes_t *offset,
6220 snd_pcm_uframes_t *frames)
6222 snd_pcm_uframes_t cont;
6223 snd_pcm_uframes_t f;
6224 snd_pcm_uframes_t avail;
6225 const snd_pcm_channel_area_t *xareas;
6226 assert(pcm && areas && offset && frames);
6227 xareas = snd_pcm_mmap_areas(pcm);
6231 *offset = *pcm->appl.ptr % pcm->buffer_size;
6232 avail = snd_pcm_mmap_avail(pcm);
6233 if (avail > pcm->buffer_size)
6234 avail = pcm->buffer_size;
6235 cont = pcm->buffer_size - *offset;
6246 * \brief Application has completed the access to area requested with #snd_pcm_mmap_begin
6247 * \param pcm PCM handle
6248 * \param offset area offset in area steps (== frames)
6249 * \param frames area portion size in frames
6250 * \return count of transferred frames otherwise a negative error code
6252 * You should pass this function the offset value that
6253 * snd_pcm_mmap_begin() returned. The frames parameter should hold the
6254 * number of frames you have written or read to/from the audio
6255 * buffer. The frames parameter must never exceed the contiguous frames
6256 * count that snd_pcm_mmap_begin() returned. Each call to snd_pcm_mmap_begin()
6257 * must be followed by a call to snd_pcm_mmap_commit().
6262 const snd_pcm_area_t *areas;
6263 snd_pcm_sframes_t avail, size, commitres;
6264 snd_pcm_uframes_t offset, frames;
6267 avail = snd_pcm_avail_update(pcm);
6270 // at this point, we can transfer at least 'avail' frames
6272 // we want to process frames in chunks (period_size)
6273 if (avail < period_size)
6276 // it is possible that contiguous areas are smaller, thus we use a loop
6280 err = snd_pcm_mmap_begin(pcm_handle, &areas, &offset, &frames);
6283 // this function fills the areas from offset with count of frames
6284 generate_sine(areas, offset, frames, &phase);
6285 commitres = snd_pcm_mmap_commit(pcm_handle, offset, frames);
6286 if (commitres < 0 || commitres != frames)
6287 error(commitres >= 0 ? -EPIPE : commitres);
6294 * Look to the \ref example_test_pcm "Sine-wave generator" example
6295 * for more details about the generate_sine function.
6297 snd_pcm_sframes_t snd_pcm_mmap_commit(snd_pcm_t *pcm,
6298 snd_pcm_uframes_t offset,
6299 snd_pcm_uframes_t frames)
6302 if (CHECK_SANITY(offset != *pcm->appl.ptr % pcm->buffer_size)) {
6303 SNDMSG("commit offset (%ld) doesn't match with appl_ptr (%ld) %% buf_size (%ld)",
6304 offset, *pcm->appl.ptr, pcm->buffer_size);
6307 if (CHECK_SANITY(frames > snd_pcm_mmap_avail(pcm))) {
6308 SNDMSG("commit frames (%ld) overflow (avail = %ld)", frames,
6309 snd_pcm_mmap_avail(pcm));
6312 return pcm->fast_ops->mmap_commit(pcm->fast_op_arg, offset, frames);
6317 int _snd_pcm_poll_descriptor(snd_pcm_t *pcm)
6320 return pcm->poll_fd;
6323 void snd_pcm_areas_from_buf(snd_pcm_t *pcm, snd_pcm_channel_area_t *areas,
6326 unsigned int channel;
6327 unsigned int channels = pcm->channels;
6328 for (channel = 0; channel < channels; ++channel, ++areas) {
6330 areas->first = channel * pcm->sample_bits;
6331 areas->step = pcm->frame_bits;
6335 void snd_pcm_areas_from_bufs(snd_pcm_t *pcm, snd_pcm_channel_area_t *areas,
6338 unsigned int channel;
6339 unsigned int channels = pcm->channels;
6340 for (channel = 0; channel < channels; ++channel, ++areas, ++bufs) {
6341 areas->addr = *bufs;
6343 areas->step = pcm->sample_bits;
6347 snd_pcm_sframes_t snd_pcm_read_areas(snd_pcm_t *pcm, const snd_pcm_channel_area_t *areas,
6348 snd_pcm_uframes_t offset, snd_pcm_uframes_t size,
6349 snd_pcm_xfer_areas_func_t func)
6351 snd_pcm_uframes_t xfer = 0;
6352 snd_pcm_sframes_t err = 0;
6353 snd_pcm_state_t state = snd_pcm_state(pcm);
6357 if (size > pcm->xfer_align)
6358 size -= size % pcm->xfer_align;
6361 case SND_PCM_STATE_PREPARED:
6362 err = snd_pcm_start(pcm);
6366 case SND_PCM_STATE_DRAINING:
6367 case SND_PCM_STATE_RUNNING:
6369 case SND_PCM_STATE_XRUN:
6371 case SND_PCM_STATE_SUSPENDED:
6373 case SND_PCM_STATE_DISCONNECTED:
6380 snd_pcm_uframes_t frames;
6381 snd_pcm_sframes_t avail;
6383 if (pcm->sleep_min == 0 && state == SND_PCM_STATE_RUNNING) {
6384 err = snd_pcm_hwsync(pcm);
6388 avail = snd_pcm_avail_update(pcm);
6393 if (((snd_pcm_uframes_t)avail < pcm->avail_min && size > (snd_pcm_uframes_t)avail) ||
6394 (size >= pcm->xfer_align && (snd_pcm_uframes_t)avail < pcm->xfer_align)) {
6396 if (pcm->mode & SND_PCM_NONBLOCK) {
6401 err = snd_pcm_wait(pcm, -1);
6407 if ((snd_pcm_uframes_t) avail > pcm->xfer_align)
6408 avail -= avail % pcm->xfer_align;
6410 if (frames > (snd_pcm_uframes_t) avail)
6414 err = func(pcm, areas, offset, frames);
6423 return xfer > 0 ? (snd_pcm_sframes_t) xfer : snd_pcm_check_error(pcm, err);
6426 snd_pcm_sframes_t snd_pcm_write_areas(snd_pcm_t *pcm, const snd_pcm_channel_area_t *areas,
6427 snd_pcm_uframes_t offset, snd_pcm_uframes_t size,
6428 snd_pcm_xfer_areas_func_t func)
6430 snd_pcm_uframes_t xfer = 0;
6431 snd_pcm_sframes_t err = 0;
6432 snd_pcm_state_t state = snd_pcm_state(pcm);
6436 if (size > pcm->xfer_align)
6437 size -= size % pcm->xfer_align;
6440 case SND_PCM_STATE_PREPARED:
6441 case SND_PCM_STATE_RUNNING:
6443 case SND_PCM_STATE_XRUN:
6445 case SND_PCM_STATE_SUSPENDED:
6447 case SND_PCM_STATE_DISCONNECTED:
6454 snd_pcm_uframes_t frames;
6455 snd_pcm_sframes_t avail;
6457 if (pcm->sleep_min == 0 && state == SND_PCM_STATE_RUNNING) {
6458 err = snd_pcm_hwsync(pcm);
6462 avail = snd_pcm_avail_update(pcm);
6467 if ((state == SND_PCM_STATE_RUNNING &&
6468 (snd_pcm_uframes_t)avail < pcm->avail_min &&
6469 size > (snd_pcm_uframes_t)avail) ||
6470 (size >= pcm->xfer_align &&
6471 (snd_pcm_uframes_t)avail < pcm->xfer_align)) {
6473 if (pcm->mode & SND_PCM_NONBLOCK) {
6478 err = snd_pcm_wait(pcm, -1);
6483 if ((snd_pcm_uframes_t) avail > pcm->xfer_align)
6484 avail -= avail % pcm->xfer_align;
6486 if (frames > (snd_pcm_uframes_t) avail)
6490 err = func(pcm, areas, offset, frames);
6494 if (state == SND_PCM_STATE_PREPARED) {
6495 snd_pcm_sframes_t hw_avail = pcm->buffer_size - avail;
6497 /* some plugins might automatically start the stream */
6498 state = snd_pcm_state(pcm);
6499 if (state == SND_PCM_STATE_PREPARED &&
6500 hw_avail >= (snd_pcm_sframes_t) pcm->start_threshold) {
6501 err = snd_pcm_start(pcm);
6511 return xfer > 0 ? (snd_pcm_sframes_t) xfer : snd_pcm_check_error(pcm, err);
6514 snd_pcm_uframes_t _snd_pcm_mmap_hw_ptr(snd_pcm_t *pcm)
6516 return *pcm->hw.ptr;
6519 snd_pcm_uframes_t _snd_pcm_boundary(snd_pcm_t *pcm)
6521 return pcm->boundary;
6525 link_warning(_snd_pcm_mmap_hw_ptr, "Warning: _snd_pcm_mmap_hw_ptr() is deprecated, consider to not use this function");
6526 link_warning(_snd_pcm_boundary, "Warning: _snd_pcm_boundary() is deprecated, consider to use snd_pcm_sw_params_current()");
6529 static const char *names[SND_PCM_HW_PARAM_LAST_INTERVAL + 1] = {
6530 [SND_PCM_HW_PARAM_FORMAT] = "format",
6531 [SND_PCM_HW_PARAM_CHANNELS] = "channels",
6532 [SND_PCM_HW_PARAM_RATE] = "rate",
6533 [SND_PCM_HW_PARAM_PERIOD_TIME] = "period_time",
6534 [SND_PCM_HW_PARAM_PERIOD_SIZE] = "period_size",
6535 [SND_PCM_HW_PARAM_BUFFER_TIME] = "buffer_time",
6536 [SND_PCM_HW_PARAM_BUFFER_SIZE] = "buffer_size",
6537 [SND_PCM_HW_PARAM_PERIODS] = "periods"
6540 int snd_pcm_slave_conf(snd_config_t *root, snd_config_t *conf,
6541 snd_config_t **_pcm_conf, unsigned int count, ...)
6543 snd_config_iterator_t i, next;
6552 snd_config_t *pcm_conf = NULL;
6559 if (snd_config_get_string(conf, &str) >= 0) {
6560 err = snd_config_search_definition(root, "pcm_slave", str, &conf);
6562 SNDERR("Invalid slave definition");
6567 if (snd_config_get_type(conf) != SND_CONFIG_TYPE_COMPOUND) {
6568 SNDERR("Invalid slave definition");
6572 va_start(args, count);
6573 for (k = 0; k < count; ++k) {
6574 fields[k].index = va_arg(args, int);
6575 fields[k].flags = va_arg(args, int);
6576 fields[k].ptr = va_arg(args, void *);
6577 fields[k].present = 0;
6580 snd_config_for_each(i, next, conf) {
6581 snd_config_t *n = snd_config_iterator_entry(i);
6583 if (snd_config_get_id(n, &id) < 0)
6585 if (strcmp(id, "comment") == 0)
6587 if (strcmp(id, "pcm") == 0) {
6588 if (pcm_conf != NULL)
6589 snd_config_delete(pcm_conf);
6590 if ((err = snd_config_copy(&pcm_conf, n)) < 0)
6594 for (k = 0; k < count; ++k) {
6595 unsigned int idx = fields[k].index;
6597 assert(idx < SND_PCM_HW_PARAM_LAST_INTERVAL);
6599 if (strcmp(id, names[idx]) != 0)
6602 case SND_PCM_HW_PARAM_FORMAT:
6605 err = snd_config_get_string(n, &str);
6608 SNDERR("invalid type for %s", id);
6611 if ((fields[k].flags & SCONF_UNCHANGED) &&
6612 strcasecmp(str, "unchanged") == 0) {
6613 *(snd_pcm_format_t*)fields[k].ptr = (snd_pcm_format_t) -2;
6616 f = snd_pcm_format_value(str);
6617 if (f == SND_PCM_FORMAT_UNKNOWN) {
6618 SNDERR("unknown format %s", str);
6622 *(snd_pcm_format_t*)fields[k].ptr = f;
6626 if ((fields[k].flags & SCONF_UNCHANGED)) {
6627 err = snd_config_get_string(n, &str);
6629 strcasecmp(str, "unchanged") == 0) {
6630 *(int*)fields[k].ptr = -2;
6634 err = snd_config_get_integer(n, &v);
6637 *(int*)fields[k].ptr = v;
6640 fields[k].present = 1;
6645 SNDERR("Unknown field %s", id);
6650 SNDERR("missing field pcm");
6654 for (k = 0; k < count; ++k) {
6655 if ((fields[k].flags & SCONF_MANDATORY) && !fields[k].present) {
6656 SNDERR("missing field %s", names[fields[k].index]);
6661 *_pcm_conf = pcm_conf;
6666 snd_config_delete(pcm_conf);
6668 snd_config_delete(conf);
6673 int snd_pcm_conf_generic_id(const char *id)
6675 static const char *ids[] = { "comment", "type", "hint" };
6677 for (k = 0; k < sizeof(ids) / sizeof(ids[0]); ++k) {
6678 if (strcmp(id, ids[k]) == 0)
6684 static void snd_pcm_set_ptr(snd_pcm_t *pcm, snd_pcm_rbptr_t *rbptr,
6685 volatile snd_pcm_uframes_t *hw_ptr, int fd, off_t offset)
6687 rbptr->master = NULL; /* I'm master */
6688 rbptr->ptr = hw_ptr;
6690 rbptr->offset = offset;
6692 rbptr->changed(pcm, NULL);
6695 void snd_pcm_set_hw_ptr(snd_pcm_t *pcm, volatile snd_pcm_uframes_t *hw_ptr, int fd, off_t offset)
6699 snd_pcm_set_ptr(pcm, &pcm->hw, hw_ptr, fd, offset);
6702 void snd_pcm_set_appl_ptr(snd_pcm_t *pcm, volatile snd_pcm_uframes_t *appl_ptr, int fd, off_t offset)
6706 snd_pcm_set_ptr(pcm, &pcm->appl, appl_ptr, fd, offset);
6709 static void snd_pcm_link_ptr(snd_pcm_t *pcm, snd_pcm_rbptr_t *pcm_rbptr,
6710 snd_pcm_t *slave, snd_pcm_rbptr_t *slave_rbptr)
6715 a = slave_rbptr->link_dst;
6716 for (idx = 0; idx < slave_rbptr->link_dst_count; idx++)
6717 if (a[idx] == NULL) {
6719 goto __found_free_place;
6721 a = realloc(a, sizeof(snd_pcm_t *) * (slave_rbptr->link_dst_count + 1));
6723 pcm_rbptr->ptr = NULL;
6725 pcm_rbptr->offset = 0UL;
6728 a[slave_rbptr->link_dst_count++] = pcm;
6730 pcm_rbptr->master = slave_rbptr->master ? slave_rbptr->master : slave;
6731 pcm_rbptr->ptr = slave_rbptr->ptr;
6732 pcm_rbptr->fd = slave_rbptr->fd;
6733 pcm_rbptr->offset = slave_rbptr->offset;
6734 slave_rbptr->link_dst = a;
6735 if (pcm_rbptr->changed)
6736 pcm_rbptr->changed(pcm, slave);
6739 static void snd_pcm_unlink_ptr(snd_pcm_t *pcm, snd_pcm_rbptr_t *pcm_rbptr,
6740 snd_pcm_t *slave, snd_pcm_rbptr_t *slave_rbptr)
6745 a = slave_rbptr->link_dst;
6746 for (idx = 0; idx < slave_rbptr->link_dst_count; idx++) {
6747 if (a[idx] == pcm) {
6756 pcm_rbptr->master = NULL;
6757 pcm_rbptr->ptr = NULL;
6759 pcm_rbptr->offset = 0UL;
6760 if (pcm_rbptr->changed)
6761 pcm_rbptr->changed(pcm, slave);
6764 void snd_pcm_link_hw_ptr(snd_pcm_t *pcm, snd_pcm_t *slave)
6768 snd_pcm_link_ptr(pcm, &pcm->hw, slave, &slave->hw);
6771 void snd_pcm_link_appl_ptr(snd_pcm_t *pcm, snd_pcm_t *slave)
6775 snd_pcm_link_ptr(pcm, &pcm->appl, slave, &slave->appl);
6778 void snd_pcm_unlink_hw_ptr(snd_pcm_t *pcm, snd_pcm_t *slave)
6782 snd_pcm_unlink_ptr(pcm, &pcm->hw, slave, &slave->hw);
6785 void snd_pcm_unlink_appl_ptr(snd_pcm_t *pcm, snd_pcm_t *slave)
6789 snd_pcm_unlink_ptr(pcm, &pcm->appl, slave, &slave->appl);
6792 #endif /* DOC_HIDDEN */
6800 #ifdef USE_VERSIONED_SYMBOLS
6802 #define OBSOLETE1(name, what, new) \
6803 default_symbol_version(__##name, name, new); \
6804 symbol_version(__old_##name, name, what);
6808 #define OBSOLETE1(name, what, new) \
6809 use_default_symbol_version(__##name, name, new);
6811 #endif /* USE_VERSIONED_SYMBOLS */
6813 #define __P_OLD_GET(pfx, name, val_type, ret_type) \
6814 ret_type pfx##name(const snd_pcm_hw_params_t *params) \
6817 if (INTERNAL(name)(params, &val) < 0) \
6819 return (ret_type)val; \
6822 #define __P_OLD_GET1(pfx, name, val_type, ret_type) \
6823 ret_type pfx##name(const snd_pcm_hw_params_t *params, int *dir) \
6826 if (INTERNAL(name)(params, &val, dir) < 0) \
6828 return (ret_type)val; \
6831 #define __OLD_GET(name, val_type, ret_type) __P_OLD_GET(__old_, name, val_type, ret_type)
6832 #define __OLD_GET1(name, val_type, ret_type) __P_OLD_GET1(__old_, name, val_type, ret_type)
6834 __OLD_GET(snd_pcm_hw_params_get_access, snd_pcm_access_t, int);
6835 __OLD_GET(snd_pcm_hw_params_get_format, snd_pcm_format_t, int);
6836 __OLD_GET(snd_pcm_hw_params_get_subformat, snd_pcm_subformat_t, int);
6837 __OLD_GET(snd_pcm_hw_params_get_channels, unsigned int, int);
6838 __OLD_GET1(snd_pcm_hw_params_get_rate, unsigned int, int);
6839 __OLD_GET1(snd_pcm_hw_params_get_period_time, unsigned int, int);
6840 __OLD_GET1(snd_pcm_hw_params_get_period_size, snd_pcm_uframes_t, snd_pcm_sframes_t);
6841 __OLD_GET1(snd_pcm_hw_params_get_periods, unsigned int, int);
6842 __OLD_GET1(snd_pcm_hw_params_get_buffer_time, unsigned int, int);
6843 __OLD_GET(snd_pcm_hw_params_get_buffer_size, snd_pcm_uframes_t, snd_pcm_sframes_t);
6844 __OLD_GET1(snd_pcm_hw_params_get_tick_time, unsigned int, int);
6846 __OLD_GET(snd_pcm_hw_params_get_channels_min, unsigned int, unsigned int);
6847 __OLD_GET1(snd_pcm_hw_params_get_rate_min, unsigned int, unsigned int);
6848 __OLD_GET1(snd_pcm_hw_params_get_period_time_min, unsigned int, unsigned int);
6849 __OLD_GET1(snd_pcm_hw_params_get_period_size_min, snd_pcm_uframes_t, snd_pcm_uframes_t);
6850 __OLD_GET1(snd_pcm_hw_params_get_periods_min, unsigned int, unsigned int);
6851 __OLD_GET1(snd_pcm_hw_params_get_buffer_time_min, unsigned int, unsigned int);
6852 __OLD_GET(snd_pcm_hw_params_get_buffer_size_min, snd_pcm_uframes_t, snd_pcm_uframes_t);
6853 __OLD_GET1(snd_pcm_hw_params_get_tick_time_min, unsigned int, unsigned int);
6855 __OLD_GET(snd_pcm_hw_params_get_channels_max, unsigned int, unsigned int);
6856 __OLD_GET1(snd_pcm_hw_params_get_rate_max, unsigned int, unsigned int);
6857 __OLD_GET1(snd_pcm_hw_params_get_period_time_max, unsigned int, unsigned int);
6858 __OLD_GET1(snd_pcm_hw_params_get_period_size_max, snd_pcm_uframes_t, snd_pcm_uframes_t);
6859 __OLD_GET1(snd_pcm_hw_params_get_periods_max, unsigned int, unsigned int);
6860 __OLD_GET1(snd_pcm_hw_params_get_buffer_time_max, unsigned int, unsigned int);
6861 __OLD_GET(snd_pcm_hw_params_get_buffer_size_max, snd_pcm_uframes_t, snd_pcm_uframes_t);
6862 __OLD_GET1(snd_pcm_hw_params_get_tick_time_max, unsigned int, unsigned int);
6864 #define __P_OLD_NEAR(pfx, name, ret_type) \
6865 ret_type pfx##name(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, ret_type val) \
6867 if (INTERNAL(name)(pcm, params, &val) < 0) \
6869 return (ret_type)val; \
6872 #define __P_OLD_NEAR1(pfx, name, ret_type) \
6873 ret_type pfx##name(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, ret_type val, int *dir) \
6875 if (INTERNAL(name)(pcm, params, &val, dir) < 0) \
6877 return (ret_type)val; \
6880 #define __OLD_NEAR(name, ret_type) __P_OLD_NEAR(__old_, name, ret_type)
6881 #define __OLD_NEAR1(name, ret_type) __P_OLD_NEAR1(__old_, name, ret_type)
6883 __OLD_NEAR(snd_pcm_hw_params_set_channels_near, unsigned int);
6884 __OLD_NEAR1(snd_pcm_hw_params_set_rate_near, unsigned int);
6885 __OLD_NEAR1(snd_pcm_hw_params_set_period_time_near, unsigned int);
6886 __OLD_NEAR1(snd_pcm_hw_params_set_period_size_near, snd_pcm_uframes_t);
6887 __OLD_NEAR1(snd_pcm_hw_params_set_periods_near, unsigned int);
6888 __OLD_NEAR1(snd_pcm_hw_params_set_buffer_time_near, unsigned int);
6889 __OLD_NEAR(snd_pcm_hw_params_set_buffer_size_near, snd_pcm_uframes_t);
6890 __OLD_NEAR1(snd_pcm_hw_params_set_tick_time_near, unsigned int);
6892 #define __P_OLD_SET_FL(pfx, name, ret_type) \
6893 ret_type pfx##name(snd_pcm_t *pcm, snd_pcm_hw_params_t *params) \
6896 if (INTERNAL(name)(pcm, params, &val) < 0) \
6898 return (ret_type)val; \
6901 #define __P_OLD_SET_FL1(pfx, name, ret_type) \
6902 ret_type pfx##name(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, int *dir) \
6905 if (INTERNAL(name)(pcm, params, &val, dir) < 0) \
6907 return (ret_type)val; \
6910 #define __OLD_SET_FL(name, ret_type) __P_OLD_SET_FL(__old_, name, ret_type)
6911 #define __OLD_SET_FL1(name, ret_type) __P_OLD_SET_FL1(__old_, name, ret_type)
6913 __OLD_SET_FL(snd_pcm_hw_params_set_access_first, snd_pcm_access_t);
6914 __OLD_SET_FL(snd_pcm_hw_params_set_format_first, snd_pcm_format_t);
6915 __OLD_SET_FL(snd_pcm_hw_params_set_subformat_first, snd_pcm_subformat_t);
6916 __OLD_SET_FL(snd_pcm_hw_params_set_channels_first, unsigned int);
6917 __OLD_SET_FL1(snd_pcm_hw_params_set_rate_first, unsigned int);
6918 __OLD_SET_FL1(snd_pcm_hw_params_set_period_time_first, unsigned int);
6919 __OLD_SET_FL1(snd_pcm_hw_params_set_period_size_first, snd_pcm_uframes_t);
6920 __OLD_SET_FL1(snd_pcm_hw_params_set_periods_first, unsigned int);
6921 __OLD_SET_FL1(snd_pcm_hw_params_set_buffer_time_first, unsigned int);
6922 __OLD_SET_FL(snd_pcm_hw_params_set_buffer_size_first, snd_pcm_uframes_t);
6923 __OLD_SET_FL1(snd_pcm_hw_params_set_tick_time_first, unsigned int);
6925 __OLD_SET_FL(snd_pcm_hw_params_set_access_last, snd_pcm_access_t);
6926 __OLD_SET_FL(snd_pcm_hw_params_set_format_last, snd_pcm_format_t);
6927 __OLD_SET_FL(snd_pcm_hw_params_set_subformat_last, snd_pcm_subformat_t);
6928 __OLD_SET_FL(snd_pcm_hw_params_set_channels_last, unsigned int);
6929 __OLD_SET_FL1(snd_pcm_hw_params_set_rate_last, unsigned int);
6930 __OLD_SET_FL1(snd_pcm_hw_params_set_period_time_last, unsigned int);
6931 __OLD_SET_FL1(snd_pcm_hw_params_set_period_size_last, snd_pcm_uframes_t);
6932 __OLD_SET_FL1(snd_pcm_hw_params_set_periods_last, unsigned int);
6933 __OLD_SET_FL1(snd_pcm_hw_params_set_buffer_time_last, unsigned int);
6934 __OLD_SET_FL(snd_pcm_hw_params_set_buffer_size_last, snd_pcm_uframes_t);
6935 __OLD_SET_FL1(snd_pcm_hw_params_set_tick_time_last, unsigned int);
6937 #define __P_OLD_GET_SW(pfx, name, ret_type) \
6938 ret_type pfx##name(snd_pcm_sw_params_t *params) \
6941 if (INTERNAL(name)(params, &val) < 0) \
6943 return (ret_type)val; \
6946 #define __OLD_GET_SW(name, ret_type) __P_OLD_GET_SW(__old_, name, ret_type)
6948 __OLD_GET_SW(snd_pcm_sw_params_get_tstamp_mode, snd_pcm_tstamp_t);
6949 __OLD_GET_SW(snd_pcm_sw_params_get_sleep_min, unsigned int);
6950 __OLD_GET_SW(snd_pcm_sw_params_get_avail_min, snd_pcm_uframes_t);
6951 __OLD_GET_SW(snd_pcm_sw_params_get_xfer_align, snd_pcm_uframes_t);
6952 __OLD_GET_SW(snd_pcm_sw_params_get_start_threshold, snd_pcm_uframes_t);
6953 __OLD_GET_SW(snd_pcm_sw_params_get_stop_threshold, snd_pcm_uframes_t);
6954 __OLD_GET_SW(snd_pcm_sw_params_get_silence_threshold, snd_pcm_uframes_t);
6955 __OLD_GET_SW(snd_pcm_sw_params_get_silence_size, snd_pcm_uframes_t);
6957 OBSOLETE1(snd_pcm_hw_params_get_access, ALSA_0.9, ALSA_0.9.0rc4);
6958 OBSOLETE1(snd_pcm_hw_params_set_access_first, ALSA_0.9, ALSA_0.9.0rc4);
6959 OBSOLETE1(snd_pcm_hw_params_set_access_last, ALSA_0.9, ALSA_0.9.0rc4);
6961 OBSOLETE1(snd_pcm_hw_params_get_format, ALSA_0.9, ALSA_0.9.0rc4);
6962 OBSOLETE1(snd_pcm_hw_params_set_format_first, ALSA_0.9, ALSA_0.9.0rc4);
6963 OBSOLETE1(snd_pcm_hw_params_set_format_last, ALSA_0.9, ALSA_0.9.0rc4);
6965 OBSOLETE1(snd_pcm_hw_params_get_subformat, ALSA_0.9, ALSA_0.9.0rc4);
6966 OBSOLETE1(snd_pcm_hw_params_set_subformat_first, ALSA_0.9, ALSA_0.9.0rc4);
6967 OBSOLETE1(snd_pcm_hw_params_set_subformat_last, ALSA_0.9, ALSA_0.9.0rc4);
6969 OBSOLETE1(snd_pcm_hw_params_get_channels, ALSA_0.9, ALSA_0.9.0rc4);
6970 OBSOLETE1(snd_pcm_hw_params_get_channels_min, ALSA_0.9, ALSA_0.9.0rc4);
6971 OBSOLETE1(snd_pcm_hw_params_get_channels_max, ALSA_0.9, ALSA_0.9.0rc4);
6972 OBSOLETE1(snd_pcm_hw_params_set_channels_near, ALSA_0.9, ALSA_0.9.0rc4);
6973 OBSOLETE1(snd_pcm_hw_params_set_channels_first, ALSA_0.9, ALSA_0.9.0rc4);
6974 OBSOLETE1(snd_pcm_hw_params_set_channels_last, ALSA_0.9, ALSA_0.9.0rc4);
6976 OBSOLETE1(snd_pcm_hw_params_get_rate, ALSA_0.9, ALSA_0.9.0rc4);
6977 OBSOLETE1(snd_pcm_hw_params_get_rate_min, ALSA_0.9, ALSA_0.9.0rc4);
6978 OBSOLETE1(snd_pcm_hw_params_get_rate_max, ALSA_0.9, ALSA_0.9.0rc4);
6979 OBSOLETE1(snd_pcm_hw_params_set_rate_near, ALSA_0.9, ALSA_0.9.0rc4);
6980 OBSOLETE1(snd_pcm_hw_params_set_rate_first, ALSA_0.9, ALSA_0.9.0rc4);
6981 OBSOLETE1(snd_pcm_hw_params_set_rate_last, ALSA_0.9, ALSA_0.9.0rc4);
6983 OBSOLETE1(snd_pcm_hw_params_get_period_time, ALSA_0.9, ALSA_0.9.0rc4);
6984 OBSOLETE1(snd_pcm_hw_params_get_period_time_min, ALSA_0.9, ALSA_0.9.0rc4);
6985 OBSOLETE1(snd_pcm_hw_params_get_period_time_max, ALSA_0.9, ALSA_0.9.0rc4);
6986 OBSOLETE1(snd_pcm_hw_params_set_period_time_near, ALSA_0.9, ALSA_0.9.0rc4);
6987 OBSOLETE1(snd_pcm_hw_params_set_period_time_first, ALSA_0.9, ALSA_0.9.0rc4);
6988 OBSOLETE1(snd_pcm_hw_params_set_period_time_last, ALSA_0.9, ALSA_0.9.0rc4);
6990 OBSOLETE1(snd_pcm_hw_params_get_period_size, ALSA_0.9, ALSA_0.9.0rc4);
6991 OBSOLETE1(snd_pcm_hw_params_get_period_size_min, ALSA_0.9, ALSA_0.9.0rc4);
6992 OBSOLETE1(snd_pcm_hw_params_get_period_size_max, ALSA_0.9, ALSA_0.9.0rc4);
6993 OBSOLETE1(snd_pcm_hw_params_set_period_size_near, ALSA_0.9, ALSA_0.9.0rc4);
6994 OBSOLETE1(snd_pcm_hw_params_set_period_size_first, ALSA_0.9, ALSA_0.9.0rc4);
6995 OBSOLETE1(snd_pcm_hw_params_set_period_size_last, ALSA_0.9, ALSA_0.9.0rc4);
6997 OBSOLETE1(snd_pcm_hw_params_get_periods, ALSA_0.9, ALSA_0.9.0rc4);
6998 OBSOLETE1(snd_pcm_hw_params_get_periods_min, ALSA_0.9, ALSA_0.9.0rc4);
6999 OBSOLETE1(snd_pcm_hw_params_get_periods_max, ALSA_0.9, ALSA_0.9.0rc4);
7000 OBSOLETE1(snd_pcm_hw_params_set_periods_near, ALSA_0.9, ALSA_0.9.0rc4);
7001 OBSOLETE1(snd_pcm_hw_params_set_periods_first, ALSA_0.9, ALSA_0.9.0rc4);
7002 OBSOLETE1(snd_pcm_hw_params_set_periods_last, ALSA_0.9, ALSA_0.9.0rc4);
7004 OBSOLETE1(snd_pcm_hw_params_get_buffer_time, ALSA_0.9, ALSA_0.9.0rc4);
7005 OBSOLETE1(snd_pcm_hw_params_get_buffer_time_min, ALSA_0.9, ALSA_0.9.0rc4);
7006 OBSOLETE1(snd_pcm_hw_params_get_buffer_time_max, ALSA_0.9, ALSA_0.9.0rc4);
7007 OBSOLETE1(snd_pcm_hw_params_set_buffer_time_near, ALSA_0.9, ALSA_0.9.0rc4);
7008 OBSOLETE1(snd_pcm_hw_params_set_buffer_time_first, ALSA_0.9, ALSA_0.9.0rc4);
7009 OBSOLETE1(snd_pcm_hw_params_set_buffer_time_last, ALSA_0.9, ALSA_0.9.0rc4);
7011 OBSOLETE1(snd_pcm_hw_params_get_buffer_size, ALSA_0.9, ALSA_0.9.0rc4);
7012 OBSOLETE1(snd_pcm_hw_params_get_buffer_size_min, ALSA_0.9, ALSA_0.9.0rc4);
7013 OBSOLETE1(snd_pcm_hw_params_get_buffer_size_max, ALSA_0.9, ALSA_0.9.0rc4);
7014 OBSOLETE1(snd_pcm_hw_params_set_buffer_size_near, ALSA_0.9, ALSA_0.9.0rc4);
7015 OBSOLETE1(snd_pcm_hw_params_set_buffer_size_first, ALSA_0.9, ALSA_0.9.0rc4);
7016 OBSOLETE1(snd_pcm_hw_params_set_buffer_size_last, ALSA_0.9, ALSA_0.9.0rc4);
7018 OBSOLETE1(snd_pcm_hw_params_get_tick_time, ALSA_0.9, ALSA_0.9.0rc4);
7019 OBSOLETE1(snd_pcm_hw_params_get_tick_time_min, ALSA_0.9, ALSA_0.9.0rc4);
7020 OBSOLETE1(snd_pcm_hw_params_get_tick_time_max, ALSA_0.9, ALSA_0.9.0rc4);
7021 OBSOLETE1(snd_pcm_hw_params_set_tick_time_near, ALSA_0.9, ALSA_0.9.0rc4);
7022 OBSOLETE1(snd_pcm_hw_params_set_tick_time_first, ALSA_0.9, ALSA_0.9.0rc4);
7023 OBSOLETE1(snd_pcm_hw_params_set_tick_time_last, ALSA_0.9, ALSA_0.9.0rc4);
7025 OBSOLETE1(snd_pcm_sw_params_get_tstamp_mode, ALSA_0.9, ALSA_0.9.0rc4);
7026 OBSOLETE1(snd_pcm_sw_params_get_sleep_min, ALSA_0.9, ALSA_0.9.0rc4);
7027 OBSOLETE1(snd_pcm_sw_params_get_avail_min, ALSA_0.9, ALSA_0.9.0rc4);
7028 OBSOLETE1(snd_pcm_sw_params_get_xfer_align, ALSA_0.9, ALSA_0.9.0rc4);
7029 OBSOLETE1(snd_pcm_sw_params_get_start_threshold, ALSA_0.9, ALSA_0.9.0rc4);
7030 OBSOLETE1(snd_pcm_sw_params_get_stop_threshold, ALSA_0.9, ALSA_0.9.0rc4);
7031 OBSOLETE1(snd_pcm_sw_params_get_silence_threshold, ALSA_0.9, ALSA_0.9.0rc4);
7032 OBSOLETE1(snd_pcm_sw_params_get_silence_size, ALSA_0.9, ALSA_0.9.0rc4);
7034 #endif /* DOC_HIDDEN */
7042 * \brief Recover the stream state from an error or suspend
7043 * \param pcm PCM handle
7044 * \param err error number
7045 * \param silent do not print error reason
7046 * \return 0 when error code was handled successfuly, otherwise a negative error code
7048 * This functions handles -EINTR (interrupted system call),
7049 * -EPIPE (overrun or underrun) and -ESTRPIPE (stream is suspended)
7050 * error codes trying to prepare given stream for next I/O.
7052 * Note that this function returs the original error code when it is not
7053 * handled inside this function (for example -EAGAIN is returned back).
7055 int snd_pcm_recover(snd_pcm_t *pcm, int err, int silent)
7059 if (err == -EINTR) /* nothing to do, continue */
7061 if (err == -EPIPE) {
7063 if (snd_pcm_stream(pcm) == SND_PCM_STREAM_PLAYBACK)
7068 SNDERR("%s occured", s);
7069 err = snd_pcm_prepare(pcm);
7071 SNDERR("cannot recovery from %s, prepare failed: %s", s, snd_strerror(err));
7076 if (err == -ESTRPIPE) {
7077 while ((err = snd_pcm_resume(pcm)) == -EAGAIN)
7078 /* wait until suspend flag is released */
7079 poll(NULL, 0, 1000);
7081 err = snd_pcm_prepare(pcm);
7083 SNDERR("cannot recovery from suspend, prepare failed: %s", snd_strerror(err));
7093 * \brief Set the hardware and software parameters in a simple way
7094 * \param pcm PCM handle
7095 * \param format required PCM format
7096 * \param access required PCM access
7097 * \param channels required PCM channels
7098 * \param rate required sample rate in Hz
7099 * \param soft_resample 0 = disallow alsa-lib resample stream, 1 = allow resampling
7100 * \param latency required overall latency in us (0 = optimum latency for players)
7101 * \return 0 on success otherwise a negative error code
7103 int snd_pcm_set_params(snd_pcm_t *pcm,
7104 snd_pcm_format_t format,
7105 snd_pcm_access_t access,
7106 unsigned int channels,
7109 unsigned int latency)
7111 snd_pcm_hw_params_t *params;
7112 snd_pcm_sw_params_t *swparams;
7113 const char *s = snd_pcm_stream_name(snd_pcm_stream(pcm));
7114 snd_pcm_uframes_t buffer_size, period_size;
7115 unsigned int rrate, period_time;
7118 snd_pcm_hw_params_alloca(¶ms);
7119 snd_pcm_sw_params_alloca(&swparams);
7122 /* choose all parameters */
7123 err = snd_pcm_hw_params_any(pcm, params);
7125 SNDERR("Broken configuration for %s: no configurations available", s);
7128 /* set software resampling */
7129 err = snd_pcm_hw_params_set_rate_resample(pcm, params, soft_resample);
7131 SNDERR("Resampling setup failed for %s: %s", s, snd_strerror(err));
7134 /* set the selected read/write format */
7135 err = snd_pcm_hw_params_set_access(pcm, params, access);
7137 SNDERR("Access type not available for %s: %s", s, snd_strerror(err));
7140 /* set the sample format */
7141 err = snd_pcm_hw_params_set_format(pcm, params, format);
7143 SNDERR("Sample format not available for %s: %s", s, snd_strerror(err));
7146 /* set the count of channels */
7147 err = snd_pcm_hw_params_set_channels(pcm, params, channels);
7149 SNDERR("Channels count (%i) not available for %s: %s", channels, s, snd_strerror(err));
7152 /* set the stream rate */
7154 err = INTERNAL(snd_pcm_hw_params_set_rate_near)(pcm, params, &rrate, 0);
7156 SNDERR("Rate %iHz not available for playback: %s", rate, snd_strerror(err));
7159 if (rrate != rate) {
7160 SNDERR("Rate doesn't match (requested %iHz, get %iHz)", rate, err);
7163 /* set the buffer time */
7164 err = INTERNAL(snd_pcm_hw_params_set_buffer_time_near)(pcm, params, &latency, NULL);
7166 /* error path -> set period size as first */
7167 /* set the period time */
7168 period_time = latency / 4;
7169 err = INTERNAL(snd_pcm_hw_params_set_period_time_near)(pcm, params, &period_time, NULL);
7171 SNDERR("Unable to set period time %i for %s: %s", period_time, s, snd_strerror(err));
7174 err = INTERNAL(snd_pcm_hw_params_get_period_size)(params, &period_size, NULL);
7176 SNDERR("Unable to get period size for %s: %s", s, snd_strerror(err));
7179 buffer_size = period_size * 4;
7180 err = INTERNAL(snd_pcm_hw_params_set_buffer_size_near)(pcm, params, &buffer_size);
7182 SNDERR("Unable to set buffer size %lu %s: %s", buffer_size, s, snd_strerror(err));
7185 err = INTERNAL(snd_pcm_hw_params_get_buffer_size)(params, &buffer_size);
7187 SNDERR("Unable to get buffer size for %s: %s", s, snd_strerror(err));
7191 /* standard configuration buffer_time -> periods */
7192 err = INTERNAL(snd_pcm_hw_params_get_buffer_size)(params, &buffer_size);
7194 SNDERR("Unable to get buffer size for %s: %s", s, snd_strerror(err));
7197 err = INTERNAL(snd_pcm_hw_params_get_buffer_time)(params, &latency, NULL);
7199 SNDERR("Unable to get buffer time (latency) for %s: %s", s, snd_strerror(err));
7202 /* set the period time */
7203 period_time = latency / 4;
7204 err = INTERNAL(snd_pcm_hw_params_set_period_time_near)(pcm, params, &period_time, NULL);
7206 SNDERR("Unable to set period time %i for %s: %s", period_time, s, snd_strerror(err));
7209 err = INTERNAL(snd_pcm_hw_params_get_period_size)(params, &period_size, NULL);
7211 SNDERR("Unable to get period size for %s: %s", s, snd_strerror(err));
7215 /* write the parameters to device */
7216 err = snd_pcm_hw_params(pcm, params);
7218 SNDERR("Unable to set hw params for %s: %s", s, snd_strerror(err));
7222 /* get the current swparams */
7223 err = snd_pcm_sw_params_current(pcm, swparams);
7225 SNDERR("Unable to determine current swparams for %s: %s", s, snd_strerror(err));
7228 /* start the transfer when the buffer is almost full: */
7229 /* (buffer_size / avail_min) * avail_min */
7230 err = snd_pcm_sw_params_set_start_threshold(pcm, swparams, (buffer_size / period_size) * period_size);
7232 SNDERR("Unable to set start threshold mode for %s: %s", s, snd_strerror(err));
7235 /* allow the transfer when at least period_size samples can be processed */
7236 err = snd_pcm_sw_params_set_avail_min(pcm, swparams, period_size);
7238 SNDERR("Unable to set avail min for %s: %s", s, snd_strerror(err));
7241 /* align all transfers to 1 sample */
7242 err = snd_pcm_sw_params_set_xfer_align(pcm, swparams, 1);
7244 SNDERR("Unable to set transfer align for %s: %s", s, snd_strerror(err));
7247 /* write the parameters to the playback device */
7248 err = snd_pcm_sw_params(pcm, swparams);
7250 SNDERR("Unable to set sw params for %s: %s", s, snd_strerror(err));
7257 * \brief Get the transfer size parameters in a simple way
7258 * \param pcm PCM handle
7259 * \param buffer_size PCM ring buffer size in frames
7260 * \param period_size PCM period size in frames
7261 * \return 0 on success otherwise a negative error code
7263 int snd_pcm_get_params(snd_pcm_t *pcm,
7264 snd_pcm_uframes_t *buffer_size,
7265 snd_pcm_uframes_t *period_size)
7267 snd_pcm_hw_params_t *hw;
7271 snd_pcm_hw_params_alloca(&hw);
7272 err = snd_pcm_hw_params_current(pcm, hw);
7275 err = INTERNAL(snd_pcm_hw_params_get_buffer_size)(hw, buffer_size);
7278 err = INTERNAL(snd_pcm_hw_params_get_period_size)(hw, period_size, NULL);