5 * \author Jaroslav Kysela <perex@perex.cz>
6 * \author Abramo Bagnara <abramo@alsa-project.org>
9 * PCM Interface is designed to write or read digital audio frames. A
10 * frame is the data unit converted into/from sound in one time unit
11 * (1/rate seconds), by example if you set your playback PCM rate to
12 * 44100 you'll hear 44100 frames per second. The size in bytes of a
13 * frame may be obtained from bits needed to store a sample and
16 * See the \ref pcm page for more details.
19 * PCM Interface - main file
20 * Copyright (c) 1998 by Jaroslav Kysela <perex@perex.cz>
21 * Copyright (c) 2000 by Abramo Bagnara <abramo@alsa-project.org>
23 * This library is free software; you can redistribute it and/or modify
24 * it under the terms of the GNU Lesser General Public License as
25 * published by the Free Software Foundation; either version 2.1 of
26 * the License, or (at your option) any later version.
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU Lesser General Public License for more details.
33 * You should have received a copy of the GNU Lesser General Public
34 * License along with this library; if not, write to the Free Software
35 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
39 /*! \page pcm PCM (digital audio) interface
41 <P>Although abbreviation PCM stands for Pulse Code Modulation, we are
42 understanding it as general digital audio processing with volume samples
43 generated in continuous time periods.</P>
45 <P>The analog signal is recorded via analog to digital converters (ADC).
46 The digital value (de-facto a volume at a specific time) obtained
47 from ADC can be further processed. The following picture shows a perfect
53 <P>Next image shows digitized representation:</P>
58 <P>As you may see, the quality of digital audio signal depends on the time
59 (recording rate) and voltage resolution (usually in an linear integer
60 representation with basic unit one bit).</P>
62 <P>The stored digital signal can be converted back to voltage (analog)
63 representation via digital to analog converters (DAC).</P>
65 <P>One digital value is called sample. More samples are collected to frames
66 (frame is terminology for ALSA) depending on count of converters used at one
67 specific time. One frame might contain one sample (when only one converter is
68 used - mono) or more samples (for example: stereo has signals from two converters
69 recorded at same time). Digital audio stream contains collection of frames
70 recorded at boundaries of continuous time periods.</P>
72 \section pcm_general_overview General overview
74 ALSA uses the ring buffer to store outgoing (playback) and incoming (capture,
75 record) samples. There are two pointers being maintained to allow
76 a precise communication between application and device pointing to current
77 processed sample by hardware and last processed sample by application.
78 The modern audio chips allow to program the transfer time periods.
79 It means that the stream of samples is divided to small chunks. Device
80 acknowledges to application when the transfer of a chunk is complete.
82 \section pcm_transfer Transfer methods in UNIX environments
84 In the UNIX environment, data chunk acknowledges are received via standard I/O
85 calls or event waiting routines (poll or select function). To accomplish
86 this list, the asynchronous notification of acknowledges should be listed
87 here. The ALSA implementation for these methods is described in
88 the \ref alsa_transfers section.
90 \subsection pcm_transfer_io Standard I/O transfers
92 The standard I/O transfers are using the read (see 'man 2 read') and write
93 (see 'man 2 write') C functions. There are two basic behaviours of these
94 functions - blocked and non-blocked (see the O_NONBLOCK flag for the
95 standard C open function - see 'man 2 open'). In non-blocked behaviour,
96 these I/O functions never stops, they return -EAGAIN error code, when no
97 data can be transferred (the ring buffer is full in our case). In blocked
98 behaviour, these I/O functions stop and wait until there is a room in the
99 ring buffer (playback) or until there are 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
655 #include <sys/mman.h>
657 #include "pcm_local.h"
660 /* return specific error codes for known bad PCM states */
661 static int pcm_state_to_error(snd_pcm_state_t state)
664 case SND_PCM_STATE_XRUN:
666 case SND_PCM_STATE_SUSPENDED:
668 case SND_PCM_STATE_DISCONNECTED:
675 #define P_STATE(x) (1U << SND_PCM_STATE_ ## x)
676 #define P_STATE_RUNNABLE (P_STATE(PREPARED) | \
682 /* check whether the PCM is in the unexpected state */
683 static int bad_pcm_state(snd_pcm_t *pcm, unsigned int supported_states)
685 snd_pcm_state_t state;
688 if (pcm->own_state_check)
689 return 0; /* don't care, the plugin checks by itself */
690 state = snd_pcm_state(pcm);
691 if (supported_states & (1U << state))
693 err = pcm_state_to_error(state);
701 * \brief get identifier of PCM handle
702 * \param pcm PCM handle
703 * \return ascii identifier of PCM handle
705 * Returns the ASCII identifier of given PCM handle. It's the same
706 * identifier specified in snd_pcm_open().
708 const char *snd_pcm_name(snd_pcm_t *pcm)
715 * \brief get type of PCM handle
716 * \param pcm PCM handle
717 * \return type of PCM handle
719 * Returns the type #snd_pcm_type_t of given PCM handle.
721 snd_pcm_type_t snd_pcm_type(snd_pcm_t *pcm)
728 * \brief get stream for a PCM handle
729 * \param pcm PCM handle
730 * \return stream of PCM handle
732 * Returns the type #snd_pcm_stream_t of given PCM handle.
734 snd_pcm_stream_t snd_pcm_stream(snd_pcm_t *pcm)
741 * \brief close PCM handle
742 * \param pcm PCM handle
743 * \return 0 on success otherwise a negative error code
745 * Closes the specified PCM handle and frees all associated
748 int snd_pcm_close(snd_pcm_t *pcm)
752 if (pcm->setup && !pcm->donot_close) {
754 err = snd_pcm_hw_free(pcm);
758 if (pcm->mmap_channels)
760 while (!list_empty(&pcm->async_handlers)) {
761 snd_async_handler_t *h = list_entry(pcm->async_handlers.next, snd_async_handler_t, hlist);
762 snd_async_del_handler(h);
764 err = pcm->ops->close(pcm->op_arg);
767 err = snd_pcm_free(pcm);
774 * \brief set nonblock mode
775 * \param pcm PCM handle
776 * \param nonblock 0 = block, 1 = nonblock mode, 2 = abort
777 * \return 0 on success otherwise a negative error code
779 * The function is thread-safe when built with the proper option.
781 int snd_pcm_nonblock(snd_pcm_t *pcm, int nonblock)
786 /* FIXME: __snd_pcm_lock() call below is commented out because of the
787 * the possible deadlock in signal handler calling snd_pcm_abort()
789 /* __snd_pcm_lock(pcm); */ /* forced lock due to pcm field change */
790 if ((err = pcm->ops->nonblock(pcm->op_arg, nonblock)) < 0)
793 pcm->mode |= SND_PCM_ABORT;
797 pcm->mode |= SND_PCM_NONBLOCK;
799 if (pcm->hw_flags & SND_PCM_HW_PARAMS_NO_PERIOD_WAKEUP)
802 pcm->mode &= ~SND_PCM_NONBLOCK;
805 /* __snd_pcm_unlock(pcm); */ /* FIXME: see above */
811 * \brief set async mode
812 * \param pcm PCM handle
813 * \param sig Signal to raise: < 0 disable, 0 default (SIGIO)
814 * \param pid Process ID to signal: 0 current
815 * \return 0 on success otherwise a negative error code
817 * A signal is raised every period.
819 int snd_pcm_async(snd_pcm_t *pcm, int sig, pid_t pid)
827 #ifdef THREAD_SAFE_API
828 /* async handler may lead to a deadlock; suppose no multi thread */
829 pcm->lock_enabled = 0;
831 return pcm->ops->async(pcm->op_arg, sig, pid);
836 * \brief Obtain general (static) information for PCM handle
837 * \param pcm PCM handle
838 * \param info Information container
839 * \return 0 on success otherwise a negative error code
841 int snd_pcm_info(snd_pcm_t *pcm, snd_pcm_info_t *info)
844 return pcm->ops->info(pcm->op_arg, info);
847 /** \brief Retreive current PCM hardware configuration chosen with #snd_pcm_hw_params
848 * \param pcm PCM handle
849 * \param params Configuration space definition container
850 * \return 0 on success otherwise a negative error code
852 int snd_pcm_hw_params_current(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
854 unsigned int frame_bits;
856 assert(pcm && params);
859 memset(params, 0, snd_pcm_hw_params_sizeof());
860 params->flags = pcm->hw_flags;
861 snd_mask_set(¶ms->masks[SND_PCM_HW_PARAM_ACCESS - SND_PCM_HW_PARAM_FIRST_MASK], pcm->access);
862 snd_mask_set(¶ms->masks[SND_PCM_HW_PARAM_FORMAT - SND_PCM_HW_PARAM_FIRST_MASK], pcm->format);
863 snd_mask_set(¶ms->masks[SND_PCM_HW_PARAM_SUBFORMAT - SND_PCM_HW_PARAM_FIRST_MASK], pcm->subformat);
864 frame_bits = snd_pcm_format_physical_width(pcm->format) * pcm->channels;
865 snd_interval_set_value(¶ms->intervals[SND_PCM_HW_PARAM_FRAME_BITS - SND_PCM_HW_PARAM_FIRST_INTERVAL], frame_bits);
866 snd_interval_set_value(¶ms->intervals[SND_PCM_HW_PARAM_CHANNELS - SND_PCM_HW_PARAM_FIRST_INTERVAL], pcm->channels);
867 snd_interval_set_value(¶ms->intervals[SND_PCM_HW_PARAM_RATE - SND_PCM_HW_PARAM_FIRST_INTERVAL], pcm->rate);
868 snd_interval_set_value(¶ms->intervals[SND_PCM_HW_PARAM_PERIOD_TIME - SND_PCM_HW_PARAM_FIRST_INTERVAL], pcm->period_time);
869 snd_interval_set_value(¶ms->intervals[SND_PCM_HW_PARAM_PERIOD_SIZE - SND_PCM_HW_PARAM_FIRST_INTERVAL], pcm->period_size);
870 snd_interval_copy(¶ms->intervals[SND_PCM_HW_PARAM_PERIODS - SND_PCM_HW_PARAM_FIRST_INTERVAL], &pcm->periods);
871 snd_interval_copy(¶ms->intervals[SND_PCM_HW_PARAM_BUFFER_TIME - SND_PCM_HW_PARAM_FIRST_INTERVAL], &pcm->buffer_time);
872 snd_interval_set_value(¶ms->intervals[SND_PCM_HW_PARAM_BUFFER_SIZE - SND_PCM_HW_PARAM_FIRST_INTERVAL], pcm->buffer_size);
873 snd_interval_set_value(¶ms->intervals[SND_PCM_HW_PARAM_BUFFER_BYTES - SND_PCM_HW_PARAM_FIRST_INTERVAL], (pcm->buffer_size * frame_bits) / 8);
874 params->info = pcm->info;
875 params->msbits = pcm->msbits;
876 params->rate_num = pcm->rate_num;
877 params->rate_den = pcm->rate_den;
878 params->fifo_size = pcm->fifo_size;
882 /** \brief Install one PCM hardware configuration chosen from a configuration space and #snd_pcm_prepare it
883 * \param pcm PCM handle
884 * \param params Configuration space definition container
885 * \return 0 on success otherwise a negative error code
887 * The configuration is chosen fixing single parameters in this order:
888 * first access, first format, first subformat, min channels, min rate,
889 * min period time, max buffer size, min tick time. If no mutually
890 * compatible set of parameters can be chosen, a negative error code
893 * After this call, #snd_pcm_prepare() is called automatically and
894 * the stream is brought to \c #SND_PCM_STATE_PREPARED state.
896 * The hardware parameters cannot be changed when the stream is
897 * running (active). The software parameters can be changed
900 * The configuration space will be updated to reflect the chosen
903 int snd_pcm_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
906 assert(pcm && params);
907 err = _snd_pcm_hw_params_internal(pcm, params);
910 err = snd_pcm_prepare(pcm);
914 /** \brief Remove PCM hardware configuration and free associated resources
915 * \param pcm PCM handle
916 * \return 0 on success otherwise a negative error code
918 int snd_pcm_hw_free(snd_pcm_t *pcm)
923 if (pcm->mmap_channels) {
924 err = snd_pcm_munmap(pcm);
928 // assert(snd_pcm_state(pcm) == SND_PCM_STATE_SETUP ||
929 // snd_pcm_state(pcm) == SND_PCM_STATE_PREPARED);
930 err = pcm->ops->hw_free(pcm->op_arg);
937 /** \brief Install PCM software configuration defined by params
938 * \param pcm PCM handle
939 * \param params Configuration container
940 * \return 0 on success otherwise a negative error code
942 * The software parameters can be changed at any time.
943 * The hardware parameters cannot be changed when the stream is
946 * The function is thread-safe when built with the proper option.
948 int snd_pcm_sw_params(snd_pcm_t *pcm, snd_pcm_sw_params_t *params)
951 /* the hw_params must be set at first!!! */
952 if (CHECK_SANITY(! pcm->setup)) {
953 SNDMSG("PCM not set up");
956 if (! params->avail_min) {
957 SNDMSG("params->avail_min is 0");
961 /* disable the check below - it looks too restrictive
962 * (start_threshold is basically independent from avail_min)
964 if (params->start_threshold <= pcm->buffer_size &&
965 params->start_threshold > (pcm->buffer_size / params->avail_min) * params->avail_min) {
966 SNDMSG("params->avail_min problem for start_threshold");
970 __snd_pcm_lock(pcm); /* forced lock due to pcm field change */
971 err = pcm->ops->sw_params(pcm->op_arg, params);
973 __snd_pcm_unlock(pcm);
976 pcm->tstamp_mode = params->tstamp_mode;
977 pcm->tstamp_type = params->tstamp_type;
978 pcm->period_step = params->period_step;
979 pcm->avail_min = params->avail_min;
980 pcm->period_event = sw_get_period_event(params);
981 pcm->start_threshold = params->start_threshold;
982 pcm->stop_threshold = params->stop_threshold;
983 pcm->silence_threshold = params->silence_threshold;
984 pcm->silence_size = params->silence_size;
985 pcm->boundary = params->boundary;
986 __snd_pcm_unlock(pcm);
991 * \brief Obtain status (runtime) information for PCM handle
992 * \param pcm PCM handle
993 * \param status Status container
994 * \return 0 on success otherwise a negative error code
996 * The function is thread-safe when built with the proper option.
998 int snd_pcm_status(snd_pcm_t *pcm, snd_pcm_status_t *status)
1002 assert(pcm && status);
1004 err = pcm->fast_ops->status(pcm->fast_op_arg, status);
1005 snd_pcm_unlock(pcm);
1011 * \brief Return PCM state
1012 * \param pcm PCM handle
1013 * \return PCM state #snd_pcm_state_t of given PCM handle
1015 * This is a faster way to obtain only the PCM state without calling
1016 * \link ::snd_pcm_status() \endlink.
1018 * The function is thread-safe when built with the proper option.
1020 snd_pcm_state_t snd_pcm_state(snd_pcm_t *pcm)
1022 snd_pcm_state_t state;
1026 state = __snd_pcm_state(pcm);
1027 snd_pcm_unlock(pcm);
1032 * \brief (DEPRECATED) Synchronize stream position with hardware
1033 * \param pcm PCM handle
1034 * \return 0 on success otherwise a negative error code
1036 * Note this function does not update the actual r/w pointer
1037 * for applications. The function #snd_pcm_avail_update()
1038 * have to be called before any mmap begin+commit operation.
1040 * The function is thread-safe when built with the proper option.
1042 * This function is deprecated. Use #snd_pcm_avail_update() instead.
1044 int snd_pcm_hwsync(snd_pcm_t *pcm)
1049 if (CHECK_SANITY(! pcm->setup)) {
1050 SNDMSG("PCM not set up");
1054 err = __snd_pcm_hwsync(pcm);
1055 snd_pcm_unlock(pcm);
1060 * \brief Obtain delay for a running PCM handle
1061 * \param pcm PCM handle
1062 * \param delayp Returned delay in frames
1063 * \return 0 on success otherwise a negative error code
1065 * For playback the delay is defined as the time that a frame that is written
1066 * to the PCM stream shortly after this call will take to be actually
1067 * audible. It is as such the overall latency from the write call to the final
1070 * For capture the delay is defined as the time that a frame that was
1071 * digitized by the audio device takes until it can be read from the PCM
1072 * stream shortly after this call returns. It is as such the overall latency
1073 * from the initial ADC to the read call.
1075 * Please note that hence in case of a playback underrun this value will not
1076 * necessarily got down to 0.
1078 * If the application is interested in the fill level of the playback buffer
1079 * of the device, it should use #snd_pcm_avail*() functions. The
1080 * value returned by that call is not directly related to the delay, since the
1081 * latter might include some additional, fixed latencies the former does not.
1083 * Note this function does not update the actual r/w pointer
1084 * for applications. The function #snd_pcm_avail_update()
1085 * have to be called before any begin+commit operation.
1087 * The function is thread-safe when built with the proper option.
1089 int snd_pcm_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp)
1094 if (CHECK_SANITY(! pcm->setup)) {
1095 SNDMSG("PCM not set up");
1099 err = __snd_pcm_delay(pcm, delayp);
1100 snd_pcm_unlock(pcm);
1105 * \brief Resume from suspend, no samples are lost
1106 * \param pcm PCM handle
1107 * \return 0 on success otherwise a negative error code
1108 * \retval -EAGAIN resume can't be proceed immediately (audio hardware is probably still suspended)
1109 * \retval -ENOSYS hardware doesn't support this feature
1111 * This function can be used when the stream is in the suspend state
1112 * to do the fine resume from this state. Not all hardware supports
1113 * this feature, when an -ENOSYS error is returned, use the \link ::snd_pcm_prepare() \endlink
1114 * function to recovery.
1116 * The function is thread-safe when built with the proper option.
1118 int snd_pcm_resume(snd_pcm_t *pcm)
1121 if (CHECK_SANITY(! pcm->setup)) {
1122 SNDMSG("PCM not set up");
1125 /* lock handled in the callback */
1126 return pcm->fast_ops->resume(pcm->fast_op_arg);
1130 * \brief Obtain last position update hi-res timestamp
1131 * \param pcm PCM handle
1132 * \param avail Number of available frames when timestamp was grabbed
1133 * \param tstamp Hi-res timestamp
1134 * \return 0 on success otherwise a negative error code
1136 * Note this function does not update the actual r/w pointer
1139 * The function is thread-safe when built with the proper option.
1141 int snd_pcm_htimestamp(snd_pcm_t *pcm, snd_pcm_uframes_t *avail, snd_htimestamp_t *tstamp)
1146 if (CHECK_SANITY(! pcm->setup)) {
1147 SNDMSG("PCM not set up");
1151 err = pcm->fast_ops->htimestamp(pcm->fast_op_arg, avail, tstamp);
1152 snd_pcm_unlock(pcm);
1157 * \brief Prepare PCM for use
1158 * \param pcm PCM handle
1159 * \return 0 on success otherwise a negative error code
1161 * The function is thread-safe when built with the proper option.
1163 int snd_pcm_prepare(snd_pcm_t *pcm)
1168 if (CHECK_SANITY(! pcm->setup)) {
1169 SNDMSG("PCM not set up");
1172 err = bad_pcm_state(pcm, ~P_STATE(DISCONNECTED));
1176 err = pcm->fast_ops->prepare(pcm->fast_op_arg);
1177 snd_pcm_unlock(pcm);
1182 * \brief Reset PCM position
1183 * \param pcm PCM handle
1184 * \return 0 on success otherwise a negative error code
1186 * Reduce PCM delay to 0.
1188 * The function is thread-safe when built with the proper option.
1190 int snd_pcm_reset(snd_pcm_t *pcm)
1195 if (CHECK_SANITY(! pcm->setup)) {
1196 SNDMSG("PCM not set up");
1200 err = pcm->fast_ops->reset(pcm->fast_op_arg);
1201 snd_pcm_unlock(pcm);
1206 * \brief Start a PCM
1207 * \param pcm PCM handle
1208 * \return 0 on success otherwise a negative error code
1210 * The function is thread-safe when built with the proper option.
1212 int snd_pcm_start(snd_pcm_t *pcm)
1217 if (CHECK_SANITY(! pcm->setup)) {
1218 SNDMSG("PCM not set up");
1221 err = bad_pcm_state(pcm, P_STATE(PREPARED));
1225 err = __snd_pcm_start(pcm);
1226 snd_pcm_unlock(pcm);
1231 * \brief Stop a PCM dropping pending frames
1232 * \param pcm PCM handle
1233 * \return 0 on success otherwise a negative error code
1235 * This function stops the PCM <i>immediately</i>.
1236 * The pending samples on the buffer are ignored.
1238 * For processing all pending samples, use \link ::snd_pcm_drain() \endlink
1241 * The function is thread-safe when built with the proper option.
1243 int snd_pcm_drop(snd_pcm_t *pcm)
1248 if (CHECK_SANITY(! pcm->setup)) {
1249 SNDMSG("PCM not set up");
1252 err = bad_pcm_state(pcm, P_STATE_RUNNABLE | P_STATE(SETUP) |
1253 P_STATE(SUSPENDED));
1257 err = pcm->fast_ops->drop(pcm->fast_op_arg);
1258 snd_pcm_unlock(pcm);
1263 * \brief Stop a PCM preserving pending frames
1264 * \param pcm PCM handle
1265 * \return 0 on success otherwise a negative error code
1266 * \retval -ESTRPIPE a suspend event occurred
1268 * For playback wait for all pending frames to be played and then stop
1270 * For capture stop PCM permitting to retrieve residual frames.
1272 * For stopping the PCM stream immediately, use \link ::snd_pcm_drop() \endlink
1275 * The function is thread-safe when built with the proper option.
1277 int snd_pcm_drain(snd_pcm_t *pcm)
1282 if (CHECK_SANITY(! pcm->setup)) {
1283 SNDMSG("PCM not set up");
1286 err = bad_pcm_state(pcm, P_STATE_RUNNABLE);
1289 /* lock handled in the callback */
1290 return pcm->fast_ops->drain(pcm->fast_op_arg);
1294 * \brief Pause/resume PCM
1295 * \param pcm PCM handle
1296 * \param enable 0 = resume, 1 = pause
1297 * \return 0 on success otherwise a negative error code
1299 * Note that this function works only on the hardware which supports
1300 * pause feature. You can check it via \link ::snd_pcm_hw_params_can_pause() \endlink
1303 * The function is thread-safe when built with the proper option.
1305 int snd_pcm_pause(snd_pcm_t *pcm, int enable)
1310 if (CHECK_SANITY(! pcm->setup)) {
1311 SNDMSG("PCM not set up");
1314 err = bad_pcm_state(pcm, P_STATE_RUNNABLE);
1318 err = pcm->fast_ops->pause(pcm->fast_op_arg, enable);
1319 snd_pcm_unlock(pcm);
1324 * \brief Get safe count of frames which can be rewinded
1325 * \param pcm PCM handle
1326 * \return a positive number of frames or negative error code
1328 * Note: The snd_pcm_rewind() can accept bigger value than returned
1329 * by this function. But it is not guaranteed that output stream
1330 * will be consistent with bigger value.
1332 * The function is thread-safe when built with the proper option.
1334 snd_pcm_sframes_t snd_pcm_rewindable(snd_pcm_t *pcm)
1336 snd_pcm_sframes_t result;
1340 if (CHECK_SANITY(! pcm->setup)) {
1341 SNDMSG("PCM not set up");
1344 err = bad_pcm_state(pcm, P_STATE_RUNNABLE);
1348 result = pcm->fast_ops->rewindable(pcm->fast_op_arg);
1349 snd_pcm_unlock(pcm);
1354 * \brief Move application frame position backward
1355 * \param pcm PCM handle
1356 * \param frames wanted displacement in frames
1357 * \return a positive number for actual displacement otherwise a
1358 * negative error code
1360 * The function is thread-safe when built with the proper option.
1362 snd_pcm_sframes_t snd_pcm_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
1364 snd_pcm_sframes_t result;
1368 if (CHECK_SANITY(! pcm->setup)) {
1369 SNDMSG("PCM not set up");
1374 err = bad_pcm_state(pcm, P_STATE_RUNNABLE);
1378 result = pcm->fast_ops->rewind(pcm->fast_op_arg, frames);
1379 snd_pcm_unlock(pcm);
1384 * \brief Get safe count of frames which can be forwarded
1385 * \param pcm PCM handle
1386 * \return a positive number of frames or negative error code
1388 * Note: The snd_pcm_forward() can accept bigger value than returned
1389 * by this function. But it is not guaranteed that output stream
1390 * will be consistent with bigger value.
1392 * The function is thread-safe when built with the proper option.
1394 snd_pcm_sframes_t snd_pcm_forwardable(snd_pcm_t *pcm)
1396 snd_pcm_sframes_t result;
1400 if (CHECK_SANITY(! pcm->setup)) {
1401 SNDMSG("PCM not set up");
1404 err = bad_pcm_state(pcm, P_STATE_RUNNABLE);
1408 result = pcm->fast_ops->forwardable(pcm->fast_op_arg);
1409 snd_pcm_unlock(pcm);
1414 * \brief Move application frame position forward
1415 * \param pcm PCM handle
1416 * \param frames wanted skip in frames
1417 * \return a positive number for actual skip otherwise a negative error code
1418 * \retval 0 means no action
1420 * The function is thread-safe when built with the proper option.
1423 EXPORT_SYMBOL snd_pcm_sframes_t INTERNAL(snd_pcm_forward)(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
1425 snd_pcm_sframes_t snd_pcm_forward(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
1428 snd_pcm_sframes_t result;
1432 if (CHECK_SANITY(! pcm->setup)) {
1433 SNDMSG("PCM not set up");
1438 err = bad_pcm_state(pcm, P_STATE_RUNNABLE);
1442 result = pcm->fast_ops->forward(pcm->fast_op_arg, frames);
1443 snd_pcm_unlock(pcm);
1446 use_default_symbol_version(__snd_pcm_forward, snd_pcm_forward, ALSA_0.9.0rc8);
1449 * \brief Write interleaved frames to a PCM
1450 * \param pcm PCM handle
1451 * \param buffer frames containing buffer
1452 * \param size frames to be written
1453 * \return a positive number of frames actually written otherwise a
1454 * negative error code
1455 * \retval -EBADFD PCM is not in the right state (#SND_PCM_STATE_PREPARED or #SND_PCM_STATE_RUNNING)
1456 * \retval -EPIPE an underrun occurred
1457 * \retval -ESTRPIPE a suspend event occurred (stream is suspended and waiting for an application recovery)
1459 * If the blocking behaviour is selected and it is running, then routine waits until
1460 * all requested frames are played or put to the playback ring buffer.
1461 * The returned number of frames can be less only if a signal or underrun occurred.
1463 * If the non-blocking behaviour is selected, then routine doesn't wait at all.
1465 * The function is thread-safe when built with the proper option.
1467 snd_pcm_sframes_t snd_pcm_writei(snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size)
1472 assert(size == 0 || buffer);
1473 if (CHECK_SANITY(! pcm->setup)) {
1474 SNDMSG("PCM not set up");
1477 if (pcm->access != SND_PCM_ACCESS_RW_INTERLEAVED) {
1478 SNDMSG("invalid access type %s", snd_pcm_access_name(pcm->access));
1481 err = bad_pcm_state(pcm, P_STATE_RUNNABLE);
1484 return _snd_pcm_writei(pcm, buffer, size);
1488 * \brief Write non interleaved frames to a PCM
1489 * \param pcm PCM handle
1490 * \param bufs frames containing buffers (one for each channel)
1491 * \param size frames to be written
1492 * \return a positive number of frames actually written otherwise a
1493 * negative error code
1494 * \retval -EBADFD PCM is not in the right state (#SND_PCM_STATE_PREPARED or #SND_PCM_STATE_RUNNING)
1495 * \retval -EPIPE an underrun occurred
1496 * \retval -ESTRPIPE a suspend event occurred (stream is suspended and waiting for an application recovery)
1498 * If the blocking behaviour is selected and it is running, then routine waits until
1499 * all requested frames are played or put to the playback ring buffer.
1500 * The returned number of frames can be less only if a signal or underrun occurred.
1502 * If the non-blocking behaviour is selected, then routine doesn't wait at all.
1504 * The function is thread-safe when built with the proper option.
1506 snd_pcm_sframes_t snd_pcm_writen(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size)
1511 assert(size == 0 || bufs);
1512 if (CHECK_SANITY(! pcm->setup)) {
1513 SNDMSG("PCM not set up");
1516 if (pcm->access != SND_PCM_ACCESS_RW_NONINTERLEAVED) {
1517 SNDMSG("invalid access type %s", snd_pcm_access_name(pcm->access));
1520 err = bad_pcm_state(pcm, P_STATE_RUNNABLE);
1523 return _snd_pcm_writen(pcm, bufs, size);
1527 * \brief Read interleaved frames from a PCM
1528 * \param pcm PCM handle
1529 * \param buffer frames containing buffer
1530 * \param size frames to be read
1531 * \return a positive number of frames actually read otherwise a
1532 * negative error code
1533 * \retval -EBADFD PCM is not in the right state (#SND_PCM_STATE_PREPARED or #SND_PCM_STATE_RUNNING)
1534 * \retval -EPIPE an overrun occurred
1535 * \retval -ESTRPIPE a suspend event occurred (stream is suspended and waiting for an application recovery)
1537 * If the blocking behaviour was selected and it is running, then routine waits until
1538 * all requested frames are filled. The returned number of frames can be less only
1539 * if a signal or underrun occurred.
1541 * If the non-blocking behaviour is selected, then routine doesn't wait at all.
1543 * The function is thread-safe when built with the proper option.
1545 snd_pcm_sframes_t snd_pcm_readi(snd_pcm_t *pcm, void *buffer, snd_pcm_uframes_t size)
1550 assert(size == 0 || buffer);
1551 if (CHECK_SANITY(! pcm->setup)) {
1552 SNDMSG("PCM not set up");
1555 if (pcm->access != SND_PCM_ACCESS_RW_INTERLEAVED) {
1556 SNDMSG("invalid access type %s", snd_pcm_access_name(pcm->access));
1559 err = bad_pcm_state(pcm, P_STATE_RUNNABLE);
1562 return _snd_pcm_readi(pcm, buffer, size);
1566 * \brief Read non interleaved frames to a PCM
1567 * \param pcm PCM handle
1568 * \param bufs frames containing buffers (one for each channel)
1569 * \param size frames to be read
1570 * \return a positive number of frames actually read otherwise a
1571 * negative error code
1572 * \retval -EBADFD PCM is not in the right state (#SND_PCM_STATE_PREPARED or #SND_PCM_STATE_RUNNING)
1573 * \retval -EPIPE an overrun occurred
1574 * \retval -ESTRPIPE a suspend event occurred (stream is suspended and waiting for an application recovery)
1576 * If the blocking behaviour was selected and it is running, then routine waits until
1577 * all requested frames are filled. The returned number of frames can be less only
1578 * if a signal or underrun occurred.
1580 * If the non-blocking behaviour is selected, then routine doesn't wait at all.
1582 * The function is thread-safe when built with the proper option.
1584 snd_pcm_sframes_t snd_pcm_readn(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size)
1589 assert(size == 0 || bufs);
1590 if (CHECK_SANITY(! pcm->setup)) {
1591 SNDMSG("PCM not set up");
1594 if (pcm->access != SND_PCM_ACCESS_RW_NONINTERLEAVED) {
1595 SNDMSG("invalid access type %s", snd_pcm_access_name(pcm->access));
1598 err = bad_pcm_state(pcm, P_STATE_RUNNABLE);
1601 return _snd_pcm_readn(pcm, bufs, size);
1605 * \brief Link two PCMs
1606 * \param pcm1 first PCM handle
1607 * \param pcm2 first PCM handle
1608 * \return 0 on success otherwise a negative error code
1610 * The two PCMs will start/stop/prepare in sync.
1612 int snd_pcm_link(snd_pcm_t *pcm1, snd_pcm_t *pcm2)
1616 if (pcm1->fast_ops->link)
1617 return pcm1->fast_ops->link(pcm1, pcm2);
1622 * \brief Remove a PCM from a linked group
1623 * \param pcm PCM handle
1624 * \return 0 on success otherwise a negative error code
1626 int snd_pcm_unlink(snd_pcm_t *pcm)
1629 if (pcm->fast_ops->unlink)
1630 return pcm->fast_ops->unlink(pcm);
1634 /* locked version */
1635 static int __snd_pcm_poll_descriptors_count(snd_pcm_t *pcm)
1637 if (pcm->fast_ops->poll_descriptors_count)
1638 return pcm->fast_ops->poll_descriptors_count(pcm->fast_op_arg);
1639 return pcm->poll_fd_count;
1643 * \brief get count of poll descriptors for PCM handle
1644 * \param pcm PCM handle
1645 * \return count of poll descriptors
1647 * The function is thread-safe when built with the proper option.
1649 int snd_pcm_poll_descriptors_count(snd_pcm_t *pcm)
1655 count = __snd_pcm_poll_descriptors_count(pcm);
1656 snd_pcm_unlock(pcm);
1660 /* locked version */
1661 static int __snd_pcm_poll_descriptors(snd_pcm_t *pcm, struct pollfd *pfds,
1664 if (pcm->fast_ops->poll_descriptors)
1665 return pcm->fast_ops->poll_descriptors(pcm->fast_op_arg, pfds, space);
1666 if (pcm->poll_fd < 0) {
1667 SNDMSG("poll_fd < 0");
1670 if (space >= 1 && pfds) {
1671 pfds->fd = pcm->poll_fd;
1672 pfds->events = pcm->poll_events | POLLERR | POLLNVAL;
1680 * \brief get poll descriptors
1681 * \param pcm PCM handle
1682 * \param pfds array of poll descriptors
1683 * \param space space in the poll descriptor array
1684 * \return count of filled descriptors
1686 * This function fills the given poll descriptor structs for the specified
1687 * PCM handle. The poll desctiptor array should have the size returned by
1688 * \link ::snd_pcm_poll_descriptors_count() \endlink function.
1690 * The result is intended for direct use with the poll() syscall.
1692 * For reading the returned events of poll descriptor after poll() system
1693 * call, use \link ::snd_pcm_poll_descriptors_revents() \endlink function.
1694 * The field values in pollfd structs may be bogus regarding the stream
1695 * direction from the application perspective (POLLIN might not imply read
1696 * direction and POLLOUT might not imply write), but
1697 * the \link ::snd_pcm_poll_descriptors_revents() \endlink function
1698 * does the right "demangling".
1700 * You can use output from this function as arguments for the select()
1701 * syscall, too. Do not forget to translate POLLIN and POLLOUT events to
1702 * corresponding FD_SET arrays and demangle events using
1703 * \link ::snd_pcm_poll_descriptors_revents() \endlink .
1705 * The function is thread-safe when built with the proper option.
1707 int snd_pcm_poll_descriptors(snd_pcm_t *pcm, struct pollfd *pfds, unsigned int space)
1711 assert(pcm && pfds);
1713 err = __snd_pcm_poll_descriptors(pcm, pfds, space);
1714 snd_pcm_unlock(pcm);
1718 static int __snd_pcm_poll_revents(snd_pcm_t *pcm, struct pollfd *pfds,
1719 unsigned int nfds, unsigned short *revents);
1722 * \brief get returned events from poll descriptors
1723 * \param pcm PCM handle
1724 * \param pfds array of poll descriptors
1725 * \param nfds count of poll descriptors
1726 * \param revents pointer to the returned (single) event
1727 * \return zero if success, otherwise a negative error code
1729 * This function does "demangling" of the revents mask returned from
1730 * the poll() syscall to correct semantics (POLLIN = read, POLLOUT = write).
1732 * Note: The null event also exists. Even if poll() or select()
1733 * syscall returned that some events are waiting, this function might
1734 * return empty set of events. In this case, application should
1735 * do next event waiting using poll() or select().
1737 * Note: Even if multiple poll descriptors are used (i.e. pfds > 1),
1738 * this function returns only a single event.
1740 * The function is thread-safe when built with the proper option.
1742 int snd_pcm_poll_descriptors_revents(snd_pcm_t *pcm, struct pollfd *pfds, unsigned int nfds, unsigned short *revents)
1746 assert(pcm && pfds && revents);
1748 err = __snd_pcm_poll_revents(pcm, pfds, nfds, revents);
1749 snd_pcm_unlock(pcm);
1753 static int __snd_pcm_poll_revents(snd_pcm_t *pcm, struct pollfd *pfds,
1754 unsigned int nfds, unsigned short *revents)
1756 if (pcm->fast_ops->poll_revents)
1757 return pcm->fast_ops->poll_revents(pcm->fast_op_arg, pfds, nfds, revents);
1759 *revents = pfds->revents;
1766 #define PCMTYPE(v) [SND_PCM_TYPE_##v] = #v
1767 #define STATE(v) [SND_PCM_STATE_##v] = #v
1768 #define STREAM(v) [SND_PCM_STREAM_##v] = #v
1769 #define READY(v) [SND_PCM_READY_##v] = #v
1770 #define XRUN(v) [SND_PCM_XRUN_##v] = #v
1771 #define SILENCE(v) [SND_PCM_SILENCE_##v] = #v
1772 #define TSTAMP(v) [SND_PCM_TSTAMP_##v] = #v
1773 #define TSTAMP_TYPE(v) [SND_PCM_TSTAMP_TYPE_##v] = #v
1774 #define ACCESS(v) [SND_PCM_ACCESS_##v] = #v
1775 #define START(v) [SND_PCM_START_##v] = #v
1776 #define HW_PARAM(v) [SND_PCM_HW_PARAM_##v] = #v
1777 #define SW_PARAM(v) [SND_PCM_SW_PARAM_##v] = #v
1778 #define FORMAT(v) [SND_PCM_FORMAT_##v] = #v
1779 #define SUBFORMAT(v) [SND_PCM_SUBFORMAT_##v] = #v
1781 #define FORMATD(v, d) [SND_PCM_FORMAT_##v] = d
1782 #define SUBFORMATD(v, d) [SND_PCM_SUBFORMAT_##v] = d
1785 static const char *const snd_pcm_stream_names[] = {
1790 static const char *const snd_pcm_state_names[] = {
1799 STATE(DISCONNECTED),
1802 static const char *const snd_pcm_access_names[] = {
1803 ACCESS(MMAP_INTERLEAVED),
1804 ACCESS(MMAP_NONINTERLEAVED),
1805 ACCESS(MMAP_COMPLEX),
1806 ACCESS(RW_INTERLEAVED),
1807 ACCESS(RW_NONINTERLEAVED),
1810 static const char *const snd_pcm_format_names[] = {
1829 FORMAT(IEC958_SUBFRAME_LE),
1830 FORMAT(IEC958_SUBFRAME_BE),
1864 static const char *const snd_pcm_format_aliases[SND_PCM_FORMAT_LAST+1] = {
1873 FORMAT(IEC958_SUBFRAME),
1878 static const char *const snd_pcm_format_descriptions[] = {
1879 FORMATD(S8, "Signed 8 bit"),
1880 FORMATD(U8, "Unsigned 8 bit"),
1881 FORMATD(S16_LE, "Signed 16 bit Little Endian"),
1882 FORMATD(S16_BE, "Signed 16 bit Big Endian"),
1883 FORMATD(U16_LE, "Unsigned 16 bit Little Endian"),
1884 FORMATD(U16_BE, "Unsigned 16 bit Big Endian"),
1885 FORMATD(S24_LE, "Signed 24 bit Little Endian"),
1886 FORMATD(S24_BE, "Signed 24 bit Big Endian"),
1887 FORMATD(U24_LE, "Unsigned 24 bit Little Endian"),
1888 FORMATD(U24_BE, "Unsigned 24 bit Big Endian"),
1889 FORMATD(S32_LE, "Signed 32 bit Little Endian"),
1890 FORMATD(S32_BE, "Signed 32 bit Big Endian"),
1891 FORMATD(U32_LE, "Unsigned 32 bit Little Endian"),
1892 FORMATD(U32_BE, "Unsigned 32 bit Big Endian"),
1893 FORMATD(FLOAT_LE, "Float 32 bit Little Endian"),
1894 FORMATD(FLOAT_BE, "Float 32 bit Big Endian"),
1895 FORMATD(FLOAT64_LE, "Float 64 bit Little Endian"),
1896 FORMATD(FLOAT64_BE, "Float 64 bit Big Endian"),
1897 FORMATD(IEC958_SUBFRAME_LE, "IEC-958 Little Endian"),
1898 FORMATD(IEC958_SUBFRAME_BE, "IEC-958 Big Endian"),
1899 FORMATD(MU_LAW, "Mu-Law"),
1900 FORMATD(A_LAW, "A-Law"),
1901 FORMATD(IMA_ADPCM, "Ima-ADPCM"),
1902 FORMATD(MPEG, "MPEG"),
1903 FORMATD(GSM, "GSM"),
1904 FORMATD(S20_LE, "Signed 20 bit Little Endian in 4 bytes, LSB justified"),
1905 FORMATD(S20_BE, "Signed 20 bit Big Endian in 4 bytes, LSB justified"),
1906 FORMATD(U20_LE, "Unsigned 20 bit Little Endian in 4 bytes, LSB justified"),
1907 FORMATD(U20_BE, "Unsigned 20 bit Big Endian in 4 bytes, LSB justified"),
1908 FORMATD(SPECIAL, "Special"),
1909 FORMATD(S24_3LE, "Signed 24 bit Little Endian in 3bytes"),
1910 FORMATD(S24_3BE, "Signed 24 bit Big Endian in 3bytes"),
1911 FORMATD(U24_3LE, "Unsigned 24 bit Little Endian in 3bytes"),
1912 FORMATD(U24_3BE, "Unsigned 24 bit Big Endian in 3bytes"),
1913 FORMATD(S20_3LE, "Signed 20 bit Little Endian in 3bytes"),
1914 FORMATD(S20_3BE, "Signed 20 bit Big Endian in 3bytes"),
1915 FORMATD(U20_3LE, "Unsigned 20 bit Little Endian in 3bytes"),
1916 FORMATD(U20_3BE, "Unsigned 20 bit Big Endian in 3bytes"),
1917 FORMATD(S18_3LE, "Signed 18 bit Little Endian in 3bytes"),
1918 FORMATD(S18_3BE, "Signed 18 bit Big Endian in 3bytes"),
1919 FORMATD(U18_3LE, "Unsigned 18 bit Little Endian in 3bytes"),
1920 FORMATD(U18_3BE, "Unsigned 18 bit Big Endian in 3bytes"),
1921 FORMATD(G723_24, "G.723 (ADPCM) 24 kbit/s, 8 samples in 3 bytes"),
1922 FORMATD(G723_24_1B, "G.723 (ADPCM) 24 kbit/s, 1 sample in 1 byte"),
1923 FORMATD(G723_40, "G.723 (ADPCM) 40 kbit/s, 8 samples in 3 bytes"),
1924 FORMATD(G723_40_1B, "G.723 (ADPCM) 40 kbit/s, 1 sample in 1 byte"),
1925 FORMATD(DSD_U8, "Direct Stream Digital, 1-byte (x8), oldest bit in MSB"),
1926 FORMATD(DSD_U16_LE, "Direct Stream Digital, 2-byte (x16), little endian, oldest bits in MSB"),
1927 FORMATD(DSD_U32_LE, "Direct Stream Digital, 4-byte (x32), little endian, oldest bits in MSB"),
1928 FORMATD(DSD_U16_BE, "Direct Stream Digital, 2-byte (x16), big endian, oldest bits in MSB"),
1929 FORMATD(DSD_U32_BE, "Direct Stream Digital, 4-byte (x32), big endian, oldest bits in MSB"),
1932 static const char *const snd_pcm_type_names[] = {
1953 PCMTYPE(LINEAR_FLOAT),
1965 static const char *const snd_pcm_subformat_names[] = {
1969 static const char *const snd_pcm_subformat_descriptions[] = {
1970 SUBFORMATD(STD, "Standard"),
1973 static const char *const snd_pcm_start_mode_names[] = {
1978 static const char *const snd_pcm_xrun_mode_names[] = {
1983 static const char *const snd_pcm_tstamp_mode_names[] = {
1988 static const char *const snd_pcm_tstamp_type_names[] = {
1989 TSTAMP_TYPE(GETTIMEOFDAY),
1990 TSTAMP_TYPE(MONOTONIC),
1991 TSTAMP_TYPE(MONOTONIC_RAW),
1996 * \brief get name of PCM stream type
1997 * \param stream PCM stream type
1998 * \return ascii name of PCM stream type
2000 const char *snd_pcm_stream_name(snd_pcm_stream_t stream)
2002 if (stream > SND_PCM_STREAM_LAST)
2004 return snd_pcm_stream_names[stream];
2008 * \brief get name of PCM access type
2009 * \param acc PCM access type
2010 * \return ascii name of PCM access type
2012 const char *snd_pcm_access_name(snd_pcm_access_t acc)
2014 if (acc > SND_PCM_ACCESS_LAST)
2016 return snd_pcm_access_names[acc];
2020 * \brief get name of PCM sample format
2021 * \param format PCM sample format
2022 * \return ascii name of PCM sample format
2024 const char *snd_pcm_format_name(snd_pcm_format_t format)
2026 if (format > SND_PCM_FORMAT_LAST)
2028 return snd_pcm_format_names[format];
2032 * \brief get description of PCM sample format
2033 * \param format PCM sample format
2034 * \return ascii description of PCM sample format
2036 const char *snd_pcm_format_description(snd_pcm_format_t format)
2038 if (format > SND_PCM_FORMAT_LAST)
2040 return snd_pcm_format_descriptions[format];
2044 * \brief get PCM sample format from name
2045 * \param name PCM sample format name (case insensitive)
2046 * \return PCM sample format
2048 snd_pcm_format_t snd_pcm_format_value(const char* name)
2050 snd_pcm_format_t format;
2051 for (format = 0; format <= SND_PCM_FORMAT_LAST; format++) {
2052 if (snd_pcm_format_names[format] &&
2053 strcasecmp(name, snd_pcm_format_names[format]) == 0) {
2056 if (snd_pcm_format_aliases[format] &&
2057 strcasecmp(name, snd_pcm_format_aliases[format]) == 0) {
2061 for (format = 0; format <= SND_PCM_FORMAT_LAST; format++) {
2062 if (snd_pcm_format_descriptions[format] &&
2063 strcasecmp(name, snd_pcm_format_descriptions[format]) == 0) {
2067 return SND_PCM_FORMAT_UNKNOWN;
2071 * \brief get name of PCM sample subformat
2072 * \param subformat PCM sample subformat
2073 * \return ascii name of PCM sample subformat
2075 const char *snd_pcm_subformat_name(snd_pcm_subformat_t subformat)
2077 if (subformat > SND_PCM_SUBFORMAT_LAST)
2079 return snd_pcm_subformat_names[subformat];
2083 * \brief get description of PCM sample subformat
2084 * \param subformat PCM sample subformat
2085 * \return ascii description of PCM sample subformat
2087 const char *snd_pcm_subformat_description(snd_pcm_subformat_t subformat)
2089 if (subformat > SND_PCM_SUBFORMAT_LAST)
2091 return snd_pcm_subformat_descriptions[subformat];
2095 * \brief (DEPRECATED) get name of PCM start mode setting
2096 * \param mode PCM start mode
2097 * \return ascii name of PCM start mode setting
2099 const char *snd_pcm_start_mode_name(snd_pcm_start_t mode)
2101 if (mode > SND_PCM_START_LAST)
2103 return snd_pcm_start_mode_names[mode];
2107 link_warning(snd_pcm_start_mode_name, "Warning: start_mode is deprecated, consider to use start_threshold");
2111 * \brief (DEPRECATED) get name of PCM xrun mode setting
2112 * \param mode PCM xrun mode
2113 * \return ascii name of PCM xrun mode setting
2115 const char *snd_pcm_xrun_mode_name(snd_pcm_xrun_t mode)
2117 if (mode > SND_PCM_XRUN_LAST)
2119 return snd_pcm_xrun_mode_names[mode];
2123 link_warning(snd_pcm_xrun_mode_name, "Warning: xrun_mode is deprecated, consider to use stop_threshold");
2127 * \brief get name of PCM tstamp mode setting
2128 * \param mode PCM tstamp mode
2129 * \return ascii name of PCM tstamp mode setting
2131 const char *snd_pcm_tstamp_mode_name(snd_pcm_tstamp_t mode)
2133 if (mode > SND_PCM_TSTAMP_LAST)
2135 return snd_pcm_tstamp_mode_names[mode];
2139 * \brief get name of PCM tstamp type setting
2140 * \param mode PCM tstamp type
2141 * \return ascii name of PCM tstamp type setting
2143 const char *snd_pcm_tstamp_type_name(snd_pcm_tstamp_type_t type)
2145 if (type > SND_PCM_TSTAMP_TYPE_LAST)
2147 return snd_pcm_tstamp_type_names[type];
2151 * \brief get name of PCM state
2152 * \param state PCM state
2153 * \return ascii name of PCM state
2155 const char *snd_pcm_state_name(snd_pcm_state_t state)
2157 if (state > SND_PCM_STATE_LAST)
2159 return snd_pcm_state_names[state];
2163 * \brief get name of PCM type
2164 * \param type PCM type
2165 * \return ascii name of PCM type
2168 EXPORT_SYMBOL const char *INTERNAL(snd_pcm_type_name)(snd_pcm_type_t type)
2170 const char *snd_pcm_type_name(snd_pcm_type_t type)
2173 if (type > SND_PCM_TYPE_LAST)
2175 return snd_pcm_type_names[type];
2177 use_default_symbol_version(__snd_pcm_type_name, snd_pcm_type_name, ALSA_0.9.0);
2180 * \brief Dump current hardware setup for PCM
2181 * \param pcm PCM handle
2182 * \param out Output handle
2183 * \return 0 on success otherwise a negative error code
2185 int snd_pcm_dump_hw_setup(snd_pcm_t *pcm, snd_output_t *out)
2189 if (CHECK_SANITY(! pcm->setup)) {
2190 SNDMSG("PCM not set up");
2193 snd_output_printf(out, " stream : %s\n", snd_pcm_stream_name(pcm->stream));
2194 snd_output_printf(out, " access : %s\n", snd_pcm_access_name(pcm->access));
2195 snd_output_printf(out, " format : %s\n", snd_pcm_format_name(pcm->format));
2196 snd_output_printf(out, " subformat : %s\n", snd_pcm_subformat_name(pcm->subformat));
2197 snd_output_printf(out, " channels : %u\n", pcm->channels);
2198 snd_output_printf(out, " rate : %u\n", pcm->rate);
2199 snd_output_printf(out, " exact rate : %g (%u/%u)\n",
2200 (pcm->rate_den ? ((double) pcm->rate_num / pcm->rate_den) : 0.0),
2201 pcm->rate_num, pcm->rate_den);
2202 snd_output_printf(out, " msbits : %u\n", pcm->msbits);
2203 snd_output_printf(out, " buffer_size : %lu\n", pcm->buffer_size);
2204 snd_output_printf(out, " period_size : %lu\n", pcm->period_size);
2205 snd_output_printf(out, " period_time : %u\n", pcm->period_time);
2210 * \brief Dump current software setup for PCM
2211 * \param pcm PCM handle
2212 * \param out Output handle
2213 * \return 0 on success otherwise a negative error code
2215 int snd_pcm_dump_sw_setup(snd_pcm_t *pcm, snd_output_t *out)
2219 if (CHECK_SANITY(! pcm->setup)) {
2220 SNDMSG("PCM not set up");
2223 snd_output_printf(out, " tstamp_mode : %s\n", snd_pcm_tstamp_mode_name(pcm->tstamp_mode));
2224 snd_output_printf(out, " tstamp_type : %s\n", snd_pcm_tstamp_type_name(pcm->tstamp_type));
2225 snd_output_printf(out, " period_step : %d\n", pcm->period_step);
2226 snd_output_printf(out, " avail_min : %ld\n", pcm->avail_min);
2227 snd_output_printf(out, " period_event : %i\n", pcm->period_event);
2228 snd_output_printf(out, " start_threshold : %ld\n", pcm->start_threshold);
2229 snd_output_printf(out, " stop_threshold : %ld\n", pcm->stop_threshold);
2230 snd_output_printf(out, " silence_threshold: %ld\n", pcm->silence_threshold);
2231 snd_output_printf(out, " silence_size : %ld\n", pcm->silence_size);
2232 snd_output_printf(out, " boundary : %ld\n", pcm->boundary);
2237 * \brief Dump current setup (hardware and software) for PCM
2238 * \param pcm PCM handle
2239 * \param out Output handle
2240 * \return 0 on success otherwise a negative error code
2242 int snd_pcm_dump_setup(snd_pcm_t *pcm, snd_output_t *out)
2244 snd_pcm_dump_hw_setup(pcm, out);
2245 snd_pcm_dump_sw_setup(pcm, out);
2250 * \brief Dump status
2251 * \param status Status container
2252 * \param out Output handle
2253 * \return 0 on success otherwise a negative error code
2255 int snd_pcm_status_dump(snd_pcm_status_t *status, snd_output_t *out)
2258 snd_output_printf(out, " state : %s\n", snd_pcm_state_name((snd_pcm_state_t) status->state));
2259 snd_output_printf(out, " trigger_time: %ld.%06ld\n",
2260 status->trigger_tstamp.tv_sec,
2261 status->trigger_tstamp.tv_nsec / 1000);
2262 snd_output_printf(out, " tstamp : %ld.%06ld\n",
2263 status->tstamp.tv_sec, status->tstamp.tv_nsec / 1000);
2264 snd_output_printf(out, " delay : %ld\n", (long)status->delay);
2265 snd_output_printf(out, " avail : %ld\n", (long)status->avail);
2266 snd_output_printf(out, " avail_max : %ld\n", (long)status->avail_max);
2271 * \brief Dump PCM info
2272 * \param pcm PCM handle
2273 * \param out Output handle
2274 * \return 0 on success otherwise a negative error code
2276 int snd_pcm_dump(snd_pcm_t *pcm, snd_output_t *out)
2280 pcm->ops->dump(pcm->op_arg, out);
2285 * \brief Convert bytes in frames for a PCM
2286 * \param pcm PCM handle
2287 * \param bytes quantity in bytes
2288 * \return quantity expressed in frames
2290 snd_pcm_sframes_t snd_pcm_bytes_to_frames(snd_pcm_t *pcm, ssize_t bytes)
2293 if (CHECK_SANITY(! pcm->setup)) {
2294 SNDMSG("PCM not set up");
2297 return bytes * 8 / pcm->frame_bits;
2301 * \brief Convert frames in bytes for a PCM
2302 * \param pcm PCM handle
2303 * \param frames quantity in frames
2304 * \return quantity expressed in bytes
2306 ssize_t snd_pcm_frames_to_bytes(snd_pcm_t *pcm, snd_pcm_sframes_t frames)
2309 if (CHECK_SANITY(! pcm->setup)) {
2310 SNDMSG("PCM not set up");
2313 return frames * pcm->frame_bits / 8;
2317 * \brief Convert bytes in samples for a PCM
2318 * \param pcm PCM handle
2319 * \param bytes quantity in bytes
2320 * \return quantity expressed in samples
2322 long snd_pcm_bytes_to_samples(snd_pcm_t *pcm, ssize_t bytes)
2325 if (CHECK_SANITY(! pcm->setup)) {
2326 SNDMSG("PCM not set up");
2329 return bytes * 8 / pcm->sample_bits;
2333 * \brief Convert samples in bytes for a PCM
2334 * \param pcm PCM handle
2335 * \param samples quantity in samples
2336 * \return quantity expressed in bytes
2338 ssize_t snd_pcm_samples_to_bytes(snd_pcm_t *pcm, long samples)
2341 if (CHECK_SANITY(! pcm->setup)) {
2342 SNDMSG("PCM not set up");
2345 return samples * pcm->sample_bits / 8;
2349 * \brief Add an async handler for a PCM
2350 * \param handler Returned handler handle
2351 * \param pcm PCM handle
2352 * \param callback Callback function
2353 * \param private_data Callback private data
2354 * \return 0 otherwise a negative error code on failure
2356 * The asynchronous callback is called when period boundary elapses.
2358 int snd_async_add_pcm_handler(snd_async_handler_t **handler, snd_pcm_t *pcm,
2359 snd_async_callback_t callback, void *private_data)
2363 snd_async_handler_t *h;
2364 err = snd_async_add_handler(&h, _snd_pcm_async_descriptor(pcm),
2365 callback, private_data);
2368 h->type = SND_ASYNC_HANDLER_PCM;
2370 was_empty = list_empty(&pcm->async_handlers);
2371 list_add_tail(&h->hlist, &pcm->async_handlers);
2373 err = snd_pcm_async(pcm, snd_async_handler_get_signo(h), getpid());
2375 snd_async_del_handler(h);
2384 * \brief Return PCM handle related to an async handler
2385 * \param handler Async handler handle
2386 * \return PCM handle
2388 snd_pcm_t *snd_async_handler_get_pcm(snd_async_handler_t *handler)
2390 if (handler->type != SND_ASYNC_HANDLER_PCM) {
2391 SNDMSG("invalid handler type %d", handler->type);
2394 return handler->u.pcm;
2397 static const char *const build_in_pcms[] = {
2398 "adpcm", "alaw", "copy", "dmix", "file", "hooks", "hw", "ladspa", "lfloat",
2399 "linear", "meter", "mulaw", "multi", "null", "empty", "plug", "rate", "route", "share",
2400 "shm", "dsnoop", "dshare", "asym", "iec958", "softvol", "mmap_emul",
2404 static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name,
2405 snd_config_t *pcm_root, snd_config_t *pcm_conf,
2406 snd_pcm_stream_t stream, int mode)
2409 char *buf = NULL, *buf1 = NULL;
2411 snd_config_t *conf, *type_conf = NULL, *tmp;
2412 snd_config_iterator_t i, next;
2414 const char *lib = NULL, *open_name = NULL;
2415 int (*open_func)(snd_pcm_t **, const char *,
2416 snd_config_t *, snd_config_t *,
2417 snd_pcm_stream_t, int) = NULL;
2419 extern void *snd_pcm_open_symbols(void);
2421 if (snd_config_get_type(pcm_conf) != SND_CONFIG_TYPE_COMPOUND) {
2424 snd_config_get_id(pcm_conf, &id);
2426 snd_config_get_ascii(pcm_conf, &val);
2427 SNDERR("Invalid type for PCM %s%sdefinition (id: %s, value: %s)", name ? name : "", name ? " " : "", id, val);
2431 err = snd_config_search(pcm_conf, "type", &conf);
2433 SNDERR("type is not defined");
2436 err = snd_config_get_id(conf, &id);
2438 SNDERR("unable to get id");
2441 err = snd_config_get_string(conf, &str);
2443 SNDERR("Invalid type for %s", id);
2446 err = snd_config_search_definition(pcm_root, "pcm_type", str, &type_conf);
2448 if (snd_config_get_type(type_conf) != SND_CONFIG_TYPE_COMPOUND) {
2449 SNDERR("Invalid type for PCM type %s definition", str);
2453 snd_config_for_each(i, next, type_conf) {
2454 snd_config_t *n = snd_config_iterator_entry(i);
2456 if (snd_config_get_id(n, &id) < 0)
2458 if (strcmp(id, "comment") == 0)
2460 if (strcmp(id, "lib") == 0) {
2461 err = snd_config_get_string(n, &lib);
2463 SNDERR("Invalid type for %s", id);
2468 if (strcmp(id, "open") == 0) {
2469 err = snd_config_get_string(n, &open_name);
2471 SNDERR("Invalid type for %s", id);
2476 SNDERR("Unknown field %s", id);
2482 buf = malloc(strlen(str) + 32);
2488 sprintf(buf, "_snd_pcm_%s_open", str);
2491 const char *const *build_in = build_in_pcms;
2493 if (!strcmp(*build_in, str))
2497 if (*build_in == NULL) {
2498 buf1 = malloc(strlen(str) + sizeof(ALSA_PLUGIN_DIR) + 32);
2504 sprintf(buf1, "%s/libasound_module_pcm_%s.so", ALSA_PLUGIN_DIR, str);
2508 snd_pcm_open_symbols(); /* this call is for static linking only */
2510 open_func = snd_dlobj_cache_get(lib, open_name,
2511 SND_DLSYM_VERSION(SND_PCM_DLSYM_VERSION), 1);
2513 err = open_func(pcmp, name, pcm_root, pcm_conf, stream, mode);
2515 if ((*pcmp)->open_func) {
2516 /* only init plugin (like empty, asym) */
2517 snd_dlobj_cache_put(open_func);
2519 (*pcmp)->open_func = open_func;
2523 snd_dlobj_cache_put(open_func);
2529 err = snd_config_search(pcm_root, "defaults.pcm.compat", &tmp);
2532 if (snd_config_get_integer(tmp, &i) >= 0) {
2534 (*pcmp)->compat = 1;
2537 char *str = getenv("LIBASOUND_COMPAT");
2539 (*pcmp)->compat = 1;
2541 err = snd_config_search(pcm_root, "defaults.pcm.minperiodtime", &tmp);
2543 snd_config_get_integer(tmp, &(*pcmp)->minperiodtime);
2548 snd_config_delete(type_conf);
2554 static int snd_pcm_open_noupdate(snd_pcm_t **pcmp, snd_config_t *root,
2555 const char *name, snd_pcm_stream_t stream,
2559 snd_config_t *pcm_conf;
2562 err = snd_config_search_definition(root, "pcm", name, &pcm_conf);
2564 SNDERR("Unknown PCM %s", name);
2567 if (snd_config_get_string(pcm_conf, &str) >= 0)
2568 err = snd_pcm_open_noupdate(pcmp, root, str, stream, mode,
2571 snd_config_set_hop(pcm_conf, hop);
2572 err = snd_pcm_open_conf(pcmp, name, root, pcm_conf, stream, mode);
2574 snd_config_delete(pcm_conf);
2579 * \brief Opens a PCM
2580 * \param pcmp Returned PCM handle
2581 * \param name ASCII identifier of the PCM handle
2582 * \param stream Wanted stream
2583 * \param mode Open mode (see #SND_PCM_NONBLOCK, #SND_PCM_ASYNC)
2584 * \return 0 on success otherwise a negative error code
2586 int snd_pcm_open(snd_pcm_t **pcmp, const char *name,
2587 snd_pcm_stream_t stream, int mode)
2592 assert(pcmp && name);
2593 err = snd_config_update_ref(&top);
2596 err = snd_pcm_open_noupdate(pcmp, top, name, stream, mode, 0);
2597 snd_config_unref(top);
2602 * \brief Opens a PCM using local configuration
2603 * \param pcmp Returned PCM handle
2604 * \param name ASCII identifier of the PCM handle
2605 * \param stream Wanted stream
2606 * \param mode Open mode (see #SND_PCM_NONBLOCK, #SND_PCM_ASYNC)
2607 * \param lconf Local configuration
2608 * \return 0 on success otherwise a negative error code
2610 int snd_pcm_open_lconf(snd_pcm_t **pcmp, const char *name,
2611 snd_pcm_stream_t stream, int mode,
2612 snd_config_t *lconf)
2614 assert(pcmp && name && lconf);
2615 return snd_pcm_open_noupdate(pcmp, lconf, name, stream, mode, 0);
2619 * \brief Opens a fallback PCM
2620 * \param pcmp Returned PCM handle
2621 * \param root Configuration root
2622 * \param name ASCII identifier of the PCM handle
2623 * \param orig_name The original ASCII name
2624 * \param stream Wanted stream
2625 * \param mode Open mode (see #SND_PCM_NONBLOCK, #SND_PCM_ASYNC)
2626 * \return 0 on success otherwise a negative error code
2628 int snd_pcm_open_fallback(snd_pcm_t **pcmp, snd_config_t *root,
2629 const char *name, const char *orig_name,
2630 snd_pcm_stream_t stream, int mode)
2633 assert(pcmp && name && root);
2634 err = snd_pcm_open_noupdate(pcmp, root, name, stream, mode, 0);
2636 free((*pcmp)->name);
2637 (*pcmp)->name = orig_name ? strdup(orig_name) : NULL;
2643 int snd_pcm_new(snd_pcm_t **pcmp, snd_pcm_type_t type, const char *name,
2644 snd_pcm_stream_t stream, int mode)
2647 #ifdef THREAD_SAFE_API
2648 pthread_mutexattr_t attr;
2651 pcm = calloc(1, sizeof(*pcm));
2656 pcm->name = strdup(name);
2657 pcm->stream = stream;
2659 pcm->poll_fd_count = 1;
2662 pcm->fast_op_arg = pcm;
2663 INIT_LIST_HEAD(&pcm->async_handlers);
2664 #ifdef THREAD_SAFE_API
2665 pthread_mutexattr_init(&attr);
2666 #ifdef HAVE_PTHREAD_MUTEX_RECURSIVE
2667 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
2669 pthread_mutex_init(&pcm->lock, &attr);
2670 /* use locking as default;
2671 * each plugin may suppress this in its open call
2674 if (mode & SND_PCM_ASYNC) {
2675 /* async handler may lead to a deadlock; suppose no MT */
2676 pcm->lock_enabled = 0;
2678 /* set lock_enabled field depending on $LIBASOUND_THREAD_SAFE */
2679 static int do_lock_enable = -1; /* uninitialized */
2681 /* evaluate env var only once at the first open for consistency */
2682 if (do_lock_enable == -1) {
2683 char *p = getenv("LIBASOUND_THREAD_SAFE");
2684 do_lock_enable = !p || *p != '0';
2686 pcm->lock_enabled = do_lock_enable;
2693 int snd_pcm_free(snd_pcm_t *pcm)
2697 free(pcm->hw.link_dst);
2698 free(pcm->appl.link_dst);
2699 snd_dlobj_cache_put(pcm->open_func);
2700 #ifdef THREAD_SAFE_API
2701 pthread_mutex_destroy(&pcm->lock);
2707 int snd_pcm_open_named_slave(snd_pcm_t **pcmp, const char *name,
2709 snd_config_t *conf, snd_pcm_stream_t stream,
2710 int mode, snd_config_t *parent_conf)
2715 if ((hop = snd_config_check_hop(parent_conf)) < 0)
2717 if (snd_config_get_string(conf, &str) >= 0)
2718 return snd_pcm_open_noupdate(pcmp, root, str, stream, mode,
2720 return snd_pcm_open_conf(pcmp, name, root, conf, stream, mode);
2725 * \brief Wait for a PCM to become ready
2726 * \param pcm PCM handle
2727 * \param timeout maximum time in milliseconds to wait,
2728 * a negative value means infinity
2729 * \return a positive value on success otherwise a negative error code
2730 * (-EPIPE for the xrun and -ESTRPIPE for the suspended status,
2731 * others for general errors)
2732 * \retval 0 timeout occurred
2733 * \retval 1 PCM stream is ready for I/O
2735 * The function is thread-safe when built with the proper option.
2737 int snd_pcm_wait(snd_pcm_t *pcm, int timeout)
2741 __snd_pcm_lock(pcm); /* forced lock */
2742 err = __snd_pcm_wait_in_lock(pcm, timeout);
2743 __snd_pcm_unlock(pcm);
2748 /* locked version */
2749 int __snd_pcm_wait_in_lock(snd_pcm_t *pcm, int timeout)
2753 /* NOTE: avail_min check can be skipped during draining */
2754 if (__snd_pcm_state(pcm) != SND_PCM_STATE_DRAINING &&
2755 !snd_pcm_may_wait_for_avail_min(pcm, snd_pcm_mmap_avail(pcm))) {
2756 /* check more precisely */
2757 err = pcm_state_to_error(__snd_pcm_state(pcm));
2758 return err < 0 ? err : 1;
2760 return snd_pcm_wait_nocheck(pcm, timeout);
2764 * like snd_pcm_wait() but doesn't check mmap_avail before calling poll()
2766 * used in drain code in some plugins
2768 * This function is called inside pcm lock.
2770 int snd_pcm_wait_nocheck(snd_pcm_t *pcm, int timeout)
2773 unsigned short revents = 0;
2774 int npfds, err, err_poll;
2776 npfds = __snd_pcm_poll_descriptors_count(pcm);
2777 if (npfds <= 0 || npfds >= 16) {
2778 SNDERR("Invalid poll_fds %d\n", npfds);
2781 pfd = alloca(sizeof(*pfd) * npfds);
2782 err = __snd_pcm_poll_descriptors(pcm, pfd, npfds);
2786 SNDMSG("invalid poll descriptors %d\n", err);
2790 __snd_pcm_unlock(pcm);
2791 err_poll = poll(pfd, npfds, timeout);
2792 __snd_pcm_lock(pcm);
2794 if (errno == EINTR && !PCMINABORT(pcm))
2800 err = __snd_pcm_poll_revents(pcm, pfd, npfds, &revents);
2803 if (revents & (POLLERR | POLLNVAL)) {
2804 /* check more precisely */
2805 err = pcm_state_to_error(__snd_pcm_state(pcm));
2806 return err < 0 ? err : -EIO;
2808 } while (!(revents & (POLLIN | POLLOUT)));
2809 #if 0 /* very useful code to test poll related problems */
2811 snd_pcm_sframes_t avail_update;
2812 __snd_pcm_hwsync(pcm);
2813 avail_update = __snd_pcm_avail_update(pcm);
2814 if (avail_update < (snd_pcm_sframes_t)pcm->avail_min) {
2815 printf("*** snd_pcm_wait() FATAL ERROR!!!\n");
2816 printf("avail_min = %li, avail_update = %li\n", pcm->avail_min, avail_update);
2820 return err_poll > 0 ? 1 : 0;
2825 * \brief Return number of frames ready to be read (capture) / written (playback)
2826 * \param pcm PCM handle
2827 * \return a positive number of frames ready otherwise a negative
2830 * On capture does all the actions needed to transport to application
2831 * level all the ready frames across underlying layers.
2833 * The position is not synced with hardware (driver) position in the sound
2834 * ring buffer in this function. This function is a light version of
2835 * #snd_pcm_avail() .
2837 * Using this function is ideal after poll() or select() when audio
2838 * file descriptor made the event and when application expects just period
2841 * Also this function might be called after #snd_pcm_delay() or
2842 * #snd_pcm_hwsync() functions to move private ring buffer pointers
2843 * in alsa-lib (the internal plugin chain).
2845 * The function is thread-safe when built with the proper option.
2847 snd_pcm_sframes_t snd_pcm_avail_update(snd_pcm_t *pcm)
2849 snd_pcm_sframes_t result;
2852 result = __snd_pcm_avail_update(pcm);
2853 snd_pcm_unlock(pcm);
2858 * \brief Return number of frames ready to be read (capture) / written (playback)
2859 * \param pcm PCM handle
2860 * \return a positive number of frames ready otherwise a negative
2863 * On capture does all the actions needed to transport to application
2864 * level all the ready frames across underlying layers.
2866 * The position is synced with hardware (driver) position in the sound
2867 * ring buffer in this functions.
2869 * The function is thread-safe when built with the proper option.
2871 snd_pcm_sframes_t snd_pcm_avail(snd_pcm_t *pcm)
2874 snd_pcm_sframes_t result;
2877 if (CHECK_SANITY(! pcm->setup)) {
2878 SNDMSG("PCM not set up");
2882 err = __snd_pcm_hwsync(pcm);
2886 result = __snd_pcm_avail_update(pcm);
2887 snd_pcm_unlock(pcm);
2892 * \brief Combine snd_pcm_avail and snd_pcm_delay functions
2893 * \param pcm PCM handle
2894 * \param availp Number of available frames in the ring buffer
2895 * \param delayp Total I/O latency in frames
2896 * \return zero on success otherwise a negative error code
2898 * The avail and delay values retuned are in sync.
2900 * The function is thread-safe when built with the proper option.
2902 int snd_pcm_avail_delay(snd_pcm_t *pcm,
2903 snd_pcm_sframes_t *availp,
2904 snd_pcm_sframes_t *delayp)
2906 snd_pcm_sframes_t sf;
2909 assert(pcm && availp && delayp);
2910 if (CHECK_SANITY(! pcm->setup)) {
2911 SNDMSG("PCM not set up");
2915 err = __snd_pcm_hwsync(pcm);
2918 sf = __snd_pcm_avail_update(pcm);
2923 err = __snd_pcm_delay(pcm, delayp);
2929 snd_pcm_unlock(pcm);
2934 * \brief Silence an area
2935 * \param dst_area area specification
2936 * \param dst_offset offset in frames inside area
2937 * \param samples samples to silence
2938 * \param format PCM sample format
2939 * \return 0 on success otherwise a negative error code
2941 int snd_pcm_area_silence(const snd_pcm_channel_area_t *dst_area, snd_pcm_uframes_t dst_offset,
2942 unsigned int samples, snd_pcm_format_t format)
2944 /* FIXME: sub byte resolution and odd dst_offset */
2946 unsigned int dst_step;
2949 if (!dst_area->addr)
2951 dst = snd_pcm_channel_area_addr(dst_area, dst_offset);
2952 width = snd_pcm_format_physical_width(format);
2953 silence = snd_pcm_format_silence_64(format);
2955 * Iterate copying silent sample for sample data aligned to 64 bit.
2956 * This is a fast path.
2958 if (dst_area->step == (unsigned int) width &&
2960 ((intptr_t)dst & 7) == 0) {
2961 unsigned int dwords = samples * width / 64;
2962 uint64_t *dstp = (uint64_t *)dst;
2963 samples -= dwords * 64 / width;
2964 while (dwords-- > 0)
2970 dst_step = dst_area->step / 8;
2973 uint8_t s0 = silence & 0xf0;
2974 uint8_t s1 = silence & 0x0f;
2975 int dstbit = dst_area->first % 8;
2976 int dstbit_step = dst_area->step % 8;
2977 while (samples-- > 0) {
2986 dstbit += dstbit_step;
2995 uint8_t sil = silence;
2996 while (samples-- > 0) {
3003 uint16_t sil = silence;
3004 while (samples-- > 0) {
3005 *(uint16_t*)dst = sil;
3011 while (samples-- > 0) {
3012 #ifdef SNDRV_LITTLE_ENDIAN
3013 *(dst + 0) = silence >> 0;
3014 *(dst + 1) = silence >> 8;
3015 *(dst + 2) = silence >> 16;
3017 *(dst + 2) = silence >> 0;
3018 *(dst + 1) = silence >> 8;
3019 *(dst + 0) = silence >> 16;
3026 uint32_t sil = silence;
3027 while (samples-- > 0) {
3028 *(uint32_t*)dst = sil;
3034 while (samples-- > 0) {
3035 *(uint64_t*)dst = silence;
3041 SNDMSG("invalid format width %d", width);
3048 * \brief Silence one or more areas
3049 * \param dst_areas areas specification (one for each channel)
3050 * \param dst_offset offset in frames inside area
3051 * \param channels channels count
3052 * \param frames frames to silence
3053 * \param format PCM sample format
3054 * \return 0 on success otherwise a negative error code
3056 int snd_pcm_areas_silence(const snd_pcm_channel_area_t *dst_areas, snd_pcm_uframes_t dst_offset,
3057 unsigned int channels, snd_pcm_uframes_t frames, snd_pcm_format_t format)
3059 int width = snd_pcm_format_physical_width(format);
3060 while (channels > 0) {
3061 void *addr = dst_areas->addr;
3062 unsigned int step = dst_areas->step;
3063 const snd_pcm_channel_area_t *begin = dst_areas;
3064 int channels1 = channels;
3065 unsigned int chns = 0;
3071 if (channels1 == 0 ||
3072 dst_areas->addr != addr ||
3073 dst_areas->step != step ||
3074 dst_areas->first != dst_areas[-1].first + width)
3077 if (chns > 1 && chns * width == step) {
3078 /* Collapse the areas */
3079 snd_pcm_channel_area_t d;
3080 d.addr = begin->addr;
3081 d.first = begin->first;
3083 err = snd_pcm_area_silence(&d, dst_offset * chns, frames * chns, format);
3086 err = snd_pcm_area_silence(begin, dst_offset, frames, format);
3087 dst_areas = begin + 1;
3098 * \brief Copy an area
3099 * \param dst_area destination area specification
3100 * \param dst_offset offset in frames inside destination area
3101 * \param src_area source area specification
3102 * \param src_offset offset in frames inside source area
3103 * \param samples samples to copy
3104 * \param format PCM sample format
3105 * \return 0 on success otherwise a negative error code
3107 int snd_pcm_area_copy(const snd_pcm_channel_area_t *dst_area, snd_pcm_uframes_t dst_offset,
3108 const snd_pcm_channel_area_t *src_area, snd_pcm_uframes_t src_offset,
3109 unsigned int samples, snd_pcm_format_t format)
3111 /* FIXME: sub byte resolution and odd dst_offset */
3115 int src_step, dst_step;
3116 if (dst_area == src_area && dst_offset == src_offset)
3118 if (!src_area->addr)
3119 return snd_pcm_area_silence(dst_area, dst_offset, samples, format);
3120 src = snd_pcm_channel_area_addr(src_area, src_offset);
3121 if (!dst_area->addr)
3123 dst = snd_pcm_channel_area_addr(dst_area, dst_offset);
3124 width = snd_pcm_format_physical_width(format);
3125 if (src_area->step == (unsigned int) width &&
3126 dst_area->step == (unsigned int) width) {
3127 size_t bytes = samples * width / 8;
3128 samples -= bytes * 8 / width;
3129 assert(src < dst || src >= dst + bytes);
3130 assert(dst < src || dst >= src + bytes);
3131 memcpy(dst, src, bytes);
3135 src_step = src_area->step / 8;
3136 dst_step = dst_area->step / 8;
3139 int srcbit = src_area->first % 8;
3140 int srcbit_step = src_area->step % 8;
3141 int dstbit = dst_area->first % 8;
3142 int dstbit_step = dst_area->step % 8;
3143 while (samples-- > 0) {
3144 unsigned char srcval;
3146 srcval = *src & 0x0f;
3148 srcval = *src & 0xf0;
3155 srcbit += srcbit_step;
3161 dstbit += dstbit_step;
3170 while (samples-- > 0) {
3178 while (samples-- > 0) {
3179 *(uint16_t*)dst = *(const uint16_t*)src;
3186 while (samples-- > 0) {
3187 *(dst + 0) = *(src + 0);
3188 *(dst + 1) = *(src + 1);
3189 *(dst + 2) = *(src + 2);
3195 while (samples-- > 0) {
3196 *(uint32_t*)dst = *(const uint32_t*)src;
3203 while (samples-- > 0) {
3204 *(uint64_t*)dst = *(const uint64_t*)src;
3211 SNDMSG("invalid format width %d", width);
3218 * \brief Copy one or more areas
3219 * \param dst_areas destination areas specification (one for each channel)
3220 * \param dst_offset offset in frames inside destination area
3221 * \param src_areas source areas specification (one for each channel)
3222 * \param src_offset offset in frames inside source area
3223 * \param channels channels count
3224 * \param frames frames to copy
3225 * \param format PCM sample format
3226 * \return 0 on success otherwise a negative error code
3228 int snd_pcm_areas_copy(const snd_pcm_channel_area_t *dst_areas, snd_pcm_uframes_t dst_offset,
3229 const snd_pcm_channel_area_t *src_areas, snd_pcm_uframes_t src_offset,
3230 unsigned int channels, snd_pcm_uframes_t frames, snd_pcm_format_t format)
3232 int width = snd_pcm_format_physical_width(format);
3236 SNDMSG("invalid channels %d", channels);
3240 SNDMSG("invalid frames %ld", frames);
3243 while (channels > 0) {
3244 unsigned int step = src_areas->step;
3245 void *src_addr = src_areas->addr;
3246 const snd_pcm_channel_area_t *src_start = src_areas;
3247 void *dst_addr = dst_areas->addr;
3248 const snd_pcm_channel_area_t *dst_start = dst_areas;
3249 int channels1 = channels;
3250 unsigned int chns = 0;
3251 while (dst_areas->step == step) {
3256 if (channels1 == 0 ||
3257 src_areas->step != step ||
3258 src_areas->addr != src_addr ||
3259 dst_areas->addr != dst_addr ||
3260 src_areas->first != src_areas[-1].first + width ||
3261 dst_areas->first != dst_areas[-1].first + width)
3264 if (chns > 1 && chns * width == step) {
3265 if (src_offset != dst_offset ||
3266 src_start->addr != dst_start->addr ||
3267 src_start->first != dst_start->first) {
3268 /* Collapse the areas */
3269 snd_pcm_channel_area_t s, d;
3270 s.addr = src_start->addr;
3271 s.first = src_start->first;
3273 d.addr = dst_start->addr;
3274 d.first = dst_start->first;
3276 snd_pcm_area_copy(&d, dst_offset * chns,
3277 &s, src_offset * chns,
3278 frames * chns, format);
3282 snd_pcm_area_copy(dst_start, dst_offset,
3283 src_start, src_offset,
3285 src_areas = src_start + 1;
3286 dst_areas = dst_start + 1;
3294 * \brief Copy one or more areas
3295 * \param dst_areas destination areas specification (one for each channel)
3296 * \param dst_offset offset in frames inside destination area
3297 * \param dst_size size in frames of the destination buffer
3298 * \param src_areas source areas specification (one for each channel)
3299 * \param src_offset offset in frames inside source area
3300 * \param dst_size size in frames of the source buffer
3301 * \param channels channels count
3302 * \param frames frames to copy
3303 * \param format PCM sample format
3304 * \return 0 on success otherwise a negative error code
3306 int snd_pcm_areas_copy_wrap(const snd_pcm_channel_area_t *dst_channels,
3307 snd_pcm_uframes_t dst_offset,
3308 const snd_pcm_uframes_t dst_size,
3309 const snd_pcm_channel_area_t *src_channels,
3310 snd_pcm_uframes_t src_offset,
3311 const snd_pcm_uframes_t src_size,
3312 const unsigned int channels,
3313 snd_pcm_uframes_t frames,
3314 const snd_pcm_format_t format)
3316 while (frames > 0) {
3318 snd_pcm_uframes_t xfer = frames;
3319 /* do not write above the destination buffer */
3320 if ((dst_offset + xfer) > dst_size)
3321 xfer = dst_size - dst_offset;
3322 /* do not read from above the source buffer */
3323 if ((src_offset + xfer) > src_size)
3324 xfer = src_size - src_offset;
3325 err = snd_pcm_areas_copy(dst_channels, dst_offset, src_channels,
3326 src_offset, channels, xfer, format);
3331 if (dst_offset >= dst_size)
3334 if (src_offset >= src_size)
3342 static void dump_one_param(snd_pcm_hw_params_t *params, unsigned int k, snd_output_t *out)
3344 snd_output_printf(out, "%s: ", snd_pcm_hw_param_name(k));
3345 snd_pcm_hw_param_dump(params, k, out);
3346 snd_output_putc(out, '\n');
3350 * \brief Dump a PCM hardware configuration space
3351 * \param params Configuration space
3352 * \param out Output handle
3353 * \return 0 on success otherwise a negative error code
3355 int snd_pcm_hw_params_dump(snd_pcm_hw_params_t *params, snd_output_t *out)
3358 for (k = SND_PCM_HW_PARAM_FIRST_MASK; k <= SND_PCM_HW_PARAM_LAST_MASK; k++)
3359 dump_one_param(params, k, out);
3360 for (k = SND_PCM_HW_PARAM_FIRST_INTERVAL; k <= SND_PCM_HW_PARAM_LAST_INTERVAL; k++)
3361 dump_one_param(params, k, out);
3366 * \brief Check if hardware supports sample-resolution mmap for given configuration
3367 * \param params Configuration space
3368 * \retval 0 Hardware doesn't support sample-resolution mmap
3369 * \retval 1 Hardware supports sample-resolution mmap
3371 * This function should only be called when the configuration space
3372 * contains a single configuration. Call #snd_pcm_hw_params to choose
3373 * a single configuration from the configuration space.
3375 int snd_pcm_hw_params_can_mmap_sample_resolution(const snd_pcm_hw_params_t *params)
3378 if (CHECK_SANITY(params->info == ~0U)) {
3379 SNDMSG("invalid PCM info field");
3380 return 0; /* FIXME: should be a negative error? */
3382 return !!(params->info & SNDRV_PCM_INFO_MMAP_VALID);
3386 * \brief Check if hardware does double buffering for start/stop for given configuration
3387 * \param params Configuration space
3388 * \retval 0 Hardware doesn't do double buffering for start/stop
3389 * \retval 1 Hardware does double buffering for start/stop
3391 * This function should only be called when the configuration space
3392 * contains a single configuration. Call #snd_pcm_hw_params to choose
3393 * a single configuration from the configuration space.
3395 int snd_pcm_hw_params_is_double(const snd_pcm_hw_params_t *params)
3398 if (CHECK_SANITY(params->info == ~0U)) {
3399 SNDMSG("invalid PCM info field");
3400 return 0; /* FIXME: should be a negative error? */
3402 return !!(params->info & SNDRV_PCM_INFO_DOUBLE);
3406 * \brief Check if hardware does double buffering for data transfers for given configuration
3407 * \param params Configuration space
3408 * \retval 0 Hardware doesn't do double buffering for data transfers
3409 * \retval 1 Hardware does double buffering for data transfers
3411 * This function should only be called when the configuration space
3412 * contains a single configuration. Call #snd_pcm_hw_params to choose
3413 * a single configuration from the configuration space.
3415 int snd_pcm_hw_params_is_batch(const snd_pcm_hw_params_t *params)
3418 if (CHECK_SANITY(params->info == ~0U)) {
3419 SNDMSG("invalid PCM info field");
3420 return 0; /* FIXME: should be a negative error? */
3422 return !!(params->info & SNDRV_PCM_INFO_BATCH);
3426 * \brief Check if hardware does block transfers for samples for given configuration
3427 * \param params Configuration space
3428 * \retval 0 Hardware doesn't block transfers
3429 * \retval 1 Hardware does block transfers
3431 * This function should only be called when the configuration space
3432 * contains a single configuration. Call #snd_pcm_hw_params to choose
3433 * a single configuration from the configuration space.
3435 int snd_pcm_hw_params_is_block_transfer(const snd_pcm_hw_params_t *params)
3438 if (CHECK_SANITY(params->info == ~0U)) {
3439 SNDMSG("invalid PCM info field");
3440 return 0; /* FIXME: should be a negative error? */
3442 return !!(params->info & SNDRV_PCM_INFO_BLOCK_TRANSFER);
3446 * \brief Check if timestamps are monotonic for given configuration
3447 * \param params Configuration space
3448 * \retval 0 Device doesn't do monotomic timestamps
3449 * \retval 1 Device does monotonic timestamps
3451 * This function should only be called when the configuration space
3452 * contains a single configuration. Call #snd_pcm_hw_params to choose
3453 * a single configuration from the configuration space.
3455 int snd_pcm_hw_params_is_monotonic(const snd_pcm_hw_params_t *params)
3458 if (CHECK_SANITY(params->info == ~0U)) {
3459 SNDMSG("invalid PCM info field");
3460 return 0; /* FIXME: should be a negative error? */
3462 return !!(params->info & SND_PCM_INFO_MONOTONIC);
3466 * \brief Check if hardware supports overrange detection
3467 * \param params Configuration space
3468 * \retval 0 Hardware doesn't support overrange detection
3469 * \retval 1 Hardware supports overrange detection
3471 * This function should only be called when the configuration space
3472 * contains a single configuration. Call #snd_pcm_hw_params to choose
3473 * a single configuration from the configuration space.
3475 int snd_pcm_hw_params_can_overrange(const snd_pcm_hw_params_t *params)
3478 if (CHECK_SANITY(params->info == ~0U)) {
3479 SNDMSG("invalid PCM info field");
3480 return 0; /* FIXME: should be a negative error? */
3482 return !!(params->info & SNDRV_PCM_INFO_OVERRANGE);
3486 * \brief Check if hardware supports pause
3487 * \param params Configuration space
3488 * \retval 0 Hardware doesn't support pause
3489 * \retval 1 Hardware supports pause
3491 * This function should only be called when the configuration space
3492 * contains a single configuration. Call #snd_pcm_hw_params to choose
3493 * a single configuration from the configuration space.
3495 int snd_pcm_hw_params_can_pause(const snd_pcm_hw_params_t *params)
3498 if (CHECK_SANITY(params->info == ~0U)) {
3499 SNDMSG("invalid PCM info field");
3500 return 0; /* FIXME: should be a negative error? */
3502 return !!(params->info & SNDRV_PCM_INFO_PAUSE);
3506 * \brief Check if hardware supports resume
3507 * \param params Configuration space
3508 * \retval 0 Hardware doesn't support resume
3509 * \retval 1 Hardware supports resume
3511 * This function should only be called when the configuration space
3512 * contains a single configuration. Call #snd_pcm_hw_params to choose
3513 * a single configuration from the configuration space.
3515 int snd_pcm_hw_params_can_resume(const snd_pcm_hw_params_t *params)
3518 if (CHECK_SANITY(params->info == ~0U)) {
3519 SNDMSG("invalid PCM info field");
3520 return 0; /* FIXME: should be a negative error? */
3522 return !!(params->info & SNDRV_PCM_INFO_RESUME);
3526 * \brief Check if hardware does half-duplex only
3527 * \param params Configuration space
3528 * \retval 0 Hardware doesn't do half-duplex
3529 * \retval 1 Hardware does half-duplex
3531 * This function should only be called when the configuration space
3532 * contains a single configuration. Call #snd_pcm_hw_params to choose
3533 * a single configuration from the configuration space.
3535 int snd_pcm_hw_params_is_half_duplex(const snd_pcm_hw_params_t *params)
3538 if (CHECK_SANITY(params->info == ~0U)) {
3539 SNDMSG("invalid PCM info field");
3540 return 0; /* FIXME: should be a negative error? */
3542 return !!(params->info & SNDRV_PCM_INFO_HALF_DUPLEX);
3546 * \brief Check if hardware does joint-duplex (playback and capture are somewhat correlated)
3547 * \param params Configuration space
3548 * \retval 0 Hardware doesn't do joint-duplex
3549 * \retval 1 Hardware does joint-duplex
3551 * This function should only be called when the configuration space
3552 * contains a single configuration. Call #snd_pcm_hw_params to choose
3553 * a single configuration from the configuration space.
3555 int snd_pcm_hw_params_is_joint_duplex(const snd_pcm_hw_params_t *params)
3558 if (CHECK_SANITY(params->info == ~0U)) {
3559 SNDMSG("invalid PCM info field");
3560 return 0; /* FIXME: should be a negative error? */
3562 return !!(params->info & SNDRV_PCM_INFO_JOINT_DUPLEX);
3566 * \brief Check if hardware supports synchronized start with sample resolution
3567 * \param params Configuration space
3568 * \retval 0 Hardware doesn't support synchronized start
3569 * \retval 1 Hardware supports synchronized start
3571 * This function should only be called when the configuration space
3572 * contains a single configuration. Call #snd_pcm_hw_params to choose
3573 * a single configuration from the configuration space.
3575 int snd_pcm_hw_params_can_sync_start(const snd_pcm_hw_params_t *params)
3578 if (CHECK_SANITY(params->info == ~0U)) {
3579 SNDMSG("invalid PCM info field");
3580 return 0; /* FIXME: should be a negative error? */
3582 return !!(params->info & SNDRV_PCM_INFO_SYNC_START);
3586 * \brief Check if hardware can disable period wakeups
3587 * \param params Configuration space
3588 * \retval 0 Hardware cannot disable period wakeups
3589 * \retval 1 Hardware can disable period wakeups
3591 int snd_pcm_hw_params_can_disable_period_wakeup(const snd_pcm_hw_params_t *params)
3594 if (CHECK_SANITY(params->info == ~0U)) {
3595 SNDMSG("invalid PCM info field");
3596 return 0; /* FIXME: should be a negative error? */
3598 return !!(params->info & SNDRV_PCM_INFO_NO_PERIOD_WAKEUP);
3602 * \brief Check if hardware supports audio wallclock timestamps
3603 * \param params Configuration space
3604 * \retval 0 Hardware doesn't support audio wallclock timestamps
3605 * \retval 1 Hardware supports audio wallclock timestamps
3607 * This function should only be called when the configuration space
3608 * contains a single configuration. Call #snd_pcm_hw_params to choose
3609 * a single configuration from the configuration space.
3611 int snd_pcm_hw_params_supports_audio_wallclock_ts(const snd_pcm_hw_params_t *params)
3614 return snd_pcm_hw_params_supports_audio_ts_type(params,
3615 SNDRV_PCM_AUDIO_TSTAMP_TYPE_COMPAT);
3619 * \brief Check if hardware supports type of audio timestamps
3620 * \param params Configuration space
3621 * \param type Audio timestamp type
3622 * \retval 0 Hardware doesn't support type of audio timestamps
3623 * \retval 1 Hardware supports type of audio timestamps
3625 * This function should only be called when the configuration space
3626 * contains a single configuration. Call #snd_pcm_hw_params to choose
3627 * a single configuration from the configuration space.
3629 int snd_pcm_hw_params_supports_audio_ts_type(const snd_pcm_hw_params_t *params, int type)
3632 if (CHECK_SANITY(params->info == ~0U)) {
3633 SNDMSG("invalid PCM info field");
3634 return 0; /* FIXME: should be a negative error? */
3637 case SNDRV_PCM_AUDIO_TSTAMP_TYPE_COMPAT:
3638 return !!(params->info & SNDRV_PCM_INFO_HAS_WALL_CLOCK); /* deprecated */
3639 case SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT:
3640 return 1; /* always supported, based on hw_ptr */
3641 case SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK:
3642 return !!(params->info & SNDRV_PCM_INFO_HAS_LINK_ATIME);
3643 case SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_ABSOLUTE:
3644 return !!(params->info & SNDRV_PCM_INFO_HAS_LINK_ABSOLUTE_ATIME);
3645 case SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_ESTIMATED:
3646 return !!(params->info & SNDRV_PCM_INFO_HAS_LINK_ESTIMATED_ATIME);
3647 case SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_SYNCHRONIZED:
3648 return !!(params->info & SNDRV_PCM_INFO_HAS_LINK_SYNCHRONIZED_ATIME);
3655 * \brief Get rate exact info from a configuration space
3656 * \param params Configuration space
3657 * \param rate_num Pointer to returned rate numerator
3658 * \param rate_den Pointer to returned rate denominator
3659 * \return 0 otherwise a negative error code if the info is not available
3661 * This function should only be called when the configuration space
3662 * contains a single configuration. Call #snd_pcm_hw_params to choose
3663 * a single configuration from the configuration space.
3665 int snd_pcm_hw_params_get_rate_numden(const snd_pcm_hw_params_t *params,
3666 unsigned int *rate_num, unsigned int *rate_den)
3669 if (CHECK_SANITY(params->rate_den == 0)) {
3670 SNDMSG("invalid rate_den value");
3673 *rate_num = params->rate_num;
3674 *rate_den = params->rate_den;
3679 * \brief Get sample resolution info from a configuration space
3680 * \param params Configuration space
3681 * \return signification bits in sample otherwise a negative error code if the info is not available
3683 * This function should only be called when the configuration space
3684 * contains a single configuration. Call #snd_pcm_hw_params to choose
3685 * a single configuration from the configuration space.
3687 int snd_pcm_hw_params_get_sbits(const snd_pcm_hw_params_t *params)
3690 if (CHECK_SANITY(params->msbits == 0)) {
3691 SNDMSG("invalid msbits value");
3694 return params->msbits;
3698 * \brief Get hardware FIFO size info from a configuration space
3699 * \param params Configuration space
3700 * \return FIFO size in frames otherwise a negative error code if the info is not available
3702 * This function should only be called when the configuration space
3703 * contains a single configuration. Call #snd_pcm_hw_params to choose
3704 * a single configuration from the configuration space.
3706 int snd_pcm_hw_params_get_fifo_size(const snd_pcm_hw_params_t *params)
3709 if (CHECK_SANITY(params->info == ~0U)) {
3710 SNDMSG("invalid PCM info field");
3713 return params->fifo_size;
3717 * \brief Fill params with a full configuration space for a PCM
3718 * \param pcm PCM handle
3719 * \param params Configuration space
3721 * The configuration space will be filled with all possible ranges
3722 * for the PCM device.
3724 int snd_pcm_hw_params_any(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
3726 _snd_pcm_hw_params_any(params);
3727 return snd_pcm_hw_refine(pcm, params);
3731 * \brief get size of #snd_pcm_access_mask_t
3732 * \return size in bytes
3734 size_t snd_pcm_access_mask_sizeof()
3736 return sizeof(snd_pcm_access_mask_t);
3740 * \brief allocate an empty #snd_pcm_access_mask_t using standard malloc
3741 * \param ptr returned pointer
3742 * \return 0 on success otherwise negative error code
3744 int snd_pcm_access_mask_malloc(snd_pcm_access_mask_t **ptr)
3747 *ptr = calloc(1, sizeof(snd_pcm_access_mask_t));
3754 * \brief frees a previously allocated #snd_pcm_access_mask_t
3755 * \param obj pointer to object to free
3757 void snd_pcm_access_mask_free(snd_pcm_access_mask_t *obj)
3763 * \brief copy one #snd_pcm_access_mask_t to another
3764 * \param dst pointer to destination
3765 * \param src pointer to source
3767 void snd_pcm_access_mask_copy(snd_pcm_access_mask_t *dst, const snd_pcm_access_mask_t *src)
3774 * \brief reset all bits in a #snd_pcm_access_mask_t
3775 * \param mask pointer to mask
3777 void snd_pcm_access_mask_none(snd_pcm_access_mask_t *mask)
3779 snd_mask_none((snd_mask_t *) mask);
3783 * \brief set all bits in a #snd_pcm_access_mask_t
3784 * \param mask pointer to mask
3786 void snd_pcm_access_mask_any(snd_pcm_access_mask_t *mask)
3788 snd_mask_any((snd_mask_t *) mask);
3792 * \brief test the presence of an access type in a #snd_pcm_access_mask_t
3793 * \param mask pointer to mask
3794 * \param val access type
3796 int snd_pcm_access_mask_test(const snd_pcm_access_mask_t *mask, snd_pcm_access_t val)
3798 return snd_mask_test((const snd_mask_t *) mask, (unsigned long) val);
3802 * \brief test, if given a #snd_pcm_access_mask_t is empty
3803 * \param mask pointer to mask
3804 * \retval 0 not empty
3807 int snd_pcm_access_mask_empty(const snd_pcm_access_mask_t *mask)
3809 return snd_mask_empty((const snd_mask_t *) mask);
3813 * \brief make an access type present in a #snd_pcm_access_mask_t
3814 * \param mask pointer to mask
3815 * \param val access type
3817 void snd_pcm_access_mask_set(snd_pcm_access_mask_t *mask, snd_pcm_access_t val)
3819 snd_mask_set((snd_mask_t *) mask, (unsigned long) val);
3823 * \brief make an access type missing from a #snd_pcm_access_mask_t
3824 * \param mask pointer to mask
3825 * \param val access type
3827 void snd_pcm_access_mask_reset(snd_pcm_access_mask_t *mask, snd_pcm_access_t val)
3829 snd_mask_reset((snd_mask_t *) mask, (unsigned long) val);
3833 * \brief get size of #snd_pcm_format_mask_t
3834 * \return size in bytes
3836 size_t snd_pcm_format_mask_sizeof()
3838 return sizeof(snd_pcm_format_mask_t);
3842 * \brief allocate an empty #snd_pcm_format_mask_t using standard malloc
3843 * \param ptr returned pointer
3844 * \return 0 on success otherwise negative error code
3846 int snd_pcm_format_mask_malloc(snd_pcm_format_mask_t **ptr)
3849 *ptr = calloc(1, sizeof(snd_pcm_format_mask_t));
3856 * \brief frees a previously allocated #snd_pcm_format_mask_t
3857 * \param obj pointer to object to free
3859 void snd_pcm_format_mask_free(snd_pcm_format_mask_t *obj)
3865 * \brief copy one #snd_pcm_format_mask_t to another
3866 * \param dst pointer to destination
3867 * \param src pointer to source
3869 void snd_pcm_format_mask_copy(snd_pcm_format_mask_t *dst, const snd_pcm_format_mask_t *src)
3876 * \brief reset all bits in a #snd_pcm_format_mask_t
3877 * \param mask pointer to mask
3879 void snd_pcm_format_mask_none(snd_pcm_format_mask_t *mask)
3881 snd_mask_none((snd_mask_t *) mask);
3885 * \brief set all bits in a #snd_pcm_format_mask_t
3886 * \param mask pointer to mask
3888 void snd_pcm_format_mask_any(snd_pcm_format_mask_t *mask)
3890 snd_mask_any((snd_mask_t *) mask);
3894 * \brief test the presence of a format in a #snd_pcm_format_mask_t
3895 * \param mask pointer to mask
3898 int snd_pcm_format_mask_test(const snd_pcm_format_mask_t *mask, snd_pcm_format_t val)
3900 return snd_mask_test((const snd_mask_t *) mask, (unsigned long) val);
3904 * \brief test, if given a #snd_pcm_format_mask_t is empty
3905 * \param mask pointer to mask
3906 * \retval 0 not empty
3909 int snd_pcm_format_mask_empty(const snd_pcm_format_mask_t *mask)
3911 return snd_mask_empty((const snd_mask_t *) mask);
3915 * \brief make a format present in a #snd_pcm_format_mask_t
3916 * \param mask pointer to mask
3919 void snd_pcm_format_mask_set(snd_pcm_format_mask_t *mask, snd_pcm_format_t val)
3921 snd_mask_set((snd_mask_t *) mask, (unsigned long) val);
3925 * \brief make a format missing from a #snd_pcm_format_mask_t
3926 * \param mask pointer to mask
3929 void snd_pcm_format_mask_reset(snd_pcm_format_mask_t *mask, snd_pcm_format_t val)
3931 snd_mask_reset((snd_mask_t *) mask, (unsigned long) val);
3936 * \brief get size of #snd_pcm_subformat_mask_t
3937 * \return size in bytes
3939 size_t snd_pcm_subformat_mask_sizeof()
3941 return sizeof(snd_pcm_subformat_mask_t);
3945 * \brief allocate an empty #snd_pcm_subformat_mask_t using standard malloc
3946 * \param ptr returned pointer
3947 * \return 0 on success otherwise negative error code
3949 int snd_pcm_subformat_mask_malloc(snd_pcm_subformat_mask_t **ptr)
3952 *ptr = calloc(1, sizeof(snd_pcm_subformat_mask_t));
3959 * \brief frees a previously allocated #snd_pcm_subformat_mask_t
3960 * \param obj pointer to object to free
3962 void snd_pcm_subformat_mask_free(snd_pcm_subformat_mask_t *obj)
3968 * \brief copy one #snd_pcm_subformat_mask_t to another
3969 * \param dst pointer to destination
3970 * \param src pointer to source
3972 void snd_pcm_subformat_mask_copy(snd_pcm_subformat_mask_t *dst, const snd_pcm_subformat_mask_t *src)
3979 * \brief reset all bits in a #snd_pcm_subformat_mask_t
3980 * \param mask pointer to mask
3982 void snd_pcm_subformat_mask_none(snd_pcm_subformat_mask_t *mask)
3984 snd_mask_none((snd_mask_t *) mask);
3988 * \brief set all bits in a #snd_pcm_subformat_mask_t
3989 * \param mask pointer to mask
3991 void snd_pcm_subformat_mask_any(snd_pcm_subformat_mask_t *mask)
3993 snd_mask_any((snd_mask_t *) mask);
3997 * \brief test the presence of a subformat in a #snd_pcm_subformat_mask_t
3998 * \param mask pointer to mask
3999 * \param val subformat
4001 int snd_pcm_subformat_mask_test(const snd_pcm_subformat_mask_t *mask, snd_pcm_subformat_t val)
4003 return snd_mask_test((const snd_mask_t *) mask, (unsigned long) val);
4007 * \brief test, if given a #snd_pcm_subformat_mask_t is empty
4008 * \param mask pointer to mask
4009 * \retval 0 not empty
4012 int snd_pcm_subformat_mask_empty(const snd_pcm_subformat_mask_t *mask)
4014 return snd_mask_empty((const snd_mask_t *) mask);
4018 * \brief make a subformat present in a #snd_pcm_subformat_mask_t
4019 * \param mask pointer to mask
4020 * \param val subformat
4022 void snd_pcm_subformat_mask_set(snd_pcm_subformat_mask_t *mask, snd_pcm_subformat_t val)
4024 snd_mask_set((snd_mask_t *) mask, (unsigned long) val);
4028 * \brief make a subformat missing from a #snd_pcm_subformat_mask_t
4029 * \param mask pointer to mask
4030 * \param val subformat
4032 void snd_pcm_subformat_mask_reset(snd_pcm_subformat_mask_t *mask, snd_pcm_subformat_t val)
4034 snd_mask_reset((snd_mask_t *) mask, (unsigned long) val);
4039 * \brief get size of #snd_pcm_hw_params_t
4040 * \return size in bytes
4042 size_t snd_pcm_hw_params_sizeof()
4044 return sizeof(snd_pcm_hw_params_t);
4048 * \brief allocate an invalid #snd_pcm_hw_params_t using standard malloc
4049 * \param ptr returned pointer
4050 * \return 0 on success otherwise negative error code
4052 int snd_pcm_hw_params_malloc(snd_pcm_hw_params_t **ptr)
4055 *ptr = calloc(1, sizeof(snd_pcm_hw_params_t));
4062 * \brief frees a previously allocated #snd_pcm_hw_params_t
4063 * \param obj pointer to object to free
4065 void snd_pcm_hw_params_free(snd_pcm_hw_params_t *obj)
4071 * \brief copy one #snd_pcm_hw_params_t to another
4072 * \param dst pointer to destination
4073 * \param src pointer to source
4075 void snd_pcm_hw_params_copy(snd_pcm_hw_params_t *dst, const snd_pcm_hw_params_t *src)
4083 * \brief Extract access type from a configuration space
4084 * \param params Configuration space
4085 * \param access Returned value
4086 * \return access type otherwise a negative error code if the configuration space does not contain a single value
4089 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_access)(const snd_pcm_hw_params_t *params, snd_pcm_access_t *access)
4091 int snd_pcm_hw_params_get_access(const snd_pcm_hw_params_t *params, snd_pcm_access_t *access)
4095 int err = snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_ACCESS, &_val, NULL);
4102 * \brief Verify if an access type is available inside a configuration space for a PCM
4103 * \param pcm PCM handle
4104 * \param params Configuration space
4105 * \param access access type
4106 * \return 0 if available a negative error code otherwise
4108 int snd_pcm_hw_params_test_access(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t access)
4110 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_ACCESS, access, 0);
4114 * \brief Restrict a configuration space to contain only one access type
4115 * \param pcm PCM handle
4116 * \param params Configuration space
4117 * \param access access type
4118 * \return 0 otherwise a negative error code if configuration space would become empty
4120 int snd_pcm_hw_params_set_access(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t access)
4122 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_ACCESS, access, 0);
4126 * \brief Restrict a configuration space to contain only its first access type
4127 * \param pcm PCM handle
4128 * \param params Configuration space
4129 * \param access Returned first access type
4130 * \return 0 otherwise a negative error code
4133 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_access_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t *access)
4135 int snd_pcm_hw_params_set_access_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t *access)
4138 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_ACCESS, access, NULL);
4142 * \brief Restrict a configuration space to contain only its last access type
4143 * \param pcm PCM handle
4144 * \param params Configuration space
4145 * \param access Returned last access type
4146 * \return 0 otherwise a negative error code
4149 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_access_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t *access)
4151 int snd_pcm_hw_params_set_access_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t *access)
4154 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_ACCESS, access, NULL);
4158 * \brief Restrict a configuration space to contain only a set of access types
4159 * \param pcm PCM handle
4160 * \param params Configuration space
4161 * \param mask Access mask
4162 * \return 0 otherwise a negative error code
4164 int snd_pcm_hw_params_set_access_mask(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_mask_t *mask)
4166 return snd_pcm_hw_param_set_mask(pcm, params, SND_TRY, SND_PCM_HW_PARAM_ACCESS, (snd_mask_t *) mask);
4170 * \brief Get access mask from a configuration space
4171 * \param params Configuration space
4172 * \param mask Returned Access mask
4174 int snd_pcm_hw_params_get_access_mask(snd_pcm_hw_params_t *params, snd_pcm_access_mask_t *mask)
4176 if (params == NULL || mask == NULL)
4178 snd_pcm_access_mask_copy(mask, snd_pcm_hw_param_get_mask(params, SND_PCM_HW_PARAM_ACCESS));
4184 * \brief Extract format from a configuration space
4185 * \param params Configuration space
4186 * \param format returned format
4187 * \return format otherwise a negative error code if the configuration space does not contain a single value
4190 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_format)(const snd_pcm_hw_params_t *params, snd_pcm_format_t *format)
4192 int snd_pcm_hw_params_get_format(const snd_pcm_hw_params_t *params, snd_pcm_format_t *format)
4195 return snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_FORMAT, (unsigned int *)format, NULL);
4199 * \brief Verify if a format is available inside a configuration space for a PCM
4200 * \param pcm PCM handle
4201 * \param params Configuration space
4202 * \param format format
4203 * \return 0 if available a negative error code otherwise
4205 int snd_pcm_hw_params_test_format(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t format)
4207 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_FORMAT, format, 0);
4211 * \brief Restrict a configuration space to contain only one format
4212 * \param pcm PCM handle
4213 * \param params Configuration space
4214 * \param format format
4215 * \return 0 otherwise a negative error code
4217 int snd_pcm_hw_params_set_format(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t format)
4219 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_FORMAT, format, 0);
4223 * \brief Restrict a configuration space to contain only its first format
4224 * \param pcm PCM handle
4225 * \param params Configuration space
4226 * \param format Returned first format
4227 * \return 0 otherwise a negative error code
4230 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_format_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t *format)
4232 int snd_pcm_hw_params_set_format_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t *format)
4235 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_FORMAT, (unsigned int *)format, NULL);
4239 * \brief Restrict a configuration space to contain only its last format
4240 * \param pcm PCM handle
4241 * \param params Configuration space
4242 * \param format Returned last format
4243 * \return 0 otherwise a negative error code
4246 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_format_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t *format)
4248 int snd_pcm_hw_params_set_format_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t *format)
4251 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_FORMAT, (unsigned int *)format, NULL);
4255 * \brief Restrict a configuration space to contain only a set of formats
4256 * \param pcm PCM handle
4257 * \param params Configuration space
4258 * \param mask Format mask
4259 * \return 0 otherwise a negative error code
4261 int snd_pcm_hw_params_set_format_mask(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_mask_t *mask)
4263 return snd_pcm_hw_param_set_mask(pcm, params, SND_TRY, SND_PCM_HW_PARAM_FORMAT, (snd_mask_t *) mask);
4267 * \brief Get format mask from a configuration space
4268 * \param params Configuration space
4269 * \param mask Returned Format mask
4271 void snd_pcm_hw_params_get_format_mask(snd_pcm_hw_params_t *params, snd_pcm_format_mask_t *mask)
4273 snd_pcm_format_mask_copy(mask, snd_pcm_hw_param_get_mask(params, SND_PCM_HW_PARAM_FORMAT));
4278 * \brief Extract subformat from a configuration space
4279 * \param params Configuration space
4280 * \param subformat Returned subformat value
4281 * \return subformat otherwise a negative error code if the configuration space does not contain a single value
4284 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_subformat)(const snd_pcm_hw_params_t *params, snd_pcm_subformat_t *subformat)
4286 int snd_pcm_hw_params_get_subformat(const snd_pcm_hw_params_t *params, snd_pcm_subformat_t *subformat)
4289 return snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_SUBFORMAT, subformat, NULL);
4293 * \brief Verify if a subformat is available inside a configuration space for a PCM
4294 * \param pcm PCM handle
4295 * \param params Configuration space
4296 * \param subformat subformat value
4297 * \return 0 if available a negative error code otherwise
4299 int snd_pcm_hw_params_test_subformat(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t subformat)
4301 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_SUBFORMAT, subformat, 0);
4305 * \brief Restrict a configuration space to contain only one subformat
4306 * \param pcm PCM handle
4307 * \param params Configuration space
4308 * \param subformat subformat value
4309 * \return 0 otherwise a negative error code if configuration space would become empty
4311 int snd_pcm_hw_params_set_subformat(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t subformat)
4313 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_SUBFORMAT, subformat, 0);
4317 * \brief Restrict a configuration space to contain only its first subformat
4318 * \param pcm PCM handle
4319 * \param params Configuration space
4320 * \param subformat Returned subformat
4321 * \return 0 otherwise a negative error code
4324 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_subformat_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t *subformat)
4326 int snd_pcm_hw_params_set_subformat_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t *subformat)
4329 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_SUBFORMAT, subformat, NULL);
4333 * \brief Restrict a configuration space to contain only its last subformat
4334 * \param pcm PCM handle
4335 * \param params Configuration space
4336 * \param subformat Returned subformat
4337 * \return 0 otherwise a negative error code
4340 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_subformat_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t *subformat)
4342 int snd_pcm_hw_params_set_subformat_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t *subformat)
4345 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_SUBFORMAT, subformat, NULL);
4349 * \brief Restrict a configuration space to contain only a set of subformats
4350 * \param pcm PCM handle
4351 * \param params Configuration space
4352 * \param mask Subformat mask
4353 * \return 0 otherwise a negative error code
4355 int snd_pcm_hw_params_set_subformat_mask(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_mask_t *mask)
4357 return snd_pcm_hw_param_set_mask(pcm, params, SND_TRY, SND_PCM_HW_PARAM_SUBFORMAT, (snd_mask_t *) mask);
4361 * \brief Get subformat mask from a configuration space
4362 * \param params Configuration space
4363 * \param mask Returned Subformat mask
4365 void snd_pcm_hw_params_get_subformat_mask(snd_pcm_hw_params_t *params, snd_pcm_subformat_mask_t *mask)
4367 snd_pcm_subformat_mask_copy(mask, snd_pcm_hw_param_get_mask(params, SND_PCM_HW_PARAM_SUBFORMAT));
4372 * \brief Extract channels from a configuration space
4373 * \param params Configuration space
4374 * \param val Returned channels count
4375 * \return 0 otherwise a negative error code if the configuration space does not contain a single value
4378 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_channels)(const snd_pcm_hw_params_t *params, unsigned int *val)
4380 int snd_pcm_hw_params_get_channels(const snd_pcm_hw_params_t *params, unsigned int *val)
4383 return snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
4387 * \brief Extract minimum channels count from a configuration space
4388 * \param params Configuration space
4389 * \param val minimum channels count
4390 * \return 0 otherwise a negative error code
4393 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_channels_min)(const snd_pcm_hw_params_t *params, unsigned int *val)
4395 int snd_pcm_hw_params_get_channels_min(const snd_pcm_hw_params_t *params, unsigned int *val)
4398 return snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
4402 * \brief Extract maximum channels count from a configuration space
4403 * \param params Configuration space
4404 * \param val maximum channels count
4405 * \return 0 otherwise a negative error code
4408 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_channels_max)(const snd_pcm_hw_params_t *params, unsigned int *val)
4410 int snd_pcm_hw_params_get_channels_max(const snd_pcm_hw_params_t *params, unsigned int *val)
4413 return snd_pcm_hw_param_get_max(params, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
4417 * \brief Verify if a channels count is available inside a configuration space for a PCM
4418 * \param pcm PCM handle
4419 * \param params Configuration space
4420 * \param val channels count
4421 * \return 0 if available a negative error code otherwise
4423 int snd_pcm_hw_params_test_channels(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val)
4425 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_CHANNELS, val, 0);
4429 * \brief Restrict a configuration space to contain only one channels count
4430 * \param pcm PCM handle
4431 * \param params Configuration space
4432 * \param val channels count
4433 * \return 0 otherwise a negative error code if configuration space would become empty
4435 int snd_pcm_hw_params_set_channels(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val)
4437 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_CHANNELS, val, 0);
4441 * \brief Restrict a configuration space with a minimum channels count
4442 * \param pcm PCM handle
4443 * \param params Configuration space
4444 * \param val minimum channels count (on return filled with actual minimum)
4445 * \return 0 otherwise a negative error code if configuration space would become empty
4447 int snd_pcm_hw_params_set_channels_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4449 return snd_pcm_hw_param_set_min(pcm, params, SND_TRY, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
4453 * \brief Restrict a configuration space with a maximum channels count
4454 * \param pcm PCM handle
4455 * \param params Configuration space
4456 * \param val maximum channels count (on return filled with actual maximum)
4457 * \return 0 otherwise a negative error code if configuration space would become empty
4459 int snd_pcm_hw_params_set_channels_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4461 return snd_pcm_hw_param_set_max(pcm, params, SND_TRY, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
4465 * \brief Restrict a configuration space to have channels counts in a given range
4466 * \param pcm PCM handle
4467 * \param params Configuration space
4468 * \param min minimum channels count (on return filled with actual minimum)
4469 * \param max maximum channels count (on return filled with actual maximum)
4470 * \return 0 otherwise a negative error code if configuration space would become empty
4472 int snd_pcm_hw_params_set_channels_minmax(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *min, unsigned int *max)
4474 return snd_pcm_hw_param_set_minmax(pcm, params, SND_TRY, SND_PCM_HW_PARAM_CHANNELS, min, NULL, max, NULL);
4478 * \brief Restrict a configuration space to have channels count nearest to a target
4479 * \param pcm PCM handle
4480 * \param params Configuration space
4481 * \param val target channels count, returned chosen channels count
4482 * \return 0 otherwise a negative error code if configuration space is empty
4485 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_channels_near)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4487 int snd_pcm_hw_params_set_channels_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4490 return snd_pcm_hw_param_set_near(pcm, params, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
4494 * \brief Restrict a configuration space to contain only its minimum channels count
4495 * \param pcm PCM handle
4496 * \param params Configuration space
4497 * \param val minimum channels count
4498 * \return 0 otherwise a negative error code
4501 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_channels_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4503 int snd_pcm_hw_params_set_channels_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4506 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
4510 * \brief Restrict a configuration space to contain only its maximum channels count
4511 * \param pcm PCM handle
4512 * \param params Configuration space
4513 * \param val maximum channels count
4514 * \return 0 otherwise a negative error code
4517 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_channels_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4519 int snd_pcm_hw_params_set_channels_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4522 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_CHANNELS, val, NULL);
4527 * \brief Extract rate from a configuration space
4528 * \param params Configuration space
4529 * \param val Returned approximate rate
4530 * \param dir Sub unit direction
4531 * \return 0 otherwise a negative error code if the configuration space does not contain a single value
4533 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
4536 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_rate)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4538 int snd_pcm_hw_params_get_rate(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4541 return snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_RATE, val, dir);
4545 * \brief Extract minimum rate from a configuration space
4546 * \param params Configuration space
4547 * \param val Returned approximate minimum rate
4548 * \param dir Sub unit direction
4549 * \return 0 otherwise a negative error code
4551 * Exact value is <,=,> the returned one following dir (-1,0,1)
4554 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_rate_min)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4556 int snd_pcm_hw_params_get_rate_min(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4559 return snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_RATE, val, dir);
4563 * \brief Extract maximum rate from a configuration space
4564 * \param params Configuration space
4565 * \param val Returned approximate maximum rate
4566 * \param dir Sub unit direction
4567 * \return 0 otherwise a negative error code
4569 * Exact value is <,=,> the returned one following dir (-1,0,1)
4572 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_rate_max)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4574 int snd_pcm_hw_params_get_rate_max(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4577 return snd_pcm_hw_param_get_max(params, SND_PCM_HW_PARAM_RATE, val, dir);
4581 * \brief Verify if a rate is available inside a configuration space for a PCM
4582 * \param pcm PCM handle
4583 * \param params Configuration space
4584 * \param val approximate rate
4585 * \param dir Sub unit direction
4586 * \return 0 if available a negative error code otherwise
4588 * Wanted exact value is <,=,> val following dir (-1,0,1)
4590 int snd_pcm_hw_params_test_rate(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
4592 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_RATE, val, dir);
4596 * \brief Restrict a configuration space to contain only one rate
4597 * \param pcm PCM handle
4598 * \param params Configuration space
4599 * \param val approximate rate
4600 * \param dir Sub unit direction
4601 * \return 0 otherwise a negative error code if configuration space would become empty
4603 * Wanted exact value is <,=,> val following dir (-1,0,1)
4605 int snd_pcm_hw_params_set_rate(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
4607 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_RATE, val, dir);
4611 * \brief Restrict a configuration space with a minimum rate
4612 * \param pcm PCM handle
4613 * \param params Configuration space
4614 * \param val approximate minimum rate (on return filled with actual minimum)
4615 * \param dir Sub unit direction (on return filled with actual direction)
4616 * \return 0 otherwise a negative error code if configuration space would become empty
4618 * Wanted/actual exact minimum is <,=,> val following dir (-1,0,1)
4620 int snd_pcm_hw_params_set_rate_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4622 return snd_pcm_hw_param_set_min(pcm, params, SND_TRY, SND_PCM_HW_PARAM_RATE, val, dir);
4626 * \brief Restrict a configuration space with a maximum rate
4627 * \param pcm PCM handle
4628 * \param params Configuration space
4629 * \param val approximate maximum rate (on return filled with actual maximum)
4630 * \param dir Sub unit direction (on return filled with actual direction)
4631 * \return 0 otherwise a negative error code if configuration space would become empty
4633 * Wanted/actual exact maximum is <,=,> val following dir (-1,0,1)
4635 int snd_pcm_hw_params_set_rate_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4637 return snd_pcm_hw_param_set_max(pcm, params, SND_TRY, SND_PCM_HW_PARAM_RATE, val, dir);
4641 * \brief Restrict a configuration space to have rates in a given range
4642 * \param pcm PCM handle
4643 * \param params Configuration space
4644 * \param min approximate minimum rate (on return filled with actual minimum)
4645 * \param mindir Sub unit direction for minimum (on return filled with actual direction)
4646 * \param max approximate maximum rate (on return filled with actual maximum)
4647 * \param maxdir Sub unit direction for maximum (on return filled with actual direction)
4648 * \return 0 otherwise a negative error code if configuration space would become empty
4650 * Wanted/actual exact min/max is <,=,> val following dir (-1,0,1)
4652 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)
4654 return snd_pcm_hw_param_set_minmax(pcm, params, SND_TRY, SND_PCM_HW_PARAM_RATE, min, mindir, max, maxdir);
4658 * \brief Restrict a configuration space to have rate nearest to a target
4659 * \param pcm PCM handle
4660 * \param params Configuration space
4661 * \param val approximate target rate / returned approximate set rate
4662 * \param dir Sub unit direction
4663 * \return 0 otherwise a negative error code if configuration space is empty
4665 * target/chosen exact value is <,=,> val following dir (-1,0,1)
4668 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_rate_near)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4670 int snd_pcm_hw_params_set_rate_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4673 return snd_pcm_hw_param_set_near(pcm, params, SND_PCM_HW_PARAM_RATE, val, dir);
4677 * \brief Restrict a configuration space to contain only its minimum rate
4678 * \param pcm PCM handle
4679 * \param params Configuration space
4680 * \param val Returned minimum approximate rate
4681 * \param dir Sub unit direction
4682 * \return 0 otherwise a negative error code
4684 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
4687 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_rate_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4689 int snd_pcm_hw_params_set_rate_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4692 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_RATE, val, dir);
4696 * \brief Restrict a configuration space to contain only its maximum rate
4697 * \param pcm PCM handle
4698 * \param params Configuration space
4699 * \param val Returned maximum approximate rate
4700 * \param dir Sub unit direction
4701 * \return 0 otherwise a negative error code
4703 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
4706 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_rate_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4708 int snd_pcm_hw_params_set_rate_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4711 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_RATE, val, dir);
4715 * \brief Restrict a configuration space to contain only real hardware rates
4716 * \param pcm PCM handle
4717 * \param params Configuration space
4718 * \param val 0 = disable, 1 = enable (default) rate resampling
4719 * \return 0 otherwise a negative error code
4721 int snd_pcm_hw_params_set_rate_resample(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val)
4723 assert(pcm && params);
4725 params->flags |= SND_PCM_HW_PARAMS_NORESAMPLE;
4727 params->flags &= ~SND_PCM_HW_PARAMS_NORESAMPLE;
4729 return snd_pcm_hw_refine(pcm, params);
4733 * \brief Extract resample state from a configuration space
4734 * \param pcm PCM handle
4735 * \param params Configuration space
4736 * \param val 0 = disable, 1 = enable rate resampling
4737 * \return 0 otherwise a negative error code
4739 int snd_pcm_hw_params_get_rate_resample(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4741 assert(pcm && params && val);
4742 *val = params->flags & SND_PCM_HW_PARAMS_NORESAMPLE ? 0 : 1;
4747 * \brief Restrict a configuration space to allow the buffer to be accessible from outside
4748 * \param pcm PCM handle
4749 * \param params Configuration space
4750 * \param val 0 = disable, 1 = enable (default) exporting buffer
4751 * \return 0 otherwise a negative error code
4753 int snd_pcm_hw_params_set_export_buffer(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val)
4755 assert(pcm && params);
4757 params->flags |= SND_PCM_HW_PARAMS_EXPORT_BUFFER;
4759 params->flags &= ~SND_PCM_HW_PARAMS_EXPORT_BUFFER;
4761 return snd_pcm_hw_refine(pcm, params);
4765 * \brief Extract buffer accessibility from a configuration space
4766 * \param pcm PCM handle
4767 * \param params Configuration space
4768 * \param val 0 = disable, 1 = enable exporting buffer
4769 * \return 0 otherwise a negative error code
4771 int snd_pcm_hw_params_get_export_buffer(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4773 assert(pcm && params && val);
4774 *val = params->flags & SND_PCM_HW_PARAMS_EXPORT_BUFFER ? 1 : 0;
4779 * \brief Restrict a configuration space to settings without period wakeups
4780 * \param pcm PCM handle
4781 * \param params Configuration space
4782 * \param val 0 = disable, 1 = enable (default) period wakeup
4783 * \return Zero on success, otherwise a negative error code.
4785 * This function must be called only on devices where non-blocking mode is
4788 * To check whether the hardware does support disabling period wakeups, call
4789 * #snd_pcm_hw_params_can_disable_period_wakeup(). If the hardware does not
4790 * support this mode, standard period wakeups will be generated.
4792 * Even with disabled period wakeups, the period size/time/count parameters
4793 * are valid; it is suggested to use #snd_pcm_hw_params_set_period_size_last().
4795 * When period wakeups are disabled, the application must not use any functions
4796 * that could block on this device. The use of poll should be limited to error
4797 * cases. The application needs to use an external event or a timer to
4798 * check the state of the ring buffer and refill it apropriately.
4800 int snd_pcm_hw_params_set_period_wakeup(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val)
4802 assert(pcm && params);
4805 if (!(pcm->mode & SND_PCM_NONBLOCK))
4807 params->flags |= SND_PCM_HW_PARAMS_NO_PERIOD_WAKEUP;
4809 params->flags &= ~SND_PCM_HW_PARAMS_NO_PERIOD_WAKEUP;
4812 return snd_pcm_hw_refine(pcm, params);
4816 * \brief Extract period wakeup flag from a configuration space
4817 * \param pcm PCM handle
4818 * \param params Configuration space
4819 * \param val 0 = disabled, 1 = enabled period wakeups
4820 * \return Zero on success, otherwise a negative error code.
4822 int snd_pcm_hw_params_get_period_wakeup(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
4824 assert(pcm && params && val);
4825 *val = params->flags & SND_PCM_HW_PARAMS_NO_PERIOD_WAKEUP ? 0 : 1;
4830 * \brief Extract period time from a configuration space
4831 * \param params Configuration space
4832 * \param val Returned approximate period duration in us
4833 * \param dir Sub unit direction
4834 * \return 0 otherwise a negative error code if the configuration space does not contain a single value
4836 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
4839 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_period_time)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4841 int snd_pcm_hw_params_get_period_time(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4844 return snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
4848 * \brief Extract minimum period time from a configuration space
4849 * \param params Configuration space
4850 * \param val approximate minimum period duration in us
4851 * \param dir Sub unit direction
4852 * \return 0 otherwise a negative error code
4854 * Exact value is <,=,> the returned one following dir (-1,0,1)
4857 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_period_time_min)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4859 int snd_pcm_hw_params_get_period_time_min(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4862 return snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
4866 * \brief Extract maximum period time from a configuration space
4867 * \param params Configuration space
4868 * \param val approximate maximum period duration in us
4869 * \param dir Sub unit direction
4870 * \return 0 otherwise a negative error code
4872 * Exact value is <,=,> the returned one following dir (-1,0,1)
4875 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_period_time_max)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4877 int snd_pcm_hw_params_get_period_time_max(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4880 return snd_pcm_hw_param_get_max(params, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
4884 * \brief Verify if a period time is available inside a configuration space for a PCM
4885 * \param pcm PCM handle
4886 * \param params Configuration space
4887 * \param val approximate period duration in us
4888 * \param dir Sub unit direction
4889 * \return 0 if available a negative error code otherwise
4891 * Wanted exact value is <,=,> val following dir (-1,0,1)
4893 int snd_pcm_hw_params_test_period_time(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
4895 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
4899 * \brief Restrict a configuration space to contain only one period time
4900 * \param pcm PCM handle
4901 * \param params Configuration space
4902 * \param val approximate period duration in us
4903 * \param dir Sub unit direction
4904 * \return 0 otherwise a negative error code if configuration space would become empty
4906 * Wanted exact value is <,=,> val following dir (-1,0,1)
4908 int snd_pcm_hw_params_set_period_time(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
4910 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
4915 * \brief Restrict a configuration space with a minimum period time
4916 * \param pcm PCM handle
4917 * \param params Configuration space
4918 * \param val approximate minimum period duration in us (on return filled with actual minimum)
4919 * \param dir Sub unit direction (on return filled with actual direction)
4920 * \return 0 otherwise a negative error code if configuration space would become empty
4922 * Wanted/actual exact minimum is <,=,> val following dir (-1,0,1)
4924 int snd_pcm_hw_params_set_period_time_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4926 return snd_pcm_hw_param_set_min(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
4930 * \brief Restrict a configuration space with a maximum period time
4931 * \param pcm PCM handle
4932 * \param params Configuration space
4933 * \param val approximate maximum period duration in us (on return filled with actual maximum)
4934 * \param dir Sub unit direction (on return filled with actual direction)
4935 * \return 0 otherwise a negative error code if configuration space would become empty
4937 * Wanted/actual exact maximum is <,=,> val following dir (-1,0,1)
4939 int snd_pcm_hw_params_set_period_time_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4941 return snd_pcm_hw_param_set_max(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
4945 * \brief Restrict a configuration space to have period times in a given range
4946 * \param pcm PCM handle
4947 * \param params Configuration space
4948 * \param min approximate minimum period duration in us (on return filled with actual minimum)
4949 * \param mindir Sub unit direction for minimum (on return filled with actual direction)
4950 * \param max approximate maximum period duration in us (on return filled with actual maximum)
4951 * \param maxdir Sub unit direction for maximum (on return filled with actual direction)
4952 * \return 0 otherwise a negative error code if configuration space would become empty
4954 * Wanted/actual exact min/max is <,=,> val following dir (-1,0,1)
4956 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)
4958 return snd_pcm_hw_param_set_minmax(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_TIME, min, mindir, max, maxdir);
4962 * \brief Restrict a configuration space to have period time nearest to a target
4963 * \param pcm PCM handle
4964 * \param params Configuration space
4965 * \param val approximate target period duration in us / returned chosen approximate target period duration
4966 * \param dir Sub unit direction
4967 * \return 0 otherwise a negative error code if configuration space is empty
4969 * target/chosen exact value is <,=,> val following dir (-1,0,1)
4972 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_period_time_near)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4974 int snd_pcm_hw_params_set_period_time_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4977 return snd_pcm_hw_param_set_near(pcm, params, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
4981 * \brief Restrict a configuration space to contain only its minimum period time
4982 * \param pcm PCM handle
4983 * \param params Configuration space
4984 * \param val Returned approximate period duration in us
4985 * \param dir Sub unit direction
4986 * \return 0 otherwise a negative error code
4988 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
4991 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_period_time_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4993 int snd_pcm_hw_params_set_period_time_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
4996 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
5000 * \brief Restrict a configuration space to contain only its maximum period time
5001 * \param pcm PCM handle
5002 * \param params Configuration space
5003 * \param val Returned maximum approximate period time
5004 * \param dir Sub unit direction
5005 * \return approximate period duration in us
5008 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_period_time_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5010 int snd_pcm_hw_params_set_period_time_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5013 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_PERIOD_TIME, val, dir);
5018 * \brief Extract period size from a configuration space
5019 * \param params Configuration space
5020 * \param val Returned approximate period size in frames
5021 * \param dir Sub unit direction
5022 * \return 0 otherwise a negative error code if the configuration space does not contain a single value
5024 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5027 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_period_size)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
5029 int snd_pcm_hw_params_get_period_size(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
5033 int err = snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
5040 * \brief Extract minimum period size from a configuration space
5041 * \param params Configuration space
5042 * \param val approximate minimum period size in frames
5043 * \param dir Sub unit direction
5044 * \return 0 otherwise a negative error code
5046 * Exact value is <,=,> the returned one following dir (-1,0,1)
5049 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_period_size_min)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
5051 int snd_pcm_hw_params_get_period_size_min(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
5054 unsigned int _val = *val;
5055 int err = snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
5062 * \brief Extract maximum period size from a configuration space
5063 * \param params Configuration space
5064 * \param val approximate minimum period size in frames
5065 * \param dir Sub unit direction
5066 * \return 0 otherwise a negative error code
5068 * Exact value is <,=,> the returned one following dir (-1,0,1)
5071 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_period_size_max)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
5073 int snd_pcm_hw_params_get_period_size_max(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
5076 unsigned int _val = *val;
5077 int err = snd_pcm_hw_param_get_max(params, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
5084 * \brief Verify if a period size is available inside a configuration space for a PCM
5085 * \param pcm PCM handle
5086 * \param params Configuration space
5087 * \param val approximate period size in frames
5088 * \param dir Sub unit direction
5089 * \return 0 if available a negative error code otherwise
5091 * Wanted exact value is <,=,> val following dir (-1,0,1)
5093 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)
5095 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_PERIOD_SIZE, val, dir);
5099 * \brief Restrict a configuration space to contain only one period size
5100 * \param pcm PCM handle
5101 * \param params Configuration space
5102 * \param val approximate period size in frames
5103 * \param dir Sub unit direction
5104 * \return 0 otherwise a negative error code if configuration space would become empty
5106 * Wanted exact value is <,=,> val following dir (-1,0,1)
5108 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)
5110 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_SIZE, val, dir);
5114 * \brief Restrict a configuration space with a minimum period size
5115 * \param pcm PCM handle
5116 * \param params Configuration space
5117 * \param val approximate minimum period size in frames (on return filled with actual minimum)
5118 * \param dir Sub unit direction (on return filled with actual direction)
5119 * \return 0 otherwise a negative error code if configuration space would become empty
5121 * Wanted/actual exact minimum is <,=,> val following dir (-1,0,1)
5123 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)
5125 unsigned int _val = *val;
5126 int err = snd_pcm_hw_param_set_min(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
5133 * \brief Restrict a configuration space with a maximum period size
5134 * \param pcm PCM handle
5135 * \param params Configuration space
5136 * \param val approximate maximum period size in frames (on return filled with actual maximum)
5137 * \param dir Sub unit direction (on return filled with actual direction)
5138 * \return 0 otherwise a negative error code if configuration space would become empty
5140 * Wanted/actual exact minimum is <,=,> val following dir (-1,0,1)
5142 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)
5144 unsigned int _val = *val;
5145 int err = snd_pcm_hw_param_set_max(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
5152 * \brief Restrict a configuration space to have period sizes in a given range
5153 * \param pcm PCM handle
5154 * \param params Configuration space
5155 * \param min approximate minimum period size in frames (on return filled with actual minimum)
5156 * \param mindir Sub unit direction for minimum (on return filled with actual direction)
5157 * \param max approximate maximum period size in frames (on return filled with actual maximum)
5158 * \param maxdir Sub unit direction for maximum (on return filled with actual direction)
5159 * \return 0 otherwise a negative error code if configuration space would become empty
5161 * Wanted/actual exact min/max is <,=,> val following dir (-1,0,1)
5163 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)
5165 unsigned int _min = *min;
5166 unsigned int _max = *max;
5167 int err = snd_pcm_hw_param_set_minmax(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_SIZE, &_min, mindir, &_max, maxdir);
5174 * \brief Restrict a configuration space to have period size nearest to a target
5175 * \param pcm PCM handle
5176 * \param params Configuration space
5177 * \param val approximate target period size in frames / returned chosen approximate target period size
5178 * \param dir Sub unit direction
5179 * \return 0 otherwise a negative error code if configuration space is empty
5181 * target/chosen exact value is <,=,> val following dir (-1,0,1)
5184 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_period_size_near)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
5186 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)
5189 unsigned int _val = *val;
5190 int err = snd_pcm_hw_param_set_near(pcm, params, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
5197 * \brief Restrict a configuration space to contain only its minimum period size
5198 * \param pcm PCM handle
5199 * \param params Configuration space
5200 * \param val Returned maximum approximate period size in frames
5201 * \param dir Sub unit direction
5202 * \return 0 otherwise a negative error code
5204 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5207 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_period_size_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
5209 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)
5213 int err = snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
5220 * \brief Restrict a configuration space to contain only its maximum period size
5221 * \param pcm PCM handle
5222 * \param params Configuration space
5223 * \param val Returned maximum approximate period size in frames
5224 * \param dir Sub unit direction
5225 * \return 0 otherwise a negative error code
5227 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5230 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_period_size_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
5232 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)
5236 int err = snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_PERIOD_SIZE, &_val, dir);
5243 * \brief Restrict a configuration space to contain only integer period sizes
5244 * \param pcm PCM handle
5245 * \param params Configuration space
5246 * \return 0 otherwise a negative error code if configuration space would become empty
5248 int snd_pcm_hw_params_set_period_size_integer(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
5250 return snd_pcm_hw_param_set_integer(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIOD_SIZE);
5255 * \brief Extract periods from a configuration space
5256 * \param params Configuration space
5257 * \param val approximate periods per buffer
5258 * \param dir Sub unit direction
5259 * \return 0 otherwise a negative error code if the configuration space does not contain a single value
5261 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5264 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_periods)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5266 int snd_pcm_hw_params_get_periods(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5269 return snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_PERIODS, val, dir);
5273 * \brief Extract minimum periods count from a configuration space
5274 * \param params Configuration space
5275 * \param val approximate minimum periods per buffer
5276 * \param dir Sub unit direction
5277 * \return 0 otherwise a negative error code
5279 * Exact value is <,=,> the returned one following dir (-1,0,1)
5282 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_periods_min)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5284 int snd_pcm_hw_params_get_periods_min(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5287 return snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_PERIODS, val, dir);
5291 * \brief Extract maximum periods count from a configuration space
5292 * \param params Configuration space
5293 * \param val approximate maximum periods per buffer
5294 * \param dir Sub unit direction
5295 * \return 0 otherwise a negative error code
5297 * Exact value is <,=,> the returned one following dir (-1,0,1)
5300 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_periods_max)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5302 int snd_pcm_hw_params_get_periods_max(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5305 return snd_pcm_hw_param_get_max(params, SND_PCM_HW_PARAM_PERIODS, val, dir);
5309 * \brief Verify if a periods count is available inside a configuration space for a PCM
5310 * \param pcm PCM handle
5311 * \param params Configuration space
5312 * \param val approximate periods per buffer
5313 * \param dir Sub unit direction
5314 * \return 0 if available a negative error code otherwise
5316 * Wanted exact value is <,=,> val following dir (-1,0,1)
5318 int snd_pcm_hw_params_test_periods(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
5320 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_PERIODS, val, dir);
5324 * \brief Restrict a configuration space to contain only one periods count
5325 * \param pcm PCM handle
5326 * \param params Configuration space
5327 * \param val approximate periods per buffer
5328 * \param dir Sub unit direction
5329 * \return 0 otherwise a negative error code if configuration space would become empty
5331 * Wanted exact value is <,=,> val following dir (-1,0,1)
5333 int snd_pcm_hw_params_set_periods(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
5335 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIODS, val, dir);
5339 * \brief Restrict a configuration space with a minimum periods count
5340 * \param pcm PCM handle
5341 * \param params Configuration space
5342 * \param val approximate minimum periods per buffer (on return filled with actual minimum)
5343 * \param dir Sub unit direction (on return filled with actual direction)
5344 * \return 0 otherwise a negative error code if configuration space would become empty
5346 * Wanted/actual exact minimum is <,=,> val following dir (-1,0,1)
5348 int snd_pcm_hw_params_set_periods_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5350 return snd_pcm_hw_param_set_min(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIODS, val, dir);
5354 * \brief Restrict a configuration space with a maximum periods count
5355 * \param pcm PCM handle
5356 * \param params Configuration space
5357 * \param val approximate maximum periods per buffer (on return filled with actual maximum)
5358 * \param dir Sub unit direction (on return filled with actual direction)
5359 * \return 0 otherwise a negative error code if configuration space would become empty
5361 * Wanted/actual exact maximum is <,=,> val following dir (-1,0,1)
5363 int snd_pcm_hw_params_set_periods_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5365 return snd_pcm_hw_param_set_max(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIODS, val, dir);
5369 * \brief Restrict a configuration space to have periods counts in a given range
5370 * \param pcm PCM handle
5371 * \param params Configuration space
5372 * \param min approximate minimum periods per buffer (on return filled with actual minimum)
5373 * \param mindir Sub unit direction for minimum (on return filled with actual direction)
5374 * \param max approximate maximum periods per buffer (on return filled with actual maximum)
5375 * \param maxdir Sub unit direction for maximum (on return filled with actual direction)
5376 * \return 0 otherwise a negative error code if configuration space would become empty
5378 * Wanted/actual exact min/max is <,=,> val following dir (-1,0,1)
5380 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)
5382 return snd_pcm_hw_param_set_minmax(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIODS, min, mindir, max, maxdir);
5386 * \brief Restrict a configuration space to have periods count nearest to a target
5387 * \param pcm PCM handle
5388 * \param params Configuration space
5389 * \param val approximate target periods per buffer / returned chosen approximate target periods per buffer
5390 * \param dir Sub unit direction
5391 * \return 0 otherwise a negative error code if configuration space is empty
5393 * target/chosen exact value is <,=,> val following dir (-1,0,1)
5396 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_periods_near)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5398 int snd_pcm_hw_params_set_periods_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5401 return snd_pcm_hw_param_set_near(pcm, params, SND_PCM_HW_PARAM_PERIODS, val, dir);
5405 * \brief Restrict a configuration space to contain only its minimum periods count
5406 * \param pcm PCM handle
5407 * \param params Configuration space
5408 * \param val Returned approximate minimum periods per buffer
5409 * \param dir Sub unit direction
5410 * \return 0 otherwise a negative error code
5412 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5415 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_periods_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5417 int snd_pcm_hw_params_set_periods_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5420 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_PERIODS, val, dir);
5424 * \brief Restrict a configuration space to contain only its maximum periods count
5425 * \param pcm PCM handle
5426 * \param params Configuration space
5427 * \param val Returned approximate maximum periods per buffer
5428 * \param dir Sub unit direction
5429 * \return 0 otherwise a negative error code
5431 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5434 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_periods_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5436 int snd_pcm_hw_params_set_periods_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5439 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_PERIODS, val, dir);
5443 * \brief Restrict a configuration space to contain only integer periods counts
5444 * \param pcm PCM handle
5445 * \param params Configuration space
5446 * \return 0 otherwise a negative error code if configuration space would become empty
5448 int snd_pcm_hw_params_set_periods_integer(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
5450 return snd_pcm_hw_param_set_integer(pcm, params, SND_TRY, SND_PCM_HW_PARAM_PERIODS);
5455 * \brief Extract buffer time from a configuration space
5456 * \param params Configuration space
5457 * \param val Returned buffer time in us
5458 * \param dir Sub unit direction
5459 * \return 0 otherwise a negative error code if the configuration space does not contain a single value
5461 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5464 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_buffer_time)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5466 int snd_pcm_hw_params_get_buffer_time(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5469 return snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5473 * \brief Extract minimum buffer time from a configuration space
5474 * \param params Configuration space
5475 * \param val approximate minimum buffer duration in us
5476 * \param dir Sub unit direction
5477 * \return 0 otherwise a negative error code
5479 * Exact value is <,=,> the returned one following dir (-1,0,1)
5482 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_buffer_time_min)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5484 int snd_pcm_hw_params_get_buffer_time_min(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5487 return snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5491 * \brief Extract maximum buffer time from a configuration space
5492 * \param params Configuration space
5493 * \param val approximate maximum buffer duration in us
5494 * \param dir Sub unit direction
5495 * \return 0 otherwise a negative error code
5497 * Exact value is <,=,> the returned one following dir (-1,0,1)
5500 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_buffer_time_max)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5502 int snd_pcm_hw_params_get_buffer_time_max(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5505 return snd_pcm_hw_param_get_max(params, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5509 * \brief Verify if a buffer time is available inside a configuration space for a PCM
5510 * \param pcm PCM handle
5511 * \param params Configuration space
5512 * \param val approximate buffer duration in us
5513 * \param dir Sub unit direction
5514 * \return 0 if available a negative error code otherwise
5516 * Wanted exact value is <,=,> val following dir (-1,0,1)
5518 int snd_pcm_hw_params_test_buffer_time(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
5520 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5524 * \brief Restrict a configuration space to contain only one buffer time
5525 * \param pcm PCM handle
5526 * \param params Configuration space
5527 * \param val approximate buffer duration in us
5528 * \param dir Sub unit direction
5529 * \return 0 otherwise a negative error code if configuration space would become empty
5531 * Wanted exact value is <,=,> val following dir (-1,0,1)
5533 int snd_pcm_hw_params_set_buffer_time(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir)
5535 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5539 * \brief Restrict a configuration space with a minimum buffer time
5540 * \param pcm PCM handle
5541 * \param params Configuration space
5542 * \param val approximate minimum buffer duration in us (on return filled with actual minimum)
5543 * \param dir Sub unit direction (on return filled with actual direction)
5544 * \return 0 otherwise a negative error code if configuration space would become empty
5546 * Wanted/actual exact minimum is <,=,> val following dir (-1,0,1)
5548 int snd_pcm_hw_params_set_buffer_time_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5550 return snd_pcm_hw_param_set_min(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5554 * \brief Restrict a configuration space with a maximum buffer time
5555 * \param pcm PCM handle
5556 * \param params Configuration space
5557 * \param val approximate maximum buffer duration in us (on return filled with actual maximum)
5558 * \param dir Sub unit direction (on return filled with actual direction)
5559 * \return 0 otherwise a negative error code if configuration space would become empty
5561 * Wanted/actual exact maximum is <,=,> val following dir (-1,0,1)
5563 int snd_pcm_hw_params_set_buffer_time_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5565 return snd_pcm_hw_param_set_max(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5569 * \brief Restrict a configuration space to have buffer times in a given range
5570 * \param pcm PCM handle
5571 * \param params Configuration space
5572 * \param min approximate minimum buffer duration in us (on return filled with actual minimum)
5573 * \param mindir Sub unit direction for minimum (on return filled with actual direction)
5574 * \param max approximate maximum buffer duration in us (on return filled with actual maximum)
5575 * \param maxdir Sub unit direction for maximum (on return filled with actual direction)
5576 * \return 0 otherwise a negative error code if configuration space would become empty
5578 * Wanted/actual exact min/max is <,=,> val following dir (-1,0,1)
5580 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)
5582 return snd_pcm_hw_param_set_minmax(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_TIME, min, mindir, max, maxdir);
5586 * \brief Restrict a configuration space to have buffer time nearest to a target
5587 * \param pcm PCM handle
5588 * \param params Configuration space
5589 * \param val approximate target buffer duration in us / returned chosen approximate target buffer duration
5590 * \param dir Sub unit direction
5591 * \return 0 otherwise a negative error code if configuration space is empty
5593 * target/chosen exact value is <,=,> val following dir (-1,0,1)
5596 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_buffer_time_near)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5598 int snd_pcm_hw_params_set_buffer_time_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5601 return snd_pcm_hw_param_set_near(pcm, params, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5605 * \brief Restrict a configuration space to contain only its minimum buffer time
5606 * \param pcm PCM handle
5607 * \param params Configuration space
5608 * \param val Returned approximate minimum buffer duration in us
5609 * \param dir Sub unit direction
5610 * \return 0 otherwise a negative error code
5612 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5615 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_buffer_time_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5617 int snd_pcm_hw_params_set_buffer_time_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5620 return snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5624 * \brief Restrict a configuration space to contain only its maximum buffered time
5625 * \param pcm PCM handle
5626 * \param params Configuration space
5627 * \param val Returned approximate maximum buffer duration in us
5628 * \param dir Sub unit direction
5629 * \return 0 otherwise a negative error code
5631 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5634 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_buffer_time_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5636 int snd_pcm_hw_params_set_buffer_time_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5639 return snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_BUFFER_TIME, val, dir);
5644 * \brief Extract buffer size from a configuration space
5645 * \param params Configuration space
5646 * \param val Returned buffer size in frames
5647 * \return 0 otherwise a negative error code if the configuration space does not contain a single value
5650 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_buffer_size)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5652 int snd_pcm_hw_params_get_buffer_size(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5656 int err = snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
5663 * \brief Extract minimum buffer size from a configuration space
5664 * \param params Configuration space
5665 * \param val Returned approximate minimum buffer size in frames
5666 * \return 0 otherwise a negative error code
5669 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_buffer_size_min)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5671 int snd_pcm_hw_params_get_buffer_size_min(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5675 int err = snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
5682 * \brief Extract maximum buffer size from a configuration space
5683 * \param params Configuration space
5684 * \param val Returned approximate maximum buffer size in frames
5685 * \return 0 otherwise a negative error code
5687 * Exact value is <,=,> the returned one following dir (-1,0,1)
5690 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_buffer_size_max)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5692 int snd_pcm_hw_params_get_buffer_size_max(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5696 int err = snd_pcm_hw_param_get_max(params, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
5703 * \brief Verify if a buffer size is available inside a configuration space for a PCM
5704 * \param pcm PCM handle
5705 * \param params Configuration space
5706 * \param val buffer size in frames
5707 * \return 0 if available a negative error code otherwise
5709 * Wanted exact value is <,=,> val following dir (-1,0,1)
5711 int snd_pcm_hw_params_test_buffer_size(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t val)
5713 return snd_pcm_hw_param_set(pcm, params, SND_TEST, SND_PCM_HW_PARAM_BUFFER_SIZE, val, 0);
5717 * \brief Restrict a configuration space to contain only one buffer size
5718 * \param pcm PCM handle
5719 * \param params Configuration space
5720 * \param val buffer size in frames
5721 * \return 0 otherwise a negative error code if configuration space would become empty
5723 * Wanted exact value is <,=,> val following dir (-1,0,1)
5725 int snd_pcm_hw_params_set_buffer_size(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t val)
5727 return snd_pcm_hw_param_set(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_SIZE, val, 0);
5731 * \brief Restrict a configuration space with a minimum buffer size
5732 * \param pcm PCM handle
5733 * \param params Configuration space
5734 * \param val approximate minimum buffer size in frames (on return filled with actual minimum)
5735 * \return 0 otherwise a negative error code if configuration space would become empty
5737 int snd_pcm_hw_params_set_buffer_size_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5739 unsigned int _val = *val;
5740 int err = snd_pcm_hw_param_set_min(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
5747 * \brief Restrict a configuration space with a maximum buffer size
5748 * \param pcm PCM handle
5749 * \param params Configuration space
5750 * \param val approximate maximum buffer size in frames (on return filled with actual maximum)
5751 * \return 0 otherwise a negative error code if configuration space would become empty
5753 int snd_pcm_hw_params_set_buffer_size_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5755 unsigned int _val = *val;
5756 int err = snd_pcm_hw_param_set_max(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
5763 * \brief Restrict a configuration space to have buffer sizes in a given range
5764 * \param pcm PCM handle
5765 * \param params Configuration space
5766 * \param min approximate minimum buffer size in frames (on return filled with actual minimum)
5767 * \param max approximate maximum buffer size in frames (on return filled with actual maximum)
5768 * \return 0 otherwise a negative error code if configuration space would become empty
5770 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)
5772 unsigned int _min = *min;
5773 unsigned int _max = *max;
5774 int err = snd_pcm_hw_param_set_minmax(pcm, params, SND_TRY, SND_PCM_HW_PARAM_BUFFER_SIZE, &_min, NULL, &_max, NULL);
5781 * \brief Restrict a configuration space to have buffer size nearest to a target
5782 * \param pcm PCM handle
5783 * \param params Configuration space
5784 * \param val approximate target buffer size in frames / returned chosen approximate target buffer size in frames
5785 * \return 0 otherwise a negative error code if configuration space is empty
5788 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_buffer_size_near)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5790 int snd_pcm_hw_params_set_buffer_size_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5793 unsigned int _val = *val;
5794 int err = snd_pcm_hw_param_set_near(pcm, params, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
5801 * \brief Restrict a configuration space to contain only its minimum buffer size
5802 * \param pcm PCM handle
5803 * \param params Configuration space
5804 * \param val Returned minimum buffer size in frames
5805 * \return buffer size in frames
5808 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_buffer_size_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5810 int snd_pcm_hw_params_set_buffer_size_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5814 int err = snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
5821 * \brief Restrict a configuration space to contain only its maximum buffer size
5822 * \param pcm PCM handle
5823 * \param params Configuration space
5824 * \param val Returned maximum buffer size in frames
5825 * \return 0 otherwise a negative error code
5828 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_buffer_size_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5830 int snd_pcm_hw_params_set_buffer_size_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
5834 int err = snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_BUFFER_SIZE, &_val, NULL);
5842 * \brief (DEPRECATED) Extract tick time from a configuration space
5843 * \param params Configuration space
5844 * \param val Returned approximate tick duration in us
5845 * \param dir Sub unit direction
5846 * \return 0 otherwise a negative error code if the configuration space does not contain a single value
5848 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
5851 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_tick_time)(const snd_pcm_hw_params_t *params ATTRIBUTE_UNUSED, unsigned int *val, int *dir ATTRIBUTE_UNUSED)
5853 int snd_pcm_hw_params_get_tick_time(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5861 * \brief (DEPRECATED) Extract minimum tick time from a configuration space
5862 * \param params Configuration space
5863 * \param val Returned approximate minimum tick duration in us
5864 * \param dir Sub unit direction
5865 * \return 0 otherwise a negative error code
5867 * Exact value is <,=,> the returned one following dir (-1,0,1)
5870 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_tick_time_min)(const snd_pcm_hw_params_t *params ATTRIBUTE_UNUSED, unsigned int *val, int *dir ATTRIBUTE_UNUSED)
5872 int snd_pcm_hw_params_get_tick_time_min(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5880 * \brief (DEPRECATED) Extract maximum tick time from a configuration space
5881 * \param params Configuration space
5882 * \param val Returned approximate maximum tick duration in us
5883 * \param dir Sub unit direction
5884 * \return 0 otherwise a negative error code
5886 * Exact value is <,=,> the returned one following dir (-1,0,1)
5889 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_get_tick_time_max)(const snd_pcm_hw_params_t *params ATTRIBUTE_UNUSED, unsigned int *val, int *dir ATTRIBUTE_UNUSED)
5891 int snd_pcm_hw_params_get_tick_time_max(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5899 * \brief (DEPRECATED) Verify if a tick time is available inside a configuration space for a PCM
5900 * \param pcm PCM handle
5901 * \param params Configuration space
5902 * \param val approximate tick duration in us
5903 * \param dir Sub unit direction
5904 * \return 0 if available a negative error code otherwise
5906 * Wanted exact value is <,=,> val following dir (-1,0,1)
5908 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)
5910 return val ? -EINVAL : 0;
5914 * \brief (DEPRECATED) Restrict a configuration space to contain only one tick time
5915 * \param pcm PCM handle
5916 * \param params Configuration space
5917 * \param val approximate tick duration in us
5918 * \param dir Sub unit direction
5919 * \return 0 otherwise a negative error code if configuration space would become empty
5921 * Wanted exact value is <,=,> val following dir (-1,0,1)
5923 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)
5929 * \brief (DEPRECATED) Restrict a configuration space with a minimum tick time
5930 * \param pcm PCM handle
5931 * \param params Configuration space
5932 * \param val approximate minimum tick duration in us (on return filled with actual minimum)
5933 * \param dir Sub unit direction (on return filled with actual direction)
5934 * \return 0 otherwise a negative error code if configuration space would become empty
5936 * Wanted/actual exact minimum is <,=,> val following dir (-1,0,1)
5938 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)
5944 * \brief (DEPRECATED) Restrict a configuration space with a maximum tick time
5945 * \param pcm PCM handle
5946 * \param params Configuration space
5947 * \param val approximate maximum tick duration in us (on return filled with actual maximum)
5948 * \param dir Sub unit direction (on return filled with actual direction)
5949 * \return 0 otherwise a negative error code if configuration space would become empty
5951 * Wanted/actual exact maximum is <,=,> val following dir (-1,0,1)
5953 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)
5959 * \brief (DEPRECATED) Restrict a configuration space to have tick times in a given range
5960 * \param pcm PCM handle
5961 * \param params Configuration space
5962 * \param min approximate minimum tick duration in us (on return filled with actual minimum)
5963 * \param mindir Sub unit direction for minimum (on return filled with actual direction)
5964 * \param max approximate maximum tick duration in us (on return filled with actual maximum)
5965 * \param maxdir Sub unit direction for maximum (on return filled with actual direction)
5966 * \return 0 otherwise a negative error code if configuration space would become empty
5968 * Wanted/actual exact min/max is <,=,> val following dir (-1,0,1)
5970 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)
5976 * \brief (DEPRECATED) Restrict a configuration space to have tick time nearest to a target
5977 * \param pcm PCM handle
5978 * \param params Configuration space
5979 * \param val approximate target tick duration in us / returned chosen approximate target tick duration in us
5980 * \param dir Sub unit direction
5981 * \return 0 otherwise a negative error code if configuration space is empty
5983 * target/chosen exact value is <,=,> val following dir (-1,0,1)
5986 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_tick_time_near)(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_hw_params_t *params ATTRIBUTE_UNUSED, unsigned int *val ATTRIBUTE_UNUSED, int *dir ATTRIBUTE_UNUSED)
5988 int snd_pcm_hw_params_set_tick_time_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
5995 * \brief (DEPRECATED) Restrict a configuration space to contain only its minimum tick time
5996 * \param pcm PCM handle
5997 * \param params Configuration space
5998 * \param val Returned approximate minimum tick duration in us
5999 * \param dir Sub unit direction
6000 * \return 0 otherwise a negative error code
6002 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
6005 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_tick_time_first)(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_hw_params_t *params ATTRIBUTE_UNUSED, unsigned int *val ATTRIBUTE_UNUSED, int *dir ATTRIBUTE_UNUSED)
6007 int snd_pcm_hw_params_set_tick_time_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
6014 * \brief (DEPRECATED) Restrict a configuration space to contain only its maximum tick time
6015 * \param pcm PCM handle
6016 * \param params Configuration space
6017 * \param val Returned approximate maximum tick duration in us
6018 * \param dir Sub unit direction
6019 * \return 0 otherwise a negative error code
6021 * Actual exact value is <,=,> the approximate one following dir (-1, 0, 1)
6024 EXPORT_SYMBOL int INTERNAL(snd_pcm_hw_params_set_tick_time_last)(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_hw_params_t *params ATTRIBUTE_UNUSED, unsigned int *val ATTRIBUTE_UNUSED, int *dir ATTRIBUTE_UNUSED)
6026 int snd_pcm_hw_params_set_tick_time_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)
6033 * \brief Get the minimum transfer align value in samples
6034 * \param params Configuration space
6035 * \param val Returned minimum align value
6036 * \return 0 otherwise a negative error code if the configuration space does not contain a single value
6038 int snd_pcm_hw_params_get_min_align(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)
6040 unsigned int format, channels, fb, min_align;
6043 err = snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_FORMAT, &format, NULL);
6046 err = snd_pcm_hw_param_get(params, SND_PCM_HW_PARAM_CHANNELS, &channels, NULL);
6049 // compute frame bits
6050 fb = snd_pcm_format_physical_width((snd_pcm_format_t)format) * channels;
6062 * \brief Return current software configuration for a PCM
6063 * \param pcm PCM handle
6064 * \param params Software configuration container
6065 * \return 0 on success otherwise a negative error code
6067 * The function is thread-safe when built with the proper option.
6069 int snd_pcm_sw_params_current(snd_pcm_t *pcm, snd_pcm_sw_params_t *params)
6071 assert(pcm && params);
6072 if (CHECK_SANITY(! pcm->setup)) {
6073 SNDMSG("PCM not set up");
6076 __snd_pcm_lock(pcm); /* forced lock due to pcm field changes */
6077 params->proto = SNDRV_PCM_VERSION;
6078 params->tstamp_mode = pcm->tstamp_mode;
6079 params->tstamp_type = pcm->tstamp_type;
6080 params->period_step = pcm->period_step;
6081 params->sleep_min = 0;
6082 params->avail_min = pcm->avail_min;
6083 sw_set_period_event(params, pcm->period_event);
6084 params->xfer_align = 1;
6085 params->start_threshold = pcm->start_threshold;
6086 params->stop_threshold = pcm->stop_threshold;
6087 params->silence_threshold = pcm->silence_threshold;
6088 params->silence_size = pcm->silence_size;
6089 params->boundary = pcm->boundary;
6090 __snd_pcm_unlock(pcm);
6095 * \brief Dump a software configuration
6096 * \param params Software configuration container
6097 * \param out Output handle
6098 * \return 0 on success otherwise a negative error code
6100 int snd_pcm_sw_params_dump(snd_pcm_sw_params_t *params, snd_output_t *out)
6102 snd_output_printf(out, "tstamp_mode: %s\n", snd_pcm_tstamp_mode_name(params->tstamp_mode));
6103 snd_output_printf(out, "tstamp_type: %s\n", snd_pcm_tstamp_type_name(params->tstamp_type));
6104 snd_output_printf(out, "period_step: %u\n", params->period_step);
6105 snd_output_printf(out, "avail_min: %lu\n", params->avail_min);
6106 snd_output_printf(out, "start_threshold: %ld\n", params->start_threshold);
6107 snd_output_printf(out, "stop_threshold: %ld\n", params->stop_threshold);
6108 snd_output_printf(out, "silence_threshold: %lu\n", params->silence_threshold);
6109 snd_output_printf(out, "silence_size: %lu\n", params->silence_size);
6110 snd_output_printf(out, "boundary: %lu\n", params->boundary);
6115 * \brief get size of #snd_pcm_sw_params_t
6116 * \return size in bytes
6118 size_t snd_pcm_sw_params_sizeof()
6120 return sizeof(snd_pcm_sw_params_t);
6124 * \brief allocate an invalid #snd_pcm_sw_params_t using standard malloc
6125 * \param ptr returned pointer
6126 * \return 0 on success otherwise negative error code
6128 int snd_pcm_sw_params_malloc(snd_pcm_sw_params_t **ptr)
6131 *ptr = calloc(1, sizeof(snd_pcm_sw_params_t));
6138 * \brief frees a previously allocated #snd_pcm_sw_params_t
6139 * \param obj pointer to object to free
6141 void snd_pcm_sw_params_free(snd_pcm_sw_params_t *obj)
6147 * \brief copy one #snd_pcm_sw_params_t to another
6148 * \param dst pointer to destination
6149 * \param src pointer to source
6151 void snd_pcm_sw_params_copy(snd_pcm_sw_params_t *dst, const snd_pcm_sw_params_t *src)
6158 * \brief Get boundary for ring pointers from a software configuration container
6159 * \param params Software configuration container
6160 * \param val Returned boundary in frames
6161 * \return 0 otherwise a negative error code
6163 int snd_pcm_sw_params_get_boundary(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6166 *val = params->boundary;
6171 * \brief (DEPRECATED) Set start mode inside a software configuration container
6172 * \param pcm PCM handle
6173 * \param params Software configuration container
6174 * \param val Start mode
6175 * \return 0 otherwise a negative error code
6177 int snd_pcm_sw_params_set_start_mode(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_start_t val)
6179 assert(pcm && params);
6181 case SND_PCM_START_DATA:
6182 params->start_threshold = 1;
6184 case SND_PCM_START_EXPLICIT:
6185 params->start_threshold = pcm->boundary;
6188 SNDMSG("invalid start mode value %d\n", val);
6195 link_warning(snd_pcm_sw_params_set_start_mode, "Warning: start_mode is deprecated, consider to use start_threshold");
6199 * \brief (DEPRECATED) Get start mode from a software configuration container
6200 * \param params Software configuration container
6201 * \return start mode
6203 snd_pcm_start_t snd_pcm_sw_params_get_start_mode(const snd_pcm_sw_params_t *params)
6207 return params->start_threshold > 1024 * 1024 ? SND_PCM_START_EXPLICIT : SND_PCM_START_DATA;
6211 link_warning(snd_pcm_sw_params_get_start_mode, "Warning: start_mode is deprecated, consider to use start_threshold");
6215 * \brief (DEPRECATED) Set xrun mode inside a software configuration container
6216 * \param pcm PCM handle
6217 * \param params Software configuration container
6218 * \param val Xrun mode
6219 * \return 0 otherwise a negative error code
6222 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)
6224 int snd_pcm_sw_params_set_xrun_mode(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_xrun_t val)
6227 assert(pcm && params);
6229 case SND_PCM_XRUN_STOP:
6230 params->stop_threshold = pcm->buffer_size;
6232 case SND_PCM_XRUN_NONE:
6233 params->stop_threshold = pcm->boundary;
6236 SNDMSG("invalid xrun mode value %d\n", val);
6243 link_warning(snd_pcm_sw_params_set_xrun_mode, "Warning: xrun_mode is deprecated, consider to use stop_threshold");
6247 * \brief (DEPRECATED) Get xrun mode from a software configuration container
6248 * \param params Software configuration container
6251 snd_pcm_xrun_t snd_pcm_sw_params_get_xrun_mode(const snd_pcm_sw_params_t *params)
6255 return params->stop_threshold > 1024 * 1024 ? SND_PCM_XRUN_NONE : SND_PCM_XRUN_STOP;
6259 link_warning(snd_pcm_sw_params_get_xrun_mode, "Warning: xrun_mode is deprecated, consider to use stop_threshold");
6263 * \brief Set timestamp mode inside a software configuration container
6264 * \param pcm PCM handle
6265 * \param params Software configuration container
6266 * \param val Timestamp mode
6267 * \return 0 otherwise a negative error code
6270 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)
6272 int snd_pcm_sw_params_set_tstamp_mode(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_tstamp_t val)
6275 assert(pcm && params);
6276 if (CHECK_SANITY(val > SND_PCM_TSTAMP_LAST)) {
6277 SNDMSG("invalid tstamp_mode value %d", val);
6280 params->tstamp_mode = val;
6285 * \brief Get timestamp mode from a software configuration container
6286 * \param params Software configuration container
6287 * \param val Returned timestamp
6288 * \return 0 otherwise a negative error code
6291 EXPORT_SYMBOL int INTERNAL(snd_pcm_sw_params_get_tstamp_mode)(const snd_pcm_sw_params_t *params, snd_pcm_tstamp_t *val)
6293 int snd_pcm_sw_params_get_tstamp_mode(const snd_pcm_sw_params_t *params, snd_pcm_tstamp_t *val)
6296 assert(params && val);
6297 *val = params->tstamp_mode;
6302 * \brief Set timestamp type inside a software configuration container
6303 * \param pcm PCM handle
6304 * \param params Software configuration container
6305 * \param val Timestamp type
6306 * \return 0 otherwise a negative error code
6308 int snd_pcm_sw_params_set_tstamp_type(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_tstamp_type_t val)
6310 assert(pcm && params);
6311 if (CHECK_SANITY(val > SND_PCM_TSTAMP_TYPE_LAST)) {
6312 SNDMSG("invalid tstamp_type value %d", val);
6315 params->tstamp_type = val;
6320 * \brief Get timestamp type from a software configuration container
6321 * \param params Software configuration container
6322 * \param val Returned timestamp type
6323 * \return 0 otherwise a negative error code
6325 int snd_pcm_sw_params_get_tstamp_type(const snd_pcm_sw_params_t *params, snd_pcm_tstamp_type_t *val)
6327 assert(params && val);
6328 *val = params->tstamp_type;
6333 * \brief (DEPRECATED) Set minimum number of ticks to sleep inside a software configuration container
6334 * \param pcm PCM handle
6335 * \param params Software configuration container
6336 * \param val Minimum ticks to sleep or 0 to disable the use of tick timer
6337 * \return 0 otherwise a negative error code
6340 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)
6342 int snd_pcm_sw_params_set_sleep_min(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, unsigned int val)
6349 * \brief (DEPRECATED) Get minimum numbers of ticks to sleep from a software configuration container
6350 * \param params Software configuration container
6351 * \param val returned minimum number of ticks to sleep or 0 if tick timer is disabled
6352 * \return 0 otherwise a negative error code
6355 EXPORT_SYMBOL int INTERNAL(snd_pcm_sw_params_get_sleep_min)(const snd_pcm_sw_params_t *params ATTRIBUTE_UNUSED, unsigned int *val)
6357 int snd_pcm_sw_params_get_sleep_min(const snd_pcm_sw_params_t *params, unsigned int *val)
6365 * \brief Set avail min inside a software configuration container
6366 * \param pcm PCM handle
6367 * \param params Software configuration container
6368 * \param val Minimum avail frames to consider PCM ready
6369 * \return 0 otherwise a negative error code
6371 * Note: This is similar to setting an OSS wakeup point. The valid
6372 * values for 'val' are determined by the specific hardware. Most PC
6373 * sound cards can only accept power of 2 frame counts (i.e. 512,
6374 * 1024, 2048). You cannot use this as a high resolution timer - it
6375 * is limited to how often the sound card hardware raises an
6379 EXPORT_SYMBOL int snd_pcm_sw_params_set_avail_min(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
6381 int snd_pcm_sw_params_set_avail_min(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
6384 assert(pcm && params);
6385 /* Fix avail_min if it's below period size. The period_size
6386 * defines the minimal wake-up timing accuracy, so it doesn't
6387 * make sense to set below that.
6389 if (val < pcm->period_size)
6390 val = pcm->period_size;
6391 params->avail_min = val;
6396 * \brief Get avail min from a software configuration container
6397 * \param params Software configuration container
6398 * \param val returned minimum available frames to consider PCM ready
6399 * \return 0 otherwise a negative error code
6402 EXPORT_SYMBOL int INTERNAL(snd_pcm_sw_params_get_avail_min)(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6404 int snd_pcm_sw_params_get_avail_min(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6407 assert(params && val);
6408 *val = params->avail_min;
6413 * \brief Set period event inside a software configuration container
6414 * \param pcm PCM handle
6415 * \param params Software configuration container
6416 * \param val 0 = disable period event, 1 = enable period event
6417 * \return 0 otherwise a negative error code
6419 * An poll (select) wakeup event is raised if enabled.
6421 int snd_pcm_sw_params_set_period_event(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, int val)
6423 assert(pcm && params);
6424 sw_set_period_event(params, val);
6429 * \brief Get period event from a software configuration container
6430 * \param params Software configuration container
6431 * \param val returned period event state
6432 * \return 0 otherwise a negative error code
6434 int snd_pcm_sw_params_get_period_event(const snd_pcm_sw_params_t *params, int *val)
6436 assert(params && val);
6437 *val = sw_get_period_event(params);
6442 * \brief (DEPRECATED) Set xfer align inside a software configuration container
6443 * \param pcm PCM handle
6444 * \param params Software configuration container
6445 * \param val Chunk size (frames are attempted to be transferred in chunks)
6446 * \return 0 otherwise a negative error code
6449 EXPORT_SYMBOL int snd_pcm_sw_params_set_xfer_align(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_sw_params_t *params ATTRIBUTE_UNUSED, snd_pcm_uframes_t val ATTRIBUTE_UNUSED)
6451 int snd_pcm_sw_params_set_xfer_align(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
6458 * \brief (DEPRECATED) Get xfer align from a software configuration container
6459 * \param params Software configuration container
6460 * \param val returned chunk size (frames are attempted to be transferred in chunks)
6461 * \return 0 otherwise a negative error code
6464 EXPORT_SYMBOL int INTERNAL(snd_pcm_sw_params_get_xfer_align)(const snd_pcm_sw_params_t *params ATTRIBUTE_UNUSED, snd_pcm_uframes_t *val)
6466 int snd_pcm_sw_params_get_xfer_align(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6474 * \brief Set start threshold inside a software configuration container
6475 * \param pcm PCM handle
6476 * \param params Software configuration container
6477 * \param val Start threshold in frames
6478 * \return 0 otherwise a negative error code
6480 * PCM is automatically started when playback frames available to PCM
6481 * are >= threshold or when requested capture frames are >= threshold
6484 EXPORT_SYMBOL int snd_pcm_sw_params_set_start_threshold(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
6486 int snd_pcm_sw_params_set_start_threshold(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
6489 assert(pcm && params);
6490 params->start_threshold = val;
6495 * \brief Get start threshold from a software configuration container
6496 * \param params Software configuration container
6497 * \param val Returned start threshold in frames
6498 * \return 0 otherwise a negative error code
6500 * PCM is automatically started when playback frames available to PCM
6501 * are >= threshold or when requested capture frames are >= threshold
6504 EXPORT_SYMBOL int INTERNAL(snd_pcm_sw_params_get_start_threshold)(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6506 int snd_pcm_sw_params_get_start_threshold(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6510 *val = params->start_threshold;
6516 * \brief Set stop threshold inside a software configuration container
6517 * \param pcm PCM handle
6518 * \param params Software configuration container
6519 * \param val Stop threshold in frames
6520 * \return 0 otherwise a negative error code
6522 * PCM is automatically stopped in #SND_PCM_STATE_XRUN state when available
6523 * frames is >= threshold. If the stop threshold is equal to boundary (also
6524 * software parameter - sw_param) then automatic stop will be disabled
6525 * (thus device will do the endless loop in the ring buffer).
6528 EXPORT_SYMBOL int snd_pcm_sw_params_set_stop_threshold(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
6530 int snd_pcm_sw_params_set_stop_threshold(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
6533 assert(pcm && params);
6534 params->stop_threshold = val;
6539 * \brief Get stop threshold from a software configuration container
6540 * \param params Software configuration container
6541 * \param val Returned stop threshold in frames
6542 * \return 0 otherwise a negative error code
6544 * PCM is automatically stopped in #SND_PCM_STATE_XRUN state when available
6545 * frames is >= threshold. If the stop threshold is equal to boundary (also
6546 * software parameter - sw_param) then automatic stop will be disabled
6547 * (thus device will do the endless loop in the ring buffer).
6550 EXPORT_SYMBOL int INTERNAL(snd_pcm_sw_params_get_stop_threshold)(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6552 int snd_pcm_sw_params_get_stop_threshold(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6556 *val = params->stop_threshold;
6562 * \brief Set silence threshold inside a software configuration container
6563 * \param pcm PCM handle
6564 * \param params Software configuration container
6565 * \param val Silence threshold in frames
6566 * \return 0 otherwise a negative error code
6568 * A portion of playback buffer is overwritten with silence (see
6569 * #snd_pcm_sw_params_set_silence_size) when playback underrun is nearer
6570 * than silence threshold.
6573 EXPORT_SYMBOL int snd_pcm_sw_params_set_silence_threshold(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
6575 int snd_pcm_sw_params_set_silence_threshold(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
6578 assert(pcm && params);
6579 if (CHECK_SANITY(val >= pcm->buffer_size)) {
6580 SNDMSG("invalid silent_threshold value %ld (buffer_size = %ld)",
6581 val, pcm->buffer_size);
6584 params->silence_threshold = val;
6589 * \brief Get silence threshold from a software configuration container
6590 * \param params Software configuration container
6591 * \param val Returned silence threshold in frames
6592 * \return 0 otherwise a negative error value
6594 * A portion of playback buffer is overwritten with silence (see
6595 * #snd_pcm_sw_params_set_silence_size) when playback underrun is nearer
6596 * than silence threshold.
6599 EXPORT_SYMBOL int INTERNAL(snd_pcm_sw_params_get_silence_threshold)(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6601 int snd_pcm_sw_params_get_silence_threshold(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6604 assert(params && val);
6605 *val = params->silence_threshold;
6611 * \brief Set silence size inside a software configuration container
6612 * \param pcm PCM handle
6613 * \param params Software configuration container
6614 * \param val Silence size in frames (0 for disabled)
6615 * \return 0 otherwise a negative error code
6617 * A portion of playback buffer is overwritten with silence when playback
6618 * underrun is nearer than silence threshold (see
6619 * #snd_pcm_sw_params_set_silence_threshold)
6621 * The special case is when silence size value is equal or greater than
6622 * boundary. The unused portion of the ring buffer (initial written samples
6623 * are untouched) is filled with silence at start. Later, only just processed
6624 * sample area is filled with silence. Note: silence_threshold must be set to zero.
6627 EXPORT_SYMBOL int snd_pcm_sw_params_set_silence_size(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
6629 int snd_pcm_sw_params_set_silence_size(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val)
6632 assert(pcm && params);
6633 if (CHECK_SANITY(val < pcm->boundary && val > pcm->buffer_size)) {
6634 SNDMSG("invalid silence_size %ld (boundary %ld, buffer_size %ld)",
6635 val, pcm->boundary, pcm->buffer_size);
6638 params->silence_size = val;
6643 * \brief Get silence size from a software configuration container
6644 * \param params Software configuration container
6645 * \param val Returned silence size in frames (0 for disabled)
6646 * \return 0 otherwise a negative error code
6648 * A portion of playback buffer is overwritten with silence when playback
6649 * underrun is nearer than silence threshold (see
6650 * #snd_pcm_sw_params_set_silence_threshold)
6653 EXPORT_SYMBOL int INTERNAL(snd_pcm_sw_params_get_silence_size)(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6655 int snd_pcm_sw_params_get_silence_size(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val)
6659 *val = params->silence_size;
6665 * \brief get size of #snd_pcm_status_t
6666 * \return size in bytes
6668 size_t snd_pcm_status_sizeof()
6670 return sizeof(snd_pcm_status_t);
6674 * \brief allocate an invalid #snd_pcm_status_t using standard malloc
6675 * \param ptr returned pointer
6676 * \return 0 on success otherwise negative error code
6678 int snd_pcm_status_malloc(snd_pcm_status_t **ptr)
6681 *ptr = calloc(1, sizeof(snd_pcm_status_t));
6688 * \brief frees a previously allocated #snd_pcm_status_t
6689 * \param obj pointer to object to free
6691 void snd_pcm_status_free(snd_pcm_status_t *obj)
6697 * \brief copy one #snd_pcm_status_t to another
6698 * \param dst pointer to destination
6699 * \param src pointer to source
6701 void snd_pcm_status_copy(snd_pcm_status_t *dst, const snd_pcm_status_t *src)
6708 * \brief Get state from a PCM status container (see #snd_pcm_state)
6709 * \param obj #snd_pcm_status_t pointer
6712 snd_pcm_state_t snd_pcm_status_get_state(const snd_pcm_status_t *obj)
6719 * \brief Get trigger timestamp from a PCM status container
6720 * \param obj #snd_pcm_status_t pointer
6721 * \param ptr Pointer to returned timestamp
6723 * Trigger means a PCM state transition (from stopped to running or
6724 * versa vice). It applies also to pause and suspend. In other words,
6725 * timestamp contains time when stream started or when it was stopped.
6727 void snd_pcm_status_get_trigger_tstamp(const snd_pcm_status_t *obj, snd_timestamp_t *ptr)
6730 ptr->tv_sec = obj->trigger_tstamp.tv_sec;
6731 ptr->tv_usec = obj->trigger_tstamp.tv_nsec / 1000L;
6735 * \brief Get trigger hi-res timestamp from a PCM status container
6736 * \param obj #snd_pcm_status_t pointer
6737 * \param ptr Pointer to returned timestamp
6739 * Trigger means a PCM state transition (from stopped to running or
6740 * versa vice). It applies also to pause and suspend. In other words,
6741 * timestamp contains time when stream started or when it was stopped.
6744 EXPORT_SYMBOL void INTERNAL(snd_pcm_status_get_trigger_htstamp)(const snd_pcm_status_t *obj, snd_htimestamp_t *ptr)
6746 void snd_pcm_status_get_trigger_htstamp(const snd_pcm_status_t *obj, snd_htimestamp_t *ptr)
6750 *ptr = obj->trigger_tstamp;
6752 use_default_symbol_version(__snd_pcm_status_get_trigger_htstamp, snd_pcm_status_get_trigger_htstamp, ALSA_0.9.0rc8);
6755 * \brief Get "now" timestamp from a PCM status container
6756 * \param obj #snd_pcm_status_t pointer
6757 * \param ptr Pointer to returned timestamp
6759 void snd_pcm_status_get_tstamp(const snd_pcm_status_t *obj, snd_timestamp_t *ptr)
6762 ptr->tv_sec = obj->tstamp.tv_sec;
6763 ptr->tv_usec = obj->tstamp.tv_nsec / 1000L;
6767 * \brief Get "now" hi-res timestamp from a PCM status container
6768 * \param obj pointer to #snd_pcm_status_t
6769 * \param ptr Pointer to returned timestamp
6772 EXPORT_SYMBOL void INTERNAL(snd_pcm_status_get_htstamp)(const snd_pcm_status_t *obj, snd_htimestamp_t *ptr)
6774 void snd_pcm_status_get_htstamp(const snd_pcm_status_t *obj, snd_htimestamp_t *ptr)
6780 use_default_symbol_version(__snd_pcm_status_get_htstamp, snd_pcm_status_get_htstamp, ALSA_0.9.0rc8);
6783 * \brief Get "now" hi-res audio timestamp from a PCM status container
6784 * \param obj pointer to #snd_pcm_status_t
6785 * \param ptr Pointer to returned timestamp
6787 void snd_pcm_status_get_audio_htstamp(const snd_pcm_status_t *obj, snd_htimestamp_t *ptr)
6790 *ptr = obj->audio_tstamp;
6794 * \brief Get "now" hi-res driver timestamp from a PCM status container. Defines when the status
6795 * was generated by driver, may differ from normal timestamp.
6796 * \param obj pointer to #snd_pcm_status_t
6797 * \param ptr Pointer to returned timestamp
6799 void snd_pcm_status_get_driver_htstamp(const snd_pcm_status_t *obj, snd_htimestamp_t *ptr)
6802 *ptr = obj->driver_tstamp;
6806 * \brief Get audio_tstamp_report from a PCM status container
6807 * \param obj pointer to #snd_pcm_status_t
6808 * \param ptr Pointer to returned report (valid fields are accuracy and type)
6810 void snd_pcm_status_get_audio_htstamp_report(const snd_pcm_status_t *obj,
6811 snd_pcm_audio_tstamp_report_t *audio_tstamp_report)
6813 assert(obj && audio_tstamp_report);
6814 snd_pcm_unpack_audio_tstamp_report(obj->audio_tstamp_data,
6815 obj->audio_tstamp_accuracy,
6816 audio_tstamp_report);
6820 * \brief set audio_tstamp_config from a PCM status container
6821 * \param obj pointer to #snd_pcm_status_t
6822 * \param ptr Pointer to config (valid fields are type and report_analog_delay)
6824 void snd_pcm_status_set_audio_htstamp_config(snd_pcm_status_t *obj,
6825 snd_pcm_audio_tstamp_config_t *audio_tstamp_config)
6827 assert(obj && audio_tstamp_config);
6828 snd_pcm_pack_audio_tstamp_config(&obj->audio_tstamp_data, audio_tstamp_config);
6832 * \brief Get delay from a PCM status container (see #snd_pcm_delay)
6833 * \return Delay in frames
6835 * Delay is distance between current application frame position and
6836 * sound frame position.
6837 * It's positive and less than buffer size in normal situation,
6838 * negative on playback underrun and greater than buffer size on
6841 snd_pcm_sframes_t snd_pcm_status_get_delay(const snd_pcm_status_t *obj)
6848 * \brief Get number of frames available from a PCM status container (see #snd_pcm_avail_update)
6849 * \return Number of frames ready to be read/written
6851 snd_pcm_uframes_t snd_pcm_status_get_avail(const snd_pcm_status_t *obj)
6858 * \brief Get maximum number of frames available from a PCM status container after last #snd_pcm_status call
6859 * \return Maximum number of frames ready to be read/written
6861 snd_pcm_uframes_t snd_pcm_status_get_avail_max(const snd_pcm_status_t *obj)
6864 return obj->avail_max;
6868 * \brief Get count of ADC overrange detections since last call
6869 * \return Count of ADC overrange detections
6871 snd_pcm_uframes_t snd_pcm_status_get_overrange(const snd_pcm_status_t *obj)
6874 return obj->overrange;
6878 * \brief get size of #snd_pcm_info_t
6879 * \return size in bytes
6881 size_t snd_pcm_info_sizeof()
6883 return sizeof(snd_pcm_info_t);
6887 * \brief allocate an invalid #snd_pcm_info_t using standard malloc
6888 * \param ptr returned pointer
6889 * \return 0 on success otherwise negative error code
6891 int snd_pcm_info_malloc(snd_pcm_info_t **ptr)
6894 *ptr = calloc(1, sizeof(snd_pcm_info_t));
6901 * \brief frees a previously allocated #snd_pcm_info_t
6902 * \param obj pointer to object to free
6904 void snd_pcm_info_free(snd_pcm_info_t *obj)
6910 * \brief copy one #snd_pcm_info_t to another
6911 * \param dst pointer to destination
6912 * \param src pointer to source
6914 void snd_pcm_info_copy(snd_pcm_info_t *dst, const snd_pcm_info_t *src)
6921 * \brief Get device from a PCM info container
6922 * \param obj PCM info container
6923 * \return device number
6925 unsigned int snd_pcm_info_get_device(const snd_pcm_info_t *obj)
6932 * \brief Get subdevice from a PCM info container
6933 * \param obj PCM info container
6934 * \return subdevice number
6936 unsigned int snd_pcm_info_get_subdevice(const snd_pcm_info_t *obj)
6939 return obj->subdevice;
6943 * \brief Get stream (direction) from a PCM info container
6944 * \param obj PCM info container
6947 snd_pcm_stream_t snd_pcm_info_get_stream(const snd_pcm_info_t *obj)
6954 * \brief Get card from a PCM info container
6955 * \param obj PCM info container
6956 * \return card number otherwise a negative error code if not associable to a card
6958 int snd_pcm_info_get_card(const snd_pcm_info_t *obj)
6965 * \brief Get id from a PCM info container
6966 * \param obj PCM info container
6967 * \return short id of PCM
6969 const char *snd_pcm_info_get_id(const snd_pcm_info_t *obj)
6972 return (const char *)obj->id;
6976 * \brief Get name from a PCM info container
6977 * \param obj PCM info container
6978 * \return name of PCM
6980 const char *snd_pcm_info_get_name(const snd_pcm_info_t *obj)
6983 return (const char *)obj->name;
6987 * \brief Get subdevice name from a PCM info container
6988 * \param obj PCM info container
6989 * \return name of used PCM subdevice
6991 const char *snd_pcm_info_get_subdevice_name(const snd_pcm_info_t *obj)
6994 return (const char *)obj->subname;
6998 * \brief Get class from a PCM info container
6999 * \param obj PCM info container
7000 * \return class of PCM
7002 snd_pcm_class_t snd_pcm_info_get_class(const snd_pcm_info_t *obj)
7005 return obj->dev_class;
7009 * \brief Get subclass from a PCM info container
7010 * \param obj PCM info container
7011 * \return subclass of PCM
7013 snd_pcm_subclass_t snd_pcm_info_get_subclass(const snd_pcm_info_t *obj)
7016 return obj->dev_subclass;
7020 * \brief Get subdevices count from a PCM info container
7021 * \param obj PCM info container
7022 * \return subdevices total count of PCM
7024 unsigned int snd_pcm_info_get_subdevices_count(const snd_pcm_info_t *obj)
7027 return obj->subdevices_count;
7031 * \brief Get available subdevices count from a PCM info container
7032 * \param obj PCM info container
7033 * \return available subdevices count of PCM
7035 unsigned int snd_pcm_info_get_subdevices_avail(const snd_pcm_info_t *obj)
7038 return obj->subdevices_avail;
7042 * \brief Get hardware synchronization ID from a PCM info container
7043 * \param obj PCM info container
7044 * \return hardware synchronization ID
7046 snd_pcm_sync_id_t snd_pcm_info_get_sync(const snd_pcm_info_t *obj)
7048 snd_pcm_sync_id_t res;
7050 memcpy(&res, &obj->sync, sizeof(res));
7055 * \brief Set wanted device inside a PCM info container (see #snd_ctl_pcm_info)
7056 * \param obj PCM info container
7057 * \param val Device number
7059 void snd_pcm_info_set_device(snd_pcm_info_t *obj, unsigned int val)
7066 * \brief Set wanted subdevice inside a PCM info container (see #snd_ctl_pcm_info)
7067 * \param obj PCM info container
7068 * \param val Subdevice number
7070 void snd_pcm_info_set_subdevice(snd_pcm_info_t *obj, unsigned int val)
7073 obj->subdevice = val;
7077 * \brief Set wanted stream inside a PCM info container (see #snd_ctl_pcm_info)
7078 * \param obj PCM info container
7081 void snd_pcm_info_set_stream(snd_pcm_info_t *obj, snd_pcm_stream_t val)
7088 * \brief Application request to access a portion of direct (mmap) area
7089 * \param pcm PCM handle
7090 * \param areas Returned mmap channel areas
7091 * \param offset Returned mmap area offset in area steps (== frames)
7092 * \param frames mmap area portion size in frames (wanted on entry, contiguous available on exit)
7093 * \return 0 on success otherwise a negative error code
7095 * It is necessary to call the snd_pcm_avail_update() function directly before
7096 * this call. Otherwise, this function can return a wrong count of available frames.
7098 * The function should be called before a sample-direct area can be accessed.
7099 * The resulting size parameter is always less or equal to the input count of frames
7100 * and can be zero, if no frames can be processed (the ring buffer is full).
7102 * See the snd_pcm_mmap_commit() function to finish the frame processing in
7105 * The function is thread-safe when built with the proper option.
7107 int snd_pcm_mmap_begin(snd_pcm_t *pcm,
7108 const snd_pcm_channel_area_t **areas,
7109 snd_pcm_uframes_t *offset,
7110 snd_pcm_uframes_t *frames)
7114 err = bad_pcm_state(pcm, P_STATE_RUNNABLE);
7118 err = __snd_pcm_mmap_begin(pcm, areas, offset, frames);
7119 snd_pcm_unlock(pcm);
7124 /* locked version */
7125 int __snd_pcm_mmap_begin(snd_pcm_t *pcm, const snd_pcm_channel_area_t **areas,
7126 snd_pcm_uframes_t *offset, snd_pcm_uframes_t *frames)
7128 snd_pcm_uframes_t cont;
7129 snd_pcm_uframes_t f;
7130 snd_pcm_uframes_t avail;
7131 const snd_pcm_channel_area_t *xareas;
7132 assert(pcm && areas && offset && frames);
7133 xareas = snd_pcm_mmap_areas(pcm);
7137 *offset = *pcm->appl.ptr % pcm->buffer_size;
7138 avail = snd_pcm_mmap_avail(pcm);
7139 if (avail > pcm->buffer_size)
7140 avail = pcm->buffer_size;
7141 cont = pcm->buffer_size - *offset;
7153 * \brief Application has completed the access to area requested with #snd_pcm_mmap_begin
7154 * \param pcm PCM handle
7155 * \param offset area offset in area steps (== frames)
7156 * \param frames area portion size in frames
7157 * \return count of transferred frames otherwise a negative error code
7159 * You should pass this function the offset value that
7160 * snd_pcm_mmap_begin() returned. The frames parameter should hold the
7161 * number of frames you have written or read to/from the audio
7162 * buffer. The frames parameter must never exceed the contiguous frames
7163 * count that snd_pcm_mmap_begin() returned. Each call to snd_pcm_mmap_begin()
7164 * must be followed by a call to snd_pcm_mmap_commit().
7169 const snd_pcm_area_t *areas;
7170 snd_pcm_sframes_t avail, size, commitres;
7171 snd_pcm_uframes_t offset, frames;
7174 avail = snd_pcm_avail_update(pcm);
7177 // at this point, we can transfer at least 'avail' frames
7179 // we want to process frames in chunks (period_size)
7180 if (avail < period_size)
7183 // it is possible that contiguous areas are smaller, thus we use a loop
7187 err = snd_pcm_mmap_begin(pcm_handle, &areas, &offset, &frames);
7190 // this function fills the areas from offset with count of frames
7191 generate_sine(areas, offset, frames, &phase);
7192 commitres = snd_pcm_mmap_commit(pcm_handle, offset, frames);
7193 if (commitres < 0 || commitres != frames)
7194 error(commitres >= 0 ? -EPIPE : commitres);
7201 * Look to the \ref example_test_pcm "Sine-wave generator" example
7202 * for more details about the generate_sine function.
7204 * The function is thread-safe when built with the proper option.
7206 snd_pcm_sframes_t snd_pcm_mmap_commit(snd_pcm_t *pcm,
7207 snd_pcm_uframes_t offset,
7208 snd_pcm_uframes_t frames)
7210 snd_pcm_sframes_t result;
7213 err = bad_pcm_state(pcm, P_STATE_RUNNABLE);
7217 result = __snd_pcm_mmap_commit(pcm, offset, frames);
7218 snd_pcm_unlock(pcm);
7224 snd_pcm_sframes_t __snd_pcm_mmap_commit(snd_pcm_t *pcm,
7225 snd_pcm_uframes_t offset,
7226 snd_pcm_uframes_t frames)
7229 if (CHECK_SANITY(offset != *pcm->appl.ptr % pcm->buffer_size)) {
7230 SNDMSG("commit offset (%ld) doesn't match with appl_ptr (%ld) %% buf_size (%ld)",
7231 offset, *pcm->appl.ptr, pcm->buffer_size);
7234 if (CHECK_SANITY(frames > snd_pcm_mmap_avail(pcm))) {
7235 SNDMSG("commit frames (%ld) overflow (avail = %ld)", frames,
7236 snd_pcm_mmap_avail(pcm));
7239 return pcm->fast_ops->mmap_commit(pcm->fast_op_arg, offset, frames);
7242 int _snd_pcm_poll_descriptor(snd_pcm_t *pcm)
7245 return pcm->poll_fd;
7248 void snd_pcm_areas_from_buf(snd_pcm_t *pcm, snd_pcm_channel_area_t *areas,
7251 unsigned int channel;
7252 unsigned int channels;
7255 channels = pcm->channels;
7256 for (channel = 0; channel < channels; ++channel, ++areas) {
7258 areas->first = channel * pcm->sample_bits;
7259 areas->step = pcm->frame_bits;
7261 snd_pcm_unlock(pcm);
7264 void snd_pcm_areas_from_bufs(snd_pcm_t *pcm, snd_pcm_channel_area_t *areas,
7267 unsigned int channel;
7268 unsigned int channels;
7271 channels = pcm->channels;
7272 for (channel = 0; channel < channels; ++channel, ++areas, ++bufs) {
7273 areas->addr = *bufs;
7275 areas->step = pcm->sample_bits;
7277 snd_pcm_unlock(pcm);
7280 snd_pcm_sframes_t snd_pcm_read_areas(snd_pcm_t *pcm, const snd_pcm_channel_area_t *areas,
7281 snd_pcm_uframes_t offset, snd_pcm_uframes_t size,
7282 snd_pcm_xfer_areas_func_t func)
7284 snd_pcm_uframes_t xfer = 0;
7285 snd_pcm_sframes_t err = 0;
7286 snd_pcm_state_t state;
7291 __snd_pcm_lock(pcm); /* forced lock */
7293 snd_pcm_uframes_t frames;
7294 snd_pcm_sframes_t avail;
7296 state = __snd_pcm_state(pcm);
7298 case SND_PCM_STATE_PREPARED:
7299 err = __snd_pcm_start(pcm);
7303 case SND_PCM_STATE_RUNNING:
7304 err = __snd_pcm_hwsync(pcm);
7308 case SND_PCM_STATE_DRAINING:
7309 case SND_PCM_STATE_PAUSED:
7312 err = pcm_state_to_error(state);
7317 avail = __snd_pcm_avail_update(pcm);
7323 if (state == SND_PCM_STATE_DRAINING)
7325 if (pcm->mode & SND_PCM_NONBLOCK) {
7330 err = __snd_pcm_wait_in_lock(pcm, -1);
7337 if (frames > (snd_pcm_uframes_t) avail)
7341 err = func(pcm, areas, offset, frames);
7350 __snd_pcm_unlock(pcm);
7351 return xfer > 0 ? (snd_pcm_sframes_t) xfer : snd_pcm_check_error(pcm, err);
7354 snd_pcm_sframes_t snd_pcm_write_areas(snd_pcm_t *pcm, const snd_pcm_channel_area_t *areas,
7355 snd_pcm_uframes_t offset, snd_pcm_uframes_t size,
7356 snd_pcm_xfer_areas_func_t func)
7358 snd_pcm_uframes_t xfer = 0;
7359 snd_pcm_sframes_t err = 0;
7360 snd_pcm_state_t state;
7365 __snd_pcm_lock(pcm); /* forced lock */
7367 snd_pcm_uframes_t frames;
7368 snd_pcm_sframes_t avail;
7370 state = __snd_pcm_state(pcm);
7372 case SND_PCM_STATE_PREPARED:
7373 case SND_PCM_STATE_PAUSED:
7375 case SND_PCM_STATE_RUNNING:
7376 err = __snd_pcm_hwsync(pcm);
7381 err = pcm_state_to_error(state);
7386 avail = __snd_pcm_avail_update(pcm);
7391 if (state == SND_PCM_STATE_RUNNING &&
7392 size > (snd_pcm_uframes_t)avail) {
7393 if (snd_pcm_may_wait_for_avail_min(pcm, avail)) {
7394 if (pcm->mode & SND_PCM_NONBLOCK) {
7399 err = snd_pcm_wait_nocheck(pcm, -1);
7404 /* the snd_pcm_may_wait_for_avail_min may check against the
7405 * updated hw.ptr (slaves), get the avail again here
7407 avail = __snd_pcm_avail_update(pcm);
7414 if (frames > (snd_pcm_uframes_t) avail)
7418 err = func(pcm, areas, offset, frames);
7422 if (state == SND_PCM_STATE_PREPARED) {
7423 snd_pcm_sframes_t hw_avail = pcm->buffer_size - avail;
7425 /* some plugins might automatically start the stream */
7426 state = __snd_pcm_state(pcm);
7427 if (state == SND_PCM_STATE_PREPARED &&
7428 hw_avail >= (snd_pcm_sframes_t) pcm->start_threshold) {
7429 err = __snd_pcm_start(pcm);
7439 __snd_pcm_unlock(pcm);
7440 return xfer > 0 ? (snd_pcm_sframes_t) xfer : snd_pcm_check_error(pcm, err);
7443 snd_pcm_uframes_t _snd_pcm_mmap_hw_ptr(snd_pcm_t *pcm)
7445 return *pcm->hw.ptr;
7448 snd_pcm_uframes_t _snd_pcm_boundary(snd_pcm_t *pcm)
7450 return pcm->boundary;
7454 link_warning(_snd_pcm_mmap_hw_ptr, "Warning: _snd_pcm_mmap_hw_ptr() is deprecated, consider to not use this function");
7455 link_warning(_snd_pcm_boundary, "Warning: _snd_pcm_boundary() is deprecated, consider to use snd_pcm_sw_params_current()");
7458 static const char *const names[SND_PCM_HW_PARAM_LAST_INTERVAL + 1] = {
7459 [SND_PCM_HW_PARAM_FORMAT] = "format",
7460 [SND_PCM_HW_PARAM_CHANNELS] = "channels",
7461 [SND_PCM_HW_PARAM_RATE] = "rate",
7462 [SND_PCM_HW_PARAM_PERIOD_TIME] = "period_time",
7463 [SND_PCM_HW_PARAM_PERIOD_SIZE] = "period_size",
7464 [SND_PCM_HW_PARAM_BUFFER_TIME] = "buffer_time",
7465 [SND_PCM_HW_PARAM_BUFFER_SIZE] = "buffer_size",
7466 [SND_PCM_HW_PARAM_PERIODS] = "periods"
7469 int snd_pcm_slave_conf(snd_config_t *root, snd_config_t *conf,
7470 snd_config_t **_pcm_conf, unsigned int count, ...)
7472 snd_config_iterator_t i, next;
7481 snd_config_t *pcm_conf = NULL;
7488 if (snd_config_get_string(conf, &str) >= 0) {
7489 err = snd_config_search_definition(root, "pcm_slave", str, &conf);
7491 SNDERR("Invalid slave definition");
7496 if (snd_config_get_type(conf) != SND_CONFIG_TYPE_COMPOUND) {
7497 SNDERR("Invalid slave definition");
7501 va_start(args, count);
7502 for (k = 0; k < count; ++k) {
7503 fields[k].index = va_arg(args, int);
7504 fields[k].flags = va_arg(args, int);
7505 fields[k].ptr = va_arg(args, void *);
7506 fields[k].present = 0;
7509 snd_config_for_each(i, next, conf) {
7510 snd_config_t *n = snd_config_iterator_entry(i);
7512 if (snd_config_get_id(n, &id) < 0)
7514 if (strcmp(id, "comment") == 0)
7516 if (strcmp(id, "pcm") == 0) {
7517 if (pcm_conf != NULL)
7518 snd_config_delete(pcm_conf);
7519 if ((err = snd_config_copy(&pcm_conf, n)) < 0)
7523 for (k = 0; k < count; ++k) {
7524 unsigned int idx = fields[k].index;
7526 assert(idx < SND_PCM_HW_PARAM_LAST_INTERVAL);
7528 if (strcmp(id, names[idx]) != 0)
7531 case SND_PCM_HW_PARAM_FORMAT:
7534 err = snd_config_get_string(n, &str);
7537 SNDERR("invalid type for %s", id);
7540 if ((fields[k].flags & SCONF_UNCHANGED) &&
7541 strcasecmp(str, "unchanged") == 0) {
7542 *(snd_pcm_format_t*)fields[k].ptr = (snd_pcm_format_t) -2;
7545 f = snd_pcm_format_value(str);
7546 if (f == SND_PCM_FORMAT_UNKNOWN) {
7547 SNDERR("unknown format %s", str);
7551 *(snd_pcm_format_t*)fields[k].ptr = f;
7555 if ((fields[k].flags & SCONF_UNCHANGED)) {
7556 err = snd_config_get_string(n, &str);
7558 strcasecmp(str, "unchanged") == 0) {
7559 *(int*)fields[k].ptr = -2;
7563 err = snd_config_get_integer(n, &v);
7566 *(int*)fields[k].ptr = v;
7569 fields[k].present = 1;
7574 SNDERR("Unknown field %s", id);
7579 SNDERR("missing field pcm");
7583 for (k = 0; k < count; ++k) {
7584 if ((fields[k].flags & SCONF_MANDATORY) && !fields[k].present) {
7585 SNDERR("missing field %s", names[fields[k].index]);
7590 *_pcm_conf = pcm_conf;
7595 snd_config_delete(pcm_conf);
7597 snd_config_delete(conf);
7601 static void snd_pcm_set_ptr(snd_pcm_t *pcm, snd_pcm_rbptr_t *rbptr,
7602 volatile snd_pcm_uframes_t *hw_ptr, int fd, off_t offset)
7604 rbptr->master = NULL; /* I'm master */
7605 rbptr->ptr = hw_ptr;
7607 rbptr->offset = offset;
7609 rbptr->changed(pcm, NULL);
7612 void snd_pcm_set_hw_ptr(snd_pcm_t *pcm, volatile snd_pcm_uframes_t *hw_ptr, int fd, off_t offset)
7616 snd_pcm_set_ptr(pcm, &pcm->hw, hw_ptr, fd, offset);
7619 void snd_pcm_set_appl_ptr(snd_pcm_t *pcm, volatile snd_pcm_uframes_t *appl_ptr, int fd, off_t offset)
7623 snd_pcm_set_ptr(pcm, &pcm->appl, appl_ptr, fd, offset);
7626 static void snd_pcm_link_ptr(snd_pcm_t *pcm, snd_pcm_rbptr_t *pcm_rbptr,
7627 snd_pcm_t *slave, snd_pcm_rbptr_t *slave_rbptr)
7632 a = slave_rbptr->link_dst;
7633 for (idx = 0; idx < slave_rbptr->link_dst_count; idx++)
7634 if (a[idx] == NULL) {
7636 goto __found_free_place;
7638 a = realloc(a, sizeof(snd_pcm_t *) * (slave_rbptr->link_dst_count + 1));
7640 pcm_rbptr->ptr = NULL;
7642 pcm_rbptr->offset = 0UL;
7645 a[slave_rbptr->link_dst_count++] = pcm;
7647 pcm_rbptr->master = slave_rbptr->master ? slave_rbptr->master : slave;
7648 pcm_rbptr->ptr = slave_rbptr->ptr;
7649 pcm_rbptr->fd = slave_rbptr->fd;
7650 pcm_rbptr->offset = slave_rbptr->offset;
7651 slave_rbptr->link_dst = a;
7652 if (pcm_rbptr->changed)
7653 pcm_rbptr->changed(pcm, slave);
7656 static void snd_pcm_unlink_ptr(snd_pcm_t *pcm, snd_pcm_rbptr_t *pcm_rbptr,
7657 snd_pcm_t *slave, snd_pcm_rbptr_t *slave_rbptr)
7662 a = slave_rbptr->link_dst;
7663 for (idx = 0; idx < slave_rbptr->link_dst_count; idx++) {
7664 if (a[idx] == pcm) {
7673 pcm_rbptr->master = NULL;
7674 pcm_rbptr->ptr = NULL;
7676 pcm_rbptr->offset = 0UL;
7677 if (pcm_rbptr->changed)
7678 pcm_rbptr->changed(pcm, slave);
7681 void snd_pcm_link_hw_ptr(snd_pcm_t *pcm, snd_pcm_t *slave)
7685 snd_pcm_link_ptr(pcm, &pcm->hw, slave, &slave->hw);
7688 void snd_pcm_link_appl_ptr(snd_pcm_t *pcm, snd_pcm_t *slave)
7692 snd_pcm_link_ptr(pcm, &pcm->appl, slave, &slave->appl);
7695 void snd_pcm_unlink_hw_ptr(snd_pcm_t *pcm, snd_pcm_t *slave)
7699 snd_pcm_unlink_ptr(pcm, &pcm->hw, slave, &slave->hw);
7702 void snd_pcm_unlink_appl_ptr(snd_pcm_t *pcm, snd_pcm_t *slave)
7706 snd_pcm_unlink_ptr(pcm, &pcm->appl, slave, &slave->appl);
7709 #endif /* DOC_HIDDEN */
7717 #ifdef USE_VERSIONED_SYMBOLS
7719 #define OBSOLETE1(name, what, new) \
7720 default_symbol_version(__##name, name, new); \
7721 symbol_version(__old_##name, name, what);
7725 #define OBSOLETE1(name, what, new) \
7726 use_default_symbol_version(__##name, name, new);
7728 #endif /* USE_VERSIONED_SYMBOLS */
7730 #define __P_OLD_GET(pfx, name, val_type, ret_type) \
7731 ret_type pfx##name(const snd_pcm_hw_params_t *params) \
7734 if (INTERNAL(name)(params, &val) < 0) \
7736 return (ret_type)val; \
7739 #define __P_OLD_GET1(pfx, name, val_type, ret_type) \
7740 ret_type pfx##name(const snd_pcm_hw_params_t *params, int *dir) \
7743 if (INTERNAL(name)(params, &val, dir) < 0) \
7745 return (ret_type)val; \
7748 #define __OLD_GET(name, val_type, ret_type) __P_OLD_GET(__old_, name, val_type, ret_type)
7749 #define __OLD_GET1(name, val_type, ret_type) __P_OLD_GET1(__old_, name, val_type, ret_type)
7751 __OLD_GET(snd_pcm_hw_params_get_access, snd_pcm_access_t, int);
7752 __OLD_GET(snd_pcm_hw_params_get_format, snd_pcm_format_t, int);
7753 __OLD_GET(snd_pcm_hw_params_get_subformat, snd_pcm_subformat_t, int);
7754 __OLD_GET(snd_pcm_hw_params_get_channels, unsigned int, int);
7755 __OLD_GET1(snd_pcm_hw_params_get_rate, unsigned int, int);
7756 __OLD_GET1(snd_pcm_hw_params_get_period_time, unsigned int, int);
7757 __OLD_GET1(snd_pcm_hw_params_get_period_size, snd_pcm_uframes_t, snd_pcm_sframes_t);
7758 __OLD_GET1(snd_pcm_hw_params_get_periods, unsigned int, int);
7759 __OLD_GET1(snd_pcm_hw_params_get_buffer_time, unsigned int, int);
7760 __OLD_GET(snd_pcm_hw_params_get_buffer_size, snd_pcm_uframes_t, snd_pcm_sframes_t);
7761 __OLD_GET1(snd_pcm_hw_params_get_tick_time, unsigned int, int);
7763 __OLD_GET(snd_pcm_hw_params_get_channels_min, unsigned int, unsigned int);
7764 __OLD_GET1(snd_pcm_hw_params_get_rate_min, unsigned int, unsigned int);
7765 __OLD_GET1(snd_pcm_hw_params_get_period_time_min, unsigned int, unsigned int);
7766 __OLD_GET1(snd_pcm_hw_params_get_period_size_min, snd_pcm_uframes_t, snd_pcm_uframes_t);
7767 __OLD_GET1(snd_pcm_hw_params_get_periods_min, unsigned int, unsigned int);
7768 __OLD_GET1(snd_pcm_hw_params_get_buffer_time_min, unsigned int, unsigned int);
7769 __OLD_GET(snd_pcm_hw_params_get_buffer_size_min, snd_pcm_uframes_t, snd_pcm_uframes_t);
7770 __OLD_GET1(snd_pcm_hw_params_get_tick_time_min, unsigned int, unsigned int);
7772 __OLD_GET(snd_pcm_hw_params_get_channels_max, unsigned int, unsigned int);
7773 __OLD_GET1(snd_pcm_hw_params_get_rate_max, unsigned int, unsigned int);
7774 __OLD_GET1(snd_pcm_hw_params_get_period_time_max, unsigned int, unsigned int);
7775 __OLD_GET1(snd_pcm_hw_params_get_period_size_max, snd_pcm_uframes_t, snd_pcm_uframes_t);
7776 __OLD_GET1(snd_pcm_hw_params_get_periods_max, unsigned int, unsigned int);
7777 __OLD_GET1(snd_pcm_hw_params_get_buffer_time_max, unsigned int, unsigned int);
7778 __OLD_GET(snd_pcm_hw_params_get_buffer_size_max, snd_pcm_uframes_t, snd_pcm_uframes_t);
7779 __OLD_GET1(snd_pcm_hw_params_get_tick_time_max, unsigned int, unsigned int);
7781 #define __P_OLD_NEAR(pfx, name, ret_type) \
7782 ret_type pfx##name(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, ret_type val) \
7784 if (INTERNAL(name)(pcm, params, &val) < 0) \
7786 return (ret_type)val; \
7789 #define __P_OLD_NEAR1(pfx, name, ret_type) \
7790 ret_type pfx##name(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, ret_type val, int *dir) \
7792 if (INTERNAL(name)(pcm, params, &val, dir) < 0) \
7794 return (ret_type)val; \
7797 #define __OLD_NEAR(name, ret_type) __P_OLD_NEAR(__old_, name, ret_type)
7798 #define __OLD_NEAR1(name, ret_type) __P_OLD_NEAR1(__old_, name, ret_type)
7800 __OLD_NEAR(snd_pcm_hw_params_set_channels_near, unsigned int);
7801 __OLD_NEAR1(snd_pcm_hw_params_set_rate_near, unsigned int);
7802 __OLD_NEAR1(snd_pcm_hw_params_set_period_time_near, unsigned int);
7803 __OLD_NEAR1(snd_pcm_hw_params_set_period_size_near, snd_pcm_uframes_t);
7804 __OLD_NEAR1(snd_pcm_hw_params_set_periods_near, unsigned int);
7805 __OLD_NEAR1(snd_pcm_hw_params_set_buffer_time_near, unsigned int);
7806 __OLD_NEAR(snd_pcm_hw_params_set_buffer_size_near, snd_pcm_uframes_t);
7807 __OLD_NEAR1(snd_pcm_hw_params_set_tick_time_near, unsigned int);
7809 #define __P_OLD_SET_FL(pfx, name, ret_type) \
7810 ret_type pfx##name(snd_pcm_t *pcm, snd_pcm_hw_params_t *params) \
7813 if (INTERNAL(name)(pcm, params, &val) < 0) \
7815 return (ret_type)val; \
7818 #define __P_OLD_SET_FL1(pfx, name, ret_type) \
7819 ret_type pfx##name(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, int *dir) \
7822 if (INTERNAL(name)(pcm, params, &val, dir) < 0) \
7824 return (ret_type)val; \
7827 #define __OLD_SET_FL(name, ret_type) __P_OLD_SET_FL(__old_, name, ret_type)
7828 #define __OLD_SET_FL1(name, ret_type) __P_OLD_SET_FL1(__old_, name, ret_type)
7830 __OLD_SET_FL(snd_pcm_hw_params_set_access_first, snd_pcm_access_t);
7831 __OLD_SET_FL(snd_pcm_hw_params_set_format_first, snd_pcm_format_t);
7832 __OLD_SET_FL(snd_pcm_hw_params_set_subformat_first, snd_pcm_subformat_t);
7833 __OLD_SET_FL(snd_pcm_hw_params_set_channels_first, unsigned int);
7834 __OLD_SET_FL1(snd_pcm_hw_params_set_rate_first, unsigned int);
7835 __OLD_SET_FL1(snd_pcm_hw_params_set_period_time_first, unsigned int);
7836 __OLD_SET_FL1(snd_pcm_hw_params_set_period_size_first, snd_pcm_uframes_t);
7837 __OLD_SET_FL1(snd_pcm_hw_params_set_periods_first, unsigned int);
7838 __OLD_SET_FL1(snd_pcm_hw_params_set_buffer_time_first, unsigned int);
7839 __OLD_SET_FL(snd_pcm_hw_params_set_buffer_size_first, snd_pcm_uframes_t);
7840 __OLD_SET_FL1(snd_pcm_hw_params_set_tick_time_first, unsigned int);
7842 __OLD_SET_FL(snd_pcm_hw_params_set_access_last, snd_pcm_access_t);
7843 __OLD_SET_FL(snd_pcm_hw_params_set_format_last, snd_pcm_format_t);
7844 __OLD_SET_FL(snd_pcm_hw_params_set_subformat_last, snd_pcm_subformat_t);
7845 __OLD_SET_FL(snd_pcm_hw_params_set_channels_last, unsigned int);
7846 __OLD_SET_FL1(snd_pcm_hw_params_set_rate_last, unsigned int);
7847 __OLD_SET_FL1(snd_pcm_hw_params_set_period_time_last, unsigned int);
7848 __OLD_SET_FL1(snd_pcm_hw_params_set_period_size_last, snd_pcm_uframes_t);
7849 __OLD_SET_FL1(snd_pcm_hw_params_set_periods_last, unsigned int);
7850 __OLD_SET_FL1(snd_pcm_hw_params_set_buffer_time_last, unsigned int);
7851 __OLD_SET_FL(snd_pcm_hw_params_set_buffer_size_last, snd_pcm_uframes_t);
7852 __OLD_SET_FL1(snd_pcm_hw_params_set_tick_time_last, unsigned int);
7854 #define __P_OLD_GET_SW(pfx, name, ret_type) \
7855 ret_type pfx##name(snd_pcm_sw_params_t *params) \
7858 if (INTERNAL(name)(params, &val) < 0) \
7860 return (ret_type)val; \
7863 #define __OLD_GET_SW(name, ret_type) __P_OLD_GET_SW(__old_, name, ret_type)
7865 __OLD_GET_SW(snd_pcm_sw_params_get_tstamp_mode, snd_pcm_tstamp_t);
7866 __OLD_GET_SW(snd_pcm_sw_params_get_sleep_min, unsigned int);
7867 __OLD_GET_SW(snd_pcm_sw_params_get_avail_min, snd_pcm_uframes_t);
7868 __OLD_GET_SW(snd_pcm_sw_params_get_xfer_align, snd_pcm_uframes_t);
7869 __OLD_GET_SW(snd_pcm_sw_params_get_start_threshold, snd_pcm_uframes_t);
7870 __OLD_GET_SW(snd_pcm_sw_params_get_stop_threshold, snd_pcm_uframes_t);
7871 __OLD_GET_SW(snd_pcm_sw_params_get_silence_threshold, snd_pcm_uframes_t);
7872 __OLD_GET_SW(snd_pcm_sw_params_get_silence_size, snd_pcm_uframes_t);
7874 OBSOLETE1(snd_pcm_hw_params_get_access, ALSA_0.9, ALSA_0.9.0rc4);
7875 OBSOLETE1(snd_pcm_hw_params_set_access_first, ALSA_0.9, ALSA_0.9.0rc4);
7876 OBSOLETE1(snd_pcm_hw_params_set_access_last, ALSA_0.9, ALSA_0.9.0rc4);
7878 OBSOLETE1(snd_pcm_hw_params_get_format, ALSA_0.9, ALSA_0.9.0rc4);
7879 OBSOLETE1(snd_pcm_hw_params_set_format_first, ALSA_0.9, ALSA_0.9.0rc4);
7880 OBSOLETE1(snd_pcm_hw_params_set_format_last, ALSA_0.9, ALSA_0.9.0rc4);
7882 OBSOLETE1(snd_pcm_hw_params_get_subformat, ALSA_0.9, ALSA_0.9.0rc4);
7883 OBSOLETE1(snd_pcm_hw_params_set_subformat_first, ALSA_0.9, ALSA_0.9.0rc4);
7884 OBSOLETE1(snd_pcm_hw_params_set_subformat_last, ALSA_0.9, ALSA_0.9.0rc4);
7886 OBSOLETE1(snd_pcm_hw_params_get_channels, ALSA_0.9, ALSA_0.9.0rc4);
7887 OBSOLETE1(snd_pcm_hw_params_get_channels_min, ALSA_0.9, ALSA_0.9.0rc4);
7888 OBSOLETE1(snd_pcm_hw_params_get_channels_max, ALSA_0.9, ALSA_0.9.0rc4);
7889 OBSOLETE1(snd_pcm_hw_params_set_channels_near, ALSA_0.9, ALSA_0.9.0rc4);
7890 OBSOLETE1(snd_pcm_hw_params_set_channels_first, ALSA_0.9, ALSA_0.9.0rc4);
7891 OBSOLETE1(snd_pcm_hw_params_set_channels_last, ALSA_0.9, ALSA_0.9.0rc4);
7893 OBSOLETE1(snd_pcm_hw_params_get_rate, ALSA_0.9, ALSA_0.9.0rc4);
7894 OBSOLETE1(snd_pcm_hw_params_get_rate_min, ALSA_0.9, ALSA_0.9.0rc4);
7895 OBSOLETE1(snd_pcm_hw_params_get_rate_max, ALSA_0.9, ALSA_0.9.0rc4);
7896 OBSOLETE1(snd_pcm_hw_params_set_rate_near, ALSA_0.9, ALSA_0.9.0rc4);
7897 OBSOLETE1(snd_pcm_hw_params_set_rate_first, ALSA_0.9, ALSA_0.9.0rc4);
7898 OBSOLETE1(snd_pcm_hw_params_set_rate_last, ALSA_0.9, ALSA_0.9.0rc4);
7900 OBSOLETE1(snd_pcm_hw_params_get_period_time, ALSA_0.9, ALSA_0.9.0rc4);
7901 OBSOLETE1(snd_pcm_hw_params_get_period_time_min, ALSA_0.9, ALSA_0.9.0rc4);
7902 OBSOLETE1(snd_pcm_hw_params_get_period_time_max, ALSA_0.9, ALSA_0.9.0rc4);
7903 OBSOLETE1(snd_pcm_hw_params_set_period_time_near, ALSA_0.9, ALSA_0.9.0rc4);
7904 OBSOLETE1(snd_pcm_hw_params_set_period_time_first, ALSA_0.9, ALSA_0.9.0rc4);
7905 OBSOLETE1(snd_pcm_hw_params_set_period_time_last, ALSA_0.9, ALSA_0.9.0rc4);
7907 OBSOLETE1(snd_pcm_hw_params_get_period_size, ALSA_0.9, ALSA_0.9.0rc4);
7908 OBSOLETE1(snd_pcm_hw_params_get_period_size_min, ALSA_0.9, ALSA_0.9.0rc4);
7909 OBSOLETE1(snd_pcm_hw_params_get_period_size_max, ALSA_0.9, ALSA_0.9.0rc4);
7910 OBSOLETE1(snd_pcm_hw_params_set_period_size_near, ALSA_0.9, ALSA_0.9.0rc4);
7911 OBSOLETE1(snd_pcm_hw_params_set_period_size_first, ALSA_0.9, ALSA_0.9.0rc4);
7912 OBSOLETE1(snd_pcm_hw_params_set_period_size_last, ALSA_0.9, ALSA_0.9.0rc4);
7914 OBSOLETE1(snd_pcm_hw_params_get_periods, ALSA_0.9, ALSA_0.9.0rc4);
7915 OBSOLETE1(snd_pcm_hw_params_get_periods_min, ALSA_0.9, ALSA_0.9.0rc4);
7916 OBSOLETE1(snd_pcm_hw_params_get_periods_max, ALSA_0.9, ALSA_0.9.0rc4);
7917 OBSOLETE1(snd_pcm_hw_params_set_periods_near, ALSA_0.9, ALSA_0.9.0rc4);
7918 OBSOLETE1(snd_pcm_hw_params_set_periods_first, ALSA_0.9, ALSA_0.9.0rc4);
7919 OBSOLETE1(snd_pcm_hw_params_set_periods_last, ALSA_0.9, ALSA_0.9.0rc4);
7921 OBSOLETE1(snd_pcm_hw_params_get_buffer_time, ALSA_0.9, ALSA_0.9.0rc4);
7922 OBSOLETE1(snd_pcm_hw_params_get_buffer_time_min, ALSA_0.9, ALSA_0.9.0rc4);
7923 OBSOLETE1(snd_pcm_hw_params_get_buffer_time_max, ALSA_0.9, ALSA_0.9.0rc4);
7924 OBSOLETE1(snd_pcm_hw_params_set_buffer_time_near, ALSA_0.9, ALSA_0.9.0rc4);
7925 OBSOLETE1(snd_pcm_hw_params_set_buffer_time_first, ALSA_0.9, ALSA_0.9.0rc4);
7926 OBSOLETE1(snd_pcm_hw_params_set_buffer_time_last, ALSA_0.9, ALSA_0.9.0rc4);
7928 OBSOLETE1(snd_pcm_hw_params_get_buffer_size, ALSA_0.9, ALSA_0.9.0rc4);
7929 OBSOLETE1(snd_pcm_hw_params_get_buffer_size_min, ALSA_0.9, ALSA_0.9.0rc4);
7930 OBSOLETE1(snd_pcm_hw_params_get_buffer_size_max, ALSA_0.9, ALSA_0.9.0rc4);
7931 OBSOLETE1(snd_pcm_hw_params_set_buffer_size_near, ALSA_0.9, ALSA_0.9.0rc4);
7932 OBSOLETE1(snd_pcm_hw_params_set_buffer_size_first, ALSA_0.9, ALSA_0.9.0rc4);
7933 OBSOLETE1(snd_pcm_hw_params_set_buffer_size_last, ALSA_0.9, ALSA_0.9.0rc4);
7935 OBSOLETE1(snd_pcm_hw_params_get_tick_time, ALSA_0.9, ALSA_0.9.0rc4);
7936 OBSOLETE1(snd_pcm_hw_params_get_tick_time_min, ALSA_0.9, ALSA_0.9.0rc4);
7937 OBSOLETE1(snd_pcm_hw_params_get_tick_time_max, ALSA_0.9, ALSA_0.9.0rc4);
7938 OBSOLETE1(snd_pcm_hw_params_set_tick_time_near, ALSA_0.9, ALSA_0.9.0rc4);
7939 OBSOLETE1(snd_pcm_hw_params_set_tick_time_first, ALSA_0.9, ALSA_0.9.0rc4);
7940 OBSOLETE1(snd_pcm_hw_params_set_tick_time_last, ALSA_0.9, ALSA_0.9.0rc4);
7942 OBSOLETE1(snd_pcm_sw_params_get_tstamp_mode, ALSA_0.9, ALSA_0.9.0rc4);
7943 OBSOLETE1(snd_pcm_sw_params_get_sleep_min, ALSA_0.9, ALSA_0.9.0rc4);
7944 OBSOLETE1(snd_pcm_sw_params_get_avail_min, ALSA_0.9, ALSA_0.9.0rc4);
7945 OBSOLETE1(snd_pcm_sw_params_get_xfer_align, ALSA_0.9, ALSA_0.9.0rc4);
7946 OBSOLETE1(snd_pcm_sw_params_get_start_threshold, ALSA_0.9, ALSA_0.9.0rc4);
7947 OBSOLETE1(snd_pcm_sw_params_get_stop_threshold, ALSA_0.9, ALSA_0.9.0rc4);
7948 OBSOLETE1(snd_pcm_sw_params_get_silence_threshold, ALSA_0.9, ALSA_0.9.0rc4);
7949 OBSOLETE1(snd_pcm_sw_params_get_silence_size, ALSA_0.9, ALSA_0.9.0rc4);
7951 #endif /* DOC_HIDDEN */
7953 static int chmap_equal(const snd_pcm_chmap_t *a, const snd_pcm_chmap_t *b)
7955 if (a->channels != b->channels)
7957 return !memcmp(a->pos, b->pos, a->channels * sizeof(a->pos[0]));
7961 * \!brief Query the available channel maps
7962 * \param pcm PCM handle to query
7963 * \return the NULL-terminated array of integer pointers, each of
7964 * which contains the channel map. A channel map is represented by an
7965 * integer array, beginning with the channel map type, followed by the
7966 * number of channels, and the position of each channel.
7968 * Note: the caller is requested to release the returned value via
7969 * snd_pcm_free_chmaps().
7971 snd_pcm_chmap_query_t **snd_pcm_query_chmaps(snd_pcm_t *pcm)
7973 if (!pcm->ops->query_chmaps)
7975 return pcm->ops->query_chmaps(pcm);
7979 * \!brief Release the channel map array allocated via #snd_pcm_query_chmaps
7980 * \param maps the array pointer to release
7982 void snd_pcm_free_chmaps(snd_pcm_chmap_query_t **maps)
7984 snd_pcm_chmap_query_t **p;
7987 for (p = maps; *p; p++)
7993 * \!brief Get the current channel map
7994 * \param pcm PCM instance
7995 * \return the current channel map, or NULL if error
7997 * Note: the caller is requested to release the returned value via free()
7999 snd_pcm_chmap_t *snd_pcm_get_chmap(snd_pcm_t *pcm)
8001 if (!pcm->ops->get_chmap)
8003 return pcm->ops->get_chmap(pcm);
8007 * \!brief Configure the current channel map
8008 * \param pcm PCM instance
8009 * \param map the channel map to write
8010 * \return zero if succeeded, or a negative error code
8012 int snd_pcm_set_chmap(snd_pcm_t *pcm, const snd_pcm_chmap_t *map)
8014 const snd_pcm_chmap_t *oldmap = snd_pcm_get_chmap(pcm);
8015 if (oldmap && chmap_equal(oldmap, map))
8018 if (!pcm->ops->set_chmap)
8020 return pcm->ops->set_chmap(pcm, map);
8026 #define _NAME(n) [SND_CHMAP_TYPE_##n] = #n
8027 static const char *chmap_type_names[SND_CHMAP_TYPE_LAST + 1] = {
8028 _NAME(NONE), _NAME(FIXED), _NAME(VAR), _NAME(PAIRED),
8034 * \!brief Get a name string for a channel map type as query results
8035 * \param val Channel position
8036 * \return The string corresponding to the given type, or NULL
8038 const char *snd_pcm_chmap_type_name(enum snd_pcm_chmap_type val)
8040 if (val <= SND_CHMAP_TYPE_LAST)
8041 return chmap_type_names[val];
8047 #define _NAME(n) [SND_CHMAP_##n] = #n
8048 static const char *chmap_names[SND_CHMAP_LAST + 1] = {
8049 _NAME(UNKNOWN), _NAME(NA), _NAME(MONO),
8050 _NAME(FL), _NAME(FR),
8051 _NAME(RL), _NAME(RR),
8052 _NAME(FC), _NAME(LFE),
8053 _NAME(SL), _NAME(SR),
8054 _NAME(RC), _NAME(FLC), _NAME(FRC), _NAME(RLC), _NAME(RRC),
8055 _NAME(FLW), _NAME(FRW),
8056 _NAME(FLH), _NAME(FCH), _NAME(FRH), _NAME(TC),
8057 _NAME(TFL), _NAME(TFR), _NAME(TFC),
8058 _NAME(TRL), _NAME(TRR), _NAME(TRC),
8059 _NAME(TFLC), _NAME(TFRC), _NAME(TSL), _NAME(TSR),
8060 _NAME(LLFE), _NAME(RLFE),
8061 _NAME(BC), _NAME(BLC), _NAME(BRC),
8067 * \!brief Get a name string for a standard channel map position
8068 * \param val Channel position
8069 * \return The string corresponding to the given position, or NULL
8071 const char *snd_pcm_chmap_name(enum snd_pcm_chmap_position val)
8073 if (val <= SND_CHMAP_LAST)
8074 return chmap_names[val];
8079 static const char *chmap_long_names[SND_CHMAP_LAST + 1] = {
8080 [SND_CHMAP_UNKNOWN] = "Unknown",
8081 [SND_CHMAP_NA] = "Unused",
8082 [SND_CHMAP_MONO] = "Mono",
8083 [SND_CHMAP_FL] = "Front Left",
8084 [SND_CHMAP_FR] = "Front Right",
8085 [SND_CHMAP_RL] = "Rear Left",
8086 [SND_CHMAP_RR] = "Rear Right",
8087 [SND_CHMAP_FC] = "Front Center",
8088 [SND_CHMAP_LFE] = "LFE",
8089 [SND_CHMAP_SL] = "Side Left",
8090 [SND_CHMAP_SR] = "Side Right",
8091 [SND_CHMAP_RC] = "Rear Center",
8092 [SND_CHMAP_FLC] = "Front Left Center",
8093 [SND_CHMAP_FRC] = "Front Right Center",
8094 [SND_CHMAP_RLC] = "Rear Left Center",
8095 [SND_CHMAP_RRC] = "Rear Right Center",
8096 [SND_CHMAP_FLW] = "Front Left Wide",
8097 [SND_CHMAP_FRW] = "Front Right Wide",
8098 [SND_CHMAP_FLH] = "Front Left High",
8099 [SND_CHMAP_FCH] = "Front Center High",
8100 [SND_CHMAP_FRH] = "Front Right High",
8101 [SND_CHMAP_TC] = "Top Center",
8102 [SND_CHMAP_TFL] = "Top Front Left",
8103 [SND_CHMAP_TFR] = "Top Front Right",
8104 [SND_CHMAP_TFC] = "Top Front Center",
8105 [SND_CHMAP_TRL] = "Top Rear Left",
8106 [SND_CHMAP_TRR] = "Top Rear Right",
8107 [SND_CHMAP_TRC] = "Top Rear Center",
8108 [SND_CHMAP_TFLC] = "Top Front Left Center",
8109 [SND_CHMAP_TFRC] = "Top Front Right Center",
8110 [SND_CHMAP_TSL] = "Top Side Left",
8111 [SND_CHMAP_TSR] = "Top Side Right",
8112 [SND_CHMAP_LLFE] = "Left LFE",
8113 [SND_CHMAP_RLFE] = "Right LFE",
8114 [SND_CHMAP_BC] = "Bottom Center",
8115 [SND_CHMAP_BLC] = "Bottom Left Center",
8116 [SND_CHMAP_BRC] = "Bottom Right Center",
8120 * \!brief Get a longer name string for a standard channel map position
8121 * \param val Channel position
8122 * \return The string corresponding to the given position, or NULL
8124 const char *snd_pcm_chmap_long_name(enum snd_pcm_chmap_position val)
8126 if (val <= SND_CHMAP_LAST)
8127 return chmap_long_names[val];
8133 * \!brief Print the channels in chmap on the buffer
8134 * \param map The channel map to print
8135 * \param maxlen The maximal length to write (including NUL letter)
8136 * \param buf The buffer to write
8137 * \return The actual string length or a negative error code
8139 int snd_pcm_chmap_print(const snd_pcm_chmap_t *map, size_t maxlen, char *buf)
8141 unsigned int i, len = 0;
8143 for (i = 0; i < map->channels; i++) {
8144 unsigned int p = map->pos[i] & SND_CHMAP_POSITION_MASK;
8146 len += snprintf(buf + len, maxlen - len, " ");
8150 if (map->pos[i] & SND_CHMAP_DRIVER_SPEC)
8151 len += snprintf(buf + len, maxlen - len, "%d", p);
8153 const char *name = chmap_names[p];
8155 len += snprintf(buf + len, maxlen - len,
8158 len += snprintf(buf + len, maxlen - len,
8163 if (map->pos[i] & SND_CHMAP_PHASE_INVERSE) {
8164 len += snprintf(buf + len, maxlen - len, "[INV]");
8172 static int str_to_chmap(const char *str, int len)
8178 if (isdigit(*str)) {
8179 v = strtoul(str, &p, 0);
8183 val |= SND_CHMAP_DRIVER_SPEC;
8185 } else if (!strncasecmp(str, "ch", 2)) {
8186 v = strtoul(str + 2, &p, 0);
8192 for (val = 0; val <= SND_CHMAP_LAST; val++) {
8194 assert(chmap_names[val]);
8195 slen = strlen(chmap_names[val]);
8198 if (!strncasecmp(str, chmap_names[val], slen) &&
8199 !isalpha(str[slen])) {
8204 if (val > SND_CHMAP_LAST)
8207 if (str && !strncasecmp(str, "[INV]", 5))
8208 val |= SND_CHMAP_PHASE_INVERSE;
8213 * \!brief Convert from string to channel position
8214 * \param str The string to parse
8215 * \return The channel position value or -1 as an error
8217 unsigned int snd_pcm_chmap_from_string(const char *str)
8219 return str_to_chmap(str, strlen(str));
8223 * \!brief Convert from string to channel map
8224 * \param str The string to parse
8225 * \return The channel map
8227 * Note: the caller is requested to release the returned value via free()
8229 snd_pcm_chmap_t *snd_pcm_chmap_parse_string(const char *str)
8233 snd_pcm_chmap_t *map;
8239 if (ch >= (int)(sizeof(tmp_map) / sizeof(tmp_map[0])))
8241 for (p = str; *p && isalnum(*p); p++)
8246 val = str_to_chmap(str, len);
8251 if (!strncmp(str, "[INV]", 5)) {
8252 val |= SND_CHMAP_PHASE_INVERSE;
8258 for (; *str && !isalnum(*str); str++)
8263 map = malloc(sizeof(*map) + ch * sizeof(int));
8267 for (i = 0; i < ch; i++)
8268 map->pos[i] = tmp_map[i];
8272 /* copy a single channel map with the fixed type to chmap_query pointer */
8273 static int _copy_to_fixed_query_map(snd_pcm_chmap_query_t **dst,
8274 const snd_pcm_chmap_t *src)
8276 *dst = malloc((src->channels + 2) * sizeof(int));
8279 (*dst)->type = SND_CHMAP_TYPE_FIXED;
8280 memcpy(&(*dst)->map, src, (src->channels + 1) * sizeof(int));
8285 /* make a chmap_query array from a single channel map */
8286 snd_pcm_chmap_query_t **
8287 _snd_pcm_make_single_query_chmaps(const snd_pcm_chmap_t *src)
8289 snd_pcm_chmap_query_t **maps;
8291 maps = calloc(2, sizeof(*maps));
8294 if (_copy_to_fixed_query_map(maps, src)) {
8301 /* make a copy of chmap */
8302 snd_pcm_chmap_t *_snd_pcm_copy_chmap(const snd_pcm_chmap_t *src)
8304 snd_pcm_chmap_t *map;
8306 map = malloc((src->channels + 1) * sizeof(int));
8309 memcpy(map, src, (src->channels + 1) * sizeof(int));
8313 /* make a copy of channel maps */
8314 snd_pcm_chmap_query_t **
8315 _snd_pcm_copy_chmap_query(snd_pcm_chmap_query_t * const *src)
8317 snd_pcm_chmap_query_t * const *p;
8318 snd_pcm_chmap_query_t **maps;
8321 for (nums = 0, p = src; *p; p++)
8324 maps = calloc(nums + 1, sizeof(*maps));
8327 for (i = 0; i < nums; i++) {
8328 maps[i] = malloc((src[i]->map.channels + 2) * sizeof(int));
8330 snd_pcm_free_chmaps(maps);
8333 memcpy(maps[i], src[i], (src[i]->map.channels + 2) * sizeof(int));
8338 /* select the channel map with the current PCM channels and make a copy */
8340 _snd_pcm_choose_fixed_chmap(snd_pcm_t *pcm, snd_pcm_chmap_query_t * const *maps)
8342 snd_pcm_chmap_query_t * const *p;
8344 for (p = maps; *p; p++) {
8345 if ((*p)->map.channels == pcm->channels)
8346 return _snd_pcm_copy_chmap(&(*p)->map);
8351 /* make chmap_query array from the config tree;
8352 * conf must be a compound (array)
8354 snd_pcm_chmap_query_t **
8355 _snd_pcm_parse_config_chmaps(snd_config_t *conf)
8357 snd_pcm_chmap_t *chmap;
8358 snd_pcm_chmap_query_t **maps;
8359 snd_config_iterator_t i, next;
8363 if (snd_config_get_type(conf) != SND_CONFIG_TYPE_COMPOUND)
8367 snd_config_for_each(i, next, conf) {
8371 maps = calloc(nums + 1, sizeof(*maps));
8376 snd_config_for_each(i, next, conf) {
8377 snd_config_t *n = snd_config_iterator_entry(i);
8378 err = snd_config_get_string(n, &str);
8381 chmap = snd_pcm_chmap_parse_string(str);
8384 if (_copy_to_fixed_query_map(maps + nums, chmap)) {
8393 snd_pcm_free_chmaps(maps);
8396 #endif /* DOC_HIDDEN */
8404 * \brief Recover the stream state from an error or suspend
8405 * \param pcm PCM handle
8406 * \param err error number
8407 * \param silent do not print error reason
8408 * \return 0 when error code was handled successfuly, otherwise a negative error code
8410 * This a high-level helper function building on other functions.
8412 * This functions handles -EINTR (interrupted system call),
8413 * -EPIPE (overrun or underrun) and -ESTRPIPE (stream is suspended)
8414 * error codes trying to prepare given stream for next I/O.
8416 * Note that this function returs the original error code when it is not
8417 * handled inside this function (for example -EAGAIN is returned back).
8419 int snd_pcm_recover(snd_pcm_t *pcm, int err, int silent)
8423 if (err == -EINTR) /* nothing to do, continue */
8425 if (err == -EPIPE) {
8427 if (snd_pcm_stream(pcm) == SND_PCM_STREAM_PLAYBACK)
8432 SNDERR("%s occurred", s);
8433 err = snd_pcm_prepare(pcm);
8435 SNDERR("cannot recovery from %s, prepare failed: %s", s, snd_strerror(err));
8440 if (err == -ESTRPIPE) {
8441 while ((err = snd_pcm_resume(pcm)) == -EAGAIN)
8442 /* wait until suspend flag is released */
8443 poll(NULL, 0, 1000);
8445 err = snd_pcm_prepare(pcm);
8447 SNDERR("cannot recovery from suspend, prepare failed: %s", snd_strerror(err));
8457 * \brief Set the hardware and software parameters in a simple way
8458 * \param pcm PCM handle
8459 * \param format required PCM format
8460 * \param access required PCM access
8461 * \param channels required PCM channels
8462 * \param rate required sample rate in Hz
8463 * \param soft_resample 0 = disallow alsa-lib resample stream, 1 = allow resampling
8464 * \param latency required overall latency in us
8465 * \return 0 on success otherwise a negative error code
8467 int snd_pcm_set_params(snd_pcm_t *pcm,
8468 snd_pcm_format_t format,
8469 snd_pcm_access_t access,
8470 unsigned int channels,
8473 unsigned int latency)
8475 snd_pcm_hw_params_t params_saved, params = {0};
8476 snd_pcm_sw_params_t swparams = {0};
8477 const char *s = snd_pcm_stream_name(snd_pcm_stream(pcm));
8478 snd_pcm_uframes_t buffer_size, period_size;
8479 unsigned int rrate, period_time;
8483 /* choose all parameters */
8484 err = snd_pcm_hw_params_any(pcm, ¶ms);
8486 SNDERR("Broken configuration for %s: no configurations available",
8490 /* set software resampling */
8491 err = snd_pcm_hw_params_set_rate_resample(pcm, ¶ms, soft_resample);
8493 SNDERR("Resampling setup failed for %s: %s",
8494 s, snd_strerror(err));
8497 /* set the selected read/write format */
8498 err = snd_pcm_hw_params_set_access(pcm, ¶ms, access);
8500 SNDERR("Access type not available for %s: %s",
8501 s, snd_strerror(err));
8504 /* set the sample format */
8505 err = snd_pcm_hw_params_set_format(pcm, ¶ms, format);
8507 SNDERR("Sample format not available for %s: %s",
8508 s, snd_strerror(err));
8511 /* set the count of channels */
8512 err = snd_pcm_hw_params_set_channels(pcm, ¶ms, channels);
8514 SNDERR("Channels count (%i) not available for %s: %s",
8515 channels, s, snd_strerror(err));
8518 /* set the stream rate */
8520 err = INTERNAL(snd_pcm_hw_params_set_rate_near)(pcm, ¶ms, &rrate,
8523 SNDERR("Rate %iHz not available for playback: %s",
8524 rate, snd_strerror(err));
8527 if (rrate != rate) {
8528 SNDERR("Rate doesn't match (requested %iHz, get %iHz)",
8532 /* set the buffer time */
8533 params_saved = params;
8534 err = INTERNAL(snd_pcm_hw_params_set_buffer_time_near)(pcm, ¶ms,
8537 /* error path -> set period size as first */
8538 params = params_saved;
8539 /* set the period time */
8540 period_time = latency / 4;
8541 err = INTERNAL(snd_pcm_hw_params_set_period_time_near)(pcm,
8542 ¶ms, &period_time, NULL);
8544 SNDERR("Unable to set period time %i for %s: %s",
8545 period_time, s, snd_strerror(err));
8548 err = INTERNAL(snd_pcm_hw_params_get_period_size)(¶ms,
8549 &period_size, NULL);
8551 SNDERR("Unable to get period size for %s: %s",
8552 s, snd_strerror(err));
8555 buffer_size = period_size * 4;
8556 err = INTERNAL(snd_pcm_hw_params_set_buffer_size_near)(pcm,
8557 ¶ms, &buffer_size);
8559 SNDERR("Unable to set buffer size %lu %s: %s",
8560 buffer_size, s, snd_strerror(err));
8563 err = INTERNAL(snd_pcm_hw_params_get_buffer_size)(¶ms,
8566 SNDERR("Unable to get buffer size for %s: %s",
8567 s, snd_strerror(err));
8571 /* standard configuration buffer_time -> periods */
8572 err = INTERNAL(snd_pcm_hw_params_get_buffer_size)(¶ms,
8575 SNDERR("Unable to get buffer size for %s: %s",
8576 s, snd_strerror(err));
8579 err = INTERNAL(snd_pcm_hw_params_get_buffer_time)(¶ms,
8582 SNDERR("Unable to get buffer time (latency) for %s: %s",
8583 s, snd_strerror(err));
8586 /* set the period time */
8587 period_time = latency / 4;
8588 err = INTERNAL(snd_pcm_hw_params_set_period_time_near)(pcm,
8589 ¶ms, &period_time, NULL);
8591 SNDERR("Unable to set period time %i for %s: %s",
8592 period_time, s, snd_strerror(err));
8595 err = INTERNAL(snd_pcm_hw_params_get_period_size)(¶ms,
8596 &period_size, NULL);
8598 SNDERR("Unable to get period size for %s: %s",
8599 s, snd_strerror(err));
8603 /* write the parameters to device */
8604 err = snd_pcm_hw_params(pcm, ¶ms);
8606 SNDERR("Unable to set hw params for %s: %s",
8607 s, snd_strerror(err));
8611 /* get the current swparams */
8612 err = snd_pcm_sw_params_current(pcm, &swparams);
8614 SNDERR("Unable to determine current swparams for %s: %s",
8615 s, snd_strerror(err));
8619 * start the transfer when the buffer is almost full:
8620 * (buffer_size / avail_min) * avail_min
8622 err = snd_pcm_sw_params_set_start_threshold(pcm, &swparams,
8623 (buffer_size / period_size) * period_size);
8625 SNDERR("Unable to set start threshold mode for %s: %s",
8626 s, snd_strerror(err));
8630 * allow the transfer when at least period_size samples can be
8633 err = snd_pcm_sw_params_set_avail_min(pcm, &swparams, period_size);
8635 SNDERR("Unable to set avail min for %s: %s",
8636 s, snd_strerror(err));
8639 /* write the parameters to the playback device */
8640 err = snd_pcm_sw_params(pcm, &swparams);
8642 SNDERR("Unable to set sw params for %s: %s",
8643 s, snd_strerror(err));
8650 * \brief Get the transfer size parameters in a simple way
8651 * \param pcm PCM handle
8652 * \param buffer_size PCM ring buffer size in frames
8653 * \param period_size PCM period size in frames
8654 * \return 0 on success otherwise a negative error code
8656 int snd_pcm_get_params(snd_pcm_t *pcm,
8657 snd_pcm_uframes_t *buffer_size,
8658 snd_pcm_uframes_t *period_size)
8660 snd_pcm_hw_params_t params = {0};
8664 err = snd_pcm_hw_params_current(pcm, ¶ms);
8667 err = INTERNAL(snd_pcm_hw_params_get_buffer_size)(¶ms, buffer_size);
8670 return INTERNAL(snd_pcm_hw_params_get_period_size)(¶ms, period_size,