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 SNDMSG("PCM not set up");
1009 if (! params->avail_min) {
1010 SNDMSG("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 SNDMSG("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 SNDMSG("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 SNDMSG("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 SNDMSG("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 SNDMSG("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 SNDMSG("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 SNDMSG("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 SNDMSG("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 SNDMSG("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 SNDMSG("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 SNDMSG("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 SNDMSG("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 SNDMSG("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 SNDMSG("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 SNDMSG("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 SNDMSG("PCM not set up");
1579 if (pcm->access != SND_PCM_ACCESS_RW_INTERLEAVED) {
1580 SNDMSG("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 SNDMSG("PCM not set up");
1618 if (pcm->access != SND_PCM_ACCESS_RW_NONINTERLEAVED) {
1619 SNDMSG("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 SNDMSG("PCM not set up");
1657 if (pcm->access != SND_PCM_ACCESS_RW_INTERLEAVED) {
1658 SNDMSG("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 SNDMSG("PCM not set up");
1696 if (pcm->access != SND_PCM_ACCESS_RW_NONINTERLEAVED) {
1697 SNDMSG("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 SNDMSG("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 SNDMSG("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 SNDMSG("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 SNDMSG("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 SNDMSG("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 SNDMSG("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 SNDMSG("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 SNDMSG("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) {
2582 snd_config_get_id(pcm_conf, &id);
2584 snd_config_get_ascii(pcm_conf, &val);
2585 SNDERR("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 SNDERR("type is not defined");
2594 err = snd_config_get_id(conf, &id);
2596 SNDERR("unable to get id");
2599 err = snd_config_get_string(conf, &str);
2601 SNDERR("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 SNDERR("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 SNDERR("Invalid type for %s", id);
2626 if (strcmp(id, "open") == 0) {
2627 err = snd_config_get_string(n, &open_name);
2629 SNDERR("Invalid type for %s", id);
2634 SNDERR("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 SNDERR("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 SNDERR("Invalid poll_fds %d", npfds);
2978 pfd = alloca(sizeof(*pfd) * npfds);
2979 err = __snd_pcm_poll_descriptors(pcm, pfd, npfds);
2983 SNDMSG("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 SNDMSG("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 SNDMSG("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 SNDMSG("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);
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 SNDMSG("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);
3338 if (src_area->step == (unsigned int) width &&
3339 dst_area->step == (unsigned int) width) {
3340 size_t bytes = samples * width / 8;
3341 samples -= bytes * 8 / width;
3342 assert(src < dst || src >= dst + bytes);
3343 assert(dst < src || dst >= src + bytes);
3344 memcpy(dst, src, bytes);
3348 src_step = src_area->step / 8;
3349 dst_step = dst_area->step / 8;
3352 int srcbit = src_area->first % 8;
3353 int srcbit_step = src_area->step % 8;
3354 int dstbit = dst_area->first % 8;
3355 int dstbit_step = dst_area->step % 8;
3356 while (samples-- > 0) {
3357 unsigned char srcval;
3359 srcval = *src & 0x0f;
3361 srcval = *src & 0xf0;
3368 srcbit += srcbit_step;
3374 dstbit += dstbit_step;
3383 while (samples-- > 0) {
3391 while (samples-- > 0) {
3392 *(uint16_t*)dst = *(const uint16_t*)src;
3399 while (samples-- > 0) {
3400 *(dst + 0) = *(src + 0);
3401 *(dst + 1) = *(src + 1);
3402 *(dst + 2) = *(src + 2);
3408 while (samples-- > 0) {
3409 *(uint32_t*)dst = *(const uint32_t*)src;
3416 while (samples-- > 0) {
3417 *(uint64_t*)dst = *(const uint64_t*)src;
3424 SNDMSG("invalid format width %d", width);
3431 * \brief Copy one or more areas
3432 * \param dst_areas destination areas specification (one for each channel)
3433 * \param dst_offset offset in frames inside destination area
3434 * \param src_areas source areas specification (one for each channel)
3435 * \param src_offset offset in frames inside source area
3436 * \param channels channels count
3437 * \param frames frames to copy
3438 * \param format PCM sample format
3439 * \return 0 on success otherwise a negative error code
3441 int snd_pcm_areas_copy(const snd_pcm_channel_area_t *dst_areas, snd_pcm_uframes_t dst_offset,
3442 const snd_pcm_channel_area_t *src_areas, snd_pcm_uframes_t src_offset,
3443 unsigned int channels, snd_pcm_uframes_t frames, snd_pcm_format_t format)
3445 int width = snd_pcm_format_physical_width(format);
3449 SNDMSG("invalid channels %d", channels);
3453 SNDMSG("invalid frames %ld", frames);
3456 while (channels > 0) {
3457 unsigned int step = src_areas->step;
3458 void *src_addr = src_areas->addr;
3459 const snd_pcm_channel_area_t *src_start = src_areas;
3460 void *dst_addr = dst_areas->addr;
3461 const snd_pcm_channel_area_t *dst_start = dst_areas;
3462 int channels1 = channels;
3463 unsigned int chns = 0;
3464 while (dst_areas->step == step) {
3469 if (channels1 == 0 ||
3470 src_areas->step != step ||
3471 src_areas->addr != src_addr ||
3472 dst_areas->addr != dst_addr ||
3473 src_areas->first != src_areas[-1].first + width ||
3474 dst_areas->first != dst_areas[-1].first + width)
3477 if (chns > 1 && chns * width == step) {
3478 if (src_offset != dst_offset ||
3479 src_start->addr != dst_start->addr ||
3480 src_start->first != dst_start->first) {
3481 /* Collapse the areas */
3482 snd_pcm_channel_area_t s, d;
3483 s.addr = src_start->addr;
3484 s.first = src_start->first;
3486 d.addr = dst_start->addr;
3487 d.first = dst_start->first;
3489 snd_pcm_area_copy(&d, dst_offset * chns,
3490 &s, src_offset * chns,
3491 frames * chns, format);
3495 snd_pcm_area_copy(dst_start, dst_offset,
3496 src_start, src_offset,
3498 src_areas = src_start + 1;
3499 dst_areas = dst_start + 1;
3507 * \brief Copy one or more areas
3508 * \param dst_channels destination areas specification (one for each channel)
3509 * \param dst_offset offset in frames inside destination area
3510 * \param dst_size size in frames of the destination buffer
3511 * \param src_channels source areas specification (one for each channel)
3512 * \param src_offset offset in frames inside source area
3513 * \param src_size size in frames of the source buffer
3514 * \param channels channels count
3515 * \param frames frames to copy
3516 * \param format PCM sample format
3517 * \return 0 on success otherwise a negative error code
3519 int snd_pcm_areas_copy_wrap(const snd_pcm_channel_area_t *dst_channels,
3520 snd_pcm_uframes_t dst_offset,
3521 const snd_pcm_uframes_t dst_size,
3522 const snd_pcm_channel_area_t *src_channels,
3523 snd_pcm_uframes_t src_offset,
3524 const snd_pcm_uframes_t src_size,
3525 const unsigned int channels,
3526 snd_pcm_uframes_t frames,
3527 const snd_pcm_format_t format)
3529 while (frames > 0) {
3531 snd_pcm_uframes_t xfer = frames;
3532 /* do not write above the destination buffer */
3533 if ((dst_offset + xfer) > dst_size)
3534 xfer = dst_size - dst_offset;
3535 /* do not read from above the source buffer */
3536 if ((src_offset + xfer) > src_size)
3537 xfer = src_size - src_offset;
3538 err = snd_pcm_areas_copy(dst_channels, dst_offset, src_channels,
3539 src_offset, channels, xfer, format);
3544 if (dst_offset >= dst_size)
3547 if (src_offset >= src_size)
3555 static void dump_one_param(snd_pcm_hw_params_t *params, unsigned int k, snd_output_t *out)
3557 snd_output_printf(out, "%s: ", snd_pcm_hw_param_name(k));
3558 snd_pcm_hw_param_dump(params, k, out);
3559 snd_output_putc(out, '\n');
3563 * \brief Dump a PCM hardware configuration space
3564 * \param params Configuration space
3565 * \param out Output handle
3566 * \return 0 on success otherwise a negative error code
3568 int snd_pcm_hw_params_dump(snd_pcm_hw_params_t *params, snd_output_t *out)
3571 for (k = SND_PCM_HW_PARAM_FIRST_MASK; k <= SND_PCM_HW_PARAM_LAST_MASK; k++)
3572 dump_one_param(params, k, out);
3573 for (k = SND_PCM_HW_PARAM_FIRST_INTERVAL; k <= SND_PCM_HW_PARAM_LAST_INTERVAL; k++)
3574 dump_one_param(params, k, out);
3579 * \brief Check if hardware supports sample-resolution mmap for given configuration
3580 * \param params Configuration space
3581 * \retval 0 Hardware doesn't support sample-resolution mmap
3582 * \retval 1 Hardware supports sample-resolution mmap
3584 * This function should only be called when the configuration space
3585 * contains a single configuration. Call #snd_pcm_hw_params to choose
3586 * a single configuration from the configuration space.
3588 int snd_pcm_hw_params_can_mmap_sample_resolution(const snd_pcm_hw_params_t *params)
3591 if (CHECK_SANITY(params->info == ~0U)) {
3592 SNDMSG("invalid PCM info field");
3593 return 0; /* FIXME: should be a negative error? */
3595 return !!(params->info & SNDRV_PCM_INFO_MMAP_VALID);
3599 * \brief Check if hardware does double buffering for start/stop for given configuration
3600 * \param params Configuration space
3601 * \retval 0 Hardware doesn't do double buffering for start/stop
3602 * \retval 1 Hardware does double buffering for start/stop
3604 * This function should only be called when the configuration space
3605 * contains a single configuration. Call #snd_pcm_hw_params to choose
3606 * a single configuration from the configuration space.
3608 int snd_pcm_hw_params_is_double(const snd_pcm_hw_params_t *params)
3611 if (CHECK_SANITY(params->info == ~0U)) {
3612 SNDMSG("invalid PCM info field");
3613 return 0; /* FIXME: should be a negative error? */
3615 return !!(params->info & SNDRV_PCM_INFO_DOUBLE);
3619 * \brief Check if hardware does double buffering for data transfers for given configuration
3620 * \param params Configuration space
3621 * \retval 0 Hardware doesn't do double buffering for data transfers
3622 * \retval 1 Hardware does double buffering for data transfers
3624 * This function should only be called when the configuration space
3625 * contains a single configuration. Call #snd_pcm_hw_params to choose
3626 * a single configuration from the configuration space.
3628 int snd_pcm_hw_params_is_batch(const snd_pcm_hw_params_t *params)
3631 if (CHECK_SANITY(params->info == ~0U)) {
3632 SNDMSG("invalid PCM info field");
3633 return 0; /* FIXME: should be a negative error? */
3635 return !!(params->info & SNDRV_PCM_INFO_BATCH);
3639 * \brief Check if hardware does block transfers for samples for given configuration
3640 * \param params Configuration space
3641 * \retval 0 Hardware doesn't block transfers
3642 * \retval 1 Hardware does block transfers
3644 * This function should only be called when the configuration space
3645 * contains a single configuration. Call #snd_pcm_hw_params to choose
3646 * a single configuration from the configuration space.
3648 int snd_pcm_hw_params_is_block_transfer(const snd_pcm_hw_params_t *params)
3651 if (CHECK_SANITY(params->info == ~0U)) {
3652 SNDMSG("invalid PCM info field");
3653 return 0; /* FIXME: should be a negative error? */
3655 return !!(params->info & SNDRV_PCM_INFO_BLOCK_TRANSFER);
3659 * \brief Check if timestamps are monotonic for given configuration
3660 * \param params Configuration space
3661 * \retval 0 Device doesn't do monotomic timestamps
3662 * \retval 1 Device does monotonic timestamps
3664 * This function should only be called when the configuration space
3665 * contains a single configuration. Call #snd_pcm_hw_params to choose
3666 * a single configuration from the configuration space.
3668 int snd_pcm_hw_params_is_monotonic(const snd_pcm_hw_params_t *params)
3671 if (CHECK_SANITY(params->info == ~0U)) {
3672 SNDMSG("invalid PCM info field");
3673 return 0; /* FIXME: should be a negative error? */
3675 return !!(params->info & SND_PCM_INFO_MONOTONIC);
3679 * \brief Check if hardware supports overrange detection
3680 * \param params Configuration space
3681 * \retval 0 Hardware doesn't support overrange detection
3682 * \retval 1 Hardware supports overrange detection
3684 * This function should only be called when the configuration space
3685 * contains a single configuration. Call #snd_pcm_hw_params to choose
3686 * a single configuration from the configuration space.
3688 int snd_pcm_hw_params_can_overrange(const snd_pcm_hw_params_t *params)
3691 if (CHECK_SANITY(params->info == ~0U)) {
3692 SNDMSG("invalid PCM info field");
3693 return 0; /* FIXME: should be a negative error? */
3695 return !!(params->info & SNDRV_PCM_INFO_OVERRANGE);
3699 * \brief Check if hardware supports pause
3700 * \param params Configuration space
3701 * \retval 0 Hardware doesn't support pause
3702 * \retval 1 Hardware supports pause
3704 * This function should only be called when the configuration space
3705 * contains a single configuration. Call #snd_pcm_hw_params to choose
3706 * a single configuration from the configuration space.
3708 int snd_pcm_hw_params_can_pause(const snd_pcm_hw_params_t *params)
3711 if (CHECK_SANITY(params->info == ~0U)) {
3712 SNDMSG("invalid PCM info field");
3713 return 0; /* FIXME: should be a negative error? */
3715 return !!(params->info & SNDRV_PCM_INFO_PAUSE);
3719 * \brief Check if hardware supports resume
3720 * \param params Configuration space
3721 * \retval 0 Hardware doesn't support resume
3722 * \retval 1 Hardware supports resume
3724 * This function should only be called when the configuration space
3725 * contains a single configuration. Call #snd_pcm_hw_params to choose
3726 * a single configuration from the configuration space.
3728 int snd_pcm_hw_params_can_resume(const snd_pcm_hw_params_t *params)
3731 if (CHECK_SANITY(params->info == ~0U)) {
3732 SNDMSG("invalid PCM info field");
3733 return 0; /* FIXME: should be a negative error? */
3735 return !!(params->info & SNDRV_PCM_INFO_RESUME);
3739 * \brief Check if hardware does half-duplex only
3740 * \param params Configuration space
3741 * \retval 0 Hardware doesn't do half-duplex
3742 * \retval 1 Hardware does half-duplex
3744 * This function should only be called when the configuration space
3745 * contains a single configuration. Call #snd_pcm_hw_params to choose
3746 * a single configuration from the configuration space.
3748 int snd_pcm_hw_params_is_half_duplex(const snd_pcm_hw_params_t *params)
3751 if (CHECK_SANITY(params->info == ~0U)) {
3752 SNDMSG("invalid PCM info field");
3753 return 0; /* FIXME: should be a negative error? */
3755 return !!(params->info & SNDRV_PCM_INFO_HALF_DUPLEX);
3759 * \brief Check if hardware does joint-duplex (playback and capture are somewhat correlated)
3760 * \param params Configuration space
3761 * \retval 0 Hardware doesn't do joint-duplex
3762 * \retval 1 Hardware does joint-duplex
3764 * This function should only be called when the configuration space
3765 * contains a single configuration. Call #snd_pcm_hw_params to choose
3766 * a single configuration from the configuration space.
3768 int snd_pcm_hw_params_is_joint_duplex(const snd_pcm_hw_params_t *params)
3771 if (CHECK_SANITY(params->info == ~0U)) {
3772 SNDMSG("invalid PCM info field");
3773 return 0; /* FIXME: should be a negative error? */
3775 return !!(params->info & SNDRV_PCM_INFO_JOINT_DUPLEX);
3779 * \brief Check if hardware supports synchronized start with sample resolution
3780 * \param params Configuration space
3781 * \retval 0 Hardware doesn't support synchronized start
3782 * \retval 1 Hardware supports synchronized start
3784 * This function should only be called when the configuration space
3785 * contains a single configuration. Call #snd_pcm_hw_params to choose
3786 * a single configuration from the configuration space.
3788 int snd_pcm_hw_params_can_sync_start(const snd_pcm_hw_params_t *params)
3791 if (CHECK_SANITY(params->info == ~0U)) {
3792 SNDMSG("invalid PCM info field");
3793 return 0; /* FIXME: should be a negative error? */
3795 return !!(params->info & SNDRV_PCM_INFO_SYNC_START);
3799 * \brief Check if hardware can disable period wakeups
3800 * \param params Configuration space
3801 * \retval 0 Hardware cannot disable period wakeups
3802 * \retval 1 Hardware can disable period wakeups
3804 int snd_pcm_hw_params_can_disable_period_wakeup(const snd_pcm_hw_params_t *params)
3807 if (CHECK_SANITY(params->info == ~0U)) {
3808 SNDMSG("invalid PCM info field");
3809 return 0; /* FIXME: should be a negative error? */
3811 return !!(params->info & SNDRV_PCM_INFO_NO_PERIOD_WAKEUP);
3815 * \brief Check if hardware is capable of perfect drain
3816 * \param params Configuration space
3817 * \retval 0 Hardware doesn't do perfect drain
3818 * \retval 1 Hardware does perfect drain
3820 * This function should only be called when the configuration space
3821 * contains a single configuration. Call #snd_pcm_hw_params to choose
3822 * a single configuration from the configuration space.
3824 * Perfect drain means that the hardware does not use samples
3825 * beyond the stream application pointer.
3827 int snd_pcm_hw_params_is_perfect_drain(const snd_pcm_hw_params_t *params)
3830 if (CHECK_SANITY(params->info == ~0U)) {
3831 SNDMSG("invalid PCM info field");
3832 return 0; /* FIXME: should be a negative error? */
3834 return !!(params->info & SNDRV_PCM_INFO_PERFECT_DRAIN);
3838 * \brief Check if hardware supports audio wallclock timestamps
3839 * \param params Configuration space
3840 * \retval 0 Hardware doesn't support audio wallclock timestamps
3841 * \retval 1 Hardware supports audio wallclock timestamps
3843 * This function should only be called when the configuration space
3844 * contains a single configuration. Call #snd_pcm_hw_params to choose
3845 * a single configuration from the configuration space.
3847 int snd_pcm_hw_params_supports_audio_wallclock_ts(const snd_pcm_hw_params_t *params)
3850 return snd_pcm_hw_params_supports_audio_ts_type(params,
3851 SNDRV_PCM_AUDIO_TSTAMP_TYPE_COMPAT);
3855 * \brief Check if hardware supports type of audio timestamps
3856 * \param params Configuration space
3857 * \param type Audio timestamp type
3858 * \retval 0 Hardware doesn't support type of audio timestamps
3859 * \retval 1 Hardware supports type of audio timestamps
3861 * This function should only be called when the configuration space
3862 * contains a single configuration. Call #snd_pcm_hw_params to choose
3863 * a single configuration from the configuration space.
3865 int snd_pcm_hw_params_supports_audio_ts_type(const snd_pcm_hw_params_t *params, int type)
3868 if (CHECK_SANITY(params->info == ~0U)) {
3869 SNDMSG("invalid PCM info field");
3870 return 0; /* FIXME: should be a negative error? */
3873 case SNDRV_PCM_AUDIO_TSTAMP_TYPE_COMPAT:
3874 return !!(params->info & SNDRV_PCM_INFO_HAS_WALL_CLOCK); /* deprecated */
3875 case SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT:
3876 return 1; /* always supported, based on hw_ptr */
3877 case SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK:
3878 return !!(params->info & SNDRV_PCM_INFO_HAS_LINK_ATIME);
3879 case SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_ABSOLUTE:
3880 return !!(params->info & SNDRV_PCM_INFO_HAS_LINK_ABSOLUTE_ATIME);
3881 case SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_ESTIMATED:
3882 return !!(params->info & SNDRV_PCM_INFO_HAS_LINK_ESTIMATED_ATIME);
3883 case SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_SYNCHRONIZED:
3884 return !!(params->info & SNDRV_PCM_INFO_HAS_LINK_SYNCHRONIZED_ATIME);
3891 * \brief Get rate exact info from a configuration space
3892 * \param params Configuration space
3893 * \param rate_num Pointer to returned rate numerator
3894 * \param rate_den Pointer to returned rate denominator
3895 * \return 0 otherwise a negative error code if the info is not available
3897 * This function should only be called when the configuration space
3898 * contains a single configuration. Call #snd_pcm_hw_params to choose
3899 * a single configuration from the configuration space.
3901 int snd_pcm_hw_params_get_rate_numden(const snd_pcm_hw_params_t *params,
3902 unsigned int *rate_num, unsigned int *rate_den)
3905 if (CHECK_SANITY(params->rate_den == 0)) {
3906 SNDMSG("invalid rate_den value");
3909 *rate_num = params->rate_num;
3910 *rate_den = params->rate_den;
3915 * \brief Get sample resolution info from a configuration space
3916 * \param params Configuration space
3917 * \return sample resolution (in bits) otherwise a negative error code if the info is not available
3919 * For linear formats, this function returns sample resolution -
3920 * used bits starting from the first usable significant bit defined by
3921 * the format (e.g. bit 31 for S32_LE format or bit 23 for S24_LE format -
3922 * starting from bit zero). Application may use full sample bit range defined
3923 * by the format, but additional bits (outside this sample resolution) are
3924 * stripped (not processed).
3926 * For non-linear formats, this value may have a special meaning which may be defined in future.
3928 * This function should only be called when the configuration space
3929 * contains a single configuration. Call #snd_pcm_hw_params to choose
3930 * a single configuration from the configuration space.
3932 int snd_pcm_hw_params_get_sbits(const snd_pcm_hw_params_t *params)
3935 if (CHECK_SANITY(params->msbits == 0)) {
3936 SNDMSG("invalid msbits value");
3939 return params->msbits;
3943 * \brief Get hardware FIFO size info from a configuration space
3944 * \param params Configuration space
3945 * \return FIFO size in frames otherwise a negative error code if the info is not available
3947 * This function should only be called when the configuration space
3948 * contains a single configuration. Call #snd_pcm_hw_params to choose
3949 * a single configuration from the configuration space.
3951 int snd_pcm_hw_params_get_fifo_size(const snd_pcm_hw_params_t *params)
3954 if (CHECK_SANITY(params->info == ~0U)) {
3955 SNDMSG("invalid PCM info field");
3958 return params->fifo_size;
3962 * \brief Get hardware synchronization ID from a PCM info container
3963 * \param params Configuration space
3964 * \return 16-byte synchronization ID (use #SND_PCM_HW_PARAMS_SYNC_SIZE)
3966 * This synchronization ID determines the similar clocks for the
3967 * PCM stream between multiple devices (including different cards).
3968 * "All zeros" means "not set". The contents of the ID can be used
3969 * only for a comparison with the contents of another ID returned
3970 * from this function. Applications should not do a comparison with
3971 * hard-coded values, because the implementation generating such
3972 * synchronization IDs may be changed in future.
3974 const unsigned char *snd_pcm_hw_params_get_sync(const snd_pcm_hw_params_t *params)
3977 return params->sync;
3981 * \brief Fill params with a full configuration space for a PCM
3982 * \param pcm PCM handle
3983 * \param params Configuration space
3985 * The configuration space will be filled with all possible ranges
3986 * for the PCM device.
3988 * Note that the configuration space may be constrained by the
3989 * currently installed configuration on the PCM device. To remove
3990 * any constrains, free the configuration with #snd_pcm_hw_free
3993 int snd_pcm_hw_params_any(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
3995 _snd_pcm_hw_params_any(params);
3996 return snd_pcm_hw_refine(pcm, params);
4000 * \brief get size of #snd_pcm_access_mask_t
4001 * \return size in bytes
4003 size_t snd_pcm_access_mask_sizeof()
4005 return sizeof(snd_pcm_access_mask_t);
4009 * \brief allocate an empty #snd_pcm_access_mask_t using standard malloc
4010 * \param ptr returned pointer
4011 * \return 0 on success otherwise negative error code
4013 int snd_pcm_access_mask_malloc(snd_pcm_access_mask_t **ptr)
4016 *ptr = calloc(1, sizeof(snd_pcm_access_mask_t));
4023 * \brief frees a previously allocated #snd_pcm_access_mask_t
4024 * \param obj pointer to object to free
4026 void snd_pcm_access_mask_free(snd_pcm_access_mask_t *obj)
4032 * \brief copy one #snd_pcm_access_mask_t to another
4033 * \param dst pointer to destination
4034 * \param src pointer to source
4036 void snd_pcm_access_mask_copy(snd_pcm_access_mask_t *dst, const snd_pcm_access_mask_t *src)
4043 * \brief reset all bits in a #snd_pcm_access_mask_t
4044 * \param mask pointer to mask
4046 void snd_pcm_access_mask_none(snd_pcm_access_mask_t *mask)
4048 snd_mask_none((snd_mask_t *) mask);
4052 * \brief set all bits in a #snd_pcm_access_mask_t
4053 * \param mask pointer to mask
4055 void snd_pcm_access_mask_any(snd_pcm_access_mask_t *mask)
4057 snd_mask_any((snd_mask_t *) mask);
4061 * \brief test the presence of an access type in a #snd_pcm_access_mask_t
4062 * \param mask pointer to mask
4063 * \param val access type
4065 int snd_pcm_access_mask_test(const snd_pcm_access_mask_t *mask, snd_pcm_access_t val)
4067 return snd_mask_test((const snd_mask_t *) mask, (unsigned long) val);
4071 * \brief test, if given a #snd_pcm_access_mask_t is empty
4072 * \param mask pointer to mask
4073 * \retval 0 not empty
4076 int snd_pcm_access_mask_empty(const snd_pcm_access_mask_t *mask)
4078 return snd_mask_empty((const snd_mask_t *) mask);
4082 * \brief make an access type present in a #snd_pcm_access_mask_t
4083 * \param mask pointer to mask
4084 * \param val access type
4086 void snd_pcm_access_mask_set(snd_pcm_access_mask_t *mask, snd_pcm_access_t val)
4088 snd_mask_set((snd_mask_t *) mask, (unsigned long) val);
4092 * \brief make an access type missing from a #snd_pcm_access_mask_t
4093 * \param mask pointer to mask
4094 * \param val access type
4096 void snd_pcm_access_mask_reset(snd_pcm_access_mask_t *mask, snd_pcm_access_t val)
4098 snd_mask_reset((snd_mask_t *) mask, (unsigned long) val);
4102 * \brief get size of #snd_pcm_format_mask_t
4103 * \return size in bytes
4105 size_t snd_pcm_format_mask_sizeof()
4107 return sizeof(snd_pcm_format_mask_t);
4111 * \brief allocate an empty #snd_pcm_format_mask_t using standard malloc
4112 * \param ptr returned pointer
4113 * \return 0 on success otherwise negative error code
4115 int snd_pcm_format_mask_malloc(snd_pcm_format_mask_t **ptr)
4118 *ptr = calloc(1, sizeof(snd_pcm_format_mask_t));
4125 * \brief frees a previously allocated #snd_pcm_format_mask_t
4126 * \param obj pointer to object to free
4128 void snd_pcm_format_mask_free(snd_pcm_format_mask_t *obj)
4134 * \brief copy one #snd_pcm_format_mask_t to another
4135 * \param dst pointer to destination
4136 * \param src pointer to source
4138 void snd_pcm_format_mask_copy(snd_pcm_format_mask_t *dst, const snd_pcm_format_mask_t *src)
4145 * \brief reset all bits in a #snd_pcm_format_mask_t
4146 * \param mask pointer to mask
4148 void snd_pcm_format_mask_none(snd_pcm_format_mask_t *mask)
4150 snd_mask_none((snd_mask_t *) mask);
4154 * \brief set all bits in a #snd_pcm_format_mask_t
4155 * \param mask pointer to mask
4157 void snd_pcm_format_mask_any(snd_pcm_format_mask_t *mask)
4159 snd_mask_any((snd_mask_t *) mask);
4163 * \brief test the presence of a format in a #snd_pcm_format_mask_t
4164 * \param mask pointer to mask
4167 int snd_pcm_format_mask_test(const snd_pcm_format_mask_t *mask, snd_pcm_format_t val)
4169 return snd_mask_test((const snd_mask_t *) mask, (unsigned long) val);
4173 * \brief test, if given a #snd_pcm_format_mask_t is empty
4174 * \param mask pointer to mask
4175 * \retval 0 not empty
4178 int snd_pcm_format_mask_empty(const snd_pcm_format_mask_t *mask)
4180 return snd_mask_empty((const snd_mask_t *) mask);
4184 * \brief make a format present in a #snd_pcm_format_mask_t
4185 * \param mask pointer to mask
4188 void snd_pcm_format_mask_set(snd_pcm_format_mask_t *mask, snd_pcm_format_t val)
4190 snd_mask_set((snd_mask_t *) mask, (unsigned long) val);
4194 * \brief make a format missing from a #snd_pcm_format_mask_t
4195 * \param mask pointer to mask
4198 void snd_pcm_format_mask_reset(snd_pcm_format_mask_t *mask, snd_pcm_format_t val)
4200 snd_mask_reset((snd_mask_t *) mask, (unsigned long) val);
4205 * \brief get size of #snd_pcm_subformat_mask_t
4206 * \return size in bytes
4208 size_t snd_pcm_subformat_mask_sizeof()
4210 return sizeof(snd_pcm_subformat_mask_t);
4214 * \brief allocate an empty #snd_pcm_subformat_mask_t using standard malloc
4215 * \param ptr returned pointer
4216 * \return 0 on success otherwise negative error code
4218 int snd_pcm_subformat_mask_malloc(snd_pcm_subformat_mask_t **ptr)
4221 *ptr = calloc(1, sizeof(snd_pcm_subformat_mask_t));
4228 * \brief frees a previously allocated #snd_pcm_subformat_mask_t
4229 * \param obj pointer to object to free
4231 void snd_pcm_subformat_mask_free(snd_pcm_subformat_mask_t *obj)
4237 * \brief copy one #snd_pcm_subformat_mask_t to another
4238 * \param dst pointer to destination
4239 * \param src pointer to source
4241 void snd_pcm_subformat_mask_copy(snd_pcm_subformat_mask_t *dst, const snd_pcm_subformat_mask_t *src)
4248 * \brief reset all bits in a #snd_pcm_subformat_mask_t
4249 * \param mask pointer to mask
4251 void snd_pcm_subformat_mask_none(snd_pcm_subformat_mask_t *mask)
4253 snd_mask_none((snd_mask_t *) mask);
4257 * \brief set all bits in a #snd_pcm_subformat_mask_t
4258 * \param mask pointer to mask
4260 void snd_pcm_subformat_mask_any(snd_pcm_subformat_mask_t *mask)
4262 snd_mask_any((snd_mask_t *) mask);
4266 * \brief test the presence of a subformat in a #snd_pcm_subformat_mask_t
4267 * \param mask pointer to mask
4268 * \param val subformat
4270 int snd_pcm_subformat_mask_test(const snd_pcm_subformat_mask_t *mask, snd_pcm_subformat_t val)
4272 return snd_mask_test((const snd_mask_t *) mask, (unsigned long) val);
4276 * \brief test, if given a #snd_pcm_subformat_mask_t is empty
4277 * \param mask pointer to mask
4278 * \retval 0 not empty
4281 int snd_pcm_subformat_mask_empty(const snd_pcm_subformat_mask_t *mask)
4283 return snd_mask_empty((const snd_mask_t *) mask);
4287 * \brief make a subformat present in a #snd_pcm_subformat_mask_t
4288 * \param mask pointer to mask
4289 * \param val subformat
4291 void snd_pcm_subformat_mask_set(snd_pcm_subformat_mask_t *mask, snd_pcm_subformat_t val)
4293 snd_mask_set((snd_mask_t *) mask, (unsigned long) val);
4297 * \brief make a subformat missing from a #snd_pcm_subformat_mask_t
4298 * \param mask pointer to mask
4299 * \param val subformat
4301 void snd_pcm_subformat_mask_reset(snd_pcm_subformat_mask_t *mask, snd_pcm_subformat_t val)
4303 snd_mask_reset((snd_mask_t *) mask, (unsigned long) val);
4308 * \brief get size of #snd_pcm_hw_params_t
4309 * \return size in bytes
4311 size_t snd_pcm_hw_params_sizeof()
4313 return sizeof(snd_pcm_hw_params_t);
4317 * \brief allocate an invalid #snd_pcm_hw_params_t using standard malloc
4318 * \param ptr returned pointer
4319 * \return 0 on success otherwise negative error code
4321 int snd_pcm_hw_params_malloc(snd_pcm_hw_params_t **ptr)
4324 *ptr = calloc(1, sizeof(snd_pcm_hw_params_t));
4331 * \brief frees a previously allocated #snd_pcm_hw_params_t
4332 * \param obj pointer to object to free
4334 void snd_pcm_hw_params_free(snd_pcm_hw_params_t *obj)
4340 * \brief copy one #snd_pcm_hw_params_t to another
4341 * \param dst pointer to destination
4342 * \param src pointer to source
4344 void snd_pcm_hw_params_copy(snd_pcm_hw_params_t *dst, const snd_pcm_hw_params_t *src)
4352 * \brief Extract access type from a configuration space
4353 * \param params Configuration space
4354 * \param access Returned value
4355 * \return access type otherwise a negative error code if the configuration space does not contain a single value
4358 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_access)(const snd_pcm_hw_params_t *params, snd_pcm_access_t *access)
4360 int snd_pcm_hw_params_get_access(const snd_pcm_hw_params_t *params, snd_pcm_access_t *access)
4364 int err = snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_ACCESS, &_val, NULL);
4371 * \brief Verify if an access type is available inside a configuration space for a PCM
4372 * \param pcm PCM handle
4373 * \param params Configuration space
4374 * \param access access type
4375 * \return 0 if available a negative error code otherwise
4377 int snd_pcm_hw_params_test_access(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t access)
4379 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_ACCESS, access, 0);
4383 * \brief Restrict a configuration space to contain only one access type
4384 * \param pcm PCM handle
4385 * \param params Configuration space
4386 * \param access access type
4387 * \return 0 otherwise a negative error code if configuration space would become empty
4389 int snd_pcm_hw_params_set_access(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t access)
4391 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_ACCESS, access, 0);
4395 * \brief Restrict a configuration space to contain only its first access type
4396 * \param pcm PCM handle
4397 * \param params Configuration space
4398 * \param access Returned first access type
4399 * \return 0 otherwise a negative error code
4402 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)
4404 int snd_pcm_hw_params_set_access_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t *access)
4407 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_ACCESS, access, NULL);
4411 * \brief Restrict a configuration space to contain only its last access type
4412 * \param pcm PCM handle
4413 * \param params Configuration space
4414 * \param access Returned last access type
4415 * \return 0 otherwise a negative error code
4418 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)
4420 int snd_pcm_hw_params_set_access_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t *access)
4423 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_ACCESS, access, NULL);
4427 * \brief Restrict a configuration space to contain only a set of access types
4428 * \param pcm PCM handle
4429 * \param params Configuration space
4430 * \param mask Access mask
4431 * \return 0 otherwise a negative error code
4433 int snd_pcm_hw_params_set_access_mask(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_mask_t *mask)
4435 return snd_pcm_hw_param_set_mask(pcm, params, SND_TRY, SND_PCM_HW_PARAM_ACCESS, (snd_mask_t *) mask);
4439 * \brief Get access mask from a configuration space
4440 * \param params Configuration space
4441 * \param mask Returned Access mask
4443 int snd_pcm_hw_params_get_access_mask(snd_pcm_hw_params_t *params, snd_pcm_access_mask_t *mask)
4445 if (params == NULL || mask == NULL)
4447 snd_pcm_access_mask_copy(mask, snd_pcm_hw_param_get_mask(params, SND_PCM_HW_PARAM_ACCESS));
4453 * \brief Extract format from a configuration space
4454 * \param params Configuration space
4455 * \param format returned format
4456 * \return format otherwise a negative error code if the configuration space does not contain a single value
4459 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_format)(const snd_pcm_hw_params_t *params, snd_pcm_format_t *format)
4461 int snd_pcm_hw_params_get_format(const snd_pcm_hw_params_t *params, snd_pcm_format_t *format)
4464 return snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_FORMAT, (unsigned int *)format, NULL);
4468 * \brief Verify if a format is available inside a configuration space for a PCM
4469 * \param pcm PCM handle
4470 * \param params Configuration space
4471 * \param format format
4472 * \return 0 if available a negative error code otherwise
4474 int snd_pcm_hw_params_test_format(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t format)
4476 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_FORMAT, format, 0);
4480 * \brief Restrict a configuration space to contain only one format
4481 * \param pcm PCM handle
4482 * \param params Configuration space
4483 * \param format format
4484 * \return 0 otherwise a negative error code
4486 int snd_pcm_hw_params_set_format(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t format)
4488 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_FORMAT, format, 0);
4492 * \brief Restrict a configuration space to contain only its first format
4493 * \param pcm PCM handle
4494 * \param params Configuration space
4495 * \param format Returned first format
4496 * \return 0 otherwise a negative error code
4499 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)
4501 int snd_pcm_hw_params_set_format_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t *format)
4504 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_FORMAT, (unsigned int *)format, NULL);
4508 * \brief Restrict a configuration space to contain only its last format
4509 * \param pcm PCM handle
4510 * \param params Configuration space
4511 * \param format Returned last format
4512 * \return 0 otherwise a negative error code
4515 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)
4517 int snd_pcm_hw_params_set_format_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t *format)
4520 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_FORMAT, (unsigned int *)format, NULL);
4524 * \brief Restrict a configuration space to contain only a set of formats
4525 * \param pcm PCM handle
4526 * \param params Configuration space
4527 * \param mask Format mask
4528 * \return 0 otherwise a negative error code
4530 int snd_pcm_hw_params_set_format_mask(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_mask_t *mask)
4532 return snd_pcm_hw_param_set_mask(pcm, params, SND_TRY, SND_PCM_HW_PARAM_FORMAT, (snd_mask_t *) mask);
4536 * \brief Get format mask from a configuration space
4537 * \param params Configuration space
4538 * \param mask Returned Format mask
4540 void snd_pcm_hw_params_get_format_mask(snd_pcm_hw_params_t *params, snd_pcm_format_mask_t *mask)
4542 snd_pcm_format_mask_copy(mask, snd_pcm_hw_param_get_mask(params, SND_PCM_HW_PARAM_FORMAT));
4547 * \brief Extract subformat from a configuration space
4548 * \param params Configuration space
4549 * \param subformat Returned subformat value
4550 * \return subformat otherwise a negative error code if the configuration space does not contain a single value
4553 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_subformat)(const snd_pcm_hw_params_t *params, snd_pcm_subformat_t *subformat)
4555 int snd_pcm_hw_params_get_subformat(const snd_pcm_hw_params_t *params, snd_pcm_subformat_t *subformat)
4558 return snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_SUBFORMAT, (unsigned int *)subformat, NULL);
4562 * \brief Verify if a subformat is available inside a configuration space for a PCM
4563 * \param pcm PCM handle
4564 * \param params Configuration space
4565 * \param subformat subformat value
4566 * \return 0 if available a negative error code otherwise
4568 int snd_pcm_hw_params_test_subformat(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t subformat)
4570 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_SUBFORMAT, subformat, 0);
4574 * \brief Restrict a configuration space to contain only one subformat
4575 * \param pcm PCM handle
4576 * \param params Configuration space
4577 * \param subformat subformat value
4578 * \return 0 otherwise a negative error code if configuration space would become empty
4580 int snd_pcm_hw_params_set_subformat(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t subformat)
4582 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_SUBFORMAT, subformat, 0);
4586 * \brief Restrict a configuration space to contain only its first subformat
4587 * \param pcm PCM handle
4588 * \param params Configuration space
4589 * \param subformat Returned subformat
4590 * \return 0 otherwise a negative error code
4593 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)
4595 int snd_pcm_hw_params_set_subformat_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t *subformat)
4598 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_SUBFORMAT, (unsigned int *)subformat, NULL);
4602 * \brief Restrict a configuration space to contain only its last subformat
4603 * \param pcm PCM handle
4604 * \param params Configuration space
4605 * \param subformat Returned subformat
4606 * \return 0 otherwise a negative error code
4609 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)
4611 int snd_pcm_hw_params_set_subformat_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t *subformat)
4614 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_SUBFORMAT, (unsigned int *)subformat, NULL);
4618 * \brief Restrict a configuration space to contain only a set of subformats
4619 * \param pcm PCM handle
4620 * \param params Configuration space
4621 * \param mask Subformat mask
4622 * \return 0 otherwise a negative error code
4624 int snd_pcm_hw_params_set_subformat_mask(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_mask_t *mask)
4626 return snd_pcm_hw_param_set_mask(pcm, params, SND_TRY, SND_PCM_HW_PARAM_SUBFORMAT, (snd_mask_t *) mask);
4630 * \brief Get subformat mask from a configuration space
4631 * \param params Configuration space
4632 * \param mask Returned Subformat mask
4634 void snd_pcm_hw_params_get_subformat_mask(snd_pcm_hw_params_t *params, snd_pcm_subformat_mask_t *mask)
4636 snd_pcm_subformat_mask_copy(mask, snd_pcm_hw_param_get_mask(params, SND_PCM_HW_PARAM_SUBFORMAT));
4641 * \brief Extract channels from a configuration space
4642 * \param params Configuration space
4643 * \param val Returned channels count
4644 * \return 0 otherwise a negative error code if the configuration space does not contain a single value
4647 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_channels)(const snd_pcm_hw_params_t *params, unsigned int *val)
4649 int snd_pcm_hw_params_get_channels(const snd_pcm_hw_params_t *params, unsigned int *val)
4652 return snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
4656 * \brief Extract minimum channels count from a configuration space
4657 * \param params Configuration space
4658 * \param val minimum channels count
4659 * \return 0 otherwise a negative error code
4662 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_channels_min)(const snd_pcm_hw_params_t *params, unsigned int *val)
4664 int snd_pcm_hw_params_get_channels_min(const snd_pcm_hw_params_t *params, unsigned int *val)
4667 return snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
4671 * \brief Extract maximum channels count from a configuration space
4672 * \param params Configuration space
4673 * \param val maximum channels count
4674 * \return 0 otherwise a negative error code
4677 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_channels_max)(const snd_pcm_hw_params_t *params, unsigned int *val)
4679 int snd_pcm_hw_params_get_channels_max(const snd_pcm_hw_params_t *params, unsigned int *val)
4682 return snd_pcm_hw_param_get_max(params, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
4686 * \brief Verify if a channels count is available inside a configuration space for a PCM
4687 * \param pcm PCM handle
4688 * \param params Configuration space
4689 * \param val channels count
4690 * \return 0 if available a negative error code otherwise
4692 int snd_pcm_hw_params_test_channels(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val)
4694 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_CHANNELS, val, 0);
4698 * \brief Restrict a configuration space to contain only one channels count
4699 * \param pcm PCM handle
4700 * \param params Configuration space
4701 * \param val channels count
4702 * \return 0 otherwise a negative error code if configuration space would become empty
4704 int snd_pcm_hw_params_set_channels(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val)
4706 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_CHANNELS, val, 0);
4710 * \brief Restrict a configuration space with a minimum channels count
4711 * \param pcm PCM handle
4712 * \param params Configuration space
4713 * \param val minimum channels count (on return filled with actual minimum)
4714 * \return 0 otherwise a negative error code if configuration space would become empty
4716 int snd_pcm_hw_params_set_channels_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4718 return snd_pcm_hw_param_set_min(pcm, params, SND_TRY, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
4722 * \brief Restrict a configuration space with a maximum channels count
4723 * \param pcm PCM handle
4724 * \param params Configuration space
4725 * \param val maximum channels count (on return filled with actual maximum)
4726 * \return 0 otherwise a negative error code if configuration space would become empty
4728 int snd_pcm_hw_params_set_channels_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4730 return snd_pcm_hw_param_set_max(pcm, params, SND_TRY, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
4734 * \brief Restrict a configuration space to have channels counts in a given range
4735 * \param pcm PCM handle
4736 * \param params Configuration space
4737 * \param min minimum channels count (on return filled with actual minimum)
4738 * \param max maximum channels count (on return filled with actual maximum)
4739 * \return 0 otherwise a negative error code if configuration space would become empty
4741 int snd_pcm_hw_params_set_channels_minmax(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *min, unsigned int *max)
4743 return snd_pcm_hw_param_set_minmax(pcm, params, SND_TRY, SND_PCM_HW_PARAM_CHANNELS, min, NULL, max, NULL);
4747 * \brief Restrict a configuration space to have channels count nearest to a target
4748 * \param pcm PCM handle
4749 * \param params Configuration space
4750 * \param val target channels count, returned chosen channels count
4751 * \return 0 otherwise a negative error code if configuration space is empty
4754 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_channels_near)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4756 int snd_pcm_hw_params_set_channels_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4759 return snd_pcm_hw_param_set_near(pcm, params, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
4763 * \brief Restrict a configuration space to contain only its minimum channels count
4764 * \param pcm PCM handle
4765 * \param params Configuration space
4766 * \param val minimum channels count
4767 * \return 0 otherwise a negative error code
4770 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_channels_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4772 int snd_pcm_hw_params_set_channels_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4775 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
4779 * \brief Restrict a configuration space to contain only its maximum channels count
4780 * \param pcm PCM handle
4781 * \param params Configuration space
4782 * \param val maximum channels count
4783 * \return 0 otherwise a negative error code
4786 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_channels_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4788 int snd_pcm_hw_params_set_channels_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4791 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
4796 * \brief Extract rate from a configuration space
4797 * \param params Configuration space
4798 * \param val Returned approximate rate
4799 * \param dir Sub unit direction
4800 * \return 0 otherwise a negative error code if the configuration space does not contain a single value
4802 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
4805 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_rate)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4807 int snd_pcm_hw_params_get_rate(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4810 return snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_RATE, val, dir);
4814 * \brief Extract minimum rate from a configuration space
4815 * \param params Configuration space
4816 * \param val Returned approximate minimum rate
4817 * \param dir Sub unit direction
4818 * \return 0 otherwise a negative error code
4820 * Exact value is <,=,> the returned one following dir (-1,0,1)
4823 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_rate_min)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4825 int snd_pcm_hw_params_get_rate_min(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4828 return snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_RATE, val, dir);
4832 * \brief Extract maximum rate from a configuration space
4833 * \param params Configuration space
4834 * \param val Returned approximate maximum rate
4835 * \param dir Sub unit direction
4836 * \return 0 otherwise a negative error code
4838 * Exact value is <,=,> the returned one following dir (-1,0,1)
4841 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_rate_max)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4843 int snd_pcm_hw_params_get_rate_max(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4846 return snd_pcm_hw_param_get_max(params, SND_PCM_HW_PARAM_RATE, val, dir);
4850 * \brief Verify if a rate is available inside a configuration space for a PCM
4851 * \param pcm PCM handle
4852 * \param params Configuration space
4853 * \param val approximate rate
4854 * \param dir Sub unit direction
4855 * \return 0 if available a negative error code otherwise
4857 * Wanted exact value is <,=,> val following dir (-1,0,1)
4859 int snd_pcm_hw_params_test_rate(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
4861 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_RATE, val, dir);
4865 * \brief Restrict a configuration space to contain only one rate
4866 * \param pcm PCM handle
4867 * \param params Configuration space
4868 * \param val approximate rate
4869 * \param dir Sub unit direction
4870 * \return 0 otherwise a negative error code if configuration space would become empty
4872 * Wanted exact value is <,=,> val following dir (-1,0,1)
4874 int snd_pcm_hw_params_set_rate(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
4876 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_RATE, val, dir);
4880 * \brief Restrict a configuration space with a minimum rate
4881 * \param pcm PCM handle
4882 * \param params Configuration space
4883 * \param val approximate minimum rate (on return filled with actual minimum)
4884 * \param dir Sub unit direction (on return filled with actual direction)
4885 * \return 0 otherwise a negative error code if configuration space would become empty
4887 * Wanted/actual exact minimum is <,=,> val following dir (-1,0,1)
4889 int snd_pcm_hw_params_set_rate_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4891 return snd_pcm_hw_param_set_min(pcm, params, SND_TRY, SND_PCM_HW_PARAM_RATE, val, dir);
4895 * \brief Restrict a configuration space with a maximum rate
4896 * \param pcm PCM handle
4897 * \param params Configuration space
4898 * \param val approximate maximum rate (on return filled with actual maximum)
4899 * \param dir Sub unit direction (on return filled with actual direction)
4900 * \return 0 otherwise a negative error code if configuration space would become empty
4902 * Wanted/actual exact maximum is <,=,> val following dir (-1,0,1)
4904 int snd_pcm_hw_params_set_rate_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4906 return snd_pcm_hw_param_set_max(pcm, params, SND_TRY, SND_PCM_HW_PARAM_RATE, val, dir);
4910 * \brief Restrict a configuration space to have rates in a given range
4911 * \param pcm PCM handle
4912 * \param params Configuration space
4913 * \param min approximate minimum rate (on return filled with actual minimum)
4914 * \param mindir Sub unit direction for minimum (on return filled with actual direction)
4915 * \param max approximate maximum rate (on return filled with actual maximum)
4916 * \param maxdir Sub unit direction for maximum (on return filled with actual direction)
4917 * \return 0 otherwise a negative error code if configuration space would become empty
4919 * Wanted/actual exact min/max is <,=,> val following dir (-1,0,1)
4921 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)
4923 return snd_pcm_hw_param_set_minmax(pcm, params, SND_TRY, SND_PCM_HW_PARAM_RATE, min, mindir, max, maxdir);
4927 * \brief Restrict a configuration space to have rate nearest to a target
4928 * \param pcm PCM handle
4929 * \param params Configuration space
4930 * \param val approximate target rate / returned approximate set rate
4931 * \param dir Sub unit direction
4932 * \return 0 otherwise a negative error code if configuration space is empty
4934 * target/chosen exact value is <,=,> val following dir (-1,0,1)
4937 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)
4939 int snd_pcm_hw_params_set_rate_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4942 return snd_pcm_hw_param_set_near(pcm, params, SND_PCM_HW_PARAM_RATE, val, dir);
4946 * \brief Restrict a configuration space to contain only its minimum rate
4947 * \param pcm PCM handle
4948 * \param params Configuration space
4949 * \param val Returned minimum approximate rate
4950 * \param dir Sub unit direction
4951 * \return 0 otherwise a negative error code
4953 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
4956 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)
4958 int snd_pcm_hw_params_set_rate_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4961 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_RATE, val, dir);
4965 * \brief Restrict a configuration space to contain only its maximum rate
4966 * \param pcm PCM handle
4967 * \param params Configuration space
4968 * \param val Returned maximum approximate rate
4969 * \param dir Sub unit direction
4970 * \return 0 otherwise a negative error code
4972 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
4975 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)
4977 int snd_pcm_hw_params_set_rate_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4980 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_RATE, val, dir);
4984 * \brief Restrict a configuration space to contain only real hardware rates
4985 * \param pcm PCM handle
4986 * \param params Configuration space
4987 * \param val 0 = disable, 1 = enable (default) rate resampling
4988 * \return 0 otherwise a negative error code
4990 int snd_pcm_hw_params_set_rate_resample(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val)
4992 assert(pcm && params);
4994 params->flags |= SND_PCM_HW_PARAMS_NORESAMPLE;
4996 params->flags &= ~SND_PCM_HW_PARAMS_NORESAMPLE;
4998 return snd_pcm_hw_refine(pcm, params);
5002 * \brief Extract resample state from a configuration space
5003 * \param pcm PCM handle
5004 * \param params Configuration space
5005 * \param val 0 = disable, 1 = enable rate resampling
5006 * \return 0 otherwise a negative error code
5008 int snd_pcm_hw_params_get_rate_resample(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
5010 assert(pcm && params && val);
5011 *val = params->flags & SND_PCM_HW_PARAMS_NORESAMPLE ? 0 : 1;
5016 * \brief Restrict a configuration space to allow the buffer to be accessible from outside
5017 * \param pcm PCM handle
5018 * \param params Configuration space
5019 * \param val 0 = disable, 1 = enable (default) exporting buffer
5020 * \return 0 otherwise a negative error code
5022 int snd_pcm_hw_params_set_export_buffer(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val)
5024 assert(pcm && params);
5026 params->flags |= SND_PCM_HW_PARAMS_EXPORT_BUFFER;
5028 params->flags &= ~SND_PCM_HW_PARAMS_EXPORT_BUFFER;
5030 return snd_pcm_hw_refine(pcm, params);
5034 * \brief Extract buffer accessibility from a configuration space
5035 * \param pcm PCM handle
5036 * \param params Configuration space
5037 * \param val 0 = disable, 1 = enable exporting buffer
5038 * \return 0 otherwise a negative error code
5040 int snd_pcm_hw_params_get_export_buffer(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
5042 assert(pcm && params && val);
5043 *val = params->flags & SND_PCM_HW_PARAMS_EXPORT_BUFFER ? 1 : 0;
5048 * \brief Restrict a configuration space to settings without period wakeups
5049 * \param pcm PCM handle
5050 * \param params Configuration space
5051 * \param val 0 = disable, 1 = enable (default) period wakeup
5052 * \return Zero on success, otherwise a negative error code.
5054 * This function must be called only on devices where non-blocking mode is
5057 * To check whether the hardware does support disabling period wakeups, call
5058 * #snd_pcm_hw_params_can_disable_period_wakeup(). If the hardware does not
5059 * support this mode, standard period wakeups will be generated.
5061 * Even with disabled period wakeups, the period size/time/count parameters
5062 * are valid; it is suggested to use #snd_pcm_hw_params_set_period_size_last().
5064 * When period wakeups are disabled, the application must not use any functions
5065 * that could block on this device. The use of poll should be limited to error
5066 * cases. The application needs to use an external event or a timer to
5067 * check the state of the ring buffer and refill it apropriately.
5069 int snd_pcm_hw_params_set_period_wakeup(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val)
5071 assert(pcm && params);
5074 if (!(pcm->mode & SND_PCM_NONBLOCK))
5076 params->flags |= SND_PCM_HW_PARAMS_NO_PERIOD_WAKEUP;
5078 params->flags &= ~SND_PCM_HW_PARAMS_NO_PERIOD_WAKEUP;
5081 return snd_pcm_hw_refine(pcm, params);
5085 * \brief Extract period wakeup flag from a configuration space
5086 * \param pcm PCM handle
5087 * \param params Configuration space
5088 * \param val 0 = disabled, 1 = enabled period wakeups
5089 * \return Zero on success, otherwise a negative error code.
5091 int snd_pcm_hw_params_get_period_wakeup(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
5093 assert(pcm && params && val);
5094 *val = params->flags & SND_PCM_HW_PARAMS_NO_PERIOD_WAKEUP ? 0 : 1;
5099 * \brief Restrict a configuration space to fill the end of playback stream with silence when drain() is invoked
5100 * \param pcm PCM handle
5101 * \param params Configuration space
5102 * \param val 0 = disabled, 1 = enabled (default) fill the end of the playback stream with silence when drain() is invoked
5103 * \return Zero on success, otherwise a negative error code.
5105 * When disabled, the application should handle the end of stream gracefully
5106 * (fill the silent samples to align to the period size plus some extra
5107 * samples for hardware / driver without perfect drain). Note that the rewind
5108 * may be used for this purpose or the sw_params silencing mechanism.
5110 int snd_pcm_hw_params_set_drain_silence(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val)
5112 assert(pcm && params);
5114 params->flags &= ~SND_PCM_HW_PARAMS_NO_DRAIN_SILENCE;
5116 params->flags |= SND_PCM_HW_PARAMS_NO_DRAIN_SILENCE;
5118 return snd_pcm_hw_refine(pcm, params);
5122 * \brief Extract drain with the filling of silence samples from a configuration space
5123 * \param pcm PCM handle
5124 * \param params Configuration space
5125 * \param val 0 = disabled, 1 = enabled
5126 * \return 0 otherwise a negative error code
5128 int snd_pcm_hw_params_get_drain_silence(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
5130 assert(pcm && params && val);
5131 *val = params->flags & SND_PCM_HW_PARAMS_NO_DRAIN_SILENCE ? 0 : 1;
5136 * \brief Extract period time from a configuration space
5137 * \param params Configuration space
5138 * \param val Returned approximate period duration in us
5139 * \param dir Sub unit direction
5140 * \return 0 otherwise a negative error code if the configuration space does not contain a single value
5142 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5145 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_period_time)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5147 int snd_pcm_hw_params_get_period_time(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5150 return snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
5154 * \brief Extract minimum period time from a configuration space
5155 * \param params Configuration space
5156 * \param val approximate minimum period duration in us
5157 * \param dir Sub unit direction
5158 * \return 0 otherwise a negative error code
5160 * Exact value is <,=,> the returned one following dir (-1,0,1)
5163 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_period_time_min)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5165 int snd_pcm_hw_params_get_period_time_min(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5168 return snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
5172 * \brief Extract maximum period time from a configuration space
5173 * \param params Configuration space
5174 * \param val approximate maximum period duration in us
5175 * \param dir Sub unit direction
5176 * \return 0 otherwise a negative error code
5178 * Exact value is <,=,> the returned one following dir (-1,0,1)
5181 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_period_time_max)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5183 int snd_pcm_hw_params_get_period_time_max(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5186 return snd_pcm_hw_param_get_max(params, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
5190 * \brief Verify if a period time is available inside a configuration space for a PCM
5191 * \param pcm PCM handle
5192 * \param params Configuration space
5193 * \param val approximate period duration in us
5194 * \param dir Sub unit direction
5195 * \return 0 if available a negative error code otherwise
5197 * Wanted exact value is <,=,> val following dir (-1,0,1)
5199 int snd_pcm_hw_params_test_period_time(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
5201 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
5205 * \brief Restrict a configuration space to contain only one period time
5206 * \param pcm PCM handle
5207 * \param params Configuration space
5208 * \param val approximate period duration in us
5209 * \param dir Sub unit direction
5210 * \return 0 otherwise a negative error code if configuration space would become empty
5212 * Wanted exact value is <,=,> val following dir (-1,0,1)
5214 int snd_pcm_hw_params_set_period_time(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
5216 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
5221 * \brief Restrict a configuration space with a minimum period time
5222 * \param pcm PCM handle
5223 * \param params Configuration space
5224 * \param val approximate minimum period duration in us (on return filled with actual minimum)
5225 * \param dir Sub unit direction (on return filled with actual direction)
5226 * \return 0 otherwise a negative error code if configuration space would become empty
5228 * Wanted/actual exact minimum is <,=,> val following dir (-1,0,1)
5230 int snd_pcm_hw_params_set_period_time_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5232 return snd_pcm_hw_param_set_min(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
5236 * \brief Restrict a configuration space with a maximum period time
5237 * \param pcm PCM handle
5238 * \param params Configuration space
5239 * \param val approximate maximum period duration in us (on return filled with actual maximum)
5240 * \param dir Sub unit direction (on return filled with actual direction)
5241 * \return 0 otherwise a negative error code if configuration space would become empty
5243 * Wanted/actual exact maximum is <,=,> val following dir (-1,0,1)
5245 int snd_pcm_hw_params_set_period_time_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5247 return snd_pcm_hw_param_set_max(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
5251 * \brief Restrict a configuration space to have period times in a given range
5252 * \param pcm PCM handle
5253 * \param params Configuration space
5254 * \param min approximate minimum period duration in us (on return filled with actual minimum)
5255 * \param mindir Sub unit direction for minimum (on return filled with actual direction)
5256 * \param max approximate maximum period duration in us (on return filled with actual maximum)
5257 * \param maxdir Sub unit direction for maximum (on return filled with actual direction)
5258 * \return 0 otherwise a negative error code if configuration space would become empty
5260 * Wanted/actual exact min/max is <,=,> val following dir (-1,0,1)
5262 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)
5264 return snd_pcm_hw_param_set_minmax(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_TIME, min, mindir, max, maxdir);
5268 * \brief Restrict a configuration space to have period time nearest to a target
5269 * \param pcm PCM handle
5270 * \param params Configuration space
5271 * \param val approximate target period duration in us / returned chosen approximate target period duration
5272 * \param dir Sub unit direction
5273 * \return 0 otherwise a negative error code if configuration space is empty
5275 * target/chosen exact value is <,=,> val following dir (-1,0,1)
5278 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)
5280 int snd_pcm_hw_params_set_period_time_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5283 return snd_pcm_hw_param_set_near(pcm, params, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
5287 * \brief Restrict a configuration space to contain only its minimum period time
5288 * \param pcm PCM handle
5289 * \param params Configuration space
5290 * \param val Returned approximate period duration in us
5291 * \param dir Sub unit direction
5292 * \return 0 otherwise a negative error code
5294 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5297 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)
5299 int snd_pcm_hw_params_set_period_time_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5302 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
5306 * \brief Restrict a configuration space to contain only its maximum period time
5307 * \param pcm PCM handle
5308 * \param params Configuration space
5309 * \param val Returned maximum approximate period time
5310 * \param dir Sub unit direction
5311 * \return approximate period duration in us
5314 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)
5316 int snd_pcm_hw_params_set_period_time_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5319 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
5324 * \brief Extract period size from a configuration space
5325 * \param params Configuration space
5326 * \param val Returned approximate period size in frames
5327 * \param dir Sub unit direction
5328 * \return 0 otherwise a negative error code if the configuration space does not contain a single value
5330 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5333 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)
5335 int snd_pcm_hw_params_get_period_size(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
5339 int err = snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
5346 * \brief Extract minimum period size from a configuration space
5347 * \param params Configuration space
5348 * \param val approximate minimum period size in frames
5349 * \param dir Sub unit direction
5350 * \return 0 otherwise a negative error code
5352 * Exact value is <,=,> the returned one following dir (-1,0,1)
5355 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)
5357 int snd_pcm_hw_params_get_period_size_min(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
5360 unsigned int _val = *val;
5361 int err = snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
5368 * \brief Extract maximum period size from a configuration space
5369 * \param params Configuration space
5370 * \param val approximate minimum period size in frames
5371 * \param dir Sub unit direction
5372 * \return 0 otherwise a negative error code
5374 * Exact value is <,=,> the returned one following dir (-1,0,1)
5377 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)
5379 int snd_pcm_hw_params_get_period_size_max(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
5382 unsigned int _val = *val;
5383 int err = snd_pcm_hw_param_get_max(params, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
5390 * \brief Verify if a period size is available inside a configuration space for a PCM
5391 * \param pcm PCM handle
5392 * \param params Configuration space
5393 * \param val approximate period size in frames
5394 * \param dir Sub unit direction
5395 * \return 0 if available a negative error code otherwise
5397 * Wanted exact value is <,=,> val following dir (-1,0,1)
5399 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)
5401 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_PERIOD_SIZE, val, dir);
5405 * \brief Restrict a configuration space to contain only one period size
5406 * \param pcm PCM handle
5407 * \param params Configuration space
5408 * \param val approximate period size in frames
5409 * \param dir Sub unit direction
5410 * \return 0 otherwise a negative error code if configuration space would become empty
5412 * Wanted exact value is <,=,> val following dir (-1,0,1)
5414 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)
5416 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_SIZE, val, dir);
5420 * \brief Restrict a configuration space with a minimum period size
5421 * \param pcm PCM handle
5422 * \param params Configuration space
5423 * \param val approximate minimum period size in frames (on return filled with actual minimum)
5424 * \param dir Sub unit direction (on return filled with actual direction)
5425 * \return 0 otherwise a negative error code if configuration space would become empty
5427 * Wanted/actual exact minimum is <,=,> val following dir (-1,0,1)
5429 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)
5431 unsigned int _val = *val;
5432 int err = snd_pcm_hw_param_set_min(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
5439 * \brief Restrict a configuration space with a maximum period size
5440 * \param pcm PCM handle
5441 * \param params Configuration space
5442 * \param val approximate maximum period size in frames (on return filled with actual maximum)
5443 * \param dir Sub unit direction (on return filled with actual direction)
5444 * \return 0 otherwise a negative error code if configuration space would become empty
5446 * Wanted/actual exact minimum is <,=,> val following dir (-1,0,1)
5448 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)
5450 unsigned int _val = *val;
5451 int err = snd_pcm_hw_param_set_max(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
5458 * \brief Restrict a configuration space to have period sizes in a given range
5459 * \param pcm PCM handle
5460 * \param params Configuration space
5461 * \param min approximate minimum period size in frames (on return filled with actual minimum)
5462 * \param mindir Sub unit direction for minimum (on return filled with actual direction)
5463 * \param max approximate maximum period size in frames (on return filled with actual maximum)
5464 * \param maxdir Sub unit direction for maximum (on return filled with actual direction)
5465 * \return 0 otherwise a negative error code if configuration space would become empty
5467 * Wanted/actual exact min/max is <,=,> val following dir (-1,0,1)
5469 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)
5471 unsigned int _min = *min;
5472 unsigned int _max = *max;
5473 int err = snd_pcm_hw_param_set_minmax(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_SIZE, &_min, mindir, &_max, maxdir);
5480 * \brief Restrict a configuration space to have period size nearest to a target
5481 * \param pcm PCM handle
5482 * \param params Configuration space
5483 * \param val approximate target period size in frames / returned chosen approximate target period size
5484 * \param dir Sub unit direction
5485 * \return 0 otherwise a negative error code if configuration space is empty
5487 * target/chosen exact value is <,=,> val following dir (-1,0,1)
5490 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)
5492 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)
5495 unsigned int _val = *val;
5496 int err = snd_pcm_hw_param_set_near(pcm, params, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
5503 * \brief Restrict a configuration space to contain only its minimum period size
5504 * \param pcm PCM handle
5505 * \param params Configuration space
5506 * \param val Returned maximum approximate period size in frames
5507 * \param dir Sub unit direction
5508 * \return 0 otherwise a negative error code
5510 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5513 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)
5515 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)
5519 int err = snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
5526 * \brief Restrict a configuration space to contain only its maximum period size
5527 * \param pcm PCM handle
5528 * \param params Configuration space
5529 * \param val Returned maximum approximate period size in frames
5530 * \param dir Sub unit direction
5531 * \return 0 otherwise a negative error code
5533 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5536 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)
5538 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)
5542 int err = snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
5549 * \brief Restrict a configuration space to contain only integer period sizes
5550 * \param pcm PCM handle
5551 * \param params Configuration space
5552 * \return 0 otherwise a negative error code if configuration space would become empty
5554 int snd_pcm_hw_params_set_period_size_integer(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
5556 return snd_pcm_hw_param_set_integer(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_SIZE);
5561 * \brief Extract periods from a configuration space
5562 * \param params Configuration space
5563 * \param val approximate periods per buffer
5564 * \param dir Sub unit direction
5565 * \return 0 otherwise a negative error code if the configuration space does not contain a single value
5567 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5570 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_periods)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5572 int snd_pcm_hw_params_get_periods(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5575 return snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_PERIODS, val, dir);
5579 * \brief Extract minimum periods count from a configuration space
5580 * \param params Configuration space
5581 * \param val approximate minimum periods per buffer
5582 * \param dir Sub unit direction
5583 * \return 0 otherwise a negative error code
5585 * Exact value is <,=,> the returned one following dir (-1,0,1)
5588 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_periods_min)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5590 int snd_pcm_hw_params_get_periods_min(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5593 return snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_PERIODS, val, dir);
5597 * \brief Extract maximum periods count from a configuration space
5598 * \param params Configuration space
5599 * \param val approximate maximum periods per buffer
5600 * \param dir Sub unit direction
5601 * \return 0 otherwise a negative error code
5603 * Exact value is <,=,> the returned one following dir (-1,0,1)
5606 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_periods_max)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5608 int snd_pcm_hw_params_get_periods_max(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5611 return snd_pcm_hw_param_get_max(params, SND_PCM_HW_PARAM_PERIODS, val, dir);
5615 * \brief Verify if a periods count is available inside a configuration space for a PCM
5616 * \param pcm PCM handle
5617 * \param params Configuration space
5618 * \param val approximate periods per buffer
5619 * \param dir Sub unit direction
5620 * \return 0 if available a negative error code otherwise
5622 * Wanted exact value is <,=,> val following dir (-1,0,1)
5624 int snd_pcm_hw_params_test_periods(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
5626 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_PERIODS, val, dir);
5630 * \brief Restrict a configuration space to contain only one periods count
5631 * \param pcm PCM handle
5632 * \param params Configuration space
5633 * \param val approximate periods per buffer
5634 * \param dir Sub unit direction
5635 * \return 0 otherwise a negative error code if configuration space would become empty
5637 * Wanted exact value is <,=,> val following dir (-1,0,1)
5639 int snd_pcm_hw_params_set_periods(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
5641 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIODS, val, dir);
5645 * \brief Restrict a configuration space with a minimum periods count
5646 * \param pcm PCM handle
5647 * \param params Configuration space
5648 * \param val approximate minimum periods per buffer (on return filled with actual minimum)
5649 * \param dir Sub unit direction (on return filled with actual direction)
5650 * \return 0 otherwise a negative error code if configuration space would become empty
5652 * Wanted/actual exact minimum is <,=,> val following dir (-1,0,1)
5654 int snd_pcm_hw_params_set_periods_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5656 return snd_pcm_hw_param_set_min(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIODS, val, dir);
5660 * \brief Restrict a configuration space with a maximum periods count
5661 * \param pcm PCM handle
5662 * \param params Configuration space
5663 * \param val approximate maximum periods per buffer (on return filled with actual maximum)
5664 * \param dir Sub unit direction (on return filled with actual direction)
5665 * \return 0 otherwise a negative error code if configuration space would become empty
5667 * Wanted/actual exact maximum is <,=,> val following dir (-1,0,1)
5669 int snd_pcm_hw_params_set_periods_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5671 return snd_pcm_hw_param_set_max(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIODS, val, dir);
5675 * \brief Restrict a configuration space to have periods counts in a given range
5676 * \param pcm PCM handle
5677 * \param params Configuration space
5678 * \param min approximate minimum periods per buffer (on return filled with actual minimum)
5679 * \param mindir Sub unit direction for minimum (on return filled with actual direction)
5680 * \param max approximate maximum periods per buffer (on return filled with actual maximum)
5681 * \param maxdir Sub unit direction for maximum (on return filled with actual direction)
5682 * \return 0 otherwise a negative error code if configuration space would become empty
5684 * Wanted/actual exact min/max is <,=,> val following dir (-1,0,1)
5686 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)
5688 return snd_pcm_hw_param_set_minmax(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIODS, min, mindir, max, maxdir);
5692 * \brief Restrict a configuration space to have periods count nearest to a target
5693 * \param pcm PCM handle
5694 * \param params Configuration space
5695 * \param val approximate target periods per buffer / returned chosen approximate target periods per buffer
5696 * \param dir Sub unit direction
5697 * \return 0 otherwise a negative error code if configuration space is empty
5699 * target/chosen exact value is <,=,> val following dir (-1,0,1)
5702 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)
5704 int snd_pcm_hw_params_set_periods_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5707 return snd_pcm_hw_param_set_near(pcm, params, SND_PCM_HW_PARAM_PERIODS, val, dir);
5711 * \brief Restrict a configuration space to contain only its minimum periods count
5712 * \param pcm PCM handle
5713 * \param params Configuration space
5714 * \param val Returned approximate minimum periods per buffer
5715 * \param dir Sub unit direction
5716 * \return 0 otherwise a negative error code
5718 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5721 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)
5723 int snd_pcm_hw_params_set_periods_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5726 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_PERIODS, val, dir);
5730 * \brief Restrict a configuration space to contain only its maximum periods count
5731 * \param pcm PCM handle
5732 * \param params Configuration space
5733 * \param val Returned approximate maximum periods per buffer
5734 * \param dir Sub unit direction
5735 * \return 0 otherwise a negative error code
5737 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5740 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)
5742 int snd_pcm_hw_params_set_periods_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5745 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_PERIODS, val, dir);
5749 * \brief Restrict a configuration space to contain only integer periods counts
5750 * \param pcm PCM handle
5751 * \param params Configuration space
5752 * \return 0 otherwise a negative error code if configuration space would become empty
5754 int snd_pcm_hw_params_set_periods_integer(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
5756 return snd_pcm_hw_param_set_integer(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIODS);
5761 * \brief Extract buffer time from a configuration space
5762 * \param params Configuration space
5763 * \param val Returned buffer time in us
5764 * \param dir Sub unit direction
5765 * \return 0 otherwise a negative error code if the configuration space does not contain a single value
5767 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5770 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_buffer_time)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5772 int snd_pcm_hw_params_get_buffer_time(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5775 return snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5779 * \brief Extract minimum buffer time from a configuration space
5780 * \param params Configuration space
5781 * \param val approximate minimum buffer duration in us
5782 * \param dir Sub unit direction
5783 * \return 0 otherwise a negative error code
5785 * Exact value is <,=,> the returned one following dir (-1,0,1)
5788 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_buffer_time_min)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5790 int snd_pcm_hw_params_get_buffer_time_min(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5793 return snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5797 * \brief Extract maximum buffer time from a configuration space
5798 * \param params Configuration space
5799 * \param val approximate maximum buffer duration in us
5800 * \param dir Sub unit direction
5801 * \return 0 otherwise a negative error code
5803 * Exact value is <,=,> the returned one following dir (-1,0,1)
5806 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_buffer_time_max)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5808 int snd_pcm_hw_params_get_buffer_time_max(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5811 return snd_pcm_hw_param_get_max(params, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5815 * \brief Verify if a buffer time is available inside a configuration space for a PCM
5816 * \param pcm PCM handle
5817 * \param params Configuration space
5818 * \param val approximate buffer duration in us
5819 * \param dir Sub unit direction
5820 * \return 0 if available a negative error code otherwise
5822 * Wanted exact value is <,=,> val following dir (-1,0,1)
5824 int snd_pcm_hw_params_test_buffer_time(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
5826 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5830 * \brief Restrict a configuration space to contain only one buffer time
5831 * \param pcm PCM handle
5832 * \param params Configuration space
5833 * \param val approximate buffer duration in us
5834 * \param dir Sub unit direction
5835 * \return 0 otherwise a negative error code if configuration space would become empty
5837 * Wanted exact value is <,=,> val following dir (-1,0,1)
5839 int snd_pcm_hw_params_set_buffer_time(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
5841 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5845 * \brief Restrict a configuration space with a minimum buffer time
5846 * \param pcm PCM handle
5847 * \param params Configuration space
5848 * \param val approximate minimum buffer duration in us (on return filled with actual minimum)
5849 * \param dir Sub unit direction (on return filled with actual direction)
5850 * \return 0 otherwise a negative error code if configuration space would become empty
5852 * Wanted/actual exact minimum is <,=,> val following dir (-1,0,1)
5854 int snd_pcm_hw_params_set_buffer_time_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5856 return snd_pcm_hw_param_set_min(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5860 * \brief Restrict a configuration space with a maximum buffer time
5861 * \param pcm PCM handle
5862 * \param params Configuration space
5863 * \param val approximate maximum buffer duration in us (on return filled with actual maximum)
5864 * \param dir Sub unit direction (on return filled with actual direction)
5865 * \return 0 otherwise a negative error code if configuration space would become empty
5867 * Wanted/actual exact maximum is <,=,> val following dir (-1,0,1)
5869 int snd_pcm_hw_params_set_buffer_time_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5871 return snd_pcm_hw_param_set_max(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5875 * \brief Restrict a configuration space to have buffer times in a given range
5876 * \param pcm PCM handle
5877 * \param params Configuration space
5878 * \param min approximate minimum buffer duration in us (on return filled with actual minimum)
5879 * \param mindir Sub unit direction for minimum (on return filled with actual direction)
5880 * \param max approximate maximum buffer duration in us (on return filled with actual maximum)
5881 * \param maxdir Sub unit direction for maximum (on return filled with actual direction)
5882 * \return 0 otherwise a negative error code if configuration space would become empty
5884 * Wanted/actual exact min/max is <,=,> val following dir (-1,0,1)
5886 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)
5888 return snd_pcm_hw_param_set_minmax(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_TIME, min, mindir, max, maxdir);
5892 * \brief Restrict a configuration space to have buffer time nearest to a target
5893 * \param pcm PCM handle
5894 * \param params Configuration space
5895 * \param val approximate target buffer duration in us / returned chosen approximate target buffer duration
5896 * \param dir Sub unit direction
5897 * \return 0 otherwise a negative error code if configuration space is empty
5899 * target/chosen exact value is <,=,> val following dir (-1,0,1)
5902 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)
5904 int snd_pcm_hw_params_set_buffer_time_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5907 return snd_pcm_hw_param_set_near(pcm, params, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5911 * \brief Restrict a configuration space to contain only its minimum buffer time
5912 * \param pcm PCM handle
5913 * \param params Configuration space
5914 * \param val Returned approximate minimum buffer duration in us
5915 * \param dir Sub unit direction
5916 * \return 0 otherwise a negative error code
5918 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5921 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)
5923 int snd_pcm_hw_params_set_buffer_time_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5926 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5930 * \brief Restrict a configuration space to contain only its maximum buffered time
5931 * \param pcm PCM handle
5932 * \param params Configuration space
5933 * \param val Returned approximate maximum buffer duration in us
5934 * \param dir Sub unit direction
5935 * \return 0 otherwise a negative error code
5937 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5940 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)
5942 int snd_pcm_hw_params_set_buffer_time_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5945 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5950 * \brief Extract buffer size from a configuration space
5951 * \param params Configuration space
5952 * \param val Returned buffer size in frames
5953 * \return 0 otherwise a negative error code if the configuration space does not contain a single value
5956 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_buffer_size)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5958 int snd_pcm_hw_params_get_buffer_size(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5962 int err = snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
5969 * \brief Extract minimum buffer size from a configuration space
5970 * \param params Configuration space
5971 * \param val Returned approximate minimum buffer size in frames
5972 * \return 0 otherwise a negative error code
5975 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_buffer_size_min)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5977 int snd_pcm_hw_params_get_buffer_size_min(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5981 int err = snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
5988 * \brief Extract maximum buffer size from a configuration space
5989 * \param params Configuration space
5990 * \param val Returned approximate maximum buffer size in frames
5991 * \return 0 otherwise a negative error code
5993 * Exact value is <,=,> the returned one following dir (-1,0,1)
5996 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_buffer_size_max)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5998 int snd_pcm_hw_params_get_buffer_size_max(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
6002 int err = snd_pcm_hw_param_get_max(params, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
6009 * \brief Verify if a buffer size is available inside a configuration space for a PCM
6010 * \param pcm PCM handle
6011 * \param params Configuration space
6012 * \param val buffer size in frames
6013 * \return 0 if available a negative error code otherwise
6015 * Wanted exact value is <,=,> val following dir (-1,0,1)
6017 int snd_pcm_hw_params_test_buffer_size(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t val)
6019 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_BUFFER_SIZE, val, 0);
6023 * \brief Restrict a configuration space to contain only one buffer size
6024 * \param pcm PCM handle
6025 * \param params Configuration space
6026 * \param val buffer size in frames
6027 * \return 0 otherwise a negative error code if configuration space would become empty
6029 * Wanted exact value is <,=,> val following dir (-1,0,1)
6031 int snd_pcm_hw_params_set_buffer_size(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t val)
6033 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_SIZE, val, 0);
6037 * \brief Restrict a configuration space with a minimum buffer size
6038 * \param pcm PCM handle
6039 * \param params Configuration space
6040 * \param val approximate minimum buffer size in frames (on return filled with actual minimum)
6041 * \return 0 otherwise a negative error code if configuration space would become empty
6043 int snd_pcm_hw_params_set_buffer_size_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
6045 unsigned int _val = *val;
6046 int err = snd_pcm_hw_param_set_min(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
6053 * \brief Restrict a configuration space with a maximum buffer size
6054 * \param pcm PCM handle
6055 * \param params Configuration space
6056 * \param val approximate maximum buffer size in frames (on return filled with actual maximum)
6057 * \return 0 otherwise a negative error code if configuration space would become empty
6059 int snd_pcm_hw_params_set_buffer_size_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
6061 unsigned int _val = *val;
6062 int err = snd_pcm_hw_param_set_max(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
6069 * \brief Restrict a configuration space to have buffer sizes in a given range
6070 * \param pcm PCM handle
6071 * \param params Configuration space
6072 * \param min approximate minimum buffer size in frames (on return filled with actual minimum)
6073 * \param max approximate maximum buffer size in frames (on return filled with actual maximum)
6074 * \return 0 otherwise a negative error code if configuration space would become empty
6076 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)
6078 unsigned int _min = *min;
6079 unsigned int _max = *max;
6080 int err = snd_pcm_hw_param_set_minmax(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_SIZE, &_min, NULL, &_max, NULL);
6087 * \brief Restrict a configuration space to have buffer size nearest to a target
6088 * \param pcm PCM handle
6089 * \param params Configuration space
6090 * \param val approximate target buffer size in frames / returned chosen approximate target buffer size in frames
6091 * \return 0 otherwise a negative error code if configuration space is empty
6094 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)
6096 int snd_pcm_hw_params_set_buffer_size_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
6099 unsigned int _val = *val;
6100 int err = snd_pcm_hw_param_set_near(pcm, params, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
6107 * \brief Restrict a configuration space to contain only its minimum buffer size
6108 * \param pcm PCM handle
6109 * \param params Configuration space
6110 * \param val Returned minimum buffer size in frames
6111 * \return buffer size in frames
6114 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)
6116 int snd_pcm_hw_params_set_buffer_size_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
6120 int err = snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
6127 * \brief Restrict a configuration space to contain only its maximum buffer size
6128 * \param pcm PCM handle
6129 * \param params Configuration space
6130 * \param val Returned maximum buffer size in frames
6131 * \return 0 otherwise a negative error code
6134 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)
6136 int snd_pcm_hw_params_set_buffer_size_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
6140 int err = snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
6148 * \brief (DEPRECATED) Extract tick time from a configuration space
6149 * \param params Configuration space
6150 * \param val Returned approximate tick duration in us
6151 * \param dir Sub unit direction
6152 * \return 0 otherwise a negative error code if the configuration space does not contain a single value
6154 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
6157 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)
6159 int snd_pcm_hw_params_get_tick_time(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
6167 * \brief (DEPRECATED) Extract minimum tick time from a configuration space
6168 * \param params Configuration space
6169 * \param val Returned approximate minimum tick duration in us
6170 * \param dir Sub unit direction
6171 * \return 0 otherwise a negative error code
6173 * Exact value is <,=,> the returned one following dir (-1,0,1)
6176 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)
6178 int snd_pcm_hw_params_get_tick_time_min(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
6186 * \brief (DEPRECATED) Extract maximum tick time from a configuration space
6187 * \param params Configuration space
6188 * \param val Returned approximate maximum tick duration in us
6189 * \param dir Sub unit direction
6190 * \return 0 otherwise a negative error code
6192 * Exact value is <,=,> the returned one following dir (-1,0,1)
6195 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)
6197 int snd_pcm_hw_params_get_tick_time_max(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
6205 * \brief (DEPRECATED) Verify if a tick time is available inside a configuration space for a PCM
6206 * \param pcm PCM handle
6207 * \param params Configuration space
6208 * \param val approximate tick duration in us
6209 * \param dir Sub unit direction
6210 * \return 0 if available a negative error code otherwise
6212 * Wanted exact value is <,=,> val following dir (-1,0,1)
6214 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)
6216 return val ? -EINVAL : 0;
6220 * \brief (DEPRECATED) Restrict a configuration space to contain only one tick time
6221 * \param pcm PCM handle
6222 * \param params Configuration space
6223 * \param val approximate tick duration in us
6224 * \param dir Sub unit direction
6225 * \return 0 otherwise a negative error code if configuration space would become empty
6227 * Wanted exact value is <,=,> val following dir (-1,0,1)
6229 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)
6235 * \brief (DEPRECATED) Restrict a configuration space with a minimum tick time
6236 * \param pcm PCM handle
6237 * \param params Configuration space
6238 * \param val approximate minimum tick duration in us (on return filled with actual minimum)
6239 * \param dir Sub unit direction (on return filled with actual direction)
6240 * \return 0 otherwise a negative error code if configuration space would become empty
6242 * Wanted/actual exact minimum is <,=,> val following dir (-1,0,1)
6244 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)
6250 * \brief (DEPRECATED) Restrict a configuration space with a maximum tick time
6251 * \param pcm PCM handle
6252 * \param params Configuration space
6253 * \param val approximate maximum tick duration in us (on return filled with actual maximum)
6254 * \param dir Sub unit direction (on return filled with actual direction)
6255 * \return 0 otherwise a negative error code if configuration space would become empty
6257 * Wanted/actual exact maximum is <,=,> val following dir (-1,0,1)
6259 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)
6265 * \brief (DEPRECATED) Restrict a configuration space to have tick times in a given range
6266 * \param pcm PCM handle
6267 * \param params Configuration space
6268 * \param min approximate minimum tick duration in us (on return filled with actual minimum)
6269 * \param mindir Sub unit direction for minimum (on return filled with actual direction)
6270 * \param max approximate maximum tick duration in us (on return filled with actual maximum)
6271 * \param maxdir Sub unit direction for maximum (on return filled with actual direction)
6272 * \return 0 otherwise a negative error code if configuration space would become empty
6274 * Wanted/actual exact min/max is <,=,> val following dir (-1,0,1)
6276 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)
6282 * \brief (DEPRECATED) Restrict a configuration space to have tick time nearest to a target
6283 * \param pcm PCM handle
6284 * \param params Configuration space
6285 * \param val approximate target tick duration in us / returned chosen approximate target tick duration in us
6286 * \param dir Sub unit direction
6287 * \return 0 otherwise a negative error code if configuration space is empty
6289 * target/chosen exact value is <,=,> val following dir (-1,0,1)
6292 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)
6294 int snd_pcm_hw_params_set_tick_time_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
6301 * \brief (DEPRECATED) Restrict a configuration space to contain only its minimum tick time
6302 * \param pcm PCM handle
6303 * \param params Configuration space
6304 * \param val Returned approximate minimum tick duration in us
6305 * \param dir Sub unit direction
6306 * \return 0 otherwise a negative error code
6308 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
6311 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)
6313 int snd_pcm_hw_params_set_tick_time_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
6320 * \brief (DEPRECATED) Restrict a configuration space to contain only its maximum tick time
6321 * \param pcm PCM handle
6322 * \param params Configuration space
6323 * \param val Returned approximate maximum tick duration in us
6324 * \param dir Sub unit direction
6325 * \return 0 otherwise a negative error code
6327 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
6330 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)
6332 int snd_pcm_hw_params_set_tick_time_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
6339 * \brief Get the minimum transfer align value in samples
6340 * \param params Configuration space
6341 * \param val Returned minimum align value
6342 * \return 0 otherwise a negative error code if the configuration space does not contain a single value
6344 int snd_pcm_hw_params_get_min_align(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
6346 unsigned int format, channels, fb, min_align;
6349 err = snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_FORMAT, &format, NULL);
6352 err = snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_CHANNELS, &channels, NULL);
6355 // compute frame bits
6356 fb = snd_pcm_format_physical_width((snd_pcm_format_t)format) * channels;
6368 void snd_pcm_sw_params_current_no_lock(snd_pcm_t *pcm, snd_pcm_sw_params_t *params)
6370 params->proto = SNDRV_PCM_VERSION;
6371 params->tstamp_mode = pcm->tstamp_mode;
6372 params->tstamp_type = pcm->tstamp_type;
6373 params->period_step = pcm->period_step;
6374 params->sleep_min = 0;
6375 params->avail_min = pcm->avail_min;
6376 sw_set_period_event(params, pcm->period_event);
6377 params->xfer_align = 1;
6378 params->start_threshold = pcm->start_threshold;
6379 params->stop_threshold = pcm->stop_threshold;
6380 params->silence_threshold = pcm->silence_threshold;
6381 params->silence_size = pcm->silence_size;
6382 params->boundary = pcm->boundary;
6387 * \brief Return current software configuration for a PCM
6388 * \param pcm PCM handle
6389 * \param params Software configuration container
6390 * \return 0 on success otherwise a negative error code
6392 * The function is thread-safe when built with the proper option.
6394 int snd_pcm_sw_params_current(snd_pcm_t *pcm, snd_pcm_sw_params_t *params)
6396 assert(pcm && params);
6397 if (CHECK_SANITY(! pcm->setup)) {
6398 SNDMSG("PCM not set up");
6401 __snd_pcm_lock(pcm); /* forced lock due to pcm field changes */
6402 snd_pcm_sw_params_current_no_lock(pcm, params);
6403 __snd_pcm_unlock(pcm);
6408 * \brief Dump a software configuration
6409 * \param params Software configuration container
6410 * \param out Output handle
6411 * \return 0 on success otherwise a negative error code
6413 int snd_pcm_sw_params_dump(snd_pcm_sw_params_t *params, snd_output_t *out)
6415 snd_output_printf(out, "tstamp_mode: %s\n", snd_pcm_tstamp_mode_name(params->tstamp_mode));
6416 snd_output_printf(out, "tstamp_type: %s\n", snd_pcm_tstamp_type_name(params->tstamp_type));
6417 snd_output_printf(out, "period_step: %u\n", params->period_step);
6418 snd_output_printf(out, "avail_min: %lu\n", params->avail_min);
6419 snd_output_printf(out, "start_threshold: %ld\n", params->start_threshold);
6420 snd_output_printf(out, "stop_threshold: %ld\n", params->stop_threshold);
6421 snd_output_printf(out, "silence_threshold: %lu\n", params->silence_threshold);
6422 snd_output_printf(out, "silence_size: %lu\n", params->silence_size);
6423 snd_output_printf(out, "boundary: %lu\n", params->boundary);
6428 * \brief get size of #snd_pcm_sw_params_t
6429 * \return size in bytes
6431 size_t snd_pcm_sw_params_sizeof()
6433 return sizeof(snd_pcm_sw_params_t);
6437 * \brief allocate an invalid #snd_pcm_sw_params_t using standard malloc
6438 * \param ptr returned pointer
6439 * \return 0 on success otherwise negative error code
6441 int snd_pcm_sw_params_malloc(snd_pcm_sw_params_t **ptr)
6444 *ptr = calloc(1, sizeof(snd_pcm_sw_params_t));
6451 * \brief frees a previously allocated #snd_pcm_sw_params_t
6452 * \param obj pointer to object to free
6454 void snd_pcm_sw_params_free(snd_pcm_sw_params_t *obj)
6460 * \brief copy one #snd_pcm_sw_params_t to another
6461 * \param dst pointer to destination
6462 * \param src pointer to source
6464 void snd_pcm_sw_params_copy(snd_pcm_sw_params_t *dst, const snd_pcm_sw_params_t *src)
6471 * \brief Get boundary for ring pointers from a software configuration container
6472 * \param params Software configuration container
6473 * \param val Returned boundary in frames
6474 * \return 0 otherwise a negative error code
6476 int snd_pcm_sw_params_get_boundary(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6479 *val = params->boundary;
6484 * \brief (DEPRECATED) Set start mode inside a software configuration container
6485 * \param pcm PCM handle
6486 * \param params Software configuration container
6487 * \param val Start mode
6488 * \return 0 otherwise a negative error code
6490 int snd_pcm_sw_params_set_start_mode(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_start_t val)
6492 assert(pcm && params);
6494 case SND_PCM_START_DATA:
6495 params->start_threshold = 1;
6497 case SND_PCM_START_EXPLICIT:
6498 params->start_threshold = pcm->boundary;
6501 SNDMSG("invalid start mode value %d", val);
6508 link_warning(snd_pcm_sw_params_set_start_mode, "Warning: start_mode is deprecated, consider to use start_threshold");
6512 * \brief (DEPRECATED) Get start mode from a software configuration container
6513 * \param params Software configuration container
6514 * \return start mode
6516 snd_pcm_start_t snd_pcm_sw_params_get_start_mode(const snd_pcm_sw_params_t *params)
6520 return params->start_threshold > 1024 * 1024 ? SND_PCM_START_EXPLICIT : SND_PCM_START_DATA;
6524 link_warning(snd_pcm_sw_params_get_start_mode, "Warning: start_mode is deprecated, consider to use start_threshold");
6528 * \brief (DEPRECATED) Set xrun mode inside a software configuration container
6529 * \param pcm PCM handle
6530 * \param params Software configuration container
6531 * \param val Xrun mode
6532 * \return 0 otherwise a negative error code
6535 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)
6537 int snd_pcm_sw_params_set_xrun_mode(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_xrun_t val)
6540 assert(pcm && params);
6542 case SND_PCM_XRUN_STOP:
6543 params->stop_threshold = pcm->buffer_size;
6545 case SND_PCM_XRUN_NONE:
6546 params->stop_threshold = pcm->boundary;
6549 SNDMSG("invalid xrun mode value %d", val);
6556 link_warning(snd_pcm_sw_params_set_xrun_mode, "Warning: xrun_mode is deprecated, consider to use stop_threshold");
6560 * \brief (DEPRECATED) Get xrun mode from a software configuration container
6561 * \param params Software configuration container
6564 snd_pcm_xrun_t snd_pcm_sw_params_get_xrun_mode(const snd_pcm_sw_params_t *params)
6568 return params->stop_threshold > 1024 * 1024 ? SND_PCM_XRUN_NONE : SND_PCM_XRUN_STOP;
6572 link_warning(snd_pcm_sw_params_get_xrun_mode, "Warning: xrun_mode is deprecated, consider to use stop_threshold");
6576 * \brief Set timestamp mode inside a software configuration container
6577 * \param pcm PCM handle
6578 * \param params Software configuration container
6579 * \param val Timestamp mode
6580 * \return 0 otherwise a negative error code
6583 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)
6585 int snd_pcm_sw_params_set_tstamp_mode(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_tstamp_t val)
6588 assert(pcm && params);
6589 if (CHECK_SANITY(val > SND_PCM_TSTAMP_LAST)) {
6590 SNDMSG("invalid tstamp_mode value %d", val);
6593 params->tstamp_mode = val;
6598 * \brief Get timestamp mode from a software configuration container
6599 * \param params Software configuration container
6600 * \param val Returned timestamp
6601 * \return 0 otherwise a negative error code
6604 EXPORT_SYMBOL int INTERNAL(snd_pcm_sw_params_get_tstamp_mode)(const snd_pcm_sw_params_t *params, snd_pcm_tstamp_t *val)
6606 int snd_pcm_sw_params_get_tstamp_mode(const snd_pcm_sw_params_t *params, snd_pcm_tstamp_t *val)
6609 assert(params && val);
6610 *val = params->tstamp_mode;
6615 * \brief Set timestamp type inside a software configuration container
6616 * \param pcm PCM handle
6617 * \param params Software configuration container
6618 * \param val Timestamp type
6619 * \return 0 otherwise a negative error code
6621 int snd_pcm_sw_params_set_tstamp_type(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_tstamp_type_t val)
6623 assert(pcm && params);
6624 if (CHECK_SANITY(val > SND_PCM_TSTAMP_TYPE_LAST)) {
6625 SNDMSG("invalid tstamp_type value %d", val);
6628 params->tstamp_type = val;
6633 * \brief Get timestamp type from a software configuration container
6634 * \param params Software configuration container
6635 * \param val Returned timestamp type
6636 * \return 0 otherwise a negative error code
6638 int snd_pcm_sw_params_get_tstamp_type(const snd_pcm_sw_params_t *params, snd_pcm_tstamp_type_t *val)
6640 assert(params && val);
6641 *val = params->tstamp_type;
6646 * \brief (DEPRECATED) Set minimum number of ticks to sleep inside a software configuration container
6647 * \param pcm PCM handle
6648 * \param params Software configuration container
6649 * \param val Minimum ticks to sleep or 0 to disable the use of tick timer
6650 * \return 0 otherwise a negative error code
6653 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)
6655 int snd_pcm_sw_params_set_sleep_min(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, unsigned int val)
6662 * \brief (DEPRECATED) Get minimum numbers of ticks to sleep from a software configuration container
6663 * \param params Software configuration container
6664 * \param val returned minimum number of ticks to sleep or 0 if tick timer is disabled
6665 * \return 0 otherwise a negative error code
6668 EXPORT_SYMBOL int INTERNAL(snd_pcm_sw_params_get_sleep_min)(const snd_pcm_sw_params_t *params ATTRIBUTE_UNUSED, unsigned int *val)
6670 int snd_pcm_sw_params_get_sleep_min(const snd_pcm_sw_params_t *params, unsigned int *val)
6678 * \brief Set avail min inside a software configuration container
6679 * \param pcm PCM handle
6680 * \param params Software configuration container
6681 * \param val Minimum avail frames to consider PCM ready
6682 * \return 0 otherwise a negative error code
6684 * Note: This is similar to setting an OSS wakeup point. The valid
6685 * values for 'val' are determined by the specific hardware. Most PC
6686 * sound cards can only accept power of 2 frame counts (i.e. 512,
6687 * 1024, 2048). You cannot use this as a high resolution timer - it
6688 * is limited to how often the sound card hardware raises an
6692 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)
6694 int snd_pcm_sw_params_set_avail_min(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
6697 assert(pcm && params);
6698 /* Fix avail_min if it's below period size. The period_size
6699 * defines the minimal wake-up timing accuracy, so it doesn't
6700 * make sense to set below that.
6702 if (val < pcm->period_size)
6703 val = pcm->period_size;
6704 params->avail_min = val;
6709 * \brief Get avail min from a software configuration container
6710 * \param params Software configuration container
6711 * \param val returned minimum available frames to consider PCM ready
6712 * \return 0 otherwise a negative error code
6714 * This is a threshold value when the PCM stream is considered as ready for
6715 * another read/write operation or poll event.
6718 EXPORT_SYMBOL int INTERNAL(snd_pcm_sw_params_get_avail_min)(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6720 int snd_pcm_sw_params_get_avail_min(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6723 assert(params && val);
6724 *val = params->avail_min;
6729 * \brief Set period event inside a software configuration container
6730 * \param pcm PCM handle
6731 * \param params Software configuration container
6732 * \param val 0 = disable period event, 1 = enable period event
6733 * \return 0 otherwise a negative error code
6735 * An poll (select) wakeup event is raised if enabled.
6737 int snd_pcm_sw_params_set_period_event(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, int val)
6739 assert(pcm && params);
6740 sw_set_period_event(params, val);
6745 * \brief Get period event from a software configuration container
6746 * \param params Software configuration container
6747 * \param val returned period event state
6748 * \return 0 otherwise a negative error code
6750 int snd_pcm_sw_params_get_period_event(const snd_pcm_sw_params_t *params, int *val)
6752 assert(params && val);
6753 *val = sw_get_period_event(params);
6758 * \brief (DEPRECATED) Set xfer align inside a software configuration container
6759 * \param pcm PCM handle
6760 * \param params Software configuration container
6761 * \param val Chunk size (frames are attempted to be transferred in chunks)
6762 * \return 0 otherwise a negative error code
6765 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)
6767 int snd_pcm_sw_params_set_xfer_align(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
6774 * \brief (DEPRECATED) Get xfer align from a software configuration container
6775 * \param params Software configuration container
6776 * \param val returned chunk size (frames are attempted to be transferred in chunks)
6777 * \return 0 otherwise a negative error code
6780 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)
6782 int snd_pcm_sw_params_get_xfer_align(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6790 * \brief Set start threshold inside a software configuration container
6791 * \param pcm PCM handle
6792 * \param params Software configuration container
6793 * \param val Start threshold in frames
6794 * \return 0 otherwise a negative error code
6796 * PCM is automatically started when playback frames available to PCM
6797 * are >= threshold or when requested capture frames are >= threshold
6800 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)
6802 int snd_pcm_sw_params_set_start_threshold(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
6805 assert(pcm && params);
6806 params->start_threshold = val;
6811 * \brief Get start threshold from a software configuration container
6812 * \param params Software configuration container
6813 * \param val Returned start threshold in frames
6814 * \return 0 otherwise a negative error code
6816 * PCM is automatically started when playback frames available to PCM
6817 * are >= threshold or when requested capture frames are >= threshold
6820 EXPORT_SYMBOL int INTERNAL(snd_pcm_sw_params_get_start_threshold)(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6822 int snd_pcm_sw_params_get_start_threshold(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6826 *val = params->start_threshold;
6832 * \brief Set stop threshold inside a software configuration container
6833 * \param pcm PCM handle
6834 * \param params Software configuration container
6835 * \param val Stop threshold in frames
6836 * \return 0 otherwise a negative error code
6838 * PCM is automatically stopped in #SND_PCM_STATE_XRUN state when available
6839 * frames is >= threshold. If the stop threshold is equal to boundary (also
6840 * software parameter - sw_param) then automatic stop will be disabled
6841 * (thus device will do the endless loop in the ring buffer).
6844 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)
6846 int snd_pcm_sw_params_set_stop_threshold(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
6849 assert(pcm && params);
6850 params->stop_threshold = val;
6855 * \brief Get stop threshold from a software configuration container
6856 * \param params Software configuration container
6857 * \param val Returned stop threshold in frames
6858 * \return 0 otherwise a negative error code
6860 * PCM is automatically stopped in #SND_PCM_STATE_XRUN state when available
6861 * frames is >= threshold. If the stop threshold is equal to boundary (also
6862 * software parameter - sw_param) then automatic stop will be disabled
6863 * (thus device will do the endless loop in the ring buffer).
6866 EXPORT_SYMBOL int INTERNAL(snd_pcm_sw_params_get_stop_threshold)(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6868 int snd_pcm_sw_params_get_stop_threshold(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6872 *val = params->stop_threshold;
6878 * \brief Set silence threshold inside a software configuration container
6879 * \param pcm PCM handle
6880 * \param params Software configuration container
6881 * \param val Silence threshold in frames
6882 * \return 0 otherwise a negative error code
6884 * A portion of playback buffer is overwritten with silence (see
6885 * #snd_pcm_sw_params_set_silence_size) when playback underrun is nearer
6886 * than silence threshold.
6889 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)
6891 int snd_pcm_sw_params_set_silence_threshold(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
6894 assert(pcm && params);
6895 if (CHECK_SANITY(val >= pcm->buffer_size)) {
6896 SNDMSG("invalid silent_threshold value %ld (buffer_size = %ld)",
6897 val, pcm->buffer_size);
6900 params->silence_threshold = val;
6905 * \brief Get silence threshold from a software configuration container
6906 * \param params Software configuration container
6907 * \param val Returned silence threshold in frames
6908 * \return 0 otherwise a negative error value
6910 * A portion of playback buffer is overwritten with silence (see
6911 * #snd_pcm_sw_params_set_silence_size) when playback underrun is nearer
6912 * than silence threshold.
6915 EXPORT_SYMBOL int INTERNAL(snd_pcm_sw_params_get_silence_threshold)(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6917 int snd_pcm_sw_params_get_silence_threshold(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6920 assert(params && val);
6921 *val = params->silence_threshold;
6927 * \brief Set silence size inside a software configuration container
6928 * \param pcm PCM handle
6929 * \param params Software configuration container
6930 * \param val Silence size in frames (0 for disabled)
6931 * \return 0 otherwise a negative error code
6933 * A portion of playback buffer is overwritten with silence when playback
6934 * underrun is nearer than silence threshold (see
6935 * #snd_pcm_sw_params_set_silence_threshold)
6937 * When drain silence (see #snd_pcm_hw_params_get_drain_silence) is disabled,
6938 * this will also apply for draining, i.e. silence is written also when the
6939 * drain end is nearer than the silence threshold.
6941 * The special case is when silence size value is equal or greater than
6942 * boundary. The unused portion of the ring buffer (initial written samples
6943 * are untouched) is filled with silence at start. Later, only just processed
6944 * sample area is filled with silence. Note: silence_threshold must be set to zero.
6947 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)
6949 int snd_pcm_sw_params_set_silence_size(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
6952 assert(pcm && params);
6953 if (CHECK_SANITY(val < pcm->boundary && val > pcm->buffer_size)) {
6954 SNDMSG("invalid silence_size %ld (boundary %ld, buffer_size %ld)",
6955 val, pcm->boundary, pcm->buffer_size);
6958 params->silence_size = val;
6963 * \brief Get silence size from a software configuration container
6964 * \param params Software configuration container
6965 * \param val Returned silence size in frames (0 for disabled)
6966 * \return 0 otherwise a negative error code
6968 * A portion of playback buffer is overwritten with silence when playback
6969 * underrun is nearer than silence threshold (see
6970 * #snd_pcm_sw_params_set_silence_threshold)
6973 EXPORT_SYMBOL int INTERNAL(snd_pcm_sw_params_get_silence_size)(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6975 int snd_pcm_sw_params_get_silence_size(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6979 *val = params->silence_size;
6985 * \brief get size of #snd_pcm_status_t
6986 * \return size in bytes
6988 size_t snd_pcm_status_sizeof()
6990 return sizeof(snd_pcm_status_t);
6994 * \brief allocate an invalid #snd_pcm_status_t using standard malloc
6995 * \param ptr returned pointer
6996 * \return 0 on success otherwise negative error code
6998 int snd_pcm_status_malloc(snd_pcm_status_t **ptr)
7001 *ptr = calloc(1, sizeof(snd_pcm_status_t));
7008 * \brief frees a previously allocated #snd_pcm_status_t
7009 * \param obj pointer to object to free
7011 void snd_pcm_status_free(snd_pcm_status_t *obj)
7017 * \brief copy one #snd_pcm_status_t to another
7018 * \param dst pointer to destination
7019 * \param src pointer to source
7021 void snd_pcm_status_copy(snd_pcm_status_t *dst, const snd_pcm_status_t *src)
7028 * \brief Get state from a PCM status container (see #snd_pcm_state)
7029 * \param obj #snd_pcm_status_t pointer
7032 snd_pcm_state_t snd_pcm_status_get_state(const snd_pcm_status_t *obj)
7039 * \brief Get trigger timestamp from a PCM status container
7040 * \param obj #snd_pcm_status_t pointer
7041 * \param ptr Pointer to returned timestamp
7043 * Trigger means a PCM state transition (from stopped to running or
7044 * versa vice). It applies also to pause and suspend. In other words,
7045 * timestamp contains time when stream started or when it was stopped.
7047 void snd_pcm_status_get_trigger_tstamp(const snd_pcm_status_t *obj, snd_timestamp_t *ptr)
7050 ptr->tv_sec = obj->trigger_tstamp.tv_sec;
7051 ptr->tv_usec = obj->trigger_tstamp.tv_nsec / 1000L;
7055 * \brief Get trigger hi-res timestamp from a PCM status container
7056 * \param obj #snd_pcm_status_t pointer
7057 * \param ptr Pointer to returned timestamp
7059 * Trigger means a PCM state transition (from stopped to running or
7060 * versa vice). It applies also to pause and suspend. In other words,
7061 * timestamp contains time when stream started or when it was stopped.
7064 EXPORT_SYMBOL void INTERNAL(snd_pcm_status_get_trigger_htstamp)(const snd_pcm_status_t *obj, snd_htimestamp_t *ptr)
7066 void snd_pcm_status_get_trigger_htstamp(const snd_pcm_status_t *obj, snd_htimestamp_t *ptr)
7070 *ptr = obj->trigger_tstamp;
7072 use_default_symbol_version(__snd_pcm_status_get_trigger_htstamp, snd_pcm_status_get_trigger_htstamp, ALSA_0.9.0rc8);
7075 * \brief Get "now" timestamp from a PCM status container
7076 * \param obj #snd_pcm_status_t pointer
7077 * \param ptr Pointer to returned timestamp
7079 void snd_pcm_status_get_tstamp(const snd_pcm_status_t *obj, snd_timestamp_t *ptr)
7082 ptr->tv_sec = obj->tstamp.tv_sec;
7083 ptr->tv_usec = obj->tstamp.tv_nsec / 1000L;
7087 * \brief Get "now" hi-res timestamp from a PCM status container
7088 * \param obj pointer to #snd_pcm_status_t
7089 * \param ptr Pointer to returned timestamp
7092 EXPORT_SYMBOL void INTERNAL(snd_pcm_status_get_htstamp)(const snd_pcm_status_t *obj, snd_htimestamp_t *ptr)
7094 void snd_pcm_status_get_htstamp(const snd_pcm_status_t *obj, snd_htimestamp_t *ptr)
7100 use_default_symbol_version(__snd_pcm_status_get_htstamp, snd_pcm_status_get_htstamp, ALSA_0.9.0rc8);
7103 * \brief Get "now" hi-res audio timestamp from a PCM status container
7104 * \param obj pointer to #snd_pcm_status_t
7105 * \param ptr Pointer to returned timestamp
7107 void snd_pcm_status_get_audio_htstamp(const snd_pcm_status_t *obj, snd_htimestamp_t *ptr)
7110 *ptr = obj->audio_tstamp;
7114 * \brief Get "now" hi-res driver timestamp from a PCM status container. Defines when the status
7115 * was generated by driver, may differ from normal timestamp.
7116 * \param obj pointer to #snd_pcm_status_t
7117 * \param ptr Pointer to returned timestamp
7119 void snd_pcm_status_get_driver_htstamp(const snd_pcm_status_t *obj, snd_htimestamp_t *ptr)
7122 *ptr = obj->driver_tstamp;
7126 * \brief Get audio_tstamp_report from a PCM status container
7127 * \param obj pointer to #snd_pcm_status_t
7128 * \param audio_tstamp_report Pointer to returned report
7130 void snd_pcm_status_get_audio_htstamp_report(const snd_pcm_status_t *obj,
7131 snd_pcm_audio_tstamp_report_t *audio_tstamp_report)
7133 assert(obj && audio_tstamp_report);
7134 snd_pcm_unpack_audio_tstamp_report(obj->audio_tstamp_data,
7135 obj->audio_tstamp_accuracy,
7136 audio_tstamp_report);
7140 * \brief set audio_tstamp_config from a PCM status container
7141 * \param obj pointer to #snd_pcm_status_t
7142 * \param audio_tstamp_config Pointer to config (valid fields are type_requested and report_delay)
7144 void snd_pcm_status_set_audio_htstamp_config(snd_pcm_status_t *obj,
7145 snd_pcm_audio_tstamp_config_t *audio_tstamp_config)
7147 assert(obj && audio_tstamp_config);
7148 snd_pcm_pack_audio_tstamp_config(&obj->audio_tstamp_data, audio_tstamp_config);
7152 * \brief Get delay from a PCM status container (see #snd_pcm_delay)
7153 * \return Delay in frames
7155 * Delay is distance between current application frame position and
7156 * sound frame position.
7157 * It's positive and less than buffer size in normal situation,
7158 * negative on playback underrun and greater than buffer size on
7161 snd_pcm_sframes_t snd_pcm_status_get_delay(const snd_pcm_status_t *obj)
7168 * \brief Get number of frames available from a PCM status container (see #snd_pcm_avail_update)
7169 * \return Number of frames ready to be read/written
7171 snd_pcm_uframes_t snd_pcm_status_get_avail(const snd_pcm_status_t *obj)
7178 * \brief Get maximum number of frames available from a PCM status container after last #snd_pcm_status call
7179 * \return Maximum number of frames ready to be read/written
7181 * This value returns the peak for the available frames between #snd_pcm_status calls.
7183 snd_pcm_uframes_t snd_pcm_status_get_avail_max(const snd_pcm_status_t *obj)
7186 return obj->avail_max;
7190 * \brief Get count of ADC overrange detections since last call
7191 * \return Count of ADC overrange detections
7193 snd_pcm_uframes_t snd_pcm_status_get_overrange(const snd_pcm_status_t *obj)
7196 return obj->overrange;
7200 * \brief get size of #snd_pcm_info_t
7201 * \return size in bytes
7203 size_t snd_pcm_info_sizeof()
7205 return sizeof(snd_pcm_info_t);
7209 * \brief allocate an invalid #snd_pcm_info_t using standard malloc
7210 * \param ptr returned pointer
7211 * \return 0 on success otherwise negative error code
7213 int snd_pcm_info_malloc(snd_pcm_info_t **ptr)
7216 *ptr = calloc(1, sizeof(snd_pcm_info_t));
7223 * \brief frees a previously allocated #snd_pcm_info_t
7224 * \param obj pointer to object to free
7226 void snd_pcm_info_free(snd_pcm_info_t *obj)
7232 * \brief copy one #snd_pcm_info_t to another
7233 * \param dst pointer to destination
7234 * \param src pointer to source
7236 void snd_pcm_info_copy(snd_pcm_info_t *dst, const snd_pcm_info_t *src)
7243 * \brief Get device from a PCM info container
7244 * \param obj PCM info container
7245 * \return device number
7247 unsigned int snd_pcm_info_get_device(const snd_pcm_info_t *obj)
7254 * \brief Get subdevice from a PCM info container
7255 * \param obj PCM info container
7256 * \return subdevice number
7258 unsigned int snd_pcm_info_get_subdevice(const snd_pcm_info_t *obj)
7261 return obj->subdevice;
7265 * \brief Get stream (direction) from a PCM info container
7266 * \param obj PCM info container
7269 snd_pcm_stream_t snd_pcm_info_get_stream(const snd_pcm_info_t *obj)
7276 * \brief Get card from a PCM info container
7277 * \param obj PCM info container
7278 * \return card number otherwise a negative error code if not associable to a card
7280 int snd_pcm_info_get_card(const snd_pcm_info_t *obj)
7287 * \brief Get id from a PCM info container
7288 * \param obj PCM info container
7289 * \return short id of PCM
7291 const char *snd_pcm_info_get_id(const snd_pcm_info_t *obj)
7294 return (const char *)obj->id;
7298 * \brief Get name from a PCM info container
7299 * \param obj PCM info container
7300 * \return name of PCM
7302 const char *snd_pcm_info_get_name(const snd_pcm_info_t *obj)
7305 return (const char *)obj->name;
7309 * \brief Get subdevice name from a PCM info container
7310 * \param obj PCM info container
7311 * \return name of used PCM subdevice
7313 const char *snd_pcm_info_get_subdevice_name(const snd_pcm_info_t *obj)
7316 return (const char *)obj->subname;
7320 * \brief Get class from a PCM info container
7321 * \param obj PCM info container
7322 * \return class of PCM
7324 snd_pcm_class_t snd_pcm_info_get_class(const snd_pcm_info_t *obj)
7327 return obj->dev_class;
7331 * \brief Get subclass from a PCM info container
7332 * \param obj PCM info container
7333 * \return subclass of PCM
7335 snd_pcm_subclass_t snd_pcm_info_get_subclass(const snd_pcm_info_t *obj)
7338 return obj->dev_subclass;
7342 * \brief Get subdevices count from a PCM info container
7343 * \param obj PCM info container
7344 * \return subdevices total count of PCM
7346 unsigned int snd_pcm_info_get_subdevices_count(const snd_pcm_info_t *obj)
7349 return obj->subdevices_count;
7353 * \brief Get available subdevices count from a PCM info container
7354 * \param obj PCM info container
7355 * \return available subdevices count of PCM
7357 unsigned int snd_pcm_info_get_subdevices_avail(const snd_pcm_info_t *obj)
7360 return obj->subdevices_avail;
7364 * \brief (DEPRECATED) Get hardware synchronization ID from a PCM info container
7365 * \param obj PCM info container
7366 * \return hardware synchronization ID
7368 snd_pcm_sync_id_t snd_pcm_info_get_sync(const snd_pcm_info_t *obj)
7370 snd_pcm_sync_id_t res;
7372 bzero(&res, sizeof(res));
7376 link_warning(snd_pcm_info_get_sync, "Warning: snd_pcm_info_get_sync is deprecated, consider to use snd_pcm_hw_params_get_sync");
7380 * \brief Set wanted device inside a PCM info container (see #snd_ctl_pcm_info)
7381 * \param obj PCM info container
7382 * \param val Device number
7384 void snd_pcm_info_set_device(snd_pcm_info_t *obj, unsigned int val)
7391 * \brief Set wanted subdevice inside a PCM info container (see #snd_ctl_pcm_info)
7392 * \param obj PCM info container
7393 * \param val Subdevice number
7395 void snd_pcm_info_set_subdevice(snd_pcm_info_t *obj, unsigned int val)
7398 obj->subdevice = val;
7402 * \brief Set wanted stream inside a PCM info container (see #snd_ctl_pcm_info)
7403 * \param obj PCM info container
7406 void snd_pcm_info_set_stream(snd_pcm_info_t *obj, snd_pcm_stream_t val)
7413 * \brief Application request to access a portion of direct (mmap) area
7414 * \param pcm PCM handle
7415 * \param areas Returned mmap channel areas
7416 * \param offset Returned mmap area offset in area steps (== frames)
7417 * \param frames mmap area portion size in frames (wanted on entry, contiguous available on exit)
7418 * \return 0 on success otherwise a negative error code
7420 * It is necessary to call the snd_pcm_avail_update() function directly before
7421 * this call. Otherwise, this function can return a wrong count of available frames.
7423 * The function should be called before a sample-direct area can be accessed.
7424 * The resulting size parameter is always less or equal to the input count of frames
7425 * and can be zero, if no frames can be processed (the ring buffer is full).
7427 * See the snd_pcm_mmap_commit() function to finish the frame processing in
7430 * The function is thread-safe when built with the proper option.
7432 int snd_pcm_mmap_begin(snd_pcm_t *pcm,
7433 const snd_pcm_channel_area_t **areas,
7434 snd_pcm_uframes_t *offset,
7435 snd_pcm_uframes_t *frames)
7439 err = bad_pcm_state(pcm, P_STATE_RUNNABLE, 0);
7442 snd_pcm_lock(pcm->fast_op_arg);
7443 err = __snd_pcm_mmap_begin(pcm, areas, offset, frames);
7444 snd_pcm_unlock(pcm->fast_op_arg);
7449 int __snd_pcm_mmap_begin_generic(snd_pcm_t *pcm, const snd_pcm_channel_area_t **areas,
7450 snd_pcm_uframes_t *offset, snd_pcm_uframes_t *frames)
7452 snd_pcm_uframes_t cont;
7453 snd_pcm_uframes_t f;
7454 snd_pcm_uframes_t avail;
7455 const snd_pcm_channel_area_t *xareas;
7457 assert(pcm && areas && offset && frames);
7459 /* fallback for plugins that do not specify new callback */
7460 xareas = snd_pcm_mmap_areas(pcm);
7464 *offset = *pcm->appl.ptr % pcm->buffer_size;
7465 avail = snd_pcm_mmap_avail(pcm);
7466 if (avail > pcm->buffer_size)
7467 avail = pcm->buffer_size;
7468 cont = pcm->buffer_size - *offset;
7478 /* locked version */
7479 int __snd_pcm_mmap_begin(snd_pcm_t *pcm, const snd_pcm_channel_area_t **areas,
7480 snd_pcm_uframes_t *offset, snd_pcm_uframes_t *frames)
7482 assert(pcm && areas && offset && frames);
7484 if (pcm->fast_ops->mmap_begin)
7485 return pcm->fast_ops->mmap_begin(pcm->fast_op_arg, areas, offset, frames);
7487 return __snd_pcm_mmap_begin_generic(pcm, areas, offset, frames);
7492 * \brief Application has completed the access to area requested with #snd_pcm_mmap_begin
7493 * \param pcm PCM handle
7494 * \param offset area offset in area steps (== frames)
7495 * \param frames area portion size in frames
7496 * \return count of transferred frames otherwise a negative error code
7498 * You should pass this function the offset value that
7499 * snd_pcm_mmap_begin() returned. The frames parameter should hold the
7500 * number of frames you have written or read to/from the audio
7501 * buffer. The frames parameter must never exceed the contiguous frames
7502 * count that snd_pcm_mmap_begin() returned. Each call to snd_pcm_mmap_begin()
7503 * must be followed by a call to snd_pcm_mmap_commit().
7508 const snd_pcm_area_t *areas;
7509 snd_pcm_sframes_t avail, size, commitres;
7510 snd_pcm_uframes_t offset, frames;
7513 avail = snd_pcm_avail_update(pcm);
7516 // at this point, we can transfer at least 'avail' frames
7518 // we want to process frames in chunks (period_size)
7519 if (avail < period_size)
7522 // it is possible that contiguous areas are smaller, thus we use a loop
7526 err = snd_pcm_mmap_begin(pcm_handle, &areas, &offset, &frames);
7529 // this function fills the areas from offset with count of frames
7530 generate_sine(areas, offset, frames, &phase);
7531 commitres = snd_pcm_mmap_commit(pcm_handle, offset, frames);
7532 if (commitres < 0 || commitres != frames)
7533 error(commitres >= 0 ? -EPIPE : commitres);
7540 * Look to the \link example_test_pcm Sine-wave generator \endlink example
7541 * for more details about the generate_sine function.
7543 * The function is thread-safe when built with the proper option.
7545 snd_pcm_sframes_t snd_pcm_mmap_commit(snd_pcm_t *pcm,
7546 snd_pcm_uframes_t offset,
7547 snd_pcm_uframes_t frames)
7549 snd_pcm_sframes_t result;
7552 err = bad_pcm_state(pcm, P_STATE_RUNNABLE, 0);
7555 snd_pcm_lock(pcm->fast_op_arg);
7556 result = __snd_pcm_mmap_commit(pcm, offset, frames);
7557 snd_pcm_unlock(pcm->fast_op_arg);
7563 snd_pcm_sframes_t __snd_pcm_mmap_commit(snd_pcm_t *pcm,
7564 snd_pcm_uframes_t offset,
7565 snd_pcm_uframes_t frames)
7568 if (CHECK_SANITY(offset != *pcm->appl.ptr % pcm->buffer_size)) {
7569 SNDMSG("commit offset (%ld) doesn't match with appl_ptr (%ld) %% buf_size (%ld)",
7570 offset, *pcm->appl.ptr, pcm->buffer_size);
7573 if (CHECK_SANITY(frames > snd_pcm_mmap_avail(pcm))) {
7574 SNDMSG("commit frames (%ld) overflow (avail = %ld)", frames,
7575 snd_pcm_mmap_avail(pcm));
7578 if (pcm->fast_ops->mmap_commit)
7579 return pcm->fast_ops->mmap_commit(pcm->fast_op_arg, offset, frames);
7584 int _snd_pcm_poll_descriptor(snd_pcm_t *pcm)
7587 return pcm->poll_fd;
7590 void snd_pcm_areas_from_buf(snd_pcm_t *pcm, snd_pcm_channel_area_t *areas,
7593 unsigned int channel;
7594 unsigned int channels;
7597 channels = pcm->channels;
7598 for (channel = 0; channel < channels; ++channel, ++areas) {
7600 areas->first = channel * pcm->sample_bits;
7601 areas->step = pcm->frame_bits;
7603 snd_pcm_unlock(pcm);
7606 void snd_pcm_areas_from_bufs(snd_pcm_t *pcm, snd_pcm_channel_area_t *areas,
7609 unsigned int channel;
7610 unsigned int channels;
7613 channels = pcm->channels;
7614 for (channel = 0; channel < channels; ++channel, ++areas, ++bufs) {
7615 areas->addr = *bufs;
7617 areas->step = pcm->sample_bits;
7619 snd_pcm_unlock(pcm);
7622 snd_pcm_sframes_t snd_pcm_read_areas(snd_pcm_t *pcm, const snd_pcm_channel_area_t *areas,
7623 snd_pcm_uframes_t offset, snd_pcm_uframes_t size,
7624 snd_pcm_xfer_areas_func_t func)
7626 snd_pcm_uframes_t xfer = 0;
7627 snd_pcm_sframes_t err = 0;
7628 snd_pcm_state_t state;
7633 __snd_pcm_lock(pcm->fast_op_arg); /* forced lock */
7635 snd_pcm_uframes_t frames;
7636 snd_pcm_sframes_t avail;
7638 state = __snd_pcm_state(pcm);
7640 case SND_PCM_STATE_PREPARED:
7641 err = __snd_pcm_start(pcm);
7645 case SND_PCM_STATE_RUNNING:
7646 err = __snd_pcm_hwsync(pcm);
7650 case SND_PCM_STATE_DRAINING:
7651 case SND_PCM_STATE_PAUSED:
7654 err = pcm_state_to_error(state);
7659 avail = __snd_pcm_avail_update(pcm);
7665 if (state == SND_PCM_STATE_DRAINING)
7667 if (pcm->mode & SND_PCM_NONBLOCK) {
7672 err = __snd_pcm_wait_in_lock(pcm, SND_PCM_WAIT_IO);
7679 if (frames > (snd_pcm_uframes_t) avail)
7683 err = func(pcm, areas, offset, frames);
7692 __snd_pcm_unlock(pcm->fast_op_arg);
7693 return xfer > 0 ? (snd_pcm_sframes_t) xfer : snd_pcm_check_error(pcm, err);
7696 snd_pcm_sframes_t snd_pcm_write_areas(snd_pcm_t *pcm, const snd_pcm_channel_area_t *areas,
7697 snd_pcm_uframes_t offset, snd_pcm_uframes_t size,
7698 snd_pcm_xfer_areas_func_t func)
7700 snd_pcm_uframes_t xfer = 0;
7701 snd_pcm_sframes_t err = 0;
7702 snd_pcm_state_t state;
7707 __snd_pcm_lock(pcm->fast_op_arg); /* forced lock */
7709 snd_pcm_uframes_t frames;
7710 snd_pcm_sframes_t avail;
7712 state = __snd_pcm_state(pcm);
7714 case SND_PCM_STATE_PREPARED:
7715 case SND_PCM_STATE_PAUSED:
7717 case SND_PCM_STATE_RUNNING:
7718 err = __snd_pcm_hwsync(pcm);
7723 err = pcm_state_to_error(state);
7728 avail = __snd_pcm_avail_update(pcm);
7733 if (state == SND_PCM_STATE_RUNNING &&
7734 size > (snd_pcm_uframes_t)avail) {
7735 if (snd_pcm_may_wait_for_avail_min(pcm, avail)) {
7736 if (pcm->mode & SND_PCM_NONBLOCK) {
7741 err = snd_pcm_wait_nocheck(pcm, SND_PCM_WAIT_IO);
7746 /* the snd_pcm_may_wait_for_avail_min may check against the
7747 * updated hw.ptr (slaves), get the avail again here
7749 avail = __snd_pcm_avail_update(pcm);
7756 if (frames > (snd_pcm_uframes_t) avail)
7760 err = func(pcm, areas, offset, frames);
7764 if (state == SND_PCM_STATE_PREPARED) {
7765 snd_pcm_sframes_t hw_avail = pcm->buffer_size - avail;
7767 /* some plugins might automatically start the stream */
7768 state = __snd_pcm_state(pcm);
7769 if (state == SND_PCM_STATE_PREPARED &&
7771 (snd_pcm_uframes_t) hw_avail >= pcm->start_threshold) {
7772 err = __snd_pcm_start(pcm);
7782 __snd_pcm_unlock(pcm->fast_op_arg);
7783 return xfer > 0 ? (snd_pcm_sframes_t) xfer : snd_pcm_check_error(pcm, err);
7786 snd_pcm_uframes_t _snd_pcm_mmap_hw_ptr(snd_pcm_t *pcm)
7788 return *pcm->hw.ptr;
7791 snd_pcm_uframes_t _snd_pcm_boundary(snd_pcm_t *pcm)
7793 return pcm->boundary;
7797 link_warning(_snd_pcm_mmap_hw_ptr, "Warning: _snd_pcm_mmap_hw_ptr() is deprecated, consider to not use this function");
7798 link_warning(_snd_pcm_boundary, "Warning: _snd_pcm_boundary() is deprecated, consider to use snd_pcm_sw_params_current()");
7801 static const char *const names[SND_PCM_HW_PARAM_LAST_INTERVAL + 1] = {
7802 [SND_PCM_HW_PARAM_FORMAT] = "format",
7803 [SND_PCM_HW_PARAM_CHANNELS] = "channels",
7804 [SND_PCM_HW_PARAM_RATE] = "rate",
7805 [SND_PCM_HW_PARAM_PERIOD_TIME] = "period_time",
7806 [SND_PCM_HW_PARAM_PERIOD_SIZE] = "period_size",
7807 [SND_PCM_HW_PARAM_BUFFER_TIME] = "buffer_time",
7808 [SND_PCM_HW_PARAM_BUFFER_SIZE] = "buffer_size",
7809 [SND_PCM_HW_PARAM_PERIODS] = "periods"
7812 int snd_pcm_slave_conf(snd_config_t *root, snd_config_t *conf,
7813 snd_config_t **_pcm_conf, unsigned int count, ...)
7815 snd_config_iterator_t i, next;
7824 snd_config_t *pcm_conf = NULL;
7831 if (snd_config_get_string(conf, &str) >= 0) {
7832 err = snd_config_search_definition(root, "pcm_slave", str, &conf);
7834 SNDERR("Invalid slave definition");
7839 if (snd_config_get_type(conf) != SND_CONFIG_TYPE_COMPOUND) {
7840 SNDERR("Invalid slave definition");
7844 va_start(args, count);
7845 for (k = 0; k < count; ++k) {
7846 fields[k].index = va_arg(args, int);
7847 fields[k].flags = va_arg(args, int);
7848 fields[k].ptr = va_arg(args, void *);
7849 fields[k].present = 0;
7852 snd_config_for_each(i, next, conf) {
7853 snd_config_t *n = snd_config_iterator_entry(i);
7855 if (snd_config_get_id(n, &id) < 0)
7857 if (strcmp(id, "comment") == 0)
7859 if (strcmp(id, "pcm") == 0) {
7860 if (pcm_conf != NULL)
7861 snd_config_delete(pcm_conf);
7862 if ((err = snd_config_copy(&pcm_conf, n)) < 0)
7866 for (k = 0; k < count; ++k) {
7867 unsigned int idx = fields[k].index;
7869 assert(idx < SND_PCM_HW_PARAM_LAST_INTERVAL);
7871 if (strcmp(id, names[idx]) != 0)
7874 case SND_PCM_HW_PARAM_FORMAT:
7877 err = snd_config_get_string(n, &str);
7880 SNDERR("invalid type for %s", id);
7883 if ((fields[k].flags & SCONF_UNCHANGED) &&
7884 strcasecmp(str, "unchanged") == 0) {
7885 *(snd_pcm_format_t*)fields[k].ptr = (snd_pcm_format_t) -2;
7888 f = snd_pcm_format_value(str);
7889 if (f == SND_PCM_FORMAT_UNKNOWN) {
7890 SNDERR("unknown format %s", str);
7894 *(snd_pcm_format_t*)fields[k].ptr = f;
7898 if ((fields[k].flags & SCONF_UNCHANGED)) {
7899 err = snd_config_get_string(n, &str);
7901 strcasecmp(str, "unchanged") == 0) {
7902 *(int*)fields[k].ptr = -2;
7906 err = snd_config_get_integer(n, &v);
7909 *(int*)fields[k].ptr = v;
7912 fields[k].present = 1;
7917 SNDERR("Unknown field %s", id);
7922 SNDERR("missing field pcm");
7926 for (k = 0; k < count; ++k) {
7927 if ((fields[k].flags & SCONF_MANDATORY) && !fields[k].present) {
7928 SNDERR("missing field %s", names[fields[k].index]);
7933 *_pcm_conf = pcm_conf;
7938 snd_config_delete(pcm_conf);
7940 snd_config_delete(conf);
7944 static void snd_pcm_set_ptr(snd_pcm_t *pcm, snd_pcm_rbptr_t *rbptr,
7945 volatile snd_pcm_uframes_t *hw_ptr, int fd, off_t offset)
7947 rbptr->master = NULL; /* I'm master */
7948 rbptr->ptr = hw_ptr;
7950 rbptr->offset = offset;
7952 rbptr->changed(pcm, NULL);
7955 void snd_pcm_set_hw_ptr(snd_pcm_t *pcm, volatile snd_pcm_uframes_t *hw_ptr, int fd, off_t offset)
7959 snd_pcm_set_ptr(pcm, &pcm->hw, hw_ptr, fd, offset);
7962 void snd_pcm_set_appl_ptr(snd_pcm_t *pcm, volatile snd_pcm_uframes_t *appl_ptr, int fd, off_t offset)
7966 snd_pcm_set_ptr(pcm, &pcm->appl, appl_ptr, fd, offset);
7969 static void snd_pcm_link_ptr(snd_pcm_t *pcm, snd_pcm_rbptr_t *pcm_rbptr,
7970 snd_pcm_t *slave, snd_pcm_rbptr_t *slave_rbptr)
7975 a = slave_rbptr->link_dst;
7976 for (idx = 0; idx < slave_rbptr->link_dst_count; idx++)
7977 if (a[idx] == NULL) {
7979 goto __found_free_place;
7981 a = realloc(a, sizeof(snd_pcm_t *) * (slave_rbptr->link_dst_count + 1));
7983 pcm_rbptr->ptr = NULL;
7985 pcm_rbptr->offset = 0UL;
7988 a[slave_rbptr->link_dst_count++] = pcm;
7990 pcm_rbptr->master = slave_rbptr->master ? slave_rbptr->master : slave;
7991 pcm_rbptr->ptr = slave_rbptr->ptr;
7992 pcm_rbptr->fd = slave_rbptr->fd;
7993 pcm_rbptr->offset = slave_rbptr->offset;
7994 slave_rbptr->link_dst = a;
7995 if (pcm_rbptr->changed)
7996 pcm_rbptr->changed(pcm, slave);
7999 static void snd_pcm_unlink_ptr(snd_pcm_t *pcm, snd_pcm_rbptr_t *pcm_rbptr,
8000 snd_pcm_t *slave, snd_pcm_rbptr_t *slave_rbptr)
8005 a = slave_rbptr->link_dst;
8006 for (idx = 0; idx < slave_rbptr->link_dst_count; idx++) {
8007 if (a[idx] == pcm) {
8016 pcm_rbptr->master = NULL;
8017 pcm_rbptr->ptr = NULL;
8019 pcm_rbptr->offset = 0UL;
8020 if (pcm_rbptr->changed)
8021 pcm_rbptr->changed(pcm, slave);
8024 void snd_pcm_link_hw_ptr(snd_pcm_t *pcm, snd_pcm_t *slave)
8028 snd_pcm_link_ptr(pcm, &pcm->hw, slave, &slave->hw);
8031 void snd_pcm_link_appl_ptr(snd_pcm_t *pcm, snd_pcm_t *slave)
8035 snd_pcm_link_ptr(pcm, &pcm->appl, slave, &slave->appl);
8038 void snd_pcm_unlink_hw_ptr(snd_pcm_t *pcm, snd_pcm_t *slave)
8042 snd_pcm_unlink_ptr(pcm, &pcm->hw, slave, &slave->hw);
8045 void snd_pcm_unlink_appl_ptr(snd_pcm_t *pcm, snd_pcm_t *slave)
8049 snd_pcm_unlink_ptr(pcm, &pcm->appl, slave, &slave->appl);
8052 #endif /* DOC_HIDDEN */
8060 #ifdef USE_VERSIONED_SYMBOLS
8062 #define OBSOLETE1(name, what, new) \
8063 default_symbol_version(__##name, name, new); \
8064 symbol_version(__old_##name, name, what);
8068 #define OBSOLETE1(name, what, new) \
8069 use_default_symbol_version(__##name, name, new);
8071 #endif /* USE_VERSIONED_SYMBOLS */
8073 #define __P_OLD_GET(pfx, name, val_type, ret_type) \
8074 EXPORT_SYMBOL ret_type pfx##name(const snd_pcm_hw_params_t *params) \
8077 if (INTERNAL(name)(params, &val) < 0) \
8079 return (ret_type)val; \
8082 #define __P_OLD_GET1(pfx, name, val_type, ret_type) \
8083 EXPORT_SYMBOL ret_type pfx##name(const snd_pcm_hw_params_t *params, int *dir) \
8086 if (INTERNAL(name)(params, &val, dir) < 0) \
8088 return (ret_type)val; \
8091 #define __OLD_GET(name, val_type, ret_type) __P_OLD_GET(__old_, name, val_type, ret_type)
8092 #define __OLD_GET1(name, val_type, ret_type) __P_OLD_GET1(__old_, name, val_type, ret_type)
8094 __OLD_GET(snd_pcm_hw_params_get_access, snd_pcm_access_t, int);
8095 __OLD_GET(snd_pcm_hw_params_get_format, snd_pcm_format_t, int);
8096 __OLD_GET(snd_pcm_hw_params_get_subformat, snd_pcm_subformat_t, int);
8097 __OLD_GET(snd_pcm_hw_params_get_channels, unsigned int, int);
8098 __OLD_GET1(snd_pcm_hw_params_get_rate, unsigned int, int);
8099 __OLD_GET1(snd_pcm_hw_params_get_period_time, unsigned int, int);
8100 __OLD_GET1(snd_pcm_hw_params_get_period_size, snd_pcm_uframes_t, snd_pcm_sframes_t);
8101 __OLD_GET1(snd_pcm_hw_params_get_periods, unsigned int, int);
8102 __OLD_GET1(snd_pcm_hw_params_get_buffer_time, unsigned int, int);
8103 __OLD_GET(snd_pcm_hw_params_get_buffer_size, snd_pcm_uframes_t, snd_pcm_sframes_t);
8104 __OLD_GET1(snd_pcm_hw_params_get_tick_time, unsigned int, int);
8106 __OLD_GET(snd_pcm_hw_params_get_channels_min, unsigned int, unsigned int);
8107 __OLD_GET1(snd_pcm_hw_params_get_rate_min, unsigned int, unsigned int);
8108 __OLD_GET1(snd_pcm_hw_params_get_period_time_min, unsigned int, unsigned int);
8109 __OLD_GET1(snd_pcm_hw_params_get_period_size_min, snd_pcm_uframes_t, snd_pcm_uframes_t);
8110 __OLD_GET1(snd_pcm_hw_params_get_periods_min, unsigned int, unsigned int);
8111 __OLD_GET1(snd_pcm_hw_params_get_buffer_time_min, unsigned int, unsigned int);
8112 __OLD_GET(snd_pcm_hw_params_get_buffer_size_min, snd_pcm_uframes_t, snd_pcm_uframes_t);
8113 __OLD_GET1(snd_pcm_hw_params_get_tick_time_min, unsigned int, unsigned int);
8115 __OLD_GET(snd_pcm_hw_params_get_channels_max, unsigned int, unsigned int);
8116 __OLD_GET1(snd_pcm_hw_params_get_rate_max, unsigned int, unsigned int);
8117 __OLD_GET1(snd_pcm_hw_params_get_period_time_max, unsigned int, unsigned int);
8118 __OLD_GET1(snd_pcm_hw_params_get_period_size_max, snd_pcm_uframes_t, snd_pcm_uframes_t);
8119 __OLD_GET1(snd_pcm_hw_params_get_periods_max, unsigned int, unsigned int);
8120 __OLD_GET1(snd_pcm_hw_params_get_buffer_time_max, unsigned int, unsigned int);
8121 __OLD_GET(snd_pcm_hw_params_get_buffer_size_max, snd_pcm_uframes_t, snd_pcm_uframes_t);
8122 __OLD_GET1(snd_pcm_hw_params_get_tick_time_max, unsigned int, unsigned int);
8124 #define __P_OLD_NEAR(pfx, name, ret_type) \
8125 EXPORT_SYMBOL ret_type pfx##name(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, ret_type val) \
8127 if (INTERNAL(name)(pcm, params, &val) < 0) \
8129 return (ret_type)val; \
8132 #define __P_OLD_NEAR1(pfx, name, ret_type) \
8133 EXPORT_SYMBOL ret_type pfx##name(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, ret_type val, int *dir) \
8135 if (INTERNAL(name)(pcm, params, &val, dir) < 0) \
8137 return (ret_type)val; \
8140 #define __OLD_NEAR(name, ret_type) __P_OLD_NEAR(__old_, name, ret_type)
8141 #define __OLD_NEAR1(name, ret_type) __P_OLD_NEAR1(__old_, name, ret_type)
8143 __OLD_NEAR(snd_pcm_hw_params_set_channels_near, unsigned int);
8144 __OLD_NEAR1(snd_pcm_hw_params_set_rate_near, unsigned int);
8145 __OLD_NEAR1(snd_pcm_hw_params_set_period_time_near, unsigned int);
8146 __OLD_NEAR1(snd_pcm_hw_params_set_period_size_near, snd_pcm_uframes_t);
8147 __OLD_NEAR1(snd_pcm_hw_params_set_periods_near, unsigned int);
8148 __OLD_NEAR1(snd_pcm_hw_params_set_buffer_time_near, unsigned int);
8149 __OLD_NEAR(snd_pcm_hw_params_set_buffer_size_near, snd_pcm_uframes_t);
8150 __OLD_NEAR1(snd_pcm_hw_params_set_tick_time_near, unsigned int);
8152 #define __P_OLD_SET_FL(pfx, name, ret_type) \
8153 EXPORT_SYMBOL ret_type pfx##name(snd_pcm_t *pcm, snd_pcm_hw_params_t *params) \
8156 if (INTERNAL(name)(pcm, params, &val) < 0) \
8158 return (ret_type)val; \
8161 #define __P_OLD_SET_FL1(pfx, name, ret_type) \
8162 EXPORT_SYMBOL ret_type pfx##name(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, int *dir) \
8165 if (INTERNAL(name)(pcm, params, &val, dir) < 0) \
8167 return (ret_type)val; \
8170 #define __OLD_SET_FL(name, ret_type) __P_OLD_SET_FL(__old_, name, ret_type)
8171 #define __OLD_SET_FL1(name, ret_type) __P_OLD_SET_FL1(__old_, name, ret_type)
8173 __OLD_SET_FL(snd_pcm_hw_params_set_access_first, snd_pcm_access_t);
8174 __OLD_SET_FL(snd_pcm_hw_params_set_format_first, snd_pcm_format_t);
8175 __OLD_SET_FL(snd_pcm_hw_params_set_subformat_first, snd_pcm_subformat_t);
8176 __OLD_SET_FL(snd_pcm_hw_params_set_channels_first, unsigned int);
8177 __OLD_SET_FL1(snd_pcm_hw_params_set_rate_first, unsigned int);
8178 __OLD_SET_FL1(snd_pcm_hw_params_set_period_time_first, unsigned int);
8179 __OLD_SET_FL1(snd_pcm_hw_params_set_period_size_first, snd_pcm_uframes_t);
8180 __OLD_SET_FL1(snd_pcm_hw_params_set_periods_first, unsigned int);
8181 __OLD_SET_FL1(snd_pcm_hw_params_set_buffer_time_first, unsigned int);
8182 __OLD_SET_FL(snd_pcm_hw_params_set_buffer_size_first, snd_pcm_uframes_t);
8183 __OLD_SET_FL1(snd_pcm_hw_params_set_tick_time_first, unsigned int);
8185 __OLD_SET_FL(snd_pcm_hw_params_set_access_last, snd_pcm_access_t);
8186 __OLD_SET_FL(snd_pcm_hw_params_set_format_last, snd_pcm_format_t);
8187 __OLD_SET_FL(snd_pcm_hw_params_set_subformat_last, snd_pcm_subformat_t);
8188 __OLD_SET_FL(snd_pcm_hw_params_set_channels_last, unsigned int);
8189 __OLD_SET_FL1(snd_pcm_hw_params_set_rate_last, unsigned int);
8190 __OLD_SET_FL1(snd_pcm_hw_params_set_period_time_last, unsigned int);
8191 __OLD_SET_FL1(snd_pcm_hw_params_set_period_size_last, snd_pcm_uframes_t);
8192 __OLD_SET_FL1(snd_pcm_hw_params_set_periods_last, unsigned int);
8193 __OLD_SET_FL1(snd_pcm_hw_params_set_buffer_time_last, unsigned int);
8194 __OLD_SET_FL(snd_pcm_hw_params_set_buffer_size_last, snd_pcm_uframes_t);
8195 __OLD_SET_FL1(snd_pcm_hw_params_set_tick_time_last, unsigned int);
8197 #define __P_OLD_GET_SW(pfx, name, ret_type) \
8198 EXPORT_SYMBOL ret_type pfx##name(snd_pcm_sw_params_t *params) \
8201 if (INTERNAL(name)(params, &val) < 0) \
8203 return (ret_type)val; \
8206 #define __OLD_GET_SW(name, ret_type) __P_OLD_GET_SW(__old_, name, ret_type)
8208 __OLD_GET_SW(snd_pcm_sw_params_get_tstamp_mode, snd_pcm_tstamp_t);
8209 __OLD_GET_SW(snd_pcm_sw_params_get_sleep_min, unsigned int);
8210 __OLD_GET_SW(snd_pcm_sw_params_get_avail_min, snd_pcm_uframes_t);
8211 __OLD_GET_SW(snd_pcm_sw_params_get_xfer_align, snd_pcm_uframes_t);
8212 __OLD_GET_SW(snd_pcm_sw_params_get_start_threshold, snd_pcm_uframes_t);
8213 __OLD_GET_SW(snd_pcm_sw_params_get_stop_threshold, snd_pcm_uframes_t);
8214 __OLD_GET_SW(snd_pcm_sw_params_get_silence_threshold, snd_pcm_uframes_t);
8215 __OLD_GET_SW(snd_pcm_sw_params_get_silence_size, snd_pcm_uframes_t);
8217 OBSOLETE1(snd_pcm_hw_params_get_access, ALSA_0.9, ALSA_0.9.0rc4);
8218 OBSOLETE1(snd_pcm_hw_params_set_access_first, ALSA_0.9, ALSA_0.9.0rc4);
8219 OBSOLETE1(snd_pcm_hw_params_set_access_last, ALSA_0.9, ALSA_0.9.0rc4);
8221 OBSOLETE1(snd_pcm_hw_params_get_format, ALSA_0.9, ALSA_0.9.0rc4);
8222 OBSOLETE1(snd_pcm_hw_params_set_format_first, ALSA_0.9, ALSA_0.9.0rc4);
8223 OBSOLETE1(snd_pcm_hw_params_set_format_last, ALSA_0.9, ALSA_0.9.0rc4);
8225 OBSOLETE1(snd_pcm_hw_params_get_subformat, ALSA_0.9, ALSA_0.9.0rc4);
8226 OBSOLETE1(snd_pcm_hw_params_set_subformat_first, ALSA_0.9, ALSA_0.9.0rc4);
8227 OBSOLETE1(snd_pcm_hw_params_set_subformat_last, ALSA_0.9, ALSA_0.9.0rc4);
8229 OBSOLETE1(snd_pcm_hw_params_get_channels, ALSA_0.9, ALSA_0.9.0rc4);
8230 OBSOLETE1(snd_pcm_hw_params_get_channels_min, ALSA_0.9, ALSA_0.9.0rc4);
8231 OBSOLETE1(snd_pcm_hw_params_get_channels_max, ALSA_0.9, ALSA_0.9.0rc4);
8232 OBSOLETE1(snd_pcm_hw_params_set_channels_near, ALSA_0.9, ALSA_0.9.0rc4);
8233 OBSOLETE1(snd_pcm_hw_params_set_channels_first, ALSA_0.9, ALSA_0.9.0rc4);
8234 OBSOLETE1(snd_pcm_hw_params_set_channels_last, ALSA_0.9, ALSA_0.9.0rc4);
8236 OBSOLETE1(snd_pcm_hw_params_get_rate, ALSA_0.9, ALSA_0.9.0rc4);
8237 OBSOLETE1(snd_pcm_hw_params_get_rate_min, ALSA_0.9, ALSA_0.9.0rc4);
8238 OBSOLETE1(snd_pcm_hw_params_get_rate_max, ALSA_0.9, ALSA_0.9.0rc4);
8239 OBSOLETE1(snd_pcm_hw_params_set_rate_near, ALSA_0.9, ALSA_0.9.0rc4);
8240 OBSOLETE1(snd_pcm_hw_params_set_rate_first, ALSA_0.9, ALSA_0.9.0rc4);
8241 OBSOLETE1(snd_pcm_hw_params_set_rate_last, ALSA_0.9, ALSA_0.9.0rc4);
8243 OBSOLETE1(snd_pcm_hw_params_get_period_time, ALSA_0.9, ALSA_0.9.0rc4);
8244 OBSOLETE1(snd_pcm_hw_params_get_period_time_min, ALSA_0.9, ALSA_0.9.0rc4);
8245 OBSOLETE1(snd_pcm_hw_params_get_period_time_max, ALSA_0.9, ALSA_0.9.0rc4);
8246 OBSOLETE1(snd_pcm_hw_params_set_period_time_near, ALSA_0.9, ALSA_0.9.0rc4);
8247 OBSOLETE1(snd_pcm_hw_params_set_period_time_first, ALSA_0.9, ALSA_0.9.0rc4);
8248 OBSOLETE1(snd_pcm_hw_params_set_period_time_last, ALSA_0.9, ALSA_0.9.0rc4);
8250 OBSOLETE1(snd_pcm_hw_params_get_period_size, ALSA_0.9, ALSA_0.9.0rc4);
8251 OBSOLETE1(snd_pcm_hw_params_get_period_size_min, ALSA_0.9, ALSA_0.9.0rc4);
8252 OBSOLETE1(snd_pcm_hw_params_get_period_size_max, ALSA_0.9, ALSA_0.9.0rc4);
8253 OBSOLETE1(snd_pcm_hw_params_set_period_size_near, ALSA_0.9, ALSA_0.9.0rc4);
8254 OBSOLETE1(snd_pcm_hw_params_set_period_size_first, ALSA_0.9, ALSA_0.9.0rc4);
8255 OBSOLETE1(snd_pcm_hw_params_set_period_size_last, ALSA_0.9, ALSA_0.9.0rc4);
8257 OBSOLETE1(snd_pcm_hw_params_get_periods, ALSA_0.9, ALSA_0.9.0rc4);
8258 OBSOLETE1(snd_pcm_hw_params_get_periods_min, ALSA_0.9, ALSA_0.9.0rc4);
8259 OBSOLETE1(snd_pcm_hw_params_get_periods_max, ALSA_0.9, ALSA_0.9.0rc4);
8260 OBSOLETE1(snd_pcm_hw_params_set_periods_near, ALSA_0.9, ALSA_0.9.0rc4);
8261 OBSOLETE1(snd_pcm_hw_params_set_periods_first, ALSA_0.9, ALSA_0.9.0rc4);
8262 OBSOLETE1(snd_pcm_hw_params_set_periods_last, ALSA_0.9, ALSA_0.9.0rc4);
8264 OBSOLETE1(snd_pcm_hw_params_get_buffer_time, ALSA_0.9, ALSA_0.9.0rc4);
8265 OBSOLETE1(snd_pcm_hw_params_get_buffer_time_min, ALSA_0.9, ALSA_0.9.0rc4);
8266 OBSOLETE1(snd_pcm_hw_params_get_buffer_time_max, ALSA_0.9, ALSA_0.9.0rc4);
8267 OBSOLETE1(snd_pcm_hw_params_set_buffer_time_near, ALSA_0.9, ALSA_0.9.0rc4);
8268 OBSOLETE1(snd_pcm_hw_params_set_buffer_time_first, ALSA_0.9, ALSA_0.9.0rc4);
8269 OBSOLETE1(snd_pcm_hw_params_set_buffer_time_last, ALSA_0.9, ALSA_0.9.0rc4);
8271 OBSOLETE1(snd_pcm_hw_params_get_buffer_size, ALSA_0.9, ALSA_0.9.0rc4);
8272 OBSOLETE1(snd_pcm_hw_params_get_buffer_size_min, ALSA_0.9, ALSA_0.9.0rc4);
8273 OBSOLETE1(snd_pcm_hw_params_get_buffer_size_max, ALSA_0.9, ALSA_0.9.0rc4);
8274 OBSOLETE1(snd_pcm_hw_params_set_buffer_size_near, ALSA_0.9, ALSA_0.9.0rc4);
8275 OBSOLETE1(snd_pcm_hw_params_set_buffer_size_first, ALSA_0.9, ALSA_0.9.0rc4);
8276 OBSOLETE1(snd_pcm_hw_params_set_buffer_size_last, ALSA_0.9, ALSA_0.9.0rc4);
8278 OBSOLETE1(snd_pcm_hw_params_get_tick_time, ALSA_0.9, ALSA_0.9.0rc4);
8279 OBSOLETE1(snd_pcm_hw_params_get_tick_time_min, ALSA_0.9, ALSA_0.9.0rc4);
8280 OBSOLETE1(snd_pcm_hw_params_get_tick_time_max, ALSA_0.9, ALSA_0.9.0rc4);
8281 OBSOLETE1(snd_pcm_hw_params_set_tick_time_near, ALSA_0.9, ALSA_0.9.0rc4);
8282 OBSOLETE1(snd_pcm_hw_params_set_tick_time_first, ALSA_0.9, ALSA_0.9.0rc4);
8283 OBSOLETE1(snd_pcm_hw_params_set_tick_time_last, ALSA_0.9, ALSA_0.9.0rc4);
8285 OBSOLETE1(snd_pcm_sw_params_get_tstamp_mode, ALSA_0.9, ALSA_0.9.0rc4);
8286 OBSOLETE1(snd_pcm_sw_params_get_sleep_min, ALSA_0.9, ALSA_0.9.0rc4);
8287 OBSOLETE1(snd_pcm_sw_params_get_avail_min, ALSA_0.9, ALSA_0.9.0rc4);
8288 OBSOLETE1(snd_pcm_sw_params_get_xfer_align, ALSA_0.9, ALSA_0.9.0rc4);
8289 OBSOLETE1(snd_pcm_sw_params_get_start_threshold, ALSA_0.9, ALSA_0.9.0rc4);
8290 OBSOLETE1(snd_pcm_sw_params_get_stop_threshold, ALSA_0.9, ALSA_0.9.0rc4);
8291 OBSOLETE1(snd_pcm_sw_params_get_silence_threshold, ALSA_0.9, ALSA_0.9.0rc4);
8292 OBSOLETE1(snd_pcm_sw_params_get_silence_size, ALSA_0.9, ALSA_0.9.0rc4);
8294 #endif /* DOC_HIDDEN */
8296 static int chmap_equal(const snd_pcm_chmap_t *a, const snd_pcm_chmap_t *b)
8298 if (a->channels != b->channels)
8300 return !memcmp(a->pos, b->pos, a->channels * sizeof(a->pos[0]));
8304 * \!brief Query the available channel maps
8305 * \param pcm PCM handle to query
8306 * \return the NULL-terminated array of integer pointers, each of
8307 * which contains the channel map. A channel map is represented by an
8308 * integer array, beginning with the channel map type, followed by the
8309 * number of channels, and the position of each channel. Return NULL
8310 * in case of an error.
8312 * Note: the caller is requested to release the returned value via
8313 * snd_pcm_free_chmaps().
8315 snd_pcm_chmap_query_t **snd_pcm_query_chmaps(snd_pcm_t *pcm)
8317 if (!pcm->ops->query_chmaps)
8319 return pcm->ops->query_chmaps(pcm);
8323 * \!brief Release the channel map array allocated via #snd_pcm_query_chmaps
8324 * \param maps the array pointer to release
8326 void snd_pcm_free_chmaps(snd_pcm_chmap_query_t **maps)
8328 snd_pcm_chmap_query_t **p;
8331 for (p = maps; *p; p++)
8337 * \!brief Get the current channel map
8338 * \param pcm PCM instance
8339 * \return the current channel map, or NULL if error
8341 * Note: the caller is requested to release the returned value via free()
8343 snd_pcm_chmap_t *snd_pcm_get_chmap(snd_pcm_t *pcm)
8345 if (!pcm->ops->get_chmap)
8347 return pcm->ops->get_chmap(pcm);
8351 * \!brief Configure the current channel map
8352 * \param pcm PCM instance
8353 * \param map the channel map to write
8354 * \return zero if succeeded, or a negative error code
8356 int snd_pcm_set_chmap(snd_pcm_t *pcm, const snd_pcm_chmap_t *map)
8358 const snd_pcm_chmap_t *oldmap;
8361 oldmap = snd_pcm_get_chmap(pcm);
8362 nochange = (oldmap && chmap_equal(oldmap, map));
8363 free((void *)oldmap);
8367 if (!pcm->ops->set_chmap)
8369 return pcm->ops->set_chmap(pcm, map);
8375 #define _NAME(n) [SND_CHMAP_TYPE_##n] = #n
8376 static const char *chmap_type_names[SND_CHMAP_TYPE_LAST + 1] = {
8377 _NAME(NONE), _NAME(FIXED), _NAME(VAR), _NAME(PAIRED),
8383 * \!brief Get a name string for a channel map type as query results
8384 * \param val Channel position
8385 * \return The string corresponding to the given type, or NULL
8387 const char *snd_pcm_chmap_type_name(enum snd_pcm_chmap_type val)
8389 if (val <= SND_CHMAP_TYPE_LAST)
8390 return chmap_type_names[val];
8396 #define _NAME(n) [SND_CHMAP_##n] = #n
8397 static const char *chmap_names[SND_CHMAP_LAST + 1] = {
8398 _NAME(UNKNOWN), _NAME(NA), _NAME(MONO),
8399 _NAME(FL), _NAME(FR),
8400 _NAME(RL), _NAME(RR),
8401 _NAME(FC), _NAME(LFE),
8402 _NAME(SL), _NAME(SR),
8403 _NAME(RC), _NAME(FLC), _NAME(FRC), _NAME(RLC), _NAME(RRC),
8404 _NAME(FLW), _NAME(FRW),
8405 _NAME(FLH), _NAME(FCH), _NAME(FRH), _NAME(TC),
8406 _NAME(TFL), _NAME(TFR), _NAME(TFC),
8407 _NAME(TRL), _NAME(TRR), _NAME(TRC),
8408 _NAME(TFLC), _NAME(TFRC), _NAME(TSL), _NAME(TSR),
8409 _NAME(LLFE), _NAME(RLFE),
8410 _NAME(BC), _NAME(BLC), _NAME(BRC),
8416 * \!brief Get a name string for a standard channel map position
8417 * \param val Channel position
8418 * \return The string corresponding to the given position, or NULL
8420 const char *snd_pcm_chmap_name(enum snd_pcm_chmap_position val)
8422 if (val <= SND_CHMAP_LAST)
8423 return chmap_names[val];
8428 static const char *chmap_long_names[SND_CHMAP_LAST + 1] = {
8429 [SND_CHMAP_UNKNOWN] = "Unknown",
8430 [SND_CHMAP_NA] = "Unused",
8431 [SND_CHMAP_MONO] = "Mono",
8432 [SND_CHMAP_FL] = "Front Left",
8433 [SND_CHMAP_FR] = "Front Right",
8434 [SND_CHMAP_RL] = "Rear Left",
8435 [SND_CHMAP_RR] = "Rear Right",
8436 [SND_CHMAP_FC] = "Front Center",
8437 [SND_CHMAP_LFE] = "LFE",
8438 [SND_CHMAP_SL] = "Side Left",
8439 [SND_CHMAP_SR] = "Side Right",
8440 [SND_CHMAP_RC] = "Rear Center",
8441 [SND_CHMAP_FLC] = "Front Left Center",
8442 [SND_CHMAP_FRC] = "Front Right Center",
8443 [SND_CHMAP_RLC] = "Rear Left Center",
8444 [SND_CHMAP_RRC] = "Rear Right Center",
8445 [SND_CHMAP_FLW] = "Front Left Wide",
8446 [SND_CHMAP_FRW] = "Front Right Wide",
8447 [SND_CHMAP_FLH] = "Front Left High",
8448 [SND_CHMAP_FCH] = "Front Center High",
8449 [SND_CHMAP_FRH] = "Front Right High",
8450 [SND_CHMAP_TC] = "Top Center",
8451 [SND_CHMAP_TFL] = "Top Front Left",
8452 [SND_CHMAP_TFR] = "Top Front Right",
8453 [SND_CHMAP_TFC] = "Top Front Center",
8454 [SND_CHMAP_TRL] = "Top Rear Left",
8455 [SND_CHMAP_TRR] = "Top Rear Right",
8456 [SND_CHMAP_TRC] = "Top Rear Center",
8457 [SND_CHMAP_TFLC] = "Top Front Left Center",
8458 [SND_CHMAP_TFRC] = "Top Front Right Center",
8459 [SND_CHMAP_TSL] = "Top Side Left",
8460 [SND_CHMAP_TSR] = "Top Side Right",
8461 [SND_CHMAP_LLFE] = "Left LFE",
8462 [SND_CHMAP_RLFE] = "Right LFE",
8463 [SND_CHMAP_BC] = "Bottom Center",
8464 [SND_CHMAP_BLC] = "Bottom Left Center",
8465 [SND_CHMAP_BRC] = "Bottom Right Center",
8469 * \!brief Get a longer name string for a standard channel map position
8470 * \param val Channel position
8471 * \return The string corresponding to the given position, or NULL
8473 const char *snd_pcm_chmap_long_name(enum snd_pcm_chmap_position val)
8475 if (val <= SND_CHMAP_LAST)
8476 return chmap_long_names[val];
8482 * \!brief Print the channels in chmap on the buffer
8483 * \param map The channel map to print
8484 * \param maxlen The maximal length to write (including NUL letter)
8485 * \param buf The buffer to write
8486 * \return The actual string length or a negative error code
8488 int snd_pcm_chmap_print(const snd_pcm_chmap_t *map, size_t maxlen, char *buf)
8490 unsigned int i, len = 0;
8492 for (i = 0; i < map->channels; i++) {
8493 unsigned int p = map->pos[i] & SND_CHMAP_POSITION_MASK;
8495 len += snprintf(buf + len, maxlen - len, " ");
8499 if (map->pos[i] & SND_CHMAP_DRIVER_SPEC)
8500 len += snprintf(buf + len, maxlen - len, "%d", p);
8502 const char *name = chmap_names[p];
8504 len += snprintf(buf + len, maxlen - len,
8507 len += snprintf(buf + len, maxlen - len,
8512 if (map->pos[i] & SND_CHMAP_PHASE_INVERSE) {
8513 len += snprintf(buf + len, maxlen - len, "[INV]");
8521 static int str_to_chmap(const char *str, int len)
8527 if (isdigit(*str)) {
8528 v = strtoul(str, &p, 0);
8532 val |= SND_CHMAP_DRIVER_SPEC;
8534 } else if (!strncasecmp(str, "ch", 2)) {
8535 v = strtoul(str + 2, &p, 0);
8541 for (val = 0; val <= SND_CHMAP_LAST; val++) {
8543 assert(chmap_names[val]);
8544 slen = strlen(chmap_names[val]);
8547 if (!strncasecmp(str, chmap_names[val], slen) &&
8548 !isalpha(str[slen])) {
8553 if (val > SND_CHMAP_LAST)
8556 if (str && !strncasecmp(str, "[INV]", 5))
8557 val |= SND_CHMAP_PHASE_INVERSE;
8562 * \!brief Convert from string to channel position
8563 * \param str The string to parse
8564 * \return The channel position value or -1 as an error
8566 unsigned int snd_pcm_chmap_from_string(const char *str)
8568 return str_to_chmap(str, strlen(str));
8572 * \!brief Convert from string to channel map
8573 * \param str The string to parse
8574 * \return The channel map
8576 * Note: the caller is requested to release the returned value via free()
8578 snd_pcm_chmap_t *snd_pcm_chmap_parse_string(const char *str)
8582 snd_pcm_chmap_t *map;
8588 if (ch >= (int)(sizeof(tmp_map) / sizeof(tmp_map[0])))
8590 for (p = str; *p && isalnum(*p); p++)
8595 val = str_to_chmap(str, len);
8600 if (!strncmp(str, "[INV]", 5)) {
8601 val |= SND_CHMAP_PHASE_INVERSE;
8607 for (; *str && !isalnum(*str); str++)
8612 map = malloc(sizeof(*map) + ch * sizeof(int));
8616 for (i = 0; i < ch; i++)
8617 map->pos[i] = tmp_map[i];
8621 /* copy a single channel map with the fixed type to chmap_query pointer */
8622 static int _copy_to_fixed_query_map(snd_pcm_chmap_query_t **dst,
8623 const snd_pcm_chmap_t *src)
8625 *dst = malloc((src->channels + 2) * sizeof(int));
8628 (*dst)->type = SND_CHMAP_TYPE_FIXED;
8629 memcpy(&(*dst)->map, src, (src->channels + 1) * sizeof(int));
8634 /* make a chmap_query array from a single channel map */
8635 snd_pcm_chmap_query_t **
8636 _snd_pcm_make_single_query_chmaps(const snd_pcm_chmap_t *src)
8638 snd_pcm_chmap_query_t **maps;
8640 maps = calloc(2, sizeof(*maps));
8643 if (_copy_to_fixed_query_map(maps, src)) {
8650 /* make a copy of chmap */
8651 snd_pcm_chmap_t *_snd_pcm_copy_chmap(const snd_pcm_chmap_t *src)
8653 snd_pcm_chmap_t *map;
8655 map = malloc((src->channels + 1) * sizeof(int));
8658 memcpy(map, src, (src->channels + 1) * sizeof(int));
8662 /* make a copy of channel maps */
8663 snd_pcm_chmap_query_t **
8664 _snd_pcm_copy_chmap_query(snd_pcm_chmap_query_t * const *src)
8666 snd_pcm_chmap_query_t * const *p;
8667 snd_pcm_chmap_query_t **maps;
8670 for (nums = 0, p = src; *p; p++)
8673 maps = calloc(nums + 1, sizeof(*maps));
8676 for (i = 0; i < nums; i++) {
8677 maps[i] = malloc((src[i]->map.channels + 2) * sizeof(int));
8679 snd_pcm_free_chmaps(maps);
8682 memcpy(maps[i], src[i], (src[i]->map.channels + 2) * sizeof(int));
8687 /* select the channel map with the current PCM channels and make a copy */
8689 _snd_pcm_choose_fixed_chmap(snd_pcm_t *pcm, snd_pcm_chmap_query_t * const *maps)
8691 snd_pcm_chmap_query_t * const *p;
8693 for (p = maps; *p; p++) {
8694 if ((*p)->map.channels == pcm->channels)
8695 return _snd_pcm_copy_chmap(&(*p)->map);
8700 /* make chmap_query array from the config tree;
8701 * conf must be a compound (array)
8703 snd_pcm_chmap_query_t **
8704 _snd_pcm_parse_config_chmaps(snd_config_t *conf)
8706 snd_pcm_chmap_t *chmap;
8707 snd_pcm_chmap_query_t **maps;
8708 snd_config_iterator_t i, next;
8712 if (snd_config_get_type(conf) != SND_CONFIG_TYPE_COMPOUND)
8716 snd_config_for_each(i, next, conf) {
8720 maps = calloc(nums + 1, sizeof(*maps));
8725 snd_config_for_each(i, next, conf) {
8726 snd_config_t *n = snd_config_iterator_entry(i);
8727 err = snd_config_get_string(n, &str);
8730 chmap = snd_pcm_chmap_parse_string(str);
8733 if (_copy_to_fixed_query_map(maps + nums, chmap)) {
8743 snd_pcm_free_chmaps(maps);
8746 #endif /* DOC_HIDDEN */
8754 * \brief Recover the stream state from an error or suspend
8755 * \param pcm PCM handle
8756 * \param err error number
8757 * \param silent do not print error reason
8758 * \return 0 when error code was handled successfuly, otherwise a negative error code
8760 * This a high-level helper function building on other functions.
8762 * This functions handles -EINTR (interrupted system call),
8763 * -EPIPE (overrun or underrun) and -ESTRPIPE (stream is suspended)
8764 * error codes trying to prepare given stream for next I/O.
8766 * Note that this function returns the original error code when it is not
8767 * handled inside this function (for example -EAGAIN is returned back).
8769 int snd_pcm_recover(snd_pcm_t *pcm, int err, int silent)
8773 if (err == -EINTR) /* nothing to do, continue */
8775 if (err == -EPIPE) {
8777 if (snd_pcm_stream(pcm) == SND_PCM_STREAM_PLAYBACK)
8782 SNDERR("%s occurred", s);
8783 err = snd_pcm_prepare(pcm);
8785 SNDERR("cannot recovery from %s, prepare failed: %s", s, snd_strerror(err));
8790 if (err == -ESTRPIPE) {
8791 while ((err = snd_pcm_resume(pcm)) == -EAGAIN)
8792 /* wait until suspend flag is released */
8793 poll(NULL, 0, 1000);
8795 err = snd_pcm_prepare(pcm);
8797 SNDERR("cannot recovery from suspend, prepare failed: %s", snd_strerror(err));
8807 * \brief Set the hardware and software parameters in a simple way
8808 * \param pcm PCM handle
8809 * \param format required PCM format
8810 * \param access required PCM access
8811 * \param channels required PCM channels
8812 * \param rate required sample rate in Hz
8813 * \param soft_resample 0 = disallow alsa-lib resample stream, 1 = allow resampling
8814 * \param latency required overall latency in us
8815 * \return 0 on success otherwise a negative error code
8817 int snd_pcm_set_params(snd_pcm_t *pcm,
8818 snd_pcm_format_t format,
8819 snd_pcm_access_t access,
8820 unsigned int channels,
8823 unsigned int latency)
8825 snd_pcm_hw_params_t params_saved, params = {0};
8826 snd_pcm_sw_params_t swparams = {0};
8827 const char *s = snd_pcm_stream_name(snd_pcm_stream(pcm));
8828 snd_pcm_uframes_t buffer_size, period_size;
8829 unsigned int rrate, period_time;
8833 /* choose all parameters */
8834 err = snd_pcm_hw_params_any(pcm, ¶ms);
8836 SNDERR("Broken configuration for %s: no configurations available",
8840 /* set software resampling */
8841 err = snd_pcm_hw_params_set_rate_resample(pcm, ¶ms, soft_resample);
8843 SNDERR("Resampling setup failed for %s: %s",
8844 s, snd_strerror(err));
8847 /* set the selected read/write format */
8848 err = snd_pcm_hw_params_set_access(pcm, ¶ms, access);
8850 SNDERR("Access type not available for %s: %s",
8851 s, snd_strerror(err));
8854 /* set the sample format */
8855 err = snd_pcm_hw_params_set_format(pcm, ¶ms, format);
8857 SNDERR("Sample format not available for %s: %s",
8858 s, snd_strerror(err));
8861 /* set the count of channels */
8862 err = snd_pcm_hw_params_set_channels(pcm, ¶ms, channels);
8864 SNDERR("Channels count (%i) not available for %s: %s",
8865 channels, s, snd_strerror(err));
8868 /* set the stream rate */
8870 err = INTERNAL(snd_pcm_hw_params_set_rate_near)(pcm, ¶ms, &rrate,
8873 SNDERR("Rate %iHz not available for playback: %s",
8874 rate, snd_strerror(err));
8877 if (rrate != rate) {
8878 SNDERR("Rate doesn't match (requested %iHz, get %iHz)",
8882 /* set the buffer time */
8883 params_saved = params;
8884 err = INTERNAL(snd_pcm_hw_params_set_buffer_time_near)(pcm, ¶ms,
8887 /* error path -> set period size as first */
8888 params = params_saved;
8889 /* set the period time */
8890 period_time = latency / 4;
8891 err = INTERNAL(snd_pcm_hw_params_set_period_time_near)(pcm,
8892 ¶ms, &period_time, NULL);
8894 SNDERR("Unable to set period time %i for %s: %s",
8895 period_time, s, snd_strerror(err));
8898 err = INTERNAL(snd_pcm_hw_params_get_period_size)(¶ms,
8899 &period_size, NULL);
8901 SNDERR("Unable to get period size for %s: %s",
8902 s, snd_strerror(err));
8905 buffer_size = period_size * 4;
8906 err = INTERNAL(snd_pcm_hw_params_set_buffer_size_near)(pcm,
8907 ¶ms, &buffer_size);
8909 SNDERR("Unable to set buffer size %lu %s: %s",
8910 buffer_size, s, snd_strerror(err));
8913 err = INTERNAL(snd_pcm_hw_params_get_buffer_size)(¶ms,
8916 SNDERR("Unable to get buffer size for %s: %s",
8917 s, snd_strerror(err));
8921 /* standard configuration buffer_time -> periods */
8922 err = INTERNAL(snd_pcm_hw_params_get_buffer_size)(¶ms,
8925 SNDERR("Unable to get buffer size for %s: %s",
8926 s, snd_strerror(err));
8929 err = INTERNAL(snd_pcm_hw_params_get_buffer_time)(¶ms,
8932 SNDERR("Unable to get buffer time (latency) for %s: %s",
8933 s, snd_strerror(err));
8936 /* set the period time */
8937 period_time = latency / 4;
8938 err = INTERNAL(snd_pcm_hw_params_set_period_time_near)(pcm,
8939 ¶ms, &period_time, NULL);
8941 SNDERR("Unable to set period time %i for %s: %s",
8942 period_time, s, snd_strerror(err));
8945 err = INTERNAL(snd_pcm_hw_params_get_period_size)(¶ms,
8946 &period_size, NULL);
8948 SNDERR("Unable to get period size for %s: %s",
8949 s, snd_strerror(err));
8953 /* write the parameters to device */
8954 err = snd_pcm_hw_params(pcm, ¶ms);
8956 SNDERR("Unable to set hw params for %s: %s",
8957 s, snd_strerror(err));
8961 /* get the current swparams */
8962 err = snd_pcm_sw_params_current(pcm, &swparams);
8964 SNDERR("Unable to determine current swparams for %s: %s",
8965 s, snd_strerror(err));
8969 * start the transfer when the buffer is almost full:
8970 * (buffer_size / avail_min) * avail_min
8972 err = snd_pcm_sw_params_set_start_threshold(pcm, &swparams,
8973 (buffer_size / period_size) * period_size);
8975 SNDERR("Unable to set start threshold mode for %s: %s",
8976 s, snd_strerror(err));
8980 * allow the transfer when at least period_size samples can be
8983 err = snd_pcm_sw_params_set_avail_min(pcm, &swparams, period_size);
8985 SNDERR("Unable to set avail min for %s: %s",
8986 s, snd_strerror(err));
8989 /* write the parameters to the playback device */
8990 err = snd_pcm_sw_params(pcm, &swparams);
8992 SNDERR("Unable to set sw params for %s: %s",
8993 s, snd_strerror(err));
9000 * \brief Get the transfer size parameters in a simple way
9001 * \param pcm PCM handle
9002 * \param buffer_size PCM ring buffer size in frames
9003 * \param period_size PCM period size in frames
9004 * \return 0 on success otherwise a negative error code
9006 int snd_pcm_get_params(snd_pcm_t *pcm,
9007 snd_pcm_uframes_t *buffer_size,
9008 snd_pcm_uframes_t *period_size)
9010 snd_pcm_hw_params_t params = {0};
9014 err = snd_pcm_hw_params_current(pcm, ¶ms);
9017 err = INTERNAL(snd_pcm_hw_params_get_buffer_size)(¶ms, buffer_size);
9020 return INTERNAL(snd_pcm_hw_params_get_period_size)(¶ms, period_size,