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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 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 file
108 descriptors to poll or select on (note that wait direction might be different
109 than expected - do not use only returned file descriptors, but handle
110 events member as well - see \ref snd_pcm_poll_descriptors function
111 description for more details and \ref snd_pcm_poll_descriptors_revents for
112 events demangling). The implemented transfer routines can be found in
113 the \ref alsa_transfers section.
115 \subsection pcm_transfer_async Asynchronous notification
117 ALSA driver and library knows to handle the asynchronous notifications over
118 the SIGIO signal. This signal allows to interrupt application and transfer
119 data in the signal handler. For further details see the sigaction function
120 ('man 2 sigaction'). The section \ref pcm_async describes the ALSA API for
121 this extension. The implemented transfer routines can be found in the
122 \ref alsa_transfers section.
124 \section pcm_open_behaviour Blocked and non-blocked open
126 The ALSA PCM API uses a different behaviour when the device is opened
127 with blocked or non-blocked mode. The mode can be specified with
128 \a mode argument in #snd_pcm_open() function.
129 The blocked mode is the default (without #SND_PCM_NONBLOCK mode).
130 In this mode, the behaviour is that if the resources have already used
131 with another application, then it blocks the caller, until resources are
132 free. The non-blocked behaviour (with #SND_PCM_NONBLOCK)
133 doesn't block the caller in any way and returns -EBUSY error when the
134 resources are not available. Note that the mode also determines the
135 behaviour of standard I/O calls, returning -EAGAIN when non-blocked mode is
136 used and the ring buffer is full (playback) or empty (capture).
137 The operation mode for I/O calls can be changed later with
138 the #snd_pcm_nonblock() function.
140 \section pcm_async Asynchronous mode
142 There is also possibility to receive asynchronous notification after
143 specified time periods. You may see the #SND_PCM_ASYNC
144 mode for #snd_pcm_open() function and
145 #snd_async_add_pcm_handler() function for further details.
147 \section pcm_handshake Handshake between application and library
149 The ALSA PCM API design uses the states to determine the communication
150 phase between application and library. The actual state can be determined
151 using #snd_pcm_state() call. There are these states:
153 \par SND_PCM_STATE_OPEN
154 The PCM device is in the open state. After the #snd_pcm_open() open call,
155 the device is in this state. Also, when #snd_pcm_hw_params() call fails,
156 then this state is entered to force application calling
157 #snd_pcm_hw_params() function to set right communication
160 \par SND_PCM_STATE_SETUP
161 The PCM device has accepted communication parameters and it is waiting
162 for #snd_pcm_prepare() call to prepare the hardware for
163 selected operation (playback or capture).
165 \par SND_PCM_STATE_PREPARED
166 The PCM device is prepared for operation. Application can use
167 #snd_pcm_start() call, write or read data to start
170 \par SND_PCM_STATE_RUNNING
171 The PCM device has been started and is running. It processes the samples. The stream can
172 be stopped using the #snd_pcm_drop() or
173 #snd_pcm_drain() calls.
175 \par SND_PCM_STATE_XRUN
176 The PCM device reached overrun (capture) or underrun (playback).
177 You can use the -EPIPE return code from I/O functions
178 (#snd_pcm_writei(), #snd_pcm_writen(), #snd_pcm_readi(), #snd_pcm_readn())
179 to determine this state without checking
180 the actual state via #snd_pcm_state() call. It is recommended to use
181 the helper function #snd_pcm_recover() to recover from this state, but you can also use #snd_pcm_prepare(),
182 #snd_pcm_drop() or #snd_pcm_drain() calls.
184 \par SND_PCM_STATE_DRAINING
185 The device is in this state when application using the capture mode
186 called #snd_pcm_drain() function. Until all data are
187 read from the internal ring buffer using I/O routines
188 (#snd_pcm_readi(), #snd_pcm_readn()),
189 then the device stays in this state.
191 \par SND_PCM_STATE_PAUSED
192 The device is in this state when application called
193 the #snd_pcm_pause() function until the pause is released.
194 Not all hardware supports this feature. Application should check the
195 capability with the #snd_pcm_hw_params_can_pause().
197 \par SND_PCM_STATE_SUSPENDED
198 The device is in the suspend state provoked with the power management
199 system. The stream can be resumed using #snd_pcm_resume()
200 call, but not all hardware supports this feature. Application should check
201 the capability with the #snd_pcm_hw_params_can_resume().
202 In other case, the calls #snd_pcm_prepare(),
203 #snd_pcm_drop(), #snd_pcm_drain() can be used
206 \par SND_PCM_STATE_DISCONNECTED
207 The device is physicaly disconnected. It does not accept any I/O calls in this state.
209 \section pcm_formats PCM formats
211 The full list of formats present the #snd_pcm_format_t type.
212 The 24-bit linear samples use 32-bit physical space, but the sample is
213 stored in the lower three bytes. Some hardware does not support processing of full
214 range, thus you may get the significant bits for linear samples via
215 #snd_pcm_hw_params_get_sbits() function. The example: ICE1712
216 chips support 32-bit sample processing, but low byte is ignored (playback)
217 or zero (capture). The function snd_pcm_hw_params_get_sbits()
218 returns 24 in this case. The significant bits are related to the usable
219 sample bits (width) not the physical sample space.
221 \section alsa_transfers ALSA transfers
223 There are two methods to transfer samples in application. The first method
224 is the standard read / write one. The second method, uses the direct audio
225 buffer to communicate with the device while ALSA library manages this space
226 itself. You can find examples of all communication schemes for playback
227 in \link example_test_pcm Sine-wave generator example \endlink. To complete the
228 list, we should note that #snd_pcm_wait() function contains
229 embedded poll waiting implementation.
231 \subsection alsa_pcm_rw Read / Write transfer
233 There are two versions of read / write routines. The first expects the
234 interleaved samples at input (#SND_PCM_ACCESS_RW_INTERLEAVED access method),
235 and the second one expects non-interleaved (samples in separated buffers -
236 #SND_PCM_ACCESS_RW_NONINTERLEAVED access method) at input. There are these
237 functions for interleaved transfers: #snd_pcm_writei()
238 #snd_pcm_readi(). For non-interleaved transfers, there are
239 these functions: #snd_pcm_writen() and #snd_pcm_readn().
241 \subsection alsa_mmap_rw Direct Read / Write transfer (via mmap'ed areas)
243 Three kinds of organization of ring buffer memory areas exist in ALSA API.
244 Access #SND_PCM_ACCESS_MMAP_INTERLEAVED has interleaved samples. Access
245 #SND_PCM_ACCESS_MMAP_NONINTERLEAVED expects continous sample areas for
246 one channel. Access #SND_PCM_ACCESS_MMAP_COMPLEX does not fit to interleaved
247 and non-interleaved ring buffer organization.
249 There are two functions for this kind of transfer. Application can get an
250 access to memory areas via #snd_pcm_mmap_begin() function.
251 This function returns the areas (single area is equal to a channel)
252 containing the direct pointers to memory and sample position description
253 in #snd_pcm_channel_area_t structure. After application
254 transfers the data in the memory areas, then it must be acknowledged
255 the end of transfer via #snd_pcm_mmap_commit() function
256 to allow the ALSA library update the pointers to ring buffer. This kind of
257 communication is also called "zero-copy", because the device does not require
258 to copy the samples from application to another place in system memory.
260 If you like to use the compatibility functions in mmap mode, there are
261 read / write routines equaling to standard read / write transfers. Using
262 these functions discards the benefits of direct access to memory region.
263 See the #snd_pcm_mmap_readi(),
264 #snd_pcm_mmap_writei(), #snd_pcm_mmap_readn()
265 and #snd_pcm_mmap_writen() functions. These functions use
266 #snd_pcm_areas_copy() internally.
268 \section pcm_errors Error codes
272 This error means xrun (underrun for playback or overrun for capture).
273 The underrun can happen when an application does not feed new samples
274 in time to alsa-lib (due CPU usage). The overrun can happen when
275 an application does not take new captured samples in time from alsa-lib.
279 This error means that system has suspended drivers. The application
280 should wait in loop when snd_pcm_resume() != -EAGAIN and then
281 call snd_pcm_prepare() when snd_pcm_resume() return an error code.
282 If snd_pcm_resume() does not fail (a zero value is returned), driver
283 supports resume and the snd_pcm_prepare() call can be ommited.
287 This error means that the device is in a bad state. It means that
288 the handshake between application and alsa-lib is corrupted.
290 \par -ENOTTY, -ENODEV
292 This error can happen when device is physically removed (for example
293 some hotplug devices like USB or PCMCIA, CardBus or ExpressCard
294 can be removed on the fly).
298 This error can happen if the device data transfer is dependent on
299 an external condition and that condition is not met. For example,
300 PCM device for echo reference as described by SND_USE_CASE_MOD_ECHO_REF
301 UCM token, may return -ENODATA if the linked playback stream has not been
304 There is no defined recovery or event mechanism to signal the data / link
305 availability at the moment. The PCM must be completely restarted until
306 the mechanism is designed. The #snd_pcm_recover() function cannot be
309 \section pcm_params Managing parameters
311 The ALSA PCM device uses two groups of PCM related parameters. The hardware
312 parameters contains the stream description like format, rate, count of
313 channels, ring buffer size etc. The software parameters contains the
314 software (driver) related parameters. The communication behaviour can be
315 controlled via these parameters, like automatic start, automatic stop,
316 interrupting (chunk acknowledge) etc. The software parameters can be
317 modified at any time (when valid hardware parameters are set). It includes
318 the running state as well.
320 \subsection pcm_hw_params Hardware related parameters
322 The ALSA PCM devices use the parameter refining system for hardware
323 parameters - #snd_pcm_hw_params_t. It means, that
324 application choose the full-range of configurations at first and then
325 application sets single parameters until all parameters are elementary
330 ALSA knows about five access modes. The first three can be used for direct
331 communication. The access mode #SND_PCM_ACCESS_MMAP_INTERLEAVED
332 determines the direct memory area and interleaved sample organization.
333 Interleaved organization means, that samples from channels are mixed together.
334 The access mode #SND_PCM_ACCESS_MMAP_NONINTERLEAVED
335 determines the direct memory area and non-interleaved sample organization.
336 Each channel has a separate buffer in the case. The complex direct memory
337 organization represents the #SND_PCM_ACCESS_MMAP_COMPLEX
338 access mode. The sample organization does not fit the interleaved or
339 non-interleaved access modes in the case. The last two access modes
340 describes the read / write access methods.
341 The #SND_PCM_ACCESS_RW_INTERLEAVED access represents the read /
342 write interleaved access and the #SND_PCM_ACCESS_RW_NONINTERLEAVED
343 represents the non-interleaved access.
347 The full list of formats is available in #snd_pcm_format_t
350 \subsection pcm_sw_params Software related parameters
352 These parameters - #snd_pcm_sw_params_t can be modified at
353 any time including the running state.
355 \par Minimum available count of frames
357 This parameter controls the wakeup point. If the count of available frames
358 is equal or greater than this value, then application will be activated.
362 The timestamp mode specifies, if timestamps are activated. Currently, only
363 #SND_PCM_TSTAMP_NONE and #SND_PCM_TSTAMP_MMAP
364 modes are known. The mmap mode means that timestamp is taken
365 on every period time boundary. Corresponding position in the ring buffer
366 assigned to timestamp can be obtained using #snd_pcm_htimestamp() function.
370 The read / write transfers can be aligned to this sample count. The modulo
371 is ignored by device. Usually, this value is set to one (no align).
375 The start threshold parameter is used to determine the start point in
376 stream. For playback, if the frame count in the ring buffer is equal or greater
377 than the start threshold parameter and the stream is not running, the stream
378 will be started automatically from the device. For capture, if the application
379 wants to read count of frames equal or greater then the stream will be started.
380 If you want to use explicit start (#snd_pcm_start), you can set this value
381 greater than the ring buffer size (in frames). For that simply using a large
382 constant such as LONG_MAX or the boundary value is not a bad idea.
386 Similarly, the stop threshold parameter is used to automatically stop
387 the running stream, when the available frames crosses this boundary.
388 It means, for playback, the empty samples in ring buffer and for capture,
389 the filled (used) samples in ring buffer.
391 \par Silence threshold
393 The silence threshold specifies the count of frames before an underrun when the
394 buffer gets filled with frames of silence according to the silence size parameter
395 ahead of the current application pointer for playback. It is usable for applications
396 when an underrun is possible (like tasks depending on network I/O etc.). If
397 application wants to manage the ahead samples itself, the #snd_pcm_rewind() function
398 allows to forget the last samples in the stream.
400 \section pcm_status Obtaining stream status
402 The stream status is stored in #snd_pcm_status_t structure.
403 These parameters can be obtained: the current stream state -
404 #snd_pcm_status_get_state(), timestamp of trigger -
405 #snd_pcm_status_get_trigger_tstamp(), timestamp of last
406 pointer update #snd_pcm_status_get_tstamp(), delay in frames -
407 #snd_pcm_status_get_delay(), available count in frames -
408 #snd_pcm_status_get_avail(), maximum available frames -
409 #snd_pcm_status_get_avail_max(), ADC over-range count in
410 frames - #snd_pcm_status_get_overrange(). The last two
411 parameters - avail_max and overrange are reset to zero after the status
414 \subsection pcm_status_fast Obtaining stream state fast and update r/w pointer
417 The function #snd_pcm_avail_update() updates the current
418 available count of frames for writing (playback) or filled frames for
419 reading (capture). This call is mandatory for updating actual r/w pointer.
420 Using standalone, it is a light method to obtain current stream position,
421 because it does not require the user <-> kernel context switch, but the value
422 is less accurate, because ring buffer pointers are updated in kernel drivers
423 only when an interrupt occurs. If you want to get accurate stream state,
424 use functions #snd_pcm_avail(), #snd_pcm_delay() or #snd_pcm_avail_delay().
427 The function #snd_pcm_avail() reads the current hardware pointer
428 in the ring buffer from hardware and calls #snd_pcm_avail_update() then.
431 The function #snd_pcm_delay() returns the delay in frames.
432 For playback, it means count of frames in the ring buffer before
433 the next frames will be sent to DAC. For capture, it means count of frames
434 in the ring buffer before the next frames will be captured from ADC. It works
435 only when the stream is in the running or draining (playback only) state.
436 Note that this function does not update the current r/w pointer for applications,
437 so the function #snd_pcm_avail_update() must be called afterwards
438 before any read/write begin+commit operations.
441 The function #snd_pcm_avail_delay() combines #snd_pcm_avail() and
442 #snd_pcm_delay() and returns both values in sync.
445 \section pcm_action Managing the stream state
447 The following functions directly and indirectly affect the stream state:
449 \par snd_pcm_hw_params
450 The #snd_pcm_hw_params() function brings the stream state
451 to #SND_PCM_STATE_SETUP
452 if successfully finishes, otherwise the state #SND_PCM_STATE_OPEN
454 When it is brought to SETUP state, this function automatically
455 calls #snd_pcm_prepare() function to bring to the PREPARED state
459 The #snd_pcm_prepare() function enters from #SND_PCM_STATE_SETUP
460 to the #SND_PCM_STATE_PREPARED after a successful finish.
463 The #snd_pcm_start() function enters
464 the #SND_PCM_STATE_RUNNING after a successful finish.
467 The #snd_pcm_drop() function enters the
468 #SND_PCM_STATE_SETUP state.
471 The #snd_pcm_drain() function enters the
472 #SND_PCM_STATE_DRAINING, if
473 the capture device has some samples in the ring buffer otherwise
474 #SND_PCM_STATE_SETUP state is entered.
477 The #snd_pcm_pause() function enters the
478 #SND_PCM_STATE_PAUSED or #SND_PCM_STATE_RUNNING.
480 \par snd_pcm_writei, snd_pcm_writen
481 The #snd_pcm_writei() and #snd_pcm_writen()
482 functions can conditionally start the stream -
483 #SND_PCM_STATE_RUNNING. They depend on the start threshold
486 \par snd_pcm_readi, snd_pcm_readn
487 The #snd_pcm_readi() and #snd_pcm_readn()
488 functions can conditionally start the stream -
489 #SND_PCM_STATE_RUNNING. They depend on the start threshold
492 \section pcm_sync Streams synchronization
494 There are two functions allowing link multiple streams together. In the
495 case, the linking means that all operations are synchronized. Because the
496 drivers cannot guarantee the synchronization (sample resolution) on hardware
497 lacking this feature, the #snd_pcm_hw_params_get_sync() function
498 returns 16-byte synchronization ID, which is equal
499 for hardware synchronized streams. When the #snd_pcm_link()
500 function is called, all operations managing the stream state for these two
501 streams are joined. The opposite function is #snd_pcm_unlink().
503 \section pcm_thread_safety Thread-safety
505 When the library is configured with the proper option, some PCM functions
506 (e.g. #snd_pcm_avail_update()) are thread-safe and can be called concurrently
507 from multiple threads. Meanwhile, some functions (e.g. #snd_pcm_hw_params())
508 aren't thread-safe, and application needs to call them carefully when they
509 are called from multiple threads. In general, all the functions that are
510 often called during streaming are covered as thread-safe.
512 This thread-safe behavior can be disabled also by passing 0 to the environment
513 variable LIBASOUND_THREAD_SAFE, e.g.
515 LIBASOUND_THREAD_SAFE=0 aplay foo.wav
517 for making the debugging easier.
519 \section pcm_dev_names PCM naming conventions
521 The ALSA library uses a generic string representation for names of devices.
522 The devices might be virtual, physical or a mix of both. The generic string
523 is passed to #snd_pcm_open() or #snd_pcm_open_lconf().
524 It contains two parts: device name and arguments. Devices and arguments are described
525 in configuration files. The usual place for default definitions is at /usr/share/alsa/alsa.conf.
526 For detailed descriptions about integrated PCM plugins look to \ref pcm_plugins.
528 \subsection pcm_dev_names_default Default device
530 The default device is equal to plug plugin with hw plugin as slave. The defaults are
535 defaults.pcm.device 0
536 defaults.pcm.subdevice -1
539 These defaults can be freely overwritten in local configuration files.
547 \subsection pcm_dev_names_hw HW device
549 The hw device description uses the hw plugin. The three arguments (in order: CARD,DEV,SUBDEV)
550 specify card number or identifier, device number and subdevice number (-1 means any).
560 hw:DEV=1,CARD=soundwave,SUBDEV=2
563 \subsection pcm_dev_names_plughw Plug->HW device
565 The plughw device description uses the plug plugin and hw plugin as slave. The arguments
566 are same as for hw device.
576 plughw:DEV=1,CARD=soundwave,SUBDEV=2
579 \subsection pcm_dev_names_plug Plug device
581 The plug device uses the plug plugin. The one SLAVE argument specifies the slave plugin.
592 \subsection pcm_dev_names_shm Shared memory device
594 The shm device uses the shm plugin. The two arguments (in order: SOCKET,PCM) specify
595 UNIX socket name (for example /tmp/alsa.socket) for server communication and server's PCM name.
600 shm:'/tmp/alsa.sock',default
601 shm:SOCKET='/tmp/alsa.sock',PCM=default
604 \subsection pcm_dev_names_tee Tee device
606 The tee device stores contents of a stream to given file plus transfers it to given slave plugin.
607 The three arguments (in order: SLAVE,FILE,FORMAT) specify slave plugin, filename and file format.
612 tee:hw,'/tmp/out.raw',raw
615 \subsection pcm_dev_names_file File device
617 The file device is file plugin with null plugin as slave. The arguments (in order: FILE,FORMAT)
618 specify filename and file format.
623 file:'/tmp/out.raw',raw
626 \subsection pcm_dev_names_null Null device
628 The null device is null plugin. This device has not any arguments.
631 \section pcm_examples Examples
633 The full featured examples with cross-links can be found in Examples section
636 \par Sine-wave generator
638 \link example_test_pcm alsa-lib/test/pcm.c \endlink
639 example shows various transfer methods for the playback direction.
641 \par Minimalistic PCM playback code
643 \link example_test_minimal alsa-lib/test/pcm_min.c \endlink
644 example shows the minimal code to produce a sound.
646 \par Latency measuring tool
648 \link example_test_latency alsa-lib/test/latency.c \endlink
649 example shows the measuring of minimal latency between capture and
655 \example ../../test/pcm.c
656 \anchor example_test_pcm
657 Shows various transfer methods for the playback direction.
660 \example ../../test/pcm_min.c
661 \anchor example_test_minimal
662 Shows the minimal code to produce a sound.
665 \example ../../test/latency.c
666 \anchor example_test_latency
667 Shows the measuring of minimal latency between capture and
671 #include "pcm_local.h"
681 #include <sys/mman.h>
685 /* return specific error codes for known bad PCM states */
686 static int pcm_state_to_error(snd_pcm_state_t state)
689 case SND_PCM_STATE_XRUN:
691 case SND_PCM_STATE_SUSPENDED:
693 case SND_PCM_STATE_DISCONNECTED:
700 #define P_STATE(x) (1U << SND_PCM_STATE_ ## x)
701 #define P_STATE_RUNNABLE (P_STATE(PREPARED) | \
707 /* check whether the PCM is in the unexpected state */
708 static int bad_pcm_state(snd_pcm_t *pcm, unsigned int supported_states,
709 unsigned int noop_states)
711 snd_pcm_state_t state;
714 if (pcm->own_state_check)
715 return 0; /* don't care, the plugin checks by itself */
716 state = snd_pcm_state(pcm);
717 if (noop_states & (1U << state))
718 return 1; /* OK, return immediately */
719 if (supported_states & (1U << state))
721 err = pcm_state_to_error(state);
729 * \brief get identifier of PCM handle
730 * \param pcm PCM handle
731 * \return ascii identifier of PCM handle
733 * Returns the ASCII identifier of given PCM handle. It's the same
734 * identifier specified in snd_pcm_open().
736 const char *snd_pcm_name(snd_pcm_t *pcm)
743 * \brief get type of PCM handle
744 * \param pcm PCM handle
745 * \return type of PCM handle
747 * Returns the type #snd_pcm_type_t of given PCM handle.
749 snd_pcm_type_t snd_pcm_type(snd_pcm_t *pcm)
756 * \brief get stream for a PCM handle
757 * \param pcm PCM handle
758 * \return stream of PCM handle
760 * Returns the type #snd_pcm_stream_t of given PCM handle.
762 snd_pcm_stream_t snd_pcm_stream(snd_pcm_t *pcm)
769 * \brief close PCM handle
770 * \param pcm PCM handle
771 * \return 0 on success otherwise a negative error code
773 * Closes the specified PCM handle and frees all associated
776 int snd_pcm_close(snd_pcm_t *pcm)
780 while (!list_empty(&pcm->async_handlers)) {
781 snd_async_handler_t *h = list_entry(pcm->async_handlers.next, snd_async_handler_t, hlist);
782 snd_async_del_handler(h);
784 if (pcm->setup && !pcm->donot_close) {
786 err = snd_pcm_hw_free(pcm);
790 if (pcm->mmap_channels)
793 err = pcm->ops->close(pcm->op_arg);
798 err = snd_pcm_free(pcm);
805 * \brief set nonblock mode
806 * \param pcm PCM handle
807 * \param nonblock 0 = block, 1 = nonblock mode, 2 = abort
808 * \return 0 on success otherwise a negative error code
810 * The function is thread-safe when built with the proper option.
812 int snd_pcm_nonblock(snd_pcm_t *pcm, int nonblock)
817 /* FIXME: __snd_pcm_lock() call below is commented out because of the
818 * the possible deadlock in signal handler calling snd_pcm_abort()
820 /* __snd_pcm_lock(pcm->op_arg); */ /* forced lock due to pcm field change */
821 if (pcm->ops->nonblock)
822 err = pcm->ops->nonblock(pcm->op_arg, nonblock);
828 pcm->mode |= SND_PCM_ABORT;
832 pcm->mode |= SND_PCM_NONBLOCK;
834 if (pcm->hw_flags & SND_PCM_HW_PARAMS_NO_PERIOD_WAKEUP)
837 pcm->mode &= ~SND_PCM_NONBLOCK;
840 /* __snd_pcm_unlock(pcm->op_arg); */ /* FIXME: see above */
846 * \brief set async mode
847 * \param pcm PCM handle
848 * \param sig Signal to raise: < 0 disable, 0 default (SIGIO)
849 * \param pid Process ID to signal: 0 current
850 * \return 0 on success otherwise a negative error code
852 * A signal is raised every period.
854 int snd_pcm_async(snd_pcm_t *pcm, int sig, pid_t pid)
864 #ifdef THREAD_SAFE_API
865 /* async handler may lead to a deadlock; suppose no multi thread */
866 pcm->lock_enabled = 0;
869 err = pcm->ops->async(pcm->op_arg, sig, pid);
877 * \brief Obtain general (static) information for PCM handle
878 * \param pcm PCM handle
879 * \param info Information container
880 * \return 0 on success otherwise a negative error code
882 int snd_pcm_info(snd_pcm_t *pcm, snd_pcm_info_t *info)
888 err = pcm->ops->info(pcm->op_arg, info);
894 /** \brief Retreive current PCM hardware configuration chosen with #snd_pcm_hw_params
895 * \param pcm PCM handle
896 * \param params Configuration space definition container
897 * \return 0 on success otherwise a negative error code
898 * \retval -EBADFD no hardware configuration is set
900 int snd_pcm_hw_params_current(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
902 unsigned int frame_bits;
904 assert(pcm && params);
907 memset(params, 0, snd_pcm_hw_params_sizeof());
908 params->flags = pcm->hw_flags;
909 snd_mask_set(¶ms->masks[SND_PCM_HW_PARAM_ACCESS - SND_PCM_HW_PARAM_FIRST_MASK], pcm->access);
910 snd_mask_set(¶ms->masks[SND_PCM_HW_PARAM_FORMAT - SND_PCM_HW_PARAM_FIRST_MASK], pcm->format);
911 snd_mask_set(¶ms->masks[SND_PCM_HW_PARAM_SUBFORMAT - SND_PCM_HW_PARAM_FIRST_MASK], pcm->subformat);
912 frame_bits = snd_pcm_format_physical_width(pcm->format) * pcm->channels;
913 snd_interval_set_value(¶ms->intervals[SND_PCM_HW_PARAM_FRAME_BITS - SND_PCM_HW_PARAM_FIRST_INTERVAL], frame_bits);
914 snd_interval_set_value(¶ms->intervals[SND_PCM_HW_PARAM_CHANNELS - SND_PCM_HW_PARAM_FIRST_INTERVAL], pcm->channels);
915 snd_interval_set_value(¶ms->intervals[SND_PCM_HW_PARAM_RATE - SND_PCM_HW_PARAM_FIRST_INTERVAL], pcm->rate);
916 snd_interval_set_value(¶ms->intervals[SND_PCM_HW_PARAM_PERIOD_TIME - SND_PCM_HW_PARAM_FIRST_INTERVAL], pcm->period_time);
917 snd_interval_set_value(¶ms->intervals[SND_PCM_HW_PARAM_PERIOD_SIZE - SND_PCM_HW_PARAM_FIRST_INTERVAL], pcm->period_size);
918 snd_interval_copy(¶ms->intervals[SND_PCM_HW_PARAM_PERIODS - SND_PCM_HW_PARAM_FIRST_INTERVAL], &pcm->periods);
919 snd_interval_copy(¶ms->intervals[SND_PCM_HW_PARAM_BUFFER_TIME - SND_PCM_HW_PARAM_FIRST_INTERVAL], &pcm->buffer_time);
920 snd_interval_set_value(¶ms->intervals[SND_PCM_HW_PARAM_BUFFER_SIZE - SND_PCM_HW_PARAM_FIRST_INTERVAL], pcm->buffer_size);
921 snd_interval_set_value(¶ms->intervals[SND_PCM_HW_PARAM_BUFFER_BYTES - SND_PCM_HW_PARAM_FIRST_INTERVAL], (pcm->buffer_size * frame_bits) / 8);
922 params->info = pcm->info;
923 params->msbits = pcm->msbits;
924 params->rate_num = pcm->rate_num;
925 params->rate_den = pcm->rate_den;
926 params->fifo_size = pcm->fifo_size;
930 /** \brief Install one PCM hardware configuration chosen from a configuration space and #snd_pcm_prepare it
931 * \param pcm PCM handle
932 * \param params Configuration space definition container
933 * \return 0 on success otherwise a negative error code
935 * The configuration is chosen fixing single parameters in this order:
936 * first access, first format, first subformat, min channels, min rate,
937 * min period time, max buffer size, min tick time. If no mutually
938 * compatible set of parameters can be chosen, a negative error code
941 * After this call, #snd_pcm_prepare() is called automatically and
942 * the stream is brought to \c #SND_PCM_STATE_PREPARED state.
944 * The hardware parameters cannot be changed when the stream is
945 * running (active). The software parameters can be changed
948 * The configuration space will be updated to reflect the chosen
951 int snd_pcm_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
954 assert(pcm && params);
955 err = _snd_pcm_hw_params_internal(pcm, params);
958 err = snd_pcm_prepare(pcm);
962 /** \brief Remove PCM hardware configuration and free associated resources
963 * \param pcm PCM handle
964 * \return 0 on success otherwise a negative error code
966 * The function will also report success if no configuration is set.
968 int snd_pcm_hw_free(snd_pcm_t *pcm)
973 if (pcm->mmap_channels) {
974 err = snd_pcm_munmap(pcm);
978 // assert(snd_pcm_state(pcm) == SND_PCM_STATE_SETUP ||
979 // snd_pcm_state(pcm) == SND_PCM_STATE_PREPARED);
980 if (pcm->ops->hw_free)
981 err = pcm->ops->hw_free(pcm->op_arg);
990 /** \brief Install PCM software configuration defined by params
991 * \param pcm PCM handle
992 * \param params Configuration container
993 * \return 0 on success otherwise a negative error code
995 * The software parameters can be changed at any time.
996 * The hardware parameters cannot be changed when the stream is
999 * The function is thread-safe when built with the proper option.
1001 int snd_pcm_sw_params(snd_pcm_t *pcm, snd_pcm_sw_params_t *params)
1004 /* the hw_params must be set at first!!! */
1005 if (CHECK_SANITY(! pcm->setup)) {
1006 snd_check(PCM, "PCM not set up");
1009 if (! params->avail_min) {
1010 snd_check(PCM, "params->avail_min is 0");
1014 /* disable the check below - it looks too restrictive
1015 * (start_threshold is basically independent from avail_min)
1017 if (params->start_threshold <= pcm->buffer_size &&
1018 params->start_threshold > (pcm->buffer_size / params->avail_min) * params->avail_min) {
1019 snd_check(PCM, "params->avail_min problem for start_threshold");
1023 __snd_pcm_lock(pcm->op_arg); /* forced lock due to pcm field change */
1024 if (pcm->ops->sw_params)
1025 err = pcm->ops->sw_params(pcm->op_arg, params);
1029 __snd_pcm_unlock(pcm->op_arg);
1032 pcm->tstamp_mode = params->tstamp_mode;
1033 pcm->tstamp_type = params->tstamp_type;
1034 pcm->period_step = params->period_step;
1035 pcm->avail_min = params->avail_min;
1036 pcm->period_event = sw_get_period_event(params);
1037 pcm->start_threshold = params->start_threshold;
1038 pcm->stop_threshold = params->stop_threshold;
1039 pcm->silence_threshold = params->silence_threshold;
1040 pcm->silence_size = params->silence_size;
1041 pcm->boundary = params->boundary;
1042 __snd_pcm_unlock(pcm->op_arg);
1047 * \brief Obtain status (runtime) information for PCM handle
1048 * \param pcm PCM handle
1049 * \param status Status container
1050 * \return 0 on success otherwise a negative error code
1052 * The function is thread-safe when built with the proper option.
1054 int snd_pcm_status(snd_pcm_t *pcm, snd_pcm_status_t *status)
1058 assert(pcm && status);
1059 snd_pcm_lock(pcm->fast_op_arg);
1060 if (pcm->fast_ops->status)
1061 err = pcm->fast_ops->status(pcm->fast_op_arg, status);
1064 snd_pcm_unlock(pcm->fast_op_arg);
1070 * \brief Return PCM state
1071 * \param pcm PCM handle
1072 * \return PCM state #snd_pcm_state_t of given PCM handle
1074 * This is a faster way to obtain only the PCM state without calling
1075 * \link ::snd_pcm_status() \endlink.
1077 * Note that this function always returns one of the
1078 * #snd_pcm_state_t enum variants.
1079 * It will never return a negative error code.
1081 * The function is thread-safe when built with the proper option.
1083 snd_pcm_state_t snd_pcm_state(snd_pcm_t *pcm)
1085 snd_pcm_state_t state;
1088 snd_pcm_lock(pcm->fast_op_arg);
1089 state = __snd_pcm_state(pcm);
1090 snd_pcm_unlock(pcm->fast_op_arg);
1095 * \brief (DEPRECATED) Synchronize stream position with hardware
1096 * \param pcm PCM handle
1097 * \return 0 on success otherwise a negative error code
1099 * Note this function does not update the actual r/w pointer
1100 * for applications. The function #snd_pcm_avail_update()
1101 * have to be called before any mmap begin+commit operation.
1103 * The function is thread-safe when built with the proper option.
1105 * This function is deprecated. Use #snd_pcm_avail_update() instead.
1107 int snd_pcm_hwsync(snd_pcm_t *pcm)
1112 if (CHECK_SANITY(! pcm->setup)) {
1113 snd_check(PCM, "PCM not set up");
1116 snd_pcm_lock(pcm->fast_op_arg);
1117 err = __snd_pcm_hwsync(pcm);
1118 snd_pcm_unlock(pcm->fast_op_arg);
1123 * \brief Obtain delay for a running PCM handle
1124 * \param pcm PCM handle
1125 * \param delayp Returned delay in frames
1126 * \return 0 on success otherwise a negative error code
1128 * For playback the delay is defined as the time that a frame that is written
1129 * to the PCM stream shortly after this call will take to be actually
1130 * audible. It is as such the overall latency from the write call to the final
1133 * For capture the delay is defined as the time that a frame that was
1134 * digitized by the audio device takes until it can be read from the PCM
1135 * stream shortly after this call returns. It is as such the overall latency
1136 * from the initial ADC to the read call.
1138 * Please note that hence in case of a playback underrun this value will not
1139 * necessarily got down to 0.
1141 * If the application is interested in the fill level of the playback buffer
1142 * of the device, it should use #snd_pcm_avail*() functions. The
1143 * value returned by that call is not directly related to the delay, since the
1144 * latter might include some additional, fixed latencies the former does not.
1146 * Note this function does not update the actual r/w pointer
1147 * for applications. The function #snd_pcm_avail_update()
1148 * have to be called before any begin+commit operation.
1150 * The function is thread-safe when built with the proper option.
1152 int snd_pcm_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp)
1157 if (CHECK_SANITY(! pcm->setup)) {
1158 snd_check(PCM, "PCM not set up");
1161 snd_pcm_lock(pcm->fast_op_arg);
1162 err = __snd_pcm_delay(pcm, delayp);
1163 snd_pcm_unlock(pcm->fast_op_arg);
1168 * \brief Resume from suspend, no samples are lost
1169 * \param pcm PCM handle
1170 * \return 0 on success otherwise a negative error code
1171 * \retval -EAGAIN resume can't be proceed immediately (audio hardware is probably still suspended)
1172 * \retval -ENOSYS hardware doesn't support this feature
1174 * This function can be used when the stream is in the suspend state
1175 * to do the fine resume from this state. Not all hardware supports
1176 * this feature, when an -ENOSYS error is returned, use the \link ::snd_pcm_prepare() \endlink
1177 * function to recovery.
1179 * The function is thread-safe when built with the proper option.
1181 int snd_pcm_resume(snd_pcm_t *pcm)
1186 if (CHECK_SANITY(! pcm->setup)) {
1187 snd_check(PCM, "PCM not set up");
1190 /* lock handled in the callback */
1191 if (pcm->fast_ops->resume)
1192 err = pcm->fast_ops->resume(pcm->fast_op_arg);
1199 * \brief Obtain last position update hi-res timestamp
1200 * \param pcm PCM handle
1201 * \param avail Number of available frames when timestamp was grabbed
1202 * \param tstamp Hi-res timestamp
1203 * \return 0 on success otherwise a negative error code
1205 * Note this function does not update the actual r/w pointer
1208 * The function is thread-safe when built with the proper option.
1210 int snd_pcm_htimestamp(snd_pcm_t *pcm, snd_pcm_uframes_t *avail, snd_htimestamp_t *tstamp)
1215 if (CHECK_SANITY(! pcm->setup)) {
1216 snd_check(PCM, "PCM not set up");
1219 snd_pcm_lock(pcm->fast_op_arg);
1220 if (pcm->fast_ops->htimestamp)
1221 err = pcm->fast_ops->htimestamp(pcm->fast_op_arg, avail, tstamp);
1224 snd_pcm_unlock(pcm->fast_op_arg);
1229 * \brief Prepare PCM for use
1230 * \param pcm PCM handle
1231 * \return 0 on success otherwise a negative error code
1233 * The function is thread-safe when built with the proper option.
1235 int snd_pcm_prepare(snd_pcm_t *pcm)
1240 if (CHECK_SANITY(! pcm->setup)) {
1241 snd_check(PCM, "PCM not set up");
1244 err = bad_pcm_state(pcm, ~P_STATE(DISCONNECTED), 0);
1247 snd_pcm_lock(pcm->fast_op_arg);
1248 if (pcm->fast_ops->prepare)
1249 err = pcm->fast_ops->prepare(pcm->fast_op_arg);
1252 snd_pcm_unlock(pcm->fast_op_arg);
1257 * \brief Reset PCM position
1258 * \param pcm PCM handle
1259 * \return 0 on success otherwise a negative error code
1261 * Reduce PCM delay to 0.
1263 * The function is thread-safe when built with the proper option.
1265 int snd_pcm_reset(snd_pcm_t *pcm)
1270 if (CHECK_SANITY(! pcm->setup)) {
1271 snd_check(PCM, "PCM not set up");
1274 snd_pcm_lock(pcm->fast_op_arg);
1275 if (pcm->fast_ops->reset)
1276 err = pcm->fast_ops->reset(pcm->fast_op_arg);
1279 snd_pcm_unlock(pcm->fast_op_arg);
1284 * \brief Start a PCM
1285 * \param pcm PCM handle
1286 * \return 0 on success otherwise a negative error code
1288 * The function is thread-safe when built with the proper option.
1290 int snd_pcm_start(snd_pcm_t *pcm)
1295 if (CHECK_SANITY(! pcm->setup)) {
1296 snd_check(PCM, "PCM not set up");
1299 err = bad_pcm_state(pcm, P_STATE(PREPARED), 0);
1302 snd_pcm_lock(pcm->fast_op_arg);
1303 err = __snd_pcm_start(pcm);
1304 snd_pcm_unlock(pcm->fast_op_arg);
1309 * \brief Stop a PCM dropping pending frames
1310 * \param pcm PCM handle
1311 * \return 0 on success otherwise a negative error code
1313 * This function stops the PCM <i>immediately</i>.
1314 * The pending samples on the buffer are ignored.
1316 * For processing all pending samples, use \link ::snd_pcm_drain() \endlink
1319 * The function is thread-safe when built with the proper option.
1321 int snd_pcm_drop(snd_pcm_t *pcm)
1326 if (CHECK_SANITY(! pcm->setup)) {
1327 snd_check(PCM, "PCM not set up");
1330 err = bad_pcm_state(pcm, P_STATE_RUNNABLE | P_STATE(SETUP) |
1331 P_STATE(SUSPENDED), 0);
1334 snd_pcm_lock(pcm->fast_op_arg);
1335 if (pcm->fast_ops->drop)
1336 err = pcm->fast_ops->drop(pcm->fast_op_arg);
1339 snd_pcm_unlock(pcm->fast_op_arg);
1344 * \brief Stop a PCM preserving pending frames
1345 * \param pcm PCM handle
1346 * \return 0 on success otherwise a negative error code
1347 * \retval -ESTRPIPE a suspend event occurred
1349 * For playback wait for all pending frames to be played and then stop
1351 * For capture stop PCM permitting to retrieve residual frames.
1353 * For stopping the PCM stream immediately, use \link ::snd_pcm_drop() \endlink
1356 * The function is thread-safe when built with the proper option.
1358 int snd_pcm_drain(snd_pcm_t *pcm)
1363 if (CHECK_SANITY(! pcm->setup)) {
1364 snd_check(PCM, "PCM not set up");
1367 err = bad_pcm_state(pcm, P_STATE_RUNNABLE | P_STATE(SETUP), P_STATE(SETUP));
1372 /* lock handled in the callback */
1373 if (pcm->fast_ops->drain)
1374 err = pcm->fast_ops->drain(pcm->fast_op_arg);
1381 * \brief Pause/resume PCM
1382 * \param pcm PCM handle
1383 * \param enable 0 = resume, 1 = pause
1384 * \return 0 on success otherwise a negative error code
1386 * Note that this function works only on the hardware which supports
1387 * pause feature. You can check it via \link ::snd_pcm_hw_params_can_pause() \endlink
1390 * The function is thread-safe when built with the proper option.
1392 int snd_pcm_pause(snd_pcm_t *pcm, int enable)
1397 if (CHECK_SANITY(! pcm->setup)) {
1398 snd_check(PCM, "PCM not set up");
1401 err = bad_pcm_state(pcm, P_STATE_RUNNABLE, 0);
1404 snd_pcm_lock(pcm->fast_op_arg);
1405 if (pcm->fast_ops->pause)
1406 err = pcm->fast_ops->pause(pcm->fast_op_arg, enable);
1409 snd_pcm_unlock(pcm->fast_op_arg);
1414 * \brief Get safe count of frames which can be rewinded
1415 * \param pcm PCM handle
1416 * \return a positive number of frames or negative error code
1418 * Note: The snd_pcm_rewind() can accept bigger value than returned
1419 * by this function. But it is not guaranteed that output stream
1420 * will be consistent with bigger value.
1422 * The function is thread-safe when built with the proper option.
1424 snd_pcm_sframes_t snd_pcm_rewindable(snd_pcm_t *pcm)
1426 snd_pcm_sframes_t result;
1430 if (CHECK_SANITY(! pcm->setup)) {
1431 snd_check(PCM, "PCM not set up");
1434 err = bad_pcm_state(pcm, P_STATE_RUNNABLE, 0);
1437 snd_pcm_lock(pcm->fast_op_arg);
1438 if (pcm->fast_ops->rewindable)
1439 result = pcm->fast_ops->rewindable(pcm->fast_op_arg);
1442 snd_pcm_unlock(pcm->fast_op_arg);
1447 * \brief Move application frame position backward
1448 * \param pcm PCM handle
1449 * \param frames wanted displacement in frames
1450 * \return a positive number for actual displacement otherwise a
1451 * negative error code
1453 * The function is thread-safe when built with the proper option.
1455 snd_pcm_sframes_t snd_pcm_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
1457 snd_pcm_sframes_t result;
1461 if (CHECK_SANITY(! pcm->setup)) {
1462 snd_check(PCM, "PCM not set up");
1467 err = bad_pcm_state(pcm, P_STATE_RUNNABLE, 0);
1470 snd_pcm_lock(pcm->fast_op_arg);
1471 if (pcm->fast_ops->rewind)
1472 result = pcm->fast_ops->rewind(pcm->fast_op_arg, frames);
1475 snd_pcm_unlock(pcm->fast_op_arg);
1480 * \brief Get safe count of frames which can be forwarded
1481 * \param pcm PCM handle
1482 * \return a positive number of frames or negative error code
1484 * Note: The snd_pcm_forward() can accept bigger value than returned
1485 * by this function. But it is not guaranteed that output stream
1486 * will be consistent with bigger value.
1488 * The function is thread-safe when built with the proper option.
1490 snd_pcm_sframes_t snd_pcm_forwardable(snd_pcm_t *pcm)
1492 snd_pcm_sframes_t result;
1496 if (CHECK_SANITY(! pcm->setup)) {
1497 snd_check(PCM, "PCM not set up");
1500 err = bad_pcm_state(pcm, P_STATE_RUNNABLE, 0);
1503 snd_pcm_lock(pcm->fast_op_arg);
1504 if (pcm->fast_ops->forwardable)
1505 result = pcm->fast_ops->forwardable(pcm->fast_op_arg);
1508 snd_pcm_unlock(pcm->fast_op_arg);
1513 * \brief Move application frame position forward
1514 * \param pcm PCM handle
1515 * \param frames wanted skip in frames
1516 * \return a positive number for actual skip otherwise a negative error code
1517 * \retval 0 means no action
1519 * The function is thread-safe when built with the proper option.
1522 EXPORT_SYMBOL snd_pcm_sframes_t INTERNAL(snd_pcm_forward)(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
1524 snd_pcm_sframes_t snd_pcm_forward(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
1527 snd_pcm_sframes_t result;
1531 if (CHECK_SANITY(! pcm->setup)) {
1532 snd_check(PCM, "PCM not set up");
1537 err = bad_pcm_state(pcm, P_STATE_RUNNABLE, 0);
1540 snd_pcm_lock(pcm->fast_op_arg);
1541 if (pcm->fast_ops->forward)
1542 result = pcm->fast_ops->forward(pcm->fast_op_arg, frames);
1545 snd_pcm_unlock(pcm->fast_op_arg);
1548 use_default_symbol_version(__snd_pcm_forward, snd_pcm_forward, ALSA_0.9.0rc8);
1551 * \brief Write interleaved frames to a PCM
1552 * \param pcm PCM handle
1553 * \param buffer frames containing buffer
1554 * \param size frames to be written
1555 * \return a positive number of frames actually written otherwise a
1556 * negative error code
1557 * \retval -EBADFD PCM is not in the right state (#SND_PCM_STATE_PREPARED or #SND_PCM_STATE_RUNNING)
1558 * \retval -EPIPE an underrun occurred
1559 * \retval -ESTRPIPE a suspend event occurred (stream is suspended and waiting for an application recovery)
1561 * If the blocking behaviour is selected and it is running, then routine waits until
1562 * all requested frames are played or put to the playback ring buffer.
1563 * The returned number of frames can be less only if a signal or underrun occurred.
1565 * If the non-blocking behaviour is selected, then routine doesn't wait at all.
1567 * The function is thread-safe when built with the proper option.
1569 snd_pcm_sframes_t snd_pcm_writei(snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size)
1574 assert(size == 0 || buffer);
1575 if (CHECK_SANITY(! pcm->setup)) {
1576 snd_check(PCM, "PCM not set up");
1579 if (pcm->access != SND_PCM_ACCESS_RW_INTERLEAVED) {
1580 snd_check(PCM, "invalid access type %s", snd_pcm_access_name(pcm->access));
1583 err = bad_pcm_state(pcm, P_STATE_RUNNABLE, 0);
1586 return _snd_pcm_writei(pcm, buffer, size);
1590 * \brief Write non interleaved frames to a PCM
1591 * \param pcm PCM handle
1592 * \param bufs frames containing buffers (one for each channel)
1593 * \param size frames to be written
1594 * \return a positive number of frames actually written otherwise a
1595 * negative error code
1596 * \retval -EBADFD PCM is not in the right state (#SND_PCM_STATE_PREPARED or #SND_PCM_STATE_RUNNING)
1597 * \retval -EPIPE an underrun occurred
1598 * \retval -ESTRPIPE a suspend event occurred (stream is suspended and waiting for an application recovery)
1600 * If the blocking behaviour is selected and it is running, then routine waits until
1601 * all requested frames are played or put to the playback ring buffer.
1602 * The returned number of frames can be less only if a signal or underrun occurred.
1604 * If the non-blocking behaviour is selected, then routine doesn't wait at all.
1606 * The function is thread-safe when built with the proper option.
1608 snd_pcm_sframes_t snd_pcm_writen(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size)
1613 assert(size == 0 || bufs);
1614 if (CHECK_SANITY(! pcm->setup)) {
1615 snd_check(PCM, "PCM not set up");
1618 if (pcm->access != SND_PCM_ACCESS_RW_NONINTERLEAVED) {
1619 snd_check(PCM, "invalid access type %s", snd_pcm_access_name(pcm->access));
1622 err = bad_pcm_state(pcm, P_STATE_RUNNABLE, 0);
1625 return _snd_pcm_writen(pcm, bufs, size);
1629 * \brief Read interleaved frames from a PCM
1630 * \param pcm PCM handle
1631 * \param buffer frames containing buffer
1632 * \param size frames to be read
1633 * \return a positive number of frames actually read otherwise a
1634 * negative error code
1635 * \retval -EBADFD PCM is not in the right state (#SND_PCM_STATE_PREPARED or #SND_PCM_STATE_RUNNING)
1636 * \retval -EPIPE an overrun occurred
1637 * \retval -ESTRPIPE a suspend event occurred (stream is suspended and waiting for an application recovery)
1639 * If the blocking behaviour was selected and it is running, then routine waits until
1640 * all requested frames are filled. The returned number of frames can be less only
1641 * if a signal or underrun occurred.
1643 * If the non-blocking behaviour is selected, then routine doesn't wait at all.
1645 * The function is thread-safe when built with the proper option.
1647 snd_pcm_sframes_t snd_pcm_readi(snd_pcm_t *pcm, void *buffer, snd_pcm_uframes_t size)
1652 assert(size == 0 || buffer);
1653 if (CHECK_SANITY(! pcm->setup)) {
1654 snd_check(PCM, "PCM not set up");
1657 if (pcm->access != SND_PCM_ACCESS_RW_INTERLEAVED) {
1658 snd_check(PCM, "invalid access type %s", snd_pcm_access_name(pcm->access));
1661 err = bad_pcm_state(pcm, P_STATE_RUNNABLE, 0);
1664 return _snd_pcm_readi(pcm, buffer, size);
1668 * \brief Read non interleaved frames to a PCM
1669 * \param pcm PCM handle
1670 * \param bufs frames containing buffers (one for each channel)
1671 * \param size frames to be read
1672 * \return a positive number of frames actually read otherwise a
1673 * negative error code
1674 * \retval -EBADFD PCM is not in the right state (#SND_PCM_STATE_PREPARED or #SND_PCM_STATE_RUNNING)
1675 * \retval -EPIPE an overrun occurred
1676 * \retval -ESTRPIPE a suspend event occurred (stream is suspended and waiting for an application recovery)
1678 * If the blocking behaviour was selected and it is running, then routine waits until
1679 * all requested frames are filled. The returned number of frames can be less only
1680 * if a signal or underrun occurred.
1682 * If the non-blocking behaviour is selected, then routine doesn't wait at all.
1684 * The function is thread-safe when built with the proper option.
1686 snd_pcm_sframes_t snd_pcm_readn(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size)
1691 assert(size == 0 || bufs);
1692 if (CHECK_SANITY(! pcm->setup)) {
1693 snd_check(PCM, "PCM not set up");
1696 if (pcm->access != SND_PCM_ACCESS_RW_NONINTERLEAVED) {
1697 snd_check(PCM, "invalid access type %s", snd_pcm_access_name(pcm->access));
1700 err = bad_pcm_state(pcm, P_STATE_RUNNABLE, 0);
1703 return _snd_pcm_readn(pcm, bufs, size);
1707 * \brief Link two PCMs
1708 * \param pcm1 first PCM handle
1709 * \param pcm2 first PCM handle
1710 * \return 0 on success otherwise a negative error code
1712 * The two PCMs will start/stop/prepare in sync.
1714 int snd_pcm_link(snd_pcm_t *pcm1, snd_pcm_t *pcm2)
1720 if (pcm1->fast_ops->link)
1721 err = pcm1->fast_ops->link(pcm1->fast_op_arg, pcm2);
1728 * \brief Remove a PCM from a linked group
1729 * \param pcm PCM handle
1730 * \return 0 on success otherwise a negative error code
1732 int snd_pcm_unlink(snd_pcm_t *pcm)
1737 if (pcm->fast_ops->unlink)
1738 err = pcm->fast_ops->unlink(pcm->fast_op_arg);
1744 /* locked version */
1745 static int __snd_pcm_poll_descriptors_count(snd_pcm_t *pcm)
1747 if (pcm->fast_ops->poll_descriptors_count)
1748 return pcm->fast_ops->poll_descriptors_count(pcm->fast_op_arg);
1749 return pcm->poll_fd_count;
1753 * \brief get count of poll descriptors for PCM handle
1754 * \param pcm PCM handle
1755 * \return count of poll descriptors
1757 * The function is thread-safe when built with the proper option.
1759 int snd_pcm_poll_descriptors_count(snd_pcm_t *pcm)
1764 snd_pcm_lock(pcm->fast_op_arg);
1765 count = __snd_pcm_poll_descriptors_count(pcm);
1766 snd_pcm_unlock(pcm->fast_op_arg);
1770 /* locked version */
1771 static int __snd_pcm_poll_descriptors(snd_pcm_t *pcm, struct pollfd *pfds,
1774 if (pcm->fast_ops->poll_descriptors)
1775 return pcm->fast_ops->poll_descriptors(pcm->fast_op_arg, pfds, space);
1776 if (pcm->poll_fd < 0) {
1777 snd_check(PCM, "poll_fd < 0");
1780 if (space >= 1 && pfds) {
1781 pfds->fd = pcm->poll_fd;
1782 pfds->events = pcm->poll_events | POLLERR | POLLNVAL;
1790 * \brief get poll descriptors
1791 * \param pcm PCM handle
1792 * \param pfds array of poll descriptors
1793 * \param space space in the poll descriptor array
1794 * \return count of filled descriptors
1796 * This function fills the given poll descriptor structs for the specified
1797 * PCM handle. The poll desctiptor array should have the size returned by
1798 * \link ::snd_pcm_poll_descriptors_count() \endlink function.
1800 * The result is intended for direct use with the poll() syscall.
1802 * For reading the returned events of poll descriptor after poll() system
1803 * call, use \link ::snd_pcm_poll_descriptors_revents() \endlink function.
1804 * The field values in pollfd structs may be bogus regarding the stream
1805 * direction from the application perspective (POLLIN might not imply read
1806 * direction and POLLOUT might not imply write), but
1807 * the \link ::snd_pcm_poll_descriptors_revents() \endlink function
1808 * does the right "demangling".
1810 * You can use output from this function as arguments for the select()
1811 * syscall, too. Do not forget to translate POLLIN and POLLOUT events to
1812 * corresponding FD_SET arrays and demangle events using
1813 * \link ::snd_pcm_poll_descriptors_revents() \endlink .
1815 * It is guaranteed that for the given PCM handle, the output poll
1816 * descriptor structs (and their count) will not change after
1817 * hardware and software parameters setup. Thus it is valid to call
1818 * the function once when all parameters are set and reuse its output
1819 * for the lifetime of the stream parameters.
1821 * The function is thread-safe when built with the proper option.
1823 int snd_pcm_poll_descriptors(snd_pcm_t *pcm, struct pollfd *pfds, unsigned int space)
1827 assert(pcm && pfds);
1828 snd_pcm_lock(pcm->fast_op_arg);
1829 err = __snd_pcm_poll_descriptors(pcm, pfds, space);
1830 snd_pcm_unlock(pcm->fast_op_arg);
1834 static int __snd_pcm_poll_revents(snd_pcm_t *pcm, struct pollfd *pfds,
1835 unsigned int nfds, unsigned short *revents);
1838 * \brief get returned events from poll descriptors
1839 * \param pcm PCM handle
1840 * \param pfds array of poll descriptors
1841 * \param nfds count of poll descriptors
1842 * \param revents pointer to the returned (single) event
1843 * \return zero if success, otherwise a negative error code
1845 * This function does "demangling" of the revents mask returned from
1846 * the poll() syscall to correct semantics (POLLIN = read, POLLOUT = write).
1848 * Note: The null event also exists. Even if poll() or select()
1849 * syscall returned that some events are waiting, this function might
1850 * return empty set of events. In this case, application should
1851 * do next event waiting using poll() or select().
1853 * Note: Even if multiple poll descriptors are used (i.e. pfds > 1),
1854 * this function returns only a single event.
1856 * The passed in count of poll descriptors must be equal to
1857 * \link ::snd_pcm_poll_descriptors_count() \endlink and the passed in array
1858 * must match the array returned by \link ::snd_pcm_poll_descriptors() \endlink
1859 * (in its full length and original order) with the revent fields updated
1860 * according to the poll() result. This function will not modify the file
1861 * descriptor or event field of any element of the given poll descriptor array.
1863 * The function is thread-safe when built with the proper option.
1865 int snd_pcm_poll_descriptors_revents(snd_pcm_t *pcm, struct pollfd *pfds, unsigned int nfds, unsigned short *revents)
1869 assert(pcm && pfds && revents);
1870 snd_pcm_lock(pcm->fast_op_arg);
1871 err = __snd_pcm_poll_revents(pcm, pfds, nfds, revents);
1872 snd_pcm_unlock(pcm->fast_op_arg);
1876 static int __snd_pcm_poll_revents(snd_pcm_t *pcm, struct pollfd *pfds,
1877 unsigned int nfds, unsigned short *revents)
1879 if (pcm->fast_ops->poll_revents)
1880 return pcm->fast_ops->poll_revents(pcm->fast_op_arg, pfds, nfds, revents);
1882 *revents = pfds->revents;
1889 #define PCMTYPE(v) [SND_PCM_TYPE_##v] = #v
1890 #define STATE(v) [SND_PCM_STATE_##v] = #v
1891 #define STREAM(v) [SND_PCM_STREAM_##v] = #v
1892 #define READY(v) [SND_PCM_READY_##v] = #v
1893 #define XRUN(v) [SND_PCM_XRUN_##v] = #v
1894 #define SILENCE(v) [SND_PCM_SILENCE_##v] = #v
1895 #define TSTAMP(v) [SND_PCM_TSTAMP_##v] = #v
1896 #define TSTAMP_TYPE(v) [SND_PCM_TSTAMP_TYPE_##v] = #v
1897 #define ACCESS(v) [SND_PCM_ACCESS_##v] = #v
1898 #define START(v) [SND_PCM_START_##v] = #v
1899 #define HW_PARAM(v) [SND_PCM_HW_PARAM_##v] = #v
1900 #define SW_PARAM(v) [SND_PCM_SW_PARAM_##v] = #v
1901 #define FORMAT(v) [SND_PCM_FORMAT_##v] = #v
1902 #define SUBFORMAT(v) [SND_PCM_SUBFORMAT_##v] = #v
1904 #define FORMATD(v, d) [SND_PCM_FORMAT_##v] = d
1905 #define SUBFORMATD(v, d) [SND_PCM_SUBFORMAT_##v] = d
1908 static const char *const snd_pcm_stream_names[] = {
1913 static const char *const snd_pcm_state_names[] = {
1922 STATE(DISCONNECTED),
1925 static const char *const snd_pcm_access_names[] = {
1926 ACCESS(MMAP_INTERLEAVED),
1927 ACCESS(MMAP_NONINTERLEAVED),
1928 ACCESS(MMAP_COMPLEX),
1929 ACCESS(RW_INTERLEAVED),
1930 ACCESS(RW_NONINTERLEAVED),
1933 static const char *const snd_pcm_format_names[] = {
1952 FORMAT(IEC958_SUBFRAME_LE),
1953 FORMAT(IEC958_SUBFRAME_BE),
1987 static const char *const snd_pcm_format_aliases[SND_PCM_FORMAT_LAST+1] = {
1996 FORMAT(IEC958_SUBFRAME),
2001 static const char *const snd_pcm_format_descriptions[] = {
2002 FORMATD(S8, "Signed 8 bit"),
2003 FORMATD(U8, "Unsigned 8 bit"),
2004 FORMATD(S16_LE, "Signed 16 bit Little Endian"),
2005 FORMATD(S16_BE, "Signed 16 bit Big Endian"),
2006 FORMATD(U16_LE, "Unsigned 16 bit Little Endian"),
2007 FORMATD(U16_BE, "Unsigned 16 bit Big Endian"),
2008 FORMATD(S24_LE, "Signed 24 bit Little Endian"),
2009 FORMATD(S24_BE, "Signed 24 bit Big Endian"),
2010 FORMATD(U24_LE, "Unsigned 24 bit Little Endian"),
2011 FORMATD(U24_BE, "Unsigned 24 bit Big Endian"),
2012 FORMATD(S32_LE, "Signed 32 bit Little Endian"),
2013 FORMATD(S32_BE, "Signed 32 bit Big Endian"),
2014 FORMATD(U32_LE, "Unsigned 32 bit Little Endian"),
2015 FORMATD(U32_BE, "Unsigned 32 bit Big Endian"),
2016 FORMATD(FLOAT_LE, "Float 32 bit Little Endian"),
2017 FORMATD(FLOAT_BE, "Float 32 bit Big Endian"),
2018 FORMATD(FLOAT64_LE, "Float 64 bit Little Endian"),
2019 FORMATD(FLOAT64_BE, "Float 64 bit Big Endian"),
2020 FORMATD(IEC958_SUBFRAME_LE, "IEC-958 Little Endian"),
2021 FORMATD(IEC958_SUBFRAME_BE, "IEC-958 Big Endian"),
2022 FORMATD(MU_LAW, "Mu-Law"),
2023 FORMATD(A_LAW, "A-Law"),
2024 FORMATD(IMA_ADPCM, "Ima-ADPCM"),
2025 FORMATD(MPEG, "MPEG"),
2026 FORMATD(GSM, "GSM"),
2027 FORMATD(S20_LE, "Signed 20 bit Little Endian in 4 bytes, LSB justified"),
2028 FORMATD(S20_BE, "Signed 20 bit Big Endian in 4 bytes, LSB justified"),
2029 FORMATD(U20_LE, "Unsigned 20 bit Little Endian in 4 bytes, LSB justified"),
2030 FORMATD(U20_BE, "Unsigned 20 bit Big Endian in 4 bytes, LSB justified"),
2031 FORMATD(SPECIAL, "Special"),
2032 FORMATD(S24_3LE, "Signed 24 bit Little Endian in 3bytes"),
2033 FORMATD(S24_3BE, "Signed 24 bit Big Endian in 3bytes"),
2034 FORMATD(U24_3LE, "Unsigned 24 bit Little Endian in 3bytes"),
2035 FORMATD(U24_3BE, "Unsigned 24 bit Big Endian in 3bytes"),
2036 FORMATD(S20_3LE, "Signed 20 bit Little Endian in 3bytes"),
2037 FORMATD(S20_3BE, "Signed 20 bit Big Endian in 3bytes"),
2038 FORMATD(U20_3LE, "Unsigned 20 bit Little Endian in 3bytes"),
2039 FORMATD(U20_3BE, "Unsigned 20 bit Big Endian in 3bytes"),
2040 FORMATD(S18_3LE, "Signed 18 bit Little Endian in 3bytes"),
2041 FORMATD(S18_3BE, "Signed 18 bit Big Endian in 3bytes"),
2042 FORMATD(U18_3LE, "Unsigned 18 bit Little Endian in 3bytes"),
2043 FORMATD(U18_3BE, "Unsigned 18 bit Big Endian in 3bytes"),
2044 FORMATD(G723_24, "G.723 (ADPCM) 24 kbit/s, 8 samples in 3 bytes"),
2045 FORMATD(G723_24_1B, "G.723 (ADPCM) 24 kbit/s, 1 sample in 1 byte"),
2046 FORMATD(G723_40, "G.723 (ADPCM) 40 kbit/s, 8 samples in 3 bytes"),
2047 FORMATD(G723_40_1B, "G.723 (ADPCM) 40 kbit/s, 1 sample in 1 byte"),
2048 FORMATD(DSD_U8, "Direct Stream Digital, 1-byte (x8), oldest bit in MSB"),
2049 FORMATD(DSD_U16_LE, "Direct Stream Digital, 2-byte (x16), little endian, oldest bits in MSB"),
2050 FORMATD(DSD_U32_LE, "Direct Stream Digital, 4-byte (x32), little endian, oldest bits in MSB"),
2051 FORMATD(DSD_U16_BE, "Direct Stream Digital, 2-byte (x16), big endian, oldest bits in MSB"),
2052 FORMATD(DSD_U32_BE, "Direct Stream Digital, 4-byte (x32), big endian, oldest bits in MSB"),
2055 static const char *const snd_pcm_type_names[] = {
2076 PCMTYPE(LINEAR_FLOAT),
2088 static const char *const snd_pcm_subformat_names[] = {
2090 SUBFORMAT(MSBITS_MAX),
2091 SUBFORMAT(MSBITS_20),
2092 SUBFORMAT(MSBITS_24),
2095 static const char *const snd_pcm_subformat_descriptions[] = {
2096 SUBFORMATD(STD, "Standard"),
2097 SUBFORMATD(MSBITS_MAX, "Maximum based on PCM format"),
2098 SUBFORMATD(MSBITS_20, "20 most significant bits"),
2099 SUBFORMATD(MSBITS_24, "24 most significant bits"),
2102 static const char *const snd_pcm_start_mode_names[] = {
2107 static const char *const snd_pcm_xrun_mode_names[] = {
2112 static const char *const snd_pcm_tstamp_mode_names[] = {
2117 static const char *const snd_pcm_tstamp_type_names[] = {
2118 TSTAMP_TYPE(GETTIMEOFDAY),
2119 TSTAMP_TYPE(MONOTONIC),
2120 TSTAMP_TYPE(MONOTONIC_RAW),
2125 * \brief get name of PCM stream type
2126 * \param stream PCM stream type
2127 * \return ascii name of PCM stream type
2129 const char *snd_pcm_stream_name(const snd_pcm_stream_t stream)
2131 if (stream > SND_PCM_STREAM_LAST)
2133 return snd_pcm_stream_names[stream];
2137 * \brief get name of PCM access type
2138 * \param acc PCM access type
2139 * \return ascii name of PCM access type
2141 const char *snd_pcm_access_name(const snd_pcm_access_t acc)
2143 if (acc > SND_PCM_ACCESS_LAST)
2145 return snd_pcm_access_names[acc];
2149 * \brief get name of PCM sample format
2150 * \param format PCM sample format
2151 * \return ascii name of PCM sample format
2153 const char *snd_pcm_format_name(const snd_pcm_format_t format)
2155 if (format > SND_PCM_FORMAT_LAST)
2157 return snd_pcm_format_names[format];
2161 * \brief get description of PCM sample format
2162 * \param format PCM sample format
2163 * \return ascii description of PCM sample format
2165 const char *snd_pcm_format_description(const snd_pcm_format_t format)
2167 if (format > SND_PCM_FORMAT_LAST)
2169 return snd_pcm_format_descriptions[format];
2173 * \brief get PCM sample format from name
2174 * \param name PCM sample format name (case insensitive)
2175 * \return PCM sample format
2177 snd_pcm_format_t snd_pcm_format_value(const char* name)
2179 snd_pcm_format_t format;
2180 for (format = 0; format <= SND_PCM_FORMAT_LAST; format++) {
2181 if (snd_pcm_format_names[format] &&
2182 strcasecmp(name, snd_pcm_format_names[format]) == 0) {
2185 if (snd_pcm_format_aliases[format] &&
2186 strcasecmp(name, snd_pcm_format_aliases[format]) == 0) {
2190 for (format = 0; format <= SND_PCM_FORMAT_LAST; format++) {
2191 if (snd_pcm_format_descriptions[format] &&
2192 strcasecmp(name, snd_pcm_format_descriptions[format]) == 0) {
2196 return SND_PCM_FORMAT_UNKNOWN;
2200 * \brief get name of PCM sample subformat
2201 * \param subformat PCM sample subformat
2202 * \return ascii name of PCM sample subformat
2204 const char *snd_pcm_subformat_name(const snd_pcm_subformat_t subformat)
2206 if (subformat > SND_PCM_SUBFORMAT_LAST)
2208 return snd_pcm_subformat_names[subformat];
2212 * \brief get description of PCM sample subformat
2213 * \param subformat PCM sample subformat
2214 * \return ascii description of PCM sample subformat
2216 const char *snd_pcm_subformat_description(const snd_pcm_subformat_t subformat)
2218 if (subformat > SND_PCM_SUBFORMAT_LAST)
2220 return snd_pcm_subformat_descriptions[subformat];
2224 * \brief get PCM sample subformat from name
2225 * \param name PCM sample subformat name (case insensitive)
2226 * \return PCM sample subformat
2228 snd_pcm_subformat_t snd_pcm_subformat_value(const char* name)
2230 snd_pcm_subformat_t subformat;
2232 for (subformat = 0; subformat <= SND_PCM_SUBFORMAT_LAST; subformat++) {
2233 if (snd_pcm_subformat_names[subformat] &&
2234 !strcasecmp(name, snd_pcm_subformat_names[subformat]))
2238 for (subformat = 0; subformat <= SND_PCM_SUBFORMAT_LAST; subformat++) {
2239 if (snd_pcm_subformat_descriptions[subformat] &&
2240 !strcasecmp(name, snd_pcm_subformat_descriptions[subformat]))
2244 return SND_PCM_SUBFORMAT_UNKNOWN;
2248 * \brief (DEPRECATED) get name of PCM start mode setting
2249 * \param mode PCM start mode
2250 * \return ascii name of PCM start mode setting
2252 const char *snd_pcm_start_mode_name(snd_pcm_start_t mode)
2254 if (mode > SND_PCM_START_LAST)
2256 return snd_pcm_start_mode_names[mode];
2260 link_warning(snd_pcm_start_mode_name, "Warning: start_mode is deprecated, consider to use start_threshold");
2264 * \brief (DEPRECATED) get name of PCM xrun mode setting
2265 * \param mode PCM xrun mode
2266 * \return ascii name of PCM xrun mode setting
2268 const char *snd_pcm_xrun_mode_name(snd_pcm_xrun_t mode)
2270 if (mode > SND_PCM_XRUN_LAST)
2272 return snd_pcm_xrun_mode_names[mode];
2276 link_warning(snd_pcm_xrun_mode_name, "Warning: xrun_mode is deprecated, consider to use stop_threshold");
2280 * \brief get name of PCM tstamp mode setting
2281 * \param mode PCM tstamp mode
2282 * \return ascii name of PCM tstamp mode setting
2284 const char *snd_pcm_tstamp_mode_name(const snd_pcm_tstamp_t mode)
2286 if (mode > SND_PCM_TSTAMP_LAST)
2288 return snd_pcm_tstamp_mode_names[mode];
2292 * \brief get name of PCM tstamp type setting
2293 * \param type PCM tstamp type
2294 * \return ascii name of PCM tstamp type setting
2296 const char *snd_pcm_tstamp_type_name(snd_pcm_tstamp_type_t type)
2298 if (type > SND_PCM_TSTAMP_TYPE_LAST)
2300 return snd_pcm_tstamp_type_names[type];
2304 * \brief get name of PCM state
2305 * \param state PCM state
2306 * \return ascii name of PCM state
2308 const char *snd_pcm_state_name(const snd_pcm_state_t state)
2310 if (state > SND_PCM_STATE_LAST)
2312 return snd_pcm_state_names[state];
2316 * \brief get name of PCM type
2317 * \param type PCM type
2318 * \return ascii name of PCM type
2321 EXPORT_SYMBOL const char *INTERNAL(snd_pcm_type_name)(snd_pcm_type_t type)
2323 const char *snd_pcm_type_name(snd_pcm_type_t type)
2326 if (type > SND_PCM_TYPE_LAST)
2328 return snd_pcm_type_names[type];
2330 use_default_symbol_version(__snd_pcm_type_name, snd_pcm_type_name, ALSA_0.9.0);
2333 * \brief Dump current hardware setup for PCM
2334 * \param pcm PCM handle
2335 * \param out Output handle
2336 * \return 0 on success otherwise a negative error code
2338 int snd_pcm_dump_hw_setup(snd_pcm_t *pcm, snd_output_t *out)
2342 if (CHECK_SANITY(! pcm->setup)) {
2343 snd_check(PCM, "PCM not set up");
2346 snd_output_printf(out, " stream : %s\n", snd_pcm_stream_name(pcm->stream));
2347 snd_output_printf(out, " access : %s\n", snd_pcm_access_name(pcm->access));
2348 snd_output_printf(out, " format : %s\n", snd_pcm_format_name(pcm->format));
2349 snd_output_printf(out, " subformat : %s\n", snd_pcm_subformat_name(pcm->subformat));
2350 snd_output_printf(out, " channels : %u\n", pcm->channels);
2351 snd_output_printf(out, " rate : %u\n", pcm->rate);
2352 snd_output_printf(out, " exact rate : %g (%u/%u)\n",
2353 (pcm->rate_den ? ((double) pcm->rate_num / pcm->rate_den) : 0.0),
2354 pcm->rate_num, pcm->rate_den);
2355 snd_output_printf(out, " msbits : %u\n", pcm->msbits);
2356 snd_output_printf(out, " buffer_size : %lu\n", pcm->buffer_size);
2357 snd_output_printf(out, " period_size : %lu\n", pcm->period_size);
2358 snd_output_printf(out, " period_time : %u\n", pcm->period_time);
2363 * \brief Dump current software setup for PCM
2364 * \param pcm PCM handle
2365 * \param out Output handle
2366 * \return 0 on success otherwise a negative error code
2368 int snd_pcm_dump_sw_setup(snd_pcm_t *pcm, snd_output_t *out)
2372 if (CHECK_SANITY(! pcm->setup)) {
2373 snd_check(PCM, "PCM not set up");
2376 snd_output_printf(out, " tstamp_mode : %s\n", snd_pcm_tstamp_mode_name(pcm->tstamp_mode));
2377 snd_output_printf(out, " tstamp_type : %s\n", snd_pcm_tstamp_type_name(pcm->tstamp_type));
2378 snd_output_printf(out, " period_step : %d\n", pcm->period_step);
2379 snd_output_printf(out, " avail_min : %ld\n", pcm->avail_min);
2380 snd_output_printf(out, " period_event : %i\n", pcm->period_event);
2381 snd_output_printf(out, " start_threshold : %ld\n", pcm->start_threshold);
2382 snd_output_printf(out, " stop_threshold : %ld\n", pcm->stop_threshold);
2383 snd_output_printf(out, " silence_threshold: %ld\n", pcm->silence_threshold);
2384 snd_output_printf(out, " silence_size : %ld\n", pcm->silence_size);
2385 snd_output_printf(out, " boundary : %ld\n", pcm->boundary);
2390 * \brief Dump current setup (hardware and software) for PCM
2391 * \param pcm PCM handle
2392 * \param out Output handle
2393 * \return 0 on success otherwise a negative error code
2395 int snd_pcm_dump_setup(snd_pcm_t *pcm, snd_output_t *out)
2397 snd_pcm_dump_hw_setup(pcm, out);
2398 snd_pcm_dump_sw_setup(pcm, out);
2403 * \brief Dump status
2404 * \param status Status container
2405 * \param out Output handle
2406 * \return 0 on success otherwise a negative error code
2408 int snd_pcm_status_dump(snd_pcm_status_t *status, snd_output_t *out)
2411 snd_output_printf(out, " state : %s\n", snd_pcm_state_name((snd_pcm_state_t) status->state));
2412 snd_output_printf(out, " trigger_time: %ld.%06ld\n",
2413 status->trigger_tstamp.tv_sec,
2414 status->trigger_tstamp.tv_nsec / 1000);
2415 snd_output_printf(out, " tstamp : %ld.%06ld\n",
2416 status->tstamp.tv_sec, status->tstamp.tv_nsec / 1000);
2417 snd_output_printf(out, " delay : %ld\n", (long)status->delay);
2418 snd_output_printf(out, " avail : %ld\n", (long)status->avail);
2419 snd_output_printf(out, " avail_max : %ld\n", (long)status->avail_max);
2424 * \brief Dump PCM info
2425 * \param pcm PCM handle
2426 * \param out Output handle
2427 * \return 0 on success otherwise a negative error code
2429 int snd_pcm_dump(snd_pcm_t *pcm, snd_output_t *out)
2436 pcm->ops->dump(pcm->op_arg, out);
2443 * \brief Convert bytes in frames for a PCM
2444 * \param pcm PCM handle
2445 * \param bytes quantity in bytes
2446 * \return quantity expressed in frames
2448 snd_pcm_sframes_t snd_pcm_bytes_to_frames(snd_pcm_t *pcm, ssize_t bytes)
2451 if (CHECK_SANITY(! pcm->setup)) {
2452 snd_check(PCM, "PCM not set up");
2455 return bytes * 8 / pcm->frame_bits;
2459 * \brief Convert frames in bytes for a PCM
2460 * \param pcm PCM handle
2461 * \param frames quantity in frames
2462 * \return quantity expressed in bytes
2464 ssize_t snd_pcm_frames_to_bytes(snd_pcm_t *pcm, snd_pcm_sframes_t frames)
2467 if (CHECK_SANITY(! pcm->setup)) {
2468 snd_check(PCM, "PCM not set up");
2471 return frames * pcm->frame_bits / 8;
2475 * \brief Convert bytes in samples for a PCM
2476 * \param pcm PCM handle
2477 * \param bytes quantity in bytes
2478 * \return quantity expressed in samples
2480 long snd_pcm_bytes_to_samples(snd_pcm_t *pcm, ssize_t bytes)
2483 if (CHECK_SANITY(! pcm->setup)) {
2484 snd_check(PCM, "PCM not set up");
2487 return bytes * 8 / pcm->sample_bits;
2491 * \brief Convert samples in bytes for a PCM
2492 * \param pcm PCM handle
2493 * \param samples quantity in samples
2494 * \return quantity expressed in bytes
2496 ssize_t snd_pcm_samples_to_bytes(snd_pcm_t *pcm, long samples)
2499 if (CHECK_SANITY(! pcm->setup)) {
2500 snd_check(PCM, "PCM not set up");
2503 return samples * pcm->sample_bits / 8;
2507 * \brief Add an async handler for a PCM
2508 * \param handler Returned handler handle
2509 * \param pcm PCM handle
2510 * \param callback Callback function
2511 * \param private_data Callback private data
2512 * \return 0 otherwise a negative error code on failure
2514 * The asynchronous callback is called when period boundary elapses.
2516 int snd_async_add_pcm_handler(snd_async_handler_t **handler, snd_pcm_t *pcm,
2517 snd_async_callback_t callback, void *private_data)
2521 snd_async_handler_t *h;
2522 err = snd_async_add_handler(&h, _snd_pcm_async_descriptor(pcm),
2523 callback, private_data);
2526 h->type = SND_ASYNC_HANDLER_PCM;
2528 was_empty = list_empty(&pcm->async_handlers);
2529 list_add_tail(&h->hlist, &pcm->async_handlers);
2531 err = snd_pcm_async(pcm, snd_async_handler_get_signo(h), getpid());
2533 snd_async_del_handler(h);
2542 * \brief Return PCM handle related to an async handler
2543 * \param handler Async handler handle
2544 * \return PCM handle
2546 snd_pcm_t *snd_async_handler_get_pcm(snd_async_handler_t *handler)
2548 if (handler->type != SND_ASYNC_HANDLER_PCM) {
2549 snd_check(PCM, "invalid handler type %d", handler->type);
2552 return handler->u.pcm;
2555 static const char *const build_in_pcms[] = {
2556 "adpcm", "alaw", "copy", "dmix", "file", "hooks", "hw", "ladspa", "lfloat",
2557 "linear", "meter", "mulaw", "multi", "null", "empty", "plug", "rate", "route", "share",
2558 "shm", "dsnoop", "dshare", "asym", "iec958", "softvol", "mmap_emul",
2562 static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name,
2563 snd_config_t *pcm_root, snd_config_t *pcm_conf,
2564 snd_pcm_stream_t stream, int mode)
2567 char *buf = NULL, *buf1 = NULL;
2569 snd_config_t *conf, *type_conf = NULL, *tmp;
2570 snd_config_iterator_t i, next;
2572 const char *lib = NULL, *open_name = NULL;
2573 int (*open_func)(snd_pcm_t **, const char *,
2574 snd_config_t *, snd_config_t *,
2575 snd_pcm_stream_t, int) = NULL;
2577 extern void *snd_pcm_open_symbols(void);
2579 if (snd_config_get_type(pcm_conf) != SND_CONFIG_TYPE_COMPOUND) {
2581 if (snd_config_get_id(pcm_conf, &id) < 0)
2583 if (snd_config_get_ascii(pcm_conf, &val) < 0)
2585 snd_error(PCM, "Invalid type for PCM %s%sdefinition (id: %s, value: %s)", name ? name : "", name ? " " : "", id, val);
2589 err = snd_config_search(pcm_conf, "type", &conf);
2591 snd_error(PCM, "type is not defined");
2594 err = snd_config_get_id(conf, &id);
2596 snd_error(PCM, "unable to get id");
2599 err = snd_config_get_string(conf, &str);
2601 snd_error(PCM, "Invalid type for %s", id);
2604 err = snd_config_search_definition(pcm_root, "pcm_type", str, &type_conf);
2606 if (snd_config_get_type(type_conf) != SND_CONFIG_TYPE_COMPOUND) {
2607 snd_error(PCM, "Invalid type for PCM type %s definition", str);
2611 snd_config_for_each(i, next, type_conf) {
2612 snd_config_t *n = snd_config_iterator_entry(i);
2614 if (snd_config_get_id(n, &id) < 0)
2616 if (strcmp(id, "comment") == 0)
2618 if (strcmp(id, "lib") == 0) {
2619 err = snd_config_get_string(n, &lib);
2621 snd_error(PCM, "Invalid type for %s", id);
2626 if (strcmp(id, "open") == 0) {
2627 err = snd_config_get_string(n, &open_name);
2629 snd_error(PCM, "Invalid type for %s", id);
2634 snd_error(PCM, "Unknown field %s", id);
2640 buf = malloc(strlen(str) + 32);
2646 sprintf(buf, "_snd_pcm_%s_open", str);
2649 const char *const *build_in = build_in_pcms;
2651 if (!strcmp(*build_in, str))
2655 if (*build_in == NULL) {
2656 buf1 = malloc(strlen(str) + 32);
2662 sprintf(buf1, "libasound_module_pcm_%s.so", str);
2666 snd_pcm_open_symbols(); /* this call is for static linking only */
2668 open_func = snd_dlobj_cache_get(lib, open_name,
2669 SND_DLSYM_VERSION(SND_PCM_DLSYM_VERSION), 1);
2671 err = open_func(pcmp, name, pcm_root, pcm_conf, stream, mode);
2673 if ((*pcmp)->open_func) {
2674 /* only init plugin (like empty, asym) */
2675 snd_dlobj_cache_put(open_func);
2677 (*pcmp)->open_func = open_func;
2681 snd_dlobj_cache_put(open_func);
2687 err = snd_config_search(pcm_root, "defaults.pcm.compat", &tmp);
2690 if (snd_config_get_integer(tmp, &i) >= 0) {
2692 (*pcmp)->compat = 1;
2695 char *str = getenv("LIBASOUND_COMPAT");
2697 (*pcmp)->compat = 1;
2699 err = snd_config_search(pcm_root, "defaults.pcm.minperiodtime", &tmp);
2701 snd_config_get_integer(tmp, &(*pcmp)->minperiodtime);
2706 snd_config_delete(type_conf);
2712 static int snd_pcm_open_noupdate(snd_pcm_t **pcmp, snd_config_t *root,
2713 const char *name, snd_pcm_stream_t stream,
2717 snd_config_t *pcm_conf;
2720 err = snd_config_search_definition(root, "pcm", name, &pcm_conf);
2722 snd_error(PCM, "Unknown PCM %s", name);
2725 if (snd_config_get_string(pcm_conf, &str) >= 0)
2726 err = snd_pcm_open_noupdate(pcmp, root, str, stream, mode,
2729 snd_config_set_hop(pcm_conf, hop);
2730 err = snd_pcm_open_conf(pcmp, name, root, pcm_conf, stream, mode);
2732 snd_config_delete(pcm_conf);
2737 * \brief Opens a PCM
2738 * \param pcmp Returned PCM handle
2739 * \param name ASCII identifier of the PCM handle
2740 * \param stream Wanted stream
2741 * \param mode Open mode (see #SND_PCM_NONBLOCK, #SND_PCM_ASYNC)
2742 * \return 0 on success otherwise a negative error code
2744 int snd_pcm_open(snd_pcm_t **pcmp, const char *name,
2745 snd_pcm_stream_t stream, int mode)
2750 assert(pcmp && name);
2751 if (_snd_is_ucm_device(name)) {
2752 name = uc_mgr_alibcfg_by_device(&top, name);
2756 err = snd_config_update_ref(&top);
2760 err = snd_pcm_open_noupdate(pcmp, top, name, stream, mode, 0);
2761 snd_config_unref(top);
2766 * \brief Opens a PCM using local configuration
2767 * \param pcmp Returned PCM handle
2768 * \param name ASCII identifier of the PCM handle
2769 * \param stream Wanted stream
2770 * \param mode Open mode (see #SND_PCM_NONBLOCK, #SND_PCM_ASYNC)
2771 * \param lconf Local configuration
2772 * \return 0 on success otherwise a negative error code
2774 int snd_pcm_open_lconf(snd_pcm_t **pcmp, const char *name,
2775 snd_pcm_stream_t stream, int mode,
2776 snd_config_t *lconf)
2778 assert(pcmp && name && lconf);
2779 return snd_pcm_open_noupdate(pcmp, lconf, name, stream, mode, 0);
2783 * \brief Opens a fallback PCM
2784 * \param pcmp Returned PCM handle
2785 * \param root Configuration root
2786 * \param name ASCII identifier of the PCM handle
2787 * \param orig_name The original ASCII name
2788 * \param stream Wanted stream
2789 * \param mode Open mode (see #SND_PCM_NONBLOCK, #SND_PCM_ASYNC)
2790 * \return 0 on success otherwise a negative error code
2792 int snd_pcm_open_fallback(snd_pcm_t **pcmp, snd_config_t *root,
2793 const char *name, const char *orig_name,
2794 snd_pcm_stream_t stream, int mode)
2797 assert(pcmp && name && root);
2798 err = snd_pcm_open_noupdate(pcmp, root, name, stream, mode, 0);
2800 free((*pcmp)->name);
2801 (*pcmp)->name = orig_name ? strdup(orig_name) : NULL;
2807 int snd_pcm_new(snd_pcm_t **pcmp, snd_pcm_type_t type, const char *name,
2808 snd_pcm_stream_t stream, int mode)
2811 #ifdef THREAD_SAFE_API
2812 pthread_mutexattr_t attr;
2815 pcm = calloc(1, sizeof(*pcm));
2820 pcm->name = strdup(name);
2821 pcm->stream = stream;
2823 pcm->poll_fd_count = 1;
2826 pcm->fast_op_arg = pcm;
2827 INIT_LIST_HEAD(&pcm->async_handlers);
2828 #ifdef THREAD_SAFE_API
2829 pthread_mutexattr_init(&attr);
2830 #ifdef HAVE_PTHREAD_MUTEX_RECURSIVE
2831 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
2833 pthread_mutex_init(&pcm->lock, &attr);
2834 pthread_mutexattr_destroy(&attr);
2835 /* use locking as default;
2836 * each plugin may suppress this in its open call
2839 if (mode & SND_PCM_ASYNC) {
2840 /* async handler may lead to a deadlock; suppose no MT */
2841 pcm->lock_enabled = 0;
2843 /* set lock_enabled field depending on $LIBASOUND_THREAD_SAFE */
2844 static int do_lock_enable = -1; /* uninitialized */
2846 /* evaluate env var only once at the first open for consistency */
2847 if (do_lock_enable == -1) {
2848 char *p = getenv("LIBASOUND_THREAD_SAFE");
2849 do_lock_enable = !p || *p != '0';
2851 pcm->lock_enabled = do_lock_enable;
2858 int snd_pcm_free(snd_pcm_t *pcm)
2862 free(pcm->hw.link_dst);
2863 free(pcm->appl.link_dst);
2864 snd_dlobj_cache_put(pcm->open_func);
2865 #ifdef THREAD_SAFE_API
2866 pthread_mutex_destroy(&pcm->lock);
2872 int snd_pcm_open_named_slave(snd_pcm_t **pcmp, const char *name,
2874 snd_config_t *conf, snd_pcm_stream_t stream,
2875 int mode, snd_config_t *parent_conf)
2880 if ((hop = snd_config_check_hop(parent_conf)) < 0)
2882 if (snd_config_get_string(conf, &str) >= 0)
2883 return snd_pcm_open_noupdate(pcmp, root, str, stream, mode,
2885 return snd_pcm_open_conf(pcmp, name, root, conf, stream, mode);
2890 * \brief Wait for a PCM to become ready
2891 * \param pcm PCM handle
2892 * \param timeout maximum time in milliseconds to wait,
2893 * a -1 value means infinity (SND_PCM_WAIT_INFINITE),
2894 * see also SND_PCM_WAIT_IO and SND_PCM_WAIT_DRAIN
2895 * \return a positive value on success otherwise a negative error code
2896 * (-EPIPE for the xrun and -ESTRPIPE for the suspended status,
2897 * others for general errors)
2898 * \retval 0 timeout occurred
2899 * \retval 1 PCM stream is ready for I/O
2901 * The function is thread-safe when built with the proper option.
2903 int snd_pcm_wait(snd_pcm_t *pcm, int timeout)
2907 __snd_pcm_lock(pcm->fast_op_arg); /* forced lock */
2908 err = __snd_pcm_wait_in_lock(pcm, timeout);
2909 __snd_pcm_unlock(pcm->fast_op_arg);
2914 /* locked version */
2915 int __snd_pcm_wait_in_lock(snd_pcm_t *pcm, int timeout)
2919 /* NOTE: avail_min check can be skipped during draining */
2920 if (__snd_pcm_state(pcm) != SND_PCM_STATE_DRAINING &&
2921 !snd_pcm_may_wait_for_avail_min(pcm, snd_pcm_mmap_avail(pcm))) {
2922 /* check more precisely */
2923 err = pcm_state_to_error(__snd_pcm_state(pcm));
2924 return err < 0 ? err : 1;
2926 return snd_pcm_wait_nocheck(pcm, timeout);
2929 static int __snd_pcm_wait_io_timeout(snd_pcm_t *pcm)
2933 /* period size is the time boundary */
2934 timeout = (pcm->period_size * 1000ULL) / pcm->rate;
2935 /* should not happen */
2938 /* add extra time of 200 milliseconds */
2943 static int __snd_pcm_wait_drain_timeout(snd_pcm_t *pcm)
2947 /* for capture, there's no reason to wait, just one iteration */
2948 if (snd_pcm_stream(pcm) == SND_PCM_STREAM_CAPTURE)
2950 /* result is in milliseconds */
2951 timeout = (snd_pcm_mmap_playback_delay(pcm) * 1000LL) / pcm->rate;
2952 /* should not happen */
2955 /* add extra time of 200 milliseconds */
2961 * like snd_pcm_wait() but doesn't check mmap_avail before calling poll()
2963 * used in drain code in some plugins
2965 * This function is called inside pcm lock.
2967 int snd_pcm_wait_nocheck(snd_pcm_t *pcm, int timeout)
2970 unsigned short revents = 0;
2971 int npfds, err, err_poll;
2973 npfds = __snd_pcm_poll_descriptors_count(pcm);
2974 if (npfds <= 0 || npfds >= 16) {
2975 snd_error(PCM, "Invalid poll_fds %d", npfds);
2978 pfd = alloca(sizeof(*pfd) * npfds);
2979 err = __snd_pcm_poll_descriptors(pcm, pfd, npfds);
2983 snd_check(PCM, "invalid poll descriptors %d", err);
2986 if (timeout == SND_PCM_WAIT_IO)
2987 timeout = __snd_pcm_wait_io_timeout(pcm);
2988 else if (timeout == SND_PCM_WAIT_DRAIN)
2989 timeout = __snd_pcm_wait_drain_timeout(pcm);
2990 else if (timeout < -1)
2991 snd_check(PCM, "invalid snd_pcm_wait timeout argument %d", timeout);
2993 __snd_pcm_unlock(pcm->fast_op_arg);
2994 err_poll = poll(pfd, npfds, timeout);
2995 __snd_pcm_lock(pcm->fast_op_arg);
2997 if (errno == EINTR && !PCMINABORT(pcm) && !(pcm->mode & SND_PCM_EINTR))
3003 err = __snd_pcm_poll_revents(pcm, pfd, npfds, &revents);
3006 if (revents & (POLLERR | POLLNVAL)) {
3007 /* check more precisely */
3008 err = pcm_state_to_error(__snd_pcm_state(pcm));
3009 return err < 0 ? err : -EIO;
3011 } while (!(revents & (POLLIN | POLLOUT)));
3012 #if 0 /* very useful code to test poll related problems */
3014 snd_pcm_sframes_t avail_update;
3015 __snd_pcm_hwsync(pcm);
3016 avail_update = __snd_pcm_avail_update(pcm);
3017 if (avail_update < (snd_pcm_sframes_t)pcm->avail_min) {
3018 printf("*** snd_pcm_wait() FATAL ERROR!!!\n");
3019 printf("avail_min = %li, avail_update = %li\n", pcm->avail_min, avail_update);
3023 return err_poll > 0 ? 1 : 0;
3028 * \brief Return number of frames ready to be read (capture) / written (playback)
3029 * \param pcm PCM handle
3030 * \return a positive number of frames ready otherwise a negative
3033 * On capture does all the actions needed to transport to application
3034 * level all the ready frames across underlying layers.
3036 * The position is not synced with hardware (driver) position in the sound
3037 * ring buffer in this function. This function is a light version of
3038 * #snd_pcm_avail() .
3040 * Using this function is ideal after poll() or select() when audio
3041 * file descriptor made the event and when application expects just period
3044 * Also this function might be called after #snd_pcm_delay() or
3045 * #snd_pcm_hwsync() functions to move private ring buffer pointers
3046 * in alsa-lib (the internal plugin chain).
3048 * The function is thread-safe when built with the proper option.
3050 snd_pcm_sframes_t snd_pcm_avail_update(snd_pcm_t *pcm)
3052 snd_pcm_sframes_t result;
3054 snd_pcm_lock(pcm->fast_op_arg);
3055 result = __snd_pcm_avail_update(pcm);
3056 snd_pcm_unlock(pcm->fast_op_arg);
3061 * \brief Return number of frames ready to be read (capture) / written (playback)
3062 * \param pcm PCM handle
3063 * \return a positive number of frames ready otherwise a negative
3066 * On capture does all the actions needed to transport to application
3067 * level all the ready frames across underlying layers.
3069 * The position is synced with hardware (driver) position in the sound
3070 * ring buffer in this functions.
3072 * The function is thread-safe when built with the proper option.
3074 snd_pcm_sframes_t snd_pcm_avail(snd_pcm_t *pcm)
3077 snd_pcm_sframes_t result;
3080 if (CHECK_SANITY(! pcm->setup)) {
3081 snd_check(PCM, "PCM not set up");
3084 snd_pcm_lock(pcm->fast_op_arg);
3085 err = __snd_pcm_hwsync(pcm);
3089 result = __snd_pcm_avail_update(pcm);
3090 snd_pcm_unlock(pcm->fast_op_arg);
3095 * \brief Combine snd_pcm_avail and snd_pcm_delay functions
3096 * \param pcm PCM handle
3097 * \param availp Number of available frames in the ring buffer
3098 * \param delayp Total I/O latency in frames
3099 * \return zero on success otherwise a negative error code
3101 * The avail and delay values returned are in sync.
3103 * The function is thread-safe when built with the proper option.
3105 int snd_pcm_avail_delay(snd_pcm_t *pcm,
3106 snd_pcm_sframes_t *availp,
3107 snd_pcm_sframes_t *delayp)
3109 snd_pcm_sframes_t sf;
3112 assert(pcm && availp && delayp);
3113 if (CHECK_SANITY(! pcm->setup)) {
3114 snd_check(PCM, "PCM not set up");
3117 snd_pcm_lock(pcm->fast_op_arg);
3118 err = __snd_pcm_hwsync(pcm);
3123 * Delay value is relative to avail, so we have to
3124 * loop to avoid reporting stale delay data.
3127 sf = __snd_pcm_avail_update(pcm);
3129 err = sf < INT_MIN ? -EOVERFLOW : (int)sf;
3132 if (ok && sf == *availp)
3135 err = __snd_pcm_delay(pcm, delayp);
3142 snd_pcm_unlock(pcm->fast_op_arg);
3147 * \brief Silence an area
3148 * \param dst_area area specification
3149 * \param dst_offset offset in frames inside area
3150 * \param samples samples to silence
3151 * \param format PCM sample format
3152 * \return 0 on success otherwise a negative error code
3154 int snd_pcm_area_silence(const snd_pcm_channel_area_t *dst_area, snd_pcm_uframes_t dst_offset,
3155 unsigned int samples, snd_pcm_format_t format)
3157 /* FIXME: sub byte resolution and odd dst_offset */
3159 unsigned int dst_step;
3162 if (!dst_area->addr)
3164 dst = snd_pcm_channel_area_addr(dst_area, dst_offset);
3165 width = snd_pcm_format_physical_width(format);
3166 silence = snd_pcm_format_silence_64(format);
3168 * Iterate copying silent sample for sample data aligned to 64 bit.
3169 * This is a fast path.
3171 if (dst_area->step == (unsigned int) width &&
3173 ((intptr_t)dst & 7) == 0) {
3174 unsigned int dwords = samples * width / 64;
3175 uint64_t *dstp = (uint64_t *)dst;
3176 samples -= dwords * 64 / width;
3177 while (dwords-- > 0)
3183 dst_step = dst_area->step / 8;
3186 uint8_t s0 = silence & 0xf0;
3187 uint8_t s1 = silence & 0x0f;
3188 int dstbit = dst_area->first % 8;
3189 int dstbit_step = dst_area->step % 8;
3190 while (samples-- > 0) {
3199 dstbit += dstbit_step;
3208 uint8_t sil = silence;
3209 while (samples-- > 0) {
3216 uint16_t sil = silence;
3217 while (samples-- > 0) {
3218 *(uint16_t*)dst = sil;
3224 while (samples-- > 0) {
3225 #ifdef SNDRV_LITTLE_ENDIAN
3226 *(dst + 0) = silence >> 0;
3227 *(dst + 1) = silence >> 8;
3228 *(dst + 2) = silence >> 16;
3230 *(dst + 2) = silence >> 0;
3231 *(dst + 1) = silence >> 8;
3232 *(dst + 0) = silence >> 16;
3239 uint32_t sil = silence;
3240 while (samples-- > 0) {
3241 *(uint32_t*)dst = sil;
3247 while (samples-- > 0) {
3248 *(uint64_t*)dst = silence;
3254 snd_check(PCM, "invalid format width %d", width);
3261 * \brief Silence one or more areas
3262 * \param dst_areas areas specification (one for each channel)
3263 * \param dst_offset offset in frames inside area
3264 * \param channels channels count
3265 * \param frames frames to silence
3266 * \param format PCM sample format
3267 * \return 0 on success otherwise a negative error code
3269 int snd_pcm_areas_silence(const snd_pcm_channel_area_t *dst_areas, snd_pcm_uframes_t dst_offset,
3270 unsigned int channels, snd_pcm_uframes_t frames, snd_pcm_format_t format)
3272 int width = snd_pcm_format_physical_width(format);
3273 while (channels > 0) {
3274 void *addr = dst_areas->addr;
3275 unsigned int step = dst_areas->step;
3276 const snd_pcm_channel_area_t *begin = dst_areas;
3277 int channels1 = channels;
3278 unsigned int chns = 0;
3284 if (channels1 == 0 ||
3285 dst_areas->addr != addr ||
3286 dst_areas->step != step ||
3287 dst_areas->first != dst_areas[-1].first + width)
3290 if (chns > 1 && chns * width == step) {
3291 /* Collapse the areas */
3292 snd_pcm_channel_area_t d;
3293 d.addr = begin->addr;
3294 d.first = begin->first;
3296 err = snd_pcm_area_silence(&d, dst_offset * chns, frames * chns, format);
3299 err = snd_pcm_area_silence(begin, dst_offset, frames, format);
3300 dst_areas = begin + 1;
3311 * \brief Copy an area
3312 * \param dst_area destination area specification
3313 * \param dst_offset offset in frames inside destination area
3314 * \param src_area source area specification
3315 * \param src_offset offset in frames inside source area
3316 * \param samples samples to copy
3317 * \param format PCM sample format
3318 * \return 0 on success otherwise a negative error code
3320 int snd_pcm_area_copy(const snd_pcm_channel_area_t *dst_area, snd_pcm_uframes_t dst_offset,
3321 const snd_pcm_channel_area_t *src_area, snd_pcm_uframes_t src_offset,
3322 unsigned int samples, snd_pcm_format_t format)
3324 /* FIXME: sub byte resolution and odd dst_offset */
3328 int src_step, dst_step;
3329 if (dst_area == src_area && dst_offset == src_offset)
3331 if (!src_area->addr)
3332 return snd_pcm_area_silence(dst_area, dst_offset, samples, format);
3333 src = snd_pcm_channel_area_addr(src_area, src_offset);
3334 if (!dst_area->addr)
3336 dst = snd_pcm_channel_area_addr(dst_area, dst_offset);
3337 width = snd_pcm_format_physical_width(format);
3340 if (src_area->step == (unsigned int) width &&
3341 dst_area->step == (unsigned int) width) {
3342 size_t bytes = samples * width / 8;
3343 samples -= bytes * 8 / width;
3344 assert(src < dst || src >= dst + bytes);
3345 assert(dst < src || dst >= src + bytes);
3346 memcpy(dst, src, bytes);
3350 src_step = src_area->step / 8;
3351 dst_step = dst_area->step / 8;
3354 int srcbit = src_area->first % 8;
3355 int srcbit_step = src_area->step % 8;
3356 int dstbit = dst_area->first % 8;
3357 int dstbit_step = dst_area->step % 8;
3358 while (samples-- > 0) {
3359 unsigned char srcval;
3361 srcval = *src & 0x0f;
3363 srcval = *src & 0xf0;
3370 srcbit += srcbit_step;
3376 dstbit += dstbit_step;
3385 while (samples-- > 0) {
3393 while (samples-- > 0) {
3394 *(uint16_t*)dst = *(const uint16_t*)src;
3401 while (samples-- > 0) {
3402 *(dst + 0) = *(src + 0);
3403 *(dst + 1) = *(src + 1);
3404 *(dst + 2) = *(src + 2);
3410 while (samples-- > 0) {
3411 *(uint32_t*)dst = *(const uint32_t*)src;
3418 while (samples-- > 0) {
3419 *(uint64_t*)dst = *(const uint64_t*)src;
3426 snd_check(PCM, "invalid format width %d", width);
3433 * \brief Copy one or more areas
3434 * \param dst_areas destination areas specification (one for each channel)
3435 * \param dst_offset offset in frames inside destination area
3436 * \param src_areas source areas specification (one for each channel)
3437 * \param src_offset offset in frames inside source area
3438 * \param channels channels count
3439 * \param frames frames to copy
3440 * \param format PCM sample format
3441 * \return 0 on success otherwise a negative error code
3443 int snd_pcm_areas_copy(const snd_pcm_channel_area_t *dst_areas, snd_pcm_uframes_t dst_offset,
3444 const snd_pcm_channel_area_t *src_areas, snd_pcm_uframes_t src_offset,
3445 unsigned int channels, snd_pcm_uframes_t frames, snd_pcm_format_t format)
3447 int width = snd_pcm_format_physical_width(format);
3451 snd_check(PCM, "invalid channels %d", channels);
3455 snd_check(PCM, "invalid frames %ld", frames);
3458 while (channels > 0) {
3459 unsigned int step = src_areas->step;
3460 void *src_addr = src_areas->addr;
3461 const snd_pcm_channel_area_t *src_start = src_areas;
3462 void *dst_addr = dst_areas->addr;
3463 const snd_pcm_channel_area_t *dst_start = dst_areas;
3464 int channels1 = channels;
3465 unsigned int chns = 0;
3466 while (dst_areas->step == step) {
3471 if (channels1 == 0 ||
3472 src_areas->step != step ||
3473 src_areas->addr != src_addr ||
3474 dst_areas->addr != dst_addr ||
3475 src_areas->first != src_areas[-1].first + width ||
3476 dst_areas->first != dst_areas[-1].first + width)
3479 if (chns > 1 && chns * width == step) {
3480 if (src_offset != dst_offset ||
3481 src_start->addr != dst_start->addr ||
3482 src_start->first != dst_start->first) {
3483 /* Collapse the areas */
3484 snd_pcm_channel_area_t s, d;
3485 s.addr = src_start->addr;
3486 s.first = src_start->first;
3488 d.addr = dst_start->addr;
3489 d.first = dst_start->first;
3491 snd_pcm_area_copy(&d, dst_offset * chns,
3492 &s, src_offset * chns,
3493 frames * chns, format);
3497 snd_pcm_area_copy(dst_start, dst_offset,
3498 src_start, src_offset,
3500 src_areas = src_start + 1;
3501 dst_areas = dst_start + 1;
3509 * \brief Copy one or more areas
3510 * \param dst_channels destination areas specification (one for each channel)
3511 * \param dst_offset offset in frames inside destination area
3512 * \param dst_size size in frames of the destination buffer
3513 * \param src_channels source areas specification (one for each channel)
3514 * \param src_offset offset in frames inside source area
3515 * \param src_size size in frames of the source buffer
3516 * \param channels channels count
3517 * \param frames frames to copy
3518 * \param format PCM sample format
3519 * \return 0 on success otherwise a negative error code
3521 int snd_pcm_areas_copy_wrap(const snd_pcm_channel_area_t *dst_channels,
3522 snd_pcm_uframes_t dst_offset,
3523 const snd_pcm_uframes_t dst_size,
3524 const snd_pcm_channel_area_t *src_channels,
3525 snd_pcm_uframes_t src_offset,
3526 const snd_pcm_uframes_t src_size,
3527 const unsigned int channels,
3528 snd_pcm_uframes_t frames,
3529 const snd_pcm_format_t format)
3531 while (frames > 0) {
3533 snd_pcm_uframes_t xfer = frames;
3534 /* do not write above the destination buffer */
3535 if ((dst_offset + xfer) > dst_size)
3536 xfer = dst_size - dst_offset;
3537 /* do not read from above the source buffer */
3538 if ((src_offset + xfer) > src_size)
3539 xfer = src_size - src_offset;
3540 err = snd_pcm_areas_copy(dst_channels, dst_offset, src_channels,
3541 src_offset, channels, xfer, format);
3546 if (dst_offset >= dst_size)
3549 if (src_offset >= src_size)
3557 static void dump_one_param(snd_pcm_hw_params_t *params, unsigned int k, snd_output_t *out)
3559 snd_output_printf(out, "%s: ", snd_pcm_hw_param_name(k));
3560 snd_pcm_hw_param_dump(params, k, out);
3561 snd_output_putc(out, '\n');
3565 * \brief Dump a PCM hardware configuration space
3566 * \param params Configuration space
3567 * \param out Output handle
3568 * \return 0 on success otherwise a negative error code
3570 int snd_pcm_hw_params_dump(snd_pcm_hw_params_t *params, snd_output_t *out)
3573 for (k = SND_PCM_HW_PARAM_FIRST_MASK; k <= SND_PCM_HW_PARAM_LAST_MASK; k++)
3574 dump_one_param(params, k, out);
3575 for (k = SND_PCM_HW_PARAM_FIRST_INTERVAL; k <= SND_PCM_HW_PARAM_LAST_INTERVAL; k++)
3576 dump_one_param(params, k, out);
3581 * \brief Check if hardware supports sample-resolution mmap for given configuration
3582 * \param params Configuration space
3583 * \retval 0 Hardware doesn't support sample-resolution mmap
3584 * \retval 1 Hardware supports sample-resolution mmap
3586 * This function should only be called when the configuration space
3587 * contains a single configuration. Call #snd_pcm_hw_params to choose
3588 * a single configuration from the configuration space.
3590 int snd_pcm_hw_params_can_mmap_sample_resolution(const snd_pcm_hw_params_t *params)
3593 if (CHECK_SANITY(params->info == ~0U)) {
3594 snd_check(PCM, "invalid PCM info field");
3595 return 0; /* FIXME: should be a negative error? */
3597 return !!(params->info & SNDRV_PCM_INFO_MMAP_VALID);
3601 * \brief Check if hardware does double buffering for start/stop for given configuration
3602 * \param params Configuration space
3603 * \retval 0 Hardware doesn't do double buffering for start/stop
3604 * \retval 1 Hardware does double buffering for start/stop
3606 * This function should only be called when the configuration space
3607 * contains a single configuration. Call #snd_pcm_hw_params to choose
3608 * a single configuration from the configuration space.
3610 int snd_pcm_hw_params_is_double(const snd_pcm_hw_params_t *params)
3613 if (CHECK_SANITY(params->info == ~0U)) {
3614 snd_check(PCM, "invalid PCM info field");
3615 return 0; /* FIXME: should be a negative error? */
3617 return !!(params->info & SNDRV_PCM_INFO_DOUBLE);
3621 * \brief Check if hardware does double buffering for data transfers for given configuration
3622 * \param params Configuration space
3623 * \retval 0 Hardware doesn't do double buffering for data transfers
3624 * \retval 1 Hardware does double buffering for data transfers
3626 * This function should only be called when the configuration space
3627 * contains a single configuration. Call #snd_pcm_hw_params to choose
3628 * a single configuration from the configuration space.
3630 int snd_pcm_hw_params_is_batch(const snd_pcm_hw_params_t *params)
3633 if (CHECK_SANITY(params->info == ~0U)) {
3634 snd_check(PCM, "invalid PCM info field");
3635 return 0; /* FIXME: should be a negative error? */
3637 return !!(params->info & SNDRV_PCM_INFO_BATCH);
3641 * \brief Check if hardware does block transfers for samples for given configuration
3642 * \param params Configuration space
3643 * \retval 0 Hardware doesn't block transfers
3644 * \retval 1 Hardware does block transfers
3646 * This function should only be called when the configuration space
3647 * contains a single configuration. Call #snd_pcm_hw_params to choose
3648 * a single configuration from the configuration space.
3650 int snd_pcm_hw_params_is_block_transfer(const snd_pcm_hw_params_t *params)
3653 if (CHECK_SANITY(params->info == ~0U)) {
3654 snd_check(PCM, "invalid PCM info field");
3655 return 0; /* FIXME: should be a negative error? */
3657 return !!(params->info & SNDRV_PCM_INFO_BLOCK_TRANSFER);
3661 * \brief Check if timestamps are monotonic for given configuration
3662 * \param params Configuration space
3663 * \retval 0 Device doesn't do monotomic timestamps
3664 * \retval 1 Device does monotonic timestamps
3666 * This function should only be called when the configuration space
3667 * contains a single configuration. Call #snd_pcm_hw_params to choose
3668 * a single configuration from the configuration space.
3670 int snd_pcm_hw_params_is_monotonic(const snd_pcm_hw_params_t *params)
3673 if (CHECK_SANITY(params->info == ~0U)) {
3674 snd_check(PCM, "invalid PCM info field");
3675 return 0; /* FIXME: should be a negative error? */
3677 return !!(params->info & SND_PCM_INFO_MONOTONIC);
3681 * \brief Check if hardware supports overrange detection
3682 * \param params Configuration space
3683 * \retval 0 Hardware doesn't support overrange detection
3684 * \retval 1 Hardware supports overrange detection
3686 * This function should only be called when the configuration space
3687 * contains a single configuration. Call #snd_pcm_hw_params to choose
3688 * a single configuration from the configuration space.
3690 int snd_pcm_hw_params_can_overrange(const snd_pcm_hw_params_t *params)
3693 if (CHECK_SANITY(params->info == ~0U)) {
3694 snd_check(PCM, "invalid PCM info field");
3695 return 0; /* FIXME: should be a negative error? */
3697 return !!(params->info & SNDRV_PCM_INFO_OVERRANGE);
3701 * \brief Check if hardware supports pause
3702 * \param params Configuration space
3703 * \retval 0 Hardware doesn't support pause
3704 * \retval 1 Hardware supports pause
3706 * This function should only be called when the configuration space
3707 * contains a single configuration. Call #snd_pcm_hw_params to choose
3708 * a single configuration from the configuration space.
3710 int snd_pcm_hw_params_can_pause(const snd_pcm_hw_params_t *params)
3713 if (CHECK_SANITY(params->info == ~0U)) {
3714 snd_check(PCM, "invalid PCM info field");
3715 return 0; /* FIXME: should be a negative error? */
3717 return !!(params->info & SNDRV_PCM_INFO_PAUSE);
3721 * \brief Check if hardware supports resume
3722 * \param params Configuration space
3723 * \retval 0 Hardware doesn't support resume
3724 * \retval 1 Hardware supports resume
3726 * This function should only be called when the configuration space
3727 * contains a single configuration. Call #snd_pcm_hw_params to choose
3728 * a single configuration from the configuration space.
3730 int snd_pcm_hw_params_can_resume(const snd_pcm_hw_params_t *params)
3733 if (CHECK_SANITY(params->info == ~0U)) {
3734 snd_check(PCM, "invalid PCM info field");
3735 return 0; /* FIXME: should be a negative error? */
3737 return !!(params->info & SNDRV_PCM_INFO_RESUME);
3741 * \brief Check if hardware does half-duplex only
3742 * \param params Configuration space
3743 * \retval 0 Hardware doesn't do half-duplex
3744 * \retval 1 Hardware does half-duplex
3746 * This function should only be called when the configuration space
3747 * contains a single configuration. Call #snd_pcm_hw_params to choose
3748 * a single configuration from the configuration space.
3750 int snd_pcm_hw_params_is_half_duplex(const snd_pcm_hw_params_t *params)
3753 if (CHECK_SANITY(params->info == ~0U)) {
3754 snd_check(PCM, "invalid PCM info field");
3755 return 0; /* FIXME: should be a negative error? */
3757 return !!(params->info & SNDRV_PCM_INFO_HALF_DUPLEX);
3761 * \brief Check if hardware does joint-duplex (playback and capture are somewhat correlated)
3762 * \param params Configuration space
3763 * \retval 0 Hardware doesn't do joint-duplex
3764 * \retval 1 Hardware does joint-duplex
3766 * This function should only be called when the configuration space
3767 * contains a single configuration. Call #snd_pcm_hw_params to choose
3768 * a single configuration from the configuration space.
3770 int snd_pcm_hw_params_is_joint_duplex(const snd_pcm_hw_params_t *params)
3773 if (CHECK_SANITY(params->info == ~0U)) {
3774 snd_check(PCM, "invalid PCM info field");
3775 return 0; /* FIXME: should be a negative error? */
3777 return !!(params->info & SNDRV_PCM_INFO_JOINT_DUPLEX);
3781 * \brief Check if hardware supports synchronized start with sample resolution
3782 * \param params Configuration space
3783 * \retval 0 Hardware doesn't support synchronized start
3784 * \retval 1 Hardware supports synchronized start
3786 * This function should only be called when the configuration space
3787 * contains a single configuration. Call #snd_pcm_hw_params to choose
3788 * a single configuration from the configuration space.
3790 int snd_pcm_hw_params_can_sync_start(const snd_pcm_hw_params_t *params)
3793 if (CHECK_SANITY(params->info == ~0U)) {
3794 snd_check(PCM, "invalid PCM info field");
3795 return 0; /* FIXME: should be a negative error? */
3797 return !!(params->info & SNDRV_PCM_INFO_SYNC_START);
3801 * \brief Check if hardware can disable period wakeups
3802 * \param params Configuration space
3803 * \retval 0 Hardware cannot disable period wakeups
3804 * \retval 1 Hardware can disable period wakeups
3806 int snd_pcm_hw_params_can_disable_period_wakeup(const snd_pcm_hw_params_t *params)
3809 if (CHECK_SANITY(params->info == ~0U)) {
3810 snd_check(PCM, "invalid PCM info field");
3811 return 0; /* FIXME: should be a negative error? */
3813 return !!(params->info & SNDRV_PCM_INFO_NO_PERIOD_WAKEUP);
3817 * \brief Check if hardware is capable of perfect drain
3818 * \param params Configuration space
3819 * \retval 0 Hardware doesn't do perfect drain
3820 * \retval 1 Hardware does perfect drain
3822 * This function should only be called when the configuration space
3823 * contains a single configuration. Call #snd_pcm_hw_params to choose
3824 * a single configuration from the configuration space.
3826 * Perfect drain means that the hardware does not use samples
3827 * beyond the stream application pointer.
3829 int snd_pcm_hw_params_is_perfect_drain(const snd_pcm_hw_params_t *params)
3832 if (CHECK_SANITY(params->info == ~0U)) {
3833 snd_check(PCM, "invalid PCM info field");
3834 return 0; /* FIXME: should be a negative error? */
3836 return !!(params->info & SNDRV_PCM_INFO_PERFECT_DRAIN);
3840 * \brief Check if hardware supports audio wallclock timestamps
3841 * \param params Configuration space
3842 * \retval 0 Hardware doesn't support audio wallclock timestamps
3843 * \retval 1 Hardware supports audio wallclock timestamps
3845 * This function should only be called when the configuration space
3846 * contains a single configuration. Call #snd_pcm_hw_params to choose
3847 * a single configuration from the configuration space.
3849 int snd_pcm_hw_params_supports_audio_wallclock_ts(const snd_pcm_hw_params_t *params)
3852 return snd_pcm_hw_params_supports_audio_ts_type(params,
3853 SNDRV_PCM_AUDIO_TSTAMP_TYPE_COMPAT);
3857 * \brief Check if hardware supports type of audio timestamps
3858 * \param params Configuration space
3859 * \param type Audio timestamp type
3860 * \retval 0 Hardware doesn't support type of audio timestamps
3861 * \retval 1 Hardware supports type of audio timestamps
3863 * This function should only be called when the configuration space
3864 * contains a single configuration. Call #snd_pcm_hw_params to choose
3865 * a single configuration from the configuration space.
3867 int snd_pcm_hw_params_supports_audio_ts_type(const snd_pcm_hw_params_t *params, int type)
3870 if (CHECK_SANITY(params->info == ~0U)) {
3871 snd_check(PCM, "invalid PCM info field");
3872 return 0; /* FIXME: should be a negative error? */
3875 case SNDRV_PCM_AUDIO_TSTAMP_TYPE_COMPAT:
3876 return !!(params->info & SNDRV_PCM_INFO_HAS_WALL_CLOCK); /* deprecated */
3877 case SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT:
3878 return 1; /* always supported, based on hw_ptr */
3879 case SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK:
3880 return !!(params->info & SNDRV_PCM_INFO_HAS_LINK_ATIME);
3881 case SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_ABSOLUTE:
3882 return !!(params->info & SNDRV_PCM_INFO_HAS_LINK_ABSOLUTE_ATIME);
3883 case SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_ESTIMATED:
3884 return !!(params->info & SNDRV_PCM_INFO_HAS_LINK_ESTIMATED_ATIME);
3885 case SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_SYNCHRONIZED:
3886 return !!(params->info & SNDRV_PCM_INFO_HAS_LINK_SYNCHRONIZED_ATIME);
3893 * \brief Get rate exact info from a configuration space
3894 * \param params Configuration space
3895 * \param rate_num Pointer to returned rate numerator
3896 * \param rate_den Pointer to returned rate denominator
3897 * \return 0 otherwise a negative error code if the info is not available
3899 * This function should only be called when the configuration space
3900 * contains a single configuration. Call #snd_pcm_hw_params to choose
3901 * a single configuration from the configuration space.
3903 int snd_pcm_hw_params_get_rate_numden(const snd_pcm_hw_params_t *params,
3904 unsigned int *rate_num, unsigned int *rate_den)
3907 if (CHECK_SANITY(params->rate_den == 0)) {
3908 snd_check(PCM, "invalid rate_den value");
3911 *rate_num = params->rate_num;
3912 *rate_den = params->rate_den;
3917 * \brief Get sample resolution info from a configuration space
3918 * \param params Configuration space
3919 * \return sample resolution (in bits) otherwise a negative error code if the info is not available
3921 * For linear formats, this function returns sample resolution -
3922 * used bits starting from the first usable significant bit defined by
3923 * the format (e.g. bit 31 for S32_LE format or bit 23 for S24_LE format -
3924 * starting from bit zero). Application may use full sample bit range defined
3925 * by the format, but additional bits (outside this sample resolution) are
3926 * stripped (not processed).
3928 * For non-linear formats, this value may have a special meaning which may be defined in future.
3930 * This function should only be called when the configuration space
3931 * contains a single configuration. Call #snd_pcm_hw_params to choose
3932 * a single configuration from the configuration space.
3934 int snd_pcm_hw_params_get_sbits(const snd_pcm_hw_params_t *params)
3937 if (CHECK_SANITY(params->msbits == 0)) {
3938 snd_check(PCM, "invalid msbits value");
3941 return params->msbits;
3945 * \brief Get hardware FIFO size info from a configuration space
3946 * \param params Configuration space
3947 * \return FIFO size in frames otherwise a negative error code if the info is not available
3949 * This function should only be called when the configuration space
3950 * contains a single configuration. Call #snd_pcm_hw_params to choose
3951 * a single configuration from the configuration space.
3953 int snd_pcm_hw_params_get_fifo_size(const snd_pcm_hw_params_t *params)
3956 if (CHECK_SANITY(params->info == ~0U)) {
3957 snd_check(PCM, "invalid PCM info field");
3960 return params->fifo_size;
3964 * \brief Get hardware synchronization ID from a PCM info container
3965 * \param params Configuration space
3966 * \return 16-byte synchronization ID (use #SND_PCM_HW_PARAMS_SYNC_SIZE)
3968 * This synchronization ID determines the similar clocks for the
3969 * PCM stream between multiple devices (including different cards).
3970 * "All zeros" means "not set". The contents of the ID can be used
3971 * only for a comparison with the contents of another ID returned
3972 * from this function. Applications should not do a comparison with
3973 * hard-coded values, because the implementation generating such
3974 * synchronization IDs may be changed in future.
3976 const unsigned char *snd_pcm_hw_params_get_sync(const snd_pcm_hw_params_t *params)
3979 return params->sync;
3983 * \brief Fill params with a full configuration space for a PCM
3984 * \param pcm PCM handle
3985 * \param params Configuration space
3987 * The configuration space will be filled with all possible ranges
3988 * for the PCM device.
3990 * Note that the configuration space may be constrained by the
3991 * currently installed configuration on the PCM device. To remove
3992 * any constrains, free the configuration with #snd_pcm_hw_free
3995 int snd_pcm_hw_params_any(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
3997 _snd_pcm_hw_params_any(params);
3998 return snd_pcm_hw_refine(pcm, params);
4002 * \brief get size of #snd_pcm_access_mask_t
4003 * \return size in bytes
4005 size_t snd_pcm_access_mask_sizeof()
4007 return sizeof(snd_pcm_access_mask_t);
4011 * \brief allocate an empty #snd_pcm_access_mask_t using standard malloc
4012 * \param ptr returned pointer
4013 * \return 0 on success otherwise negative error code
4015 int snd_pcm_access_mask_malloc(snd_pcm_access_mask_t **ptr)
4018 *ptr = calloc(1, sizeof(snd_pcm_access_mask_t));
4025 * \brief frees a previously allocated #snd_pcm_access_mask_t
4026 * \param obj pointer to object to free
4028 void snd_pcm_access_mask_free(snd_pcm_access_mask_t *obj)
4034 * \brief copy one #snd_pcm_access_mask_t to another
4035 * \param dst pointer to destination
4036 * \param src pointer to source
4038 void snd_pcm_access_mask_copy(snd_pcm_access_mask_t *dst, const snd_pcm_access_mask_t *src)
4045 * \brief reset all bits in a #snd_pcm_access_mask_t
4046 * \param mask pointer to mask
4048 void snd_pcm_access_mask_none(snd_pcm_access_mask_t *mask)
4050 snd_mask_none((snd_mask_t *) mask);
4054 * \brief set all bits in a #snd_pcm_access_mask_t
4055 * \param mask pointer to mask
4057 void snd_pcm_access_mask_any(snd_pcm_access_mask_t *mask)
4059 snd_mask_any((snd_mask_t *) mask);
4063 * \brief test the presence of an access type in a #snd_pcm_access_mask_t
4064 * \param mask pointer to mask
4065 * \param val access type
4067 int snd_pcm_access_mask_test(const snd_pcm_access_mask_t *mask, snd_pcm_access_t val)
4069 return snd_mask_test((const snd_mask_t *) mask, (unsigned long) val);
4073 * \brief test, if given a #snd_pcm_access_mask_t is empty
4074 * \param mask pointer to mask
4075 * \retval 0 not empty
4078 int snd_pcm_access_mask_empty(const snd_pcm_access_mask_t *mask)
4080 return snd_mask_empty((const snd_mask_t *) mask);
4084 * \brief make an access type present in a #snd_pcm_access_mask_t
4085 * \param mask pointer to mask
4086 * \param val access type
4088 void snd_pcm_access_mask_set(snd_pcm_access_mask_t *mask, snd_pcm_access_t val)
4090 snd_mask_set((snd_mask_t *) mask, (unsigned long) val);
4094 * \brief make an access type missing from a #snd_pcm_access_mask_t
4095 * \param mask pointer to mask
4096 * \param val access type
4098 void snd_pcm_access_mask_reset(snd_pcm_access_mask_t *mask, snd_pcm_access_t val)
4100 snd_mask_reset((snd_mask_t *) mask, (unsigned long) val);
4104 * \brief get size of #snd_pcm_format_mask_t
4105 * \return size in bytes
4107 size_t snd_pcm_format_mask_sizeof()
4109 return sizeof(snd_pcm_format_mask_t);
4113 * \brief allocate an empty #snd_pcm_format_mask_t using standard malloc
4114 * \param ptr returned pointer
4115 * \return 0 on success otherwise negative error code
4117 int snd_pcm_format_mask_malloc(snd_pcm_format_mask_t **ptr)
4120 *ptr = calloc(1, sizeof(snd_pcm_format_mask_t));
4127 * \brief frees a previously allocated #snd_pcm_format_mask_t
4128 * \param obj pointer to object to free
4130 void snd_pcm_format_mask_free(snd_pcm_format_mask_t *obj)
4136 * \brief copy one #snd_pcm_format_mask_t to another
4137 * \param dst pointer to destination
4138 * \param src pointer to source
4140 void snd_pcm_format_mask_copy(snd_pcm_format_mask_t *dst, const snd_pcm_format_mask_t *src)
4147 * \brief reset all bits in a #snd_pcm_format_mask_t
4148 * \param mask pointer to mask
4150 void snd_pcm_format_mask_none(snd_pcm_format_mask_t *mask)
4152 snd_mask_none((snd_mask_t *) mask);
4156 * \brief set all bits in a #snd_pcm_format_mask_t
4157 * \param mask pointer to mask
4159 void snd_pcm_format_mask_any(snd_pcm_format_mask_t *mask)
4161 snd_mask_any((snd_mask_t *) mask);
4165 * \brief test the presence of a format in a #snd_pcm_format_mask_t
4166 * \param mask pointer to mask
4169 int snd_pcm_format_mask_test(const snd_pcm_format_mask_t *mask, snd_pcm_format_t val)
4171 return snd_mask_test((const snd_mask_t *) mask, (unsigned long) val);
4175 * \brief test, if given a #snd_pcm_format_mask_t is empty
4176 * \param mask pointer to mask
4177 * \retval 0 not empty
4180 int snd_pcm_format_mask_empty(const snd_pcm_format_mask_t *mask)
4182 return snd_mask_empty((const snd_mask_t *) mask);
4186 * \brief make a format present in a #snd_pcm_format_mask_t
4187 * \param mask pointer to mask
4190 void snd_pcm_format_mask_set(snd_pcm_format_mask_t *mask, snd_pcm_format_t val)
4192 snd_mask_set((snd_mask_t *) mask, (unsigned long) val);
4196 * \brief make a format missing from a #snd_pcm_format_mask_t
4197 * \param mask pointer to mask
4200 void snd_pcm_format_mask_reset(snd_pcm_format_mask_t *mask, snd_pcm_format_t val)
4202 snd_mask_reset((snd_mask_t *) mask, (unsigned long) val);
4207 * \brief get size of #snd_pcm_subformat_mask_t
4208 * \return size in bytes
4210 size_t snd_pcm_subformat_mask_sizeof()
4212 return sizeof(snd_pcm_subformat_mask_t);
4216 * \brief allocate an empty #snd_pcm_subformat_mask_t using standard malloc
4217 * \param ptr returned pointer
4218 * \return 0 on success otherwise negative error code
4220 int snd_pcm_subformat_mask_malloc(snd_pcm_subformat_mask_t **ptr)
4223 *ptr = calloc(1, sizeof(snd_pcm_subformat_mask_t));
4230 * \brief frees a previously allocated #snd_pcm_subformat_mask_t
4231 * \param obj pointer to object to free
4233 void snd_pcm_subformat_mask_free(snd_pcm_subformat_mask_t *obj)
4239 * \brief copy one #snd_pcm_subformat_mask_t to another
4240 * \param dst pointer to destination
4241 * \param src pointer to source
4243 void snd_pcm_subformat_mask_copy(snd_pcm_subformat_mask_t *dst, const snd_pcm_subformat_mask_t *src)
4250 * \brief reset all bits in a #snd_pcm_subformat_mask_t
4251 * \param mask pointer to mask
4253 void snd_pcm_subformat_mask_none(snd_pcm_subformat_mask_t *mask)
4255 snd_mask_none((snd_mask_t *) mask);
4259 * \brief set all bits in a #snd_pcm_subformat_mask_t
4260 * \param mask pointer to mask
4262 void snd_pcm_subformat_mask_any(snd_pcm_subformat_mask_t *mask)
4264 snd_mask_any((snd_mask_t *) mask);
4268 * \brief test the presence of a subformat in a #snd_pcm_subformat_mask_t
4269 * \param mask pointer to mask
4270 * \param val subformat
4272 int snd_pcm_subformat_mask_test(const snd_pcm_subformat_mask_t *mask, snd_pcm_subformat_t val)
4274 return snd_mask_test((const snd_mask_t *) mask, (unsigned long) val);
4278 * \brief test, if given a #snd_pcm_subformat_mask_t is empty
4279 * \param mask pointer to mask
4280 * \retval 0 not empty
4283 int snd_pcm_subformat_mask_empty(const snd_pcm_subformat_mask_t *mask)
4285 return snd_mask_empty((const snd_mask_t *) mask);
4289 * \brief make a subformat present in a #snd_pcm_subformat_mask_t
4290 * \param mask pointer to mask
4291 * \param val subformat
4293 void snd_pcm_subformat_mask_set(snd_pcm_subformat_mask_t *mask, snd_pcm_subformat_t val)
4295 snd_mask_set((snd_mask_t *) mask, (unsigned long) val);
4299 * \brief make a subformat missing from a #snd_pcm_subformat_mask_t
4300 * \param mask pointer to mask
4301 * \param val subformat
4303 void snd_pcm_subformat_mask_reset(snd_pcm_subformat_mask_t *mask, snd_pcm_subformat_t val)
4305 snd_mask_reset((snd_mask_t *) mask, (unsigned long) val);
4310 * \brief get size of #snd_pcm_hw_params_t
4311 * \return size in bytes
4313 size_t snd_pcm_hw_params_sizeof()
4315 return sizeof(snd_pcm_hw_params_t);
4319 * \brief allocate an invalid #snd_pcm_hw_params_t using standard malloc
4320 * \param ptr returned pointer
4321 * \return 0 on success otherwise negative error code
4323 int snd_pcm_hw_params_malloc(snd_pcm_hw_params_t **ptr)
4326 *ptr = calloc(1, sizeof(snd_pcm_hw_params_t));
4333 * \brief frees a previously allocated #snd_pcm_hw_params_t
4334 * \param obj pointer to object to free
4336 void snd_pcm_hw_params_free(snd_pcm_hw_params_t *obj)
4342 * \brief copy one #snd_pcm_hw_params_t to another
4343 * \param dst pointer to destination
4344 * \param src pointer to source
4346 void snd_pcm_hw_params_copy(snd_pcm_hw_params_t *dst, const snd_pcm_hw_params_t *src)
4354 * \brief Extract access type from a configuration space
4355 * \param params Configuration space
4356 * \param access Returned value
4357 * \return access type otherwise a negative error code if the configuration space does not contain a single value
4360 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_access)(const snd_pcm_hw_params_t *params, snd_pcm_access_t *access)
4362 int snd_pcm_hw_params_get_access(const snd_pcm_hw_params_t *params, snd_pcm_access_t *access)
4366 int err = snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_ACCESS, &_val, NULL);
4373 * \brief Verify if an access type is available inside a configuration space for a PCM
4374 * \param pcm PCM handle
4375 * \param params Configuration space
4376 * \param access access type
4377 * \return 0 if available a negative error code otherwise
4379 int snd_pcm_hw_params_test_access(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t access)
4381 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_ACCESS, access, 0);
4385 * \brief Restrict a configuration space to contain only one access type
4386 * \param pcm PCM handle
4387 * \param params Configuration space
4388 * \param access access type
4389 * \return 0 otherwise a negative error code if configuration space would become empty
4391 int snd_pcm_hw_params_set_access(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t access)
4393 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_ACCESS, access, 0);
4397 * \brief Restrict a configuration space to contain only its first access type
4398 * \param pcm PCM handle
4399 * \param params Configuration space
4400 * \param access Returned first access type
4401 * \return 0 otherwise a negative error code
4404 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_access_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t *access)
4406 int snd_pcm_hw_params_set_access_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t *access)
4409 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_ACCESS, access, NULL);
4413 * \brief Restrict a configuration space to contain only its last access type
4414 * \param pcm PCM handle
4415 * \param params Configuration space
4416 * \param access Returned last access type
4417 * \return 0 otherwise a negative error code
4420 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_access_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t *access)
4422 int snd_pcm_hw_params_set_access_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t *access)
4425 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_ACCESS, access, NULL);
4429 * \brief Restrict a configuration space to contain only a set of access types
4430 * \param pcm PCM handle
4431 * \param params Configuration space
4432 * \param mask Access mask
4433 * \return 0 otherwise a negative error code
4435 int snd_pcm_hw_params_set_access_mask(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_mask_t *mask)
4437 return snd_pcm_hw_param_set_mask(pcm, params, SND_TRY, SND_PCM_HW_PARAM_ACCESS, (snd_mask_t *) mask);
4441 * \brief Get access mask from a configuration space
4442 * \param params Configuration space
4443 * \param mask Returned Access mask
4445 int snd_pcm_hw_params_get_access_mask(snd_pcm_hw_params_t *params, snd_pcm_access_mask_t *mask)
4447 if (params == NULL || mask == NULL)
4449 snd_pcm_access_mask_copy(mask, snd_pcm_hw_param_get_mask(params, SND_PCM_HW_PARAM_ACCESS));
4455 * \brief Extract format from a configuration space
4456 * \param params Configuration space
4457 * \param format returned format
4458 * \return format otherwise a negative error code if the configuration space does not contain a single value
4461 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_format)(const snd_pcm_hw_params_t *params, snd_pcm_format_t *format)
4463 int snd_pcm_hw_params_get_format(const snd_pcm_hw_params_t *params, snd_pcm_format_t *format)
4466 return snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_FORMAT, (unsigned int *)format, NULL);
4470 * \brief Verify if a format is available inside a configuration space for a PCM
4471 * \param pcm PCM handle
4472 * \param params Configuration space
4473 * \param format format
4474 * \return 0 if available a negative error code otherwise
4476 int snd_pcm_hw_params_test_format(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t format)
4478 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_FORMAT, format, 0);
4482 * \brief Restrict a configuration space to contain only one format
4483 * \param pcm PCM handle
4484 * \param params Configuration space
4485 * \param format format
4486 * \return 0 otherwise a negative error code
4488 int snd_pcm_hw_params_set_format(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t format)
4490 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_FORMAT, format, 0);
4494 * \brief Restrict a configuration space to contain only its first format
4495 * \param pcm PCM handle
4496 * \param params Configuration space
4497 * \param format Returned first format
4498 * \return 0 otherwise a negative error code
4501 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_format_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t *format)
4503 int snd_pcm_hw_params_set_format_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t *format)
4506 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_FORMAT, (unsigned int *)format, NULL);
4510 * \brief Restrict a configuration space to contain only its last format
4511 * \param pcm PCM handle
4512 * \param params Configuration space
4513 * \param format Returned last format
4514 * \return 0 otherwise a negative error code
4517 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_format_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t *format)
4519 int snd_pcm_hw_params_set_format_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t *format)
4522 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_FORMAT, (unsigned int *)format, NULL);
4526 * \brief Restrict a configuration space to contain only a set of formats
4527 * \param pcm PCM handle
4528 * \param params Configuration space
4529 * \param mask Format mask
4530 * \return 0 otherwise a negative error code
4532 int snd_pcm_hw_params_set_format_mask(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_mask_t *mask)
4534 return snd_pcm_hw_param_set_mask(pcm, params, SND_TRY, SND_PCM_HW_PARAM_FORMAT, (snd_mask_t *) mask);
4538 * \brief Get format mask from a configuration space
4539 * \param params Configuration space
4540 * \param mask Returned Format mask
4542 void snd_pcm_hw_params_get_format_mask(snd_pcm_hw_params_t *params, snd_pcm_format_mask_t *mask)
4544 snd_pcm_format_mask_copy(mask, snd_pcm_hw_param_get_mask(params, SND_PCM_HW_PARAM_FORMAT));
4549 * \brief Extract subformat from a configuration space
4550 * \param params Configuration space
4551 * \param subformat Returned subformat value
4552 * \return subformat otherwise a negative error code if the configuration space does not contain a single value
4555 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_subformat)(const snd_pcm_hw_params_t *params, snd_pcm_subformat_t *subformat)
4557 int snd_pcm_hw_params_get_subformat(const snd_pcm_hw_params_t *params, snd_pcm_subformat_t *subformat)
4560 return snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_SUBFORMAT, (unsigned int *)subformat, NULL);
4564 * \brief Verify if a subformat is available inside a configuration space for a PCM
4565 * \param pcm PCM handle
4566 * \param params Configuration space
4567 * \param subformat subformat value
4568 * \return 0 if available a negative error code otherwise
4570 int snd_pcm_hw_params_test_subformat(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t subformat)
4572 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_SUBFORMAT, subformat, 0);
4576 * \brief Restrict a configuration space to contain only one subformat
4577 * \param pcm PCM handle
4578 * \param params Configuration space
4579 * \param subformat subformat value
4580 * \return 0 otherwise a negative error code if configuration space would become empty
4582 int snd_pcm_hw_params_set_subformat(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t subformat)
4584 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_SUBFORMAT, subformat, 0);
4588 * \brief Restrict a configuration space to contain only its first subformat
4589 * \param pcm PCM handle
4590 * \param params Configuration space
4591 * \param subformat Returned subformat
4592 * \return 0 otherwise a negative error code
4595 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_subformat_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t *subformat)
4597 int snd_pcm_hw_params_set_subformat_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t *subformat)
4600 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_SUBFORMAT, (unsigned int *)subformat, NULL);
4604 * \brief Restrict a configuration space to contain only its last subformat
4605 * \param pcm PCM handle
4606 * \param params Configuration space
4607 * \param subformat Returned subformat
4608 * \return 0 otherwise a negative error code
4611 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_subformat_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t *subformat)
4613 int snd_pcm_hw_params_set_subformat_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t *subformat)
4616 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_SUBFORMAT, (unsigned int *)subformat, NULL);
4620 * \brief Restrict a configuration space to contain only a set of subformats
4621 * \param pcm PCM handle
4622 * \param params Configuration space
4623 * \param mask Subformat mask
4624 * \return 0 otherwise a negative error code
4626 int snd_pcm_hw_params_set_subformat_mask(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_mask_t *mask)
4628 return snd_pcm_hw_param_set_mask(pcm, params, SND_TRY, SND_PCM_HW_PARAM_SUBFORMAT, (snd_mask_t *) mask);
4632 * \brief Get subformat mask from a configuration space
4633 * \param params Configuration space
4634 * \param mask Returned Subformat mask
4636 void snd_pcm_hw_params_get_subformat_mask(snd_pcm_hw_params_t *params, snd_pcm_subformat_mask_t *mask)
4638 snd_pcm_subformat_mask_copy(mask, snd_pcm_hw_param_get_mask(params, SND_PCM_HW_PARAM_SUBFORMAT));
4643 * \brief Extract channels from a configuration space
4644 * \param params Configuration space
4645 * \param val Returned channels count
4646 * \return 0 otherwise a negative error code if the configuration space does not contain a single value
4649 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_channels)(const snd_pcm_hw_params_t *params, unsigned int *val)
4651 int snd_pcm_hw_params_get_channels(const snd_pcm_hw_params_t *params, unsigned int *val)
4654 return snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
4658 * \brief Extract minimum channels count from a configuration space
4659 * \param params Configuration space
4660 * \param val minimum channels count
4661 * \return 0 otherwise a negative error code
4664 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_channels_min)(const snd_pcm_hw_params_t *params, unsigned int *val)
4666 int snd_pcm_hw_params_get_channels_min(const snd_pcm_hw_params_t *params, unsigned int *val)
4669 return snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
4673 * \brief Extract maximum channels count from a configuration space
4674 * \param params Configuration space
4675 * \param val maximum channels count
4676 * \return 0 otherwise a negative error code
4679 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_channels_max)(const snd_pcm_hw_params_t *params, unsigned int *val)
4681 int snd_pcm_hw_params_get_channels_max(const snd_pcm_hw_params_t *params, unsigned int *val)
4684 return snd_pcm_hw_param_get_max(params, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
4688 * \brief Verify if a channels count is available inside a configuration space for a PCM
4689 * \param pcm PCM handle
4690 * \param params Configuration space
4691 * \param val channels count
4692 * \return 0 if available a negative error code otherwise
4694 int snd_pcm_hw_params_test_channels(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val)
4696 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_CHANNELS, val, 0);
4700 * \brief Restrict a configuration space to contain only one channels count
4701 * \param pcm PCM handle
4702 * \param params Configuration space
4703 * \param val channels count
4704 * \return 0 otherwise a negative error code if configuration space would become empty
4706 int snd_pcm_hw_params_set_channels(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val)
4708 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_CHANNELS, val, 0);
4712 * \brief Restrict a configuration space with a minimum channels count
4713 * \param pcm PCM handle
4714 * \param params Configuration space
4715 * \param val minimum channels count (on return filled with actual minimum)
4716 * \return 0 otherwise a negative error code if configuration space would become empty
4718 int snd_pcm_hw_params_set_channels_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4720 return snd_pcm_hw_param_set_min(pcm, params, SND_TRY, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
4724 * \brief Restrict a configuration space with a maximum channels count
4725 * \param pcm PCM handle
4726 * \param params Configuration space
4727 * \param val maximum channels count (on return filled with actual maximum)
4728 * \return 0 otherwise a negative error code if configuration space would become empty
4730 int snd_pcm_hw_params_set_channels_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4732 return snd_pcm_hw_param_set_max(pcm, params, SND_TRY, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
4736 * \brief Restrict a configuration space to have channels counts in a given range
4737 * \param pcm PCM handle
4738 * \param params Configuration space
4739 * \param min minimum channels count (on return filled with actual minimum)
4740 * \param max maximum channels count (on return filled with actual maximum)
4741 * \return 0 otherwise a negative error code if configuration space would become empty
4743 int snd_pcm_hw_params_set_channels_minmax(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *min, unsigned int *max)
4745 return snd_pcm_hw_param_set_minmax(pcm, params, SND_TRY, SND_PCM_HW_PARAM_CHANNELS, min, NULL, max, NULL);
4749 * \brief Restrict a configuration space to have channels count nearest to a target
4750 * \param pcm PCM handle
4751 * \param params Configuration space
4752 * \param val target channels count, returned chosen channels count
4753 * \return 0 otherwise a negative error code if configuration space is empty
4756 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_channels_near)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4758 int snd_pcm_hw_params_set_channels_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4761 return snd_pcm_hw_param_set_near(pcm, params, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
4765 * \brief Restrict a configuration space to contain only its minimum channels count
4766 * \param pcm PCM handle
4767 * \param params Configuration space
4768 * \param val minimum channels count
4769 * \return 0 otherwise a negative error code
4772 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_channels_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4774 int snd_pcm_hw_params_set_channels_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4777 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
4781 * \brief Restrict a configuration space to contain only its maximum channels count
4782 * \param pcm PCM handle
4783 * \param params Configuration space
4784 * \param val maximum channels count
4785 * \return 0 otherwise a negative error code
4788 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_channels_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4790 int snd_pcm_hw_params_set_channels_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4793 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
4798 * \brief Extract rate from a configuration space
4799 * \param params Configuration space
4800 * \param val Returned approximate rate
4801 * \param dir Sub unit direction
4802 * \return 0 otherwise a negative error code if the configuration space does not contain a single value
4804 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
4807 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_rate)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4809 int snd_pcm_hw_params_get_rate(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4812 return snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_RATE, val, dir);
4816 * \brief Extract minimum rate from a configuration space
4817 * \param params Configuration space
4818 * \param val Returned approximate minimum rate
4819 * \param dir Sub unit direction
4820 * \return 0 otherwise a negative error code
4822 * Exact value is <,=,> the returned one following dir (-1,0,1)
4825 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_rate_min)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4827 int snd_pcm_hw_params_get_rate_min(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4830 return snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_RATE, val, dir);
4834 * \brief Extract maximum rate from a configuration space
4835 * \param params Configuration space
4836 * \param val Returned approximate maximum rate
4837 * \param dir Sub unit direction
4838 * \return 0 otherwise a negative error code
4840 * Exact value is <,=,> the returned one following dir (-1,0,1)
4843 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_rate_max)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4845 int snd_pcm_hw_params_get_rate_max(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4848 return snd_pcm_hw_param_get_max(params, SND_PCM_HW_PARAM_RATE, val, dir);
4852 * \brief Verify if a rate is available inside a configuration space for a PCM
4853 * \param pcm PCM handle
4854 * \param params Configuration space
4855 * \param val approximate rate
4856 * \param dir Sub unit direction
4857 * \return 0 if available a negative error code otherwise
4859 * Wanted exact value is <,=,> val following dir (-1,0,1)
4861 int snd_pcm_hw_params_test_rate(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
4863 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_RATE, val, dir);
4867 * \brief Restrict a configuration space to contain only one rate
4868 * \param pcm PCM handle
4869 * \param params Configuration space
4870 * \param val approximate rate
4871 * \param dir Sub unit direction
4872 * \return 0 otherwise a negative error code if configuration space would become empty
4874 * Wanted exact value is <,=,> val following dir (-1,0,1)
4876 int snd_pcm_hw_params_set_rate(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
4878 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_RATE, val, dir);
4882 * \brief Restrict a configuration space with a minimum rate
4883 * \param pcm PCM handle
4884 * \param params Configuration space
4885 * \param val approximate minimum rate (on return filled with actual minimum)
4886 * \param dir Sub unit direction (on return filled with actual direction)
4887 * \return 0 otherwise a negative error code if configuration space would become empty
4889 * Wanted/actual exact minimum is <,=,> val following dir (-1,0,1)
4891 int snd_pcm_hw_params_set_rate_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4893 return snd_pcm_hw_param_set_min(pcm, params, SND_TRY, SND_PCM_HW_PARAM_RATE, val, dir);
4897 * \brief Restrict a configuration space with a maximum rate
4898 * \param pcm PCM handle
4899 * \param params Configuration space
4900 * \param val approximate maximum rate (on return filled with actual maximum)
4901 * \param dir Sub unit direction (on return filled with actual direction)
4902 * \return 0 otherwise a negative error code if configuration space would become empty
4904 * Wanted/actual exact maximum is <,=,> val following dir (-1,0,1)
4906 int snd_pcm_hw_params_set_rate_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4908 return snd_pcm_hw_param_set_max(pcm, params, SND_TRY, SND_PCM_HW_PARAM_RATE, val, dir);
4912 * \brief Restrict a configuration space to have rates in a given range
4913 * \param pcm PCM handle
4914 * \param params Configuration space
4915 * \param min approximate minimum rate (on return filled with actual minimum)
4916 * \param mindir Sub unit direction for minimum (on return filled with actual direction)
4917 * \param max approximate maximum rate (on return filled with actual maximum)
4918 * \param maxdir Sub unit direction for maximum (on return filled with actual direction)
4919 * \return 0 otherwise a negative error code if configuration space would become empty
4921 * Wanted/actual exact min/max is <,=,> val following dir (-1,0,1)
4923 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)
4925 return snd_pcm_hw_param_set_minmax(pcm, params, SND_TRY, SND_PCM_HW_PARAM_RATE, min, mindir, max, maxdir);
4929 * \brief Restrict a configuration space to have rate nearest to a target
4930 * \param pcm PCM handle
4931 * \param params Configuration space
4932 * \param val approximate target rate / returned approximate set rate
4933 * \param dir Sub unit direction
4934 * \return 0 otherwise a negative error code if configuration space is empty
4936 * target/chosen exact value is <,=,> val following dir (-1,0,1)
4939 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_rate_near)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4941 int snd_pcm_hw_params_set_rate_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4944 return snd_pcm_hw_param_set_near(pcm, params, SND_PCM_HW_PARAM_RATE, val, dir);
4948 * \brief Restrict a configuration space to contain only its minimum rate
4949 * \param pcm PCM handle
4950 * \param params Configuration space
4951 * \param val Returned minimum approximate rate
4952 * \param dir Sub unit direction
4953 * \return 0 otherwise a negative error code
4955 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
4958 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_rate_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4960 int snd_pcm_hw_params_set_rate_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4963 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_RATE, val, dir);
4967 * \brief Restrict a configuration space to contain only its maximum rate
4968 * \param pcm PCM handle
4969 * \param params Configuration space
4970 * \param val Returned maximum approximate rate
4971 * \param dir Sub unit direction
4972 * \return 0 otherwise a negative error code
4974 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
4977 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_rate_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4979 int snd_pcm_hw_params_set_rate_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4982 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_RATE, val, dir);
4986 * \brief Restrict a configuration space to contain only real hardware rates
4987 * \param pcm PCM handle
4988 * \param params Configuration space
4989 * \param val 0 = disable, 1 = enable (default) rate resampling
4990 * \return 0 otherwise a negative error code
4992 int snd_pcm_hw_params_set_rate_resample(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val)
4994 assert(pcm && params);
4996 params->flags |= SND_PCM_HW_PARAMS_NORESAMPLE;
4998 params->flags &= ~SND_PCM_HW_PARAMS_NORESAMPLE;
5000 return snd_pcm_hw_refine(pcm, params);
5004 * \brief Extract resample state from a configuration space
5005 * \param pcm PCM handle
5006 * \param params Configuration space
5007 * \param val 0 = disable, 1 = enable rate resampling
5008 * \return 0 otherwise a negative error code
5010 int snd_pcm_hw_params_get_rate_resample(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
5012 assert(pcm && params && val);
5013 *val = params->flags & SND_PCM_HW_PARAMS_NORESAMPLE ? 0 : 1;
5018 * \brief Restrict a configuration space to allow the buffer to be accessible from outside
5019 * \param pcm PCM handle
5020 * \param params Configuration space
5021 * \param val 0 = disable, 1 = enable (default) exporting buffer
5022 * \return 0 otherwise a negative error code
5024 int snd_pcm_hw_params_set_export_buffer(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val)
5026 assert(pcm && params);
5028 params->flags |= SND_PCM_HW_PARAMS_EXPORT_BUFFER;
5030 params->flags &= ~SND_PCM_HW_PARAMS_EXPORT_BUFFER;
5032 return snd_pcm_hw_refine(pcm, params);
5036 * \brief Extract buffer accessibility from a configuration space
5037 * \param pcm PCM handle
5038 * \param params Configuration space
5039 * \param val 0 = disable, 1 = enable exporting buffer
5040 * \return 0 otherwise a negative error code
5042 int snd_pcm_hw_params_get_export_buffer(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
5044 assert(pcm && params && val);
5045 *val = params->flags & SND_PCM_HW_PARAMS_EXPORT_BUFFER ? 1 : 0;
5050 * \brief Restrict a configuration space to settings without period wakeups
5051 * \param pcm PCM handle
5052 * \param params Configuration space
5053 * \param val 0 = disable, 1 = enable (default) period wakeup
5054 * \return Zero on success, otherwise a negative error code.
5056 * This function must be called only on devices where non-blocking mode is
5059 * To check whether the hardware does support disabling period wakeups, call
5060 * #snd_pcm_hw_params_can_disable_period_wakeup(). If the hardware does not
5061 * support this mode, standard period wakeups will be generated.
5063 * Even with disabled period wakeups, the period size/time/count parameters
5064 * are valid; it is suggested to use #snd_pcm_hw_params_set_period_size_last().
5066 * When period wakeups are disabled, the application must not use any functions
5067 * that could block on this device. The use of poll should be limited to error
5068 * cases. The application needs to use an external event or a timer to
5069 * check the state of the ring buffer and refill it apropriately.
5071 int snd_pcm_hw_params_set_period_wakeup(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val)
5073 assert(pcm && params);
5076 if (!(pcm->mode & SND_PCM_NONBLOCK))
5078 params->flags |= SND_PCM_HW_PARAMS_NO_PERIOD_WAKEUP;
5080 params->flags &= ~SND_PCM_HW_PARAMS_NO_PERIOD_WAKEUP;
5083 return snd_pcm_hw_refine(pcm, params);
5087 * \brief Extract period wakeup flag from a configuration space
5088 * \param pcm PCM handle
5089 * \param params Configuration space
5090 * \param val 0 = disabled, 1 = enabled period wakeups
5091 * \return Zero on success, otherwise a negative error code.
5093 int snd_pcm_hw_params_get_period_wakeup(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
5095 assert(pcm && params && val);
5096 *val = params->flags & SND_PCM_HW_PARAMS_NO_PERIOD_WAKEUP ? 0 : 1;
5101 * \brief Restrict a configuration space to fill the end of playback stream with silence when drain() is invoked
5102 * \param pcm PCM handle
5103 * \param params Configuration space
5104 * \param val 0 = disabled, 1 = enabled (default) fill the end of the playback stream with silence when drain() is invoked
5105 * \return Zero on success, otherwise a negative error code.
5107 * When disabled, the application should handle the end of stream gracefully
5108 * (fill the silent samples to align to the period size plus some extra
5109 * samples for hardware / driver without perfect drain). Note that the rewind
5110 * may be used for this purpose or the sw_params silencing mechanism.
5112 int snd_pcm_hw_params_set_drain_silence(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val)
5114 assert(pcm && params);
5116 params->flags &= ~SND_PCM_HW_PARAMS_NO_DRAIN_SILENCE;
5118 params->flags |= SND_PCM_HW_PARAMS_NO_DRAIN_SILENCE;
5120 return snd_pcm_hw_refine(pcm, params);
5124 * \brief Extract drain with the filling of silence samples from a configuration space
5125 * \param pcm PCM handle
5126 * \param params Configuration space
5127 * \param val 0 = disabled, 1 = enabled
5128 * \return 0 otherwise a negative error code
5130 int snd_pcm_hw_params_get_drain_silence(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
5132 assert(pcm && params && val);
5133 *val = params->flags & SND_PCM_HW_PARAMS_NO_DRAIN_SILENCE ? 0 : 1;
5138 * \brief Extract period time from a configuration space
5139 * \param params Configuration space
5140 * \param val Returned approximate period duration in us
5141 * \param dir Sub unit direction
5142 * \return 0 otherwise a negative error code if the configuration space does not contain a single value
5144 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5147 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_period_time)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5149 int snd_pcm_hw_params_get_period_time(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5152 return snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
5156 * \brief Extract minimum period time from a configuration space
5157 * \param params Configuration space
5158 * \param val approximate minimum period duration in us
5159 * \param dir Sub unit direction
5160 * \return 0 otherwise a negative error code
5162 * Exact value is <,=,> the returned one following dir (-1,0,1)
5165 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_period_time_min)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5167 int snd_pcm_hw_params_get_period_time_min(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5170 return snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
5174 * \brief Extract maximum period time from a configuration space
5175 * \param params Configuration space
5176 * \param val approximate maximum period duration in us
5177 * \param dir Sub unit direction
5178 * \return 0 otherwise a negative error code
5180 * Exact value is <,=,> the returned one following dir (-1,0,1)
5183 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_period_time_max)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5185 int snd_pcm_hw_params_get_period_time_max(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5188 return snd_pcm_hw_param_get_max(params, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
5192 * \brief Verify if a period time is available inside a configuration space for a PCM
5193 * \param pcm PCM handle
5194 * \param params Configuration space
5195 * \param val approximate period duration in us
5196 * \param dir Sub unit direction
5197 * \return 0 if available a negative error code otherwise
5199 * Wanted exact value is <,=,> val following dir (-1,0,1)
5201 int snd_pcm_hw_params_test_period_time(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
5203 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
5207 * \brief Restrict a configuration space to contain only one period time
5208 * \param pcm PCM handle
5209 * \param params Configuration space
5210 * \param val approximate period duration in us
5211 * \param dir Sub unit direction
5212 * \return 0 otherwise a negative error code if configuration space would become empty
5214 * Wanted exact value is <,=,> val following dir (-1,0,1)
5216 int snd_pcm_hw_params_set_period_time(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
5218 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
5223 * \brief Restrict a configuration space with a minimum period time
5224 * \param pcm PCM handle
5225 * \param params Configuration space
5226 * \param val approximate minimum period duration in us (on return filled with actual minimum)
5227 * \param dir Sub unit direction (on return filled with actual direction)
5228 * \return 0 otherwise a negative error code if configuration space would become empty
5230 * Wanted/actual exact minimum is <,=,> val following dir (-1,0,1)
5232 int snd_pcm_hw_params_set_period_time_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5234 return snd_pcm_hw_param_set_min(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
5238 * \brief Restrict a configuration space with a maximum period time
5239 * \param pcm PCM handle
5240 * \param params Configuration space
5241 * \param val approximate maximum period duration in us (on return filled with actual maximum)
5242 * \param dir Sub unit direction (on return filled with actual direction)
5243 * \return 0 otherwise a negative error code if configuration space would become empty
5245 * Wanted/actual exact maximum is <,=,> val following dir (-1,0,1)
5247 int snd_pcm_hw_params_set_period_time_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5249 return snd_pcm_hw_param_set_max(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
5253 * \brief Restrict a configuration space to have period times in a given range
5254 * \param pcm PCM handle
5255 * \param params Configuration space
5256 * \param min approximate minimum period duration in us (on return filled with actual minimum)
5257 * \param mindir Sub unit direction for minimum (on return filled with actual direction)
5258 * \param max approximate maximum period duration in us (on return filled with actual maximum)
5259 * \param maxdir Sub unit direction for maximum (on return filled with actual direction)
5260 * \return 0 otherwise a negative error code if configuration space would become empty
5262 * Wanted/actual exact min/max is <,=,> val following dir (-1,0,1)
5264 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)
5266 return snd_pcm_hw_param_set_minmax(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_TIME, min, mindir, max, maxdir);
5270 * \brief Restrict a configuration space to have period time nearest to a target
5271 * \param pcm PCM handle
5272 * \param params Configuration space
5273 * \param val approximate target period duration in us / returned chosen approximate target period duration
5274 * \param dir Sub unit direction
5275 * \return 0 otherwise a negative error code if configuration space is empty
5277 * target/chosen exact value is <,=,> val following dir (-1,0,1)
5280 EXPORT_SYMBOL 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)
5282 int snd_pcm_hw_params_set_period_time_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5285 return snd_pcm_hw_param_set_near(pcm, params, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
5289 * \brief Restrict a configuration space to contain only its minimum period time
5290 * \param pcm PCM handle
5291 * \param params Configuration space
5292 * \param val Returned approximate period duration in us
5293 * \param dir Sub unit direction
5294 * \return 0 otherwise a negative error code
5296 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5299 EXPORT_SYMBOL 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)
5301 int snd_pcm_hw_params_set_period_time_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5304 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
5308 * \brief Restrict a configuration space to contain only its maximum period time
5309 * \param pcm PCM handle
5310 * \param params Configuration space
5311 * \param val Returned maximum approximate period time
5312 * \param dir Sub unit direction
5313 * \return approximate period duration in us
5316 EXPORT_SYMBOL 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)
5318 int snd_pcm_hw_params_set_period_time_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5321 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
5326 * \brief Extract period size from a configuration space
5327 * \param params Configuration space
5328 * \param val Returned approximate period size in frames
5329 * \param dir Sub unit direction
5330 * \return 0 otherwise a negative error code if the configuration space does not contain a single value
5332 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5335 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_period_size)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
5337 int snd_pcm_hw_params_get_period_size(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
5341 int err = snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
5348 * \brief Extract minimum period size from a configuration space
5349 * \param params Configuration space
5350 * \param val approximate minimum period size in frames
5351 * \param dir Sub unit direction
5352 * \return 0 otherwise a negative error code
5354 * Exact value is <,=,> the returned one following dir (-1,0,1)
5357 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_period_size_min)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
5359 int snd_pcm_hw_params_get_period_size_min(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
5362 unsigned int _val = *val;
5363 int err = snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
5370 * \brief Extract maximum period size from a configuration space
5371 * \param params Configuration space
5372 * \param val approximate minimum period size in frames
5373 * \param dir Sub unit direction
5374 * \return 0 otherwise a negative error code
5376 * Exact value is <,=,> the returned one following dir (-1,0,1)
5379 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_period_size_max)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
5381 int snd_pcm_hw_params_get_period_size_max(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
5384 unsigned int _val = *val;
5385 int err = snd_pcm_hw_param_get_max(params, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
5392 * \brief Verify if a period size is available inside a configuration space for a PCM
5393 * \param pcm PCM handle
5394 * \param params Configuration space
5395 * \param val approximate period size in frames
5396 * \param dir Sub unit direction
5397 * \return 0 if available a negative error code otherwise
5399 * Wanted exact value is <,=,> val following dir (-1,0,1)
5401 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)
5403 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_PERIOD_SIZE, val, dir);
5407 * \brief Restrict a configuration space to contain only one period size
5408 * \param pcm PCM handle
5409 * \param params Configuration space
5410 * \param val approximate period size in frames
5411 * \param dir Sub unit direction
5412 * \return 0 otherwise a negative error code if configuration space would become empty
5414 * Wanted exact value is <,=,> val following dir (-1,0,1)
5416 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)
5418 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_SIZE, val, dir);
5422 * \brief Restrict a configuration space with a minimum period size
5423 * \param pcm PCM handle
5424 * \param params Configuration space
5425 * \param val approximate minimum period size in frames (on return filled with actual minimum)
5426 * \param dir Sub unit direction (on return filled with actual direction)
5427 * \return 0 otherwise a negative error code if configuration space would become empty
5429 * Wanted/actual exact minimum is <,=,> val following dir (-1,0,1)
5431 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)
5433 unsigned int _val = *val;
5434 int err = snd_pcm_hw_param_set_min(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
5441 * \brief Restrict a configuration space with a maximum period size
5442 * \param pcm PCM handle
5443 * \param params Configuration space
5444 * \param val approximate maximum period size in frames (on return filled with actual maximum)
5445 * \param dir Sub unit direction (on return filled with actual direction)
5446 * \return 0 otherwise a negative error code if configuration space would become empty
5448 * Wanted/actual exact minimum is <,=,> val following dir (-1,0,1)
5450 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)
5452 unsigned int _val = *val;
5453 int err = snd_pcm_hw_param_set_max(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
5460 * \brief Restrict a configuration space to have period sizes in a given range
5461 * \param pcm PCM handle
5462 * \param params Configuration space
5463 * \param min approximate minimum period size in frames (on return filled with actual minimum)
5464 * \param mindir Sub unit direction for minimum (on return filled with actual direction)
5465 * \param max approximate maximum period size in frames (on return filled with actual maximum)
5466 * \param maxdir Sub unit direction for maximum (on return filled with actual direction)
5467 * \return 0 otherwise a negative error code if configuration space would become empty
5469 * Wanted/actual exact min/max is <,=,> val following dir (-1,0,1)
5471 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)
5473 unsigned int _min = *min;
5474 unsigned int _max = *max;
5475 int err = snd_pcm_hw_param_set_minmax(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_SIZE, &_min, mindir, &_max, maxdir);
5482 * \brief Restrict a configuration space to have period size nearest to a target
5483 * \param pcm PCM handle
5484 * \param params Configuration space
5485 * \param val approximate target period size in frames / returned chosen approximate target period size
5486 * \param dir Sub unit direction
5487 * \return 0 otherwise a negative error code if configuration space is empty
5489 * target/chosen exact value is <,=,> val following dir (-1,0,1)
5492 EXPORT_SYMBOL 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)
5494 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)
5497 unsigned int _val = *val;
5498 int err = snd_pcm_hw_param_set_near(pcm, params, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
5505 * \brief Restrict a configuration space to contain only its minimum period size
5506 * \param pcm PCM handle
5507 * \param params Configuration space
5508 * \param val Returned maximum approximate period size in frames
5509 * \param dir Sub unit direction
5510 * \return 0 otherwise a negative error code
5512 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5515 EXPORT_SYMBOL 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)
5517 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)
5521 int err = snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
5528 * \brief Restrict a configuration space to contain only its maximum period size
5529 * \param pcm PCM handle
5530 * \param params Configuration space
5531 * \param val Returned maximum approximate period size in frames
5532 * \param dir Sub unit direction
5533 * \return 0 otherwise a negative error code
5535 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5538 EXPORT_SYMBOL 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)
5540 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)
5544 int err = snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
5551 * \brief Restrict a configuration space to contain only integer period sizes
5552 * \param pcm PCM handle
5553 * \param params Configuration space
5554 * \return 0 otherwise a negative error code if configuration space would become empty
5556 int snd_pcm_hw_params_set_period_size_integer(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
5558 return snd_pcm_hw_param_set_integer(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_SIZE);
5563 * \brief Extract periods from a configuration space
5564 * \param params Configuration space
5565 * \param val approximate periods per buffer
5566 * \param dir Sub unit direction
5567 * \return 0 otherwise a negative error code if the configuration space does not contain a single value
5569 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5572 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_periods)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5574 int snd_pcm_hw_params_get_periods(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5577 return snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_PERIODS, val, dir);
5581 * \brief Extract minimum periods count from a configuration space
5582 * \param params Configuration space
5583 * \param val approximate minimum periods per buffer
5584 * \param dir Sub unit direction
5585 * \return 0 otherwise a negative error code
5587 * Exact value is <,=,> the returned one following dir (-1,0,1)
5590 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_periods_min)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5592 int snd_pcm_hw_params_get_periods_min(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5595 return snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_PERIODS, val, dir);
5599 * \brief Extract maximum periods count from a configuration space
5600 * \param params Configuration space
5601 * \param val approximate maximum periods per buffer
5602 * \param dir Sub unit direction
5603 * \return 0 otherwise a negative error code
5605 * Exact value is <,=,> the returned one following dir (-1,0,1)
5608 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_periods_max)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5610 int snd_pcm_hw_params_get_periods_max(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5613 return snd_pcm_hw_param_get_max(params, SND_PCM_HW_PARAM_PERIODS, val, dir);
5617 * \brief Verify if a periods count is available inside a configuration space for a PCM
5618 * \param pcm PCM handle
5619 * \param params Configuration space
5620 * \param val approximate periods per buffer
5621 * \param dir Sub unit direction
5622 * \return 0 if available a negative error code otherwise
5624 * Wanted exact value is <,=,> val following dir (-1,0,1)
5626 int snd_pcm_hw_params_test_periods(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
5628 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_PERIODS, val, dir);
5632 * \brief Restrict a configuration space to contain only one periods count
5633 * \param pcm PCM handle
5634 * \param params Configuration space
5635 * \param val approximate periods per buffer
5636 * \param dir Sub unit direction
5637 * \return 0 otherwise a negative error code if configuration space would become empty
5639 * Wanted exact value is <,=,> val following dir (-1,0,1)
5641 int snd_pcm_hw_params_set_periods(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
5643 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIODS, val, dir);
5647 * \brief Restrict a configuration space with a minimum periods count
5648 * \param pcm PCM handle
5649 * \param params Configuration space
5650 * \param val approximate minimum periods per buffer (on return filled with actual minimum)
5651 * \param dir Sub unit direction (on return filled with actual direction)
5652 * \return 0 otherwise a negative error code if configuration space would become empty
5654 * Wanted/actual exact minimum is <,=,> val following dir (-1,0,1)
5656 int snd_pcm_hw_params_set_periods_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5658 return snd_pcm_hw_param_set_min(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIODS, val, dir);
5662 * \brief Restrict a configuration space with a maximum periods count
5663 * \param pcm PCM handle
5664 * \param params Configuration space
5665 * \param val approximate maximum periods per buffer (on return filled with actual maximum)
5666 * \param dir Sub unit direction (on return filled with actual direction)
5667 * \return 0 otherwise a negative error code if configuration space would become empty
5669 * Wanted/actual exact maximum is <,=,> val following dir (-1,0,1)
5671 int snd_pcm_hw_params_set_periods_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5673 return snd_pcm_hw_param_set_max(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIODS, val, dir);
5677 * \brief Restrict a configuration space to have periods counts in a given range
5678 * \param pcm PCM handle
5679 * \param params Configuration space
5680 * \param min approximate minimum periods per buffer (on return filled with actual minimum)
5681 * \param mindir Sub unit direction for minimum (on return filled with actual direction)
5682 * \param max approximate maximum periods per buffer (on return filled with actual maximum)
5683 * \param maxdir Sub unit direction for maximum (on return filled with actual direction)
5684 * \return 0 otherwise a negative error code if configuration space would become empty
5686 * Wanted/actual exact min/max is <,=,> val following dir (-1,0,1)
5688 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)
5690 return snd_pcm_hw_param_set_minmax(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIODS, min, mindir, max, maxdir);
5694 * \brief Restrict a configuration space to have periods count nearest to a target
5695 * \param pcm PCM handle
5696 * \param params Configuration space
5697 * \param val approximate target periods per buffer / returned chosen approximate target periods per buffer
5698 * \param dir Sub unit direction
5699 * \return 0 otherwise a negative error code if configuration space is empty
5701 * target/chosen exact value is <,=,> val following dir (-1,0,1)
5704 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_periods_near)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5706 int snd_pcm_hw_params_set_periods_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5709 return snd_pcm_hw_param_set_near(pcm, params, SND_PCM_HW_PARAM_PERIODS, val, dir);
5713 * \brief Restrict a configuration space to contain only its minimum periods count
5714 * \param pcm PCM handle
5715 * \param params Configuration space
5716 * \param val Returned approximate minimum periods per buffer
5717 * \param dir Sub unit direction
5718 * \return 0 otherwise a negative error code
5720 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5723 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_periods_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5725 int snd_pcm_hw_params_set_periods_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5728 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_PERIODS, val, dir);
5732 * \brief Restrict a configuration space to contain only its maximum periods count
5733 * \param pcm PCM handle
5734 * \param params Configuration space
5735 * \param val Returned approximate maximum periods per buffer
5736 * \param dir Sub unit direction
5737 * \return 0 otherwise a negative error code
5739 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5742 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_periods_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5744 int snd_pcm_hw_params_set_periods_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5747 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_PERIODS, val, dir);
5751 * \brief Restrict a configuration space to contain only integer periods counts
5752 * \param pcm PCM handle
5753 * \param params Configuration space
5754 * \return 0 otherwise a negative error code if configuration space would become empty
5756 int snd_pcm_hw_params_set_periods_integer(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
5758 return snd_pcm_hw_param_set_integer(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIODS);
5763 * \brief Extract buffer time from a configuration space
5764 * \param params Configuration space
5765 * \param val Returned buffer time in us
5766 * \param dir Sub unit direction
5767 * \return 0 otherwise a negative error code if the configuration space does not contain a single value
5769 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5772 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_buffer_time)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5774 int snd_pcm_hw_params_get_buffer_time(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5777 return snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5781 * \brief Extract minimum buffer time from a configuration space
5782 * \param params Configuration space
5783 * \param val approximate minimum buffer duration in us
5784 * \param dir Sub unit direction
5785 * \return 0 otherwise a negative error code
5787 * Exact value is <,=,> the returned one following dir (-1,0,1)
5790 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_buffer_time_min)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5792 int snd_pcm_hw_params_get_buffer_time_min(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5795 return snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5799 * \brief Extract maximum buffer time from a configuration space
5800 * \param params Configuration space
5801 * \param val approximate maximum buffer duration in us
5802 * \param dir Sub unit direction
5803 * \return 0 otherwise a negative error code
5805 * Exact value is <,=,> the returned one following dir (-1,0,1)
5808 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_buffer_time_max)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5810 int snd_pcm_hw_params_get_buffer_time_max(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5813 return snd_pcm_hw_param_get_max(params, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5817 * \brief Verify if a buffer time is available inside a configuration space for a PCM
5818 * \param pcm PCM handle
5819 * \param params Configuration space
5820 * \param val approximate buffer duration in us
5821 * \param dir Sub unit direction
5822 * \return 0 if available a negative error code otherwise
5824 * Wanted exact value is <,=,> val following dir (-1,0,1)
5826 int snd_pcm_hw_params_test_buffer_time(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
5828 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5832 * \brief Restrict a configuration space to contain only one buffer time
5833 * \param pcm PCM handle
5834 * \param params Configuration space
5835 * \param val approximate buffer duration in us
5836 * \param dir Sub unit direction
5837 * \return 0 otherwise a negative error code if configuration space would become empty
5839 * Wanted exact value is <,=,> val following dir (-1,0,1)
5841 int snd_pcm_hw_params_set_buffer_time(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
5843 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5847 * \brief Restrict a configuration space with a minimum buffer time
5848 * \param pcm PCM handle
5849 * \param params Configuration space
5850 * \param val approximate minimum buffer duration in us (on return filled with actual minimum)
5851 * \param dir Sub unit direction (on return filled with actual direction)
5852 * \return 0 otherwise a negative error code if configuration space would become empty
5854 * Wanted/actual exact minimum is <,=,> val following dir (-1,0,1)
5856 int snd_pcm_hw_params_set_buffer_time_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5858 return snd_pcm_hw_param_set_min(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5862 * \brief Restrict a configuration space with a maximum buffer time
5863 * \param pcm PCM handle
5864 * \param params Configuration space
5865 * \param val approximate maximum buffer duration in us (on return filled with actual maximum)
5866 * \param dir Sub unit direction (on return filled with actual direction)
5867 * \return 0 otherwise a negative error code if configuration space would become empty
5869 * Wanted/actual exact maximum is <,=,> val following dir (-1,0,1)
5871 int snd_pcm_hw_params_set_buffer_time_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5873 return snd_pcm_hw_param_set_max(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5877 * \brief Restrict a configuration space to have buffer times in a given range
5878 * \param pcm PCM handle
5879 * \param params Configuration space
5880 * \param min approximate minimum buffer duration in us (on return filled with actual minimum)
5881 * \param mindir Sub unit direction for minimum (on return filled with actual direction)
5882 * \param max approximate maximum buffer duration in us (on return filled with actual maximum)
5883 * \param maxdir Sub unit direction for maximum (on return filled with actual direction)
5884 * \return 0 otherwise a negative error code if configuration space would become empty
5886 * Wanted/actual exact min/max is <,=,> val following dir (-1,0,1)
5888 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)
5890 return snd_pcm_hw_param_set_minmax(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_TIME, min, mindir, max, maxdir);
5894 * \brief Restrict a configuration space to have buffer time nearest to a target
5895 * \param pcm PCM handle
5896 * \param params Configuration space
5897 * \param val approximate target buffer duration in us / returned chosen approximate target buffer duration
5898 * \param dir Sub unit direction
5899 * \return 0 otherwise a negative error code if configuration space is empty
5901 * target/chosen exact value is <,=,> val following dir (-1,0,1)
5904 EXPORT_SYMBOL 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)
5906 int snd_pcm_hw_params_set_buffer_time_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5909 return snd_pcm_hw_param_set_near(pcm, params, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5913 * \brief Restrict a configuration space to contain only its minimum buffer time
5914 * \param pcm PCM handle
5915 * \param params Configuration space
5916 * \param val Returned approximate minimum buffer duration in us
5917 * \param dir Sub unit direction
5918 * \return 0 otherwise a negative error code
5920 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5923 EXPORT_SYMBOL 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)
5925 int snd_pcm_hw_params_set_buffer_time_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5928 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5932 * \brief Restrict a configuration space to contain only its maximum buffered time
5933 * \param pcm PCM handle
5934 * \param params Configuration space
5935 * \param val Returned approximate maximum buffer duration in us
5936 * \param dir Sub unit direction
5937 * \return 0 otherwise a negative error code
5939 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5942 EXPORT_SYMBOL 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)
5944 int snd_pcm_hw_params_set_buffer_time_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5947 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5952 * \brief Extract buffer size from a configuration space
5953 * \param params Configuration space
5954 * \param val Returned buffer size in frames
5955 * \return 0 otherwise a negative error code if the configuration space does not contain a single value
5958 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_buffer_size)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5960 int snd_pcm_hw_params_get_buffer_size(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5964 int err = snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
5971 * \brief Extract minimum buffer size from a configuration space
5972 * \param params Configuration space
5973 * \param val Returned approximate minimum buffer size in frames
5974 * \return 0 otherwise a negative error code
5977 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_buffer_size_min)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5979 int snd_pcm_hw_params_get_buffer_size_min(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5983 int err = snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
5990 * \brief Extract maximum buffer size from a configuration space
5991 * \param params Configuration space
5992 * \param val Returned approximate maximum buffer size in frames
5993 * \return 0 otherwise a negative error code
5995 * Exact value is <,=,> the returned one following dir (-1,0,1)
5998 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_buffer_size_max)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
6000 int snd_pcm_hw_params_get_buffer_size_max(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
6004 int err = snd_pcm_hw_param_get_max(params, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
6011 * \brief Verify if a buffer size is available inside a configuration space for a PCM
6012 * \param pcm PCM handle
6013 * \param params Configuration space
6014 * \param val buffer size in frames
6015 * \return 0 if available a negative error code otherwise
6017 * Wanted exact value is <,=,> val following dir (-1,0,1)
6019 int snd_pcm_hw_params_test_buffer_size(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t val)
6021 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_BUFFER_SIZE, val, 0);
6025 * \brief Restrict a configuration space to contain only one buffer size
6026 * \param pcm PCM handle
6027 * \param params Configuration space
6028 * \param val buffer size in frames
6029 * \return 0 otherwise a negative error code if configuration space would become empty
6031 * Wanted exact value is <,=,> val following dir (-1,0,1)
6033 int snd_pcm_hw_params_set_buffer_size(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t val)
6035 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_SIZE, val, 0);
6039 * \brief Restrict a configuration space with a minimum buffer size
6040 * \param pcm PCM handle
6041 * \param params Configuration space
6042 * \param val approximate minimum buffer size in frames (on return filled with actual minimum)
6043 * \return 0 otherwise a negative error code if configuration space would become empty
6045 int snd_pcm_hw_params_set_buffer_size_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
6047 unsigned int _val = *val;
6048 int err = snd_pcm_hw_param_set_min(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
6055 * \brief Restrict a configuration space with a maximum buffer size
6056 * \param pcm PCM handle
6057 * \param params Configuration space
6058 * \param val approximate maximum buffer size in frames (on return filled with actual maximum)
6059 * \return 0 otherwise a negative error code if configuration space would become empty
6061 int snd_pcm_hw_params_set_buffer_size_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
6063 unsigned int _val = *val;
6064 int err = snd_pcm_hw_param_set_max(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
6071 * \brief Restrict a configuration space to have buffer sizes in a given range
6072 * \param pcm PCM handle
6073 * \param params Configuration space
6074 * \param min approximate minimum buffer size in frames (on return filled with actual minimum)
6075 * \param max approximate maximum buffer size in frames (on return filled with actual maximum)
6076 * \return 0 otherwise a negative error code if configuration space would become empty
6078 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)
6080 unsigned int _min = *min;
6081 unsigned int _max = *max;
6082 int err = snd_pcm_hw_param_set_minmax(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_SIZE, &_min, NULL, &_max, NULL);
6089 * \brief Restrict a configuration space to have buffer size nearest to a target
6090 * \param pcm PCM handle
6091 * \param params Configuration space
6092 * \param val approximate target buffer size in frames / returned chosen approximate target buffer size in frames
6093 * \return 0 otherwise a negative error code if configuration space is empty
6096 EXPORT_SYMBOL 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)
6098 int snd_pcm_hw_params_set_buffer_size_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
6101 unsigned int _val = *val;
6102 int err = snd_pcm_hw_param_set_near(pcm, params, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
6109 * \brief Restrict a configuration space to contain only its minimum buffer size
6110 * \param pcm PCM handle
6111 * \param params Configuration space
6112 * \param val Returned minimum buffer size in frames
6113 * \return buffer size in frames
6116 EXPORT_SYMBOL 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)
6118 int snd_pcm_hw_params_set_buffer_size_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
6122 int err = snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
6129 * \brief Restrict a configuration space to contain only its maximum buffer size
6130 * \param pcm PCM handle
6131 * \param params Configuration space
6132 * \param val Returned maximum buffer size in frames
6133 * \return 0 otherwise a negative error code
6136 EXPORT_SYMBOL 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)
6138 int snd_pcm_hw_params_set_buffer_size_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
6142 int err = snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
6150 * \brief (DEPRECATED) Extract tick time from a configuration space
6151 * \param params Configuration space
6152 * \param val Returned approximate tick duration in us
6153 * \param dir Sub unit direction
6154 * \return 0 otherwise a negative error code if the configuration space does not contain a single value
6156 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
6159 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_tick_time)(const snd_pcm_hw_params_t *params ATTRIBUTE_UNUSED, unsigned int *val, int *dir ATTRIBUTE_UNUSED)
6161 int snd_pcm_hw_params_get_tick_time(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
6169 * \brief (DEPRECATED) Extract minimum tick time from a configuration space
6170 * \param params Configuration space
6171 * \param val Returned approximate minimum tick duration in us
6172 * \param dir Sub unit direction
6173 * \return 0 otherwise a negative error code
6175 * Exact value is <,=,> the returned one following dir (-1,0,1)
6178 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_tick_time_min)(const snd_pcm_hw_params_t *params ATTRIBUTE_UNUSED, unsigned int *val, int *dir ATTRIBUTE_UNUSED)
6180 int snd_pcm_hw_params_get_tick_time_min(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
6188 * \brief (DEPRECATED) Extract maximum tick time from a configuration space
6189 * \param params Configuration space
6190 * \param val Returned approximate maximum tick duration in us
6191 * \param dir Sub unit direction
6192 * \return 0 otherwise a negative error code
6194 * Exact value is <,=,> the returned one following dir (-1,0,1)
6197 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_tick_time_max)(const snd_pcm_hw_params_t *params ATTRIBUTE_UNUSED, unsigned int *val, int *dir ATTRIBUTE_UNUSED)
6199 int snd_pcm_hw_params_get_tick_time_max(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
6207 * \brief (DEPRECATED) Verify if a tick time is available inside a configuration space for a PCM
6208 * \param pcm PCM handle
6209 * \param params Configuration space
6210 * \param val approximate tick duration in us
6211 * \param dir Sub unit direction
6212 * \return 0 if available a negative error code otherwise
6214 * Wanted exact value is <,=,> val following dir (-1,0,1)
6216 int snd_pcm_hw_params_test_tick_time(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_hw_params_t *params ATTRIBUTE_UNUSED, unsigned int val, int dir ATTRIBUTE_UNUSED)
6218 return val ? -EINVAL : 0;
6222 * \brief (DEPRECATED) Restrict a configuration space to contain only one tick time
6223 * \param pcm PCM handle
6224 * \param params Configuration space
6225 * \param val approximate tick duration in us
6226 * \param dir Sub unit direction
6227 * \return 0 otherwise a negative error code if configuration space would become empty
6229 * Wanted exact value is <,=,> val following dir (-1,0,1)
6231 int snd_pcm_hw_params_set_tick_time(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_hw_params_t *params ATTRIBUTE_UNUSED, unsigned int val ATTRIBUTE_UNUSED, int dir ATTRIBUTE_UNUSED)
6237 * \brief (DEPRECATED) Restrict a configuration space with a minimum tick time
6238 * \param pcm PCM handle
6239 * \param params Configuration space
6240 * \param val approximate minimum tick duration in us (on return filled with actual minimum)
6241 * \param dir Sub unit direction (on return filled with actual direction)
6242 * \return 0 otherwise a negative error code if configuration space would become empty
6244 * Wanted/actual exact minimum is <,=,> val following dir (-1,0,1)
6246 int snd_pcm_hw_params_set_tick_time_min(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_hw_params_t *params ATTRIBUTE_UNUSED, unsigned int *val ATTRIBUTE_UNUSED, int *dir ATTRIBUTE_UNUSED)
6252 * \brief (DEPRECATED) Restrict a configuration space with a maximum tick time
6253 * \param pcm PCM handle
6254 * \param params Configuration space
6255 * \param val approximate maximum tick duration in us (on return filled with actual maximum)
6256 * \param dir Sub unit direction (on return filled with actual direction)
6257 * \return 0 otherwise a negative error code if configuration space would become empty
6259 * Wanted/actual exact maximum is <,=,> val following dir (-1,0,1)
6261 int snd_pcm_hw_params_set_tick_time_max(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_hw_params_t *params ATTRIBUTE_UNUSED, unsigned int *val ATTRIBUTE_UNUSED, int *dir ATTRIBUTE_UNUSED)
6267 * \brief (DEPRECATED) Restrict a configuration space to have tick times in a given range
6268 * \param pcm PCM handle
6269 * \param params Configuration space
6270 * \param min approximate minimum tick duration in us (on return filled with actual minimum)
6271 * \param mindir Sub unit direction for minimum (on return filled with actual direction)
6272 * \param max approximate maximum tick duration in us (on return filled with actual maximum)
6273 * \param maxdir Sub unit direction for maximum (on return filled with actual direction)
6274 * \return 0 otherwise a negative error code if configuration space would become empty
6276 * Wanted/actual exact min/max is <,=,> val following dir (-1,0,1)
6278 int snd_pcm_hw_params_set_tick_time_minmax(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_hw_params_t *params ATTRIBUTE_UNUSED, unsigned int *min ATTRIBUTE_UNUSED, int *mindir ATTRIBUTE_UNUSED, unsigned int *max ATTRIBUTE_UNUSED, int *maxdir ATTRIBUTE_UNUSED)
6284 * \brief (DEPRECATED) Restrict a configuration space to have tick time nearest to a target
6285 * \param pcm PCM handle
6286 * \param params Configuration space
6287 * \param val approximate target tick duration in us / returned chosen approximate target tick duration in us
6288 * \param dir Sub unit direction
6289 * \return 0 otherwise a negative error code if configuration space is empty
6291 * target/chosen exact value is <,=,> val following dir (-1,0,1)
6294 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_tick_time_near)(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_hw_params_t *params ATTRIBUTE_UNUSED, unsigned int *val ATTRIBUTE_UNUSED, int *dir ATTRIBUTE_UNUSED)
6296 int snd_pcm_hw_params_set_tick_time_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
6303 * \brief (DEPRECATED) Restrict a configuration space to contain only its minimum tick time
6304 * \param pcm PCM handle
6305 * \param params Configuration space
6306 * \param val Returned approximate minimum tick duration in us
6307 * \param dir Sub unit direction
6308 * \return 0 otherwise a negative error code
6310 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
6313 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_tick_time_first)(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_hw_params_t *params ATTRIBUTE_UNUSED, unsigned int *val ATTRIBUTE_UNUSED, int *dir ATTRIBUTE_UNUSED)
6315 int snd_pcm_hw_params_set_tick_time_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
6322 * \brief (DEPRECATED) Restrict a configuration space to contain only its maximum tick time
6323 * \param pcm PCM handle
6324 * \param params Configuration space
6325 * \param val Returned approximate maximum tick duration in us
6326 * \param dir Sub unit direction
6327 * \return 0 otherwise a negative error code
6329 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
6332 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_tick_time_last)(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_hw_params_t *params ATTRIBUTE_UNUSED, unsigned int *val ATTRIBUTE_UNUSED, int *dir ATTRIBUTE_UNUSED)
6334 int snd_pcm_hw_params_set_tick_time_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
6341 * \brief Get the minimum transfer align value in samples
6342 * \param params Configuration space
6343 * \param val Returned minimum align value
6344 * \return 0 otherwise a negative error code if the configuration space does not contain a single value
6346 int snd_pcm_hw_params_get_min_align(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
6348 unsigned int format, channels, fb, min_align;
6351 err = snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_FORMAT, &format, NULL);
6354 err = snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_CHANNELS, &channels, NULL);
6357 // compute frame bits
6358 fb = snd_pcm_format_physical_width((snd_pcm_format_t)format) * channels;
6370 void snd_pcm_sw_params_current_no_lock(snd_pcm_t *pcm, snd_pcm_sw_params_t *params)
6372 params->proto = SNDRV_PCM_VERSION;
6373 params->tstamp_mode = pcm->tstamp_mode;
6374 params->tstamp_type = pcm->tstamp_type;
6375 params->period_step = pcm->period_step;
6376 params->sleep_min = 0;
6377 params->avail_min = pcm->avail_min;
6378 sw_set_period_event(params, pcm->period_event);
6379 params->xfer_align = 1;
6380 params->start_threshold = pcm->start_threshold;
6381 params->stop_threshold = pcm->stop_threshold;
6382 params->silence_threshold = pcm->silence_threshold;
6383 params->silence_size = pcm->silence_size;
6384 params->boundary = pcm->boundary;
6389 * \brief Return current software configuration for a PCM
6390 * \param pcm PCM handle
6391 * \param params Software configuration container
6392 * \return 0 on success otherwise a negative error code
6394 * The function is thread-safe when built with the proper option.
6396 int snd_pcm_sw_params_current(snd_pcm_t *pcm, snd_pcm_sw_params_t *params)
6398 assert(pcm && params);
6399 if (CHECK_SANITY(! pcm->setup)) {
6400 snd_check(PCM, "PCM not set up");
6403 __snd_pcm_lock(pcm); /* forced lock due to pcm field changes */
6404 snd_pcm_sw_params_current_no_lock(pcm, params);
6405 __snd_pcm_unlock(pcm);
6410 * \brief Dump a software configuration
6411 * \param params Software configuration container
6412 * \param out Output handle
6413 * \return 0 on success otherwise a negative error code
6415 int snd_pcm_sw_params_dump(snd_pcm_sw_params_t *params, snd_output_t *out)
6417 snd_output_printf(out, "tstamp_mode: %s\n", snd_pcm_tstamp_mode_name(params->tstamp_mode));
6418 snd_output_printf(out, "tstamp_type: %s\n", snd_pcm_tstamp_type_name(params->tstamp_type));
6419 snd_output_printf(out, "period_step: %u\n", params->period_step);
6420 snd_output_printf(out, "avail_min: %lu\n", params->avail_min);
6421 snd_output_printf(out, "start_threshold: %ld\n", params->start_threshold);
6422 snd_output_printf(out, "stop_threshold: %ld\n", params->stop_threshold);
6423 snd_output_printf(out, "silence_threshold: %lu\n", params->silence_threshold);
6424 snd_output_printf(out, "silence_size: %lu\n", params->silence_size);
6425 snd_output_printf(out, "boundary: %lu\n", params->boundary);
6430 * \brief get size of #snd_pcm_sw_params_t
6431 * \return size in bytes
6433 size_t snd_pcm_sw_params_sizeof()
6435 return sizeof(snd_pcm_sw_params_t);
6439 * \brief allocate an invalid #snd_pcm_sw_params_t using standard malloc
6440 * \param ptr returned pointer
6441 * \return 0 on success otherwise negative error code
6443 int snd_pcm_sw_params_malloc(snd_pcm_sw_params_t **ptr)
6446 *ptr = calloc(1, sizeof(snd_pcm_sw_params_t));
6453 * \brief frees a previously allocated #snd_pcm_sw_params_t
6454 * \param obj pointer to object to free
6456 void snd_pcm_sw_params_free(snd_pcm_sw_params_t *obj)
6462 * \brief copy one #snd_pcm_sw_params_t to another
6463 * \param dst pointer to destination
6464 * \param src pointer to source
6466 void snd_pcm_sw_params_copy(snd_pcm_sw_params_t *dst, const snd_pcm_sw_params_t *src)
6473 * \brief Get boundary for ring pointers from a software configuration container
6474 * \param params Software configuration container
6475 * \param val Returned boundary in frames
6476 * \return 0 otherwise a negative error code
6478 int snd_pcm_sw_params_get_boundary(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6481 *val = params->boundary;
6486 * \brief (DEPRECATED) Set start mode inside a software configuration container
6487 * \param pcm PCM handle
6488 * \param params Software configuration container
6489 * \param val Start mode
6490 * \return 0 otherwise a negative error code
6492 int snd_pcm_sw_params_set_start_mode(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_start_t val)
6494 assert(pcm && params);
6496 case SND_PCM_START_DATA:
6497 params->start_threshold = 1;
6499 case SND_PCM_START_EXPLICIT:
6500 params->start_threshold = pcm->boundary;
6503 snd_check(PCM, "invalid start mode value %d", val);
6510 link_warning(snd_pcm_sw_params_set_start_mode, "Warning: start_mode is deprecated, consider to use start_threshold");
6514 * \brief (DEPRECATED) Get start mode from a software configuration container
6515 * \param params Software configuration container
6516 * \return start mode
6518 snd_pcm_start_t snd_pcm_sw_params_get_start_mode(const snd_pcm_sw_params_t *params)
6522 return params->start_threshold > 1024 * 1024 ? SND_PCM_START_EXPLICIT : SND_PCM_START_DATA;
6526 link_warning(snd_pcm_sw_params_get_start_mode, "Warning: start_mode is deprecated, consider to use start_threshold");
6530 * \brief (DEPRECATED) Set xrun mode inside a software configuration container
6531 * \param pcm PCM handle
6532 * \param params Software configuration container
6533 * \param val Xrun mode
6534 * \return 0 otherwise a negative error code
6537 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)
6539 int snd_pcm_sw_params_set_xrun_mode(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_xrun_t val)
6542 assert(pcm && params);
6544 case SND_PCM_XRUN_STOP:
6545 params->stop_threshold = pcm->buffer_size;
6547 case SND_PCM_XRUN_NONE:
6548 params->stop_threshold = pcm->boundary;
6551 snd_check(PCM, "invalid xrun mode value %d", val);
6558 link_warning(snd_pcm_sw_params_set_xrun_mode, "Warning: xrun_mode is deprecated, consider to use stop_threshold");
6562 * \brief (DEPRECATED) Get xrun mode from a software configuration container
6563 * \param params Software configuration container
6566 snd_pcm_xrun_t snd_pcm_sw_params_get_xrun_mode(const snd_pcm_sw_params_t *params)
6570 return params->stop_threshold > 1024 * 1024 ? SND_PCM_XRUN_NONE : SND_PCM_XRUN_STOP;
6574 link_warning(snd_pcm_sw_params_get_xrun_mode, "Warning: xrun_mode is deprecated, consider to use stop_threshold");
6578 * \brief Set timestamp mode inside a software configuration container
6579 * \param pcm PCM handle
6580 * \param params Software configuration container
6581 * \param val Timestamp mode
6582 * \return 0 otherwise a negative error code
6585 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)
6587 int snd_pcm_sw_params_set_tstamp_mode(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_tstamp_t val)
6590 assert(pcm && params);
6591 if (CHECK_SANITY(val > SND_PCM_TSTAMP_LAST)) {
6592 snd_check(PCM, "invalid tstamp_mode value %d", val);
6595 params->tstamp_mode = val;
6600 * \brief Get timestamp mode from a software configuration container
6601 * \param params Software configuration container
6602 * \param val Returned timestamp
6603 * \return 0 otherwise a negative error code
6606 EXPORT_SYMBOL int INTERNAL(snd_pcm_sw_params_get_tstamp_mode)(const snd_pcm_sw_params_t *params, snd_pcm_tstamp_t *val)
6608 int snd_pcm_sw_params_get_tstamp_mode(const snd_pcm_sw_params_t *params, snd_pcm_tstamp_t *val)
6611 assert(params && val);
6612 *val = params->tstamp_mode;
6617 * \brief Set timestamp type inside a software configuration container
6618 * \param pcm PCM handle
6619 * \param params Software configuration container
6620 * \param val Timestamp type
6621 * \return 0 otherwise a negative error code
6623 int snd_pcm_sw_params_set_tstamp_type(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_tstamp_type_t val)
6625 assert(pcm && params);
6626 if (CHECK_SANITY(val > SND_PCM_TSTAMP_TYPE_LAST)) {
6627 snd_check(PCM, "invalid tstamp_type value %d", val);
6630 params->tstamp_type = val;
6635 * \brief Get timestamp type from a software configuration container
6636 * \param params Software configuration container
6637 * \param val Returned timestamp type
6638 * \return 0 otherwise a negative error code
6640 int snd_pcm_sw_params_get_tstamp_type(const snd_pcm_sw_params_t *params, snd_pcm_tstamp_type_t *val)
6642 assert(params && val);
6643 *val = params->tstamp_type;
6648 * \brief (DEPRECATED) Set minimum number of ticks to sleep inside a software configuration container
6649 * \param pcm PCM handle
6650 * \param params Software configuration container
6651 * \param val Minimum ticks to sleep or 0 to disable the use of tick timer
6652 * \return 0 otherwise a negative error code
6655 int snd_pcm_sw_params_set_sleep_min(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_sw_params_t *params ATTRIBUTE_UNUSED, unsigned int val ATTRIBUTE_UNUSED)
6657 int snd_pcm_sw_params_set_sleep_min(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, unsigned int val)
6664 * \brief (DEPRECATED) Get minimum numbers of ticks to sleep from a software configuration container
6665 * \param params Software configuration container
6666 * \param val returned minimum number of ticks to sleep or 0 if tick timer is disabled
6667 * \return 0 otherwise a negative error code
6670 EXPORT_SYMBOL int INTERNAL(snd_pcm_sw_params_get_sleep_min)(const snd_pcm_sw_params_t *params ATTRIBUTE_UNUSED, unsigned int *val)
6672 int snd_pcm_sw_params_get_sleep_min(const snd_pcm_sw_params_t *params, unsigned int *val)
6680 * \brief Set avail min inside a software configuration container
6681 * \param pcm PCM handle
6682 * \param params Software configuration container
6683 * \param val Minimum avail frames to consider PCM ready
6684 * \return 0 otherwise a negative error code
6686 * Note: This is similar to setting an OSS wakeup point. The valid
6687 * values for 'val' are determined by the specific hardware. Most PC
6688 * sound cards can only accept power of 2 frame counts (i.e. 512,
6689 * 1024, 2048). You cannot use this as a high resolution timer - it
6690 * is limited to how often the sound card hardware raises an
6694 EXPORT_SYMBOL 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)
6696 int snd_pcm_sw_params_set_avail_min(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
6699 assert(pcm && params);
6700 /* Fix avail_min if it's below period size. The period_size
6701 * defines the minimal wake-up timing accuracy, so it doesn't
6702 * make sense to set below that.
6704 if (val < pcm->period_size)
6705 val = pcm->period_size;
6706 params->avail_min = val;
6711 * \brief Get avail min from a software configuration container
6712 * \param params Software configuration container
6713 * \param val returned minimum available frames to consider PCM ready
6714 * \return 0 otherwise a negative error code
6716 * This is a threshold value when the PCM stream is considered as ready for
6717 * another read/write operation or poll event.
6720 EXPORT_SYMBOL int INTERNAL(snd_pcm_sw_params_get_avail_min)(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6722 int snd_pcm_sw_params_get_avail_min(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6725 assert(params && val);
6726 *val = params->avail_min;
6731 * \brief Set period event inside a software configuration container
6732 * \param pcm PCM handle
6733 * \param params Software configuration container
6734 * \param val 0 = disable period event, 1 = enable period event
6735 * \return 0 otherwise a negative error code
6737 * An poll (select) wakeup event is raised if enabled.
6739 int snd_pcm_sw_params_set_period_event(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, int val)
6741 assert(pcm && params);
6742 sw_set_period_event(params, val);
6747 * \brief Get period event from a software configuration container
6748 * \param params Software configuration container
6749 * \param val returned period event state
6750 * \return 0 otherwise a negative error code
6752 int snd_pcm_sw_params_get_period_event(const snd_pcm_sw_params_t *params, int *val)
6754 assert(params && val);
6755 *val = sw_get_period_event(params);
6760 * \brief (DEPRECATED) Set xfer align inside a software configuration container
6761 * \param pcm PCM handle
6762 * \param params Software configuration container
6763 * \param val Chunk size (frames are attempted to be transferred in chunks)
6764 * \return 0 otherwise a negative error code
6767 EXPORT_SYMBOL int snd_pcm_sw_params_set_xfer_align(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_sw_params_t *params ATTRIBUTE_UNUSED, snd_pcm_uframes_t val ATTRIBUTE_UNUSED)
6769 int snd_pcm_sw_params_set_xfer_align(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
6776 * \brief (DEPRECATED) Get xfer align from a software configuration container
6777 * \param params Software configuration container
6778 * \param val returned chunk size (frames are attempted to be transferred in chunks)
6779 * \return 0 otherwise a negative error code
6782 EXPORT_SYMBOL int INTERNAL(snd_pcm_sw_params_get_xfer_align)(const snd_pcm_sw_params_t *params ATTRIBUTE_UNUSED, snd_pcm_uframes_t *val)
6784 int snd_pcm_sw_params_get_xfer_align(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6792 * \brief Set start threshold inside a software configuration container
6793 * \param pcm PCM handle
6794 * \param params Software configuration container
6795 * \param val Start threshold in frames
6796 * \return 0 otherwise a negative error code
6798 * PCM is automatically started when playback frames available to PCM
6799 * are >= threshold or when requested capture frames are >= threshold
6802 EXPORT_SYMBOL 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)
6804 int snd_pcm_sw_params_set_start_threshold(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
6807 assert(pcm && params);
6808 params->start_threshold = val;
6813 * \brief Get start threshold from a software configuration container
6814 * \param params Software configuration container
6815 * \param val Returned start threshold in frames
6816 * \return 0 otherwise a negative error code
6818 * PCM is automatically started when playback frames available to PCM
6819 * are >= threshold or when requested capture frames are >= threshold
6822 EXPORT_SYMBOL int INTERNAL(snd_pcm_sw_params_get_start_threshold)(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6824 int snd_pcm_sw_params_get_start_threshold(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6828 *val = params->start_threshold;
6834 * \brief Set stop threshold inside a software configuration container
6835 * \param pcm PCM handle
6836 * \param params Software configuration container
6837 * \param val Stop threshold in frames
6838 * \return 0 otherwise a negative error code
6840 * PCM is automatically stopped in #SND_PCM_STATE_XRUN state when available
6841 * frames is >= threshold. If the stop threshold is equal to boundary (also
6842 * software parameter - sw_param) then automatic stop will be disabled
6843 * (thus device will do the endless loop in the ring buffer).
6846 EXPORT_SYMBOL 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)
6848 int snd_pcm_sw_params_set_stop_threshold(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
6851 assert(pcm && params);
6852 params->stop_threshold = val;
6857 * \brief Get stop threshold from a software configuration container
6858 * \param params Software configuration container
6859 * \param val Returned stop threshold in frames
6860 * \return 0 otherwise a negative error code
6862 * PCM is automatically stopped in #SND_PCM_STATE_XRUN state when available
6863 * frames is >= threshold. If the stop threshold is equal to boundary (also
6864 * software parameter - sw_param) then automatic stop will be disabled
6865 * (thus device will do the endless loop in the ring buffer).
6868 EXPORT_SYMBOL int INTERNAL(snd_pcm_sw_params_get_stop_threshold)(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6870 int snd_pcm_sw_params_get_stop_threshold(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6874 *val = params->stop_threshold;
6880 * \brief Set silence threshold inside a software configuration container
6881 * \param pcm PCM handle
6882 * \param params Software configuration container
6883 * \param val Silence threshold in frames
6884 * \return 0 otherwise a negative error code
6886 * A portion of playback buffer is overwritten with silence (see
6887 * #snd_pcm_sw_params_set_silence_size) when playback underrun is nearer
6888 * than silence threshold.
6891 EXPORT_SYMBOL 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)
6893 int snd_pcm_sw_params_set_silence_threshold(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
6896 assert(pcm && params);
6897 if (CHECK_SANITY(val >= pcm->buffer_size)) {
6898 snd_check(PCM, "invalid silent_threshold value %ld (buffer_size = %ld)",
6899 val, pcm->buffer_size);
6903 params->silence_threshold = val;
6908 * \brief Get silence threshold from a software configuration container
6909 * \param params Software configuration container
6910 * \param val Returned silence threshold in frames
6911 * \return 0 otherwise a negative error value
6913 * A portion of playback buffer is overwritten with silence (see
6914 * #snd_pcm_sw_params_set_silence_size) when playback underrun is nearer
6915 * than silence threshold.
6918 EXPORT_SYMBOL int INTERNAL(snd_pcm_sw_params_get_silence_threshold)(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6920 int snd_pcm_sw_params_get_silence_threshold(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6923 assert(params && val);
6924 *val = params->silence_threshold;
6930 * \brief Set silence size inside a software configuration container
6931 * \param pcm PCM handle
6932 * \param params Software configuration container
6933 * \param val Silence size in frames (0 for disabled)
6934 * \return 0 otherwise a negative error code
6936 * A portion of playback buffer is overwritten with silence when playback
6937 * underrun is nearer than silence threshold (see
6938 * #snd_pcm_sw_params_set_silence_threshold)
6940 * When drain silence (see #snd_pcm_hw_params_get_drain_silence) is disabled,
6941 * this will also apply for draining, i.e. silence is written also when the
6942 * drain end is nearer than the silence threshold.
6944 * The special case is when silence size value is equal or greater than
6945 * boundary. The unused portion of the ring buffer (initial written samples
6946 * are untouched) is filled with silence at start. Later, only just processed
6947 * sample area is filled with silence. Note: silence_threshold must be set to zero.
6950 EXPORT_SYMBOL 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)
6952 int snd_pcm_sw_params_set_silence_size(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
6955 assert(pcm && params);
6956 if (CHECK_SANITY(val < pcm->boundary && val > pcm->buffer_size)) {
6957 snd_check(PCM, "invalid silence_size %ld (boundary %ld, buffer_size %ld)",
6958 val, pcm->boundary, pcm->buffer_size);
6962 params->silence_size = val;
6967 * \brief Get silence size from a software configuration container
6968 * \param params Software configuration container
6969 * \param val Returned silence size in frames (0 for disabled)
6970 * \return 0 otherwise a negative error code
6972 * A portion of playback buffer is overwritten with silence when playback
6973 * underrun is nearer than silence threshold (see
6974 * #snd_pcm_sw_params_set_silence_threshold)
6977 EXPORT_SYMBOL int INTERNAL(snd_pcm_sw_params_get_silence_size)(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6979 int snd_pcm_sw_params_get_silence_size(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6983 *val = params->silence_size;
6989 * \brief get size of #snd_pcm_status_t
6990 * \return size in bytes
6992 size_t snd_pcm_status_sizeof()
6994 return sizeof(snd_pcm_status_t);
6998 * \brief allocate an invalid #snd_pcm_status_t using standard malloc
6999 * \param ptr returned pointer
7000 * \return 0 on success otherwise negative error code
7002 int snd_pcm_status_malloc(snd_pcm_status_t **ptr)
7005 *ptr = calloc(1, sizeof(snd_pcm_status_t));
7012 * \brief frees a previously allocated #snd_pcm_status_t
7013 * \param obj pointer to object to free
7015 void snd_pcm_status_free(snd_pcm_status_t *obj)
7021 * \brief copy one #snd_pcm_status_t to another
7022 * \param dst pointer to destination
7023 * \param src pointer to source
7025 void snd_pcm_status_copy(snd_pcm_status_t *dst, const snd_pcm_status_t *src)
7032 * \brief Get state from a PCM status container (see #snd_pcm_state)
7033 * \param obj #snd_pcm_status_t pointer
7036 snd_pcm_state_t snd_pcm_status_get_state(const snd_pcm_status_t *obj)
7043 * \brief Get trigger timestamp from a PCM status container
7044 * \param obj #snd_pcm_status_t pointer
7045 * \param ptr Pointer to returned timestamp
7047 * Trigger means a PCM state transition (from stopped to running or
7048 * versa vice). It applies also to pause and suspend. In other words,
7049 * timestamp contains time when stream started or when it was stopped.
7051 void snd_pcm_status_get_trigger_tstamp(const snd_pcm_status_t *obj, snd_timestamp_t *ptr)
7054 ptr->tv_sec = obj->trigger_tstamp.tv_sec;
7055 ptr->tv_usec = obj->trigger_tstamp.tv_nsec / 1000L;
7059 * \brief Get trigger hi-res timestamp from a PCM status container
7060 * \param obj #snd_pcm_status_t pointer
7061 * \param ptr Pointer to returned timestamp
7063 * Trigger means a PCM state transition (from stopped to running or
7064 * versa vice). It applies also to pause and suspend. In other words,
7065 * timestamp contains time when stream started or when it was stopped.
7068 EXPORT_SYMBOL void INTERNAL(snd_pcm_status_get_trigger_htstamp)(const snd_pcm_status_t *obj, snd_htimestamp_t *ptr)
7070 void snd_pcm_status_get_trigger_htstamp(const snd_pcm_status_t *obj, snd_htimestamp_t *ptr)
7074 *ptr = obj->trigger_tstamp;
7076 use_default_symbol_version(__snd_pcm_status_get_trigger_htstamp, snd_pcm_status_get_trigger_htstamp, ALSA_0.9.0rc8);
7079 * \brief Get "now" timestamp from a PCM status container
7080 * \param obj #snd_pcm_status_t pointer
7081 * \param ptr Pointer to returned timestamp
7083 void snd_pcm_status_get_tstamp(const snd_pcm_status_t *obj, snd_timestamp_t *ptr)
7086 ptr->tv_sec = obj->tstamp.tv_sec;
7087 ptr->tv_usec = obj->tstamp.tv_nsec / 1000L;
7091 * \brief Get "now" hi-res timestamp from a PCM status container
7092 * \param obj pointer to #snd_pcm_status_t
7093 * \param ptr Pointer to returned timestamp
7096 EXPORT_SYMBOL void INTERNAL(snd_pcm_status_get_htstamp)(const snd_pcm_status_t *obj, snd_htimestamp_t *ptr)
7098 void snd_pcm_status_get_htstamp(const snd_pcm_status_t *obj, snd_htimestamp_t *ptr)
7104 use_default_symbol_version(__snd_pcm_status_get_htstamp, snd_pcm_status_get_htstamp, ALSA_0.9.0rc8);
7107 * \brief Get "now" hi-res audio timestamp from a PCM status container
7108 * \param obj pointer to #snd_pcm_status_t
7109 * \param ptr Pointer to returned timestamp
7111 void snd_pcm_status_get_audio_htstamp(const snd_pcm_status_t *obj, snd_htimestamp_t *ptr)
7114 *ptr = obj->audio_tstamp;
7118 * \brief Get "now" hi-res driver timestamp from a PCM status container. Defines when the status
7119 * was generated by driver, may differ from normal timestamp.
7120 * \param obj pointer to #snd_pcm_status_t
7121 * \param ptr Pointer to returned timestamp
7123 void snd_pcm_status_get_driver_htstamp(const snd_pcm_status_t *obj, snd_htimestamp_t *ptr)
7126 *ptr = obj->driver_tstamp;
7130 * \brief Get audio_tstamp_report from a PCM status container
7131 * \param obj pointer to #snd_pcm_status_t
7132 * \param audio_tstamp_report Pointer to returned report
7134 void snd_pcm_status_get_audio_htstamp_report(const snd_pcm_status_t *obj,
7135 snd_pcm_audio_tstamp_report_t *audio_tstamp_report)
7137 assert(obj && audio_tstamp_report);
7138 snd_pcm_unpack_audio_tstamp_report(obj->audio_tstamp_data,
7139 obj->audio_tstamp_accuracy,
7140 audio_tstamp_report);
7144 * \brief set audio_tstamp_config from a PCM status container
7145 * \param obj pointer to #snd_pcm_status_t
7146 * \param audio_tstamp_config Pointer to config (valid fields are type_requested and report_delay)
7148 void snd_pcm_status_set_audio_htstamp_config(snd_pcm_status_t *obj,
7149 snd_pcm_audio_tstamp_config_t *audio_tstamp_config)
7151 assert(obj && audio_tstamp_config);
7152 snd_pcm_pack_audio_tstamp_config(&obj->audio_tstamp_data, audio_tstamp_config);
7156 * \brief Get delay from a PCM status container (see #snd_pcm_delay)
7157 * \return Delay in frames
7159 * Delay is distance between current application frame position and
7160 * sound frame position.
7161 * It's positive and less than buffer size in normal situation,
7162 * negative on playback underrun and greater than buffer size on
7165 snd_pcm_sframes_t snd_pcm_status_get_delay(const snd_pcm_status_t *obj)
7172 * \brief Get number of frames available from a PCM status container (see #snd_pcm_avail_update)
7173 * \return Number of frames ready to be read/written
7175 snd_pcm_uframes_t snd_pcm_status_get_avail(const snd_pcm_status_t *obj)
7182 * \brief Get maximum number of frames available from a PCM status container after last #snd_pcm_status call
7183 * \return Maximum number of frames ready to be read/written
7185 * This value returns the peak for the available frames between #snd_pcm_status calls.
7187 snd_pcm_uframes_t snd_pcm_status_get_avail_max(const snd_pcm_status_t *obj)
7190 return obj->avail_max;
7194 * \brief Get count of ADC overrange detections since last call
7195 * \return Count of ADC overrange detections
7197 snd_pcm_uframes_t snd_pcm_status_get_overrange(const snd_pcm_status_t *obj)
7200 return obj->overrange;
7204 * \brief get size of #snd_pcm_info_t
7205 * \return size in bytes
7207 size_t snd_pcm_info_sizeof()
7209 return sizeof(snd_pcm_info_t);
7213 * \brief allocate an invalid #snd_pcm_info_t using standard malloc
7214 * \param ptr returned pointer
7215 * \return 0 on success otherwise negative error code
7217 int snd_pcm_info_malloc(snd_pcm_info_t **ptr)
7220 *ptr = calloc(1, sizeof(snd_pcm_info_t));
7227 * \brief frees a previously allocated #snd_pcm_info_t
7228 * \param obj pointer to object to free
7230 void snd_pcm_info_free(snd_pcm_info_t *obj)
7236 * \brief copy one #snd_pcm_info_t to another
7237 * \param dst pointer to destination
7238 * \param src pointer to source
7240 void snd_pcm_info_copy(snd_pcm_info_t *dst, const snd_pcm_info_t *src)
7247 * \brief Get device from a PCM info container
7248 * \param obj PCM info container
7249 * \return device number
7251 unsigned int snd_pcm_info_get_device(const snd_pcm_info_t *obj)
7258 * \brief Get subdevice from a PCM info container
7259 * \param obj PCM info container
7260 * \return subdevice number
7262 unsigned int snd_pcm_info_get_subdevice(const snd_pcm_info_t *obj)
7265 return obj->subdevice;
7269 * \brief Get stream (direction) from a PCM info container
7270 * \param obj PCM info container
7273 snd_pcm_stream_t snd_pcm_info_get_stream(const snd_pcm_info_t *obj)
7280 * \brief Get card from a PCM info container
7281 * \param obj PCM info container
7282 * \return card number otherwise a negative error code if not associable to a card
7284 int snd_pcm_info_get_card(const snd_pcm_info_t *obj)
7291 * \brief Get id from a PCM info container
7292 * \param obj PCM info container
7293 * \return short id of PCM
7295 const char *snd_pcm_info_get_id(const snd_pcm_info_t *obj)
7298 return (const char *)obj->id;
7302 * \brief Get name from a PCM info container
7303 * \param obj PCM info container
7304 * \return name of PCM
7306 const char *snd_pcm_info_get_name(const snd_pcm_info_t *obj)
7309 return (const char *)obj->name;
7313 * \brief Get subdevice name from a PCM info container
7314 * \param obj PCM info container
7315 * \return name of used PCM subdevice
7317 const char *snd_pcm_info_get_subdevice_name(const snd_pcm_info_t *obj)
7320 return (const char *)obj->subname;
7324 * \brief Get class from a PCM info container
7325 * \param obj PCM info container
7326 * \return class of PCM
7328 snd_pcm_class_t snd_pcm_info_get_class(const snd_pcm_info_t *obj)
7331 return obj->dev_class;
7335 * \brief Get subclass from a PCM info container
7336 * \param obj PCM info container
7337 * \return subclass of PCM
7339 snd_pcm_subclass_t snd_pcm_info_get_subclass(const snd_pcm_info_t *obj)
7342 return obj->dev_subclass;
7346 * \brief Get subdevices count from a PCM info container
7347 * \param obj PCM info container
7348 * \return subdevices total count of PCM
7350 unsigned int snd_pcm_info_get_subdevices_count(const snd_pcm_info_t *obj)
7353 return obj->subdevices_count;
7357 * \brief Get available subdevices count from a PCM info container
7358 * \param obj PCM info container
7359 * \return available subdevices count of PCM
7361 unsigned int snd_pcm_info_get_subdevices_avail(const snd_pcm_info_t *obj)
7364 return obj->subdevices_avail;
7368 * \brief (DEPRECATED) Get hardware synchronization ID from a PCM info container
7369 * \param obj PCM info container
7370 * \return hardware synchronization ID
7372 snd_pcm_sync_id_t snd_pcm_info_get_sync(const snd_pcm_info_t *obj)
7374 snd_pcm_sync_id_t res;
7376 bzero(&res, sizeof(res));
7380 link_warning(snd_pcm_info_get_sync, "Warning: snd_pcm_info_get_sync is deprecated, consider to use snd_pcm_hw_params_get_sync");
7384 * \brief Set wanted device inside a PCM info container (see #snd_ctl_pcm_info)
7385 * \param obj PCM info container
7386 * \param val Device number
7388 void snd_pcm_info_set_device(snd_pcm_info_t *obj, unsigned int val)
7395 * \brief Set wanted subdevice inside a PCM info container (see #snd_ctl_pcm_info)
7396 * \param obj PCM info container
7397 * \param val Subdevice number
7399 void snd_pcm_info_set_subdevice(snd_pcm_info_t *obj, unsigned int val)
7402 obj->subdevice = val;
7406 * \brief Set wanted stream inside a PCM info container (see #snd_ctl_pcm_info)
7407 * \param obj PCM info container
7410 void snd_pcm_info_set_stream(snd_pcm_info_t *obj, snd_pcm_stream_t val)
7417 * \brief Application request to access a portion of direct (mmap) area
7418 * \param pcm PCM handle
7419 * \param areas Returned mmap channel areas
7420 * \param offset Returned mmap area offset in area steps (== frames)
7421 * \param frames mmap area portion size in frames (wanted on entry, contiguous available on exit)
7422 * \return 0 on success otherwise a negative error code
7424 * It is necessary to call the snd_pcm_avail_update() function directly before
7425 * this call. Otherwise, this function can return a wrong count of available frames.
7427 * The function should be called before a sample-direct area can be accessed.
7428 * The resulting size parameter is always less or equal to the input count of frames
7429 * and can be zero, if no frames can be processed (the ring buffer is full).
7431 * See the snd_pcm_mmap_commit() function to finish the frame processing in
7434 * The function is thread-safe when built with the proper option.
7436 int snd_pcm_mmap_begin(snd_pcm_t *pcm,
7437 const snd_pcm_channel_area_t **areas,
7438 snd_pcm_uframes_t *offset,
7439 snd_pcm_uframes_t *frames)
7443 err = bad_pcm_state(pcm, P_STATE_RUNNABLE, 0);
7446 snd_pcm_lock(pcm->fast_op_arg);
7447 err = __snd_pcm_mmap_begin(pcm, areas, offset, frames);
7448 snd_pcm_unlock(pcm->fast_op_arg);
7453 int __snd_pcm_mmap_begin_generic(snd_pcm_t *pcm, const snd_pcm_channel_area_t **areas,
7454 snd_pcm_uframes_t *offset, snd_pcm_uframes_t *frames)
7456 snd_pcm_uframes_t cont;
7457 snd_pcm_uframes_t f;
7458 snd_pcm_uframes_t avail;
7459 const snd_pcm_channel_area_t *xareas;
7461 assert(pcm && areas && offset && frames);
7463 /* fallback for plugins that do not specify new callback */
7464 xareas = snd_pcm_mmap_areas(pcm);
7468 *offset = *pcm->appl.ptr % pcm->buffer_size;
7469 avail = snd_pcm_mmap_avail(pcm);
7470 if (avail > pcm->buffer_size)
7471 avail = pcm->buffer_size;
7472 cont = pcm->buffer_size - *offset;
7482 /* locked version */
7483 int __snd_pcm_mmap_begin(snd_pcm_t *pcm, const snd_pcm_channel_area_t **areas,
7484 snd_pcm_uframes_t *offset, snd_pcm_uframes_t *frames)
7486 assert(pcm && areas && offset && frames);
7488 if (pcm->fast_ops->mmap_begin)
7489 return pcm->fast_ops->mmap_begin(pcm->fast_op_arg, areas, offset, frames);
7491 return __snd_pcm_mmap_begin_generic(pcm, areas, offset, frames);
7496 * \brief Application has completed the access to area requested with #snd_pcm_mmap_begin
7497 * \param pcm PCM handle
7498 * \param offset area offset in area steps (== frames)
7499 * \param frames area portion size in frames
7500 * \return count of transferred frames otherwise a negative error code
7502 * You should pass this function the offset value that
7503 * snd_pcm_mmap_begin() returned. The frames parameter should hold the
7504 * number of frames you have written or read to/from the audio
7505 * buffer. The frames parameter must never exceed the contiguous frames
7506 * count that snd_pcm_mmap_begin() returned. Each call to snd_pcm_mmap_begin()
7507 * must be followed by a call to snd_pcm_mmap_commit().
7512 const snd_pcm_area_t *areas;
7513 snd_pcm_sframes_t avail, size, commitres;
7514 snd_pcm_uframes_t offset, frames;
7517 avail = snd_pcm_avail_update(pcm);
7520 // at this point, we can transfer at least 'avail' frames
7522 // we want to process frames in chunks (period_size)
7523 if (avail < period_size)
7526 // it is possible that contiguous areas are smaller, thus we use a loop
7530 err = snd_pcm_mmap_begin(pcm_handle, &areas, &offset, &frames);
7533 // this function fills the areas from offset with count of frames
7534 generate_sine(areas, offset, frames, &phase);
7535 commitres = snd_pcm_mmap_commit(pcm_handle, offset, frames);
7536 if (commitres < 0 || commitres != frames)
7537 error(commitres >= 0 ? -EPIPE : commitres);
7544 * Look to the \link example_test_pcm Sine-wave generator \endlink example
7545 * for more details about the generate_sine function.
7547 * The function is thread-safe when built with the proper option.
7549 snd_pcm_sframes_t snd_pcm_mmap_commit(snd_pcm_t *pcm,
7550 snd_pcm_uframes_t offset,
7551 snd_pcm_uframes_t frames)
7553 snd_pcm_sframes_t result;
7556 err = bad_pcm_state(pcm, P_STATE_RUNNABLE, 0);
7559 snd_pcm_lock(pcm->fast_op_arg);
7560 result = __snd_pcm_mmap_commit(pcm, offset, frames);
7561 snd_pcm_unlock(pcm->fast_op_arg);
7567 snd_pcm_sframes_t __snd_pcm_mmap_commit(snd_pcm_t *pcm,
7568 snd_pcm_uframes_t offset,
7569 snd_pcm_uframes_t frames)
7572 if (CHECK_SANITY(offset != *pcm->appl.ptr % pcm->buffer_size)) {
7573 snd_check(PCM, "commit offset (%ld) doesn't match with appl_ptr (%ld) %% buf_size (%ld)",
7574 offset, *pcm->appl.ptr, pcm->buffer_size);
7578 if (CHECK_SANITY(frames > snd_pcm_mmap_avail(pcm))) {
7579 snd_check(PCM, "commit frames (%ld) overflow (avail = %ld)", frames,
7580 snd_pcm_mmap_avail(pcm));
7584 if (pcm->fast_ops->mmap_commit)
7585 return pcm->fast_ops->mmap_commit(pcm->fast_op_arg, offset, frames);
7590 int _snd_pcm_poll_descriptor(snd_pcm_t *pcm)
7593 return pcm->poll_fd;
7596 void snd_pcm_areas_from_buf(snd_pcm_t *pcm, snd_pcm_channel_area_t *areas,
7599 unsigned int channel;
7600 unsigned int channels;
7603 channels = pcm->channels;
7604 for (channel = 0; channel < channels; ++channel, ++areas) {
7606 areas->first = channel * pcm->sample_bits;
7607 areas->step = pcm->frame_bits;
7609 snd_pcm_unlock(pcm);
7612 void snd_pcm_areas_from_bufs(snd_pcm_t *pcm, snd_pcm_channel_area_t *areas,
7615 unsigned int channel;
7616 unsigned int channels;
7619 channels = pcm->channels;
7620 for (channel = 0; channel < channels; ++channel, ++areas, ++bufs) {
7621 areas->addr = *bufs;
7623 areas->step = pcm->sample_bits;
7625 snd_pcm_unlock(pcm);
7628 snd_pcm_sframes_t snd_pcm_read_areas(snd_pcm_t *pcm, const snd_pcm_channel_area_t *areas,
7629 snd_pcm_uframes_t offset, snd_pcm_uframes_t size,
7630 snd_pcm_xfer_areas_func_t func)
7632 snd_pcm_uframes_t xfer = 0;
7633 snd_pcm_sframes_t err = 0;
7634 snd_pcm_state_t state;
7639 __snd_pcm_lock(pcm->fast_op_arg); /* forced lock */
7641 snd_pcm_uframes_t frames;
7642 snd_pcm_sframes_t avail;
7644 state = __snd_pcm_state(pcm);
7646 case SND_PCM_STATE_PREPARED:
7647 err = __snd_pcm_start(pcm);
7651 case SND_PCM_STATE_RUNNING:
7652 err = __snd_pcm_hwsync(pcm);
7656 case SND_PCM_STATE_DRAINING:
7657 case SND_PCM_STATE_PAUSED:
7660 err = pcm_state_to_error(state);
7665 avail = __snd_pcm_avail_update(pcm);
7671 if (state == SND_PCM_STATE_DRAINING)
7673 if (pcm->mode & SND_PCM_NONBLOCK) {
7678 err = __snd_pcm_wait_in_lock(pcm, SND_PCM_WAIT_IO);
7685 if (frames > (snd_pcm_uframes_t) avail)
7687 /* frames must be at least 1 here (see while condition) */
7688 err = func(pcm, areas, offset, frames);
7697 __snd_pcm_unlock(pcm->fast_op_arg);
7698 return xfer > 0 ? (snd_pcm_sframes_t) xfer : snd_pcm_check_error(pcm, err);
7701 snd_pcm_sframes_t snd_pcm_write_areas(snd_pcm_t *pcm, const snd_pcm_channel_area_t *areas,
7702 snd_pcm_uframes_t offset, snd_pcm_uframes_t size,
7703 snd_pcm_xfer_areas_func_t func)
7705 snd_pcm_uframes_t xfer = 0;
7706 snd_pcm_sframes_t err = 0;
7707 snd_pcm_state_t state;
7712 __snd_pcm_lock(pcm->fast_op_arg); /* forced lock */
7714 snd_pcm_uframes_t frames;
7715 snd_pcm_sframes_t avail;
7717 state = __snd_pcm_state(pcm);
7719 case SND_PCM_STATE_PREPARED:
7720 case SND_PCM_STATE_PAUSED:
7722 case SND_PCM_STATE_RUNNING:
7723 err = __snd_pcm_hwsync(pcm);
7728 err = pcm_state_to_error(state);
7733 avail = __snd_pcm_avail_update(pcm);
7738 if (state == SND_PCM_STATE_RUNNING &&
7739 size > (snd_pcm_uframes_t)avail) {
7740 if (snd_pcm_may_wait_for_avail_min(pcm, avail)) {
7741 if (pcm->mode & SND_PCM_NONBLOCK) {
7746 err = snd_pcm_wait_nocheck(pcm, SND_PCM_WAIT_IO);
7751 /* the snd_pcm_may_wait_for_avail_min may check against the
7752 * updated hw.ptr (slaves), get the avail again here
7754 avail = __snd_pcm_avail_update(pcm);
7761 if (frames > (snd_pcm_uframes_t) avail)
7765 err = func(pcm, areas, offset, frames);
7769 if (state == SND_PCM_STATE_PREPARED) {
7770 snd_pcm_sframes_t hw_avail = pcm->buffer_size - avail;
7772 /* some plugins might automatically start the stream */
7773 state = __snd_pcm_state(pcm);
7774 if (state == SND_PCM_STATE_PREPARED &&
7776 (snd_pcm_uframes_t) hw_avail >= pcm->start_threshold) {
7777 err = __snd_pcm_start(pcm);
7787 __snd_pcm_unlock(pcm->fast_op_arg);
7788 return xfer > 0 ? (snd_pcm_sframes_t) xfer : snd_pcm_check_error(pcm, err);
7791 snd_pcm_uframes_t _snd_pcm_mmap_hw_ptr(snd_pcm_t *pcm)
7793 return *pcm->hw.ptr;
7796 snd_pcm_uframes_t _snd_pcm_boundary(snd_pcm_t *pcm)
7798 return pcm->boundary;
7802 link_warning(_snd_pcm_mmap_hw_ptr, "Warning: _snd_pcm_mmap_hw_ptr() is deprecated, consider to not use this function");
7803 link_warning(_snd_pcm_boundary, "Warning: _snd_pcm_boundary() is deprecated, consider to use snd_pcm_sw_params_current()");
7806 static const char *const names[SND_PCM_HW_PARAM_LAST_INTERVAL + 1] = {
7807 [SND_PCM_HW_PARAM_FORMAT] = "format",
7808 [SND_PCM_HW_PARAM_CHANNELS] = "channels",
7809 [SND_PCM_HW_PARAM_RATE] = "rate",
7810 [SND_PCM_HW_PARAM_PERIOD_TIME] = "period_time",
7811 [SND_PCM_HW_PARAM_PERIOD_SIZE] = "period_size",
7812 [SND_PCM_HW_PARAM_BUFFER_TIME] = "buffer_time",
7813 [SND_PCM_HW_PARAM_BUFFER_SIZE] = "buffer_size",
7814 [SND_PCM_HW_PARAM_PERIODS] = "periods"
7817 int snd_pcm_slave_conf(snd_config_t *root, snd_config_t *conf,
7818 snd_config_t **_pcm_conf, unsigned int count, ...)
7820 snd_config_iterator_t i, next;
7829 snd_config_t *pcm_conf = NULL;
7836 if (snd_config_get_string(conf, &str) >= 0) {
7837 err = snd_config_search_definition(root, "pcm_slave", str, &conf);
7839 snd_error(PCM, "Invalid slave definition");
7844 if (snd_config_get_type(conf) != SND_CONFIG_TYPE_COMPOUND) {
7845 snd_error(PCM, "Invalid slave definition");
7849 va_start(args, count);
7850 for (k = 0; k < count; ++k) {
7851 fields[k].index = va_arg(args, int);
7852 fields[k].flags = va_arg(args, int);
7853 fields[k].ptr = va_arg(args, void *);
7854 fields[k].present = 0;
7857 snd_config_for_each(i, next, conf) {
7858 snd_config_t *n = snd_config_iterator_entry(i);
7860 if (snd_config_get_id(n, &id) < 0)
7862 if (strcmp(id, "comment") == 0)
7864 if (strcmp(id, "pcm") == 0) {
7865 if (pcm_conf != NULL)
7866 snd_config_delete(pcm_conf);
7867 if ((err = snd_config_copy(&pcm_conf, n)) < 0)
7871 for (k = 0; k < count; ++k) {
7872 unsigned int idx = fields[k].index;
7874 assert(idx < SND_PCM_HW_PARAM_LAST_INTERVAL);
7876 if (strcmp(id, names[idx]) != 0)
7879 case SND_PCM_HW_PARAM_FORMAT:
7882 err = snd_config_get_string(n, &str);
7885 snd_error(PCM, "invalid type for %s", id);
7888 if ((fields[k].flags & SCONF_UNCHANGED) &&
7889 strcasecmp(str, "unchanged") == 0) {
7890 *(snd_pcm_format_t*)fields[k].ptr = (snd_pcm_format_t) -2;
7893 f = snd_pcm_format_value(str);
7894 if (f == SND_PCM_FORMAT_UNKNOWN) {
7895 snd_error(PCM, "unknown format %s", str);
7899 *(snd_pcm_format_t*)fields[k].ptr = f;
7903 if ((fields[k].flags & SCONF_UNCHANGED)) {
7904 err = snd_config_get_string(n, &str);
7906 strcasecmp(str, "unchanged") == 0) {
7907 *(int*)fields[k].ptr = -2;
7911 err = snd_config_get_integer(n, &v);
7914 *(int*)fields[k].ptr = v;
7917 fields[k].present = 1;
7922 snd_error(PCM, "Unknown field %s", id);
7927 snd_error(PCM, "missing field pcm");
7931 for (k = 0; k < count; ++k) {
7932 if ((fields[k].flags & SCONF_MANDATORY) && !fields[k].present) {
7933 snd_error(PCM, "missing field %s", names[fields[k].index]);
7938 *_pcm_conf = pcm_conf;
7943 snd_config_delete(pcm_conf);
7945 snd_config_delete(conf);
7949 static void snd_pcm_set_ptr(snd_pcm_t *pcm, snd_pcm_rbptr_t *rbptr,
7950 volatile snd_pcm_uframes_t *hw_ptr, int fd, off_t offset)
7952 rbptr->master = NULL; /* I'm master */
7953 rbptr->ptr = hw_ptr;
7955 rbptr->offset = offset;
7957 rbptr->changed(pcm, NULL);
7960 void snd_pcm_set_hw_ptr(snd_pcm_t *pcm, volatile snd_pcm_uframes_t *hw_ptr, int fd, off_t offset)
7964 snd_pcm_set_ptr(pcm, &pcm->hw, hw_ptr, fd, offset);
7967 void snd_pcm_set_appl_ptr(snd_pcm_t *pcm, volatile snd_pcm_uframes_t *appl_ptr, int fd, off_t offset)
7971 snd_pcm_set_ptr(pcm, &pcm->appl, appl_ptr, fd, offset);
7974 static void snd_pcm_link_ptr(snd_pcm_t *pcm, snd_pcm_rbptr_t *pcm_rbptr,
7975 snd_pcm_t *slave, snd_pcm_rbptr_t *slave_rbptr)
7980 a = slave_rbptr->link_dst;
7981 for (idx = 0; idx < slave_rbptr->link_dst_count; idx++)
7982 if (a[idx] == NULL) {
7984 goto __found_free_place;
7986 a = realloc(a, sizeof(snd_pcm_t *) * (slave_rbptr->link_dst_count + 1));
7988 pcm_rbptr->ptr = NULL;
7990 pcm_rbptr->offset = 0UL;
7993 a[slave_rbptr->link_dst_count++] = pcm;
7995 pcm_rbptr->master = slave_rbptr->master ? slave_rbptr->master : slave;
7996 pcm_rbptr->ptr = slave_rbptr->ptr;
7997 pcm_rbptr->fd = slave_rbptr->fd;
7998 pcm_rbptr->offset = slave_rbptr->offset;
7999 slave_rbptr->link_dst = a;
8000 if (pcm_rbptr->changed)
8001 pcm_rbptr->changed(pcm, slave);
8004 static void snd_pcm_unlink_ptr(snd_pcm_t *pcm, snd_pcm_rbptr_t *pcm_rbptr,
8005 snd_pcm_t *slave, snd_pcm_rbptr_t *slave_rbptr)
8010 a = slave_rbptr->link_dst;
8011 for (idx = 0; idx < slave_rbptr->link_dst_count; idx++) {
8012 if (a[idx] == pcm) {
8021 pcm_rbptr->master = NULL;
8022 pcm_rbptr->ptr = NULL;
8024 pcm_rbptr->offset = 0UL;
8025 if (pcm_rbptr->changed)
8026 pcm_rbptr->changed(pcm, slave);
8029 void snd_pcm_link_hw_ptr(snd_pcm_t *pcm, snd_pcm_t *slave)
8033 snd_pcm_link_ptr(pcm, &pcm->hw, slave, &slave->hw);
8036 void snd_pcm_link_appl_ptr(snd_pcm_t *pcm, snd_pcm_t *slave)
8040 snd_pcm_link_ptr(pcm, &pcm->appl, slave, &slave->appl);
8043 void snd_pcm_unlink_hw_ptr(snd_pcm_t *pcm, snd_pcm_t *slave)
8047 snd_pcm_unlink_ptr(pcm, &pcm->hw, slave, &slave->hw);
8050 void snd_pcm_unlink_appl_ptr(snd_pcm_t *pcm, snd_pcm_t *slave)
8054 snd_pcm_unlink_ptr(pcm, &pcm->appl, slave, &slave->appl);
8057 #endif /* DOC_HIDDEN */
8063 #if !defined(DOC_HIDDEN) && !defined(__COVERITY__)
8065 #ifdef USE_VERSIONED_SYMBOLS
8067 #define OBSOLETE1(name, what, new) \
8068 default_symbol_version(__##name, name, new); \
8069 symbol_version(__old_##name, name, what);
8073 #define OBSOLETE1(name, what, new) \
8074 use_default_symbol_version(__##name, name, new);
8076 #endif /* USE_VERSIONED_SYMBOLS */
8078 #define __P_OLD_GET(pfx, name, val_type, ret_type) \
8079 EXPORT_SYMBOL ret_type pfx##name(const snd_pcm_hw_params_t *params) \
8082 if (INTERNAL(name)(params, &val) < 0) \
8084 return (ret_type)val; \
8087 #define __P_OLD_GET1(pfx, name, val_type, ret_type) \
8088 EXPORT_SYMBOL ret_type pfx##name(const snd_pcm_hw_params_t *params, int *dir) \
8091 if (INTERNAL(name)(params, &val, dir) < 0) \
8093 return (ret_type)val; \
8096 #define __OLD_GET(name, val_type, ret_type) __P_OLD_GET(__old_, name, val_type, ret_type)
8097 #define __OLD_GET1(name, val_type, ret_type) __P_OLD_GET1(__old_, name, val_type, ret_type)
8099 __OLD_GET(snd_pcm_hw_params_get_access, snd_pcm_access_t, int);
8100 __OLD_GET(snd_pcm_hw_params_get_format, snd_pcm_format_t, int);
8101 __OLD_GET(snd_pcm_hw_params_get_subformat, snd_pcm_subformat_t, int);
8102 __OLD_GET(snd_pcm_hw_params_get_channels, unsigned int, int);
8103 __OLD_GET1(snd_pcm_hw_params_get_rate, unsigned int, int);
8104 __OLD_GET1(snd_pcm_hw_params_get_period_time, unsigned int, int);
8105 __OLD_GET1(snd_pcm_hw_params_get_period_size, snd_pcm_uframes_t, snd_pcm_sframes_t);
8106 __OLD_GET1(snd_pcm_hw_params_get_periods, unsigned int, int);
8107 __OLD_GET1(snd_pcm_hw_params_get_buffer_time, unsigned int, int);
8108 __OLD_GET(snd_pcm_hw_params_get_buffer_size, snd_pcm_uframes_t, snd_pcm_sframes_t);
8109 __OLD_GET1(snd_pcm_hw_params_get_tick_time, unsigned int, int);
8111 __OLD_GET(snd_pcm_hw_params_get_channels_min, unsigned int, unsigned int);
8112 __OLD_GET1(snd_pcm_hw_params_get_rate_min, unsigned int, unsigned int);
8113 __OLD_GET1(snd_pcm_hw_params_get_period_time_min, unsigned int, unsigned int);
8114 __OLD_GET1(snd_pcm_hw_params_get_period_size_min, snd_pcm_uframes_t, snd_pcm_uframes_t);
8115 __OLD_GET1(snd_pcm_hw_params_get_periods_min, unsigned int, unsigned int);
8116 __OLD_GET1(snd_pcm_hw_params_get_buffer_time_min, unsigned int, unsigned int);
8117 __OLD_GET(snd_pcm_hw_params_get_buffer_size_min, snd_pcm_uframes_t, snd_pcm_uframes_t);
8118 __OLD_GET1(snd_pcm_hw_params_get_tick_time_min, unsigned int, unsigned int);
8120 __OLD_GET(snd_pcm_hw_params_get_channels_max, unsigned int, unsigned int);
8121 __OLD_GET1(snd_pcm_hw_params_get_rate_max, unsigned int, unsigned int);
8122 __OLD_GET1(snd_pcm_hw_params_get_period_time_max, unsigned int, unsigned int);
8123 __OLD_GET1(snd_pcm_hw_params_get_period_size_max, snd_pcm_uframes_t, snd_pcm_uframes_t);
8124 __OLD_GET1(snd_pcm_hw_params_get_periods_max, unsigned int, unsigned int);
8125 __OLD_GET1(snd_pcm_hw_params_get_buffer_time_max, unsigned int, unsigned int);
8126 __OLD_GET(snd_pcm_hw_params_get_buffer_size_max, snd_pcm_uframes_t, snd_pcm_uframes_t);
8127 __OLD_GET1(snd_pcm_hw_params_get_tick_time_max, unsigned int, unsigned int);
8129 #define __P_OLD_NEAR(pfx, name, ret_type) \
8130 EXPORT_SYMBOL ret_type pfx##name(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, ret_type val) \
8132 if (INTERNAL(name)(pcm, params, &val) < 0) \
8134 return (ret_type)val; \
8137 #define __P_OLD_NEAR1(pfx, name, ret_type) \
8138 EXPORT_SYMBOL ret_type pfx##name(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, ret_type val, int *dir) \
8140 if (INTERNAL(name)(pcm, params, &val, dir) < 0) \
8142 return (ret_type)val; \
8145 #define __OLD_NEAR(name, ret_type) __P_OLD_NEAR(__old_, name, ret_type)
8146 #define __OLD_NEAR1(name, ret_type) __P_OLD_NEAR1(__old_, name, ret_type)
8148 __OLD_NEAR(snd_pcm_hw_params_set_channels_near, unsigned int);
8149 __OLD_NEAR1(snd_pcm_hw_params_set_rate_near, unsigned int);
8150 __OLD_NEAR1(snd_pcm_hw_params_set_period_time_near, unsigned int);
8151 __OLD_NEAR1(snd_pcm_hw_params_set_period_size_near, snd_pcm_uframes_t);
8152 __OLD_NEAR1(snd_pcm_hw_params_set_periods_near, unsigned int);
8153 __OLD_NEAR1(snd_pcm_hw_params_set_buffer_time_near, unsigned int);
8154 __OLD_NEAR(snd_pcm_hw_params_set_buffer_size_near, snd_pcm_uframes_t);
8155 __OLD_NEAR1(snd_pcm_hw_params_set_tick_time_near, unsigned int);
8157 #define __P_OLD_SET_FL(pfx, name, ret_type) \
8158 EXPORT_SYMBOL ret_type pfx##name(snd_pcm_t *pcm, snd_pcm_hw_params_t *params) \
8161 if (INTERNAL(name)(pcm, params, &val) < 0) \
8163 return (ret_type)val; \
8166 #define __P_OLD_SET_FL1(pfx, name, ret_type) \
8167 EXPORT_SYMBOL ret_type pfx##name(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, int *dir) \
8170 if (INTERNAL(name)(pcm, params, &val, dir) < 0) \
8172 return (ret_type)val; \
8175 #define __OLD_SET_FL(name, ret_type) __P_OLD_SET_FL(__old_, name, ret_type)
8176 #define __OLD_SET_FL1(name, ret_type) __P_OLD_SET_FL1(__old_, name, ret_type)
8178 __OLD_SET_FL(snd_pcm_hw_params_set_access_first, snd_pcm_access_t);
8179 __OLD_SET_FL(snd_pcm_hw_params_set_format_first, snd_pcm_format_t);
8180 __OLD_SET_FL(snd_pcm_hw_params_set_subformat_first, snd_pcm_subformat_t);
8181 __OLD_SET_FL(snd_pcm_hw_params_set_channels_first, unsigned int);
8182 __OLD_SET_FL1(snd_pcm_hw_params_set_rate_first, unsigned int);
8183 __OLD_SET_FL1(snd_pcm_hw_params_set_period_time_first, unsigned int);
8184 __OLD_SET_FL1(snd_pcm_hw_params_set_period_size_first, snd_pcm_uframes_t);
8185 __OLD_SET_FL1(snd_pcm_hw_params_set_periods_first, unsigned int);
8186 __OLD_SET_FL1(snd_pcm_hw_params_set_buffer_time_first, unsigned int);
8187 __OLD_SET_FL(snd_pcm_hw_params_set_buffer_size_first, snd_pcm_uframes_t);
8188 __OLD_SET_FL1(snd_pcm_hw_params_set_tick_time_first, unsigned int);
8190 __OLD_SET_FL(snd_pcm_hw_params_set_access_last, snd_pcm_access_t);
8191 __OLD_SET_FL(snd_pcm_hw_params_set_format_last, snd_pcm_format_t);
8192 __OLD_SET_FL(snd_pcm_hw_params_set_subformat_last, snd_pcm_subformat_t);
8193 __OLD_SET_FL(snd_pcm_hw_params_set_channels_last, unsigned int);
8194 __OLD_SET_FL1(snd_pcm_hw_params_set_rate_last, unsigned int);
8195 __OLD_SET_FL1(snd_pcm_hw_params_set_period_time_last, unsigned int);
8196 __OLD_SET_FL1(snd_pcm_hw_params_set_period_size_last, snd_pcm_uframes_t);
8197 __OLD_SET_FL1(snd_pcm_hw_params_set_periods_last, unsigned int);
8198 __OLD_SET_FL1(snd_pcm_hw_params_set_buffer_time_last, unsigned int);
8199 __OLD_SET_FL(snd_pcm_hw_params_set_buffer_size_last, snd_pcm_uframes_t);
8200 __OLD_SET_FL1(snd_pcm_hw_params_set_tick_time_last, unsigned int);
8202 #define __P_OLD_GET_SW(pfx, name, ret_type) \
8203 EXPORT_SYMBOL ret_type pfx##name(snd_pcm_sw_params_t *params) \
8206 if (INTERNAL(name)(params, &val) < 0) \
8208 return (ret_type)val; \
8211 #define __OLD_GET_SW(name, ret_type) __P_OLD_GET_SW(__old_, name, ret_type)
8213 __OLD_GET_SW(snd_pcm_sw_params_get_tstamp_mode, snd_pcm_tstamp_t);
8214 __OLD_GET_SW(snd_pcm_sw_params_get_sleep_min, unsigned int);
8215 __OLD_GET_SW(snd_pcm_sw_params_get_avail_min, snd_pcm_uframes_t);
8216 __OLD_GET_SW(snd_pcm_sw_params_get_xfer_align, snd_pcm_uframes_t);
8217 __OLD_GET_SW(snd_pcm_sw_params_get_start_threshold, snd_pcm_uframes_t);
8218 __OLD_GET_SW(snd_pcm_sw_params_get_stop_threshold, snd_pcm_uframes_t);
8219 __OLD_GET_SW(snd_pcm_sw_params_get_silence_threshold, snd_pcm_uframes_t);
8220 __OLD_GET_SW(snd_pcm_sw_params_get_silence_size, snd_pcm_uframes_t);
8222 OBSOLETE1(snd_pcm_hw_params_get_access, ALSA_0.9, ALSA_0.9.0rc4);
8223 OBSOLETE1(snd_pcm_hw_params_set_access_first, ALSA_0.9, ALSA_0.9.0rc4);
8224 OBSOLETE1(snd_pcm_hw_params_set_access_last, ALSA_0.9, ALSA_0.9.0rc4);
8226 OBSOLETE1(snd_pcm_hw_params_get_format, ALSA_0.9, ALSA_0.9.0rc4);
8227 OBSOLETE1(snd_pcm_hw_params_set_format_first, ALSA_0.9, ALSA_0.9.0rc4);
8228 OBSOLETE1(snd_pcm_hw_params_set_format_last, ALSA_0.9, ALSA_0.9.0rc4);
8230 OBSOLETE1(snd_pcm_hw_params_get_subformat, ALSA_0.9, ALSA_0.9.0rc4);
8231 OBSOLETE1(snd_pcm_hw_params_set_subformat_first, ALSA_0.9, ALSA_0.9.0rc4);
8232 OBSOLETE1(snd_pcm_hw_params_set_subformat_last, ALSA_0.9, ALSA_0.9.0rc4);
8234 OBSOLETE1(snd_pcm_hw_params_get_channels, ALSA_0.9, ALSA_0.9.0rc4);
8235 OBSOLETE1(snd_pcm_hw_params_get_channels_min, ALSA_0.9, ALSA_0.9.0rc4);
8236 OBSOLETE1(snd_pcm_hw_params_get_channels_max, ALSA_0.9, ALSA_0.9.0rc4);
8237 OBSOLETE1(snd_pcm_hw_params_set_channels_near, ALSA_0.9, ALSA_0.9.0rc4);
8238 OBSOLETE1(snd_pcm_hw_params_set_channels_first, ALSA_0.9, ALSA_0.9.0rc4);
8239 OBSOLETE1(snd_pcm_hw_params_set_channels_last, ALSA_0.9, ALSA_0.9.0rc4);
8241 OBSOLETE1(snd_pcm_hw_params_get_rate, ALSA_0.9, ALSA_0.9.0rc4);
8242 OBSOLETE1(snd_pcm_hw_params_get_rate_min, ALSA_0.9, ALSA_0.9.0rc4);
8243 OBSOLETE1(snd_pcm_hw_params_get_rate_max, ALSA_0.9, ALSA_0.9.0rc4);
8244 OBSOLETE1(snd_pcm_hw_params_set_rate_near, ALSA_0.9, ALSA_0.9.0rc4);
8245 OBSOLETE1(snd_pcm_hw_params_set_rate_first, ALSA_0.9, ALSA_0.9.0rc4);
8246 OBSOLETE1(snd_pcm_hw_params_set_rate_last, ALSA_0.9, ALSA_0.9.0rc4);
8248 OBSOLETE1(snd_pcm_hw_params_get_period_time, ALSA_0.9, ALSA_0.9.0rc4);
8249 OBSOLETE1(snd_pcm_hw_params_get_period_time_min, ALSA_0.9, ALSA_0.9.0rc4);
8250 OBSOLETE1(snd_pcm_hw_params_get_period_time_max, ALSA_0.9, ALSA_0.9.0rc4);
8251 OBSOLETE1(snd_pcm_hw_params_set_period_time_near, ALSA_0.9, ALSA_0.9.0rc4);
8252 OBSOLETE1(snd_pcm_hw_params_set_period_time_first, ALSA_0.9, ALSA_0.9.0rc4);
8253 OBSOLETE1(snd_pcm_hw_params_set_period_time_last, ALSA_0.9, ALSA_0.9.0rc4);
8255 OBSOLETE1(snd_pcm_hw_params_get_period_size, ALSA_0.9, ALSA_0.9.0rc4);
8256 OBSOLETE1(snd_pcm_hw_params_get_period_size_min, ALSA_0.9, ALSA_0.9.0rc4);
8257 OBSOLETE1(snd_pcm_hw_params_get_period_size_max, ALSA_0.9, ALSA_0.9.0rc4);
8258 OBSOLETE1(snd_pcm_hw_params_set_period_size_near, ALSA_0.9, ALSA_0.9.0rc4);
8259 OBSOLETE1(snd_pcm_hw_params_set_period_size_first, ALSA_0.9, ALSA_0.9.0rc4);
8260 OBSOLETE1(snd_pcm_hw_params_set_period_size_last, ALSA_0.9, ALSA_0.9.0rc4);
8262 OBSOLETE1(snd_pcm_hw_params_get_periods, ALSA_0.9, ALSA_0.9.0rc4);
8263 OBSOLETE1(snd_pcm_hw_params_get_periods_min, ALSA_0.9, ALSA_0.9.0rc4);
8264 OBSOLETE1(snd_pcm_hw_params_get_periods_max, ALSA_0.9, ALSA_0.9.0rc4);
8265 OBSOLETE1(snd_pcm_hw_params_set_periods_near, ALSA_0.9, ALSA_0.9.0rc4);
8266 OBSOLETE1(snd_pcm_hw_params_set_periods_first, ALSA_0.9, ALSA_0.9.0rc4);
8267 OBSOLETE1(snd_pcm_hw_params_set_periods_last, ALSA_0.9, ALSA_0.9.0rc4);
8269 OBSOLETE1(snd_pcm_hw_params_get_buffer_time, ALSA_0.9, ALSA_0.9.0rc4);
8270 OBSOLETE1(snd_pcm_hw_params_get_buffer_time_min, ALSA_0.9, ALSA_0.9.0rc4);
8271 OBSOLETE1(snd_pcm_hw_params_get_buffer_time_max, ALSA_0.9, ALSA_0.9.0rc4);
8272 OBSOLETE1(snd_pcm_hw_params_set_buffer_time_near, ALSA_0.9, ALSA_0.9.0rc4);
8273 OBSOLETE1(snd_pcm_hw_params_set_buffer_time_first, ALSA_0.9, ALSA_0.9.0rc4);
8274 OBSOLETE1(snd_pcm_hw_params_set_buffer_time_last, ALSA_0.9, ALSA_0.9.0rc4);
8276 OBSOLETE1(snd_pcm_hw_params_get_buffer_size, ALSA_0.9, ALSA_0.9.0rc4);
8277 OBSOLETE1(snd_pcm_hw_params_get_buffer_size_min, ALSA_0.9, ALSA_0.9.0rc4);
8278 OBSOLETE1(snd_pcm_hw_params_get_buffer_size_max, ALSA_0.9, ALSA_0.9.0rc4);
8279 OBSOLETE1(snd_pcm_hw_params_set_buffer_size_near, ALSA_0.9, ALSA_0.9.0rc4);
8280 OBSOLETE1(snd_pcm_hw_params_set_buffer_size_first, ALSA_0.9, ALSA_0.9.0rc4);
8281 OBSOLETE1(snd_pcm_hw_params_set_buffer_size_last, ALSA_0.9, ALSA_0.9.0rc4);
8283 OBSOLETE1(snd_pcm_hw_params_get_tick_time, ALSA_0.9, ALSA_0.9.0rc4);
8284 OBSOLETE1(snd_pcm_hw_params_get_tick_time_min, ALSA_0.9, ALSA_0.9.0rc4);
8285 OBSOLETE1(snd_pcm_hw_params_get_tick_time_max, ALSA_0.9, ALSA_0.9.0rc4);
8286 OBSOLETE1(snd_pcm_hw_params_set_tick_time_near, ALSA_0.9, ALSA_0.9.0rc4);
8287 OBSOLETE1(snd_pcm_hw_params_set_tick_time_first, ALSA_0.9, ALSA_0.9.0rc4);
8288 OBSOLETE1(snd_pcm_hw_params_set_tick_time_last, ALSA_0.9, ALSA_0.9.0rc4);
8290 OBSOLETE1(snd_pcm_sw_params_get_tstamp_mode, ALSA_0.9, ALSA_0.9.0rc4);
8291 OBSOLETE1(snd_pcm_sw_params_get_sleep_min, ALSA_0.9, ALSA_0.9.0rc4);
8292 OBSOLETE1(snd_pcm_sw_params_get_avail_min, ALSA_0.9, ALSA_0.9.0rc4);
8293 OBSOLETE1(snd_pcm_sw_params_get_xfer_align, ALSA_0.9, ALSA_0.9.0rc4);
8294 OBSOLETE1(snd_pcm_sw_params_get_start_threshold, ALSA_0.9, ALSA_0.9.0rc4);
8295 OBSOLETE1(snd_pcm_sw_params_get_stop_threshold, ALSA_0.9, ALSA_0.9.0rc4);
8296 OBSOLETE1(snd_pcm_sw_params_get_silence_threshold, ALSA_0.9, ALSA_0.9.0rc4);
8297 OBSOLETE1(snd_pcm_sw_params_get_silence_size, ALSA_0.9, ALSA_0.9.0rc4);
8299 #endif /* DOC_HIDDEN/COVERITY */
8301 static int chmap_equal(const snd_pcm_chmap_t *a, const snd_pcm_chmap_t *b)
8303 if (a->channels != b->channels)
8305 return !memcmp(a->pos, b->pos, a->channels * sizeof(a->pos[0]));
8309 * \!brief Query the available channel maps
8310 * \param pcm PCM handle to query
8311 * \return the NULL-terminated array of integer pointers, each of
8312 * which contains the channel map. A channel map is represented by an
8313 * integer array, beginning with the channel map type, followed by the
8314 * number of channels, and the position of each channel. Return NULL
8315 * in case of an error.
8317 * Note: the caller is requested to release the returned value via
8318 * snd_pcm_free_chmaps().
8320 snd_pcm_chmap_query_t **snd_pcm_query_chmaps(snd_pcm_t *pcm)
8322 if (!pcm->ops->query_chmaps)
8324 return pcm->ops->query_chmaps(pcm);
8328 * \!brief Release the channel map array allocated via #snd_pcm_query_chmaps
8329 * \param maps the array pointer to release
8331 void snd_pcm_free_chmaps(snd_pcm_chmap_query_t **maps)
8333 snd_pcm_chmap_query_t **p;
8336 for (p = maps; *p; p++)
8342 * \!brief Get the current channel map
8343 * \param pcm PCM instance
8344 * \return the current channel map, or NULL if error
8346 * Note: the caller is requested to release the returned value via free()
8348 snd_pcm_chmap_t *snd_pcm_get_chmap(snd_pcm_t *pcm)
8350 if (!pcm->ops->get_chmap)
8352 return pcm->ops->get_chmap(pcm);
8356 * \!brief Configure the current channel map
8357 * \param pcm PCM instance
8358 * \param map the channel map to write
8359 * \return zero if succeeded, or a negative error code
8361 int snd_pcm_set_chmap(snd_pcm_t *pcm, const snd_pcm_chmap_t *map)
8363 const snd_pcm_chmap_t *oldmap;
8366 oldmap = snd_pcm_get_chmap(pcm);
8367 nochange = (oldmap && chmap_equal(oldmap, map));
8368 free((void *)oldmap);
8372 if (!pcm->ops->set_chmap)
8374 return pcm->ops->set_chmap(pcm, map);
8380 #define _NAME(n) [SND_CHMAP_TYPE_##n] = #n
8381 static const char *chmap_type_names[SND_CHMAP_TYPE_LAST + 1] = {
8382 _NAME(NONE), _NAME(FIXED), _NAME(VAR), _NAME(PAIRED),
8388 * \!brief Get a name string for a channel map type as query results
8389 * \param val Channel position
8390 * \return The string corresponding to the given type, or NULL
8392 const char *snd_pcm_chmap_type_name(enum snd_pcm_chmap_type val)
8394 if (val <= SND_CHMAP_TYPE_LAST)
8395 return chmap_type_names[val];
8401 #define _NAME(n) [SND_CHMAP_##n] = #n
8402 static const char *chmap_names[SND_CHMAP_LAST + 1] = {
8403 _NAME(UNKNOWN), _NAME(NA), _NAME(MONO),
8404 _NAME(FL), _NAME(FR),
8405 _NAME(RL), _NAME(RR),
8406 _NAME(FC), _NAME(LFE),
8407 _NAME(SL), _NAME(SR),
8408 _NAME(RC), _NAME(FLC), _NAME(FRC), _NAME(RLC), _NAME(RRC),
8409 _NAME(FLW), _NAME(FRW),
8410 _NAME(FLH), _NAME(FCH), _NAME(FRH), _NAME(TC),
8411 _NAME(TFL), _NAME(TFR), _NAME(TFC),
8412 _NAME(TRL), _NAME(TRR), _NAME(TRC),
8413 _NAME(TFLC), _NAME(TFRC), _NAME(TSL), _NAME(TSR),
8414 _NAME(LLFE), _NAME(RLFE),
8415 _NAME(BC), _NAME(BLC), _NAME(BRC),
8421 * \!brief Get a name string for a standard channel map position
8422 * \param val Channel position
8423 * \return The string corresponding to the given position, or NULL
8425 const char *snd_pcm_chmap_name(enum snd_pcm_chmap_position val)
8427 if (val <= SND_CHMAP_LAST)
8428 return chmap_names[val];
8433 static const char *chmap_long_names[SND_CHMAP_LAST + 1] = {
8434 [SND_CHMAP_UNKNOWN] = "Unknown",
8435 [SND_CHMAP_NA] = "Unused",
8436 [SND_CHMAP_MONO] = "Mono",
8437 [SND_CHMAP_FL] = "Front Left",
8438 [SND_CHMAP_FR] = "Front Right",
8439 [SND_CHMAP_RL] = "Rear Left",
8440 [SND_CHMAP_RR] = "Rear Right",
8441 [SND_CHMAP_FC] = "Front Center",
8442 [SND_CHMAP_LFE] = "LFE",
8443 [SND_CHMAP_SL] = "Side Left",
8444 [SND_CHMAP_SR] = "Side Right",
8445 [SND_CHMAP_RC] = "Rear Center",
8446 [SND_CHMAP_FLC] = "Front Left Center",
8447 [SND_CHMAP_FRC] = "Front Right Center",
8448 [SND_CHMAP_RLC] = "Rear Left Center",
8449 [SND_CHMAP_RRC] = "Rear Right Center",
8450 [SND_CHMAP_FLW] = "Front Left Wide",
8451 [SND_CHMAP_FRW] = "Front Right Wide",
8452 [SND_CHMAP_FLH] = "Front Left High",
8453 [SND_CHMAP_FCH] = "Front Center High",
8454 [SND_CHMAP_FRH] = "Front Right High",
8455 [SND_CHMAP_TC] = "Top Center",
8456 [SND_CHMAP_TFL] = "Top Front Left",
8457 [SND_CHMAP_TFR] = "Top Front Right",
8458 [SND_CHMAP_TFC] = "Top Front Center",
8459 [SND_CHMAP_TRL] = "Top Rear Left",
8460 [SND_CHMAP_TRR] = "Top Rear Right",
8461 [SND_CHMAP_TRC] = "Top Rear Center",
8462 [SND_CHMAP_TFLC] = "Top Front Left Center",
8463 [SND_CHMAP_TFRC] = "Top Front Right Center",
8464 [SND_CHMAP_TSL] = "Top Side Left",
8465 [SND_CHMAP_TSR] = "Top Side Right",
8466 [SND_CHMAP_LLFE] = "Left LFE",
8467 [SND_CHMAP_RLFE] = "Right LFE",
8468 [SND_CHMAP_BC] = "Bottom Center",
8469 [SND_CHMAP_BLC] = "Bottom Left Center",
8470 [SND_CHMAP_BRC] = "Bottom Right Center",
8474 * \!brief Get a longer name string for a standard channel map position
8475 * \param val Channel position
8476 * \return The string corresponding to the given position, or NULL
8478 const char *snd_pcm_chmap_long_name(enum snd_pcm_chmap_position val)
8480 if (val <= SND_CHMAP_LAST)
8481 return chmap_long_names[val];
8487 * \!brief Print the channels in chmap on the buffer
8488 * \param map The channel map to print
8489 * \param maxlen The maximal length to write (including NUL letter)
8490 * \param buf The buffer to write
8491 * \return The actual string length or a negative error code
8493 int snd_pcm_chmap_print(const snd_pcm_chmap_t *map, size_t maxlen, char *buf)
8495 unsigned int i, len = 0;
8497 for (i = 0; i < map->channels; i++) {
8498 unsigned int p = map->pos[i] & SND_CHMAP_POSITION_MASK;
8500 len += snprintf(buf + len, maxlen - len, " ");
8504 if (map->pos[i] & SND_CHMAP_DRIVER_SPEC)
8505 len += snprintf(buf + len, maxlen - len, "%d", p);
8507 const char *name = chmap_names[p];
8509 len += snprintf(buf + len, maxlen - len,
8512 len += snprintf(buf + len, maxlen - len,
8517 if (map->pos[i] & SND_CHMAP_PHASE_INVERSE) {
8518 len += snprintf(buf + len, maxlen - len, "[INV]");
8526 static int str_to_chmap(const char *str, int len)
8532 if (isdigit(*str)) {
8533 v = strtoul(str, &p, 0);
8537 val |= SND_CHMAP_DRIVER_SPEC;
8539 } else if (!strncasecmp(str, "ch", 2)) {
8540 v = strtoul(str + 2, &p, 0);
8546 for (val = 0; val <= SND_CHMAP_LAST; val++) {
8548 assert(chmap_names[val]);
8549 slen = strlen(chmap_names[val]);
8552 if (!strncasecmp(str, chmap_names[val], slen) &&
8553 !isalpha(str[slen])) {
8558 if (val > SND_CHMAP_LAST)
8561 if (str && !strncasecmp(str, "[INV]", 5))
8562 val |= SND_CHMAP_PHASE_INVERSE;
8567 * \!brief Convert from string to channel position
8568 * \param str The string to parse
8569 * \return The channel position value or -1 as an error
8571 unsigned int snd_pcm_chmap_from_string(const char *str)
8573 return str_to_chmap(str, strlen(str));
8577 * \!brief Convert from string to channel map
8578 * \param str The string to parse
8579 * \return The channel map
8581 * Note: the caller is requested to release the returned value via free()
8583 snd_pcm_chmap_t *snd_pcm_chmap_parse_string(const char *str)
8587 snd_pcm_chmap_t *map;
8593 if (ch >= (int)(sizeof(tmp_map) / sizeof(tmp_map[0])))
8595 for (p = str; *p && isalnum(*p); p++)
8600 val = str_to_chmap(str, len);
8605 if (!strncmp(str, "[INV]", 5)) {
8606 val |= SND_CHMAP_PHASE_INVERSE;
8612 for (; *str && !isalnum(*str); str++)
8617 map = malloc(sizeof(*map) + ch * sizeof(int));
8621 for (i = 0; i < ch; i++)
8622 map->pos[i] = tmp_map[i];
8626 /* copy a single channel map with the fixed type to chmap_query pointer */
8627 static int _copy_to_fixed_query_map(snd_pcm_chmap_query_t **dst,
8628 const snd_pcm_chmap_t *src)
8630 *dst = malloc((src->channels + 2) * sizeof(int));
8633 (*dst)->type = SND_CHMAP_TYPE_FIXED;
8634 memcpy(&(*dst)->map, src, (src->channels + 1) * sizeof(int));
8639 /* make a chmap_query array from a single channel map */
8640 snd_pcm_chmap_query_t **
8641 _snd_pcm_make_single_query_chmaps(const snd_pcm_chmap_t *src)
8643 snd_pcm_chmap_query_t **maps;
8645 maps = calloc(2, sizeof(*maps));
8648 if (_copy_to_fixed_query_map(maps, src)) {
8655 /* make a copy of chmap */
8656 snd_pcm_chmap_t *_snd_pcm_copy_chmap(const snd_pcm_chmap_t *src)
8658 snd_pcm_chmap_t *map;
8660 map = malloc((src->channels + 1) * sizeof(int));
8663 memcpy(map, src, (src->channels + 1) * sizeof(int));
8667 /* make a copy of channel maps */
8668 snd_pcm_chmap_query_t **
8669 _snd_pcm_copy_chmap_query(snd_pcm_chmap_query_t * const *src)
8671 snd_pcm_chmap_query_t * const *p;
8672 snd_pcm_chmap_query_t **maps;
8675 for (nums = 0, p = src; *p; p++)
8678 maps = calloc(nums + 1, sizeof(*maps));
8681 for (i = 0; i < nums; i++) {
8682 maps[i] = malloc((src[i]->map.channels + 2) * sizeof(int));
8684 snd_pcm_free_chmaps(maps);
8687 memcpy(maps[i], src[i], (src[i]->map.channels + 2) * sizeof(int));
8692 /* select the channel map with the current PCM channels and make a copy */
8694 _snd_pcm_choose_fixed_chmap(snd_pcm_t *pcm, snd_pcm_chmap_query_t * const *maps)
8696 snd_pcm_chmap_query_t * const *p;
8698 for (p = maps; *p; p++) {
8699 if ((*p)->map.channels == pcm->channels)
8700 return _snd_pcm_copy_chmap(&(*p)->map);
8705 /* make chmap_query array from the config tree;
8706 * conf must be a compound (array)
8708 snd_pcm_chmap_query_t **
8709 _snd_pcm_parse_config_chmaps(snd_config_t *conf)
8711 snd_pcm_chmap_t *chmap;
8712 snd_pcm_chmap_query_t **maps;
8713 snd_config_iterator_t i, next;
8717 if (snd_config_get_type(conf) != SND_CONFIG_TYPE_COMPOUND)
8721 snd_config_for_each(i, next, conf) {
8725 maps = calloc(nums + 1, sizeof(*maps));
8730 snd_config_for_each(i, next, conf) {
8731 snd_config_t *n = snd_config_iterator_entry(i);
8732 err = snd_config_get_string(n, &str);
8735 chmap = snd_pcm_chmap_parse_string(str);
8738 if (_copy_to_fixed_query_map(maps + nums, chmap)) {
8748 snd_pcm_free_chmaps(maps);
8751 #endif /* DOC_HIDDEN */
8759 * \brief Recover the stream state from an error or suspend
8760 * \param pcm PCM handle
8761 * \param err error number
8762 * \param silent do not print error reason
8763 * \return 0 when error code was handled successfuly, otherwise a negative error code
8765 * This a high-level helper function building on other functions.
8767 * This functions handles -EINTR (interrupted system call),
8768 * -EPIPE (overrun or underrun) and -ESTRPIPE (stream is suspended)
8769 * error codes trying to prepare given stream for next I/O.
8771 * Note that this function returns the original error code when it is not
8772 * handled inside this function (for example -EAGAIN is returned back).
8774 int snd_pcm_recover(snd_pcm_t *pcm, int err, int silent)
8778 if (err == -EINTR) /* nothing to do, continue */
8780 if (err == -EPIPE) {
8782 if (snd_pcm_stream(pcm) == SND_PCM_STREAM_PLAYBACK)
8787 snd_error(PCM, "%s occurred", s);
8788 err = snd_pcm_prepare(pcm);
8790 snd_error(PCM, "cannot recovery from %s, prepare failed: %s", s, snd_strerror(err));
8795 if (err == -ESTRPIPE) {
8796 while ((err = snd_pcm_resume(pcm)) == -EAGAIN)
8797 /* wait until suspend flag is released */
8798 (void)poll(NULL, 0, 1000);
8800 err = snd_pcm_prepare(pcm);
8802 snd_error(PCM, "cannot recovery from suspend, prepare failed: %s", snd_strerror(err));
8812 * \brief Set the hardware and software parameters in a simple way
8813 * \param pcm PCM handle
8814 * \param format required PCM format
8815 * \param access required PCM access
8816 * \param channels required PCM channels
8817 * \param rate required sample rate in Hz
8818 * \param soft_resample 0 = disallow alsa-lib resample stream, 1 = allow resampling
8819 * \param latency required overall latency in us
8820 * \return 0 on success otherwise a negative error code
8822 int snd_pcm_set_params(snd_pcm_t *pcm,
8823 snd_pcm_format_t format,
8824 snd_pcm_access_t access,
8825 unsigned int channels,
8828 unsigned int latency)
8830 snd_pcm_hw_params_t params_saved, params = {0};
8831 snd_pcm_sw_params_t swparams = {0};
8832 const char *s = snd_pcm_stream_name(snd_pcm_stream(pcm));
8833 snd_pcm_uframes_t buffer_size, period_size;
8834 unsigned int rrate, period_time;
8838 /* choose all parameters */
8839 err = snd_pcm_hw_params_any(pcm, ¶ms);
8841 snd_error(PCM, "Broken configuration for %s: no configurations available",
8846 /* set software resampling */
8847 err = snd_pcm_hw_params_set_rate_resample(pcm, ¶ms, soft_resample);
8849 snd_error(PCM, "Resampling setup failed for %s: %s",
8850 s, snd_strerror(err));
8854 /* set the selected read/write format */
8855 err = snd_pcm_hw_params_set_access(pcm, ¶ms, access);
8857 snd_error(PCM, "Access type not available for %s: %s",
8858 s, snd_strerror(err));
8862 /* set the sample format */
8863 err = snd_pcm_hw_params_set_format(pcm, ¶ms, format);
8865 snd_error(PCM, "Sample format not available for %s: %s",
8866 s, snd_strerror(err));
8870 /* set the count of channels */
8871 err = snd_pcm_hw_params_set_channels(pcm, ¶ms, channels);
8873 snd_error(PCM, "Channels count (%i) not available for %s: %s",
8874 channels, s, snd_strerror(err));
8878 /* set the stream rate */
8880 err = INTERNAL(snd_pcm_hw_params_set_rate_near)(pcm, ¶ms, &rrate,
8883 snd_error(PCM, "Rate %iHz not available for playback: %s",
8884 rate, snd_strerror(err));
8888 if (rrate != rate) {
8889 snd_error(PCM, "Rate doesn't match (requested %iHz, get %iHz)",
8894 /* set the buffer time */
8895 params_saved = params;
8896 err = INTERNAL(snd_pcm_hw_params_set_buffer_time_near)(pcm, ¶ms,
8899 /* error path -> set period size as first */
8900 params = params_saved;
8901 /* set the period time */
8902 period_time = latency / 4;
8903 err = INTERNAL(snd_pcm_hw_params_set_period_time_near)(pcm,
8904 ¶ms, &period_time, NULL);
8906 snd_error(PCM, "Unable to set period time %i for %s: %s",
8907 period_time, s, snd_strerror(err));
8911 err = INTERNAL(snd_pcm_hw_params_get_period_size)(¶ms,
8912 &period_size, NULL);
8914 snd_error(PCM, "Unable to get period size for %s: %s",
8915 s, snd_strerror(err));
8919 buffer_size = period_size * 4;
8920 err = INTERNAL(snd_pcm_hw_params_set_buffer_size_near)(pcm,
8921 ¶ms, &buffer_size);
8923 snd_error(PCM, "Unable to set buffer size %lu %s: %s",
8924 buffer_size, s, snd_strerror(err));
8928 err = INTERNAL(snd_pcm_hw_params_get_buffer_size)(¶ms,
8931 snd_error(PCM, "Unable to get buffer size for %s: %s",
8932 s, snd_strerror(err));
8937 /* standard configuration buffer_time -> periods */
8938 err = INTERNAL(snd_pcm_hw_params_get_buffer_size)(¶ms,
8941 snd_error(PCM, "Unable to get buffer size for %s: %s",
8942 s, snd_strerror(err));
8946 err = INTERNAL(snd_pcm_hw_params_get_buffer_time)(¶ms,
8949 snd_error(PCM, "Unable to get buffer time (latency) for %s: %s",
8950 s, snd_strerror(err));
8954 /* set the period time */
8955 period_time = latency / 4;
8956 err = INTERNAL(snd_pcm_hw_params_set_period_time_near)(pcm,
8957 ¶ms, &period_time, NULL);
8959 snd_error(PCM, "Unable to set period time %i for %s: %s",
8960 period_time, s, snd_strerror(err));
8964 err = INTERNAL(snd_pcm_hw_params_get_period_size)(¶ms,
8965 &period_size, NULL);
8967 snd_error(PCM, "Unable to get period size for %s: %s",
8968 s, snd_strerror(err));
8973 /* write the parameters to device */
8974 err = snd_pcm_hw_params(pcm, ¶ms);
8976 snd_error(PCM, "Unable to set hw params for %s: %s",
8977 s, snd_strerror(err));
8982 /* get the current swparams */
8983 err = snd_pcm_sw_params_current(pcm, &swparams);
8985 snd_error(PCM, "Unable to determine current swparams for %s: %s",
8986 s, snd_strerror(err));
8991 * start the transfer when the buffer is almost full:
8992 * (buffer_size / avail_min) * avail_min
8994 err = snd_pcm_sw_params_set_start_threshold(pcm, &swparams,
8995 (buffer_size / period_size) * period_size);
8997 snd_error(PCM, "Unable to set start threshold mode for %s: %s",
8998 s, snd_strerror(err));
9003 * allow the transfer when at least period_size samples can be
9006 err = snd_pcm_sw_params_set_avail_min(pcm, &swparams, period_size);
9008 snd_error(PCM, "Unable to set avail min for %s: %s",
9009 s, snd_strerror(err));
9013 /* write the parameters to the playback device */
9014 err = snd_pcm_sw_params(pcm, &swparams);
9016 snd_error(PCM, "Unable to set sw params for %s: %s",
9017 s, snd_strerror(err));
9025 * \brief Get the transfer size parameters in a simple way
9026 * \param pcm PCM handle
9027 * \param buffer_size PCM ring buffer size in frames
9028 * \param period_size PCM period size in frames
9029 * \return 0 on success otherwise a negative error code
9031 int snd_pcm_get_params(snd_pcm_t *pcm,
9032 snd_pcm_uframes_t *buffer_size,
9033 snd_pcm_uframes_t *period_size)
9035 snd_pcm_hw_params_t params = {0};
9039 err = snd_pcm_hw_params_current(pcm, ¶ms);
9042 err = INTERNAL(snd_pcm_hw_params_get_buffer_size)(¶ms, buffer_size);
9045 return INTERNAL(snd_pcm_hw_params_get_period_size)(¶ms, period_size,