5 * \author Jaroslav Kysela <perex@perex.cz>
6 * \author Abramo Bagnara <abramo@alsa-project.org>
9 * PCM Interface is designed to write or read digital audio frames. A
10 * frame is the data unit converted into/from sound in one time unit
11 * (1/rate seconds), by example if you set your playback PCM rate to
12 * 44100 you'll hear 44100 frames per second. The size in bytes of a
13 * frame may be obtained from bits needed to store a sample and
16 * See the \ref pcm page for more details.
19 * PCM Interface - main file
20 * Copyright (c) 1998 by Jaroslav Kysela <perex@perex.cz>
21 * Copyright (c) 2000 by Abramo Bagnara <abramo@alsa-project.org>
23 * This library is free software; you can redistribute it and/or modify
24 * it under the terms of the GNU Lesser General Public License as
25 * published by the Free Software Foundation; either version 2.1 of
26 * the License, or (at your option) any later version.
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU Lesser General Public License for more details.
33 * You should have received a copy of the GNU Lesser General Public
34 * License along with this library; if not, write to the Free Software
35 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
39 /*! \page pcm PCM (digital audio) interface
41 <P>Although abbreviation PCM stands for Pulse Code Modulation, we are
42 understanding it as general digital audio processing with volume samples
43 generated in continuous time periods.</P>
45 <P>The analog signal is recorded via analog to digital converters (ADC).
46 The digital value (de-facto a volume at a specific time) obtained
47 from ADC can be further processed. The following picture shows a perfect
53 <P>Next image shows digitized representation:</P>
58 <P>As you may see, the quality of digital audio signal depends on the time
59 (recording rate) and voltage resolution (usually in an linear integer
60 representation with basic unit one bit).</P>
62 <P>The stored digital signal can be converted back to voltage (analog)
63 representation via digital to analog converters (DAC).</P>
65 <P>One digital value is called sample. More samples are collected to frames
66 (frame is terminology for ALSA) depending on count of converters used at one
67 specific time. One frame might contain one sample (when only one converter is
68 used - mono) or more samples (for example: stereo has signals from two converters
69 recorded at same time). Digital audio stream contains collection of frames
70 recorded at boundaries of continuous time periods.</P>
72 \section pcm_general_overview General overview
74 ALSA uses the ring buffer to store outgoing (playback) and incoming (capture,
75 record) samples. There are two pointers being maintained to allow
76 a precise communication between application and device pointing to current
77 processed sample by hardware and last processed sample by application.
78 The modern audio chips allow to program the transfer time periods.
79 It means that the stream of samples is divided to small chunks. Device
80 acknowledges to application when the transfer of a chunk is complete.
82 \section pcm_transfer Transfer methods in UNIX environments
84 In the UNIX environment, data chunk acknowledges are received via standard I/O
85 calls or event waiting routines (poll or select function). To accomplish
86 this list, the asynchronous notification of acknowledges should be listed
87 here. The ALSA implementation for these methods is described in
88 the \ref alsa_transfers section.
90 \subsection pcm_transfer_io Standard I/O transfers
92 The standard I/O transfers are using the read (see 'man 2 read') and write
93 (see 'man 2 write') C functions. There are two basic behaviours of these
94 functions - blocked and non-blocked (see the O_NONBLOCK flag for the
95 standard C open function - see 'man 2 open'). In non-blocked behaviour,
96 these I/O functions never stops, they return -EAGAIN error code, when no
97 data can be transferred (the ring buffer is full in our case). In blocked
98 behaviour, these I/O functions stop and wait until there is a room in the
99 ring buffer (playback) or until there are a new samples (capture). The ALSA
100 implementation can be found in the \ref alsa_pcm_rw section.
102 \subsection pcm_transfer_event Event waiting routines
104 The poll or select functions (see 'man 2 poll' or 'man 2 select' for further
105 details) allows to receive requests/events from the device while
106 an application is waiting on events from other sources (like keyboard, screen,
107 network etc.), too. \ref snd_pcm_poll_descriptors can be used to get 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.
220 \section alsa_transfers ALSA transfers
222 There are two methods to transfer samples in application. The first method
223 is the standard read / write one. The second method, uses the direct audio
224 buffer to communicate with the device while ALSA library manages this space
225 itself. You can find examples of all communication schemes for playback
226 in \ref example_test_pcm "Sine-wave generator example". To complete the
227 list, we should note that #snd_pcm_wait() function contains
228 embedded poll waiting implementation.
230 \subsection alsa_pcm_rw Read / Write transfer
232 There are two versions of read / write routines. The first expects the
233 interleaved samples at input (#SND_PCM_ACCESS_RW_INTERLEAVED access method),
234 and the second one expects non-interleaved (samples in separated buffers -
235 #SND_PCM_ACCESS_RW_NONINTERLEAVED access method) at input. There are these
236 functions for interleaved transfers: #snd_pcm_writei()
237 #snd_pcm_readi(). For non-interleaved transfers, there are
238 these functions: #snd_pcm_writen() and #snd_pcm_readn().
240 \subsection alsa_mmap_rw Direct Read / Write transfer (via mmap'ed areas)
242 Three kinds of organization of ring buffer memory areas exist in ALSA API.
243 Access #SND_PCM_ACCESS_MMAP_INTERLEAVED has interleaved samples. Access
244 #SND_PCM_ACCESS_MMAP_NONINTERLEAVED expects continous sample areas for
245 one channel. Access #SND_PCM_ACCESS_MMAP_COMPLEX does not fit to interleaved
246 and non-interleaved ring buffer organization.
248 There are two functions for this kind of transfer. Application can get an
249 access to memory areas via #snd_pcm_mmap_begin() function.
250 This function returns the areas (single area is equal to a channel)
251 containing the direct pointers to memory and sample position description
252 in #snd_pcm_channel_area_t structure. After application
253 transfers the data in the memory areas, then it must be acknowledged
254 the end of transfer via #snd_pcm_mmap_commit() function
255 to allow the ALSA library update the pointers to ring buffer. This kind of
256 communication is also called "zero-copy", because the device does not require
257 to copy the samples from application to another place in system memory.
259 If you like to use the compatibility functions in mmap mode, there are
260 read / write routines equaling to standard read / write transfers. Using
261 these functions discards the benefits of direct access to memory region.
262 See the #snd_pcm_mmap_readi(),
263 #snd_pcm_mmap_writei(), #snd_pcm_mmap_readn()
264 and #snd_pcm_mmap_writen() functions. These functions use
265 #snd_pcm_areas_copy() internally.
267 \section pcm_errors Error codes
271 This error means xrun (underrun for playback or overrun for capture).
272 The underrun can happen when an application does not feed new samples
273 in time to alsa-lib (due CPU usage). The overrun can happen when
274 an application does not take new captured samples in time from alsa-lib.
278 This error means that system has suspended drivers. The application
279 should wait in loop when snd_pcm_resume() != -EAGAIN and then
280 call snd_pcm_prepare() when snd_pcm_resume() return an error code.
281 If snd_pcm_resume() does not fail (a zero value is returned), driver
282 supports resume and the snd_pcm_prepare() call can be ommited.
286 This error means that the device is in a bad state. It means that
287 the handskahe between application and alsa-lib is corrupted.
289 \par -ENOTTY, -ENODEV
291 This error can happen when device is physically removed (for example
292 some hotplug devices like USB or PCMCIA, CardBus or ExpressCard
293 can be removed on the fly).
295 \section pcm_params Managing parameters
297 The ALSA PCM device uses two groups of PCM related parameters. The hardware
298 parameters contains the stream description like format, rate, count of
299 channels, ring buffer size etc. The software parameters contains the
300 software (driver) related parameters. The communication behaviour can be
301 controlled via these parameters, like automatic start, automatic stop,
302 interrupting (chunk acknowledge) etc. The software parameters can be
303 modified at any time (when valid hardware parameters are set). It includes
304 the running state as well.
306 \subsection pcm_hw_params Hardware related parameters
308 The ALSA PCM devices use the parameter refining system for hardware
309 parameters - #snd_pcm_hw_params_t. It means, that
310 application choose the full-range of configurations at first and then
311 application sets single parameters until all parameters are elementary
316 ALSA knows about five access modes. The first three can be used for direct
317 communication. The access mode #SND_PCM_ACCESS_MMAP_INTERLEAVED
318 determines the direct memory area and interleaved sample organization.
319 Interleaved organization means, that samples from channels are mixed together.
320 The access mode #SND_PCM_ACCESS_MMAP_NONINTERLEAVED
321 determines the direct memory area and non-interleaved sample organization.
322 Each channel has a separate buffer in the case. The complex direct memory
323 organization represents the #SND_PCM_ACCESS_MMAP_COMPLEX
324 access mode. The sample organization does not fit the interleaved or
325 non-interleaved access modes in the case. The last two access modes
326 describes the read / write access methods.
327 The #SND_PCM_ACCESS_RW_INTERLEAVED access represents the read /
328 write interleaved access and the #SND_PCM_ACCESS_RW_NONINTERLEAVED
329 represents the non-interleaved access.
333 The full list of formats is available in #snd_pcm_format_t
336 \subsection pcm_sw_params Software related parameters
338 These parameters - #snd_pcm_sw_params_t can be modified at
339 any time including the running state.
341 \par Minimum available count of samples
343 This parameter controls the wakeup point. If the count of available samples
344 is equal or greater than this value, then application will be activated.
348 The timestamp mode specifies, if timestamps are activated. Currently, only
349 #SND_PCM_TSTAMP_NONE and #SND_PCM_TSTAMP_MMAP
350 modes are known. The mmap mode means that timestamp is taken
351 on every period time boundary. Corresponding position in the ring buffer
352 assigned to timestamp can be obtained using #snd_pcm_htimestamp() function.
356 The read / write transfers can be aligned to this sample count. The modulo
357 is ignored by device. Usually, this value is set to one (no align).
361 The start threshold parameter is used to determine the start point in
362 stream. For playback, if samples in ring buffer is equal or greater than
363 the start threshold parameters and the stream is not running, the stream will
364 be started automatically from the device. For capture, if the application wants
365 to read count of samples equal or greater then the stream will be started.
366 If you want to use explicit start (#snd_pcm_start), you can
367 set this value greater than ring buffer size (in samples), but use the
368 constant MAXINT is not a bad idea.
372 Similarly, the stop threshold parameter is used to automatically stop
373 the running stream, when the available samples crosses this boundary.
374 It means, for playback, the empty samples in ring buffer and for capture,
375 the filled (used) samples in ring buffer.
377 \par Silence threshold
379 The silence threshold specifies count of samples filled with silence
380 ahead of the current application pointer for playback. It is usable
381 for applications when an overrun is possible (like tasks depending on
382 network I/O etc.). If application wants to manage the ahead samples itself,
383 the #snd_pcm_rewind() function allows to forget the last
384 samples in the stream.
386 \section pcm_status Obtaining stream status
388 The stream status is stored in #snd_pcm_status_t structure.
389 These parameters can be obtained: the current stream state -
390 #snd_pcm_status_get_state(), timestamp of trigger -
391 #snd_pcm_status_get_trigger_tstamp(), timestamp of last
392 pointer update #snd_pcm_status_get_tstamp(), delay in samples -
393 #snd_pcm_status_get_delay(), available count in samples -
394 #snd_pcm_status_get_avail(), maximum available samples -
395 #snd_pcm_status_get_avail_max(), ADC over-range count in
396 samples - #snd_pcm_status_get_overrange(). The last two
397 parameters - avail_max and overrange are reset to zero after the status
400 \subsection pcm_status_fast Obtaining stream state fast and update r/w pointer
403 The function #snd_pcm_avail_update() updates the current
404 available count of samples for writing (playback) or filled samples for
405 reading (capture). This call is mandatory for updating actual r/w pointer.
406 Using standalone, it is a light method to obtain current stream position,
407 because it does not require the user <-> kernel context switch, but the value
408 is less accurate, because ring buffer pointers are updated in kernel drivers
409 only when an interrupt occurs. If you want to get accurate stream state,
410 use functions #snd_pcm_avail(), #snd_pcm_delay() or #snd_pcm_avail_delay().
413 The function #snd_pcm_avail() reads the current hardware pointer
414 in the ring buffer from hardware and calls #snd_pcm_avail_update() then.
417 The function #snd_pcm_delay() returns the delay in samples.
418 For playback, it means count of samples in the ring buffer before
419 the next sample will be sent to DAC. For capture, it means count of samples
420 in the ring buffer before the next sample will be captured from ADC. It works
421 only when the stream is in the running or draining (playback only) state.
422 Note that this function does not update the current r/w pointer for applications,
423 so the function #snd_pcm_avail_update() must be called afterwards
424 before any read/write begin+commit operations.
427 The function #snd_pcm_avail_delay() combines #snd_pcm_avail() and
428 #snd_pcm_delay() and returns both values in sync.
431 \section pcm_action Managing the stream state
433 The following functions directly and indirectly affect the stream state:
435 \par snd_pcm_hw_params
436 The #snd_pcm_hw_params() function brings the stream state
437 to #SND_PCM_STATE_SETUP
438 if successfully finishes, otherwise the state #SND_PCM_STATE_OPEN
440 When it is brought to SETUP state, this function automatically
441 calls #snd_pcm_prepare() function to bring to the PREPARED state
445 The #snd_pcm_prepare() function enters from #SND_PCM_STATE_SETUP
446 to the #SND_PCM_STATE_PREPARED after a successful finish.
449 The #snd_pcm_start() function enters
450 the #SND_PCM_STATE_RUNNING after a successful finish.
453 The #snd_pcm_drop() function enters the
454 #SND_PCM_STATE_SETUP state.
457 The #snd_pcm_drain() function enters the
458 #SND_PCM_STATE_DRAINING, if
459 the capture device has some samples in the ring buffer otherwise
460 #SND_PCM_STATE_SETUP state is entered.
463 The #snd_pcm_pause() function enters the
464 #SND_PCM_STATE_PAUSED or #SND_PCM_STATE_RUNNING.
466 \par snd_pcm_writei, snd_pcm_writen
467 The #snd_pcm_writei() and #snd_pcm_writen()
468 functions can conditionally start the stream -
469 #SND_PCM_STATE_RUNNING. They depend on the start threshold
472 \par snd_pcm_readi, snd_pcm_readn
473 The #snd_pcm_readi() and #snd_pcm_readn()
474 functions can conditionally start the stream -
475 #SND_PCM_STATE_RUNNING. They depend on the start threshold
478 \section pcm_sync Streams synchronization
480 There are two functions allowing link multiple streams together. In the
481 case, the linking means that all operations are synchronized. Because the
482 drivers cannot guarantee the synchronization (sample resolution) on hardware
483 lacking this feature, the #snd_pcm_info_get_sync() function
484 returns synchronization ID - #snd_pcm_sync_id_t, which is equal
485 for hardware synchronized streams. When the #snd_pcm_link()
486 function is called, all operations managing the stream state for these two
487 streams are joined. The opposite function is #snd_pcm_unlink().
489 \section pcm_thread_safety Thread-safety
491 When the library is configured with the proper option, some PCM functions
492 (e.g. #snd_pcm_avail_update()) are thread-safe and can be called concurrently
493 from multiple threads. Meanwhile, some functions (e.g. #snd_pcm_hw_params())
494 aren't thread-safe, and application needs to call them carefully when they
495 are called from multiple threads. In general, all the functions that are
496 often called during streaming are covered as thread-safe.
498 This thread-safe behavior can be disabled also by passing 0 to the environment
499 variable LIBASOUND_THREAD_SAFE, e.g.
501 LIBASOUND_THREAD_SAFE=0 aplay foo.wav
503 for making the debugging easier.
505 \section pcm_dev_names PCM naming conventions
507 The ALSA library uses a generic string representation for names of devices.
508 The devices might be virtual, physical or a mix of both. The generic string
509 is passed to #snd_pcm_open() or #snd_pcm_open_lconf().
510 It contains two parts: device name and arguments. Devices and arguments are described
511 in configuration files. The usual place for default definitions is at /usr/share/alsa/alsa.conf.
512 For detailed descriptions about integrated PCM plugins look to \ref pcm_plugins.
514 \subsection pcm_dev_names_default Default device
516 The default device is equal to plug plugin with hw plugin as slave. The defaults are
521 defaults.pcm.device 0
522 defaults.pcm.subdevice -1
525 These defaults can be freely overwritten in local configuration files.
533 \subsection pcm_dev_names_hw HW device
535 The hw device description uses the hw plugin. The three arguments (in order: CARD,DEV,SUBDEV)
536 specify card number or identifier, device number and subdevice number (-1 means any).
546 hw:DEV=1,CARD=soundwave,SUBDEV=2
549 \subsection pcm_dev_names_plughw Plug->HW device
551 The plughw device description uses the plug plugin and hw plugin as slave. The arguments
552 are same as for hw device.
562 plughw:DEV=1,CARD=soundwave,SUBDEV=2
565 \subsection pcm_dev_names_plug Plug device
567 The plug device uses the plug plugin. The one SLAVE argument specifies the slave plugin.
578 \subsection pcm_dev_names_shm Shared memory device
580 The shm device uses the shm plugin. The two arguments (in order: SOCKET,PCM) specify
581 UNIX socket name (for example /tmp/alsa.socket) for server communication and server's PCM name.
586 shm:'/tmp/alsa.sock',default
587 shm:SOCKET='/tmp/alsa.sock',PCM=default
590 \subsection pcm_dev_names_tee Tee device
592 The tee device stores contents of a stream to given file plus transfers it to given slave plugin.
593 The three arguments (in order: SLAVE,FILE,FORMAT) specify slave plugin, filename and file format.
598 tee:hw,'/tmp/out.raw',raw
601 \subsection pcm_dev_names_file File device
603 The file device is file plugin with null plugin as slave. The arguments (in order: FILE,FORMAT)
604 specify filename and file format.
609 file:'/tmp/out.raw',raw
612 \subsection pcm_dev_names_null Null device
614 The null device is null plugin. This device has not any arguments.
617 \section pcm_examples Examples
619 The full featured examples with cross-links can be found in Examples section
622 \anchor example_test_pcm
623 \par Sine-wave generator
625 alsa-lib/test/pcm.c example shows various transfer methods for the playback direction.
627 \par Minimalistic PCM playback code
629 alsa-lib/test/pcm_min.c example shows the minimal code to produce a sound.
631 \par Latency measuring tool
633 alsa-lib/test/latency.c example shows the measuring of minimal latency between capture and
639 \example ../../test/pcm.c
642 \example ../../test/pcm_min.c
645 \example ../../test/latency.c
654 #include <sys/poll.h>
655 #include <sys/mman.h>
657 #include "pcm_local.h"
660 #define P_STATE(x) (1U << SND_PCM_STATE_ ## x)
661 #define P_STATE_RUNNABLE (P_STATE(PREPARED) | \
667 /* check whether the PCM is in the unexpected state */
668 static int bad_pcm_state(snd_pcm_t *pcm, unsigned int supported_states)
670 if (pcm->own_state_check)
671 return 0; /* don't care, the plugin checks by itself */
672 return !(supported_states & (1U << snd_pcm_state(pcm)));
677 * \brief get identifier of PCM handle
678 * \param pcm PCM handle
679 * \return ascii identifier of PCM handle
681 * Returns the ASCII identifier of given PCM handle. It's the same
682 * identifier specified in snd_pcm_open().
684 const char *snd_pcm_name(snd_pcm_t *pcm)
691 * \brief get type of PCM handle
692 * \param pcm PCM handle
693 * \return type of PCM handle
695 * Returns the type #snd_pcm_type_t of given PCM handle.
697 snd_pcm_type_t snd_pcm_type(snd_pcm_t *pcm)
704 * \brief get stream for a PCM handle
705 * \param pcm PCM handle
706 * \return stream of PCM handle
708 * Returns the type #snd_pcm_stream_t of given PCM handle.
710 snd_pcm_stream_t snd_pcm_stream(snd_pcm_t *pcm)
717 * \brief close PCM handle
718 * \param pcm PCM handle
719 * \return 0 on success otherwise a negative error code
721 * Closes the specified PCM handle and frees all associated
724 int snd_pcm_close(snd_pcm_t *pcm)
728 if (pcm->setup && !pcm->donot_close) {
730 err = snd_pcm_hw_free(pcm);
734 if (pcm->mmap_channels)
736 while (!list_empty(&pcm->async_handlers)) {
737 snd_async_handler_t *h = list_entry(pcm->async_handlers.next, snd_async_handler_t, hlist);
738 snd_async_del_handler(h);
740 err = pcm->ops->close(pcm->op_arg);
743 err = snd_pcm_free(pcm);
750 * \brief set nonblock mode
751 * \param pcm PCM handle
752 * \param nonblock 0 = block, 1 = nonblock mode, 2 = abort
753 * \return 0 on success otherwise a negative error code
755 * The function is thread-safe when built with the proper option.
757 int snd_pcm_nonblock(snd_pcm_t *pcm, int nonblock)
762 /* FIXME: __snd_pcm_lock() call below is commented out because of the
763 * the possible deadlock in signal handler calling snd_pcm_abort()
765 /* __snd_pcm_lock(pcm); */ /* forced lock due to pcm field change */
766 if ((err = pcm->ops->nonblock(pcm->op_arg, nonblock)) < 0)
769 pcm->mode |= SND_PCM_ABORT;
773 pcm->mode |= SND_PCM_NONBLOCK;
775 if (pcm->hw_flags & SND_PCM_HW_PARAMS_NO_PERIOD_WAKEUP)
778 pcm->mode &= ~SND_PCM_NONBLOCK;
781 /* __snd_pcm_unlock(pcm); */ /* FIXME: see above */
787 * \brief set async mode
788 * \param pcm PCM handle
789 * \param sig Signal to raise: < 0 disable, 0 default (SIGIO)
790 * \param pid Process ID to signal: 0 current
791 * \return 0 on success otherwise a negative error code
793 * A signal is raised every period.
795 int snd_pcm_async(snd_pcm_t *pcm, int sig, pid_t pid)
802 /* async handler may lead to a deadlock; suppose no multi thread */
803 pcm->lock_enabled = 0;
804 return pcm->ops->async(pcm->op_arg, sig, pid);
809 * \brief Obtain general (static) information for PCM handle
810 * \param pcm PCM handle
811 * \param info Information container
812 * \return 0 on success otherwise a negative error code
814 int snd_pcm_info(snd_pcm_t *pcm, snd_pcm_info_t *info)
817 return pcm->ops->info(pcm->op_arg, info);
820 /** \brief Retreive current PCM hardware configuration chosen with #snd_pcm_hw_params
821 * \param pcm PCM handle
822 * \param params Configuration space definition container
823 * \return 0 on success otherwise a negative error code
825 int snd_pcm_hw_params_current(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
827 unsigned int frame_bits;
829 assert(pcm && params);
832 memset(params, 0, snd_pcm_hw_params_sizeof());
833 params->flags = pcm->hw_flags;
834 snd_mask_set(¶ms->masks[SND_PCM_HW_PARAM_ACCESS - SND_PCM_HW_PARAM_FIRST_MASK], pcm->access);
835 snd_mask_set(¶ms->masks[SND_PCM_HW_PARAM_FORMAT - SND_PCM_HW_PARAM_FIRST_MASK], pcm->format);
836 snd_mask_set(¶ms->masks[SND_PCM_HW_PARAM_SUBFORMAT - SND_PCM_HW_PARAM_FIRST_MASK], pcm->subformat);
837 frame_bits = snd_pcm_format_physical_width(pcm->format) * pcm->channels;
838 snd_interval_set_value(¶ms->intervals[SND_PCM_HW_PARAM_FRAME_BITS - SND_PCM_HW_PARAM_FIRST_INTERVAL], frame_bits);
839 snd_interval_set_value(¶ms->intervals[SND_PCM_HW_PARAM_CHANNELS - SND_PCM_HW_PARAM_FIRST_INTERVAL], pcm->channels);
840 snd_interval_set_value(¶ms->intervals[SND_PCM_HW_PARAM_RATE - SND_PCM_HW_PARAM_FIRST_INTERVAL], pcm->rate);
841 snd_interval_set_value(¶ms->intervals[SND_PCM_HW_PARAM_PERIOD_TIME - SND_PCM_HW_PARAM_FIRST_INTERVAL], pcm->period_time);
842 snd_interval_set_value(¶ms->intervals[SND_PCM_HW_PARAM_PERIOD_SIZE - SND_PCM_HW_PARAM_FIRST_INTERVAL], pcm->period_size);
843 snd_interval_copy(¶ms->intervals[SND_PCM_HW_PARAM_PERIODS - SND_PCM_HW_PARAM_FIRST_INTERVAL], &pcm->periods);
844 snd_interval_copy(¶ms->intervals[SND_PCM_HW_PARAM_BUFFER_TIME - SND_PCM_HW_PARAM_FIRST_INTERVAL], &pcm->buffer_time);
845 snd_interval_set_value(¶ms->intervals[SND_PCM_HW_PARAM_BUFFER_SIZE - SND_PCM_HW_PARAM_FIRST_INTERVAL], pcm->buffer_size);
846 snd_interval_set_value(¶ms->intervals[SND_PCM_HW_PARAM_BUFFER_BYTES - SND_PCM_HW_PARAM_FIRST_INTERVAL], (pcm->buffer_size * frame_bits) / 8);
847 params->info = pcm->info;
848 params->msbits = pcm->msbits;
849 params->rate_num = pcm->rate_num;
850 params->rate_den = pcm->rate_den;
851 params->fifo_size = pcm->fifo_size;
855 /** \brief Install one PCM hardware configuration chosen from a configuration space and #snd_pcm_prepare it
856 * \param pcm PCM handle
857 * \param params Configuration space definition container
858 * \return 0 on success otherwise a negative error code
860 * The configuration is chosen fixing single parameters in this order:
861 * first access, first format, first subformat, min channels, min rate,
862 * min period time, max buffer size, min tick time. If no mutually
863 * compatible set of parameters can be chosen, a negative error code
866 * After this call, #snd_pcm_prepare() is called automatically and
867 * the stream is brought to \c #SND_PCM_STATE_PREPARED state.
869 * The hardware parameters cannot be changed when the stream is
870 * running (active). The software parameters can be changed
873 * The configuration space will be updated to reflect the chosen
876 int snd_pcm_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
879 assert(pcm && params);
880 err = _snd_pcm_hw_params_internal(pcm, params);
883 err = snd_pcm_prepare(pcm);
887 /** \brief Remove PCM hardware configuration and free associated resources
888 * \param pcm PCM handle
889 * \return 0 on success otherwise a negative error code
891 int snd_pcm_hw_free(snd_pcm_t *pcm)
896 if (pcm->mmap_channels) {
897 err = snd_pcm_munmap(pcm);
901 // assert(snd_pcm_state(pcm) == SND_PCM_STATE_SETUP ||
902 // snd_pcm_state(pcm) == SND_PCM_STATE_PREPARED);
903 err = pcm->ops->hw_free(pcm->op_arg);
910 /** \brief Install PCM software configuration defined by params
911 * \param pcm PCM handle
912 * \param params Configuration container
913 * \return 0 on success otherwise a negative error code
915 * The software parameters can be changed at any time.
916 * The hardware parameters cannot be changed when the stream is
919 * The function is thread-safe when built with the proper option.
921 int snd_pcm_sw_params(snd_pcm_t *pcm, snd_pcm_sw_params_t *params)
924 /* the hw_params must be set at first!!! */
925 if (CHECK_SANITY(! pcm->setup)) {
926 SNDMSG("PCM not set up");
929 if (! params->avail_min) {
930 SNDMSG("params->avail_min is 0");
934 /* disable the check below - it looks too restrictive
935 * (start_threshold is basically independent from avail_min)
937 if (params->start_threshold <= pcm->buffer_size &&
938 params->start_threshold > (pcm->buffer_size / params->avail_min) * params->avail_min) {
939 SNDMSG("params->avail_min problem for start_threshold");
943 __snd_pcm_lock(pcm); /* forced lock due to pcm field change */
944 err = pcm->ops->sw_params(pcm->op_arg, params);
946 __snd_pcm_unlock(pcm);
949 pcm->tstamp_mode = params->tstamp_mode;
950 pcm->tstamp_type = params->tstamp_type;
951 pcm->period_step = params->period_step;
952 pcm->avail_min = params->avail_min;
953 pcm->period_event = sw_get_period_event(params);
954 pcm->start_threshold = params->start_threshold;
955 pcm->stop_threshold = params->stop_threshold;
956 pcm->silence_threshold = params->silence_threshold;
957 pcm->silence_size = params->silence_size;
958 pcm->boundary = params->boundary;
959 __snd_pcm_unlock(pcm);
964 * \brief Obtain status (runtime) information for PCM handle
965 * \param pcm PCM handle
966 * \param status Status container
967 * \return 0 on success otherwise a negative error code
969 * The function is thread-safe when built with the proper option.
971 int snd_pcm_status(snd_pcm_t *pcm, snd_pcm_status_t *status)
975 assert(pcm && status);
977 err = pcm->fast_ops->status(pcm->fast_op_arg, status);
984 * \brief Return PCM state
985 * \param pcm PCM handle
986 * \return PCM state #snd_pcm_state_t of given PCM handle
988 * This is a faster way to obtain only the PCM state without calling
989 * \link ::snd_pcm_status() \endlink.
991 * The function is thread-safe when built with the proper option.
993 snd_pcm_state_t snd_pcm_state(snd_pcm_t *pcm)
995 snd_pcm_state_t state;
999 state = __snd_pcm_state(pcm);
1000 snd_pcm_unlock(pcm);
1005 * \brief (DEPRECATED) Synchronize stream position with hardware
1006 * \param pcm PCM handle
1007 * \return 0 on success otherwise a negative error code
1009 * Note this function does not update the actual r/w pointer
1010 * for applications. The function #snd_pcm_avail_update()
1011 * have to be called before any mmap begin+commit operation.
1013 * The function is thread-safe when built with the proper option.
1015 int snd_pcm_hwsync(snd_pcm_t *pcm)
1020 if (CHECK_SANITY(! pcm->setup)) {
1021 SNDMSG("PCM not set up");
1025 err = __snd_pcm_hwsync(pcm);
1026 snd_pcm_unlock(pcm);
1030 link_warning(snd_pcm_hwsync, "Warning: snd_pcm_hwsync() is deprecated, consider to use snd_pcm_avail()");
1034 * \brief Obtain delay for a running PCM handle
1035 * \param pcm PCM handle
1036 * \param delayp Returned delay in frames
1037 * \return 0 on success otherwise a negative error code
1039 * For playback the delay is defined as the time that a frame that is written
1040 * to the PCM stream shortly after this call will take to be actually
1041 * audible. It is as such the overall latency from the write call to the final
1044 * For capture the delay is defined as the time that a frame that was
1045 * digitized by the audio device takes until it can be read from the PCM
1046 * stream shortly after this call returns. It is as such the overall latency
1047 * from the initial ADC to the read call.
1049 * Please note that hence in case of a playback underrun this value will not
1050 * necessarily got down to 0.
1052 * If the application is interested in the fill level of the playback buffer
1053 * of the device, it should use #snd_pcm_avail*() functions. The
1054 * value returned by that call is not directly related to the delay, since the
1055 * latter might include some additional, fixed latencies the former does not.
1057 * Note this function does not update the actual r/w pointer
1058 * for applications. The function #snd_pcm_avail_update()
1059 * have to be called before any begin+commit operation.
1061 * The function is thread-safe when built with the proper option.
1063 int snd_pcm_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp)
1068 if (CHECK_SANITY(! pcm->setup)) {
1069 SNDMSG("PCM not set up");
1073 err = __snd_pcm_delay(pcm, delayp);
1074 snd_pcm_unlock(pcm);
1079 * \brief Resume from suspend, no samples are lost
1080 * \param pcm PCM handle
1081 * \return 0 on success otherwise a negative error code
1082 * \retval -EAGAIN resume can't be proceed immediately (audio hardware is probably still suspended)
1083 * \retval -ENOSYS hardware doesn't support this feature
1085 * This function can be used when the stream is in the suspend state
1086 * to do the fine resume from this state. Not all hardware supports
1087 * this feature, when an -ENOSYS error is returned, use the \link ::snd_pcm_prepare() \endlink
1088 * function to recovery.
1090 * The function is thread-safe when built with the proper option.
1092 int snd_pcm_resume(snd_pcm_t *pcm)
1095 if (CHECK_SANITY(! pcm->setup)) {
1096 SNDMSG("PCM not set up");
1099 /* lock handled in the callback */
1100 return pcm->fast_ops->resume(pcm->fast_op_arg);
1104 * \brief Obtain last position update hi-res timestamp
1105 * \param pcm PCM handle
1106 * \param avail Number of available frames when timestamp was grabbed
1107 * \param tstamp Hi-res timestamp
1108 * \return 0 on success otherwise a negative error code
1110 * Note this function does not update the actual r/w pointer
1113 * The function is thread-safe when built with the proper option.
1115 int snd_pcm_htimestamp(snd_pcm_t *pcm, snd_pcm_uframes_t *avail, snd_htimestamp_t *tstamp)
1120 if (CHECK_SANITY(! pcm->setup)) {
1121 SNDMSG("PCM not set up");
1125 err = pcm->fast_ops->htimestamp(pcm->fast_op_arg, avail, tstamp);
1126 snd_pcm_unlock(pcm);
1131 * \brief Prepare PCM for use
1132 * \param pcm PCM handle
1133 * \return 0 on success otherwise a negative error code
1135 * The function is thread-safe when built with the proper option.
1137 int snd_pcm_prepare(snd_pcm_t *pcm)
1142 if (CHECK_SANITY(! pcm->setup)) {
1143 SNDMSG("PCM not set up");
1146 if (bad_pcm_state(pcm, ~P_STATE(DISCONNECTED)))
1149 err = pcm->fast_ops->prepare(pcm->fast_op_arg);
1150 snd_pcm_unlock(pcm);
1155 * \brief Reset PCM position
1156 * \param pcm PCM handle
1157 * \return 0 on success otherwise a negative error code
1159 * Reduce PCM delay to 0.
1161 * The function is thread-safe when built with the proper option.
1163 int snd_pcm_reset(snd_pcm_t *pcm)
1168 if (CHECK_SANITY(! pcm->setup)) {
1169 SNDMSG("PCM not set up");
1173 err = pcm->fast_ops->reset(pcm->fast_op_arg);
1174 snd_pcm_unlock(pcm);
1179 * \brief Start a PCM
1180 * \param pcm PCM handle
1181 * \return 0 on success otherwise a negative error code
1183 * The function is thread-safe when built with the proper option.
1185 int snd_pcm_start(snd_pcm_t *pcm)
1190 if (CHECK_SANITY(! pcm->setup)) {
1191 SNDMSG("PCM not set up");
1194 if (bad_pcm_state(pcm, P_STATE(PREPARED)))
1197 err = __snd_pcm_start(pcm);
1198 snd_pcm_unlock(pcm);
1203 * \brief Stop a PCM dropping pending frames
1204 * \param pcm PCM handle
1205 * \return 0 on success otherwise a negative error code
1207 * This function stops the PCM <i>immediately</i>.
1208 * The pending samples on the buffer are ignored.
1210 * For processing all pending samples, use \link ::snd_pcm_drain() \endlink
1213 * The function is thread-safe when built with the proper option.
1215 int snd_pcm_drop(snd_pcm_t *pcm)
1220 if (CHECK_SANITY(! pcm->setup)) {
1221 SNDMSG("PCM not set up");
1224 if (bad_pcm_state(pcm, P_STATE_RUNNABLE | P_STATE(SETUP) |
1225 P_STATE(SUSPENDED)))
1228 err = pcm->fast_ops->drop(pcm->fast_op_arg);
1229 snd_pcm_unlock(pcm);
1234 * \brief Stop a PCM preserving pending frames
1235 * \param pcm PCM handle
1236 * \return 0 on success otherwise a negative error code
1237 * \retval -ESTRPIPE a suspend event occurred
1239 * For playback wait for all pending frames to be played and then stop
1241 * For capture stop PCM permitting to retrieve residual frames.
1243 * For stopping the PCM stream immediately, use \link ::snd_pcm_drop() \endlink
1246 * The function is thread-safe when built with the proper option.
1248 int snd_pcm_drain(snd_pcm_t *pcm)
1251 if (CHECK_SANITY(! pcm->setup)) {
1252 SNDMSG("PCM not set up");
1255 if (bad_pcm_state(pcm, P_STATE_RUNNABLE))
1257 /* lock handled in the callback */
1258 return pcm->fast_ops->drain(pcm->fast_op_arg);
1262 * \brief Pause/resume PCM
1263 * \param pcm PCM handle
1264 * \param enable 0 = resume, 1 = pause
1265 * \return 0 on success otherwise a negative error code
1267 * Note that this function works only on the hardware which supports
1268 * pause feature. You can check it via \link ::snd_pcm_hw_params_can_pause() \endlink
1271 * The function is thread-safe when built with the proper option.
1273 int snd_pcm_pause(snd_pcm_t *pcm, int enable)
1278 if (CHECK_SANITY(! pcm->setup)) {
1279 SNDMSG("PCM not set up");
1282 if (bad_pcm_state(pcm, P_STATE_RUNNABLE))
1285 err = pcm->fast_ops->pause(pcm->fast_op_arg, enable);
1286 snd_pcm_unlock(pcm);
1291 * \brief Get safe count of frames which can be rewinded
1292 * \param pcm PCM handle
1293 * \return a positive number of frames or negative error code
1295 * Note: The snd_pcm_rewind() can accept bigger value than returned
1296 * by this function. But it is not guaranteed that output stream
1297 * will be consistent with bigger value.
1299 * The function is thread-safe when built with the proper option.
1301 snd_pcm_sframes_t snd_pcm_rewindable(snd_pcm_t *pcm)
1303 snd_pcm_sframes_t result;
1306 if (CHECK_SANITY(! pcm->setup)) {
1307 SNDMSG("PCM not set up");
1310 if (bad_pcm_state(pcm, P_STATE_RUNNABLE))
1313 result = pcm->fast_ops->rewindable(pcm->fast_op_arg);
1314 snd_pcm_unlock(pcm);
1319 * \brief Move application frame position backward
1320 * \param pcm PCM handle
1321 * \param frames wanted displacement in frames
1322 * \return a positive number for actual displacement otherwise a
1323 * negative error code
1325 * The function is thread-safe when built with the proper option.
1327 snd_pcm_sframes_t snd_pcm_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
1329 snd_pcm_sframes_t result;
1332 if (CHECK_SANITY(! pcm->setup)) {
1333 SNDMSG("PCM not set up");
1338 if (bad_pcm_state(pcm, P_STATE_RUNNABLE))
1341 result = pcm->fast_ops->rewind(pcm->fast_op_arg, frames);
1342 snd_pcm_unlock(pcm);
1347 * \brief Get safe count of frames which can be forwarded
1348 * \param pcm PCM handle
1349 * \return a positive number of frames or negative error code
1351 * Note: The snd_pcm_forward() can accept bigger value than returned
1352 * by this function. But it is not guaranteed that output stream
1353 * will be consistent with bigger value.
1355 * The function is thread-safe when built with the proper option.
1357 snd_pcm_sframes_t snd_pcm_forwardable(snd_pcm_t *pcm)
1359 snd_pcm_sframes_t result;
1362 if (CHECK_SANITY(! pcm->setup)) {
1363 SNDMSG("PCM not set up");
1366 if (bad_pcm_state(pcm, P_STATE_RUNNABLE))
1369 result = pcm->fast_ops->forwardable(pcm->fast_op_arg);
1370 snd_pcm_unlock(pcm);
1375 * \brief Move application frame position forward
1376 * \param pcm PCM handle
1377 * \param frames wanted skip in frames
1378 * \return a positive number for actual skip otherwise a negative error code
1379 * \retval 0 means no action
1381 * The function is thread-safe when built with the proper option.
1384 snd_pcm_sframes_t INTERNAL(snd_pcm_forward)(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
1386 snd_pcm_sframes_t snd_pcm_forward(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
1389 snd_pcm_sframes_t result;
1392 if (CHECK_SANITY(! pcm->setup)) {
1393 SNDMSG("PCM not set up");
1398 if (bad_pcm_state(pcm, P_STATE_RUNNABLE))
1401 result = pcm->fast_ops->forward(pcm->fast_op_arg, frames);
1402 snd_pcm_unlock(pcm);
1405 use_default_symbol_version(__snd_pcm_forward, snd_pcm_forward, ALSA_0.9.0rc8);
1408 * \brief Write interleaved frames to a PCM
1409 * \param pcm PCM handle
1410 * \param buffer frames containing buffer
1411 * \param size frames to be written
1412 * \return a positive number of frames actually written otherwise a
1413 * negative error code
1414 * \retval -EBADFD PCM is not in the right state (#SND_PCM_STATE_PREPARED or #SND_PCM_STATE_RUNNING)
1415 * \retval -EPIPE an underrun occurred
1416 * \retval -ESTRPIPE a suspend event occurred (stream is suspended and waiting for an application recovery)
1418 * If the blocking behaviour is selected and it is running, then routine waits until
1419 * all requested frames are played or put to the playback ring buffer.
1420 * The returned number of frames can be less only if a signal or underrun occurred.
1422 * If the non-blocking behaviour is selected, then routine doesn't wait at all.
1424 * The function is thread-safe when built with the proper option.
1426 snd_pcm_sframes_t snd_pcm_writei(snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size)
1429 assert(size == 0 || buffer);
1430 if (CHECK_SANITY(! pcm->setup)) {
1431 SNDMSG("PCM not set up");
1434 if (pcm->access != SND_PCM_ACCESS_RW_INTERLEAVED) {
1435 SNDMSG("invalid access type %s", snd_pcm_access_name(pcm->access));
1438 if (bad_pcm_state(pcm, P_STATE_RUNNABLE))
1440 return _snd_pcm_writei(pcm, buffer, size);
1444 * \brief Write non interleaved frames to a PCM
1445 * \param pcm PCM handle
1446 * \param bufs frames containing buffers (one for each channel)
1447 * \param size frames to be written
1448 * \return a positive number of frames actually written otherwise a
1449 * negative error code
1450 * \retval -EBADFD PCM is not in the right state (#SND_PCM_STATE_PREPARED or #SND_PCM_STATE_RUNNING)
1451 * \retval -EPIPE an underrun occurred
1452 * \retval -ESTRPIPE a suspend event occurred (stream is suspended and waiting for an application recovery)
1454 * If the blocking behaviour is selected and it is running, then routine waits until
1455 * all requested frames are played or put to the playback ring buffer.
1456 * The returned number of frames can be less only if a signal or underrun occurred.
1458 * If the non-blocking behaviour is selected, then routine doesn't wait at all.
1460 * The function is thread-safe when built with the proper option.
1462 snd_pcm_sframes_t snd_pcm_writen(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size)
1465 assert(size == 0 || bufs);
1466 if (CHECK_SANITY(! pcm->setup)) {
1467 SNDMSG("PCM not set up");
1470 if (pcm->access != SND_PCM_ACCESS_RW_NONINTERLEAVED) {
1471 SNDMSG("invalid access type %s", snd_pcm_access_name(pcm->access));
1474 if (bad_pcm_state(pcm, P_STATE_RUNNABLE))
1476 return _snd_pcm_writen(pcm, bufs, size);
1480 * \brief Read interleaved frames from a PCM
1481 * \param pcm PCM handle
1482 * \param buffer frames containing buffer
1483 * \param size frames to be read
1484 * \return a positive number of frames actually read otherwise a
1485 * negative error code
1486 * \retval -EBADFD PCM is not in the right state (#SND_PCM_STATE_PREPARED or #SND_PCM_STATE_RUNNING)
1487 * \retval -EPIPE an overrun occurred
1488 * \retval -ESTRPIPE a suspend event occurred (stream is suspended and waiting for an application recovery)
1490 * If the blocking behaviour was selected and it is running, then routine waits until
1491 * all requested frames are filled. The returned number of frames can be less only
1492 * if a signal or underrun occurred.
1494 * If the non-blocking behaviour is selected, then routine doesn't wait at all.
1496 * The function is thread-safe when built with the proper option.
1498 snd_pcm_sframes_t snd_pcm_readi(snd_pcm_t *pcm, void *buffer, snd_pcm_uframes_t size)
1501 assert(size == 0 || buffer);
1502 if (CHECK_SANITY(! pcm->setup)) {
1503 SNDMSG("PCM not set up");
1506 if (pcm->access != SND_PCM_ACCESS_RW_INTERLEAVED) {
1507 SNDMSG("invalid access type %s", snd_pcm_access_name(pcm->access));
1510 if (bad_pcm_state(pcm, P_STATE_RUNNABLE))
1512 return _snd_pcm_readi(pcm, buffer, size);
1516 * \brief Read non interleaved frames to a PCM
1517 * \param pcm PCM handle
1518 * \param bufs frames containing buffers (one for each channel)
1519 * \param size frames to be read
1520 * \return a positive number of frames actually read otherwise a
1521 * negative error code
1522 * \retval -EBADFD PCM is not in the right state (#SND_PCM_STATE_PREPARED or #SND_PCM_STATE_RUNNING)
1523 * \retval -EPIPE an overrun occurred
1524 * \retval -ESTRPIPE a suspend event occurred (stream is suspended and waiting for an application recovery)
1526 * If the blocking behaviour was selected and it is running, then routine waits until
1527 * all requested frames are filled. The returned number of frames can be less only
1528 * if a signal or underrun occurred.
1530 * If the non-blocking behaviour is selected, then routine doesn't wait at all.
1532 * The function is thread-safe when built with the proper option.
1534 snd_pcm_sframes_t snd_pcm_readn(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size)
1537 assert(size == 0 || bufs);
1538 if (CHECK_SANITY(! pcm->setup)) {
1539 SNDMSG("PCM not set up");
1542 if (pcm->access != SND_PCM_ACCESS_RW_NONINTERLEAVED) {
1543 SNDMSG("invalid access type %s", snd_pcm_access_name(pcm->access));
1546 if (bad_pcm_state(pcm, P_STATE_RUNNABLE))
1548 return _snd_pcm_readn(pcm, bufs, size);
1552 * \brief Link two PCMs
1553 * \param pcm1 first PCM handle
1554 * \param pcm2 first PCM handle
1555 * \return 0 on success otherwise a negative error code
1557 * The two PCMs will start/stop/prepare in sync.
1559 int snd_pcm_link(snd_pcm_t *pcm1, snd_pcm_t *pcm2)
1563 if (pcm1->fast_ops->link)
1564 return pcm1->fast_ops->link(pcm1, pcm2);
1569 * \brief Remove a PCM from a linked group
1570 * \param pcm PCM handle
1571 * \return 0 on success otherwise a negative error code
1573 int snd_pcm_unlink(snd_pcm_t *pcm)
1576 if (pcm->fast_ops->unlink)
1577 return pcm->fast_ops->unlink(pcm);
1581 /* locked version */
1582 static int __snd_pcm_poll_descriptors_count(snd_pcm_t *pcm)
1584 if (pcm->fast_ops->poll_descriptors_count)
1585 return pcm->fast_ops->poll_descriptors_count(pcm->fast_op_arg);
1586 return pcm->poll_fd_count;
1590 * \brief get count of poll descriptors for PCM handle
1591 * \param pcm PCM handle
1592 * \return count of poll descriptors
1594 * The function is thread-safe when built with the proper option.
1596 int snd_pcm_poll_descriptors_count(snd_pcm_t *pcm)
1602 count = __snd_pcm_poll_descriptors_count(pcm);
1603 snd_pcm_unlock(pcm);
1607 /* locked version */
1608 static int __snd_pcm_poll_descriptors(snd_pcm_t *pcm, struct pollfd *pfds,
1611 if (pcm->fast_ops->poll_descriptors)
1612 return pcm->fast_ops->poll_descriptors(pcm->fast_op_arg, pfds, space);
1613 if (pcm->poll_fd < 0) {
1614 SNDMSG("poll_fd < 0");
1617 if (space >= 1 && pfds) {
1618 pfds->fd = pcm->poll_fd;
1619 pfds->events = pcm->poll_events | POLLERR | POLLNVAL;
1627 * \brief get poll descriptors
1628 * \param pcm PCM handle
1629 * \param pfds array of poll descriptors
1630 * \param space space in the poll descriptor array
1631 * \return count of filled descriptors
1633 * This function fills the given poll descriptor structs for the specified
1634 * PCM handle. The poll desctiptor array should have the size returned by
1635 * \link ::snd_pcm_poll_descriptors_count() \endlink function.
1637 * The result is intended for direct use with the poll() syscall.
1639 * For reading the returned events of poll descriptor after poll() system
1640 * call, use \link ::snd_pcm_poll_descriptors_revents() \endlink function.
1641 * The field values in pollfd structs may be bogus regarding the stream
1642 * direction from the application perspective (POLLIN might not imply read
1643 * direction and POLLOUT might not imply write), but
1644 * the \link ::snd_pcm_poll_descriptors_revents() \endlink function
1645 * does the right "demangling".
1647 * You can use output from this function as arguments for the select()
1648 * syscall, too. Do not forget to translate POLLIN and POLLOUT events to
1649 * corresponding FD_SET arrays and demangle events using
1650 * \link ::snd_pcm_poll_descriptors_revents() \endlink .
1652 * The function is thread-safe when built with the proper option.
1654 int snd_pcm_poll_descriptors(snd_pcm_t *pcm, struct pollfd *pfds, unsigned int space)
1658 assert(pcm && pfds);
1660 err = __snd_pcm_poll_descriptors(pcm, pfds, space);
1661 snd_pcm_unlock(pcm);
1665 static int __snd_pcm_poll_revents(snd_pcm_t *pcm, struct pollfd *pfds,
1666 unsigned int nfds, unsigned short *revents);
1669 * \brief get returned events from poll descriptors
1670 * \param pcm PCM handle
1671 * \param pfds array of poll descriptors
1672 * \param nfds count of poll descriptors
1673 * \param revents pointer to the returned (single) event
1674 * \return zero if success, otherwise a negative error code
1676 * This function does "demangling" of the revents mask returned from
1677 * the poll() syscall to correct semantics (POLLIN = read, POLLOUT = write).
1679 * Note: The null event also exists. Even if poll() or select()
1680 * syscall returned that some events are waiting, this function might
1681 * return empty set of events. In this case, application should
1682 * do next event waiting using poll() or select().
1684 * Note: Even if multiple poll descriptors are used (i.e. pfds > 1),
1685 * this function returns only a single event.
1687 * The function is thread-safe when built with the proper option.
1689 int snd_pcm_poll_descriptors_revents(snd_pcm_t *pcm, struct pollfd *pfds, unsigned int nfds, unsigned short *revents)
1693 assert(pcm && pfds && revents);
1695 err = __snd_pcm_poll_revents(pcm, pfds, nfds, revents);
1696 snd_pcm_unlock(pcm);
1700 static int __snd_pcm_poll_revents(snd_pcm_t *pcm, struct pollfd *pfds,
1701 unsigned int nfds, unsigned short *revents)
1703 if (pcm->fast_ops->poll_revents)
1704 return pcm->fast_ops->poll_revents(pcm->fast_op_arg, pfds, nfds, revents);
1706 *revents = pfds->revents;
1713 #define PCMTYPE(v) [SND_PCM_TYPE_##v] = #v
1714 #define STATE(v) [SND_PCM_STATE_##v] = #v
1715 #define STREAM(v) [SND_PCM_STREAM_##v] = #v
1716 #define READY(v) [SND_PCM_READY_##v] = #v
1717 #define XRUN(v) [SND_PCM_XRUN_##v] = #v
1718 #define SILENCE(v) [SND_PCM_SILENCE_##v] = #v
1719 #define TSTAMP(v) [SND_PCM_TSTAMP_##v] = #v
1720 #define TSTAMP_TYPE(v) [SND_PCM_TSTAMP_TYPE_##v] = #v
1721 #define ACCESS(v) [SND_PCM_ACCESS_##v] = #v
1722 #define START(v) [SND_PCM_START_##v] = #v
1723 #define HW_PARAM(v) [SND_PCM_HW_PARAM_##v] = #v
1724 #define SW_PARAM(v) [SND_PCM_SW_PARAM_##v] = #v
1725 #define FORMAT(v) [SND_PCM_FORMAT_##v] = #v
1726 #define SUBFORMAT(v) [SND_PCM_SUBFORMAT_##v] = #v
1728 #define FORMATD(v, d) [SND_PCM_FORMAT_##v] = d
1729 #define SUBFORMATD(v, d) [SND_PCM_SUBFORMAT_##v] = d
1732 static const char *const snd_pcm_stream_names[] = {
1737 static const char *const snd_pcm_state_names[] = {
1746 STATE(DISCONNECTED),
1749 static const char *const snd_pcm_access_names[] = {
1750 ACCESS(MMAP_INTERLEAVED),
1751 ACCESS(MMAP_NONINTERLEAVED),
1752 ACCESS(MMAP_COMPLEX),
1753 ACCESS(RW_INTERLEAVED),
1754 ACCESS(RW_NONINTERLEAVED),
1757 static const char *const snd_pcm_format_names[] = {
1776 FORMAT(IEC958_SUBFRAME_LE),
1777 FORMAT(IEC958_SUBFRAME_BE),
1807 static const char *const snd_pcm_format_aliases[SND_PCM_FORMAT_LAST+1] = {
1816 FORMAT(IEC958_SUBFRAME),
1819 static const char *const snd_pcm_format_descriptions[] = {
1820 FORMATD(S8, "Signed 8 bit"),
1821 FORMATD(U8, "Unsigned 8 bit"),
1822 FORMATD(S16_LE, "Signed 16 bit Little Endian"),
1823 FORMATD(S16_BE, "Signed 16 bit Big Endian"),
1824 FORMATD(U16_LE, "Unsigned 16 bit Little Endian"),
1825 FORMATD(U16_BE, "Unsigned 16 bit Big Endian"),
1826 FORMATD(S24_LE, "Signed 24 bit Little Endian"),
1827 FORMATD(S24_BE, "Signed 24 bit Big Endian"),
1828 FORMATD(U24_LE, "Unsigned 24 bit Little Endian"),
1829 FORMATD(U24_BE, "Unsigned 24 bit Big Endian"),
1830 FORMATD(S32_LE, "Signed 32 bit Little Endian"),
1831 FORMATD(S32_BE, "Signed 32 bit Big Endian"),
1832 FORMATD(U32_LE, "Unsigned 32 bit Little Endian"),
1833 FORMATD(U32_BE, "Unsigned 32 bit Big Endian"),
1834 FORMATD(FLOAT_LE, "Float 32 bit Little Endian"),
1835 FORMATD(FLOAT_BE, "Float 32 bit Big Endian"),
1836 FORMATD(FLOAT64_LE, "Float 64 bit Little Endian"),
1837 FORMATD(FLOAT64_BE, "Float 64 bit Big Endian"),
1838 FORMATD(IEC958_SUBFRAME_LE, "IEC-958 Little Endian"),
1839 FORMATD(IEC958_SUBFRAME_BE, "IEC-958 Big Endian"),
1840 FORMATD(MU_LAW, "Mu-Law"),
1841 FORMATD(A_LAW, "A-Law"),
1842 FORMATD(IMA_ADPCM, "Ima-ADPCM"),
1843 FORMATD(MPEG, "MPEG"),
1844 FORMATD(GSM, "GSM"),
1845 FORMATD(SPECIAL, "Special"),
1846 FORMATD(S24_3LE, "Signed 24 bit Little Endian in 3bytes"),
1847 FORMATD(S24_3BE, "Signed 24 bit Big Endian in 3bytes"),
1848 FORMATD(U24_3LE, "Unsigned 24 bit Little Endian in 3bytes"),
1849 FORMATD(U24_3BE, "Unsigned 24 bit Big Endian in 3bytes"),
1850 FORMATD(S20_3LE, "Signed 20 bit Little Endian in 3bytes"),
1851 FORMATD(S20_3BE, "Signed 20 bit Big Endian in 3bytes"),
1852 FORMATD(U20_3LE, "Unsigned 20 bit Little Endian in 3bytes"),
1853 FORMATD(U20_3BE, "Unsigned 20 bit Big Endian in 3bytes"),
1854 FORMATD(S18_3LE, "Signed 18 bit Little Endian in 3bytes"),
1855 FORMATD(S18_3BE, "Signed 18 bit Big Endian in 3bytes"),
1856 FORMATD(U18_3LE, "Unsigned 18 bit Little Endian in 3bytes"),
1857 FORMATD(U18_3BE, "Unsigned 18 bit Big Endian in 3bytes"),
1858 FORMATD(G723_24, "G.723 (ADPCM) 24 kbit/s, 8 samples in 3 bytes"),
1859 FORMATD(G723_24_1B, "G.723 (ADPCM) 24 kbit/s, 1 sample in 1 byte"),
1860 FORMATD(G723_40, "G.723 (ADPCM) 40 kbit/s, 8 samples in 3 bytes"),
1861 FORMATD(G723_40_1B, "G.723 (ADPCM) 40 kbit/s, 1 sample in 1 byte"),
1862 FORMATD(DSD_U8, "Direct Stream Digital, 1-byte (x8), oldest bit in MSB"),
1863 FORMATD(DSD_U16_LE, "Direct Stream Digital, 2-byte (x16), little endian, oldest bits in MSB"),
1864 FORMATD(DSD_U32_LE, "Direct Stream Digital, 4-byte (x32), little endian, oldest bits in MSB"),
1865 FORMATD(DSD_U16_BE, "Direct Stream Digital, 2-byte (x16), big endian, oldest bits in MSB"),
1866 FORMATD(DSD_U32_BE, "Direct Stream Digital, 4-byte (x32), big endian, oldest bits in MSB"),
1869 static const char *const snd_pcm_type_names[] = {
1890 PCMTYPE(LINEAR_FLOAT),
1902 static const char *const snd_pcm_subformat_names[] = {
1906 static const char *const snd_pcm_subformat_descriptions[] = {
1907 SUBFORMATD(STD, "Standard"),
1910 static const char *const snd_pcm_start_mode_names[] = {
1915 static const char *const snd_pcm_xrun_mode_names[] = {
1920 static const char *const snd_pcm_tstamp_mode_names[] = {
1925 static const char *const snd_pcm_tstamp_type_names[] = {
1926 TSTAMP_TYPE(GETTIMEOFDAY),
1927 TSTAMP_TYPE(MONOTONIC),
1928 TSTAMP_TYPE(MONOTONIC_RAW),
1933 * \brief get name of PCM stream type
1934 * \param stream PCM stream type
1935 * \return ascii name of PCM stream type
1937 const char *snd_pcm_stream_name(snd_pcm_stream_t stream)
1939 if (stream > SND_PCM_STREAM_LAST)
1941 return snd_pcm_stream_names[stream];
1945 * \brief get name of PCM access type
1946 * \param acc PCM access type
1947 * \return ascii name of PCM access type
1949 const char *snd_pcm_access_name(snd_pcm_access_t acc)
1951 if (acc > SND_PCM_ACCESS_LAST)
1953 return snd_pcm_access_names[acc];
1957 * \brief get name of PCM sample format
1958 * \param format PCM sample format
1959 * \return ascii name of PCM sample format
1961 const char *snd_pcm_format_name(snd_pcm_format_t format)
1963 if (format > SND_PCM_FORMAT_LAST)
1965 return snd_pcm_format_names[format];
1969 * \brief get description of PCM sample format
1970 * \param format PCM sample format
1971 * \return ascii description of PCM sample format
1973 const char *snd_pcm_format_description(snd_pcm_format_t format)
1975 if (format > SND_PCM_FORMAT_LAST)
1977 return snd_pcm_format_descriptions[format];
1981 * \brief get PCM sample format from name
1982 * \param name PCM sample format name (case insensitive)
1983 * \return PCM sample format
1985 snd_pcm_format_t snd_pcm_format_value(const char* name)
1987 snd_pcm_format_t format;
1988 for (format = 0; format <= SND_PCM_FORMAT_LAST; format++) {
1989 if (snd_pcm_format_names[format] &&
1990 strcasecmp(name, snd_pcm_format_names[format]) == 0) {
1993 if (snd_pcm_format_aliases[format] &&
1994 strcasecmp(name, snd_pcm_format_aliases[format]) == 0) {
1998 for (format = 0; format <= SND_PCM_FORMAT_LAST; format++) {
1999 if (snd_pcm_format_descriptions[format] &&
2000 strcasecmp(name, snd_pcm_format_descriptions[format]) == 0) {
2004 return SND_PCM_FORMAT_UNKNOWN;
2008 * \brief get name of PCM sample subformat
2009 * \param subformat PCM sample subformat
2010 * \return ascii name of PCM sample subformat
2012 const char *snd_pcm_subformat_name(snd_pcm_subformat_t subformat)
2014 if (subformat > SND_PCM_SUBFORMAT_LAST)
2016 return snd_pcm_subformat_names[subformat];
2020 * \brief get description of PCM sample subformat
2021 * \param subformat PCM sample subformat
2022 * \return ascii description of PCM sample subformat
2024 const char *snd_pcm_subformat_description(snd_pcm_subformat_t subformat)
2026 if (subformat > SND_PCM_SUBFORMAT_LAST)
2028 return snd_pcm_subformat_descriptions[subformat];
2032 * \brief (DEPRECATED) get name of PCM start mode setting
2033 * \param mode PCM start mode
2034 * \return ascii name of PCM start mode setting
2036 const char *snd_pcm_start_mode_name(snd_pcm_start_t mode)
2038 if (mode > SND_PCM_START_LAST)
2040 return snd_pcm_start_mode_names[mode];
2044 link_warning(snd_pcm_start_mode_name, "Warning: start_mode is deprecated, consider to use start_threshold");
2048 * \brief (DEPRECATED) get name of PCM xrun mode setting
2049 * \param mode PCM xrun mode
2050 * \return ascii name of PCM xrun mode setting
2052 const char *snd_pcm_xrun_mode_name(snd_pcm_xrun_t mode)
2054 if (mode > SND_PCM_XRUN_LAST)
2056 return snd_pcm_xrun_mode_names[mode];
2060 link_warning(snd_pcm_xrun_mode_name, "Warning: xrun_mode is deprecated, consider to use stop_threshold");
2064 * \brief get name of PCM tstamp mode setting
2065 * \param mode PCM tstamp mode
2066 * \return ascii name of PCM tstamp mode setting
2068 const char *snd_pcm_tstamp_mode_name(snd_pcm_tstamp_t mode)
2070 if (mode > SND_PCM_TSTAMP_LAST)
2072 return snd_pcm_tstamp_mode_names[mode];
2076 * \brief get name of PCM tstamp type setting
2077 * \param mode PCM tstamp type
2078 * \return ascii name of PCM tstamp type setting
2080 const char *snd_pcm_tstamp_type_name(snd_pcm_tstamp_type_t type)
2082 if (type > SND_PCM_TSTAMP_TYPE_LAST)
2084 return snd_pcm_tstamp_type_names[type];
2088 * \brief get name of PCM state
2089 * \param state PCM state
2090 * \return ascii name of PCM state
2092 const char *snd_pcm_state_name(snd_pcm_state_t state)
2094 if (state > SND_PCM_STATE_LAST)
2096 return snd_pcm_state_names[state];
2100 * \brief get name of PCM type
2101 * \param type PCM type
2102 * \return ascii name of PCM type
2105 const char *INTERNAL(snd_pcm_type_name)(snd_pcm_type_t type)
2107 const char *snd_pcm_type_name(snd_pcm_type_t type)
2110 if (type > SND_PCM_TYPE_LAST)
2112 return snd_pcm_type_names[type];
2114 use_default_symbol_version(__snd_pcm_type_name, snd_pcm_type_name, ALSA_0.9.0);
2117 * \brief Dump current hardware setup for PCM
2118 * \param pcm PCM handle
2119 * \param out Output handle
2120 * \return 0 on success otherwise a negative error code
2122 int snd_pcm_dump_hw_setup(snd_pcm_t *pcm, snd_output_t *out)
2126 if (CHECK_SANITY(! pcm->setup)) {
2127 SNDMSG("PCM not set up");
2130 snd_output_printf(out, " stream : %s\n", snd_pcm_stream_name(pcm->stream));
2131 snd_output_printf(out, " access : %s\n", snd_pcm_access_name(pcm->access));
2132 snd_output_printf(out, " format : %s\n", snd_pcm_format_name(pcm->format));
2133 snd_output_printf(out, " subformat : %s\n", snd_pcm_subformat_name(pcm->subformat));
2134 snd_output_printf(out, " channels : %u\n", pcm->channels);
2135 snd_output_printf(out, " rate : %u\n", pcm->rate);
2136 snd_output_printf(out, " exact rate : %g (%u/%u)\n",
2137 (pcm->rate_den ? ((double) pcm->rate_num / pcm->rate_den) : 0.0),
2138 pcm->rate_num, pcm->rate_den);
2139 snd_output_printf(out, " msbits : %u\n", pcm->msbits);
2140 snd_output_printf(out, " buffer_size : %lu\n", pcm->buffer_size);
2141 snd_output_printf(out, " period_size : %lu\n", pcm->period_size);
2142 snd_output_printf(out, " period_time : %u\n", pcm->period_time);
2147 * \brief Dump current software setup for PCM
2148 * \param pcm PCM handle
2149 * \param out Output handle
2150 * \return 0 on success otherwise a negative error code
2152 int snd_pcm_dump_sw_setup(snd_pcm_t *pcm, snd_output_t *out)
2156 if (CHECK_SANITY(! pcm->setup)) {
2157 SNDMSG("PCM not set up");
2160 snd_output_printf(out, " tstamp_mode : %s\n", snd_pcm_tstamp_mode_name(pcm->tstamp_mode));
2161 snd_output_printf(out, " tstamp_type : %s\n", snd_pcm_tstamp_type_name(pcm->tstamp_type));
2162 snd_output_printf(out, " period_step : %d\n", pcm->period_step);
2163 snd_output_printf(out, " avail_min : %ld\n", pcm->avail_min);
2164 snd_output_printf(out, " period_event : %i\n", pcm->period_event);
2165 snd_output_printf(out, " start_threshold : %ld\n", pcm->start_threshold);
2166 snd_output_printf(out, " stop_threshold : %ld\n", pcm->stop_threshold);
2167 snd_output_printf(out, " silence_threshold: %ld\n", pcm->silence_threshold);
2168 snd_output_printf(out, " silence_size : %ld\n", pcm->silence_size);
2169 snd_output_printf(out, " boundary : %ld\n", pcm->boundary);
2174 * \brief Dump current setup (hardware and software) for PCM
2175 * \param pcm PCM handle
2176 * \param out Output handle
2177 * \return 0 on success otherwise a negative error code
2179 int snd_pcm_dump_setup(snd_pcm_t *pcm, snd_output_t *out)
2181 snd_pcm_dump_hw_setup(pcm, out);
2182 snd_pcm_dump_sw_setup(pcm, out);
2187 * \brief Dump status
2188 * \param status Status container
2189 * \param out Output handle
2190 * \return 0 on success otherwise a negative error code
2192 int snd_pcm_status_dump(snd_pcm_status_t *status, snd_output_t *out)
2195 snd_output_printf(out, " state : %s\n", snd_pcm_state_name((snd_pcm_state_t) status->state));
2196 snd_output_printf(out, " trigger_time: %ld.%06ld\n",
2197 status->trigger_tstamp.tv_sec,
2198 status->trigger_tstamp.tv_nsec / 1000);
2199 snd_output_printf(out, " tstamp : %ld.%06ld\n",
2200 status->tstamp.tv_sec, status->tstamp.tv_nsec / 1000);
2201 snd_output_printf(out, " delay : %ld\n", (long)status->delay);
2202 snd_output_printf(out, " avail : %ld\n", (long)status->avail);
2203 snd_output_printf(out, " avail_max : %ld\n", (long)status->avail_max);
2208 * \brief Dump PCM info
2209 * \param pcm PCM handle
2210 * \param out Output handle
2211 * \return 0 on success otherwise a negative error code
2213 int snd_pcm_dump(snd_pcm_t *pcm, snd_output_t *out)
2217 pcm->ops->dump(pcm->op_arg, out);
2222 * \brief Convert bytes in frames for a PCM
2223 * \param pcm PCM handle
2224 * \param bytes quantity in bytes
2225 * \return quantity expressed in frames
2227 snd_pcm_sframes_t snd_pcm_bytes_to_frames(snd_pcm_t *pcm, ssize_t bytes)
2230 if (CHECK_SANITY(! pcm->setup)) {
2231 SNDMSG("PCM not set up");
2234 return bytes * 8 / pcm->frame_bits;
2238 * \brief Convert frames in bytes for a PCM
2239 * \param pcm PCM handle
2240 * \param frames quantity in frames
2241 * \return quantity expressed in bytes
2243 ssize_t snd_pcm_frames_to_bytes(snd_pcm_t *pcm, snd_pcm_sframes_t frames)
2246 if (CHECK_SANITY(! pcm->setup)) {
2247 SNDMSG("PCM not set up");
2250 return frames * pcm->frame_bits / 8;
2254 * \brief Convert bytes in samples for a PCM
2255 * \param pcm PCM handle
2256 * \param bytes quantity in bytes
2257 * \return quantity expressed in samples
2259 long snd_pcm_bytes_to_samples(snd_pcm_t *pcm, ssize_t bytes)
2262 if (CHECK_SANITY(! pcm->setup)) {
2263 SNDMSG("PCM not set up");
2266 return bytes * 8 / pcm->sample_bits;
2270 * \brief Convert samples in bytes for a PCM
2271 * \param pcm PCM handle
2272 * \param samples quantity in samples
2273 * \return quantity expressed in bytes
2275 ssize_t snd_pcm_samples_to_bytes(snd_pcm_t *pcm, long samples)
2278 if (CHECK_SANITY(! pcm->setup)) {
2279 SNDMSG("PCM not set up");
2282 return samples * pcm->sample_bits / 8;
2286 * \brief Add an async handler for a PCM
2287 * \param handler Returned handler handle
2288 * \param pcm PCM handle
2289 * \param callback Callback function
2290 * \param private_data Callback private data
2291 * \return 0 otherwise a negative error code on failure
2293 * The asynchronous callback is called when period boundary elapses.
2295 int snd_async_add_pcm_handler(snd_async_handler_t **handler, snd_pcm_t *pcm,
2296 snd_async_callback_t callback, void *private_data)
2300 snd_async_handler_t *h;
2301 err = snd_async_add_handler(&h, _snd_pcm_async_descriptor(pcm),
2302 callback, private_data);
2305 h->type = SND_ASYNC_HANDLER_PCM;
2307 was_empty = list_empty(&pcm->async_handlers);
2308 list_add_tail(&h->hlist, &pcm->async_handlers);
2310 err = snd_pcm_async(pcm, snd_async_handler_get_signo(h), getpid());
2312 snd_async_del_handler(h);
2321 * \brief Return PCM handle related to an async handler
2322 * \param handler Async handler handle
2323 * \return PCM handle
2325 snd_pcm_t *snd_async_handler_get_pcm(snd_async_handler_t *handler)
2327 if (handler->type != SND_ASYNC_HANDLER_PCM) {
2328 SNDMSG("invalid handler type %d", handler->type);
2331 return handler->u.pcm;
2334 static const char *const build_in_pcms[] = {
2335 "adpcm", "alaw", "copy", "dmix", "file", "hooks", "hw", "ladspa", "lfloat",
2336 "linear", "meter", "mulaw", "multi", "null", "empty", "plug", "rate", "route", "share",
2337 "shm", "dsnoop", "dshare", "asym", "iec958", "softvol", "mmap_emul",
2341 static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name,
2342 snd_config_t *pcm_root, snd_config_t *pcm_conf,
2343 snd_pcm_stream_t stream, int mode)
2346 char *buf = NULL, *buf1 = NULL;
2348 snd_config_t *conf, *type_conf = NULL, *tmp;
2349 snd_config_iterator_t i, next;
2351 const char *lib = NULL, *open_name = NULL;
2352 int (*open_func)(snd_pcm_t **, const char *,
2353 snd_config_t *, snd_config_t *,
2354 snd_pcm_stream_t, int) = NULL;
2356 extern void *snd_pcm_open_symbols(void);
2358 if (snd_config_get_type(pcm_conf) != SND_CONFIG_TYPE_COMPOUND) {
2361 snd_config_get_id(pcm_conf, &id);
2363 snd_config_get_ascii(pcm_conf, &val);
2364 SNDERR("Invalid type for PCM %s%sdefinition (id: %s, value: %s)", name ? name : "", name ? " " : "", id, val);
2368 err = snd_config_search(pcm_conf, "type", &conf);
2370 SNDERR("type is not defined");
2373 err = snd_config_get_id(conf, &id);
2375 SNDERR("unable to get id");
2378 err = snd_config_get_string(conf, &str);
2380 SNDERR("Invalid type for %s", id);
2383 err = snd_config_search_definition(pcm_root, "pcm_type", str, &type_conf);
2385 if (snd_config_get_type(type_conf) != SND_CONFIG_TYPE_COMPOUND) {
2386 SNDERR("Invalid type for PCM type %s definition", str);
2390 snd_config_for_each(i, next, type_conf) {
2391 snd_config_t *n = snd_config_iterator_entry(i);
2393 if (snd_config_get_id(n, &id) < 0)
2395 if (strcmp(id, "comment") == 0)
2397 if (strcmp(id, "lib") == 0) {
2398 err = snd_config_get_string(n, &lib);
2400 SNDERR("Invalid type for %s", id);
2405 if (strcmp(id, "open") == 0) {
2406 err = snd_config_get_string(n, &open_name);
2408 SNDERR("Invalid type for %s", id);
2413 SNDERR("Unknown field %s", id);
2419 buf = malloc(strlen(str) + 32);
2425 sprintf(buf, "_snd_pcm_%s_open", str);
2428 const char *const *build_in = build_in_pcms;
2430 if (!strcmp(*build_in, str))
2434 if (*build_in == NULL) {
2435 buf1 = malloc(strlen(str) + sizeof(ALSA_PLUGIN_DIR) + 32);
2441 sprintf(buf1, "%s/libasound_module_pcm_%s.so", ALSA_PLUGIN_DIR, str);
2445 snd_pcm_open_symbols(); /* this call is for static linking only */
2447 open_func = snd_dlobj_cache_get(lib, open_name,
2448 SND_DLSYM_VERSION(SND_PCM_DLSYM_VERSION), 1);
2450 err = open_func(pcmp, name, pcm_root, pcm_conf, stream, mode);
2452 if ((*pcmp)->open_func) {
2453 /* only init plugin (like empty, asym) */
2454 snd_dlobj_cache_put(open_func);
2456 (*pcmp)->open_func = open_func;
2460 snd_dlobj_cache_put(open_func);
2466 err = snd_config_search(pcm_root, "defaults.pcm.compat", &tmp);
2469 if (snd_config_get_integer(tmp, &i) >= 0) {
2471 (*pcmp)->compat = 1;
2474 char *str = getenv("LIBASOUND_COMPAT");
2476 (*pcmp)->compat = 1;
2478 err = snd_config_search(pcm_root, "defaults.pcm.minperiodtime", &tmp);
2480 snd_config_get_integer(tmp, &(*pcmp)->minperiodtime);
2485 snd_config_delete(type_conf);
2491 static int snd_pcm_open_noupdate(snd_pcm_t **pcmp, snd_config_t *root,
2492 const char *name, snd_pcm_stream_t stream,
2496 snd_config_t *pcm_conf;
2499 err = snd_config_search_definition(root, "pcm", name, &pcm_conf);
2501 SNDERR("Unknown PCM %s", name);
2504 if (snd_config_get_string(pcm_conf, &str) >= 0)
2505 err = snd_pcm_open_noupdate(pcmp, root, str, stream, mode,
2508 snd_config_set_hop(pcm_conf, hop);
2509 err = snd_pcm_open_conf(pcmp, name, root, pcm_conf, stream, mode);
2511 snd_config_delete(pcm_conf);
2516 * \brief Opens a PCM
2517 * \param pcmp Returned PCM handle
2518 * \param name ASCII identifier of the PCM handle
2519 * \param stream Wanted stream
2520 * \param mode Open mode (see #SND_PCM_NONBLOCK, #SND_PCM_ASYNC)
2521 * \return 0 on success otherwise a negative error code
2523 int snd_pcm_open(snd_pcm_t **pcmp, const char *name,
2524 snd_pcm_stream_t stream, int mode)
2529 assert(pcmp && name);
2530 err = snd_config_update_ref(&top);
2533 err = snd_pcm_open_noupdate(pcmp, top, name, stream, mode, 0);
2534 snd_config_unref(top);
2539 * \brief Opens a PCM using local configuration
2540 * \param pcmp Returned PCM handle
2541 * \param name ASCII identifier of the PCM handle
2542 * \param stream Wanted stream
2543 * \param mode Open mode (see #SND_PCM_NONBLOCK, #SND_PCM_ASYNC)
2544 * \param lconf Local configuration
2545 * \return 0 on success otherwise a negative error code
2547 int snd_pcm_open_lconf(snd_pcm_t **pcmp, const char *name,
2548 snd_pcm_stream_t stream, int mode,
2549 snd_config_t *lconf)
2551 assert(pcmp && name && lconf);
2552 return snd_pcm_open_noupdate(pcmp, lconf, name, stream, mode, 0);
2556 * \brief Opens a fallback PCM
2557 * \param pcmp Returned PCM handle
2558 * \param root Configuration root
2559 * \param name ASCII identifier of the PCM handle
2560 * \param orig_name The original ASCII name
2561 * \param stream Wanted stream
2562 * \param mode Open mode (see #SND_PCM_NONBLOCK, #SND_PCM_ASYNC)
2563 * \return 0 on success otherwise a negative error code
2565 int snd_pcm_open_fallback(snd_pcm_t **pcmp, snd_config_t *root,
2566 const char *name, const char *orig_name,
2567 snd_pcm_stream_t stream, int mode)
2570 assert(pcmp && name && root);
2571 err = snd_pcm_open_noupdate(pcmp, root, name, stream, mode, 0);
2573 free((*pcmp)->name);
2574 (*pcmp)->name = orig_name ? strdup(orig_name) : NULL;
2580 int snd_pcm_new(snd_pcm_t **pcmp, snd_pcm_type_t type, const char *name,
2581 snd_pcm_stream_t stream, int mode)
2584 #ifdef THREAD_SAFE_API
2585 pthread_mutexattr_t attr;
2588 pcm = calloc(1, sizeof(*pcm));
2593 pcm->name = strdup(name);
2594 pcm->stream = stream;
2596 pcm->poll_fd_count = 1;
2599 pcm->fast_op_arg = pcm;
2600 INIT_LIST_HEAD(&pcm->async_handlers);
2601 #ifdef THREAD_SAFE_API
2602 pthread_mutexattr_init(&attr);
2603 #ifdef HAVE_PTHREAD_MUTEX_RECURSIVE
2604 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
2606 pthread_mutex_init(&pcm->lock, &attr);
2607 /* use locking as default;
2608 * each plugin may suppress this in its open call
2611 if (mode & SND_PCM_ASYNC) {
2612 /* async handler may lead to a deadlock; suppose no MT */
2613 pcm->lock_enabled = 0;
2615 /* set lock_enabled field depending on $LIBASOUND_THREAD_SAFE */
2616 static int do_lock_enable = -1; /* uninitialized */
2618 /* evaluate env var only once at the first open for consistency */
2619 if (do_lock_enable == -1) {
2620 char *p = getenv("LIBASOUND_THREAD_SAFE");
2621 do_lock_enable = !p || *p != '0';
2623 pcm->lock_enabled = do_lock_enable;
2630 int snd_pcm_free(snd_pcm_t *pcm)
2634 free(pcm->hw.link_dst);
2635 free(pcm->appl.link_dst);
2636 snd_dlobj_cache_put(pcm->open_func);
2637 #ifdef THREAD_SAFE_API
2638 pthread_mutex_destroy(&pcm->lock);
2644 int snd_pcm_open_named_slave(snd_pcm_t **pcmp, const char *name,
2646 snd_config_t *conf, snd_pcm_stream_t stream,
2647 int mode, snd_config_t *parent_conf)
2652 if ((hop = snd_config_check_hop(parent_conf)) < 0)
2654 if (snd_config_get_string(conf, &str) >= 0)
2655 return snd_pcm_open_noupdate(pcmp, root, str, stream, mode,
2657 return snd_pcm_open_conf(pcmp, name, root, conf, stream, mode);
2662 * \brief Wait for a PCM to become ready
2663 * \param pcm PCM handle
2664 * \param timeout maximum time in milliseconds to wait,
2665 * a negative value means infinity
2666 * \return a positive value on success otherwise a negative error code
2667 * (-EPIPE for the xrun and -ESTRPIPE for the suspended status,
2668 * others for general errors)
2669 * \retval 0 timeout occurred
2670 * \retval 1 PCM stream is ready for I/O
2672 * The function is thread-safe when built with the proper option.
2674 int snd_pcm_wait(snd_pcm_t *pcm, int timeout)
2678 __snd_pcm_lock(pcm); /* forced lock */
2679 err = __snd_pcm_wait_in_lock(pcm, timeout);
2680 __snd_pcm_unlock(pcm);
2685 /* locked version */
2686 int __snd_pcm_wait_in_lock(snd_pcm_t *pcm, int timeout)
2688 if (!snd_pcm_may_wait_for_avail_min(pcm, snd_pcm_mmap_avail(pcm))) {
2689 /* check more precisely */
2690 switch (__snd_pcm_state(pcm)) {
2691 case SND_PCM_STATE_XRUN:
2693 case SND_PCM_STATE_SUSPENDED:
2695 case SND_PCM_STATE_DISCONNECTED:
2701 return snd_pcm_wait_nocheck(pcm, timeout);
2705 * like snd_pcm_wait() but doesn't check mmap_avail before calling poll()
2707 * used in drain code in some plugins
2709 * This function is called inside pcm lock.
2711 int snd_pcm_wait_nocheck(snd_pcm_t *pcm, int timeout)
2714 unsigned short revents = 0;
2715 int npfds, err, err_poll;
2717 npfds = __snd_pcm_poll_descriptors_count(pcm);
2718 if (npfds <= 0 || npfds >= 16) {
2719 SNDERR("Invalid poll_fds %d\n", npfds);
2722 pfd = alloca(sizeof(*pfd) * npfds);
2723 err = __snd_pcm_poll_descriptors(pcm, pfd, npfds);
2727 SNDMSG("invalid poll descriptors %d\n", err);
2731 __snd_pcm_unlock(pcm);
2732 err_poll = poll(pfd, npfds, timeout);
2733 __snd_pcm_lock(pcm);
2735 if (errno == EINTR && !PCMINABORT(pcm))
2741 err = __snd_pcm_poll_revents(pcm, pfd, npfds, &revents);
2744 if (revents & (POLLERR | POLLNVAL)) {
2745 /* check more precisely */
2746 switch (__snd_pcm_state(pcm)) {
2747 case SND_PCM_STATE_XRUN:
2749 case SND_PCM_STATE_SUSPENDED:
2751 case SND_PCM_STATE_DISCONNECTED:
2757 } while (!(revents & (POLLIN | POLLOUT)));
2758 #if 0 /* very useful code to test poll related problems */
2760 snd_pcm_sframes_t avail_update;
2761 __snd_pcm_hwsync(pcm);
2762 avail_update = __snd_pcm_avail_update(pcm);
2763 if (avail_update < (snd_pcm_sframes_t)pcm->avail_min) {
2764 printf("*** snd_pcm_wait() FATAL ERROR!!!\n");
2765 printf("avail_min = %li, avail_update = %li\n", pcm->avail_min, avail_update);
2769 return err_poll > 0 ? 1 : 0;
2774 * \brief Return number of frames ready to be read (capture) / written (playback)
2775 * \param pcm PCM handle
2776 * \return a positive number of frames ready otherwise a negative
2779 * On capture does all the actions needed to transport to application
2780 * level all the ready frames across underlying layers.
2782 * The position is not synced with hardware (driver) position in the sound
2783 * ring buffer in this function. This function is a light version of
2784 * #snd_pcm_avail() .
2786 * Using this function is ideal after poll() or select() when audio
2787 * file descriptor made the event and when application expects just period
2790 * Also this function might be called after #snd_pcm_delay() or
2791 * #snd_pcm_hwsync() functions to move private ring buffer pointers
2792 * in alsa-lib (the internal plugin chain).
2794 * The function is thread-safe when built with the proper option.
2796 snd_pcm_sframes_t snd_pcm_avail_update(snd_pcm_t *pcm)
2798 snd_pcm_sframes_t result;
2801 result = __snd_pcm_avail_update(pcm);
2802 snd_pcm_unlock(pcm);
2807 * \brief Return number of frames ready to be read (capture) / written (playback)
2808 * \param pcm PCM handle
2809 * \return a positive number of frames ready otherwise a negative
2812 * On capture does all the actions needed to transport to application
2813 * level all the ready frames across underlying layers.
2815 * The position is synced with hardware (driver) position in the sound
2816 * ring buffer in this functions.
2818 * The function is thread-safe when built with the proper option.
2820 snd_pcm_sframes_t snd_pcm_avail(snd_pcm_t *pcm)
2823 snd_pcm_sframes_t result;
2826 if (CHECK_SANITY(! pcm->setup)) {
2827 SNDMSG("PCM not set up");
2831 err = __snd_pcm_hwsync(pcm);
2835 result = __snd_pcm_avail_update(pcm);
2836 snd_pcm_unlock(pcm);
2841 * \brief Combine snd_pcm_avail and snd_pcm_delay functions
2842 * \param pcm PCM handle
2843 * \param availp Number of available frames in the ring buffer
2844 * \param delayp Total I/O latency in frames
2845 * \return zero on success otherwise a negative error code
2847 * The avail and delay values retuned are in sync.
2849 * The function is thread-safe when built with the proper option.
2851 int snd_pcm_avail_delay(snd_pcm_t *pcm,
2852 snd_pcm_sframes_t *availp,
2853 snd_pcm_sframes_t *delayp)
2855 snd_pcm_sframes_t sf;
2858 assert(pcm && availp && delayp);
2859 if (CHECK_SANITY(! pcm->setup)) {
2860 SNDMSG("PCM not set up");
2864 err = __snd_pcm_hwsync(pcm);
2867 sf = __snd_pcm_avail_update(pcm);
2872 err = __snd_pcm_delay(pcm, delayp);
2878 snd_pcm_unlock(pcm);
2883 * \brief Silence an area
2884 * \param dst_area area specification
2885 * \param dst_offset offset in frames inside area
2886 * \param samples samples to silence
2887 * \param format PCM sample format
2888 * \return 0 on success otherwise a negative error code
2890 int snd_pcm_area_silence(const snd_pcm_channel_area_t *dst_area, snd_pcm_uframes_t dst_offset,
2891 unsigned int samples, snd_pcm_format_t format)
2893 /* FIXME: sub byte resolution and odd dst_offset */
2895 unsigned int dst_step;
2898 if (!dst_area->addr)
2900 dst = snd_pcm_channel_area_addr(dst_area, dst_offset);
2901 width = snd_pcm_format_physical_width(format);
2902 silence = snd_pcm_format_silence_64(format);
2903 if (dst_area->step == (unsigned int) width) {
2904 unsigned int dwords = samples * width / 64;
2905 u_int64_t *dstp = (u_int64_t *)dst;
2906 samples -= dwords * 64 / width;
2907 while (dwords-- > 0)
2912 dst_step = dst_area->step / 8;
2915 u_int8_t s0 = silence & 0xf0;
2916 u_int8_t s1 = silence & 0x0f;
2917 int dstbit = dst_area->first % 8;
2918 int dstbit_step = dst_area->step % 8;
2919 while (samples-- > 0) {
2928 dstbit += dstbit_step;
2937 u_int8_t sil = silence;
2938 while (samples-- > 0) {
2945 u_int16_t sil = silence;
2946 while (samples-- > 0) {
2947 *(u_int16_t*)dst = sil;
2953 #ifdef SNDRV_LITTLE_ENDIAN
2954 *(dst + 0) = silence >> 0;
2955 *(dst + 1) = silence >> 8;
2956 *(dst + 2) = silence >> 16;
2958 *(dst + 2) = silence >> 0;
2959 *(dst + 1) = silence >> 8;
2960 *(dst + 0) = silence >> 16;
2964 u_int32_t sil = silence;
2965 while (samples-- > 0) {
2966 *(u_int32_t*)dst = sil;
2972 while (samples-- > 0) {
2973 *(u_int64_t*)dst = silence;
2979 SNDMSG("invalid format width %d", width);
2986 * \brief Silence one or more areas
2987 * \param dst_areas areas specification (one for each channel)
2988 * \param dst_offset offset in frames inside area
2989 * \param channels channels count
2990 * \param frames frames to silence
2991 * \param format PCM sample format
2992 * \return 0 on success otherwise a negative error code
2994 int snd_pcm_areas_silence(const snd_pcm_channel_area_t *dst_areas, snd_pcm_uframes_t dst_offset,
2995 unsigned int channels, snd_pcm_uframes_t frames, snd_pcm_format_t format)
2997 int width = snd_pcm_format_physical_width(format);
2998 while (channels > 0) {
2999 void *addr = dst_areas->addr;
3000 unsigned int step = dst_areas->step;
3001 const snd_pcm_channel_area_t *begin = dst_areas;
3002 int channels1 = channels;
3003 unsigned int chns = 0;
3009 if (channels1 == 0 ||
3010 dst_areas->addr != addr ||
3011 dst_areas->step != step ||
3012 dst_areas->first != dst_areas[-1].first + width)
3015 if (chns > 1 && chns * width == step) {
3016 /* Collapse the areas */
3017 snd_pcm_channel_area_t d;
3018 d.addr = begin->addr;
3019 d.first = begin->first;
3021 err = snd_pcm_area_silence(&d, dst_offset * chns, frames * chns, format);
3024 err = snd_pcm_area_silence(begin, dst_offset, frames, format);
3025 dst_areas = begin + 1;
3036 * \brief Copy an area
3037 * \param dst_area destination area specification
3038 * \param dst_offset offset in frames inside destination area
3039 * \param src_area source area specification
3040 * \param src_offset offset in frames inside source area
3041 * \param samples samples to copy
3042 * \param format PCM sample format
3043 * \return 0 on success otherwise a negative error code
3045 int snd_pcm_area_copy(const snd_pcm_channel_area_t *dst_area, snd_pcm_uframes_t dst_offset,
3046 const snd_pcm_channel_area_t *src_area, snd_pcm_uframes_t src_offset,
3047 unsigned int samples, snd_pcm_format_t format)
3049 /* FIXME: sub byte resolution and odd dst_offset */
3053 int src_step, dst_step;
3054 if (dst_area == src_area && dst_offset == src_offset)
3056 if (!src_area->addr)
3057 return snd_pcm_area_silence(dst_area, dst_offset, samples, format);
3058 src = snd_pcm_channel_area_addr(src_area, src_offset);
3059 if (!dst_area->addr)
3061 dst = snd_pcm_channel_area_addr(dst_area, dst_offset);
3062 width = snd_pcm_format_physical_width(format);
3063 if (src_area->step == (unsigned int) width &&
3064 dst_area->step == (unsigned int) width) {
3065 size_t bytes = samples * width / 8;
3066 samples -= bytes * 8 / width;
3067 assert(src < dst || src >= dst + bytes);
3068 assert(dst < src || dst >= src + bytes);
3069 memcpy(dst, src, bytes);
3073 src_step = src_area->step / 8;
3074 dst_step = dst_area->step / 8;
3077 int srcbit = src_area->first % 8;
3078 int srcbit_step = src_area->step % 8;
3079 int dstbit = dst_area->first % 8;
3080 int dstbit_step = dst_area->step % 8;
3081 while (samples-- > 0) {
3082 unsigned char srcval;
3084 srcval = *src & 0x0f;
3086 srcval = *src & 0xf0;
3093 srcbit += srcbit_step;
3099 dstbit += dstbit_step;
3108 while (samples-- > 0) {
3116 while (samples-- > 0) {
3117 *(u_int16_t*)dst = *(const u_int16_t*)src;
3124 while (samples-- > 0) {
3125 *(dst + 0) = *(src + 0);
3126 *(dst + 1) = *(src + 1);
3127 *(dst + 2) = *(src + 2);
3133 while (samples-- > 0) {
3134 *(u_int32_t*)dst = *(const u_int32_t*)src;
3141 while (samples-- > 0) {
3142 *(u_int64_t*)dst = *(const u_int64_t*)src;
3149 SNDMSG("invalid format width %d", width);
3156 * \brief Copy one or more areas
3157 * \param dst_areas destination areas specification (one for each channel)
3158 * \param dst_offset offset in frames inside destination area
3159 * \param src_areas source areas specification (one for each channel)
3160 * \param src_offset offset in frames inside source area
3161 * \param channels channels count
3162 * \param frames frames to copy
3163 * \param format PCM sample format
3164 * \return 0 on success otherwise a negative error code
3166 int snd_pcm_areas_copy(const snd_pcm_channel_area_t *dst_areas, snd_pcm_uframes_t dst_offset,
3167 const snd_pcm_channel_area_t *src_areas, snd_pcm_uframes_t src_offset,
3168 unsigned int channels, snd_pcm_uframes_t frames, snd_pcm_format_t format)
3170 int width = snd_pcm_format_physical_width(format);
3174 SNDMSG("invalid channels %d", channels);
3178 SNDMSG("invalid frames %ld", frames);
3181 while (channels > 0) {
3182 unsigned int step = src_areas->step;
3183 void *src_addr = src_areas->addr;
3184 const snd_pcm_channel_area_t *src_start = src_areas;
3185 void *dst_addr = dst_areas->addr;
3186 const snd_pcm_channel_area_t *dst_start = dst_areas;
3187 int channels1 = channels;
3188 unsigned int chns = 0;
3189 while (dst_areas->step == step) {
3194 if (channels1 == 0 ||
3195 src_areas->step != step ||
3196 src_areas->addr != src_addr ||
3197 dst_areas->addr != dst_addr ||
3198 src_areas->first != src_areas[-1].first + width ||
3199 dst_areas->first != dst_areas[-1].first + width)
3202 if (chns > 1 && chns * width == step) {
3203 if (src_offset != dst_offset ||
3204 src_start->addr != dst_start->addr ||
3205 src_start->first != dst_start->first) {
3206 /* Collapse the areas */
3207 snd_pcm_channel_area_t s, d;
3208 s.addr = src_start->addr;
3209 s.first = src_start->first;
3211 d.addr = dst_start->addr;
3212 d.first = dst_start->first;
3214 snd_pcm_area_copy(&d, dst_offset * chns,
3215 &s, src_offset * chns,
3216 frames * chns, format);
3220 snd_pcm_area_copy(dst_start, dst_offset,
3221 src_start, src_offset,
3223 src_areas = src_start + 1;
3224 dst_areas = dst_start + 1;
3231 static void dump_one_param(snd_pcm_hw_params_t *params, unsigned int k, snd_output_t *out)
3233 snd_output_printf(out, "%s: ", snd_pcm_hw_param_name(k));
3234 snd_pcm_hw_param_dump(params, k, out);
3235 snd_output_putc(out, '\n');
3239 * \brief Dump a PCM hardware configuration space
3240 * \param params Configuration space
3241 * \param out Output handle
3242 * \return 0 on success otherwise a negative error code
3244 int snd_pcm_hw_params_dump(snd_pcm_hw_params_t *params, snd_output_t *out)
3247 for (k = SND_PCM_HW_PARAM_FIRST_MASK; k <= SND_PCM_HW_PARAM_LAST_MASK; k++)
3248 dump_one_param(params, k, out);
3249 for (k = SND_PCM_HW_PARAM_FIRST_INTERVAL; k <= SND_PCM_HW_PARAM_LAST_INTERVAL; k++)
3250 dump_one_param(params, k, out);
3255 * \brief Check if hardware supports sample-resolution mmap for given configuration
3256 * \param params Configuration space
3257 * \retval 0 Hardware doesn't support sample-resolution mmap
3258 * \retval 1 Hardware supports sample-resolution mmap
3260 * This function should only be called when the configuration space
3261 * contains a single configuration. Call #snd_pcm_hw_params to choose
3262 * a single configuration from the configuration space.
3264 int snd_pcm_hw_params_can_mmap_sample_resolution(const snd_pcm_hw_params_t *params)
3267 if (CHECK_SANITY(params->info == ~0U)) {
3268 SNDMSG("invalid PCM info field");
3269 return 0; /* FIXME: should be a negative error? */
3271 return !!(params->info & SNDRV_PCM_INFO_MMAP_VALID);
3275 * \brief Check if hardware does double buffering for start/stop for given configuration
3276 * \param params Configuration space
3277 * \retval 0 Hardware doesn't do double buffering for start/stop
3278 * \retval 1 Hardware does double buffering for start/stop
3280 * This function should only be called when the configuration space
3281 * contains a single configuration. Call #snd_pcm_hw_params to choose
3282 * a single configuration from the configuration space.
3284 int snd_pcm_hw_params_is_double(const snd_pcm_hw_params_t *params)
3287 if (CHECK_SANITY(params->info == ~0U)) {
3288 SNDMSG("invalid PCM info field");
3289 return 0; /* FIXME: should be a negative error? */
3291 return !!(params->info & SNDRV_PCM_INFO_DOUBLE);
3295 * \brief Check if hardware does double buffering for data transfers for given configuration
3296 * \param params Configuration space
3297 * \retval 0 Hardware doesn't do double buffering for data transfers
3298 * \retval 1 Hardware does double buffering for data transfers
3300 * This function should only be called when the configuration space
3301 * contains a single configuration. Call #snd_pcm_hw_params to choose
3302 * a single configuration from the configuration space.
3304 int snd_pcm_hw_params_is_batch(const snd_pcm_hw_params_t *params)
3307 if (CHECK_SANITY(params->info == ~0U)) {
3308 SNDMSG("invalid PCM info field");
3309 return 0; /* FIXME: should be a negative error? */
3311 return !!(params->info & SNDRV_PCM_INFO_BATCH);
3315 * \brief Check if hardware does block transfers for samples for given configuration
3316 * \param params Configuration space
3317 * \retval 0 Hardware doesn't block transfers
3318 * \retval 1 Hardware does block transfers
3320 * This function should only be called when the configuration space
3321 * contains a single configuration. Call #snd_pcm_hw_params to choose
3322 * a single configuration from the configuration space.
3324 int snd_pcm_hw_params_is_block_transfer(const snd_pcm_hw_params_t *params)
3327 if (CHECK_SANITY(params->info == ~0U)) {
3328 SNDMSG("invalid PCM info field");
3329 return 0; /* FIXME: should be a negative error? */
3331 return !!(params->info & SNDRV_PCM_INFO_BLOCK_TRANSFER);
3335 * \brief Check if timestamps are monotonic for given configuration
3336 * \param params Configuration space
3337 * \retval 0 Device doesn't do monotomic timestamps
3338 * \retval 1 Device does monotonic timestamps
3340 * This function should only be called when the configuration space
3341 * contains a single configuration. Call #snd_pcm_hw_params to choose
3342 * a single configuration from the configuration space.
3344 int snd_pcm_hw_params_is_monotonic(const snd_pcm_hw_params_t *params)
3347 if (CHECK_SANITY(params->info == ~0U)) {
3348 SNDMSG("invalid PCM info field");
3349 return 0; /* FIXME: should be a negative error? */
3351 return !!(params->info & SND_PCM_INFO_MONOTONIC);
3355 * \brief Check if hardware supports overrange detection
3356 * \param params Configuration space
3357 * \retval 0 Hardware doesn't support overrange detection
3358 * \retval 1 Hardware supports overrange detection
3360 * This function should only be called when the configuration space
3361 * contains a single configuration. Call #snd_pcm_hw_params to choose
3362 * a single configuration from the configuration space.
3364 int snd_pcm_hw_params_can_overrange(const snd_pcm_hw_params_t *params)
3367 if (CHECK_SANITY(params->info == ~0U)) {
3368 SNDMSG("invalid PCM info field");
3369 return 0; /* FIXME: should be a negative error? */
3371 return !!(params->info & SNDRV_PCM_INFO_OVERRANGE);
3375 * \brief Check if hardware supports pause
3376 * \param params Configuration space
3377 * \retval 0 Hardware doesn't support pause
3378 * \retval 1 Hardware supports pause
3380 * This function should only be called when the configuration space
3381 * contains a single configuration. Call #snd_pcm_hw_params to choose
3382 * a single configuration from the configuration space.
3384 int snd_pcm_hw_params_can_pause(const snd_pcm_hw_params_t *params)
3387 if (CHECK_SANITY(params->info == ~0U)) {
3388 SNDMSG("invalid PCM info field");
3389 return 0; /* FIXME: should be a negative error? */
3391 return !!(params->info & SNDRV_PCM_INFO_PAUSE);
3395 * \brief Check if hardware supports resume
3396 * \param params Configuration space
3397 * \retval 0 Hardware doesn't support resume
3398 * \retval 1 Hardware supports resume
3400 * This function should only be called when the configuration space
3401 * contains a single configuration. Call #snd_pcm_hw_params to choose
3402 * a single configuration from the configuration space.
3404 int snd_pcm_hw_params_can_resume(const snd_pcm_hw_params_t *params)
3407 if (CHECK_SANITY(params->info == ~0U)) {
3408 SNDMSG("invalid PCM info field");
3409 return 0; /* FIXME: should be a negative error? */
3411 return !!(params->info & SNDRV_PCM_INFO_RESUME);
3415 * \brief Check if hardware does half-duplex only
3416 * \param params Configuration space
3417 * \retval 0 Hardware doesn't do half-duplex
3418 * \retval 1 Hardware does half-duplex
3420 * This function should only be called when the configuration space
3421 * contains a single configuration. Call #snd_pcm_hw_params to choose
3422 * a single configuration from the configuration space.
3424 int snd_pcm_hw_params_is_half_duplex(const snd_pcm_hw_params_t *params)
3427 if (CHECK_SANITY(params->info == ~0U)) {
3428 SNDMSG("invalid PCM info field");
3429 return 0; /* FIXME: should be a negative error? */
3431 return !!(params->info & SNDRV_PCM_INFO_HALF_DUPLEX);
3435 * \brief Check if hardware does joint-duplex (playback and capture are somewhat correlated)
3436 * \param params Configuration space
3437 * \retval 0 Hardware doesn't do joint-duplex
3438 * \retval 1 Hardware does joint-duplex
3440 * This function should only be called when the configuration space
3441 * contains a single configuration. Call #snd_pcm_hw_params to choose
3442 * a single configuration from the configuration space.
3444 int snd_pcm_hw_params_is_joint_duplex(const snd_pcm_hw_params_t *params)
3447 if (CHECK_SANITY(params->info == ~0U)) {
3448 SNDMSG("invalid PCM info field");
3449 return 0; /* FIXME: should be a negative error? */
3451 return !!(params->info & SNDRV_PCM_INFO_JOINT_DUPLEX);
3455 * \brief Check if hardware supports synchronized start with sample resolution
3456 * \param params Configuration space
3457 * \retval 0 Hardware doesn't support synchronized start
3458 * \retval 1 Hardware supports synchronized start
3460 * This function should only be called when the configuration space
3461 * contains a single configuration. Call #snd_pcm_hw_params to choose
3462 * a single configuration from the configuration space.
3464 int snd_pcm_hw_params_can_sync_start(const snd_pcm_hw_params_t *params)
3467 if (CHECK_SANITY(params->info == ~0U)) {
3468 SNDMSG("invalid PCM info field");
3469 return 0; /* FIXME: should be a negative error? */
3471 return !!(params->info & SNDRV_PCM_INFO_SYNC_START);
3475 * \brief Check if hardware can disable period wakeups
3476 * \param params Configuration space
3477 * \retval 0 Hardware cannot disable period wakeups
3478 * \retval 1 Hardware can disable period wakeups
3480 int snd_pcm_hw_params_can_disable_period_wakeup(const snd_pcm_hw_params_t *params)
3483 if (CHECK_SANITY(params->info == ~0U)) {
3484 SNDMSG("invalid PCM info field");
3485 return 0; /* FIXME: should be a negative error? */
3487 return !!(params->info & SNDRV_PCM_INFO_NO_PERIOD_WAKEUP);
3491 * \brief Check if hardware supports audio wallclock timestamps
3492 * \param params Configuration space
3493 * \retval 0 Hardware doesn't support audio wallclock timestamps
3494 * \retval 1 Hardware supports audio wallclock timestamps
3496 * This function should only be called when the configuration space
3497 * contains a single configuration. Call #snd_pcm_hw_params to choose
3498 * a single configuration from the configuration space.
3500 int snd_pcm_hw_params_supports_audio_wallclock_ts(const snd_pcm_hw_params_t *params)
3503 return snd_pcm_hw_params_supports_audio_ts_type(params,
3504 SNDRV_PCM_AUDIO_TSTAMP_TYPE_COMPAT);
3508 * \brief Check if hardware supports type of audio timestamps
3509 * \param params Configuration space
3510 * \param type Audio timestamp type
3511 * \retval 0 Hardware doesn't support type of audio timestamps
3512 * \retval 1 Hardware supports type of audio timestamps
3514 * This function should only be called when the configuration space
3515 * contains a single configuration. Call #snd_pcm_hw_params to choose
3516 * a single configuration from the configuration space.
3518 int snd_pcm_hw_params_supports_audio_ts_type(const snd_pcm_hw_params_t *params, int type)
3521 if (CHECK_SANITY(params->info == ~0U)) {
3522 SNDMSG("invalid PCM info field");
3523 return 0; /* FIXME: should be a negative error? */
3526 case SNDRV_PCM_AUDIO_TSTAMP_TYPE_COMPAT:
3527 return !!(params->info & SNDRV_PCM_INFO_HAS_WALL_CLOCK); /* deprecated */
3528 case SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT:
3529 return 1; /* always supported, based on hw_ptr */
3530 case SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK:
3531 return !!(params->info & SNDRV_PCM_INFO_HAS_LINK_ATIME);
3532 case SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_ABSOLUTE:
3533 return !!(params->info & SNDRV_PCM_INFO_HAS_LINK_ABSOLUTE_ATIME);
3534 case SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_ESTIMATED:
3535 return !!(params->info & SNDRV_PCM_INFO_HAS_LINK_ESTIMATED_ATIME);
3536 case SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_SYNCHRONIZED:
3537 return !!(params->info & SNDRV_PCM_INFO_HAS_LINK_SYNCHRONIZED_ATIME);
3544 * \brief Get rate exact info from a configuration space
3545 * \param params Configuration space
3546 * \param rate_num Pointer to returned rate numerator
3547 * \param rate_den Pointer to returned rate denominator
3548 * \return 0 otherwise a negative error code if the info is not available
3550 * This function should only be called when the configuration space
3551 * contains a single configuration. Call #snd_pcm_hw_params to choose
3552 * a single configuration from the configuration space.
3554 int snd_pcm_hw_params_get_rate_numden(const snd_pcm_hw_params_t *params,
3555 unsigned int *rate_num, unsigned int *rate_den)
3558 if (CHECK_SANITY(params->rate_den == 0)) {
3559 SNDMSG("invalid rate_den value");
3562 *rate_num = params->rate_num;
3563 *rate_den = params->rate_den;
3568 * \brief Get sample resolution info from a configuration space
3569 * \param params Configuration space
3570 * \return signification bits in sample otherwise a negative error code if the info is not available
3572 * This function should only be called when the configuration space
3573 * contains a single configuration. Call #snd_pcm_hw_params to choose
3574 * a single configuration from the configuration space.
3576 int snd_pcm_hw_params_get_sbits(const snd_pcm_hw_params_t *params)
3579 if (CHECK_SANITY(params->msbits == 0)) {
3580 SNDMSG("invalid msbits value");
3583 return params->msbits;
3587 * \brief Get hardware FIFO size info from a configuration space
3588 * \param params Configuration space
3589 * \return FIFO size in frames otherwise a negative error code if the info is not available
3591 * This function should only be called when the configuration space
3592 * contains a single configuration. Call #snd_pcm_hw_params to choose
3593 * a single configuration from the configuration space.
3595 int snd_pcm_hw_params_get_fifo_size(const snd_pcm_hw_params_t *params)
3598 if (CHECK_SANITY(params->info == ~0U)) {
3599 SNDMSG("invalid PCM info field");
3602 return params->fifo_size;
3606 * \brief Fill params with a full configuration space for a PCM
3607 * \param pcm PCM handle
3608 * \param params Configuration space
3610 * The configuration space will be filled with all possible ranges
3611 * for the PCM device.
3613 int snd_pcm_hw_params_any(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
3615 _snd_pcm_hw_params_any(params);
3616 return snd_pcm_hw_refine(pcm, params);
3620 * \brief get size of #snd_pcm_access_mask_t
3621 * \return size in bytes
3623 size_t snd_pcm_access_mask_sizeof()
3625 return sizeof(snd_pcm_access_mask_t);
3629 * \brief allocate an empty #snd_pcm_access_mask_t using standard malloc
3630 * \param ptr returned pointer
3631 * \return 0 on success otherwise negative error code
3633 int snd_pcm_access_mask_malloc(snd_pcm_access_mask_t **ptr)
3636 *ptr = calloc(1, sizeof(snd_pcm_access_mask_t));
3643 * \brief frees a previously allocated #snd_pcm_access_mask_t
3644 * \param obj pointer to object to free
3646 void snd_pcm_access_mask_free(snd_pcm_access_mask_t *obj)
3652 * \brief copy one #snd_pcm_access_mask_t to another
3653 * \param dst pointer to destination
3654 * \param src pointer to source
3656 void snd_pcm_access_mask_copy(snd_pcm_access_mask_t *dst, const snd_pcm_access_mask_t *src)
3663 * \brief reset all bits in a #snd_pcm_access_mask_t
3664 * \param mask pointer to mask
3666 void snd_pcm_access_mask_none(snd_pcm_access_mask_t *mask)
3668 snd_mask_none((snd_mask_t *) mask);
3672 * \brief set all bits in a #snd_pcm_access_mask_t
3673 * \param mask pointer to mask
3675 void snd_pcm_access_mask_any(snd_pcm_access_mask_t *mask)
3677 snd_mask_any((snd_mask_t *) mask);
3681 * \brief test the presence of an access type in a #snd_pcm_access_mask_t
3682 * \param mask pointer to mask
3683 * \param val access type
3685 int snd_pcm_access_mask_test(const snd_pcm_access_mask_t *mask, snd_pcm_access_t val)
3687 return snd_mask_test((const snd_mask_t *) mask, (unsigned long) val);
3691 * \brief test, if given a #snd_pcm_access_mask_t is empty
3692 * \param mask pointer to mask
3693 * \retval 0 not empty
3696 int snd_pcm_access_mask_empty(const snd_pcm_access_mask_t *mask)
3698 return snd_mask_empty((const snd_mask_t *) mask);
3702 * \brief make an access type present in a #snd_pcm_access_mask_t
3703 * \param mask pointer to mask
3704 * \param val access type
3706 void snd_pcm_access_mask_set(snd_pcm_access_mask_t *mask, snd_pcm_access_t val)
3708 snd_mask_set((snd_mask_t *) mask, (unsigned long) val);
3712 * \brief make an access type missing from a #snd_pcm_access_mask_t
3713 * \param mask pointer to mask
3714 * \param val access type
3716 void snd_pcm_access_mask_reset(snd_pcm_access_mask_t *mask, snd_pcm_access_t val)
3718 snd_mask_reset((snd_mask_t *) mask, (unsigned long) val);
3722 * \brief get size of #snd_pcm_format_mask_t
3723 * \return size in bytes
3725 size_t snd_pcm_format_mask_sizeof()
3727 return sizeof(snd_pcm_format_mask_t);
3731 * \brief allocate an empty #snd_pcm_format_mask_t using standard malloc
3732 * \param ptr returned pointer
3733 * \return 0 on success otherwise negative error code
3735 int snd_pcm_format_mask_malloc(snd_pcm_format_mask_t **ptr)
3738 *ptr = calloc(1, sizeof(snd_pcm_format_mask_t));
3745 * \brief frees a previously allocated #snd_pcm_format_mask_t
3746 * \param obj pointer to object to free
3748 void snd_pcm_format_mask_free(snd_pcm_format_mask_t *obj)
3754 * \brief copy one #snd_pcm_format_mask_t to another
3755 * \param dst pointer to destination
3756 * \param src pointer to source
3758 void snd_pcm_format_mask_copy(snd_pcm_format_mask_t *dst, const snd_pcm_format_mask_t *src)
3765 * \brief reset all bits in a #snd_pcm_format_mask_t
3766 * \param mask pointer to mask
3768 void snd_pcm_format_mask_none(snd_pcm_format_mask_t *mask)
3770 snd_mask_none((snd_mask_t *) mask);
3774 * \brief set all bits in a #snd_pcm_format_mask_t
3775 * \param mask pointer to mask
3777 void snd_pcm_format_mask_any(snd_pcm_format_mask_t *mask)
3779 snd_mask_any((snd_mask_t *) mask);
3783 * \brief test the presence of a format in a #snd_pcm_format_mask_t
3784 * \param mask pointer to mask
3787 int snd_pcm_format_mask_test(const snd_pcm_format_mask_t *mask, snd_pcm_format_t val)
3789 return snd_mask_test((const snd_mask_t *) mask, (unsigned long) val);
3793 * \brief test, if given a #snd_pcm_format_mask_t is empty
3794 * \param mask pointer to mask
3795 * \retval 0 not empty
3798 int snd_pcm_format_mask_empty(const snd_pcm_format_mask_t *mask)
3800 return snd_mask_empty((const snd_mask_t *) mask);
3804 * \brief make a format present in a #snd_pcm_format_mask_t
3805 * \param mask pointer to mask
3808 void snd_pcm_format_mask_set(snd_pcm_format_mask_t *mask, snd_pcm_format_t val)
3810 snd_mask_set((snd_mask_t *) mask, (unsigned long) val);
3814 * \brief make a format missing from a #snd_pcm_format_mask_t
3815 * \param mask pointer to mask
3818 void snd_pcm_format_mask_reset(snd_pcm_format_mask_t *mask, snd_pcm_format_t val)
3820 snd_mask_reset((snd_mask_t *) mask, (unsigned long) val);
3825 * \brief get size of #snd_pcm_subformat_mask_t
3826 * \return size in bytes
3828 size_t snd_pcm_subformat_mask_sizeof()
3830 return sizeof(snd_pcm_subformat_mask_t);
3834 * \brief allocate an empty #snd_pcm_subformat_mask_t using standard malloc
3835 * \param ptr returned pointer
3836 * \return 0 on success otherwise negative error code
3838 int snd_pcm_subformat_mask_malloc(snd_pcm_subformat_mask_t **ptr)
3841 *ptr = calloc(1, sizeof(snd_pcm_subformat_mask_t));
3848 * \brief frees a previously allocated #snd_pcm_subformat_mask_t
3849 * \param obj pointer to object to free
3851 void snd_pcm_subformat_mask_free(snd_pcm_subformat_mask_t *obj)
3857 * \brief copy one #snd_pcm_subformat_mask_t to another
3858 * \param dst pointer to destination
3859 * \param src pointer to source
3861 void snd_pcm_subformat_mask_copy(snd_pcm_subformat_mask_t *dst, const snd_pcm_subformat_mask_t *src)
3868 * \brief reset all bits in a #snd_pcm_subformat_mask_t
3869 * \param mask pointer to mask
3871 void snd_pcm_subformat_mask_none(snd_pcm_subformat_mask_t *mask)
3873 snd_mask_none((snd_mask_t *) mask);
3877 * \brief set all bits in a #snd_pcm_subformat_mask_t
3878 * \param mask pointer to mask
3880 void snd_pcm_subformat_mask_any(snd_pcm_subformat_mask_t *mask)
3882 snd_mask_any((snd_mask_t *) mask);
3886 * \brief test the presence of a subformat in a #snd_pcm_subformat_mask_t
3887 * \param mask pointer to mask
3888 * \param val subformat
3890 int snd_pcm_subformat_mask_test(const snd_pcm_subformat_mask_t *mask, snd_pcm_subformat_t val)
3892 return snd_mask_test((const snd_mask_t *) mask, (unsigned long) val);
3896 * \brief test, if given a #snd_pcm_subformat_mask_t is empty
3897 * \param mask pointer to mask
3898 * \retval 0 not empty
3901 int snd_pcm_subformat_mask_empty(const snd_pcm_subformat_mask_t *mask)
3903 return snd_mask_empty((const snd_mask_t *) mask);
3907 * \brief make a subformat present in a #snd_pcm_subformat_mask_t
3908 * \param mask pointer to mask
3909 * \param val subformat
3911 void snd_pcm_subformat_mask_set(snd_pcm_subformat_mask_t *mask, snd_pcm_subformat_t val)
3913 snd_mask_set((snd_mask_t *) mask, (unsigned long) val);
3917 * \brief make a subformat missing from a #snd_pcm_subformat_mask_t
3918 * \param mask pointer to mask
3919 * \param val subformat
3921 void snd_pcm_subformat_mask_reset(snd_pcm_subformat_mask_t *mask, snd_pcm_subformat_t val)
3923 snd_mask_reset((snd_mask_t *) mask, (unsigned long) val);
3928 * \brief get size of #snd_pcm_hw_params_t
3929 * \return size in bytes
3931 size_t snd_pcm_hw_params_sizeof()
3933 return sizeof(snd_pcm_hw_params_t);
3937 * \brief allocate an invalid #snd_pcm_hw_params_t using standard malloc
3938 * \param ptr returned pointer
3939 * \return 0 on success otherwise negative error code
3941 int snd_pcm_hw_params_malloc(snd_pcm_hw_params_t **ptr)
3944 *ptr = calloc(1, sizeof(snd_pcm_hw_params_t));
3951 * \brief frees a previously allocated #snd_pcm_hw_params_t
3952 * \param obj pointer to object to free
3954 void snd_pcm_hw_params_free(snd_pcm_hw_params_t *obj)
3960 * \brief copy one #snd_pcm_hw_params_t to another
3961 * \param dst pointer to destination
3962 * \param src pointer to source
3964 void snd_pcm_hw_params_copy(snd_pcm_hw_params_t *dst, const snd_pcm_hw_params_t *src)
3972 * \brief Extract access type from a configuration space
3973 * \param params Configuration space
3974 * \param access Returned value
3975 * \return access type otherwise a negative error code if the configuration space does not contain a single value
3978 int INTERNAL(snd_pcm_hw_params_get_access)(const snd_pcm_hw_params_t *params, snd_pcm_access_t *access)
3980 int snd_pcm_hw_params_get_access(const snd_pcm_hw_params_t *params, snd_pcm_access_t *access)
3984 int err = snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_ACCESS, &_val, NULL);
3991 * \brief Verify if an access type is available inside a configuration space for a PCM
3992 * \param pcm PCM handle
3993 * \param params Configuration space
3994 * \param access access type
3995 * \return 0 if available a negative error code otherwise
3997 int snd_pcm_hw_params_test_access(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t access)
3999 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_ACCESS, access, 0);
4003 * \brief Restrict a configuration space to contain only one access type
4004 * \param pcm PCM handle
4005 * \param params Configuration space
4006 * \param access access type
4007 * \return 0 otherwise a negative error code if configuration space would become empty
4009 int snd_pcm_hw_params_set_access(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t access)
4011 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_ACCESS, access, 0);
4015 * \brief Restrict a configuration space to contain only its first access type
4016 * \param pcm PCM handle
4017 * \param params Configuration space
4018 * \param access Returned first access type
4019 * \return 0 otherwise a negative error code
4022 int INTERNAL(snd_pcm_hw_params_set_access_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t *access)
4024 int snd_pcm_hw_params_set_access_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t *access)
4027 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_ACCESS, access, NULL);
4031 * \brief Restrict a configuration space to contain only its last access type
4032 * \param pcm PCM handle
4033 * \param params Configuration space
4034 * \param access Returned last access type
4035 * \return 0 otherwise a negative error code
4038 int INTERNAL(snd_pcm_hw_params_set_access_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t *access)
4040 int snd_pcm_hw_params_set_access_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t *access)
4043 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_ACCESS, access, NULL);
4047 * \brief Restrict a configuration space to contain only a set of access types
4048 * \param pcm PCM handle
4049 * \param params Configuration space
4050 * \param mask Access mask
4051 * \return 0 otherwise a negative error code
4053 int snd_pcm_hw_params_set_access_mask(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_mask_t *mask)
4055 return snd_pcm_hw_param_set_mask(pcm, params, SND_TRY, SND_PCM_HW_PARAM_ACCESS, (snd_mask_t *) mask);
4059 * \brief Get access mask from a configuration space
4060 * \param params Configuration space
4061 * \param mask Returned Access mask
4063 int snd_pcm_hw_params_get_access_mask(snd_pcm_hw_params_t *params, snd_pcm_access_mask_t *mask)
4065 if (params == NULL || mask == NULL)
4067 snd_pcm_access_mask_copy(mask, snd_pcm_hw_param_get_mask(params, SND_PCM_HW_PARAM_ACCESS));
4073 * \brief Extract format from a configuration space
4074 * \param params Configuration space
4075 * \param format returned format
4076 * \return format otherwise a negative error code if the configuration space does not contain a single value
4079 int INTERNAL(snd_pcm_hw_params_get_format)(const snd_pcm_hw_params_t *params, snd_pcm_format_t *format)
4081 int snd_pcm_hw_params_get_format(const snd_pcm_hw_params_t *params, snd_pcm_format_t *format)
4084 return snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_FORMAT, (unsigned int *)format, NULL);
4088 * \brief Verify if a format is available inside a configuration space for a PCM
4089 * \param pcm PCM handle
4090 * \param params Configuration space
4091 * \param format format
4092 * \return 0 if available a negative error code otherwise
4094 int snd_pcm_hw_params_test_format(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t format)
4096 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_FORMAT, format, 0);
4100 * \brief Restrict a configuration space to contain only one format
4101 * \param pcm PCM handle
4102 * \param params Configuration space
4103 * \param format format
4104 * \return 0 otherwise a negative error code
4106 int snd_pcm_hw_params_set_format(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t format)
4108 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_FORMAT, format, 0);
4112 * \brief Restrict a configuration space to contain only its first format
4113 * \param pcm PCM handle
4114 * \param params Configuration space
4115 * \param format Returned first format
4116 * \return 0 otherwise a negative error code
4119 int INTERNAL(snd_pcm_hw_params_set_format_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t *format)
4121 int snd_pcm_hw_params_set_format_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t *format)
4124 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_FORMAT, (unsigned int *)format, NULL);
4128 * \brief Restrict a configuration space to contain only its last format
4129 * \param pcm PCM handle
4130 * \param params Configuration space
4131 * \param format Returned last format
4132 * \return 0 otherwise a negative error code
4135 int INTERNAL(snd_pcm_hw_params_set_format_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t *format)
4137 int snd_pcm_hw_params_set_format_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t *format)
4140 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_FORMAT, (unsigned int *)format, NULL);
4144 * \brief Restrict a configuration space to contain only a set of formats
4145 * \param pcm PCM handle
4146 * \param params Configuration space
4147 * \param mask Format mask
4148 * \return 0 otherwise a negative error code
4150 int snd_pcm_hw_params_set_format_mask(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_mask_t *mask)
4152 return snd_pcm_hw_param_set_mask(pcm, params, SND_TRY, SND_PCM_HW_PARAM_FORMAT, (snd_mask_t *) mask);
4156 * \brief Get format mask from a configuration space
4157 * \param params Configuration space
4158 * \param mask Returned Format mask
4160 void snd_pcm_hw_params_get_format_mask(snd_pcm_hw_params_t *params, snd_pcm_format_mask_t *mask)
4162 snd_pcm_format_mask_copy(mask, snd_pcm_hw_param_get_mask(params, SND_PCM_HW_PARAM_FORMAT));
4167 * \brief Extract subformat from a configuration space
4168 * \param params Configuration space
4169 * \param subformat Returned subformat value
4170 * \return subformat otherwise a negative error code if the configuration space does not contain a single value
4173 int INTERNAL(snd_pcm_hw_params_get_subformat)(const snd_pcm_hw_params_t *params, snd_pcm_subformat_t *subformat)
4175 int snd_pcm_hw_params_get_subformat(const snd_pcm_hw_params_t *params, snd_pcm_subformat_t *subformat)
4178 return snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_SUBFORMAT, subformat, NULL);
4182 * \brief Verify if a subformat is available inside a configuration space for a PCM
4183 * \param pcm PCM handle
4184 * \param params Configuration space
4185 * \param subformat subformat value
4186 * \return 0 if available a negative error code otherwise
4188 int snd_pcm_hw_params_test_subformat(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t subformat)
4190 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_SUBFORMAT, subformat, 0);
4194 * \brief Restrict a configuration space to contain only one subformat
4195 * \param pcm PCM handle
4196 * \param params Configuration space
4197 * \param subformat subformat value
4198 * \return 0 otherwise a negative error code if configuration space would become empty
4200 int snd_pcm_hw_params_set_subformat(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t subformat)
4202 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_SUBFORMAT, subformat, 0);
4206 * \brief Restrict a configuration space to contain only its first subformat
4207 * \param pcm PCM handle
4208 * \param params Configuration space
4209 * \param subformat Returned subformat
4210 * \return 0 otherwise a negative error code
4213 int INTERNAL(snd_pcm_hw_params_set_subformat_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t *subformat)
4215 int snd_pcm_hw_params_set_subformat_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t *subformat)
4218 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_SUBFORMAT, subformat, NULL);
4222 * \brief Restrict a configuration space to contain only its last subformat
4223 * \param pcm PCM handle
4224 * \param params Configuration space
4225 * \param subformat Returned subformat
4226 * \return 0 otherwise a negative error code
4229 int INTERNAL(snd_pcm_hw_params_set_subformat_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t *subformat)
4231 int snd_pcm_hw_params_set_subformat_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t *subformat)
4234 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_SUBFORMAT, subformat, NULL);
4238 * \brief Restrict a configuration space to contain only a set of subformats
4239 * \param pcm PCM handle
4240 * \param params Configuration space
4241 * \param mask Subformat mask
4242 * \return 0 otherwise a negative error code
4244 int snd_pcm_hw_params_set_subformat_mask(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_mask_t *mask)
4246 return snd_pcm_hw_param_set_mask(pcm, params, SND_TRY, SND_PCM_HW_PARAM_SUBFORMAT, (snd_mask_t *) mask);
4250 * \brief Get subformat mask from a configuration space
4251 * \param params Configuration space
4252 * \param mask Returned Subformat mask
4254 void snd_pcm_hw_params_get_subformat_mask(snd_pcm_hw_params_t *params, snd_pcm_subformat_mask_t *mask)
4256 snd_pcm_subformat_mask_copy(mask, snd_pcm_hw_param_get_mask(params, SND_PCM_HW_PARAM_SUBFORMAT));
4261 * \brief Extract channels from a configuration space
4262 * \param params Configuration space
4263 * \param val Returned channels count
4264 * \return 0 otherwise a negative error code if the configuration space does not contain a single value
4267 int INTERNAL(snd_pcm_hw_params_get_channels)(const snd_pcm_hw_params_t *params, unsigned int *val)
4269 int snd_pcm_hw_params_get_channels(const snd_pcm_hw_params_t *params, unsigned int *val)
4272 return snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
4276 * \brief Extract minimum channels count from a configuration space
4277 * \param params Configuration space
4278 * \param val minimum channels count
4279 * \return 0 otherwise a negative error code
4282 int INTERNAL(snd_pcm_hw_params_get_channels_min)(const snd_pcm_hw_params_t *params, unsigned int *val)
4284 int snd_pcm_hw_params_get_channels_min(const snd_pcm_hw_params_t *params, unsigned int *val)
4287 return snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
4291 * \brief Extract maximum channels count from a configuration space
4292 * \param params Configuration space
4293 * \param val maximum channels count
4294 * \return 0 otherwise a negative error code
4297 int INTERNAL(snd_pcm_hw_params_get_channels_max)(const snd_pcm_hw_params_t *params, unsigned int *val)
4299 int snd_pcm_hw_params_get_channels_max(const snd_pcm_hw_params_t *params, unsigned int *val)
4302 return snd_pcm_hw_param_get_max(params, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
4306 * \brief Verify if a channels count is available inside a configuration space for a PCM
4307 * \param pcm PCM handle
4308 * \param params Configuration space
4309 * \param val channels count
4310 * \return 0 if available a negative error code otherwise
4312 int snd_pcm_hw_params_test_channels(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val)
4314 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_CHANNELS, val, 0);
4318 * \brief Restrict a configuration space to contain only one channels count
4319 * \param pcm PCM handle
4320 * \param params Configuration space
4321 * \param val channels count
4322 * \return 0 otherwise a negative error code if configuration space would become empty
4324 int snd_pcm_hw_params_set_channels(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val)
4326 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_CHANNELS, val, 0);
4330 * \brief Restrict a configuration space with a minimum channels count
4331 * \param pcm PCM handle
4332 * \param params Configuration space
4333 * \param val minimum channels count (on return filled with actual minimum)
4334 * \return 0 otherwise a negative error code if configuration space would become empty
4336 int snd_pcm_hw_params_set_channels_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4338 return snd_pcm_hw_param_set_min(pcm, params, SND_TRY, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
4342 * \brief Restrict a configuration space with a maximum channels count
4343 * \param pcm PCM handle
4344 * \param params Configuration space
4345 * \param val maximum channels count (on return filled with actual maximum)
4346 * \return 0 otherwise a negative error code if configuration space would become empty
4348 int snd_pcm_hw_params_set_channels_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4350 return snd_pcm_hw_param_set_max(pcm, params, SND_TRY, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
4354 * \brief Restrict a configuration space to have channels counts in a given range
4355 * \param pcm PCM handle
4356 * \param params Configuration space
4357 * \param min minimum channels count (on return filled with actual minimum)
4358 * \param max maximum channels count (on return filled with actual maximum)
4359 * \return 0 otherwise a negative error code if configuration space would become empty
4361 int snd_pcm_hw_params_set_channels_minmax(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *min, unsigned int *max)
4363 return snd_pcm_hw_param_set_minmax(pcm, params, SND_TRY, SND_PCM_HW_PARAM_CHANNELS, min, NULL, max, NULL);
4367 * \brief Restrict a configuration space to have channels count nearest to a target
4368 * \param pcm PCM handle
4369 * \param params Configuration space
4370 * \param val target channels count, returned chosen channels count
4371 * \return 0 otherwise a negative error code if configuration space is empty
4374 int INTERNAL(snd_pcm_hw_params_set_channels_near)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4376 int snd_pcm_hw_params_set_channels_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4379 return snd_pcm_hw_param_set_near(pcm, params, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
4383 * \brief Restrict a configuration space to contain only its minimum channels count
4384 * \param pcm PCM handle
4385 * \param params Configuration space
4386 * \param val minimum channels count
4387 * \return 0 otherwise a negative error code
4390 int INTERNAL(snd_pcm_hw_params_set_channels_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4392 int snd_pcm_hw_params_set_channels_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4395 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
4399 * \brief Restrict a configuration space to contain only its maximum channels count
4400 * \param pcm PCM handle
4401 * \param params Configuration space
4402 * \param val maximum channels count
4403 * \return 0 otherwise a negative error code
4406 int INTERNAL(snd_pcm_hw_params_set_channels_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4408 int snd_pcm_hw_params_set_channels_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4411 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
4416 * \brief Extract rate from a configuration space
4417 * \param params Configuration space
4418 * \param val Returned approximate rate
4419 * \param dir Sub unit direction
4420 * \return 0 otherwise a negative error code if the configuration space does not contain a single value
4422 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
4425 int INTERNAL(snd_pcm_hw_params_get_rate)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4427 int snd_pcm_hw_params_get_rate(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4430 return snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_RATE, val, dir);
4434 * \brief Extract minimum rate from a configuration space
4435 * \param params Configuration space
4436 * \param val Returned approximate minimum rate
4437 * \param dir Sub unit direction
4438 * \return 0 otherwise a negative error code
4440 * Exact value is <,=,> the returned one following dir (-1,0,1)
4443 int INTERNAL(snd_pcm_hw_params_get_rate_min)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4445 int snd_pcm_hw_params_get_rate_min(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4448 return snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_RATE, val, dir);
4452 * \brief Extract maximum rate from a configuration space
4453 * \param params Configuration space
4454 * \param val Returned approximate maximum rate
4455 * \param dir Sub unit direction
4456 * \return 0 otherwise a negative error code
4458 * Exact value is <,=,> the returned one following dir (-1,0,1)
4461 int INTERNAL(snd_pcm_hw_params_get_rate_max)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4463 int snd_pcm_hw_params_get_rate_max(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4466 return snd_pcm_hw_param_get_max(params, SND_PCM_HW_PARAM_RATE, val, dir);
4470 * \brief Verify if a rate is available inside a configuration space for a PCM
4471 * \param pcm PCM handle
4472 * \param params Configuration space
4473 * \param val approximate rate
4474 * \param dir Sub unit direction
4475 * \return 0 if available a negative error code otherwise
4477 * Wanted exact value is <,=,> val following dir (-1,0,1)
4479 int snd_pcm_hw_params_test_rate(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
4481 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_RATE, val, dir);
4485 * \brief Restrict a configuration space to contain only one rate
4486 * \param pcm PCM handle
4487 * \param params Configuration space
4488 * \param val approximate rate
4489 * \param dir Sub unit direction
4490 * \return 0 otherwise a negative error code if configuration space would become empty
4492 * Wanted exact value is <,=,> val following dir (-1,0,1)
4494 int snd_pcm_hw_params_set_rate(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
4496 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_RATE, val, dir);
4500 * \brief Restrict a configuration space with a minimum rate
4501 * \param pcm PCM handle
4502 * \param params Configuration space
4503 * \param val approximate minimum rate (on return filled with actual minimum)
4504 * \param dir Sub unit direction (on return filled with actual direction)
4505 * \return 0 otherwise a negative error code if configuration space would become empty
4507 * Wanted/actual exact minimum is <,=,> val following dir (-1,0,1)
4509 int snd_pcm_hw_params_set_rate_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4511 return snd_pcm_hw_param_set_min(pcm, params, SND_TRY, SND_PCM_HW_PARAM_RATE, val, dir);
4515 * \brief Restrict a configuration space with a maximum rate
4516 * \param pcm PCM handle
4517 * \param params Configuration space
4518 * \param val approximate maximum rate (on return filled with actual maximum)
4519 * \param dir Sub unit direction (on return filled with actual direction)
4520 * \return 0 otherwise a negative error code if configuration space would become empty
4522 * Wanted/actual exact maximum is <,=,> val following dir (-1,0,1)
4524 int snd_pcm_hw_params_set_rate_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4526 return snd_pcm_hw_param_set_max(pcm, params, SND_TRY, SND_PCM_HW_PARAM_RATE, val, dir);
4530 * \brief Restrict a configuration space to have rates in a given range
4531 * \param pcm PCM handle
4532 * \param params Configuration space
4533 * \param min approximate minimum rate (on return filled with actual minimum)
4534 * \param mindir Sub unit direction for minimum (on return filled with actual direction)
4535 * \param max approximate maximum rate (on return filled with actual maximum)
4536 * \param maxdir Sub unit direction for maximum (on return filled with actual direction)
4537 * \return 0 otherwise a negative error code if configuration space would become empty
4539 * Wanted/actual exact min/max is <,=,> val following dir (-1,0,1)
4541 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)
4543 return snd_pcm_hw_param_set_minmax(pcm, params, SND_TRY, SND_PCM_HW_PARAM_RATE, min, mindir, max, maxdir);
4547 * \brief Restrict a configuration space to have rate nearest to a target
4548 * \param pcm PCM handle
4549 * \param params Configuration space
4550 * \param val approximate target rate / returned approximate set rate
4551 * \param dir Sub unit direction
4552 * \return 0 otherwise a negative error code if configuration space is empty
4554 * target/chosen exact value is <,=,> val following dir (-1,0,1)
4557 int INTERNAL(snd_pcm_hw_params_set_rate_near)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4559 int snd_pcm_hw_params_set_rate_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4562 return snd_pcm_hw_param_set_near(pcm, params, SND_PCM_HW_PARAM_RATE, val, dir);
4566 * \brief Restrict a configuration space to contain only its minimum rate
4567 * \param pcm PCM handle
4568 * \param params Configuration space
4569 * \param val Returned minimum approximate rate
4570 * \param dir Sub unit direction
4571 * \return 0 otherwise a negative error code
4573 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
4576 int INTERNAL(snd_pcm_hw_params_set_rate_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4578 int snd_pcm_hw_params_set_rate_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4581 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_RATE, val, dir);
4585 * \brief Restrict a configuration space to contain only its maximum rate
4586 * \param pcm PCM handle
4587 * \param params Configuration space
4588 * \param val Returned maximum approximate rate
4589 * \param dir Sub unit direction
4590 * \return 0 otherwise a negative error code
4592 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
4595 int INTERNAL(snd_pcm_hw_params_set_rate_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4597 int snd_pcm_hw_params_set_rate_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4600 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_RATE, val, dir);
4604 * \brief Restrict a configuration space to contain only real hardware rates
4605 * \param pcm PCM handle
4606 * \param params Configuration space
4607 * \param val 0 = disable, 1 = enable (default) rate resampling
4608 * \return 0 otherwise a negative error code
4610 int snd_pcm_hw_params_set_rate_resample(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val)
4612 assert(pcm && params);
4614 params->flags |= SND_PCM_HW_PARAMS_NORESAMPLE;
4616 params->flags &= ~SND_PCM_HW_PARAMS_NORESAMPLE;
4618 return snd_pcm_hw_refine(pcm, params);
4622 * \brief Extract resample state from a configuration space
4623 * \param pcm PCM handle
4624 * \param params Configuration space
4625 * \param val 0 = disable, 1 = enable rate resampling
4626 * \return 0 otherwise a negative error code
4628 int snd_pcm_hw_params_get_rate_resample(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4630 assert(pcm && params && val);
4631 *val = params->flags & SND_PCM_HW_PARAMS_NORESAMPLE ? 0 : 1;
4636 * \brief Restrict a configuration space to allow the buffer to be accessible from outside
4637 * \param pcm PCM handle
4638 * \param params Configuration space
4639 * \param val 0 = disable, 1 = enable (default) exporting buffer
4640 * \return 0 otherwise a negative error code
4642 int snd_pcm_hw_params_set_export_buffer(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val)
4644 assert(pcm && params);
4646 params->flags |= SND_PCM_HW_PARAMS_EXPORT_BUFFER;
4648 params->flags &= ~SND_PCM_HW_PARAMS_EXPORT_BUFFER;
4650 return snd_pcm_hw_refine(pcm, params);
4654 * \brief Extract buffer accessibility from a configuration space
4655 * \param pcm PCM handle
4656 * \param params Configuration space
4657 * \param val 0 = disable, 1 = enable exporting buffer
4658 * \return 0 otherwise a negative error code
4660 int snd_pcm_hw_params_get_export_buffer(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4662 assert(pcm && params && val);
4663 *val = params->flags & SND_PCM_HW_PARAMS_EXPORT_BUFFER ? 1 : 0;
4668 * \brief Restrict a configuration space to settings without period wakeups
4669 * \param pcm PCM handle
4670 * \param params Configuration space
4671 * \param val 0 = disable, 1 = enable (default) period wakeup
4672 * \return Zero on success, otherwise a negative error code.
4674 * This function must be called only on devices where non-blocking mode is
4677 * To check whether the hardware does support disabling period wakeups, call
4678 * #snd_pcm_hw_params_can_disable_period_wakeup(). If the hardware does not
4679 * support this mode, standard period wakeups will be generated.
4681 * Even with disabled period wakeups, the period size/time/count parameters
4682 * are valid; it is suggested to use #snd_pcm_hw_params_set_period_size_last().
4684 * When period wakeups are disabled, the application must not use any functions
4685 * that could block on this device. The use of poll should be limited to error
4686 * cases. The application needs to use an external event or a timer to
4687 * check the state of the ring buffer and refill it apropriately.
4689 int snd_pcm_hw_params_set_period_wakeup(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val)
4691 assert(pcm && params);
4694 if (!(pcm->mode & SND_PCM_NONBLOCK))
4696 params->flags |= SND_PCM_HW_PARAMS_NO_PERIOD_WAKEUP;
4698 params->flags &= ~SND_PCM_HW_PARAMS_NO_PERIOD_WAKEUP;
4701 return snd_pcm_hw_refine(pcm, params);
4705 * \brief Extract period wakeup flag from a configuration space
4706 * \param pcm PCM handle
4707 * \param params Configuration space
4708 * \param val 0 = disabled, 1 = enabled period wakeups
4709 * \return Zero on success, otherwise a negative error code.
4711 int snd_pcm_hw_params_get_period_wakeup(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4713 assert(pcm && params && val);
4714 *val = params->flags & SND_PCM_HW_PARAMS_NO_PERIOD_WAKEUP ? 0 : 1;
4719 * \brief Extract period time from a configuration space
4720 * \param params Configuration space
4721 * \param val Returned approximate period duration in us
4722 * \param dir Sub unit direction
4723 * \return 0 otherwise a negative error code if the configuration space does not contain a single value
4725 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
4728 int INTERNAL(snd_pcm_hw_params_get_period_time)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4730 int snd_pcm_hw_params_get_period_time(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4733 return snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
4737 * \brief Extract minimum period time from a configuration space
4738 * \param params Configuration space
4739 * \param val approximate minimum period duration in us
4740 * \param dir Sub unit direction
4741 * \return 0 otherwise a negative error code
4743 * Exact value is <,=,> the returned one following dir (-1,0,1)
4746 int INTERNAL(snd_pcm_hw_params_get_period_time_min)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4748 int snd_pcm_hw_params_get_period_time_min(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4751 return snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
4755 * \brief Extract maximum period time from a configuration space
4756 * \param params Configuration space
4757 * \param val approximate maximum period duration in us
4758 * \param dir Sub unit direction
4759 * \return 0 otherwise a negative error code
4761 * Exact value is <,=,> the returned one following dir (-1,0,1)
4764 int INTERNAL(snd_pcm_hw_params_get_period_time_max)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4766 int snd_pcm_hw_params_get_period_time_max(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4769 return snd_pcm_hw_param_get_max(params, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
4773 * \brief Verify if a period time is available inside a configuration space for a PCM
4774 * \param pcm PCM handle
4775 * \param params Configuration space
4776 * \param val approximate period duration in us
4777 * \param dir Sub unit direction
4778 * \return 0 if available a negative error code otherwise
4780 * Wanted exact value is <,=,> val following dir (-1,0,1)
4782 int snd_pcm_hw_params_test_period_time(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
4784 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
4788 * \brief Restrict a configuration space to contain only one period time
4789 * \param pcm PCM handle
4790 * \param params Configuration space
4791 * \param val approximate period duration in us
4792 * \param dir Sub unit direction
4793 * \return 0 otherwise a negative error code if configuration space would become empty
4795 * Wanted exact value is <,=,> val following dir (-1,0,1)
4797 int snd_pcm_hw_params_set_period_time(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
4799 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
4804 * \brief Restrict a configuration space with a minimum period time
4805 * \param pcm PCM handle
4806 * \param params Configuration space
4807 * \param val approximate minimum period duration in us (on return filled with actual minimum)
4808 * \param dir Sub unit direction (on return filled with actual direction)
4809 * \return 0 otherwise a negative error code if configuration space would become empty
4811 * Wanted/actual exact minimum is <,=,> val following dir (-1,0,1)
4813 int snd_pcm_hw_params_set_period_time_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4815 return snd_pcm_hw_param_set_min(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
4819 * \brief Restrict a configuration space with a maximum period time
4820 * \param pcm PCM handle
4821 * \param params Configuration space
4822 * \param val approximate maximum period duration in us (on return filled with actual maximum)
4823 * \param dir Sub unit direction (on return filled with actual direction)
4824 * \return 0 otherwise a negative error code if configuration space would become empty
4826 * Wanted/actual exact maximum is <,=,> val following dir (-1,0,1)
4828 int snd_pcm_hw_params_set_period_time_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4830 return snd_pcm_hw_param_set_max(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
4834 * \brief Restrict a configuration space to have period times in a given range
4835 * \param pcm PCM handle
4836 * \param params Configuration space
4837 * \param min approximate minimum period duration in us (on return filled with actual minimum)
4838 * \param mindir Sub unit direction for minimum (on return filled with actual direction)
4839 * \param max approximate maximum period duration in us (on return filled with actual maximum)
4840 * \param maxdir Sub unit direction for maximum (on return filled with actual direction)
4841 * \return 0 otherwise a negative error code if configuration space would become empty
4843 * Wanted/actual exact min/max is <,=,> val following dir (-1,0,1)
4845 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)
4847 return snd_pcm_hw_param_set_minmax(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_TIME, min, mindir, max, maxdir);
4851 * \brief Restrict a configuration space to have period time nearest to a target
4852 * \param pcm PCM handle
4853 * \param params Configuration space
4854 * \param val approximate target period duration in us / returned chosen approximate target period duration
4855 * \param dir Sub unit direction
4856 * \return 0 otherwise a negative error code if configuration space is empty
4858 * target/chosen exact value is <,=,> val following dir (-1,0,1)
4861 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)
4863 int snd_pcm_hw_params_set_period_time_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4866 return snd_pcm_hw_param_set_near(pcm, params, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
4870 * \brief Restrict a configuration space to contain only its minimum period time
4871 * \param pcm PCM handle
4872 * \param params Configuration space
4873 * \param val Returned approximate period duration in us
4874 * \param dir Sub unit direction
4875 * \return 0 otherwise a negative error code
4877 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
4880 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)
4882 int snd_pcm_hw_params_set_period_time_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4885 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
4889 * \brief Restrict a configuration space to contain only its maximum period time
4890 * \param pcm PCM handle
4891 * \param params Configuration space
4892 * \param val Returned maximum approximate period time
4893 * \param dir Sub unit direction
4894 * \return approximate period duration in us
4897 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)
4899 int snd_pcm_hw_params_set_period_time_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4902 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
4907 * \brief Extract period size from a configuration space
4908 * \param params Configuration space
4909 * \param val Returned approximate period size in frames
4910 * \param dir Sub unit direction
4911 * \return 0 otherwise a negative error code if the configuration space does not contain a single value
4913 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
4916 int INTERNAL(snd_pcm_hw_params_get_period_size)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
4918 int snd_pcm_hw_params_get_period_size(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
4922 int err = snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
4929 * \brief Extract minimum period size from a configuration space
4930 * \param params Configuration space
4931 * \param val approximate minimum period size in frames
4932 * \param dir Sub unit direction
4933 * \return 0 otherwise a negative error code
4935 * Exact value is <,=,> the returned one following dir (-1,0,1)
4938 int INTERNAL(snd_pcm_hw_params_get_period_size_min)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
4940 int snd_pcm_hw_params_get_period_size_min(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
4943 unsigned int _val = *val;
4944 int err = snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
4951 * \brief Extract maximum period size from a configuration space
4952 * \param params Configuration space
4953 * \param val approximate minimum period size in frames
4954 * \param dir Sub unit direction
4955 * \return 0 otherwise a negative error code
4957 * Exact value is <,=,> the returned one following dir (-1,0,1)
4960 int INTERNAL(snd_pcm_hw_params_get_period_size_max)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
4962 int snd_pcm_hw_params_get_period_size_max(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
4965 unsigned int _val = *val;
4966 int err = snd_pcm_hw_param_get_max(params, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
4973 * \brief Verify if a period size is available inside a configuration space for a PCM
4974 * \param pcm PCM handle
4975 * \param params Configuration space
4976 * \param val approximate period size in frames
4977 * \param dir Sub unit direction
4978 * \return 0 if available a negative error code otherwise
4980 * Wanted exact value is <,=,> val following dir (-1,0,1)
4982 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)
4984 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_PERIOD_SIZE, val, dir);
4988 * \brief Restrict a configuration space to contain only one period size
4989 * \param pcm PCM handle
4990 * \param params Configuration space
4991 * \param val approximate period size in frames
4992 * \param dir Sub unit direction
4993 * \return 0 otherwise a negative error code if configuration space would become empty
4995 * Wanted exact value is <,=,> val following dir (-1,0,1)
4997 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)
4999 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_SIZE, val, dir);
5003 * \brief Restrict a configuration space with a minimum period size
5004 * \param pcm PCM handle
5005 * \param params Configuration space
5006 * \param val approximate minimum period size in frames (on return filled with actual minimum)
5007 * \param dir Sub unit direction (on return filled with actual direction)
5008 * \return 0 otherwise a negative error code if configuration space would become empty
5010 * Wanted/actual exact minimum is <,=,> val following dir (-1,0,1)
5012 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)
5014 unsigned int _val = *val;
5015 int err = snd_pcm_hw_param_set_min(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
5022 * \brief Restrict a configuration space with a maximum period size
5023 * \param pcm PCM handle
5024 * \param params Configuration space
5025 * \param val approximate maximum period size in frames (on return filled with actual maximum)
5026 * \param dir Sub unit direction (on return filled with actual direction)
5027 * \return 0 otherwise a negative error code if configuration space would become empty
5029 * Wanted/actual exact minimum is <,=,> val following dir (-1,0,1)
5031 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)
5033 unsigned int _val = *val;
5034 int err = snd_pcm_hw_param_set_max(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
5041 * \brief Restrict a configuration space to have period sizes in a given range
5042 * \param pcm PCM handle
5043 * \param params Configuration space
5044 * \param min approximate minimum period size in frames (on return filled with actual minimum)
5045 * \param mindir Sub unit direction for minimum (on return filled with actual direction)
5046 * \param max approximate maximum period size in frames (on return filled with actual maximum)
5047 * \param maxdir Sub unit direction for maximum (on return filled with actual direction)
5048 * \return 0 otherwise a negative error code if configuration space would become empty
5050 * Wanted/actual exact min/max is <,=,> val following dir (-1,0,1)
5052 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)
5054 unsigned int _min = *min;
5055 unsigned int _max = *max;
5056 int err = snd_pcm_hw_param_set_minmax(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_SIZE, &_min, mindir, &_max, maxdir);
5063 * \brief Restrict a configuration space to have period size nearest to a target
5064 * \param pcm PCM handle
5065 * \param params Configuration space
5066 * \param val approximate target period size in frames / returned chosen approximate target period size
5067 * \param dir Sub unit direction
5068 * \return 0 otherwise a negative error code if configuration space is empty
5070 * target/chosen exact value is <,=,> val following dir (-1,0,1)
5073 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)
5075 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)
5078 unsigned int _val = *val;
5079 int err = snd_pcm_hw_param_set_near(pcm, params, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
5086 * \brief Restrict a configuration space to contain only its minimum period size
5087 * \param pcm PCM handle
5088 * \param params Configuration space
5089 * \param val Returned maximum approximate period size in frames
5090 * \param dir Sub unit direction
5091 * \return 0 otherwise a negative error code
5093 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5096 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)
5098 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)
5102 int err = snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
5109 * \brief Restrict a configuration space to contain only its maximum period size
5110 * \param pcm PCM handle
5111 * \param params Configuration space
5112 * \param val Returned maximum approximate period size in frames
5113 * \param dir Sub unit direction
5114 * \return 0 otherwise a negative error code
5116 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5119 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)
5121 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)
5125 int err = snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
5132 * \brief Restrict a configuration space to contain only integer period sizes
5133 * \param pcm PCM handle
5134 * \param params Configuration space
5135 * \return 0 otherwise a negative error code if configuration space would become empty
5137 int snd_pcm_hw_params_set_period_size_integer(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
5139 return snd_pcm_hw_param_set_integer(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_SIZE);
5144 * \brief Extract periods from a configuration space
5145 * \param params Configuration space
5146 * \param val approximate periods per buffer
5147 * \param dir Sub unit direction
5148 * \return 0 otherwise a negative error code if the configuration space does not contain a single value
5150 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5153 int INTERNAL(snd_pcm_hw_params_get_periods)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5155 int snd_pcm_hw_params_get_periods(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5158 return snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_PERIODS, val, dir);
5162 * \brief Extract minimum periods count from a configuration space
5163 * \param params Configuration space
5164 * \param val approximate minimum periods per buffer
5165 * \param dir Sub unit direction
5166 * \return 0 otherwise a negative error code
5168 * Exact value is <,=,> the returned one following dir (-1,0,1)
5171 int INTERNAL(snd_pcm_hw_params_get_periods_min)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5173 int snd_pcm_hw_params_get_periods_min(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5176 return snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_PERIODS, val, dir);
5180 * \brief Extract maximum periods count from a configuration space
5181 * \param params Configuration space
5182 * \param val approximate maximum periods per buffer
5183 * \param dir Sub unit direction
5184 * \return 0 otherwise a negative error code
5186 * Exact value is <,=,> the returned one following dir (-1,0,1)
5189 int INTERNAL(snd_pcm_hw_params_get_periods_max)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5191 int snd_pcm_hw_params_get_periods_max(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5194 return snd_pcm_hw_param_get_max(params, SND_PCM_HW_PARAM_PERIODS, val, dir);
5198 * \brief Verify if a periods count is available inside a configuration space for a PCM
5199 * \param pcm PCM handle
5200 * \param params Configuration space
5201 * \param val approximate periods per buffer
5202 * \param dir Sub unit direction
5203 * \return 0 if available a negative error code otherwise
5205 * Wanted exact value is <,=,> val following dir (-1,0,1)
5207 int snd_pcm_hw_params_test_periods(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
5209 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_PERIODS, val, dir);
5213 * \brief Restrict a configuration space to contain only one periods count
5214 * \param pcm PCM handle
5215 * \param params Configuration space
5216 * \param val approximate periods per buffer
5217 * \param dir Sub unit direction
5218 * \return 0 otherwise a negative error code if configuration space would become empty
5220 * Wanted exact value is <,=,> val following dir (-1,0,1)
5222 int snd_pcm_hw_params_set_periods(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
5224 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIODS, val, dir);
5228 * \brief Restrict a configuration space with a minimum periods count
5229 * \param pcm PCM handle
5230 * \param params Configuration space
5231 * \param val approximate minimum periods per buffer (on return filled with actual minimum)
5232 * \param dir Sub unit direction (on return filled with actual direction)
5233 * \return 0 otherwise a negative error code if configuration space would become empty
5235 * Wanted/actual exact minimum is <,=,> val following dir (-1,0,1)
5237 int snd_pcm_hw_params_set_periods_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5239 return snd_pcm_hw_param_set_min(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIODS, val, dir);
5243 * \brief Restrict a configuration space with a maximum periods count
5244 * \param pcm PCM handle
5245 * \param params Configuration space
5246 * \param val approximate maximum periods per buffer (on return filled with actual maximum)
5247 * \param dir Sub unit direction (on return filled with actual direction)
5248 * \return 0 otherwise a negative error code if configuration space would become empty
5250 * Wanted/actual exact maximum is <,=,> val following dir (-1,0,1)
5252 int snd_pcm_hw_params_set_periods_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5254 return snd_pcm_hw_param_set_max(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIODS, val, dir);
5258 * \brief Restrict a configuration space to have periods counts in a given range
5259 * \param pcm PCM handle
5260 * \param params Configuration space
5261 * \param min approximate minimum periods per buffer (on return filled with actual minimum)
5262 * \param mindir Sub unit direction for minimum (on return filled with actual direction)
5263 * \param max approximate maximum periods per buffer (on return filled with actual maximum)
5264 * \param maxdir Sub unit direction for maximum (on return filled with actual direction)
5265 * \return 0 otherwise a negative error code if configuration space would become empty
5267 * Wanted/actual exact min/max is <,=,> val following dir (-1,0,1)
5269 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)
5271 return snd_pcm_hw_param_set_minmax(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIODS, min, mindir, max, maxdir);
5275 * \brief Restrict a configuration space to have periods count nearest to a target
5276 * \param pcm PCM handle
5277 * \param params Configuration space
5278 * \param val approximate target periods per buffer / returned chosen approximate target periods per buffer
5279 * \param dir Sub unit direction
5280 * \return 0 otherwise a negative error code if configuration space is empty
5282 * target/chosen exact value is <,=,> val following dir (-1,0,1)
5285 int INTERNAL(snd_pcm_hw_params_set_periods_near)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5287 int snd_pcm_hw_params_set_periods_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5290 return snd_pcm_hw_param_set_near(pcm, params, SND_PCM_HW_PARAM_PERIODS, val, dir);
5294 * \brief Restrict a configuration space to contain only its minimum periods count
5295 * \param pcm PCM handle
5296 * \param params Configuration space
5297 * \param val Returned approximate minimum periods per buffer
5298 * \param dir Sub unit direction
5299 * \return 0 otherwise a negative error code
5301 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5304 int INTERNAL(snd_pcm_hw_params_set_periods_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5306 int snd_pcm_hw_params_set_periods_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5309 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_PERIODS, val, dir);
5313 * \brief Restrict a configuration space to contain only its maximum periods count
5314 * \param pcm PCM handle
5315 * \param params Configuration space
5316 * \param val Returned approximate maximum periods per buffer
5317 * \param dir Sub unit direction
5318 * \return 0 otherwise a negative error code
5320 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5323 int INTERNAL(snd_pcm_hw_params_set_periods_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5325 int snd_pcm_hw_params_set_periods_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5328 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_PERIODS, val, dir);
5332 * \brief Restrict a configuration space to contain only integer periods counts
5333 * \param pcm PCM handle
5334 * \param params Configuration space
5335 * \return 0 otherwise a negative error code if configuration space would become empty
5337 int snd_pcm_hw_params_set_periods_integer(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
5339 return snd_pcm_hw_param_set_integer(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIODS);
5344 * \brief Extract buffer time from a configuration space
5345 * \param params Configuration space
5346 * \param val Returned buffer time in us
5347 * \param dir Sub unit direction
5348 * \return 0 otherwise a negative error code if the configuration space does not contain a single value
5350 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5353 int INTERNAL(snd_pcm_hw_params_get_buffer_time)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5355 int snd_pcm_hw_params_get_buffer_time(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5358 return snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5362 * \brief Extract minimum buffer time from a configuration space
5363 * \param params Configuration space
5364 * \param val approximate minimum buffer duration in us
5365 * \param dir Sub unit direction
5366 * \return 0 otherwise a negative error code
5368 * Exact value is <,=,> the returned one following dir (-1,0,1)
5371 int INTERNAL(snd_pcm_hw_params_get_buffer_time_min)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5373 int snd_pcm_hw_params_get_buffer_time_min(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5376 return snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5380 * \brief Extract maximum buffer time from a configuration space
5381 * \param params Configuration space
5382 * \param val approximate maximum buffer duration in us
5383 * \param dir Sub unit direction
5384 * \return 0 otherwise a negative error code
5386 * Exact value is <,=,> the returned one following dir (-1,0,1)
5389 int INTERNAL(snd_pcm_hw_params_get_buffer_time_max)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5391 int snd_pcm_hw_params_get_buffer_time_max(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5394 return snd_pcm_hw_param_get_max(params, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5398 * \brief Verify if a buffer time is available inside a configuration space for a PCM
5399 * \param pcm PCM handle
5400 * \param params Configuration space
5401 * \param val approximate buffer duration in us
5402 * \param dir Sub unit direction
5403 * \return 0 if available a negative error code otherwise
5405 * Wanted exact value is <,=,> val following dir (-1,0,1)
5407 int snd_pcm_hw_params_test_buffer_time(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
5409 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5413 * \brief Restrict a configuration space to contain only one buffer time
5414 * \param pcm PCM handle
5415 * \param params Configuration space
5416 * \param val approximate buffer duration in us
5417 * \param dir Sub unit direction
5418 * \return 0 otherwise a negative error code if configuration space would become empty
5420 * Wanted exact value is <,=,> val following dir (-1,0,1)
5422 int snd_pcm_hw_params_set_buffer_time(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
5424 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5428 * \brief Restrict a configuration space with a minimum buffer time
5429 * \param pcm PCM handle
5430 * \param params Configuration space
5431 * \param val approximate minimum buffer duration in us (on return filled with actual minimum)
5432 * \param dir Sub unit direction (on return filled with actual direction)
5433 * \return 0 otherwise a negative error code if configuration space would become empty
5435 * Wanted/actual exact minimum is <,=,> val following dir (-1,0,1)
5437 int snd_pcm_hw_params_set_buffer_time_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5439 return snd_pcm_hw_param_set_min(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5443 * \brief Restrict a configuration space with a maximum buffer time
5444 * \param pcm PCM handle
5445 * \param params Configuration space
5446 * \param val approximate maximum buffer duration in us (on return filled with actual maximum)
5447 * \param dir Sub unit direction (on return filled with actual direction)
5448 * \return 0 otherwise a negative error code if configuration space would become empty
5450 * Wanted/actual exact maximum is <,=,> val following dir (-1,0,1)
5452 int snd_pcm_hw_params_set_buffer_time_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5454 return snd_pcm_hw_param_set_max(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5458 * \brief Restrict a configuration space to have buffer times in a given range
5459 * \param pcm PCM handle
5460 * \param params Configuration space
5461 * \param min approximate minimum buffer duration in us (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 buffer duration in us (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_buffer_time_minmax(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *min, int *mindir, unsigned int *max, int *maxdir)
5471 return snd_pcm_hw_param_set_minmax(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_TIME, min, mindir, max, maxdir);
5475 * \brief Restrict a configuration space to have buffer time nearest to a target
5476 * \param pcm PCM handle
5477 * \param params Configuration space
5478 * \param val approximate target buffer duration in us / returned chosen approximate target buffer duration
5479 * \param dir Sub unit direction
5480 * \return 0 otherwise a negative error code if configuration space is empty
5482 * target/chosen exact value is <,=,> val following dir (-1,0,1)
5485 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)
5487 int snd_pcm_hw_params_set_buffer_time_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5490 return snd_pcm_hw_param_set_near(pcm, params, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5494 * \brief Restrict a configuration space to contain only its minimum buffer time
5495 * \param pcm PCM handle
5496 * \param params Configuration space
5497 * \param val Returned approximate minimum buffer duration in us
5498 * \param dir Sub unit direction
5499 * \return 0 otherwise a negative error code
5501 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5504 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)
5506 int snd_pcm_hw_params_set_buffer_time_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5509 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5513 * \brief Restrict a configuration space to contain only its maximum buffered time
5514 * \param pcm PCM handle
5515 * \param params Configuration space
5516 * \param val Returned approximate maximum buffer duration in us
5517 * \param dir Sub unit direction
5518 * \return 0 otherwise a negative error code
5520 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5523 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)
5525 int snd_pcm_hw_params_set_buffer_time_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5528 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5533 * \brief Extract buffer size from a configuration space
5534 * \param params Configuration space
5535 * \param val Returned buffer size in frames
5536 * \return 0 otherwise a negative error code if the configuration space does not contain a single value
5539 int INTERNAL(snd_pcm_hw_params_get_buffer_size)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5541 int snd_pcm_hw_params_get_buffer_size(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5545 int err = snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
5552 * \brief Extract minimum buffer size from a configuration space
5553 * \param params Configuration space
5554 * \param val Returned approximate minimum buffer size in frames
5555 * \return 0 otherwise a negative error code
5558 int INTERNAL(snd_pcm_hw_params_get_buffer_size_min)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5560 int snd_pcm_hw_params_get_buffer_size_min(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5564 int err = snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
5571 * \brief Extract maximum buffer size from a configuration space
5572 * \param params Configuration space
5573 * \param val Returned approximate maximum buffer size in frames
5574 * \return 0 otherwise a negative error code
5576 * Exact value is <,=,> the returned one following dir (-1,0,1)
5579 int INTERNAL(snd_pcm_hw_params_get_buffer_size_max)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5581 int snd_pcm_hw_params_get_buffer_size_max(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5585 int err = snd_pcm_hw_param_get_max(params, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
5592 * \brief Verify if a buffer size is available inside a configuration space for a PCM
5593 * \param pcm PCM handle
5594 * \param params Configuration space
5595 * \param val buffer size in frames
5596 * \return 0 if available a negative error code otherwise
5598 * Wanted exact value is <,=,> val following dir (-1,0,1)
5600 int snd_pcm_hw_params_test_buffer_size(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t val)
5602 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_BUFFER_SIZE, val, 0);
5606 * \brief Restrict a configuration space to contain only one buffer size
5607 * \param pcm PCM handle
5608 * \param params Configuration space
5609 * \param val buffer size in frames
5610 * \return 0 otherwise a negative error code if configuration space would become empty
5612 * Wanted exact value is <,=,> val following dir (-1,0,1)
5614 int snd_pcm_hw_params_set_buffer_size(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t val)
5616 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_SIZE, val, 0);
5620 * \brief Restrict a configuration space with a minimum buffer size
5621 * \param pcm PCM handle
5622 * \param params Configuration space
5623 * \param val approximate minimum buffer size in frames (on return filled with actual minimum)
5624 * \return 0 otherwise a negative error code if configuration space would become empty
5626 int snd_pcm_hw_params_set_buffer_size_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5628 unsigned int _val = *val;
5629 int err = snd_pcm_hw_param_set_min(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
5636 * \brief Restrict a configuration space with a maximum buffer size
5637 * \param pcm PCM handle
5638 * \param params Configuration space
5639 * \param val approximate maximum buffer size in frames (on return filled with actual maximum)
5640 * \return 0 otherwise a negative error code if configuration space would become empty
5642 int snd_pcm_hw_params_set_buffer_size_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5644 unsigned int _val = *val;
5645 int err = snd_pcm_hw_param_set_max(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
5652 * \brief Restrict a configuration space to have buffer sizes in a given range
5653 * \param pcm PCM handle
5654 * \param params Configuration space
5655 * \param min approximate minimum buffer size in frames (on return filled with actual minimum)
5656 * \param max approximate maximum buffer size in frames (on return filled with actual maximum)
5657 * \return 0 otherwise a negative error code if configuration space would become empty
5659 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)
5661 unsigned int _min = *min;
5662 unsigned int _max = *max;
5663 int err = snd_pcm_hw_param_set_minmax(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_SIZE, &_min, NULL, &_max, NULL);
5670 * \brief Restrict a configuration space to have buffer size nearest to a target
5671 * \param pcm PCM handle
5672 * \param params Configuration space
5673 * \param val approximate target buffer size in frames / returned chosen approximate target buffer size in frames
5674 * \return 0 otherwise a negative error code if configuration space is empty
5677 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)
5679 int snd_pcm_hw_params_set_buffer_size_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5682 unsigned int _val = *val;
5683 int err = snd_pcm_hw_param_set_near(pcm, params, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
5690 * \brief Restrict a configuration space to contain only its minimum buffer size
5691 * \param pcm PCM handle
5692 * \param params Configuration space
5693 * \param val Returned minimum buffer size in frames
5694 * \return buffer size in frames
5697 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)
5699 int snd_pcm_hw_params_set_buffer_size_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5703 int err = snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
5710 * \brief Restrict a configuration space to contain only its maximum buffer size
5711 * \param pcm PCM handle
5712 * \param params Configuration space
5713 * \param val Returned maximum buffer size in frames
5714 * \return 0 otherwise a negative error code
5717 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)
5719 int snd_pcm_hw_params_set_buffer_size_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5723 int err = snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
5731 * \brief (DEPRECATED) Extract tick time from a configuration space
5732 * \param params Configuration space
5733 * \param val Returned approximate tick duration in us
5734 * \param dir Sub unit direction
5735 * \return 0 otherwise a negative error code if the configuration space does not contain a single value
5737 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5740 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)
5742 int snd_pcm_hw_params_get_tick_time(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5750 * \brief (DEPRECATED) Extract minimum tick time from a configuration space
5751 * \param params Configuration space
5752 * \param val Returned approximate minimum tick duration in us
5753 * \param dir Sub unit direction
5754 * \return 0 otherwise a negative error code
5756 * Exact value is <,=,> the returned one following dir (-1,0,1)
5759 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)
5761 int snd_pcm_hw_params_get_tick_time_min(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5769 * \brief (DEPRECATED) Extract maximum tick time from a configuration space
5770 * \param params Configuration space
5771 * \param val Returned approximate maximum tick duration in us
5772 * \param dir Sub unit direction
5773 * \return 0 otherwise a negative error code
5775 * Exact value is <,=,> the returned one following dir (-1,0,1)
5778 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)
5780 int snd_pcm_hw_params_get_tick_time_max(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5788 * \brief (DEPRECATED) Verify if a tick time is available inside a configuration space for a PCM
5789 * \param pcm PCM handle
5790 * \param params Configuration space
5791 * \param val approximate tick duration in us
5792 * \param dir Sub unit direction
5793 * \return 0 if available a negative error code otherwise
5795 * Wanted exact value is <,=,> val following dir (-1,0,1)
5797 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)
5799 return val ? -EINVAL : 0;
5803 * \brief (DEPRECATED) Restrict a configuration space to contain only one tick time
5804 * \param pcm PCM handle
5805 * \param params Configuration space
5806 * \param val approximate tick duration in us
5807 * \param dir Sub unit direction
5808 * \return 0 otherwise a negative error code if configuration space would become empty
5810 * Wanted exact value is <,=,> val following dir (-1,0,1)
5812 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)
5818 * \brief (DEPRECATED) Restrict a configuration space with a minimum tick time
5819 * \param pcm PCM handle
5820 * \param params Configuration space
5821 * \param val approximate minimum tick duration in us (on return filled with actual minimum)
5822 * \param dir Sub unit direction (on return filled with actual direction)
5823 * \return 0 otherwise a negative error code if configuration space would become empty
5825 * Wanted/actual exact minimum is <,=,> val following dir (-1,0,1)
5827 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)
5833 * \brief (DEPRECATED) Restrict a configuration space with a maximum tick time
5834 * \param pcm PCM handle
5835 * \param params Configuration space
5836 * \param val approximate maximum tick duration in us (on return filled with actual maximum)
5837 * \param dir Sub unit direction (on return filled with actual direction)
5838 * \return 0 otherwise a negative error code if configuration space would become empty
5840 * Wanted/actual exact maximum is <,=,> val following dir (-1,0,1)
5842 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)
5848 * \brief (DEPRECATED) Restrict a configuration space to have tick times in a given range
5849 * \param pcm PCM handle
5850 * \param params Configuration space
5851 * \param min approximate minimum tick duration in us (on return filled with actual minimum)
5852 * \param mindir Sub unit direction for minimum (on return filled with actual direction)
5853 * \param max approximate maximum tick duration in us (on return filled with actual maximum)
5854 * \param maxdir Sub unit direction for maximum (on return filled with actual direction)
5855 * \return 0 otherwise a negative error code if configuration space would become empty
5857 * Wanted/actual exact min/max is <,=,> val following dir (-1,0,1)
5859 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)
5865 * \brief (DEPRECATED) Restrict a configuration space to have tick time nearest to a target
5866 * \param pcm PCM handle
5867 * \param params Configuration space
5868 * \param val approximate target tick duration in us / returned chosen approximate target tick duration in us
5869 * \param dir Sub unit direction
5870 * \return 0 otherwise a negative error code if configuration space is empty
5872 * target/chosen exact value is <,=,> val following dir (-1,0,1)
5875 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)
5877 int snd_pcm_hw_params_set_tick_time_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5884 * \brief (DEPRECATED) Restrict a configuration space to contain only its minimum tick time
5885 * \param pcm PCM handle
5886 * \param params Configuration space
5887 * \param val Returned approximate minimum tick duration in us
5888 * \param dir Sub unit direction
5889 * \return 0 otherwise a negative error code
5891 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5894 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)
5896 int snd_pcm_hw_params_set_tick_time_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5903 * \brief (DEPRECATED) Restrict a configuration space to contain only its maximum tick time
5904 * \param pcm PCM handle
5905 * \param params Configuration space
5906 * \param val Returned approximate maximum tick duration in us
5907 * \param dir Sub unit direction
5908 * \return 0 otherwise a negative error code
5910 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5913 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)
5915 int snd_pcm_hw_params_set_tick_time_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5922 * \brief Get the minimum transfer align value in samples
5923 * \param params Configuration space
5924 * \param val Returned minimum align value
5925 * \return 0 otherwise a negative error code if the configuration space does not contain a single value
5927 int snd_pcm_hw_params_get_min_align(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5929 unsigned int format, channels, fb, min_align;
5932 err = snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_FORMAT, &format, NULL);
5935 err = snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_CHANNELS, &channels, NULL);
5938 // compute frame bits
5939 fb = snd_pcm_format_physical_width((snd_pcm_format_t)format) * channels;
5951 * \brief Return current software configuration for a PCM
5952 * \param pcm PCM handle
5953 * \param params Software configuration container
5954 * \return 0 on success otherwise a negative error code
5956 * The function is thread-safe when built with the proper option.
5958 int snd_pcm_sw_params_current(snd_pcm_t *pcm, snd_pcm_sw_params_t *params)
5960 assert(pcm && params);
5961 if (CHECK_SANITY(! pcm->setup)) {
5962 SNDMSG("PCM not set up");
5965 __snd_pcm_lock(pcm); /* forced lock due to pcm field changes */
5966 params->proto = SNDRV_PCM_VERSION;
5967 params->tstamp_mode = pcm->tstamp_mode;
5968 params->tstamp_type = pcm->tstamp_type;
5969 params->period_step = pcm->period_step;
5970 params->sleep_min = 0;
5971 params->avail_min = pcm->avail_min;
5972 sw_set_period_event(params, pcm->period_event);
5973 params->xfer_align = 1;
5974 params->start_threshold = pcm->start_threshold;
5975 params->stop_threshold = pcm->stop_threshold;
5976 params->silence_threshold = pcm->silence_threshold;
5977 params->silence_size = pcm->silence_size;
5978 params->boundary = pcm->boundary;
5979 __snd_pcm_unlock(pcm);
5984 * \brief Dump a software configuration
5985 * \param params Software configuration container
5986 * \param out Output handle
5987 * \return 0 on success otherwise a negative error code
5989 int snd_pcm_sw_params_dump(snd_pcm_sw_params_t *params, snd_output_t *out)
5991 snd_output_printf(out, "tstamp_mode: %s\n", snd_pcm_tstamp_mode_name(params->tstamp_mode));
5992 snd_output_printf(out, "tstamp_type: %s\n", snd_pcm_tstamp_type_name(params->tstamp_type));
5993 snd_output_printf(out, "period_step: %u\n", params->period_step);
5994 snd_output_printf(out, "avail_min: %lu\n", params->avail_min);
5995 snd_output_printf(out, "start_threshold: %ld\n", params->start_threshold);
5996 snd_output_printf(out, "stop_threshold: %ld\n", params->stop_threshold);
5997 snd_output_printf(out, "silence_threshold: %lu\n", params->silence_threshold);
5998 snd_output_printf(out, "silence_size: %lu\n", params->silence_size);
5999 snd_output_printf(out, "boundary: %lu\n", params->boundary);
6004 * \brief get size of #snd_pcm_sw_params_t
6005 * \return size in bytes
6007 size_t snd_pcm_sw_params_sizeof()
6009 return sizeof(snd_pcm_sw_params_t);
6013 * \brief allocate an invalid #snd_pcm_sw_params_t using standard malloc
6014 * \param ptr returned pointer
6015 * \return 0 on success otherwise negative error code
6017 int snd_pcm_sw_params_malloc(snd_pcm_sw_params_t **ptr)
6020 *ptr = calloc(1, sizeof(snd_pcm_sw_params_t));
6027 * \brief frees a previously allocated #snd_pcm_sw_params_t
6028 * \param obj pointer to object to free
6030 void snd_pcm_sw_params_free(snd_pcm_sw_params_t *obj)
6036 * \brief copy one #snd_pcm_sw_params_t to another
6037 * \param dst pointer to destination
6038 * \param src pointer to source
6040 void snd_pcm_sw_params_copy(snd_pcm_sw_params_t *dst, const snd_pcm_sw_params_t *src)
6047 * \brief Get boundary for ring pointers from a software configuration container
6048 * \param params Software configuration container
6049 * \param val Returned boundary in frames
6050 * \return 0 otherwise a negative error code
6052 int snd_pcm_sw_params_get_boundary(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6055 *val = params->boundary;
6060 * \brief (DEPRECATED) Set start mode inside a software configuration container
6061 * \param pcm PCM handle
6062 * \param params Software configuration container
6063 * \param val Start mode
6064 * \return 0 otherwise a negative error code
6066 int snd_pcm_sw_params_set_start_mode(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_start_t val)
6068 assert(pcm && params);
6070 case SND_PCM_START_DATA:
6071 params->start_threshold = 1;
6073 case SND_PCM_START_EXPLICIT:
6074 params->start_threshold = pcm->boundary;
6077 SNDMSG("invalid start mode value %d\n", val);
6084 link_warning(snd_pcm_sw_params_set_start_mode, "Warning: start_mode is deprecated, consider to use start_threshold");
6088 * \brief (DEPRECATED) Get start mode from a software configuration container
6089 * \param params Software configuration container
6090 * \return start mode
6092 snd_pcm_start_t snd_pcm_sw_params_get_start_mode(const snd_pcm_sw_params_t *params)
6096 return params->start_threshold > 1024 * 1024 ? SND_PCM_START_EXPLICIT : SND_PCM_START_DATA;
6100 link_warning(snd_pcm_sw_params_get_start_mode, "Warning: start_mode is deprecated, consider to use start_threshold");
6104 * \brief (DEPRECATED) Set xrun mode inside a software configuration container
6105 * \param pcm PCM handle
6106 * \param params Software configuration container
6107 * \param val Xrun mode
6108 * \return 0 otherwise a negative error code
6111 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)
6113 int snd_pcm_sw_params_set_xrun_mode(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_xrun_t val)
6116 assert(pcm && params);
6118 case SND_PCM_XRUN_STOP:
6119 params->stop_threshold = pcm->buffer_size;
6121 case SND_PCM_XRUN_NONE:
6122 params->stop_threshold = pcm->boundary;
6125 SNDMSG("invalid xrun mode value %d\n", val);
6132 link_warning(snd_pcm_sw_params_set_xrun_mode, "Warning: xrun_mode is deprecated, consider to use stop_threshold");
6136 * \brief (DEPRECATED) Get xrun mode from a software configuration container
6137 * \param params Software configuration container
6140 snd_pcm_xrun_t snd_pcm_sw_params_get_xrun_mode(const snd_pcm_sw_params_t *params)
6144 return params->stop_threshold > 1024 * 1024 ? SND_PCM_XRUN_NONE : SND_PCM_XRUN_STOP;
6148 link_warning(snd_pcm_sw_params_get_xrun_mode, "Warning: xrun_mode is deprecated, consider to use stop_threshold");
6152 * \brief Set timestamp mode inside a software configuration container
6153 * \param pcm PCM handle
6154 * \param params Software configuration container
6155 * \param val Timestamp mode
6156 * \return 0 otherwise a negative error code
6159 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)
6161 int snd_pcm_sw_params_set_tstamp_mode(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_tstamp_t val)
6164 assert(pcm && params);
6165 if (CHECK_SANITY(val > SND_PCM_TSTAMP_LAST)) {
6166 SNDMSG("invalid tstamp_mode value %d", val);
6169 params->tstamp_mode = val;
6174 * \brief Get timestamp mode from a software configuration container
6175 * \param params Software configuration container
6176 * \param val Returned timestamp
6177 * \return 0 otherwise a negative error code
6180 int INTERNAL(snd_pcm_sw_params_get_tstamp_mode)(const snd_pcm_sw_params_t *params, snd_pcm_tstamp_t *val)
6182 int snd_pcm_sw_params_get_tstamp_mode(const snd_pcm_sw_params_t *params, snd_pcm_tstamp_t *val)
6185 assert(params && val);
6186 *val = params->tstamp_mode;
6191 * \brief Set timestamp type inside a software configuration container
6192 * \param pcm PCM handle
6193 * \param params Software configuration container
6194 * \param val Timestamp type
6195 * \return 0 otherwise a negative error code
6197 int snd_pcm_sw_params_set_tstamp_type(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_tstamp_type_t val)
6199 assert(pcm && params);
6200 if (CHECK_SANITY(val > SND_PCM_TSTAMP_TYPE_LAST)) {
6201 SNDMSG("invalid tstamp_type value %d", val);
6204 params->tstamp_type = val;
6209 * \brief Get timestamp type from a software configuration container
6210 * \param params Software configuration container
6211 * \param val Returned timestamp type
6212 * \return 0 otherwise a negative error code
6214 int snd_pcm_sw_params_get_tstamp_type(const snd_pcm_sw_params_t *params, snd_pcm_tstamp_type_t *val)
6216 assert(params && val);
6217 *val = params->tstamp_type;
6222 * \brief (DEPRECATED) Set minimum number of ticks to sleep inside a software configuration container
6223 * \param pcm PCM handle
6224 * \param params Software configuration container
6225 * \param val Minimum ticks to sleep or 0 to disable the use of tick timer
6226 * \return 0 otherwise a negative error code
6229 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)
6231 int snd_pcm_sw_params_set_sleep_min(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, unsigned int val)
6238 * \brief (DEPRECATED) Get minimum numbers of ticks to sleep from a software configuration container
6239 * \param params Software configuration container
6240 * \param val returned minimum number of ticks to sleep or 0 if tick timer is disabled
6241 * \return 0 otherwise a negative error code
6244 int INTERNAL(snd_pcm_sw_params_get_sleep_min)(const snd_pcm_sw_params_t *params ATTRIBUTE_UNUSED, unsigned int *val)
6246 int snd_pcm_sw_params_get_sleep_min(const snd_pcm_sw_params_t *params, unsigned int *val)
6254 * \brief Set avail min inside a software configuration container
6255 * \param pcm PCM handle
6256 * \param params Software configuration container
6257 * \param val Minimum avail frames to consider PCM ready
6258 * \return 0 otherwise a negative error code
6260 * Note: This is similar to setting an OSS wakeup point. The valid
6261 * values for 'val' are determined by the specific hardware. Most PC
6262 * sound cards can only accept power of 2 frame counts (i.e. 512,
6263 * 1024, 2048). You cannot use this as a high resolution timer - it
6264 * is limited to how often the sound card hardware raises an
6268 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)
6270 int snd_pcm_sw_params_set_avail_min(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
6273 assert(pcm && params);
6274 /* Fix avail_min if it's below period size. The period_size
6275 * defines the minimal wake-up timing accuracy, so it doesn't
6276 * make sense to set below that.
6278 if (val < pcm->period_size)
6279 val = pcm->period_size;
6280 params->avail_min = val;
6285 * \brief Get avail min from a software configuration container
6286 * \param params Software configuration container
6287 * \param val returned minimum available frames to consider PCM ready
6288 * \return 0 otherwise a negative error code
6291 int INTERNAL(snd_pcm_sw_params_get_avail_min)(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6293 int snd_pcm_sw_params_get_avail_min(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6296 assert(params && val);
6297 *val = params->avail_min;
6302 * \brief Set period event inside a software configuration container
6303 * \param pcm PCM handle
6304 * \param params Software configuration container
6305 * \param val 0 = disable period event, 1 = enable period event
6306 * \return 0 otherwise a negative error code
6308 * An poll (select) wakeup event is raised if enabled.
6310 int snd_pcm_sw_params_set_period_event(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, int val)
6312 assert(pcm && params);
6313 sw_set_period_event(params, val);
6318 * \brief Get period event from a software configuration container
6319 * \param params Software configuration container
6320 * \param val returned period event state
6321 * \return 0 otherwise a negative error code
6323 int snd_pcm_sw_params_get_period_event(const snd_pcm_sw_params_t *params, int *val)
6325 assert(params && val);
6326 *val = sw_get_period_event(params);
6331 * \brief (DEPRECATED) Set xfer align inside a software configuration container
6332 * \param pcm PCM handle
6333 * \param params Software configuration container
6334 * \param val Chunk size (frames are attempted to be transferred in chunks)
6335 * \return 0 otherwise a negative error code
6338 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)
6340 int snd_pcm_sw_params_set_xfer_align(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
6347 * \brief (DEPRECATED) Get xfer align from a software configuration container
6348 * \param params Software configuration container
6349 * \param val returned chunk size (frames are attempted to be transferred in chunks)
6350 * \return 0 otherwise a negative error code
6353 int INTERNAL(snd_pcm_sw_params_get_xfer_align)(const snd_pcm_sw_params_t *params ATTRIBUTE_UNUSED, snd_pcm_uframes_t *val)
6355 int snd_pcm_sw_params_get_xfer_align(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6363 * \brief Set start threshold inside a software configuration container
6364 * \param pcm PCM handle
6365 * \param params Software configuration container
6366 * \param val Start threshold in frames
6367 * \return 0 otherwise a negative error code
6369 * PCM is automatically started when playback frames available to PCM
6370 * are >= threshold or when requested capture frames are >= threshold
6373 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)
6375 int snd_pcm_sw_params_set_start_threshold(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
6378 assert(pcm && params);
6379 params->start_threshold = val;
6384 * \brief Get start threshold from a software configuration container
6385 * \param params Software configuration container
6386 * \param val Returned start threshold in frames
6387 * \return 0 otherwise a negative error code
6389 * PCM is automatically started when playback frames available to PCM
6390 * are >= threshold or when requested capture frames are >= threshold
6393 int INTERNAL(snd_pcm_sw_params_get_start_threshold)(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6395 int snd_pcm_sw_params_get_start_threshold(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6399 *val = params->start_threshold;
6405 * \brief Set stop threshold inside a software configuration container
6406 * \param pcm PCM handle
6407 * \param params Software configuration container
6408 * \param val Stop threshold in frames
6409 * \return 0 otherwise a negative error code
6411 * PCM is automatically stopped in #SND_PCM_STATE_XRUN state when available
6412 * frames is >= threshold. If the stop threshold is equal to boundary (also
6413 * software parameter - sw_param) then automatic stop will be disabled
6414 * (thus device will do the endless loop in the ring buffer).
6417 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)
6419 int snd_pcm_sw_params_set_stop_threshold(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
6422 assert(pcm && params);
6423 params->stop_threshold = val;
6428 * \brief Get stop threshold from a software configuration container
6429 * \param params Software configuration container
6430 * \param val Returned stop threshold in frames
6431 * \return 0 otherwise a negative error code
6433 * PCM is automatically stopped in #SND_PCM_STATE_XRUN state when available
6434 * frames is >= threshold. If the stop threshold is equal to boundary (also
6435 * software parameter - sw_param) then automatic stop will be disabled
6436 * (thus device will do the endless loop in the ring buffer).
6439 int INTERNAL(snd_pcm_sw_params_get_stop_threshold)(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6441 int snd_pcm_sw_params_get_stop_threshold(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6445 *val = params->stop_threshold;
6451 * \brief Set silence threshold inside a software configuration container
6452 * \param pcm PCM handle
6453 * \param params Software configuration container
6454 * \param val Silence threshold in frames
6455 * \return 0 otherwise a negative error code
6457 * A portion of playback buffer is overwritten with silence (see
6458 * #snd_pcm_sw_params_set_silence_size) when playback underrun is nearer
6459 * than silence threshold.
6462 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)
6464 int snd_pcm_sw_params_set_silence_threshold(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
6467 assert(pcm && params);
6468 if (CHECK_SANITY(val >= pcm->buffer_size)) {
6469 SNDMSG("invalid silent_threshold value %ld (buffer_size = %ld)",
6470 val, pcm->buffer_size);
6473 params->silence_threshold = val;
6478 * \brief Get silence threshold from a software configuration container
6479 * \param params Software configuration container
6480 * \param val Returned silence threshold in frames
6481 * \return 0 otherwise a negative error value
6483 * A portion of playback buffer is overwritten with silence (see
6484 * #snd_pcm_sw_params_set_silence_size) when playback underrun is nearer
6485 * than silence threshold.
6488 int INTERNAL(snd_pcm_sw_params_get_silence_threshold)(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6490 int snd_pcm_sw_params_get_silence_threshold(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6493 assert(params && val);
6494 *val = params->silence_threshold;
6500 * \brief Set silence size inside a software configuration container
6501 * \param pcm PCM handle
6502 * \param params Software configuration container
6503 * \param val Silence size in frames (0 for disabled)
6504 * \return 0 otherwise a negative error code
6506 * A portion of playback buffer is overwritten with silence when playback
6507 * underrun is nearer than silence threshold (see
6508 * #snd_pcm_sw_params_set_silence_threshold)
6510 * The special case is when silence size value is equal or greater than
6511 * boundary. The unused portion of the ring buffer (initial written samples
6512 * are untouched) is filled with silence at start. Later, only just processed
6513 * sample area is filled with silence. Note: silence_threshold must be set to zero.
6516 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)
6518 int snd_pcm_sw_params_set_silence_size(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
6521 assert(pcm && params);
6522 if (CHECK_SANITY(val < pcm->boundary && val > pcm->buffer_size)) {
6523 SNDMSG("invalid silence_size %ld (boundary %ld, buffer_size %ld)",
6524 val, pcm->boundary, pcm->buffer_size);
6527 params->silence_size = val;
6532 * \brief Get silence size from a software configuration container
6533 * \param params Software configuration container
6534 * \param val Returned silence size in frames (0 for disabled)
6535 * \return 0 otherwise a negative error code
6537 * A portion of playback buffer is overwritten with silence when playback
6538 * underrun is nearer than silence threshold (see
6539 * #snd_pcm_sw_params_set_silence_threshold)
6542 int INTERNAL(snd_pcm_sw_params_get_silence_size)(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6544 int snd_pcm_sw_params_get_silence_size(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6548 *val = params->silence_size;
6554 * \brief get size of #snd_pcm_status_t
6555 * \return size in bytes
6557 size_t snd_pcm_status_sizeof()
6559 return sizeof(snd_pcm_status_t);
6563 * \brief allocate an invalid #snd_pcm_status_t using standard malloc
6564 * \param ptr returned pointer
6565 * \return 0 on success otherwise negative error code
6567 int snd_pcm_status_malloc(snd_pcm_status_t **ptr)
6570 *ptr = calloc(1, sizeof(snd_pcm_status_t));
6577 * \brief frees a previously allocated #snd_pcm_status_t
6578 * \param obj pointer to object to free
6580 void snd_pcm_status_free(snd_pcm_status_t *obj)
6586 * \brief copy one #snd_pcm_status_t to another
6587 * \param dst pointer to destination
6588 * \param src pointer to source
6590 void snd_pcm_status_copy(snd_pcm_status_t *dst, const snd_pcm_status_t *src)
6597 * \brief Get state from a PCM status container (see #snd_pcm_state)
6598 * \param obj #snd_pcm_status_t pointer
6601 snd_pcm_state_t snd_pcm_status_get_state(const snd_pcm_status_t *obj)
6608 * \brief Get trigger timestamp from a PCM status container
6609 * \param obj #snd_pcm_status_t pointer
6610 * \param ptr Pointer to returned timestamp
6612 * Trigger means a PCM state transition (from stopped to running or
6613 * versa vice). It applies also to pause and suspend. In other words,
6614 * timestamp contains time when stream started or when it was stopped.
6616 void snd_pcm_status_get_trigger_tstamp(const snd_pcm_status_t *obj, snd_timestamp_t *ptr)
6619 ptr->tv_sec = obj->trigger_tstamp.tv_sec;
6620 ptr->tv_usec = obj->trigger_tstamp.tv_nsec / 1000L;
6624 * \brief Get trigger hi-res timestamp from a PCM status container
6625 * \param obj #snd_pcm_status_t pointer
6626 * \param ptr Pointer to returned timestamp
6628 * Trigger means a PCM state transition (from stopped to running or
6629 * versa vice). It applies also to pause and suspend. In other words,
6630 * timestamp contains time when stream started or when it was stopped.
6633 void INTERNAL(snd_pcm_status_get_trigger_htstamp)(const snd_pcm_status_t *obj, snd_htimestamp_t *ptr)
6635 void snd_pcm_status_get_trigger_htstamp(const snd_pcm_status_t *obj, snd_htimestamp_t *ptr)
6639 *ptr = obj->trigger_tstamp;
6641 use_default_symbol_version(__snd_pcm_status_get_trigger_htstamp, snd_pcm_status_get_trigger_htstamp, ALSA_0.9.0rc8);
6644 * \brief Get "now" timestamp from a PCM status container
6645 * \param obj #snd_pcm_status_t pointer
6646 * \param ptr Pointer to returned timestamp
6648 void snd_pcm_status_get_tstamp(const snd_pcm_status_t *obj, snd_timestamp_t *ptr)
6651 ptr->tv_sec = obj->tstamp.tv_sec;
6652 ptr->tv_usec = obj->tstamp.tv_nsec / 1000L;
6656 * \brief Get "now" hi-res timestamp from a PCM status container
6657 * \param obj pointer to #snd_pcm_status_t
6658 * \param ptr Pointer to returned timestamp
6661 void INTERNAL(snd_pcm_status_get_htstamp)(const snd_pcm_status_t *obj, snd_htimestamp_t *ptr)
6663 void snd_pcm_status_get_htstamp(const snd_pcm_status_t *obj, snd_htimestamp_t *ptr)
6669 use_default_symbol_version(__snd_pcm_status_get_htstamp, snd_pcm_status_get_htstamp, ALSA_0.9.0rc8);
6672 * \brief Get "now" hi-res audio timestamp from a PCM status container
6673 * \param obj pointer to #snd_pcm_status_t
6674 * \param ptr Pointer to returned timestamp
6676 void snd_pcm_status_get_audio_htstamp(const snd_pcm_status_t *obj, snd_htimestamp_t *ptr)
6679 *ptr = obj->audio_tstamp;
6683 * \brief Get "now" hi-res driver timestamp from a PCM status container. Defines when the status
6684 * was generated by driver, may differ from normal timestamp.
6685 * \param obj pointer to #snd_pcm_status_t
6686 * \param ptr Pointer to returned timestamp
6688 void snd_pcm_status_get_driver_htstamp(const snd_pcm_status_t *obj, snd_htimestamp_t *ptr)
6691 *ptr = obj->driver_tstamp;
6695 * \brief Get audio_tstamp_report from a PCM status container
6696 * \param obj pointer to #snd_pcm_status_t
6697 * \param ptr Pointer to returned report (valid fields are accuracy and type)
6699 void snd_pcm_status_get_audio_htstamp_report(const snd_pcm_status_t *obj,
6700 snd_pcm_audio_tstamp_report_t *audio_tstamp_report)
6702 assert(obj && audio_tstamp_report);
6703 snd_pcm_unpack_audio_tstamp_report(obj->audio_tstamp_data,
6704 obj->audio_tstamp_accuracy,
6705 audio_tstamp_report);
6709 * \brief set audio_tstamp_config from a PCM status container
6710 * \param obj pointer to #snd_pcm_status_t
6711 * \param ptr Pointer to config (valid fields are type and report_analog_delay)
6713 void snd_pcm_status_set_audio_htstamp_config(snd_pcm_status_t *obj,
6714 snd_pcm_audio_tstamp_config_t *audio_tstamp_config)
6716 assert(obj && audio_tstamp_config);
6717 snd_pcm_pack_audio_tstamp_config(&obj->audio_tstamp_data, audio_tstamp_config);
6721 * \brief Get delay from a PCM status container (see #snd_pcm_delay)
6722 * \return Delay in frames
6724 * Delay is distance between current application frame position and
6725 * sound frame position.
6726 * It's positive and less than buffer size in normal situation,
6727 * negative on playback underrun and greater than buffer size on
6730 snd_pcm_sframes_t snd_pcm_status_get_delay(const snd_pcm_status_t *obj)
6737 * \brief Get number of frames available from a PCM status container (see #snd_pcm_avail_update)
6738 * \return Number of frames ready to be read/written
6740 snd_pcm_uframes_t snd_pcm_status_get_avail(const snd_pcm_status_t *obj)
6747 * \brief Get maximum number of frames available from a PCM status container after last #snd_pcm_status call
6748 * \return Maximum number of frames ready to be read/written
6750 snd_pcm_uframes_t snd_pcm_status_get_avail_max(const snd_pcm_status_t *obj)
6753 return obj->avail_max;
6757 * \brief Get count of ADC overrange detections since last call
6758 * \return Count of ADC overrange detections
6760 snd_pcm_uframes_t snd_pcm_status_get_overrange(const snd_pcm_status_t *obj)
6763 return obj->overrange;
6767 * \brief get size of #snd_pcm_info_t
6768 * \return size in bytes
6770 size_t snd_pcm_info_sizeof()
6772 return sizeof(snd_pcm_info_t);
6776 * \brief allocate an invalid #snd_pcm_info_t using standard malloc
6777 * \param ptr returned pointer
6778 * \return 0 on success otherwise negative error code
6780 int snd_pcm_info_malloc(snd_pcm_info_t **ptr)
6783 *ptr = calloc(1, sizeof(snd_pcm_info_t));
6790 * \brief frees a previously allocated #snd_pcm_info_t
6791 * \param obj pointer to object to free
6793 void snd_pcm_info_free(snd_pcm_info_t *obj)
6799 * \brief copy one #snd_pcm_info_t to another
6800 * \param dst pointer to destination
6801 * \param src pointer to source
6803 void snd_pcm_info_copy(snd_pcm_info_t *dst, const snd_pcm_info_t *src)
6810 * \brief Get device from a PCM info container
6811 * \param obj PCM info container
6812 * \return device number
6814 unsigned int snd_pcm_info_get_device(const snd_pcm_info_t *obj)
6821 * \brief Get subdevice from a PCM info container
6822 * \param obj PCM info container
6823 * \return subdevice number
6825 unsigned int snd_pcm_info_get_subdevice(const snd_pcm_info_t *obj)
6828 return obj->subdevice;
6832 * \brief Get stream (direction) from a PCM info container
6833 * \param obj PCM info container
6836 snd_pcm_stream_t snd_pcm_info_get_stream(const snd_pcm_info_t *obj)
6843 * \brief Get card from a PCM info container
6844 * \param obj PCM info container
6845 * \return card number otherwise a negative error code if not associable to a card
6847 int snd_pcm_info_get_card(const snd_pcm_info_t *obj)
6854 * \brief Get id from a PCM info container
6855 * \param obj PCM info container
6856 * \return short id of PCM
6858 const char *snd_pcm_info_get_id(const snd_pcm_info_t *obj)
6861 return (const char *)obj->id;
6865 * \brief Get name from a PCM info container
6866 * \param obj PCM info container
6867 * \return name of PCM
6869 const char *snd_pcm_info_get_name(const snd_pcm_info_t *obj)
6872 return (const char *)obj->name;
6876 * \brief Get subdevice name from a PCM info container
6877 * \param obj PCM info container
6878 * \return name of used PCM subdevice
6880 const char *snd_pcm_info_get_subdevice_name(const snd_pcm_info_t *obj)
6883 return (const char *)obj->subname;
6887 * \brief Get class from a PCM info container
6888 * \param obj PCM info container
6889 * \return class of PCM
6891 snd_pcm_class_t snd_pcm_info_get_class(const snd_pcm_info_t *obj)
6894 return obj->dev_class;
6898 * \brief Get subclass from a PCM info container
6899 * \param obj PCM info container
6900 * \return subclass of PCM
6902 snd_pcm_subclass_t snd_pcm_info_get_subclass(const snd_pcm_info_t *obj)
6905 return obj->dev_subclass;
6909 * \brief Get subdevices count from a PCM info container
6910 * \param obj PCM info container
6911 * \return subdevices total count of PCM
6913 unsigned int snd_pcm_info_get_subdevices_count(const snd_pcm_info_t *obj)
6916 return obj->subdevices_count;
6920 * \brief Get available subdevices count from a PCM info container
6921 * \param obj PCM info container
6922 * \return available subdevices count of PCM
6924 unsigned int snd_pcm_info_get_subdevices_avail(const snd_pcm_info_t *obj)
6927 return obj->subdevices_avail;
6931 * \brief Get hardware synchronization ID from a PCM info container
6932 * \param obj PCM info container
6933 * \return hardware synchronization ID
6935 snd_pcm_sync_id_t snd_pcm_info_get_sync(const snd_pcm_info_t *obj)
6937 snd_pcm_sync_id_t res;
6939 memcpy(&res, &obj->sync, sizeof(res));
6944 * \brief Set wanted device inside a PCM info container (see #snd_ctl_pcm_info)
6945 * \param obj PCM info container
6946 * \param val Device number
6948 void snd_pcm_info_set_device(snd_pcm_info_t *obj, unsigned int val)
6955 * \brief Set wanted subdevice inside a PCM info container (see #snd_ctl_pcm_info)
6956 * \param obj PCM info container
6957 * \param val Subdevice number
6959 void snd_pcm_info_set_subdevice(snd_pcm_info_t *obj, unsigned int val)
6962 obj->subdevice = val;
6966 * \brief Set wanted stream inside a PCM info container (see #snd_ctl_pcm_info)
6967 * \param obj PCM info container
6970 void snd_pcm_info_set_stream(snd_pcm_info_t *obj, snd_pcm_stream_t val)
6977 * \brief Application request to access a portion of direct (mmap) area
6978 * \param pcm PCM handle
6979 * \param areas Returned mmap channel areas
6980 * \param offset Returned mmap area offset in area steps (== frames)
6981 * \param frames mmap area portion size in frames (wanted on entry, contiguous available on exit)
6982 * \return 0 on success otherwise a negative error code
6984 * It is necessary to call the snd_pcm_avail_update() function directly before
6985 * this call. Otherwise, this function can return a wrong count of available frames.
6987 * The function should be called before a sample-direct area can be accessed.
6988 * The resulting size parameter is always less or equal to the input count of frames
6989 * and can be zero, if no frames can be processed (the ring buffer is full).
6991 * See the snd_pcm_mmap_commit() function to finish the frame processing in
6994 * The function is thread-safe when built with the proper option.
6996 int snd_pcm_mmap_begin(snd_pcm_t *pcm,
6997 const snd_pcm_channel_area_t **areas,
6998 snd_pcm_uframes_t *offset,
6999 snd_pcm_uframes_t *frames)
7003 if (bad_pcm_state(pcm, P_STATE_RUNNABLE))
7006 err = __snd_pcm_mmap_begin(pcm, areas, offset, frames);
7007 snd_pcm_unlock(pcm);
7012 /* locked version */
7013 int __snd_pcm_mmap_begin(snd_pcm_t *pcm, const snd_pcm_channel_area_t **areas,
7014 snd_pcm_uframes_t *offset, snd_pcm_uframes_t *frames)
7016 snd_pcm_uframes_t cont;
7017 snd_pcm_uframes_t f;
7018 snd_pcm_uframes_t avail;
7019 const snd_pcm_channel_area_t *xareas;
7020 assert(pcm && areas && offset && frames);
7021 xareas = snd_pcm_mmap_areas(pcm);
7025 *offset = *pcm->appl.ptr % pcm->buffer_size;
7026 avail = snd_pcm_mmap_avail(pcm);
7027 if (avail > pcm->buffer_size)
7028 avail = pcm->buffer_size;
7029 cont = pcm->buffer_size - *offset;
7041 * \brief Application has completed the access to area requested with #snd_pcm_mmap_begin
7042 * \param pcm PCM handle
7043 * \param offset area offset in area steps (== frames)
7044 * \param frames area portion size in frames
7045 * \return count of transferred frames otherwise a negative error code
7047 * You should pass this function the offset value that
7048 * snd_pcm_mmap_begin() returned. The frames parameter should hold the
7049 * number of frames you have written or read to/from the audio
7050 * buffer. The frames parameter must never exceed the contiguous frames
7051 * count that snd_pcm_mmap_begin() returned. Each call to snd_pcm_mmap_begin()
7052 * must be followed by a call to snd_pcm_mmap_commit().
7057 const snd_pcm_area_t *areas;
7058 snd_pcm_sframes_t avail, size, commitres;
7059 snd_pcm_uframes_t offset, frames;
7062 avail = snd_pcm_avail_update(pcm);
7065 // at this point, we can transfer at least 'avail' frames
7067 // we want to process frames in chunks (period_size)
7068 if (avail < period_size)
7071 // it is possible that contiguous areas are smaller, thus we use a loop
7075 err = snd_pcm_mmap_begin(pcm_handle, &areas, &offset, &frames);
7078 // this function fills the areas from offset with count of frames
7079 generate_sine(areas, offset, frames, &phase);
7080 commitres = snd_pcm_mmap_commit(pcm_handle, offset, frames);
7081 if (commitres < 0 || commitres != frames)
7082 error(commitres >= 0 ? -EPIPE : commitres);
7089 * Look to the \ref example_test_pcm "Sine-wave generator" example
7090 * for more details about the generate_sine function.
7092 * The function is thread-safe when built with the proper option.
7094 snd_pcm_sframes_t snd_pcm_mmap_commit(snd_pcm_t *pcm,
7095 snd_pcm_uframes_t offset,
7096 snd_pcm_uframes_t frames)
7098 snd_pcm_sframes_t result;
7100 if (bad_pcm_state(pcm, P_STATE_RUNNABLE))
7103 result = __snd_pcm_mmap_commit(pcm, offset, frames);
7104 snd_pcm_unlock(pcm);
7110 snd_pcm_sframes_t __snd_pcm_mmap_commit(snd_pcm_t *pcm,
7111 snd_pcm_uframes_t offset,
7112 snd_pcm_uframes_t frames)
7115 if (CHECK_SANITY(offset != *pcm->appl.ptr % pcm->buffer_size)) {
7116 SNDMSG("commit offset (%ld) doesn't match with appl_ptr (%ld) %% buf_size (%ld)",
7117 offset, *pcm->appl.ptr, pcm->buffer_size);
7120 if (CHECK_SANITY(frames > snd_pcm_mmap_avail(pcm))) {
7121 SNDMSG("commit frames (%ld) overflow (avail = %ld)", frames,
7122 snd_pcm_mmap_avail(pcm));
7125 return pcm->fast_ops->mmap_commit(pcm->fast_op_arg, offset, frames);
7128 int _snd_pcm_poll_descriptor(snd_pcm_t *pcm)
7131 return pcm->poll_fd;
7134 void snd_pcm_areas_from_buf(snd_pcm_t *pcm, snd_pcm_channel_area_t *areas,
7137 unsigned int channel;
7138 unsigned int channels;
7141 channels = pcm->channels;
7142 for (channel = 0; channel < channels; ++channel, ++areas) {
7144 areas->first = channel * pcm->sample_bits;
7145 areas->step = pcm->frame_bits;
7147 snd_pcm_unlock(pcm);
7150 void snd_pcm_areas_from_bufs(snd_pcm_t *pcm, snd_pcm_channel_area_t *areas,
7153 unsigned int channel;
7154 unsigned int channels;
7157 channels = pcm->channels;
7158 for (channel = 0; channel < channels; ++channel, ++areas, ++bufs) {
7159 areas->addr = *bufs;
7161 areas->step = pcm->sample_bits;
7163 snd_pcm_unlock(pcm);
7166 snd_pcm_sframes_t snd_pcm_read_areas(snd_pcm_t *pcm, const snd_pcm_channel_area_t *areas,
7167 snd_pcm_uframes_t offset, snd_pcm_uframes_t size,
7168 snd_pcm_xfer_areas_func_t func)
7170 snd_pcm_uframes_t xfer = 0;
7171 snd_pcm_sframes_t err = 0;
7172 snd_pcm_state_t state;
7177 __snd_pcm_lock(pcm); /* forced lock */
7179 snd_pcm_uframes_t frames;
7180 snd_pcm_sframes_t avail;
7182 state = __snd_pcm_state(pcm);
7184 case SND_PCM_STATE_PREPARED:
7185 err = __snd_pcm_start(pcm);
7189 case SND_PCM_STATE_RUNNING:
7190 err = __snd_pcm_hwsync(pcm);
7194 case SND_PCM_STATE_DRAINING:
7195 case SND_PCM_STATE_PAUSED:
7197 case SND_PCM_STATE_XRUN:
7200 case SND_PCM_STATE_SUSPENDED:
7203 case SND_PCM_STATE_DISCONNECTED:
7210 avail = __snd_pcm_avail_update(pcm);
7216 if (state == SND_PCM_STATE_DRAINING)
7218 if (pcm->mode & SND_PCM_NONBLOCK) {
7223 err = __snd_pcm_wait_in_lock(pcm, -1);
7230 if (frames > (snd_pcm_uframes_t) avail)
7234 err = func(pcm, areas, offset, frames);
7243 __snd_pcm_unlock(pcm);
7244 return xfer > 0 ? (snd_pcm_sframes_t) xfer : snd_pcm_check_error(pcm, err);
7247 snd_pcm_sframes_t snd_pcm_write_areas(snd_pcm_t *pcm, const snd_pcm_channel_area_t *areas,
7248 snd_pcm_uframes_t offset, snd_pcm_uframes_t size,
7249 snd_pcm_xfer_areas_func_t func)
7251 snd_pcm_uframes_t xfer = 0;
7252 snd_pcm_sframes_t err = 0;
7253 snd_pcm_state_t state;
7258 __snd_pcm_lock(pcm); /* forced lock */
7260 snd_pcm_uframes_t frames;
7261 snd_pcm_sframes_t avail;
7263 state = __snd_pcm_state(pcm);
7265 case SND_PCM_STATE_PREPARED:
7266 case SND_PCM_STATE_PAUSED:
7268 case SND_PCM_STATE_RUNNING:
7269 err = __snd_pcm_hwsync(pcm);
7273 case SND_PCM_STATE_XRUN:
7276 case SND_PCM_STATE_SUSPENDED:
7279 case SND_PCM_STATE_DISCONNECTED:
7286 avail = __snd_pcm_avail_update(pcm);
7291 if ((state == SND_PCM_STATE_RUNNING &&
7292 size > (snd_pcm_uframes_t)avail &&
7293 snd_pcm_may_wait_for_avail_min(pcm, avail))) {
7294 if (pcm->mode & SND_PCM_NONBLOCK) {
7299 err = snd_pcm_wait_nocheck(pcm, -1);
7305 if (frames > (snd_pcm_uframes_t) avail)
7309 err = func(pcm, areas, offset, frames);
7313 if (state == SND_PCM_STATE_PREPARED) {
7314 snd_pcm_sframes_t hw_avail = pcm->buffer_size - avail;
7316 /* some plugins might automatically start the stream */
7317 state = __snd_pcm_state(pcm);
7318 if (state == SND_PCM_STATE_PREPARED &&
7319 hw_avail >= (snd_pcm_sframes_t) pcm->start_threshold) {
7320 err = __snd_pcm_start(pcm);
7330 __snd_pcm_unlock(pcm);
7331 return xfer > 0 ? (snd_pcm_sframes_t) xfer : snd_pcm_check_error(pcm, err);
7334 snd_pcm_uframes_t _snd_pcm_mmap_hw_ptr(snd_pcm_t *pcm)
7336 return *pcm->hw.ptr;
7339 snd_pcm_uframes_t _snd_pcm_boundary(snd_pcm_t *pcm)
7341 return pcm->boundary;
7345 link_warning(_snd_pcm_mmap_hw_ptr, "Warning: _snd_pcm_mmap_hw_ptr() is deprecated, consider to not use this function");
7346 link_warning(_snd_pcm_boundary, "Warning: _snd_pcm_boundary() is deprecated, consider to use snd_pcm_sw_params_current()");
7349 static const char *const names[SND_PCM_HW_PARAM_LAST_INTERVAL + 1] = {
7350 [SND_PCM_HW_PARAM_FORMAT] = "format",
7351 [SND_PCM_HW_PARAM_CHANNELS] = "channels",
7352 [SND_PCM_HW_PARAM_RATE] = "rate",
7353 [SND_PCM_HW_PARAM_PERIOD_TIME] = "period_time",
7354 [SND_PCM_HW_PARAM_PERIOD_SIZE] = "period_size",
7355 [SND_PCM_HW_PARAM_BUFFER_TIME] = "buffer_time",
7356 [SND_PCM_HW_PARAM_BUFFER_SIZE] = "buffer_size",
7357 [SND_PCM_HW_PARAM_PERIODS] = "periods"
7360 int snd_pcm_slave_conf(snd_config_t *root, snd_config_t *conf,
7361 snd_config_t **_pcm_conf, unsigned int count, ...)
7363 snd_config_iterator_t i, next;
7372 snd_config_t *pcm_conf = NULL;
7379 if (snd_config_get_string(conf, &str) >= 0) {
7380 err = snd_config_search_definition(root, "pcm_slave", str, &conf);
7382 SNDERR("Invalid slave definition");
7387 if (snd_config_get_type(conf) != SND_CONFIG_TYPE_COMPOUND) {
7388 SNDERR("Invalid slave definition");
7392 va_start(args, count);
7393 for (k = 0; k < count; ++k) {
7394 fields[k].index = va_arg(args, int);
7395 fields[k].flags = va_arg(args, int);
7396 fields[k].ptr = va_arg(args, void *);
7397 fields[k].present = 0;
7400 snd_config_for_each(i, next, conf) {
7401 snd_config_t *n = snd_config_iterator_entry(i);
7403 if (snd_config_get_id(n, &id) < 0)
7405 if (strcmp(id, "comment") == 0)
7407 if (strcmp(id, "pcm") == 0) {
7408 if (pcm_conf != NULL)
7409 snd_config_delete(pcm_conf);
7410 if ((err = snd_config_copy(&pcm_conf, n)) < 0)
7414 for (k = 0; k < count; ++k) {
7415 unsigned int idx = fields[k].index;
7417 assert(idx < SND_PCM_HW_PARAM_LAST_INTERVAL);
7419 if (strcmp(id, names[idx]) != 0)
7422 case SND_PCM_HW_PARAM_FORMAT:
7425 err = snd_config_get_string(n, &str);
7428 SNDERR("invalid type for %s", id);
7431 if ((fields[k].flags & SCONF_UNCHANGED) &&
7432 strcasecmp(str, "unchanged") == 0) {
7433 *(snd_pcm_format_t*)fields[k].ptr = (snd_pcm_format_t) -2;
7436 f = snd_pcm_format_value(str);
7437 if (f == SND_PCM_FORMAT_UNKNOWN) {
7438 SNDERR("unknown format %s", str);
7442 *(snd_pcm_format_t*)fields[k].ptr = f;
7446 if ((fields[k].flags & SCONF_UNCHANGED)) {
7447 err = snd_config_get_string(n, &str);
7449 strcasecmp(str, "unchanged") == 0) {
7450 *(int*)fields[k].ptr = -2;
7454 err = snd_config_get_integer(n, &v);
7457 *(int*)fields[k].ptr = v;
7460 fields[k].present = 1;
7465 SNDERR("Unknown field %s", id);
7470 SNDERR("missing field pcm");
7474 for (k = 0; k < count; ++k) {
7475 if ((fields[k].flags & SCONF_MANDATORY) && !fields[k].present) {
7476 SNDERR("missing field %s", names[fields[k].index]);
7481 *_pcm_conf = pcm_conf;
7486 snd_config_delete(pcm_conf);
7488 snd_config_delete(conf);
7492 static void snd_pcm_set_ptr(snd_pcm_t *pcm, snd_pcm_rbptr_t *rbptr,
7493 volatile snd_pcm_uframes_t *hw_ptr, int fd, off_t offset)
7495 rbptr->master = NULL; /* I'm master */
7496 rbptr->ptr = hw_ptr;
7498 rbptr->offset = offset;
7500 rbptr->changed(pcm, NULL);
7503 void snd_pcm_set_hw_ptr(snd_pcm_t *pcm, volatile snd_pcm_uframes_t *hw_ptr, int fd, off_t offset)
7507 snd_pcm_set_ptr(pcm, &pcm->hw, hw_ptr, fd, offset);
7510 void snd_pcm_set_appl_ptr(snd_pcm_t *pcm, volatile snd_pcm_uframes_t *appl_ptr, int fd, off_t offset)
7514 snd_pcm_set_ptr(pcm, &pcm->appl, appl_ptr, fd, offset);
7517 static void snd_pcm_link_ptr(snd_pcm_t *pcm, snd_pcm_rbptr_t *pcm_rbptr,
7518 snd_pcm_t *slave, snd_pcm_rbptr_t *slave_rbptr)
7523 a = slave_rbptr->link_dst;
7524 for (idx = 0; idx < slave_rbptr->link_dst_count; idx++)
7525 if (a[idx] == NULL) {
7527 goto __found_free_place;
7529 a = realloc(a, sizeof(snd_pcm_t *) * (slave_rbptr->link_dst_count + 1));
7531 pcm_rbptr->ptr = NULL;
7533 pcm_rbptr->offset = 0UL;
7536 a[slave_rbptr->link_dst_count++] = pcm;
7538 pcm_rbptr->master = slave_rbptr->master ? slave_rbptr->master : slave;
7539 pcm_rbptr->ptr = slave_rbptr->ptr;
7540 pcm_rbptr->fd = slave_rbptr->fd;
7541 pcm_rbptr->offset = slave_rbptr->offset;
7542 slave_rbptr->link_dst = a;
7543 if (pcm_rbptr->changed)
7544 pcm_rbptr->changed(pcm, slave);
7547 static void snd_pcm_unlink_ptr(snd_pcm_t *pcm, snd_pcm_rbptr_t *pcm_rbptr,
7548 snd_pcm_t *slave, snd_pcm_rbptr_t *slave_rbptr)
7553 a = slave_rbptr->link_dst;
7554 for (idx = 0; idx < slave_rbptr->link_dst_count; idx++) {
7555 if (a[idx] == pcm) {
7564 pcm_rbptr->master = NULL;
7565 pcm_rbptr->ptr = NULL;
7567 pcm_rbptr->offset = 0UL;
7568 if (pcm_rbptr->changed)
7569 pcm_rbptr->changed(pcm, slave);
7572 void snd_pcm_link_hw_ptr(snd_pcm_t *pcm, snd_pcm_t *slave)
7576 snd_pcm_link_ptr(pcm, &pcm->hw, slave, &slave->hw);
7579 void snd_pcm_link_appl_ptr(snd_pcm_t *pcm, snd_pcm_t *slave)
7583 snd_pcm_link_ptr(pcm, &pcm->appl, slave, &slave->appl);
7586 void snd_pcm_unlink_hw_ptr(snd_pcm_t *pcm, snd_pcm_t *slave)
7590 snd_pcm_unlink_ptr(pcm, &pcm->hw, slave, &slave->hw);
7593 void snd_pcm_unlink_appl_ptr(snd_pcm_t *pcm, snd_pcm_t *slave)
7597 snd_pcm_unlink_ptr(pcm, &pcm->appl, slave, &slave->appl);
7600 #endif /* DOC_HIDDEN */
7608 #ifdef USE_VERSIONED_SYMBOLS
7610 #define OBSOLETE1(name, what, new) \
7611 default_symbol_version(__##name, name, new); \
7612 symbol_version(__old_##name, name, what);
7616 #define OBSOLETE1(name, what, new) \
7617 use_default_symbol_version(__##name, name, new);
7619 #endif /* USE_VERSIONED_SYMBOLS */
7621 #define __P_OLD_GET(pfx, name, val_type, ret_type) \
7622 ret_type pfx##name(const snd_pcm_hw_params_t *params) \
7625 if (INTERNAL(name)(params, &val) < 0) \
7627 return (ret_type)val; \
7630 #define __P_OLD_GET1(pfx, name, val_type, ret_type) \
7631 ret_type pfx##name(const snd_pcm_hw_params_t *params, int *dir) \
7634 if (INTERNAL(name)(params, &val, dir) < 0) \
7636 return (ret_type)val; \
7639 #define __OLD_GET(name, val_type, ret_type) __P_OLD_GET(__old_, name, val_type, ret_type)
7640 #define __OLD_GET1(name, val_type, ret_type) __P_OLD_GET1(__old_, name, val_type, ret_type)
7642 __OLD_GET(snd_pcm_hw_params_get_access, snd_pcm_access_t, int);
7643 __OLD_GET(snd_pcm_hw_params_get_format, snd_pcm_format_t, int);
7644 __OLD_GET(snd_pcm_hw_params_get_subformat, snd_pcm_subformat_t, int);
7645 __OLD_GET(snd_pcm_hw_params_get_channels, unsigned int, int);
7646 __OLD_GET1(snd_pcm_hw_params_get_rate, unsigned int, int);
7647 __OLD_GET1(snd_pcm_hw_params_get_period_time, unsigned int, int);
7648 __OLD_GET1(snd_pcm_hw_params_get_period_size, snd_pcm_uframes_t, snd_pcm_sframes_t);
7649 __OLD_GET1(snd_pcm_hw_params_get_periods, unsigned int, int);
7650 __OLD_GET1(snd_pcm_hw_params_get_buffer_time, unsigned int, int);
7651 __OLD_GET(snd_pcm_hw_params_get_buffer_size, snd_pcm_uframes_t, snd_pcm_sframes_t);
7652 __OLD_GET1(snd_pcm_hw_params_get_tick_time, unsigned int, int);
7654 __OLD_GET(snd_pcm_hw_params_get_channels_min, unsigned int, unsigned int);
7655 __OLD_GET1(snd_pcm_hw_params_get_rate_min, unsigned int, unsigned int);
7656 __OLD_GET1(snd_pcm_hw_params_get_period_time_min, unsigned int, unsigned int);
7657 __OLD_GET1(snd_pcm_hw_params_get_period_size_min, snd_pcm_uframes_t, snd_pcm_uframes_t);
7658 __OLD_GET1(snd_pcm_hw_params_get_periods_min, unsigned int, unsigned int);
7659 __OLD_GET1(snd_pcm_hw_params_get_buffer_time_min, unsigned int, unsigned int);
7660 __OLD_GET(snd_pcm_hw_params_get_buffer_size_min, snd_pcm_uframes_t, snd_pcm_uframes_t);
7661 __OLD_GET1(snd_pcm_hw_params_get_tick_time_min, unsigned int, unsigned int);
7663 __OLD_GET(snd_pcm_hw_params_get_channels_max, unsigned int, unsigned int);
7664 __OLD_GET1(snd_pcm_hw_params_get_rate_max, unsigned int, unsigned int);
7665 __OLD_GET1(snd_pcm_hw_params_get_period_time_max, unsigned int, unsigned int);
7666 __OLD_GET1(snd_pcm_hw_params_get_period_size_max, snd_pcm_uframes_t, snd_pcm_uframes_t);
7667 __OLD_GET1(snd_pcm_hw_params_get_periods_max, unsigned int, unsigned int);
7668 __OLD_GET1(snd_pcm_hw_params_get_buffer_time_max, unsigned int, unsigned int);
7669 __OLD_GET(snd_pcm_hw_params_get_buffer_size_max, snd_pcm_uframes_t, snd_pcm_uframes_t);
7670 __OLD_GET1(snd_pcm_hw_params_get_tick_time_max, unsigned int, unsigned int);
7672 #define __P_OLD_NEAR(pfx, name, ret_type) \
7673 ret_type pfx##name(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, ret_type val) \
7675 if (INTERNAL(name)(pcm, params, &val) < 0) \
7677 return (ret_type)val; \
7680 #define __P_OLD_NEAR1(pfx, name, ret_type) \
7681 ret_type pfx##name(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, ret_type val, int *dir) \
7683 if (INTERNAL(name)(pcm, params, &val, dir) < 0) \
7685 return (ret_type)val; \
7688 #define __OLD_NEAR(name, ret_type) __P_OLD_NEAR(__old_, name, ret_type)
7689 #define __OLD_NEAR1(name, ret_type) __P_OLD_NEAR1(__old_, name, ret_type)
7691 __OLD_NEAR(snd_pcm_hw_params_set_channels_near, unsigned int);
7692 __OLD_NEAR1(snd_pcm_hw_params_set_rate_near, unsigned int);
7693 __OLD_NEAR1(snd_pcm_hw_params_set_period_time_near, unsigned int);
7694 __OLD_NEAR1(snd_pcm_hw_params_set_period_size_near, snd_pcm_uframes_t);
7695 __OLD_NEAR1(snd_pcm_hw_params_set_periods_near, unsigned int);
7696 __OLD_NEAR1(snd_pcm_hw_params_set_buffer_time_near, unsigned int);
7697 __OLD_NEAR(snd_pcm_hw_params_set_buffer_size_near, snd_pcm_uframes_t);
7698 __OLD_NEAR1(snd_pcm_hw_params_set_tick_time_near, unsigned int);
7700 #define __P_OLD_SET_FL(pfx, name, ret_type) \
7701 ret_type pfx##name(snd_pcm_t *pcm, snd_pcm_hw_params_t *params) \
7704 if (INTERNAL(name)(pcm, params, &val) < 0) \
7706 return (ret_type)val; \
7709 #define __P_OLD_SET_FL1(pfx, name, ret_type) \
7710 ret_type pfx##name(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, int *dir) \
7713 if (INTERNAL(name)(pcm, params, &val, dir) < 0) \
7715 return (ret_type)val; \
7718 #define __OLD_SET_FL(name, ret_type) __P_OLD_SET_FL(__old_, name, ret_type)
7719 #define __OLD_SET_FL1(name, ret_type) __P_OLD_SET_FL1(__old_, name, ret_type)
7721 __OLD_SET_FL(snd_pcm_hw_params_set_access_first, snd_pcm_access_t);
7722 __OLD_SET_FL(snd_pcm_hw_params_set_format_first, snd_pcm_format_t);
7723 __OLD_SET_FL(snd_pcm_hw_params_set_subformat_first, snd_pcm_subformat_t);
7724 __OLD_SET_FL(snd_pcm_hw_params_set_channels_first, unsigned int);
7725 __OLD_SET_FL1(snd_pcm_hw_params_set_rate_first, unsigned int);
7726 __OLD_SET_FL1(snd_pcm_hw_params_set_period_time_first, unsigned int);
7727 __OLD_SET_FL1(snd_pcm_hw_params_set_period_size_first, snd_pcm_uframes_t);
7728 __OLD_SET_FL1(snd_pcm_hw_params_set_periods_first, unsigned int);
7729 __OLD_SET_FL1(snd_pcm_hw_params_set_buffer_time_first, unsigned int);
7730 __OLD_SET_FL(snd_pcm_hw_params_set_buffer_size_first, snd_pcm_uframes_t);
7731 __OLD_SET_FL1(snd_pcm_hw_params_set_tick_time_first, unsigned int);
7733 __OLD_SET_FL(snd_pcm_hw_params_set_access_last, snd_pcm_access_t);
7734 __OLD_SET_FL(snd_pcm_hw_params_set_format_last, snd_pcm_format_t);
7735 __OLD_SET_FL(snd_pcm_hw_params_set_subformat_last, snd_pcm_subformat_t);
7736 __OLD_SET_FL(snd_pcm_hw_params_set_channels_last, unsigned int);
7737 __OLD_SET_FL1(snd_pcm_hw_params_set_rate_last, unsigned int);
7738 __OLD_SET_FL1(snd_pcm_hw_params_set_period_time_last, unsigned int);
7739 __OLD_SET_FL1(snd_pcm_hw_params_set_period_size_last, snd_pcm_uframes_t);
7740 __OLD_SET_FL1(snd_pcm_hw_params_set_periods_last, unsigned int);
7741 __OLD_SET_FL1(snd_pcm_hw_params_set_buffer_time_last, unsigned int);
7742 __OLD_SET_FL(snd_pcm_hw_params_set_buffer_size_last, snd_pcm_uframes_t);
7743 __OLD_SET_FL1(snd_pcm_hw_params_set_tick_time_last, unsigned int);
7745 #define __P_OLD_GET_SW(pfx, name, ret_type) \
7746 ret_type pfx##name(snd_pcm_sw_params_t *params) \
7749 if (INTERNAL(name)(params, &val) < 0) \
7751 return (ret_type)val; \
7754 #define __OLD_GET_SW(name, ret_type) __P_OLD_GET_SW(__old_, name, ret_type)
7756 __OLD_GET_SW(snd_pcm_sw_params_get_tstamp_mode, snd_pcm_tstamp_t);
7757 __OLD_GET_SW(snd_pcm_sw_params_get_sleep_min, unsigned int);
7758 __OLD_GET_SW(snd_pcm_sw_params_get_avail_min, snd_pcm_uframes_t);
7759 __OLD_GET_SW(snd_pcm_sw_params_get_xfer_align, snd_pcm_uframes_t);
7760 __OLD_GET_SW(snd_pcm_sw_params_get_start_threshold, snd_pcm_uframes_t);
7761 __OLD_GET_SW(snd_pcm_sw_params_get_stop_threshold, snd_pcm_uframes_t);
7762 __OLD_GET_SW(snd_pcm_sw_params_get_silence_threshold, snd_pcm_uframes_t);
7763 __OLD_GET_SW(snd_pcm_sw_params_get_silence_size, snd_pcm_uframes_t);
7765 OBSOLETE1(snd_pcm_hw_params_get_access, ALSA_0.9, ALSA_0.9.0rc4);
7766 OBSOLETE1(snd_pcm_hw_params_set_access_first, ALSA_0.9, ALSA_0.9.0rc4);
7767 OBSOLETE1(snd_pcm_hw_params_set_access_last, ALSA_0.9, ALSA_0.9.0rc4);
7769 OBSOLETE1(snd_pcm_hw_params_get_format, ALSA_0.9, ALSA_0.9.0rc4);
7770 OBSOLETE1(snd_pcm_hw_params_set_format_first, ALSA_0.9, ALSA_0.9.0rc4);
7771 OBSOLETE1(snd_pcm_hw_params_set_format_last, ALSA_0.9, ALSA_0.9.0rc4);
7773 OBSOLETE1(snd_pcm_hw_params_get_subformat, ALSA_0.9, ALSA_0.9.0rc4);
7774 OBSOLETE1(snd_pcm_hw_params_set_subformat_first, ALSA_0.9, ALSA_0.9.0rc4);
7775 OBSOLETE1(snd_pcm_hw_params_set_subformat_last, ALSA_0.9, ALSA_0.9.0rc4);
7777 OBSOLETE1(snd_pcm_hw_params_get_channels, ALSA_0.9, ALSA_0.9.0rc4);
7778 OBSOLETE1(snd_pcm_hw_params_get_channels_min, ALSA_0.9, ALSA_0.9.0rc4);
7779 OBSOLETE1(snd_pcm_hw_params_get_channels_max, ALSA_0.9, ALSA_0.9.0rc4);
7780 OBSOLETE1(snd_pcm_hw_params_set_channels_near, ALSA_0.9, ALSA_0.9.0rc4);
7781 OBSOLETE1(snd_pcm_hw_params_set_channels_first, ALSA_0.9, ALSA_0.9.0rc4);
7782 OBSOLETE1(snd_pcm_hw_params_set_channels_last, ALSA_0.9, ALSA_0.9.0rc4);
7784 OBSOLETE1(snd_pcm_hw_params_get_rate, ALSA_0.9, ALSA_0.9.0rc4);
7785 OBSOLETE1(snd_pcm_hw_params_get_rate_min, ALSA_0.9, ALSA_0.9.0rc4);
7786 OBSOLETE1(snd_pcm_hw_params_get_rate_max, ALSA_0.9, ALSA_0.9.0rc4);
7787 OBSOLETE1(snd_pcm_hw_params_set_rate_near, ALSA_0.9, ALSA_0.9.0rc4);
7788 OBSOLETE1(snd_pcm_hw_params_set_rate_first, ALSA_0.9, ALSA_0.9.0rc4);
7789 OBSOLETE1(snd_pcm_hw_params_set_rate_last, ALSA_0.9, ALSA_0.9.0rc4);
7791 OBSOLETE1(snd_pcm_hw_params_get_period_time, ALSA_0.9, ALSA_0.9.0rc4);
7792 OBSOLETE1(snd_pcm_hw_params_get_period_time_min, ALSA_0.9, ALSA_0.9.0rc4);
7793 OBSOLETE1(snd_pcm_hw_params_get_period_time_max, ALSA_0.9, ALSA_0.9.0rc4);
7794 OBSOLETE1(snd_pcm_hw_params_set_period_time_near, ALSA_0.9, ALSA_0.9.0rc4);
7795 OBSOLETE1(snd_pcm_hw_params_set_period_time_first, ALSA_0.9, ALSA_0.9.0rc4);
7796 OBSOLETE1(snd_pcm_hw_params_set_period_time_last, ALSA_0.9, ALSA_0.9.0rc4);
7798 OBSOLETE1(snd_pcm_hw_params_get_period_size, ALSA_0.9, ALSA_0.9.0rc4);
7799 OBSOLETE1(snd_pcm_hw_params_get_period_size_min, ALSA_0.9, ALSA_0.9.0rc4);
7800 OBSOLETE1(snd_pcm_hw_params_get_period_size_max, ALSA_0.9, ALSA_0.9.0rc4);
7801 OBSOLETE1(snd_pcm_hw_params_set_period_size_near, ALSA_0.9, ALSA_0.9.0rc4);
7802 OBSOLETE1(snd_pcm_hw_params_set_period_size_first, ALSA_0.9, ALSA_0.9.0rc4);
7803 OBSOLETE1(snd_pcm_hw_params_set_period_size_last, ALSA_0.9, ALSA_0.9.0rc4);
7805 OBSOLETE1(snd_pcm_hw_params_get_periods, ALSA_0.9, ALSA_0.9.0rc4);
7806 OBSOLETE1(snd_pcm_hw_params_get_periods_min, ALSA_0.9, ALSA_0.9.0rc4);
7807 OBSOLETE1(snd_pcm_hw_params_get_periods_max, ALSA_0.9, ALSA_0.9.0rc4);
7808 OBSOLETE1(snd_pcm_hw_params_set_periods_near, ALSA_0.9, ALSA_0.9.0rc4);
7809 OBSOLETE1(snd_pcm_hw_params_set_periods_first, ALSA_0.9, ALSA_0.9.0rc4);
7810 OBSOLETE1(snd_pcm_hw_params_set_periods_last, ALSA_0.9, ALSA_0.9.0rc4);
7812 OBSOLETE1(snd_pcm_hw_params_get_buffer_time, ALSA_0.9, ALSA_0.9.0rc4);
7813 OBSOLETE1(snd_pcm_hw_params_get_buffer_time_min, ALSA_0.9, ALSA_0.9.0rc4);
7814 OBSOLETE1(snd_pcm_hw_params_get_buffer_time_max, ALSA_0.9, ALSA_0.9.0rc4);
7815 OBSOLETE1(snd_pcm_hw_params_set_buffer_time_near, ALSA_0.9, ALSA_0.9.0rc4);
7816 OBSOLETE1(snd_pcm_hw_params_set_buffer_time_first, ALSA_0.9, ALSA_0.9.0rc4);
7817 OBSOLETE1(snd_pcm_hw_params_set_buffer_time_last, ALSA_0.9, ALSA_0.9.0rc4);
7819 OBSOLETE1(snd_pcm_hw_params_get_buffer_size, ALSA_0.9, ALSA_0.9.0rc4);
7820 OBSOLETE1(snd_pcm_hw_params_get_buffer_size_min, ALSA_0.9, ALSA_0.9.0rc4);
7821 OBSOLETE1(snd_pcm_hw_params_get_buffer_size_max, ALSA_0.9, ALSA_0.9.0rc4);
7822 OBSOLETE1(snd_pcm_hw_params_set_buffer_size_near, ALSA_0.9, ALSA_0.9.0rc4);
7823 OBSOLETE1(snd_pcm_hw_params_set_buffer_size_first, ALSA_0.9, ALSA_0.9.0rc4);
7824 OBSOLETE1(snd_pcm_hw_params_set_buffer_size_last, ALSA_0.9, ALSA_0.9.0rc4);
7826 OBSOLETE1(snd_pcm_hw_params_get_tick_time, ALSA_0.9, ALSA_0.9.0rc4);
7827 OBSOLETE1(snd_pcm_hw_params_get_tick_time_min, ALSA_0.9, ALSA_0.9.0rc4);
7828 OBSOLETE1(snd_pcm_hw_params_get_tick_time_max, ALSA_0.9, ALSA_0.9.0rc4);
7829 OBSOLETE1(snd_pcm_hw_params_set_tick_time_near, ALSA_0.9, ALSA_0.9.0rc4);
7830 OBSOLETE1(snd_pcm_hw_params_set_tick_time_first, ALSA_0.9, ALSA_0.9.0rc4);
7831 OBSOLETE1(snd_pcm_hw_params_set_tick_time_last, ALSA_0.9, ALSA_0.9.0rc4);
7833 OBSOLETE1(snd_pcm_sw_params_get_tstamp_mode, ALSA_0.9, ALSA_0.9.0rc4);
7834 OBSOLETE1(snd_pcm_sw_params_get_sleep_min, ALSA_0.9, ALSA_0.9.0rc4);
7835 OBSOLETE1(snd_pcm_sw_params_get_avail_min, ALSA_0.9, ALSA_0.9.0rc4);
7836 OBSOLETE1(snd_pcm_sw_params_get_xfer_align, ALSA_0.9, ALSA_0.9.0rc4);
7837 OBSOLETE1(snd_pcm_sw_params_get_start_threshold, ALSA_0.9, ALSA_0.9.0rc4);
7838 OBSOLETE1(snd_pcm_sw_params_get_stop_threshold, ALSA_0.9, ALSA_0.9.0rc4);
7839 OBSOLETE1(snd_pcm_sw_params_get_silence_threshold, ALSA_0.9, ALSA_0.9.0rc4);
7840 OBSOLETE1(snd_pcm_sw_params_get_silence_size, ALSA_0.9, ALSA_0.9.0rc4);
7842 #endif /* DOC_HIDDEN */
7844 static int chmap_equal(const snd_pcm_chmap_t *a, const snd_pcm_chmap_t *b)
7846 if (a->channels != b->channels)
7848 return !memcmp(a->pos, b->pos, a->channels * sizeof(a->pos[0]));
7852 * \!brief Query the available channel maps
7853 * \param pcm PCM handle to query
7854 * \return the NULL-terminated array of integer pointers, each of
7855 * which contains the channel map. A channel map is represented by an
7856 * integer array, beginning with the channel map type, followed by the
7857 * number of channels, and the position of each channel.
7859 * Note: the caller is requested to release the returned value via
7860 * snd_pcm_free_chmaps().
7862 snd_pcm_chmap_query_t **snd_pcm_query_chmaps(snd_pcm_t *pcm)
7864 if (!pcm->ops->query_chmaps)
7866 return pcm->ops->query_chmaps(pcm);
7870 * \!brief Release the channel map array allocated via #snd_pcm_query_chmaps
7871 * \param maps the array pointer to release
7873 void snd_pcm_free_chmaps(snd_pcm_chmap_query_t **maps)
7875 snd_pcm_chmap_query_t **p;
7878 for (p = maps; *p; p++)
7884 * \!brief Get the current channel map
7885 * \param pcm PCM instance
7886 * \return the current channel map, or NULL if error
7888 * Note: the caller is requested to release the returned value via free()
7890 snd_pcm_chmap_t *snd_pcm_get_chmap(snd_pcm_t *pcm)
7892 if (!pcm->ops->get_chmap)
7894 return pcm->ops->get_chmap(pcm);
7898 * \!brief Configure the current channel map
7899 * \param pcm PCM instance
7900 * \param map the channel map to write
7901 * \return zero if succeeded, or a negative error code
7903 int snd_pcm_set_chmap(snd_pcm_t *pcm, const snd_pcm_chmap_t *map)
7905 const snd_pcm_chmap_t *oldmap = snd_pcm_get_chmap(pcm);
7906 if (oldmap && chmap_equal(oldmap, map))
7909 if (!pcm->ops->set_chmap)
7911 return pcm->ops->set_chmap(pcm, map);
7917 #define _NAME(n) [SND_CHMAP_TYPE_##n] = #n
7918 static const char *chmap_type_names[SND_CHMAP_TYPE_LAST + 1] = {
7919 _NAME(NONE), _NAME(FIXED), _NAME(VAR), _NAME(PAIRED),
7925 * \!brief Get a name string for a channel map type as query results
7926 * \param val Channel position
7927 * \return The string corresponding to the given type, or NULL
7929 const char *snd_pcm_chmap_type_name(enum snd_pcm_chmap_type val)
7931 if (val <= SND_CHMAP_TYPE_LAST)
7932 return chmap_type_names[val];
7938 #define _NAME(n) [SND_CHMAP_##n] = #n
7939 static const char *chmap_names[SND_CHMAP_LAST + 1] = {
7940 _NAME(UNKNOWN), _NAME(NA), _NAME(MONO),
7941 _NAME(FL), _NAME(FR),
7942 _NAME(RL), _NAME(RR),
7943 _NAME(FC), _NAME(LFE),
7944 _NAME(SL), _NAME(SR),
7945 _NAME(RC), _NAME(FLC), _NAME(FRC), _NAME(RLC), _NAME(RRC),
7946 _NAME(FLW), _NAME(FRW),
7947 _NAME(FLH), _NAME(FCH), _NAME(FRH), _NAME(TC),
7948 _NAME(TFL), _NAME(TFR), _NAME(TFC),
7949 _NAME(TRL), _NAME(TRR), _NAME(TRC),
7950 _NAME(TFLC), _NAME(TFRC), _NAME(TSL), _NAME(TSR),
7951 _NAME(LLFE), _NAME(RLFE),
7952 _NAME(BC), _NAME(BLC), _NAME(BRC),
7958 * \!brief Get a name string for a standard channel map position
7959 * \param val Channel position
7960 * \return The string corresponding to the given position, or NULL
7962 const char *snd_pcm_chmap_name(enum snd_pcm_chmap_position val)
7964 if (val <= SND_CHMAP_LAST)
7965 return chmap_names[val];
7970 static const char *chmap_long_names[SND_CHMAP_LAST + 1] = {
7971 [SND_CHMAP_UNKNOWN] = "Unknown",
7972 [SND_CHMAP_NA] = "Unused",
7973 [SND_CHMAP_MONO] = "Mono",
7974 [SND_CHMAP_FL] = "Front Left",
7975 [SND_CHMAP_FR] = "Front Right",
7976 [SND_CHMAP_RL] = "Rear Left",
7977 [SND_CHMAP_RR] = "Rear Right",
7978 [SND_CHMAP_FC] = "Front Center",
7979 [SND_CHMAP_LFE] = "LFE",
7980 [SND_CHMAP_SL] = "Side Left",
7981 [SND_CHMAP_SR] = "Side Right",
7982 [SND_CHMAP_RC] = "Rear Center",
7983 [SND_CHMAP_FLC] = "Front Left Center",
7984 [SND_CHMAP_FRC] = "Front Right Center",
7985 [SND_CHMAP_RLC] = "Rear Left Center",
7986 [SND_CHMAP_RRC] = "Rear Right Center",
7987 [SND_CHMAP_FLW] = "Front Left Wide",
7988 [SND_CHMAP_FRW] = "Front Right Wide",
7989 [SND_CHMAP_FLH] = "Front Left High",
7990 [SND_CHMAP_FCH] = "Front Center High",
7991 [SND_CHMAP_FRH] = "Front Right High",
7992 [SND_CHMAP_TC] = "Top Center",
7993 [SND_CHMAP_TFL] = "Top Front Left",
7994 [SND_CHMAP_TFR] = "Top Front Right",
7995 [SND_CHMAP_TFC] = "Top Front Center",
7996 [SND_CHMAP_TRL] = "Top Rear Left",
7997 [SND_CHMAP_TRR] = "Top Rear Right",
7998 [SND_CHMAP_TRC] = "Top Rear Center",
7999 [SND_CHMAP_TFLC] = "Top Front Left Center",
8000 [SND_CHMAP_TFRC] = "Top Front Right Center",
8001 [SND_CHMAP_TSL] = "Top Side Left",
8002 [SND_CHMAP_TSR] = "Top Side Right",
8003 [SND_CHMAP_LLFE] = "Left LFE",
8004 [SND_CHMAP_RLFE] = "Right LFE",
8005 [SND_CHMAP_BC] = "Bottom Center",
8006 [SND_CHMAP_BLC] = "Bottom Left Center",
8007 [SND_CHMAP_BRC] = "Bottom Right Center",
8011 * \!brief Get a longer name string for a standard channel map position
8012 * \param val Channel position
8013 * \return The string corresponding to the given position, or NULL
8015 const char *snd_pcm_chmap_long_name(enum snd_pcm_chmap_position val)
8017 if (val <= SND_CHMAP_LAST)
8018 return chmap_long_names[val];
8024 * \!brief Print the channels in chmap on the buffer
8025 * \param map The channel map to print
8026 * \param maxlen The maximal length to write (including NUL letter)
8027 * \param buf The buffer to write
8028 * \return The actual string length or a negative error code
8030 int snd_pcm_chmap_print(const snd_pcm_chmap_t *map, size_t maxlen, char *buf)
8032 unsigned int i, len = 0;
8034 for (i = 0; i < map->channels; i++) {
8035 unsigned int p = map->pos[i] & SND_CHMAP_POSITION_MASK;
8037 len += snprintf(buf + len, maxlen - len, " ");
8041 if (map->pos[i] & SND_CHMAP_DRIVER_SPEC)
8042 len += snprintf(buf + len, maxlen - len, "%d", p);
8044 const char *name = chmap_names[p];
8046 len += snprintf(buf + len, maxlen - len,
8049 len += snprintf(buf + len, maxlen - len,
8054 if (map->pos[i] & SND_CHMAP_PHASE_INVERSE) {
8055 len += snprintf(buf + len, maxlen - len, "[INV]");
8063 static int str_to_chmap(const char *str, int len)
8069 if (isdigit(*str)) {
8070 v = strtoul(str, &p, 0);
8074 val |= SND_CHMAP_DRIVER_SPEC;
8076 } else if (!strncasecmp(str, "ch", 2)) {
8077 v = strtoul(str + 2, &p, 0);
8083 for (val = 0; val <= SND_CHMAP_LAST; val++) {
8085 assert(chmap_names[val]);
8086 slen = strlen(chmap_names[val]);
8089 if (!strncasecmp(str, chmap_names[val], slen) &&
8090 !isalpha(str[slen])) {
8095 if (val > SND_CHMAP_LAST)
8098 if (str && !strncasecmp(str, "[INV]", 5))
8099 val |= SND_CHMAP_PHASE_INVERSE;
8104 * \!brief Convert from string to channel position
8105 * \param str The string to parse
8106 * \return The channel position value or -1 as an error
8108 unsigned int snd_pcm_chmap_from_string(const char *str)
8110 return str_to_chmap(str, strlen(str));
8114 * \!brief Convert from string to channel map
8115 * \param str The string to parse
8116 * \return The channel map
8118 * Note: the caller is requested to release the returned value via free()
8120 snd_pcm_chmap_t *snd_pcm_chmap_parse_string(const char *str)
8124 snd_pcm_chmap_t *map;
8130 if (ch >= (int)(sizeof(tmp_map) / sizeof(tmp_map[0])))
8132 for (p = str; *p && isalnum(*p); p++)
8137 val = str_to_chmap(str, len);
8142 if (!strncmp(str, "[INV]", 5)) {
8143 val |= SND_CHMAP_PHASE_INVERSE;
8149 for (; *str && !isalnum(*str); str++)
8154 map = malloc(sizeof(*map) + ch * sizeof(int));
8158 for (i = 0; i < ch; i++)
8159 map->pos[i] = tmp_map[i];
8163 /* copy a single channel map with the fixed type to chmap_query pointer */
8164 static int _copy_to_fixed_query_map(snd_pcm_chmap_query_t **dst,
8165 const snd_pcm_chmap_t *src)
8167 *dst = malloc((src->channels + 2) * sizeof(int));
8170 (*dst)->type = SND_CHMAP_TYPE_FIXED;
8171 memcpy(&(*dst)->map, src, (src->channels + 1) * sizeof(int));
8176 /* make a chmap_query array from a single channel map */
8177 snd_pcm_chmap_query_t **
8178 _snd_pcm_make_single_query_chmaps(const snd_pcm_chmap_t *src)
8180 snd_pcm_chmap_query_t **maps;
8182 maps = calloc(2, sizeof(*maps));
8185 if (_copy_to_fixed_query_map(maps, src)) {
8192 /* make a copy of chmap */
8193 snd_pcm_chmap_t *_snd_pcm_copy_chmap(const snd_pcm_chmap_t *src)
8195 snd_pcm_chmap_t *map;
8197 map = malloc((src->channels + 1) * sizeof(int));
8200 memcpy(map, src, (src->channels + 1) * sizeof(int));
8204 /* make a copy of channel maps */
8205 snd_pcm_chmap_query_t **
8206 _snd_pcm_copy_chmap_query(snd_pcm_chmap_query_t * const *src)
8208 snd_pcm_chmap_query_t * const *p;
8209 snd_pcm_chmap_query_t **maps;
8212 for (nums = 0, p = src; *p; p++)
8215 maps = calloc(nums + 1, sizeof(*maps));
8218 for (i = 0; i < nums; i++) {
8219 maps[i] = malloc((src[i]->map.channels + 2) * sizeof(int));
8221 snd_pcm_free_chmaps(maps);
8224 memcpy(maps[i], src[i], (src[i]->map.channels + 2) * sizeof(int));
8229 /* select the channel map with the current PCM channels and make a copy */
8231 _snd_pcm_choose_fixed_chmap(snd_pcm_t *pcm, snd_pcm_chmap_query_t * const *maps)
8233 snd_pcm_chmap_query_t * const *p;
8235 for (p = maps; *p; p++) {
8236 if ((*p)->map.channels == pcm->channels)
8237 return _snd_pcm_copy_chmap(&(*p)->map);
8242 /* make chmap_query array from the config tree;
8243 * conf must be a compound (array)
8245 snd_pcm_chmap_query_t **
8246 _snd_pcm_parse_config_chmaps(snd_config_t *conf)
8248 snd_pcm_chmap_t *chmap;
8249 snd_pcm_chmap_query_t **maps;
8250 snd_config_iterator_t i, next;
8254 if (snd_config_get_type(conf) != SND_CONFIG_TYPE_COMPOUND)
8258 snd_config_for_each(i, next, conf) {
8262 maps = calloc(nums + 1, sizeof(*maps));
8267 snd_config_for_each(i, next, conf) {
8268 snd_config_t *n = snd_config_iterator_entry(i);
8269 err = snd_config_get_string(n, &str);
8272 chmap = snd_pcm_chmap_parse_string(str);
8275 if (_copy_to_fixed_query_map(maps + nums, chmap)) {
8284 snd_pcm_free_chmaps(maps);
8287 #endif /* DOC_HIDDEN */
8295 * \brief Recover the stream state from an error or suspend
8296 * \param pcm PCM handle
8297 * \param err error number
8298 * \param silent do not print error reason
8299 * \return 0 when error code was handled successfuly, otherwise a negative error code
8301 * This a high-level helper function building on other functions.
8303 * This functions handles -EINTR (interrupted system call),
8304 * -EPIPE (overrun or underrun) and -ESTRPIPE (stream is suspended)
8305 * error codes trying to prepare given stream for next I/O.
8307 * Note that this function returs the original error code when it is not
8308 * handled inside this function (for example -EAGAIN is returned back).
8310 int snd_pcm_recover(snd_pcm_t *pcm, int err, int silent)
8314 if (err == -EINTR) /* nothing to do, continue */
8316 if (err == -EPIPE) {
8318 if (snd_pcm_stream(pcm) == SND_PCM_STREAM_PLAYBACK)
8323 SNDERR("%s occurred", s);
8324 err = snd_pcm_prepare(pcm);
8326 SNDERR("cannot recovery from %s, prepare failed: %s", s, snd_strerror(err));
8331 if (err == -ESTRPIPE) {
8332 while ((err = snd_pcm_resume(pcm)) == -EAGAIN)
8333 /* wait until suspend flag is released */
8334 poll(NULL, 0, 1000);
8336 err = snd_pcm_prepare(pcm);
8338 SNDERR("cannot recovery from suspend, prepare failed: %s", snd_strerror(err));
8348 * \brief Set the hardware and software parameters in a simple way
8349 * \param pcm PCM handle
8350 * \param format required PCM format
8351 * \param access required PCM access
8352 * \param channels required PCM channels
8353 * \param rate required sample rate in Hz
8354 * \param soft_resample 0 = disallow alsa-lib resample stream, 1 = allow resampling
8355 * \param latency required overall latency in us
8356 * \return 0 on success otherwise a negative error code
8358 int snd_pcm_set_params(snd_pcm_t *pcm,
8359 snd_pcm_format_t format,
8360 snd_pcm_access_t access,
8361 unsigned int channels,
8364 unsigned int latency)
8366 snd_pcm_hw_params_t params_saved, params = {0};
8367 snd_pcm_sw_params_t swparams = {0};
8368 const char *s = snd_pcm_stream_name(snd_pcm_stream(pcm));
8369 snd_pcm_uframes_t buffer_size, period_size;
8370 unsigned int rrate, period_time;
8374 /* choose all parameters */
8375 err = snd_pcm_hw_params_any(pcm, ¶ms);
8377 SNDERR("Broken configuration for %s: no configurations available",
8381 /* set software resampling */
8382 err = snd_pcm_hw_params_set_rate_resample(pcm, ¶ms, soft_resample);
8384 SNDERR("Resampling setup failed for %s: %s",
8385 s, snd_strerror(err));
8388 /* set the selected read/write format */
8389 err = snd_pcm_hw_params_set_access(pcm, ¶ms, access);
8391 SNDERR("Access type not available for %s: %s",
8392 s, snd_strerror(err));
8395 /* set the sample format */
8396 err = snd_pcm_hw_params_set_format(pcm, ¶ms, format);
8398 SNDERR("Sample format not available for %s: %s",
8399 s, snd_strerror(err));
8402 /* set the count of channels */
8403 err = snd_pcm_hw_params_set_channels(pcm, ¶ms, channels);
8405 SNDERR("Channels count (%i) not available for %s: %s",
8406 channels, s, snd_strerror(err));
8409 /* set the stream rate */
8411 err = INTERNAL(snd_pcm_hw_params_set_rate_near)(pcm, ¶ms, &rrate,
8414 SNDERR("Rate %iHz not available for playback: %s",
8415 rate, snd_strerror(err));
8418 if (rrate != rate) {
8419 SNDERR("Rate doesn't match (requested %iHz, get %iHz)",
8423 /* set the buffer time */
8424 params_saved = params;
8425 err = INTERNAL(snd_pcm_hw_params_set_buffer_time_near)(pcm, ¶ms,
8428 /* error path -> set period size as first */
8429 params = params_saved;
8430 /* set the period time */
8431 period_time = latency / 4;
8432 err = INTERNAL(snd_pcm_hw_params_set_period_time_near)(pcm,
8433 ¶ms, &period_time, NULL);
8435 SNDERR("Unable to set period time %i for %s: %s",
8436 period_time, s, snd_strerror(err));
8439 err = INTERNAL(snd_pcm_hw_params_get_period_size)(¶ms,
8440 &period_size, NULL);
8442 SNDERR("Unable to get period size for %s: %s",
8443 s, snd_strerror(err));
8446 buffer_size = period_size * 4;
8447 err = INTERNAL(snd_pcm_hw_params_set_buffer_size_near)(pcm,
8448 ¶ms, &buffer_size);
8450 SNDERR("Unable to set buffer size %lu %s: %s",
8451 buffer_size, s, snd_strerror(err));
8454 err = INTERNAL(snd_pcm_hw_params_get_buffer_size)(¶ms,
8457 SNDERR("Unable to get buffer size for %s: %s",
8458 s, snd_strerror(err));
8462 /* standard configuration buffer_time -> periods */
8463 err = INTERNAL(snd_pcm_hw_params_get_buffer_size)(¶ms,
8466 SNDERR("Unable to get buffer size for %s: %s",
8467 s, snd_strerror(err));
8470 err = INTERNAL(snd_pcm_hw_params_get_buffer_time)(¶ms,
8473 SNDERR("Unable to get buffer time (latency) for %s: %s",
8474 s, snd_strerror(err));
8477 /* set the period time */
8478 period_time = latency / 4;
8479 err = INTERNAL(snd_pcm_hw_params_set_period_time_near)(pcm,
8480 ¶ms, &period_time, NULL);
8482 SNDERR("Unable to set period time %i for %s: %s",
8483 period_time, s, snd_strerror(err));
8486 err = INTERNAL(snd_pcm_hw_params_get_period_size)(¶ms,
8487 &period_size, NULL);
8489 SNDERR("Unable to get period size for %s: %s",
8490 s, snd_strerror(err));
8494 /* write the parameters to device */
8495 err = snd_pcm_hw_params(pcm, ¶ms);
8497 SNDERR("Unable to set hw params for %s: %s",
8498 s, snd_strerror(err));
8502 /* get the current swparams */
8503 err = snd_pcm_sw_params_current(pcm, &swparams);
8505 SNDERR("Unable to determine current swparams for %s: %s",
8506 s, snd_strerror(err));
8510 * start the transfer when the buffer is almost full:
8511 * (buffer_size / avail_min) * avail_min
8513 err = snd_pcm_sw_params_set_start_threshold(pcm, &swparams,
8514 (buffer_size / period_size) * period_size);
8516 SNDERR("Unable to set start threshold mode for %s: %s",
8517 s, snd_strerror(err));
8521 * allow the transfer when at least period_size samples can be
8524 err = snd_pcm_sw_params_set_avail_min(pcm, &swparams, period_size);
8526 SNDERR("Unable to set avail min for %s: %s",
8527 s, snd_strerror(err));
8530 /* write the parameters to the playback device */
8531 err = snd_pcm_sw_params(pcm, &swparams);
8533 SNDERR("Unable to set sw params for %s: %s",
8534 s, snd_strerror(err));
8541 * \brief Get the transfer size parameters in a simple way
8542 * \param pcm PCM handle
8543 * \param buffer_size PCM ring buffer size in frames
8544 * \param period_size PCM period size in frames
8545 * \return 0 on success otherwise a negative error code
8547 int snd_pcm_get_params(snd_pcm_t *pcm,
8548 snd_pcm_uframes_t *buffer_size,
8549 snd_pcm_uframes_t *period_size)
8551 snd_pcm_hw_params_t params = {0};
8555 err = snd_pcm_hw_params_current(pcm, ¶ms);
8558 err = INTERNAL(snd_pcm_hw_params_get_buffer_size)(¶ms, buffer_size);
8561 return INTERNAL(snd_pcm_hw_params_get_period_size)(¶ms, period_size,