2 * Digital Audio (PCM) abstract layer
3 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
4 * Abramo Bagnara <abramo@alsa-project.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <sound/driver.h>
24 #include <linux/slab.h>
25 #include <linux/time.h>
26 #include <sound/core.h>
27 #include <sound/control.h>
28 #include <sound/info.h>
29 #include <sound/pcm.h>
30 #include <sound/pcm_params.h>
31 #include <sound/timer.h>
34 * fill ring buffer with silence
35 * runtime->silence_start: starting pointer to silence area
36 * runtime->silence_filled: size filled with silence
37 * runtime->silence_threshold: threshold from application
38 * runtime->silence_size: maximal size from application
40 * when runtime->silence_size >= runtime->boundary - fill processed area with silence immediately
42 void snd_pcm_playback_silence(snd_pcm_substream_t *substream, snd_pcm_uframes_t new_hw_ptr)
44 snd_pcm_runtime_t *runtime = substream->runtime;
45 snd_pcm_uframes_t frames, ofs, transfer;
47 if (runtime->silence_size < runtime->boundary) {
48 snd_pcm_sframes_t noise_dist, n;
49 if (runtime->silence_start != runtime->control->appl_ptr) {
50 n = runtime->control->appl_ptr - runtime->silence_start;
52 n += runtime->boundary;
53 if ((snd_pcm_uframes_t)n < runtime->silence_filled)
54 runtime->silence_filled -= n;
56 runtime->silence_filled = 0;
57 runtime->silence_start = runtime->control->appl_ptr;
59 if (runtime->silence_filled == runtime->buffer_size)
61 snd_assert(runtime->silence_filled <= runtime->buffer_size, return);
62 noise_dist = snd_pcm_playback_hw_avail(runtime) + runtime->silence_filled;
63 if (noise_dist >= (snd_pcm_sframes_t) runtime->silence_threshold)
65 frames = runtime->silence_threshold - noise_dist;
66 if (frames > runtime->silence_size)
67 frames = runtime->silence_size;
69 if (new_hw_ptr == ULONG_MAX) { /* initialization */
70 snd_pcm_sframes_t avail = snd_pcm_playback_hw_avail(runtime);
71 runtime->silence_filled = avail > 0 ? avail : 0;
72 runtime->silence_start = (runtime->status->hw_ptr +
73 runtime->silence_filled) %
76 ofs = runtime->status->hw_ptr;
77 frames = new_hw_ptr - ofs;
78 if ((snd_pcm_sframes_t)frames < 0)
79 frames += runtime->boundary;
80 runtime->silence_filled -= frames;
81 if ((snd_pcm_sframes_t)runtime->silence_filled < 0) {
82 runtime->silence_filled = 0;
83 runtime->silence_start = (ofs + frames) - runtime->buffer_size;
85 runtime->silence_start = ofs - runtime->silence_filled;
87 if ((snd_pcm_sframes_t)runtime->silence_start < 0)
88 runtime->silence_start += runtime->boundary;
90 frames = runtime->buffer_size - runtime->silence_filled;
92 snd_assert(frames <= runtime->buffer_size, return);
95 ofs = (runtime->silence_start + runtime->silence_filled) % runtime->buffer_size;
97 transfer = ofs + frames > runtime->buffer_size ? runtime->buffer_size - ofs : frames;
98 if (runtime->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED ||
99 runtime->access == SNDRV_PCM_ACCESS_MMAP_INTERLEAVED) {
100 if (substream->ops->silence) {
102 err = substream->ops->silence(substream, -1, ofs, transfer);
103 snd_assert(err >= 0, );
105 char *hwbuf = runtime->dma_area + frames_to_bytes(runtime, ofs);
106 snd_pcm_format_set_silence(runtime->format, hwbuf, transfer * runtime->channels);
110 unsigned int channels = runtime->channels;
111 if (substream->ops->silence) {
112 for (c = 0; c < channels; ++c) {
114 err = substream->ops->silence(substream, c, ofs, transfer);
115 snd_assert(err >= 0, );
118 size_t dma_csize = runtime->dma_bytes / channels;
119 for (c = 0; c < channels; ++c) {
120 char *hwbuf = runtime->dma_area + (c * dma_csize) + samples_to_bytes(runtime, ofs);
121 snd_pcm_format_set_silence(runtime->format, hwbuf, transfer);
125 runtime->silence_filled += transfer;
131 static inline snd_pcm_uframes_t snd_pcm_update_hw_ptr_pos(snd_pcm_substream_t *substream,
132 snd_pcm_runtime_t *runtime)
134 snd_pcm_uframes_t pos;
136 pos = substream->ops->pointer(substream);
137 if (runtime->tstamp_mode & SNDRV_PCM_TSTAMP_MMAP)
138 snd_timestamp_now((snd_timestamp_t*)&runtime->status->tstamp, runtime->tstamp_timespec);
139 #ifdef CONFIG_SND_DEBUG
140 if (pos >= runtime->buffer_size) {
141 snd_printk(KERN_ERR "BUG: stream = %i, pos = 0x%lx, buffer size = 0x%lx, period size = 0x%lx\n", substream->stream, pos, runtime->buffer_size, runtime->period_size);
144 snd_runtime_check(pos < runtime->buffer_size, return 0);
145 pos -= pos % runtime->min_align;
149 static inline int snd_pcm_update_hw_ptr_post(snd_pcm_substream_t *substream,
150 snd_pcm_runtime_t *runtime)
152 snd_pcm_uframes_t avail;
154 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
155 avail = snd_pcm_playback_avail(runtime);
157 avail = snd_pcm_capture_avail(runtime);
158 if (avail > runtime->avail_max)
159 runtime->avail_max = avail;
160 if (avail >= runtime->stop_threshold) {
161 snd_pcm_stop(substream,
162 runtime->status->state == SNDRV_PCM_STATE_DRAINING ?
163 SNDRV_PCM_STATE_SETUP : SNDRV_PCM_STATE_XRUN);
164 #ifdef CONFIG_SND_DEBUG
165 if (substream->pstr->xrun_debug) {
166 snd_printd(KERN_DEBUG "XRUN: pcmC%dD%d%c\n",
167 substream->pcm->card->number,
168 substream->pcm->device,
169 substream->stream ? 'c' : 'p');
170 if (substream->pstr->xrun_debug > 1)
176 if (avail >= runtime->control->avail_min)
177 wake_up(&runtime->sleep);
181 static inline int snd_pcm_update_hw_ptr_interrupt(snd_pcm_substream_t *substream)
183 snd_pcm_runtime_t *runtime = substream->runtime;
184 snd_pcm_uframes_t pos;
185 snd_pcm_uframes_t new_hw_ptr, hw_ptr_interrupt;
186 snd_pcm_sframes_t delta;
188 pos = snd_pcm_update_hw_ptr_pos(substream, runtime);
189 if (runtime->period_size == runtime->buffer_size)
191 new_hw_ptr = runtime->hw_ptr_base + pos;
192 hw_ptr_interrupt = runtime->hw_ptr_interrupt + runtime->period_size;
194 delta = hw_ptr_interrupt - new_hw_ptr;
196 if ((snd_pcm_uframes_t)delta < runtime->buffer_size / 2) {
197 #ifdef CONFIG_SND_DEBUG
198 if (runtime->periods > 1 && substream->pstr->xrun_debug) {
199 snd_printd(KERN_ERR "Unexpected hw_pointer value [1] (stream = %i, delta: -%ld, max jitter = %ld): wrong interrupt acknowledge?\n", substream->stream, (long) delta, runtime->buffer_size / 2);
200 if (substream->pstr->xrun_debug > 1)
207 runtime->hw_ptr_base += runtime->buffer_size;
208 if (runtime->hw_ptr_base == runtime->boundary)
209 runtime->hw_ptr_base = 0;
210 new_hw_ptr = runtime->hw_ptr_base + pos;
213 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
214 runtime->silence_size > 0)
215 snd_pcm_playback_silence(substream, new_hw_ptr);
217 runtime->status->hw_ptr = new_hw_ptr;
218 runtime->hw_ptr_interrupt = new_hw_ptr - new_hw_ptr % runtime->period_size;
220 return snd_pcm_update_hw_ptr_post(substream, runtime);
223 /* CAUTION: call it with irq disabled */
224 int snd_pcm_update_hw_ptr(snd_pcm_substream_t *substream)
226 snd_pcm_runtime_t *runtime = substream->runtime;
227 snd_pcm_uframes_t pos;
228 snd_pcm_uframes_t old_hw_ptr, new_hw_ptr;
229 snd_pcm_sframes_t delta;
231 old_hw_ptr = runtime->status->hw_ptr;
232 pos = snd_pcm_update_hw_ptr_pos(substream, runtime);
233 new_hw_ptr = runtime->hw_ptr_base + pos;
235 delta = old_hw_ptr - new_hw_ptr;
237 if ((snd_pcm_uframes_t)delta < runtime->buffer_size / 2) {
238 #ifdef CONFIG_SND_DEBUG
239 if (runtime->periods > 2 && substream->pstr->xrun_debug) {
240 snd_printd(KERN_ERR "Unexpected hw_pointer value [2] (stream = %i, delta: -%ld, max jitter = %ld): wrong interrupt acknowledge?\n", substream->stream, (long) delta, runtime->buffer_size / 2);
241 if (substream->pstr->xrun_debug > 1)
247 runtime->hw_ptr_base += runtime->buffer_size;
248 if (runtime->hw_ptr_base == runtime->boundary)
249 runtime->hw_ptr_base = 0;
250 new_hw_ptr = runtime->hw_ptr_base + pos;
252 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
253 runtime->silence_size > 0)
254 snd_pcm_playback_silence(substream, new_hw_ptr);
256 runtime->status->hw_ptr = new_hw_ptr;
258 return snd_pcm_update_hw_ptr_post(substream, runtime);
262 * snd_pcm_set_ops - set the PCM operators
263 * @pcm: the pcm instance
264 * @direction: stream direction, SNDRV_PCM_STREAM_XXX
265 * @ops: the operator table
267 * Sets the given PCM operators to the pcm instance.
269 void snd_pcm_set_ops(snd_pcm_t *pcm, int direction, snd_pcm_ops_t *ops)
271 snd_pcm_str_t *stream = &pcm->streams[direction];
272 snd_pcm_substream_t *substream;
274 for (substream = stream->substream; substream != NULL; substream = substream->next)
275 substream->ops = ops;
280 * snd_pcm_sync - set the PCM sync id
281 * @substream: the pcm substream
283 * Sets the PCM sync identifier for the card.
285 void snd_pcm_set_sync(snd_pcm_substream_t * substream)
287 snd_pcm_runtime_t *runtime = substream->runtime;
289 runtime->sync.id32[0] = substream->pcm->card->number;
290 runtime->sync.id32[1] = -1;
291 runtime->sync.id32[2] = -1;
292 runtime->sync.id32[3] = -1;
296 * Standard ioctl routine
299 /* Code taken from alsa-lib */
300 #define assert(a) snd_assert((a), return -EINVAL)
302 static inline unsigned int div32(unsigned int a, unsigned int b,
313 static inline unsigned int div_down(unsigned int a, unsigned int b)
320 static inline unsigned int div_up(unsigned int a, unsigned int b)
332 static inline unsigned int mul(unsigned int a, unsigned int b)
336 if (div_down(UINT_MAX, a) < b)
341 static inline unsigned int muldiv32(unsigned int a, unsigned int b,
342 unsigned int c, unsigned int *r)
344 u_int64_t n = (u_int64_t) a * b;
358 int snd_interval_refine_min(snd_interval_t *i, unsigned int min, int openmin)
361 assert(!snd_interval_empty(i));
364 i->openmin = openmin;
366 } else if (i->min == min && !i->openmin && openmin) {
376 if (snd_interval_checkempty(i)) {
377 snd_interval_none(i);
383 int snd_interval_refine_max(snd_interval_t *i, unsigned int max, int openmax)
386 assert(!snd_interval_empty(i));
389 i->openmax = openmax;
391 } else if (i->max == max && !i->openmax && openmax) {
401 if (snd_interval_checkempty(i)) {
402 snd_interval_none(i);
409 * snd_interval_refine - refine the interval value of configurator
410 * @i: the interval value to refine
411 * @v: the interval value to refer to
413 * Refines the interval value with the reference value.
414 * The interval is changed to the range satisfying both intervals.
415 * The interval status (min, max, integer, etc.) are evaluated.
417 * Returns non-zero if the value is changed, zero if not changed.
419 int snd_interval_refine(snd_interval_t *i, const snd_interval_t *v)
422 assert(!snd_interval_empty(i));
423 if (i->min < v->min) {
425 i->openmin = v->openmin;
427 } else if (i->min == v->min && !i->openmin && v->openmin) {
431 if (i->max > v->max) {
433 i->openmax = v->openmax;
435 } else if (i->max == v->max && !i->openmax && v->openmax) {
439 if (!i->integer && v->integer) {
452 } else if (!i->openmin && !i->openmax && i->min == i->max)
454 if (snd_interval_checkempty(i)) {
455 snd_interval_none(i);
461 int snd_interval_refine_first(snd_interval_t *i)
463 assert(!snd_interval_empty(i));
464 if (snd_interval_single(i))
467 i->openmax = i->openmin;
473 int snd_interval_refine_last(snd_interval_t *i)
475 assert(!snd_interval_empty(i));
476 if (snd_interval_single(i))
479 i->openmin = i->openmax;
485 int snd_interval_refine_set(snd_interval_t *i, unsigned int val)
490 t.openmin = t.openmax = 0;
492 return snd_interval_refine(i, &t);
495 void snd_interval_mul(const snd_interval_t *a, const snd_interval_t *b, snd_interval_t *c)
497 if (a->empty || b->empty) {
498 snd_interval_none(c);
502 c->min = mul(a->min, b->min);
503 c->openmin = (a->openmin || b->openmin);
504 c->max = mul(a->max, b->max);
505 c->openmax = (a->openmax || b->openmax);
506 c->integer = (a->integer && b->integer);
510 * snd_interval_div - refine the interval value with division
514 * Returns non-zero if the value is changed, zero if not changed.
516 void snd_interval_div(const snd_interval_t *a, const snd_interval_t *b, snd_interval_t *c)
519 if (a->empty || b->empty) {
520 snd_interval_none(c);
524 c->min = div32(a->min, b->max, &r);
525 c->openmin = (r || a->openmin || b->openmax);
527 c->max = div32(a->max, b->min, &r);
532 c->openmax = (a->openmax || b->openmin);
541 * snd_interval_muldivk - refine the interval value
545 * Returns non-zero if the value is changed, zero if not changed.
547 void snd_interval_muldivk(const snd_interval_t *a, const snd_interval_t *b,
548 unsigned int k, snd_interval_t *c)
551 if (a->empty || b->empty) {
552 snd_interval_none(c);
556 c->min = muldiv32(a->min, b->min, k, &r);
557 c->openmin = (r || a->openmin || b->openmin);
558 c->max = muldiv32(a->max, b->max, k, &r);
563 c->openmax = (a->openmax || b->openmax);
568 * snd_interval_mulkdiv - refine the interval value
572 * Returns non-zero if the value is changed, zero if not changed.
574 void snd_interval_mulkdiv(const snd_interval_t *a, unsigned int k,
575 const snd_interval_t *b, snd_interval_t *c)
578 if (a->empty || b->empty) {
579 snd_interval_none(c);
583 c->min = muldiv32(a->min, k, b->max, &r);
584 c->openmin = (r || a->openmin || b->openmax);
586 c->max = muldiv32(a->max, k, b->min, &r);
591 c->openmax = (a->openmax || b->openmin);
604 * snd_interval_ratnum - refine the interval value
606 * Returns non-zero if the value is changed, zero if not changed.
608 int snd_interval_ratnum(snd_interval_t *i,
609 unsigned int rats_count, ratnum_t *rats,
610 unsigned int *nump, unsigned int *denp)
612 unsigned int best_num, best_diff, best_den;
617 best_num = best_den = best_diff = 0;
618 for (k = 0; k < rats_count; ++k) {
619 unsigned int num = rats[k].num;
621 unsigned int q = i->min;
625 den = div_down(num, q);
626 if (den < rats[k].den_min)
628 if (den > rats[k].den_max)
629 den = rats[k].den_max;
632 r = (den - rats[k].den_min) % rats[k].den_step;
636 diff = num - q * den;
638 diff * best_den < best_diff * den) {
648 t.min = div_down(best_num, best_den);
649 t.openmin = !!(best_num % best_den);
651 best_num = best_den = best_diff = 0;
652 for (k = 0; k < rats_count; ++k) {
653 unsigned int num = rats[k].num;
655 unsigned int q = i->max;
661 den = div_up(num, q);
662 if (den > rats[k].den_max)
664 if (den < rats[k].den_min)
665 den = rats[k].den_min;
668 r = (den - rats[k].den_min) % rats[k].den_step;
670 den += rats[k].den_step - r;
672 diff = q * den - num;
674 diff * best_den < best_diff * den) {
684 t.max = div_up(best_num, best_den);
685 t.openmax = !!(best_num % best_den);
687 err = snd_interval_refine(i, &t);
691 if (snd_interval_single(i)) {
701 * snd_interval_ratden - refine the interval value
703 * Returns non-zero if the value is changed, zero if not changed.
705 int snd_interval_ratden(snd_interval_t *i,
706 unsigned int rats_count, ratden_t *rats,
707 unsigned int *nump, unsigned int *denp)
709 unsigned int best_num, best_diff, best_den;
714 best_num = best_den = best_diff = 0;
715 for (k = 0; k < rats_count; ++k) {
717 unsigned int den = rats[k].den;
718 unsigned int q = i->min;
721 if (num > rats[k].num_max)
723 if (num < rats[k].num_min)
724 num = rats[k].num_max;
727 r = (num - rats[k].num_min) % rats[k].num_step;
729 num += rats[k].num_step - r;
731 diff = num - q * den;
733 diff * best_den < best_diff * den) {
743 t.min = div_down(best_num, best_den);
744 t.openmin = !!(best_num % best_den);
746 best_num = best_den = best_diff = 0;
747 for (k = 0; k < rats_count; ++k) {
749 unsigned int den = rats[k].den;
750 unsigned int q = i->max;
753 if (num < rats[k].num_min)
755 if (num > rats[k].num_max)
756 num = rats[k].num_max;
759 r = (num - rats[k].num_min) % rats[k].num_step;
763 diff = q * den - num;
765 diff * best_den < best_diff * den) {
775 t.max = div_up(best_num, best_den);
776 t.openmax = !!(best_num % best_den);
778 err = snd_interval_refine(i, &t);
782 if (snd_interval_single(i)) {
792 * snd_interval_list - refine the interval value from the list
793 * @i: the interval value to refine
794 * @count: the number of elements in the list
795 * @list: the value list
796 * @mask: the bit-mask to evaluate
798 * Refines the interval value from the list.
799 * When mask is non-zero, only the elements corresponding to bit 1 are
802 * Returns non-zero if the value is changed, zero if not changed.
804 int snd_interval_list(snd_interval_t *i, unsigned int count, unsigned int *list, unsigned int mask)
808 for (k = 0; k < count; k++) {
809 if (mask && !(mask & (1 << k)))
811 if (i->min == list[k] && !i->openmin)
813 if (i->min < list[k]) {
823 for (k = count; k-- > 0;) {
824 if (mask && !(mask & (1 << k)))
826 if (i->max == list[k] && !i->openmax)
828 if (i->max > list[k]) {
838 if (snd_interval_checkempty(i)) {
845 int snd_interval_step(snd_interval_t *i, unsigned int min, unsigned int step)
849 n = (i->min - min) % step;
850 if (n != 0 || i->openmin) {
854 n = (i->max - min) % step;
855 if (n != 0 || i->openmax) {
859 if (snd_interval_checkempty(i)) {
866 /* Info constraints helpers */
869 * snd_pcm_hw_rule_add - add the hw-constraint rule
870 * @runtime: the pcm runtime instance
871 * @cond: condition bits
872 * @var: the variable to evaluate
873 * @func: the evaluation function
874 * @private: the private data pointer passed to function
875 * @dep: the dependent variables
877 * Returns zero if successful, or a negative error code on failure.
879 int snd_pcm_hw_rule_add(snd_pcm_runtime_t *runtime, unsigned int cond,
881 snd_pcm_hw_rule_func_t func, void *private,
884 snd_pcm_hw_constraints_t *constrs = &runtime->hw_constraints;
885 snd_pcm_hw_rule_t *c;
889 if (constrs->rules_num >= constrs->rules_all) {
890 snd_pcm_hw_rule_t *old = constrs->rules;
891 if (constrs->rules_all == 0)
892 constrs->rules_all = 32;
894 old = constrs->rules;
895 constrs->rules_all += 10;
897 constrs->rules = snd_kcalloc(constrs->rules_all * sizeof(*c),
902 memcpy(constrs->rules, old,
903 constrs->rules_num * sizeof(*c));
907 c = &constrs->rules[constrs->rules_num];
911 c->private = private;
914 snd_assert(k < sizeof(c->deps) / sizeof(c->deps[0]), return -EINVAL);
918 dep = va_arg(args, int);
920 constrs->rules_num++;
926 * snd_pcm_hw_constraint_mask
928 int snd_pcm_hw_constraint_mask(snd_pcm_runtime_t *runtime, snd_pcm_hw_param_t var,
931 snd_pcm_hw_constraints_t *constrs = &runtime->hw_constraints;
932 snd_mask_t *maskp = constrs_mask(constrs, var);
933 *maskp->bits &= mask;
934 memset(maskp->bits + 1, 0, (SNDRV_MASK_MAX-32) / 8); /* clear rest */
935 if (*maskp->bits == 0)
941 * snd_pcm_hw_constraint_mask64
943 int snd_pcm_hw_constraint_mask64(snd_pcm_runtime_t *runtime, snd_pcm_hw_param_t var,
946 snd_pcm_hw_constraints_t *constrs = &runtime->hw_constraints;
947 snd_mask_t *maskp = constrs_mask(constrs, var);
948 maskp->bits[0] &= (u_int32_t)mask;
949 maskp->bits[1] &= (u_int32_t)(mask >> 32);
950 memset(maskp->bits + 2, 0, (SNDRV_MASK_MAX-64) / 8); /* clear rest */
951 if (! maskp->bits[0] && ! maskp->bits[1])
957 * snd_pcm_hw_constraint_integer
959 int snd_pcm_hw_constraint_integer(snd_pcm_runtime_t *runtime, snd_pcm_hw_param_t var)
961 snd_pcm_hw_constraints_t *constrs = &runtime->hw_constraints;
962 return snd_interval_setinteger(constrs_interval(constrs, var));
966 * snd_pcm_hw_constraint_minmax
968 int snd_pcm_hw_constraint_minmax(snd_pcm_runtime_t *runtime, snd_pcm_hw_param_t var,
969 unsigned int min, unsigned int max)
971 snd_pcm_hw_constraints_t *constrs = &runtime->hw_constraints;
975 t.openmin = t.openmax = 0;
977 return snd_interval_refine(constrs_interval(constrs, var), &t);
980 static int snd_pcm_hw_rule_list(snd_pcm_hw_params_t *params,
981 snd_pcm_hw_rule_t *rule)
983 snd_pcm_hw_constraint_list_t *list = rule->private;
984 return snd_interval_list(hw_param_interval(params, rule->var), list->count, list->list, list->mask);
989 * snd_pcm_hw_constraint_list
991 int snd_pcm_hw_constraint_list(snd_pcm_runtime_t *runtime,
993 snd_pcm_hw_param_t var,
994 snd_pcm_hw_constraint_list_t *l)
996 return snd_pcm_hw_rule_add(runtime, cond, var,
997 snd_pcm_hw_rule_list, l,
1001 static int snd_pcm_hw_rule_ratnums(snd_pcm_hw_params_t *params,
1002 snd_pcm_hw_rule_t *rule)
1004 snd_pcm_hw_constraint_ratnums_t *r = rule->private;
1005 unsigned int num = 0, den = 0;
1007 err = snd_interval_ratnum(hw_param_interval(params, rule->var),
1008 r->nrats, r->rats, &num, &den);
1009 if (err >= 0 && den && rule->var == SNDRV_PCM_HW_PARAM_RATE) {
1010 params->rate_num = num;
1011 params->rate_den = den;
1017 * snd_pcm_hw_constraint_ratnums
1019 int snd_pcm_hw_constraint_ratnums(snd_pcm_runtime_t *runtime,
1021 snd_pcm_hw_param_t var,
1022 snd_pcm_hw_constraint_ratnums_t *r)
1024 return snd_pcm_hw_rule_add(runtime, cond, var,
1025 snd_pcm_hw_rule_ratnums, r,
1029 static int snd_pcm_hw_rule_ratdens(snd_pcm_hw_params_t *params,
1030 snd_pcm_hw_rule_t *rule)
1032 snd_pcm_hw_constraint_ratdens_t *r = rule->private;
1033 unsigned int num = 0, den = 0;
1034 int err = snd_interval_ratden(hw_param_interval(params, rule->var),
1035 r->nrats, r->rats, &num, &den);
1036 if (err >= 0 && den && rule->var == SNDRV_PCM_HW_PARAM_RATE) {
1037 params->rate_num = num;
1038 params->rate_den = den;
1044 * snd_pcm_hw_constraint_ratdens
1046 int snd_pcm_hw_constraint_ratdens(snd_pcm_runtime_t *runtime,
1048 snd_pcm_hw_param_t var,
1049 snd_pcm_hw_constraint_ratdens_t *r)
1051 return snd_pcm_hw_rule_add(runtime, cond, var,
1052 snd_pcm_hw_rule_ratdens, r,
1056 static int snd_pcm_hw_rule_msbits(snd_pcm_hw_params_t *params,
1057 snd_pcm_hw_rule_t *rule)
1059 unsigned int l = (unsigned long) rule->private;
1060 int width = l & 0xffff;
1061 unsigned int msbits = l >> 16;
1062 snd_interval_t *i = hw_param_interval(params, SNDRV_PCM_HW_PARAM_SAMPLE_BITS);
1063 if (snd_interval_single(i) && snd_interval_value(i) == width)
1064 params->msbits = msbits;
1069 * snd_pcm_hw_constraint_msbits
1071 int snd_pcm_hw_constraint_msbits(snd_pcm_runtime_t *runtime,
1074 unsigned int msbits)
1076 unsigned long l = (msbits << 16) | width;
1077 return snd_pcm_hw_rule_add(runtime, cond, -1,
1078 snd_pcm_hw_rule_msbits,
1080 SNDRV_PCM_HW_PARAM_SAMPLE_BITS, -1);
1083 static int snd_pcm_hw_rule_step(snd_pcm_hw_params_t *params,
1084 snd_pcm_hw_rule_t *rule)
1086 unsigned long step = (unsigned long) rule->private;
1087 return snd_interval_step(hw_param_interval(params, rule->var), 0, step);
1091 * snd_pcm_hw_constraint_step
1093 int snd_pcm_hw_constraint_step(snd_pcm_runtime_t *runtime,
1095 snd_pcm_hw_param_t var,
1098 return snd_pcm_hw_rule_add(runtime, cond, var,
1099 snd_pcm_hw_rule_step, (void *) step,
1103 static int snd_pcm_hw_rule_pow2(snd_pcm_hw_params_t *params, snd_pcm_hw_rule_t *rule)
1105 static int pow2_sizes[] = {
1106 1<<0, 1<<1, 1<<2, 1<<3, 1<<4, 1<<5, 1<<6, 1<<7,
1107 1<<8, 1<<9, 1<<10, 1<<11, 1<<12, 1<<13, 1<<14, 1<<15,
1108 1<<16, 1<<17, 1<<18, 1<<19, 1<<20, 1<<21, 1<<22, 1<<23,
1109 1<<24, 1<<25, 1<<26, 1<<27, 1<<28, 1<<29, 1<<30
1111 return snd_interval_list(hw_param_interval(params, rule->var),
1112 sizeof(pow2_sizes)/sizeof(int), pow2_sizes, 0);
1116 * snd_pcm_hw_constraint_pow2
1118 int snd_pcm_hw_constraint_pow2(snd_pcm_runtime_t *runtime,
1120 snd_pcm_hw_param_t var)
1122 return snd_pcm_hw_rule_add(runtime, cond, var,
1123 snd_pcm_hw_rule_pow2, NULL,
1127 /* To use the same code we have in alsa-lib */
1128 #define snd_pcm_t snd_pcm_substream_t
1129 #define assert(i) snd_assert((i), return -EINVAL)
1131 #define INT_MIN ((int)((unsigned int)INT_MAX+1))
1134 void _snd_pcm_hw_param_any(snd_pcm_hw_params_t *params, snd_pcm_hw_param_t var)
1136 if (hw_is_mask(var)) {
1137 snd_mask_any(hw_param_mask(params, var));
1138 params->cmask |= 1 << var;
1139 params->rmask |= 1 << var;
1142 if (hw_is_interval(var)) {
1143 snd_interval_any(hw_param_interval(params, var));
1144 params->cmask |= 1 << var;
1145 params->rmask |= 1 << var;
1152 * snd_pcm_hw_param_any
1154 int snd_pcm_hw_param_any(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
1155 snd_pcm_hw_param_t var)
1157 _snd_pcm_hw_param_any(params, var);
1158 return snd_pcm_hw_refine(pcm, params);
1161 void _snd_pcm_hw_params_any(snd_pcm_hw_params_t *params)
1164 memset(params, 0, sizeof(*params));
1165 for (k = SNDRV_PCM_HW_PARAM_FIRST_MASK; k <= SNDRV_PCM_HW_PARAM_LAST_MASK; k++)
1166 _snd_pcm_hw_param_any(params, k);
1167 for (k = SNDRV_PCM_HW_PARAM_FIRST_INTERVAL; k <= SNDRV_PCM_HW_PARAM_LAST_INTERVAL; k++)
1168 _snd_pcm_hw_param_any(params, k);
1173 * snd_pcm_hw_params_any
1175 * Fill PARAMS with full configuration space boundaries
1177 int snd_pcm_hw_params_any(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
1179 _snd_pcm_hw_params_any(params);
1180 return snd_pcm_hw_refine(pcm, params);
1184 * snd_pcm_hw_param_value
1186 * Return the value for field PAR if it's fixed in configuration space
1187 * defined by PARAMS. Return -EINVAL otherwise
1189 int snd_pcm_hw_param_value(const snd_pcm_hw_params_t *params,
1190 snd_pcm_hw_param_t var, int *dir)
1192 if (hw_is_mask(var)) {
1193 const snd_mask_t *mask = hw_param_mask_c(params, var);
1194 if (!snd_mask_single(mask))
1198 return snd_mask_value(mask);
1200 if (hw_is_interval(var)) {
1201 const snd_interval_t *i = hw_param_interval_c(params, var);
1202 if (!snd_interval_single(i))
1206 return snd_interval_value(i);
1213 * snd_pcm_hw_param_value_min
1215 * Return the minimum value for field PAR.
1217 unsigned int snd_pcm_hw_param_value_min(const snd_pcm_hw_params_t *params,
1218 snd_pcm_hw_param_t var, int *dir)
1220 if (hw_is_mask(var)) {
1223 return snd_mask_min(hw_param_mask_c(params, var));
1225 if (hw_is_interval(var)) {
1226 const snd_interval_t *i = hw_param_interval_c(params, var);
1229 return snd_interval_min(i);
1236 * snd_pcm_hw_param_value_max
1238 * Return the maximum value for field PAR.
1240 unsigned int snd_pcm_hw_param_value_max(const snd_pcm_hw_params_t *params,
1241 snd_pcm_hw_param_t var, int *dir)
1243 if (hw_is_mask(var)) {
1246 return snd_mask_max(hw_param_mask_c(params, var));
1248 if (hw_is_interval(var)) {
1249 const snd_interval_t *i = hw_param_interval_c(params, var);
1251 *dir = - (int) i->openmax;
1252 return snd_interval_max(i);
1258 void _snd_pcm_hw_param_setempty(snd_pcm_hw_params_t *params,
1259 snd_pcm_hw_param_t var)
1261 if (hw_is_mask(var)) {
1262 snd_mask_none(hw_param_mask(params, var));
1263 params->cmask |= 1 << var;
1264 params->rmask |= 1 << var;
1265 } else if (hw_is_interval(var)) {
1266 snd_interval_none(hw_param_interval(params, var));
1267 params->cmask |= 1 << var;
1268 params->rmask |= 1 << var;
1274 int _snd_pcm_hw_param_setinteger(snd_pcm_hw_params_t *params,
1275 snd_pcm_hw_param_t var)
1278 assert(hw_is_interval(var));
1279 changed = snd_interval_setinteger(hw_param_interval(params, var));
1281 params->cmask |= 1 << var;
1282 params->rmask |= 1 << var;
1288 * snd_pcm_hw_param_setinteger
1290 * Inside configuration space defined by PARAMS remove from PAR all
1291 * non integer values. Reduce configuration space accordingly.
1292 * Return -EINVAL if the configuration space is empty
1294 int snd_pcm_hw_param_setinteger(snd_pcm_t *pcm,
1295 snd_pcm_hw_params_t *params,
1296 snd_pcm_hw_param_t var)
1298 int changed = _snd_pcm_hw_param_setinteger(params, var);
1301 if (params->rmask) {
1302 int err = snd_pcm_hw_refine(pcm, params);
1309 int _snd_pcm_hw_param_first(snd_pcm_hw_params_t *params,
1310 snd_pcm_hw_param_t var)
1313 if (hw_is_mask(var))
1314 changed = snd_mask_refine_first(hw_param_mask(params, var));
1315 else if (hw_is_interval(var))
1316 changed = snd_interval_refine_first(hw_param_interval(params, var));
1322 params->cmask |= 1 << var;
1323 params->rmask |= 1 << var;
1330 * snd_pcm_hw_param_first
1332 * Inside configuration space defined by PARAMS remove from PAR all
1333 * values > minimum. Reduce configuration space accordingly.
1334 * Return the minimum.
1336 int snd_pcm_hw_param_first(snd_pcm_t *pcm,
1337 snd_pcm_hw_params_t *params,
1338 snd_pcm_hw_param_t var, int *dir)
1340 int changed = _snd_pcm_hw_param_first(params, var);
1343 if (params->rmask) {
1344 int err = snd_pcm_hw_refine(pcm, params);
1347 return snd_pcm_hw_param_value(params, var, dir);
1350 int _snd_pcm_hw_param_last(snd_pcm_hw_params_t *params,
1351 snd_pcm_hw_param_t var)
1354 if (hw_is_mask(var))
1355 changed = snd_mask_refine_last(hw_param_mask(params, var));
1356 else if (hw_is_interval(var))
1357 changed = snd_interval_refine_last(hw_param_interval(params, var));
1363 params->cmask |= 1 << var;
1364 params->rmask |= 1 << var;
1371 * snd_pcm_hw_param_last
1373 * Inside configuration space defined by PARAMS remove from PAR all
1374 * values < maximum. Reduce configuration space accordingly.
1375 * Return the maximum.
1377 int snd_pcm_hw_param_last(snd_pcm_t *pcm,
1378 snd_pcm_hw_params_t *params,
1379 snd_pcm_hw_param_t var, int *dir)
1381 int changed = _snd_pcm_hw_param_last(params, var);
1384 if (params->rmask) {
1385 int err = snd_pcm_hw_refine(pcm, params);
1388 return snd_pcm_hw_param_value(params, var, dir);
1391 int _snd_pcm_hw_param_min(snd_pcm_hw_params_t *params,
1392 snd_pcm_hw_param_t var, unsigned int val, int dir)
1399 } else if (dir < 0) {
1406 if (hw_is_mask(var))
1407 changed = snd_mask_refine_min(hw_param_mask(params, var), val + !!open);
1408 else if (hw_is_interval(var))
1409 changed = snd_interval_refine_min(hw_param_interval(params, var), val, open);
1415 params->cmask |= 1 << var;
1416 params->rmask |= 1 << var;
1422 * snd_pcm_hw_param_min
1424 * Inside configuration space defined by PARAMS remove from PAR all
1425 * values < VAL. Reduce configuration space accordingly.
1426 * Return new minimum or -EINVAL if the configuration space is empty
1428 int snd_pcm_hw_param_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
1429 snd_pcm_hw_param_t var, unsigned int val, int *dir)
1431 int changed = _snd_pcm_hw_param_min(params, var, val, dir ? *dir : 0);
1434 if (params->rmask) {
1435 int err = snd_pcm_hw_refine(pcm, params);
1439 return snd_pcm_hw_param_value_min(params, var, dir);
1442 int _snd_pcm_hw_param_max(snd_pcm_hw_params_t *params,
1443 snd_pcm_hw_param_t var, unsigned int val, int dir)
1450 } else if (dir > 0) {
1455 if (hw_is_mask(var)) {
1456 if (val == 0 && open) {
1457 snd_mask_none(hw_param_mask(params, var));
1460 changed = snd_mask_refine_max(hw_param_mask(params, var), val - !!open);
1461 } else if (hw_is_interval(var))
1462 changed = snd_interval_refine_max(hw_param_interval(params, var), val, open);
1468 params->cmask |= 1 << var;
1469 params->rmask |= 1 << var;
1475 * snd_pcm_hw_param_max
1477 * Inside configuration space defined by PARAMS remove from PAR all
1478 * values >= VAL + 1. Reduce configuration space accordingly.
1479 * Return new maximum or -EINVAL if the configuration space is empty
1481 int snd_pcm_hw_param_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
1482 snd_pcm_hw_param_t var, unsigned int val, int *dir)
1484 int changed = _snd_pcm_hw_param_max(params, var, val, dir ? *dir : 0);
1487 if (params->rmask) {
1488 int err = snd_pcm_hw_refine(pcm, params);
1492 return snd_pcm_hw_param_value_max(params, var, dir);
1495 int _snd_pcm_hw_param_set(snd_pcm_hw_params_t *params,
1496 snd_pcm_hw_param_t var, unsigned int val, int dir)
1499 if (hw_is_mask(var)) {
1500 snd_mask_t *m = hw_param_mask(params, var);
1501 if (val == 0 && dir < 0) {
1509 changed = snd_mask_refine_set(hw_param_mask(params, var), val);
1511 } else if (hw_is_interval(var)) {
1512 snd_interval_t *i = hw_param_interval(params, var);
1513 if (val == 0 && dir < 0) {
1515 snd_interval_none(i);
1516 } else if (dir == 0)
1517 changed = snd_interval_refine_set(i, val);
1531 changed = snd_interval_refine(i, &t);
1538 params->cmask |= 1 << var;
1539 params->rmask |= 1 << var;
1545 * snd_pcm_hw_param_set
1547 * Inside configuration space defined by PARAMS remove from PAR all
1548 * values != VAL. Reduce configuration space accordingly.
1549 * Return VAL or -EINVAL if the configuration space is empty
1551 int snd_pcm_hw_param_set(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
1552 snd_pcm_hw_param_t var, unsigned int val, int dir)
1554 int changed = _snd_pcm_hw_param_set(params, var, val, dir);
1557 if (params->rmask) {
1558 int err = snd_pcm_hw_refine(pcm, params);
1562 return snd_pcm_hw_param_value(params, var, NULL);
1565 int _snd_pcm_hw_param_mask(snd_pcm_hw_params_t *params,
1566 snd_pcm_hw_param_t var, const snd_mask_t *val)
1569 assert(hw_is_mask(var));
1570 changed = snd_mask_refine(hw_param_mask(params, var), val);
1572 params->cmask |= 1 << var;
1573 params->rmask |= 1 << var;
1579 * snd_pcm_hw_param_mask
1581 * Inside configuration space defined by PARAMS remove from PAR all values
1582 * not contained in MASK. Reduce configuration space accordingly.
1583 * This function can be called only for SNDRV_PCM_HW_PARAM_ACCESS,
1584 * SNDRV_PCM_HW_PARAM_FORMAT, SNDRV_PCM_HW_PARAM_SUBFORMAT.
1585 * Return 0 on success or -EINVAL
1586 * if the configuration space is empty
1588 int snd_pcm_hw_param_mask(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
1589 snd_pcm_hw_param_t var, const snd_mask_t *val)
1591 int changed = _snd_pcm_hw_param_mask(params, var, val);
1594 if (params->rmask) {
1595 int err = snd_pcm_hw_refine(pcm, params);
1602 static int boundary_sub(int a, int adir,
1606 adir = adir < 0 ? -1 : (adir > 0 ? 1 : 0);
1607 bdir = bdir < 0 ? -1 : (bdir > 0 ? 1 : 0);
1609 *cdir = adir - bdir;
1611 assert(*c > INT_MIN);
1613 } else if (*cdir == 2) {
1614 assert(*c < INT_MAX);
1620 static int boundary_lt(unsigned int a, int adir,
1621 unsigned int b, int bdir)
1623 assert(a > 0 || adir >= 0);
1624 assert(b > 0 || bdir >= 0);
1628 } else if (adir > 0)
1633 } else if (bdir > 0)
1635 return a < b || (a == b && adir < bdir);
1638 /* Return 1 if min is nearer to best than max */
1639 static int boundary_nearer(int min, int mindir,
1640 int best, int bestdir,
1641 int max, int maxdir)
1645 boundary_sub(best, bestdir, min, mindir, &dmin, &dmindir);
1646 boundary_sub(max, maxdir, best, bestdir, &dmax, &dmaxdir);
1647 return boundary_lt(dmin, dmindir, dmax, dmaxdir);
1651 * snd_pcm_hw_param_near
1653 * Inside configuration space defined by PARAMS set PAR to the available value
1654 * nearest to VAL. Reduce configuration space accordingly.
1655 * This function cannot be called for SNDRV_PCM_HW_PARAM_ACCESS,
1656 * SNDRV_PCM_HW_PARAM_FORMAT, SNDRV_PCM_HW_PARAM_SUBFORMAT.
1657 * Return the value found.
1659 int snd_pcm_hw_param_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
1660 snd_pcm_hw_param_t var, unsigned int best, int *dir)
1662 snd_pcm_hw_params_t *save = NULL;
1664 unsigned int saved_min;
1668 int valdir = dir ? *dir : 0;
1673 mindir = maxdir = valdir;
1676 else if (maxdir == 0)
1682 save = kmalloc(sizeof(*save), GFP_KERNEL);
1687 min = snd_pcm_hw_param_min(pcm, params, var, min, &mindir);
1689 snd_pcm_hw_params_t *params1;
1692 if ((unsigned int)min == saved_min && mindir == valdir)
1694 params1 = kmalloc(sizeof(*params1), GFP_KERNEL);
1695 if (params1 == NULL) {
1700 max = snd_pcm_hw_param_max(pcm, params1, var, max, &maxdir);
1705 if (boundary_nearer(max, maxdir, best, valdir, min, mindir)) {
1712 max = snd_pcm_hw_param_max(pcm, params, var, max, &maxdir);
1719 v = snd_pcm_hw_param_last(pcm, params, var, dir);
1721 v = snd_pcm_hw_param_first(pcm, params, var, dir);
1727 * snd_pcm_hw_param_choose
1729 * Choose one configuration from configuration space defined by PARAMS
1730 * The configuration chosen is that obtained fixing in this order:
1731 * first access, first format, first subformat, min channels,
1732 * min rate, min period time, max buffer size, min tick time
1734 int snd_pcm_hw_params_choose(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
1738 err = snd_pcm_hw_param_first(pcm, params, SNDRV_PCM_HW_PARAM_ACCESS, NULL);
1741 err = snd_pcm_hw_param_first(pcm, params, SNDRV_PCM_HW_PARAM_FORMAT, NULL);
1744 err = snd_pcm_hw_param_first(pcm, params, SNDRV_PCM_HW_PARAM_SUBFORMAT, NULL);
1747 err = snd_pcm_hw_param_first(pcm, params, SNDRV_PCM_HW_PARAM_CHANNELS, NULL);
1750 err = snd_pcm_hw_param_first(pcm, params, SNDRV_PCM_HW_PARAM_RATE, NULL);
1753 err = snd_pcm_hw_param_first(pcm, params, SNDRV_PCM_HW_PARAM_PERIOD_TIME, NULL);
1756 err = snd_pcm_hw_param_last(pcm, params, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, NULL);
1759 err = snd_pcm_hw_param_first(pcm, params, SNDRV_PCM_HW_PARAM_TICK_TIME, NULL);
1768 static int snd_pcm_lib_ioctl_reset(snd_pcm_substream_t *substream,
1771 snd_pcm_runtime_t *runtime = substream->runtime;
1772 if (snd_pcm_running(substream) &&
1773 snd_pcm_update_hw_ptr(substream) >= 0) {
1774 runtime->status->hw_ptr %= runtime->buffer_size;
1777 runtime->status->hw_ptr = 0;
1781 static int snd_pcm_lib_ioctl_channel_info(snd_pcm_substream_t *substream,
1784 snd_pcm_channel_info_t *info = arg;
1785 snd_pcm_runtime_t *runtime = substream->runtime;
1787 if (!(runtime->info & SNDRV_PCM_INFO_MMAP)) {
1791 width = snd_pcm_format_physical_width(runtime->format);
1795 switch (runtime->access) {
1796 case SNDRV_PCM_ACCESS_MMAP_INTERLEAVED:
1797 case SNDRV_PCM_ACCESS_RW_INTERLEAVED:
1798 info->first = info->channel * width;
1799 info->step = runtime->channels * width;
1801 case SNDRV_PCM_ACCESS_MMAP_NONINTERLEAVED:
1802 case SNDRV_PCM_ACCESS_RW_NONINTERLEAVED:
1804 size_t size = runtime->dma_bytes / runtime->channels;
1805 info->first = info->channel * size * 8;
1817 * snd_pcm_lib_ioctl - a generic PCM ioctl callback
1818 * @substream: the pcm substream instance
1819 * @cmd: ioctl command
1820 * @arg: ioctl argument
1822 * Processes the generic ioctl commands for PCM.
1823 * Can be passed as the ioctl callback for PCM ops.
1825 * Returns zero if successful, or a negative error code on failure.
1827 int snd_pcm_lib_ioctl(snd_pcm_substream_t *substream,
1828 unsigned int cmd, void *arg)
1831 case SNDRV_PCM_IOCTL1_INFO:
1833 case SNDRV_PCM_IOCTL1_RESET:
1834 return snd_pcm_lib_ioctl_reset(substream, arg);
1835 case SNDRV_PCM_IOCTL1_CHANNEL_INFO:
1836 return snd_pcm_lib_ioctl_channel_info(substream, arg);
1846 * snd_pcm_playback_ready - check whether the playback buffer is available
1847 * @substream: the pcm substream instance
1849 * Checks whether enough free space is available on the playback buffer.
1851 * Returns non-zero if available, or zero if not.
1853 int snd_pcm_playback_ready(snd_pcm_substream_t *substream)
1855 snd_pcm_runtime_t *runtime = substream->runtime;
1856 return snd_pcm_playback_avail(runtime) >= runtime->control->avail_min;
1860 * snd_pcm_capture_ready - check whether the capture buffer is available
1861 * @substream: the pcm substream instance
1863 * Checks whether enough capture data is available on the capture buffer.
1865 * Returns non-zero if available, or zero if not.
1867 int snd_pcm_capture_ready(snd_pcm_substream_t *substream)
1869 snd_pcm_runtime_t *runtime = substream->runtime;
1870 return snd_pcm_capture_avail(runtime) >= runtime->control->avail_min;
1874 * snd_pcm_playback_data - check whether any data exists on the playback buffer
1875 * @substream: the pcm substream instance
1877 * Checks whether any data exists on the playback buffer. If stop_threshold
1878 * is bigger or equal to boundary, then this function returns always non-zero.
1880 * Returns non-zero if exists, or zero if not.
1882 int snd_pcm_playback_data(snd_pcm_substream_t *substream)
1884 snd_pcm_runtime_t *runtime = substream->runtime;
1886 if (runtime->stop_threshold >= runtime->boundary)
1888 return snd_pcm_playback_avail(runtime) < runtime->buffer_size;
1892 * snd_pcm_playback_empty - check whether the playback buffer is empty
1893 * @substream: the pcm substream instance
1895 * Checks whether the playback buffer is empty.
1897 * Returns non-zero if empty, or zero if not.
1899 int snd_pcm_playback_empty(snd_pcm_substream_t *substream)
1901 snd_pcm_runtime_t *runtime = substream->runtime;
1902 return snd_pcm_playback_avail(runtime) >= runtime->buffer_size;
1906 * snd_pcm_capture_empty - check whether the capture buffer is empty
1907 * @substream: the pcm substream instance
1909 * Checks whether the capture buffer is empty.
1911 * Returns non-zero if empty, or zero if not.
1913 int snd_pcm_capture_empty(snd_pcm_substream_t *substream)
1915 snd_pcm_runtime_t *runtime = substream->runtime;
1916 return snd_pcm_capture_avail(runtime) == 0;
1919 static void snd_pcm_system_tick_set(snd_pcm_substream_t *substream,
1920 unsigned long ticks)
1922 snd_pcm_runtime_t *runtime = substream->runtime;
1924 del_timer(&runtime->tick_timer);
1926 ticks /= (1000000 / HZ);
1927 if (ticks % (1000000 / HZ))
1929 mod_timer(&runtime->tick_timer, jiffies + ticks);
1933 /* Temporary alias */
1934 void snd_pcm_tick_set(snd_pcm_substream_t *substream, unsigned long ticks)
1936 snd_pcm_system_tick_set(substream, ticks);
1939 void snd_pcm_tick_prepare(snd_pcm_substream_t *substream)
1941 snd_pcm_runtime_t *runtime = substream->runtime;
1942 snd_pcm_uframes_t frames = ULONG_MAX;
1943 snd_pcm_uframes_t avail, dist;
1947 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
1948 if (runtime->silence_size >= runtime->boundary) {
1950 } else if (runtime->silence_size > 0 &&
1951 runtime->silence_filled < runtime->buffer_size) {
1952 snd_pcm_sframes_t noise_dist;
1953 noise_dist = snd_pcm_playback_hw_avail(runtime) + runtime->silence_filled;
1954 snd_assert(noise_dist <= (snd_pcm_sframes_t)runtime->silence_threshold, );
1955 frames = noise_dist - runtime->silence_threshold;
1957 avail = snd_pcm_playback_avail(runtime);
1959 avail = snd_pcm_capture_avail(runtime);
1961 if (avail < runtime->control->avail_min) {
1962 snd_pcm_sframes_t n = runtime->control->avail_min - avail;
1963 if (n > 0 && frames > (snd_pcm_uframes_t)n)
1966 if (avail < runtime->buffer_size) {
1967 snd_pcm_sframes_t n = runtime->buffer_size - avail;
1968 if (n > 0 && frames > (snd_pcm_uframes_t)n)
1971 if (frames == ULONG_MAX) {
1972 snd_pcm_tick_set(substream, 0);
1975 dist = runtime->status->hw_ptr - runtime->hw_ptr_base;
1976 /* Distance to next interrupt */
1977 dist = runtime->period_size - dist % runtime->period_size;
1978 if (dist <= frames) {
1979 snd_pcm_tick_set(substream, 0);
1982 /* the base time is us */
1985 div64_32(&n, runtime->tick_time * runtime->rate, &r);
1986 ticks = n + (r > 0 ? 1 : 0);
1987 if (ticks < runtime->sleep_min)
1988 ticks = runtime->sleep_min;
1989 snd_pcm_tick_set(substream, (unsigned long) ticks);
1992 void snd_pcm_tick_elapsed(snd_pcm_substream_t *substream)
1994 snd_pcm_runtime_t *runtime;
1995 unsigned long flags;
1997 snd_assert(substream != NULL, return);
1998 runtime = substream->runtime;
1999 snd_assert(runtime != NULL, return);
2001 snd_pcm_stream_lock_irqsave(substream, flags);
2002 if (!snd_pcm_running(substream) ||
2003 snd_pcm_update_hw_ptr(substream) < 0)
2005 if (runtime->sleep_min)
2006 snd_pcm_tick_prepare(substream);
2008 snd_pcm_stream_unlock_irqrestore(substream, flags);
2012 * snd_pcm_period_elapsed - update the pcm status for the next period
2013 * @substream: the pcm substream instance
2015 * This function is called from the interrupt handler when the
2016 * PCM has processed the period size. It will update the current
2017 * pointer, set up the tick, wake up sleepers, etc.
2019 * Even if more than one periods have elapsed since the last call, you
2020 * have to call this only once.
2022 void snd_pcm_period_elapsed(snd_pcm_substream_t *substream)
2024 snd_pcm_runtime_t *runtime;
2025 unsigned long flags;
2027 snd_assert(substream != NULL, return);
2028 runtime = substream->runtime;
2029 snd_assert(runtime != NULL, return);
2031 if (runtime->transfer_ack_begin)
2032 runtime->transfer_ack_begin(substream);
2034 snd_pcm_stream_lock_irqsave(substream, flags);
2035 if (!snd_pcm_running(substream) ||
2036 snd_pcm_update_hw_ptr_interrupt(substream) < 0)
2039 if (substream->timer_running)
2040 snd_timer_interrupt(substream->timer, 1);
2041 if (runtime->sleep_min)
2042 snd_pcm_tick_prepare(substream);
2044 snd_pcm_stream_unlock_irqrestore(substream, flags);
2045 if (runtime->transfer_ack_end)
2046 runtime->transfer_ack_end(substream);
2047 kill_fasync(&runtime->fasync, SIGIO, POLL_IN);
2050 static int snd_pcm_lib_write_transfer(snd_pcm_substream_t *substream,
2052 unsigned long data, unsigned int off,
2053 snd_pcm_uframes_t frames)
2055 snd_pcm_runtime_t *runtime = substream->runtime;
2057 char __user *buf = (char __user *) data + frames_to_bytes(runtime, off);
2058 if (substream->ops->copy) {
2059 if ((err = substream->ops->copy(substream, -1, hwoff, buf, frames)) < 0)
2062 char *hwbuf = runtime->dma_area + frames_to_bytes(runtime, hwoff);
2063 snd_assert(runtime->dma_area, return -EFAULT);
2064 if (copy_from_user(hwbuf, buf, frames_to_bytes(runtime, frames)))
2070 typedef int (*transfer_f)(snd_pcm_substream_t *substream, unsigned int hwoff,
2071 unsigned long data, unsigned int off,
2072 snd_pcm_uframes_t size);
2074 static snd_pcm_sframes_t snd_pcm_lib_write1(snd_pcm_substream_t *substream,
2076 snd_pcm_uframes_t size,
2078 transfer_f transfer)
2080 snd_pcm_runtime_t *runtime = substream->runtime;
2081 snd_pcm_uframes_t xfer = 0;
2082 snd_pcm_uframes_t offset = 0;
2087 if (size > runtime->xfer_align)
2088 size -= size % runtime->xfer_align;
2090 snd_pcm_stream_lock_irq(substream);
2091 switch (runtime->status->state) {
2092 case SNDRV_PCM_STATE_PREPARED:
2093 case SNDRV_PCM_STATE_RUNNING:
2094 case SNDRV_PCM_STATE_PAUSED:
2096 case SNDRV_PCM_STATE_XRUN:
2099 case SNDRV_PCM_STATE_SUSPENDED:
2108 snd_pcm_uframes_t frames, appl_ptr, appl_ofs;
2109 snd_pcm_uframes_t avail;
2110 snd_pcm_uframes_t cont;
2111 if (runtime->sleep_min == 0 && runtime->status->state == SNDRV_PCM_STATE_RUNNING)
2112 snd_pcm_update_hw_ptr(substream);
2113 avail = snd_pcm_playback_avail(runtime);
2114 if (((avail < runtime->control->avail_min && size > avail) ||
2115 (size >= runtime->xfer_align && avail < runtime->xfer_align))) {
2117 enum { READY, SIGNALED, ERROR, SUSPENDED, EXPIRED } state;
2125 init_waitqueue_entry(&wait, current);
2126 add_wait_queue(&runtime->sleep, &wait);
2128 if (signal_pending(current)) {
2132 set_current_state(TASK_INTERRUPTIBLE);
2133 snd_pcm_stream_unlock_irq(substream);
2134 tout = schedule_timeout(10 * HZ);
2135 snd_pcm_stream_lock_irq(substream);
2137 if (runtime->status->state != SNDRV_PCM_STATE_PREPARED &&
2138 runtime->status->state != SNDRV_PCM_STATE_PAUSED) {
2139 state = runtime->status->state == SNDRV_PCM_STATE_SUSPENDED ? SUSPENDED : EXPIRED;
2143 switch (runtime->status->state) {
2144 case SNDRV_PCM_STATE_XRUN:
2145 case SNDRV_PCM_STATE_DRAINING:
2148 case SNDRV_PCM_STATE_SUSPENDED:
2154 avail = snd_pcm_playback_avail(runtime);
2155 if (avail >= runtime->control->avail_min) {
2161 remove_wait_queue(&runtime->sleep, &wait);
2174 snd_printd("playback write error (DMA or IRQ trouble?)\n");
2181 if (avail > runtime->xfer_align)
2182 avail -= avail % runtime->xfer_align;
2183 frames = size > avail ? avail : size;
2184 cont = runtime->buffer_size - runtime->control->appl_ptr % runtime->buffer_size;
2187 snd_assert(frames != 0, snd_pcm_stream_unlock_irq(substream); return -EINVAL);
2188 appl_ptr = runtime->control->appl_ptr;
2189 appl_ofs = appl_ptr % runtime->buffer_size;
2190 snd_pcm_stream_unlock_irq(substream);
2191 if ((err = transfer(substream, appl_ofs, data, offset, frames)) < 0)
2193 snd_pcm_stream_lock_irq(substream);
2194 switch (runtime->status->state) {
2195 case SNDRV_PCM_STATE_XRUN:
2198 case SNDRV_PCM_STATE_SUSPENDED:
2205 if (appl_ptr >= runtime->boundary) {
2206 runtime->control->appl_ptr = 0;
2208 runtime->control->appl_ptr = appl_ptr;
2210 if (substream->ops->ack)
2211 substream->ops->ack(substream);
2216 if (runtime->status->state == SNDRV_PCM_STATE_PREPARED &&
2217 snd_pcm_playback_hw_avail(runtime) >= (snd_pcm_sframes_t)runtime->start_threshold) {
2218 err = snd_pcm_start(substream);
2222 if (runtime->sleep_min &&
2223 runtime->status->state == SNDRV_PCM_STATE_RUNNING)
2224 snd_pcm_tick_prepare(substream);
2227 snd_pcm_stream_unlock_irq(substream);
2229 return xfer > 0 ? (snd_pcm_sframes_t)xfer : err;
2232 snd_pcm_sframes_t snd_pcm_lib_write(snd_pcm_substream_t *substream, const void __user *buf, snd_pcm_uframes_t size)
2234 snd_pcm_runtime_t *runtime;
2237 snd_assert(substream != NULL, return -ENXIO);
2238 runtime = substream->runtime;
2239 snd_assert(runtime != NULL, return -ENXIO);
2240 snd_assert(substream->ops->copy != NULL || runtime->dma_area != NULL, return -EINVAL);
2241 if (runtime->status->state == SNDRV_PCM_STATE_OPEN)
2244 snd_assert(substream->ffile != NULL, return -ENXIO);
2245 nonblock = !!(substream->ffile->f_flags & O_NONBLOCK);
2246 #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
2247 if (substream->oss.oss) {
2248 snd_pcm_oss_setup_t *setup = substream->oss.setup;
2249 if (setup != NULL) {
2250 if (setup->nonblock)
2252 else if (setup->block)
2258 if (runtime->access != SNDRV_PCM_ACCESS_RW_INTERLEAVED &&
2259 runtime->channels > 1)
2261 return snd_pcm_lib_write1(substream, (unsigned long)buf, size, nonblock,
2262 snd_pcm_lib_write_transfer);
2265 static int snd_pcm_lib_writev_transfer(snd_pcm_substream_t *substream,
2267 unsigned long data, unsigned int off,
2268 snd_pcm_uframes_t frames)
2270 snd_pcm_runtime_t *runtime = substream->runtime;
2272 void __user **bufs = (void __user **)data;
2273 int channels = runtime->channels;
2275 if (substream->ops->copy) {
2276 snd_assert(substream->ops->silence != NULL, return -EINVAL);
2277 for (c = 0; c < channels; ++c, ++bufs) {
2278 if (*bufs == NULL) {
2279 if ((err = substream->ops->silence(substream, c, hwoff, frames)) < 0)
2282 char __user *buf = *bufs + samples_to_bytes(runtime, off);
2283 if ((err = substream->ops->copy(substream, c, hwoff, buf, frames)) < 0)
2288 /* default transfer behaviour */
2289 size_t dma_csize = runtime->dma_bytes / channels;
2290 snd_assert(runtime->dma_area, return -EFAULT);
2291 for (c = 0; c < channels; ++c, ++bufs) {
2292 char *hwbuf = runtime->dma_area + (c * dma_csize) + samples_to_bytes(runtime, hwoff);
2293 if (*bufs == NULL) {
2294 snd_pcm_format_set_silence(runtime->format, hwbuf, frames);
2296 char __user *buf = *bufs + samples_to_bytes(runtime, off);
2297 if (copy_from_user(hwbuf, buf, samples_to_bytes(runtime, frames)))
2305 snd_pcm_sframes_t snd_pcm_lib_writev(snd_pcm_substream_t *substream,
2307 snd_pcm_uframes_t frames)
2309 snd_pcm_runtime_t *runtime;
2312 snd_assert(substream != NULL, return -ENXIO);
2313 runtime = substream->runtime;
2314 snd_assert(runtime != NULL, return -ENXIO);
2315 snd_assert(substream->ops->copy != NULL || runtime->dma_area != NULL, return -EINVAL);
2316 if (runtime->status->state == SNDRV_PCM_STATE_OPEN)
2319 snd_assert(substream->ffile != NULL, return -ENXIO);
2320 nonblock = !!(substream->ffile->f_flags & O_NONBLOCK);
2321 #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
2322 if (substream->oss.oss) {
2323 snd_pcm_oss_setup_t *setup = substream->oss.setup;
2324 if (setup != NULL) {
2325 if (setup->nonblock)
2327 else if (setup->block)
2333 if (runtime->access != SNDRV_PCM_ACCESS_RW_NONINTERLEAVED)
2335 return snd_pcm_lib_write1(substream, (unsigned long)bufs, frames,
2336 nonblock, snd_pcm_lib_writev_transfer);
2339 static int snd_pcm_lib_read_transfer(snd_pcm_substream_t *substream,
2341 unsigned long data, unsigned int off,
2342 snd_pcm_uframes_t frames)
2344 snd_pcm_runtime_t *runtime = substream->runtime;
2346 char __user *buf = (char __user *) data + frames_to_bytes(runtime, off);
2347 if (substream->ops->copy) {
2348 if ((err = substream->ops->copy(substream, -1, hwoff, buf, frames)) < 0)
2351 char *hwbuf = runtime->dma_area + frames_to_bytes(runtime, hwoff);
2352 snd_assert(runtime->dma_area, return -EFAULT);
2353 if (copy_to_user(buf, hwbuf, frames_to_bytes(runtime, frames)))
2359 static snd_pcm_sframes_t snd_pcm_lib_read1(snd_pcm_substream_t *substream,
2361 snd_pcm_uframes_t size,
2363 transfer_f transfer)
2365 snd_pcm_runtime_t *runtime = substream->runtime;
2366 snd_pcm_uframes_t xfer = 0;
2367 snd_pcm_uframes_t offset = 0;
2372 if (size > runtime->xfer_align)
2373 size -= size % runtime->xfer_align;
2375 snd_pcm_stream_lock_irq(substream);
2376 switch (runtime->status->state) {
2377 case SNDRV_PCM_STATE_PREPARED:
2378 if (size >= runtime->start_threshold) {
2379 err = snd_pcm_start(substream);
2384 case SNDRV_PCM_STATE_DRAINING:
2385 case SNDRV_PCM_STATE_RUNNING:
2386 case SNDRV_PCM_STATE_PAUSED:
2388 case SNDRV_PCM_STATE_XRUN:
2391 case SNDRV_PCM_STATE_SUSPENDED:
2400 snd_pcm_uframes_t frames, appl_ptr, appl_ofs;
2401 snd_pcm_uframes_t avail;
2402 snd_pcm_uframes_t cont;
2403 if (runtime->sleep_min == 0 && runtime->status->state == SNDRV_PCM_STATE_RUNNING)
2404 snd_pcm_update_hw_ptr(substream);
2406 avail = snd_pcm_capture_avail(runtime);
2407 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
2408 if (avail < runtime->xfer_align) {
2412 } else if ((avail < runtime->control->avail_min && size > avail) ||
2413 (size >= runtime->xfer_align && avail < runtime->xfer_align)) {
2415 enum { READY, SIGNALED, ERROR, SUSPENDED, EXPIRED } state;
2423 init_waitqueue_entry(&wait, current);
2424 add_wait_queue(&runtime->sleep, &wait);
2426 if (signal_pending(current)) {
2430 set_current_state(TASK_INTERRUPTIBLE);
2431 snd_pcm_stream_unlock_irq(substream);
2432 tout = schedule_timeout(10 * HZ);
2433 snd_pcm_stream_lock_irq(substream);
2435 if (runtime->status->state != SNDRV_PCM_STATE_PREPARED &&
2436 runtime->status->state != SNDRV_PCM_STATE_PAUSED) {
2437 state = runtime->status->state == SNDRV_PCM_STATE_SUSPENDED ? SUSPENDED : EXPIRED;
2441 switch (runtime->status->state) {
2442 case SNDRV_PCM_STATE_XRUN:
2445 case SNDRV_PCM_STATE_SUSPENDED:
2448 case SNDRV_PCM_STATE_DRAINING:
2453 avail = snd_pcm_capture_avail(runtime);
2454 if (avail >= runtime->control->avail_min) {
2460 remove_wait_queue(&runtime->sleep, &wait);
2473 snd_printd("capture read error (DMA or IRQ trouble?)\n");
2480 if (avail > runtime->xfer_align)
2481 avail -= avail % runtime->xfer_align;
2482 frames = size > avail ? avail : size;
2483 cont = runtime->buffer_size - runtime->control->appl_ptr % runtime->buffer_size;
2486 snd_assert(frames != 0, snd_pcm_stream_unlock_irq(substream); return -EINVAL);
2487 appl_ptr = runtime->control->appl_ptr;
2488 appl_ofs = appl_ptr % runtime->buffer_size;
2489 snd_pcm_stream_unlock_irq(substream);
2490 if ((err = transfer(substream, appl_ofs, data, offset, frames)) < 0)
2492 snd_pcm_stream_lock_irq(substream);
2493 switch (runtime->status->state) {
2494 case SNDRV_PCM_STATE_XRUN:
2497 case SNDRV_PCM_STATE_SUSPENDED:
2504 if (appl_ptr >= runtime->boundary) {
2505 runtime->control->appl_ptr = 0;
2507 runtime->control->appl_ptr = appl_ptr;
2509 if (substream->ops->ack)
2510 substream->ops->ack(substream);
2515 if (runtime->sleep_min &&
2516 runtime->status->state == SNDRV_PCM_STATE_RUNNING)
2517 snd_pcm_tick_prepare(substream);
2520 snd_pcm_stream_unlock_irq(substream);
2522 return xfer > 0 ? (snd_pcm_sframes_t)xfer : err;
2525 snd_pcm_sframes_t snd_pcm_lib_read(snd_pcm_substream_t *substream, void __user *buf, snd_pcm_uframes_t size)
2527 snd_pcm_runtime_t *runtime;
2530 snd_assert(substream != NULL, return -ENXIO);
2531 runtime = substream->runtime;
2532 snd_assert(runtime != NULL, return -ENXIO);
2533 snd_assert(substream->ops->copy != NULL || runtime->dma_area != NULL, return -EINVAL);
2534 if (runtime->status->state == SNDRV_PCM_STATE_OPEN)
2537 snd_assert(substream->ffile != NULL, return -ENXIO);
2538 nonblock = !!(substream->ffile->f_flags & O_NONBLOCK);
2539 #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
2540 if (substream->oss.oss) {
2541 snd_pcm_oss_setup_t *setup = substream->oss.setup;
2542 if (setup != NULL) {
2543 if (setup->nonblock)
2545 else if (setup->block)
2550 if (runtime->access != SNDRV_PCM_ACCESS_RW_INTERLEAVED)
2552 return snd_pcm_lib_read1(substream, (unsigned long)buf, size, nonblock, snd_pcm_lib_read_transfer);
2555 static int snd_pcm_lib_readv_transfer(snd_pcm_substream_t *substream,
2557 unsigned long data, unsigned int off,
2558 snd_pcm_uframes_t frames)
2560 snd_pcm_runtime_t *runtime = substream->runtime;
2562 void __user **bufs = (void __user **)data;
2563 int channels = runtime->channels;
2565 if (substream->ops->copy) {
2566 for (c = 0; c < channels; ++c, ++bufs) {
2570 buf = *bufs + samples_to_bytes(runtime, off);
2571 if ((err = substream->ops->copy(substream, c, hwoff, buf, frames)) < 0)
2575 snd_pcm_uframes_t dma_csize = runtime->dma_bytes / channels;
2576 snd_assert(runtime->dma_area, return -EFAULT);
2577 for (c = 0; c < channels; ++c, ++bufs) {
2583 hwbuf = runtime->dma_area + (c * dma_csize) + samples_to_bytes(runtime, hwoff);
2584 buf = *bufs + samples_to_bytes(runtime, off);
2585 if (copy_to_user(buf, hwbuf, samples_to_bytes(runtime, frames)))
2592 snd_pcm_sframes_t snd_pcm_lib_readv(snd_pcm_substream_t *substream,
2594 snd_pcm_uframes_t frames)
2596 snd_pcm_runtime_t *runtime;
2599 snd_assert(substream != NULL, return -ENXIO);
2600 runtime = substream->runtime;
2601 snd_assert(runtime != NULL, return -ENXIO);
2602 snd_assert(substream->ops->copy != NULL || runtime->dma_area != NULL, return -EINVAL);
2603 if (runtime->status->state == SNDRV_PCM_STATE_OPEN)
2606 snd_assert(substream->ffile != NULL, return -ENXIO);
2607 nonblock = !!(substream->ffile->f_flags & O_NONBLOCK);
2608 #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
2609 if (substream->oss.oss) {
2610 snd_pcm_oss_setup_t *setup = substream->oss.setup;
2611 if (setup != NULL) {
2612 if (setup->nonblock)
2614 else if (setup->block)
2620 if (runtime->access != SNDRV_PCM_ACCESS_RW_NONINTERLEAVED)
2622 return snd_pcm_lib_read1(substream, (unsigned long)bufs, frames, nonblock, snd_pcm_lib_readv_transfer);
2629 EXPORT_SYMBOL(snd_interval_refine);
2630 EXPORT_SYMBOL(snd_interval_list);
2631 EXPORT_SYMBOL(snd_interval_ratnum);
2632 EXPORT_SYMBOL(snd_interval_ratden);
2633 EXPORT_SYMBOL(snd_interval_muldivk);
2634 EXPORT_SYMBOL(snd_interval_mulkdiv);
2635 EXPORT_SYMBOL(snd_interval_div);
2636 EXPORT_SYMBOL(_snd_pcm_hw_params_any);
2637 EXPORT_SYMBOL(_snd_pcm_hw_param_min);
2638 EXPORT_SYMBOL(_snd_pcm_hw_param_set);
2639 EXPORT_SYMBOL(_snd_pcm_hw_param_setempty);
2640 EXPORT_SYMBOL(_snd_pcm_hw_param_setinteger);
2641 EXPORT_SYMBOL(snd_pcm_hw_param_value_min);
2642 EXPORT_SYMBOL(snd_pcm_hw_param_value_max);
2643 EXPORT_SYMBOL(snd_pcm_hw_param_mask);
2644 EXPORT_SYMBOL(snd_pcm_hw_param_first);
2645 EXPORT_SYMBOL(snd_pcm_hw_param_last);
2646 EXPORT_SYMBOL(snd_pcm_hw_param_near);
2647 EXPORT_SYMBOL(snd_pcm_hw_param_set);
2648 EXPORT_SYMBOL(snd_pcm_hw_refine);
2649 EXPORT_SYMBOL(snd_pcm_hw_constraints_init);
2650 EXPORT_SYMBOL(snd_pcm_hw_constraints_complete);
2651 EXPORT_SYMBOL(snd_pcm_hw_constraint_list);
2652 EXPORT_SYMBOL(snd_pcm_hw_constraint_step);
2653 EXPORT_SYMBOL(snd_pcm_hw_constraint_ratnums);
2654 EXPORT_SYMBOL(snd_pcm_hw_constraint_ratdens);
2655 EXPORT_SYMBOL(snd_pcm_hw_constraint_msbits);
2656 EXPORT_SYMBOL(snd_pcm_hw_constraint_minmax);
2657 EXPORT_SYMBOL(snd_pcm_hw_constraint_integer);
2658 EXPORT_SYMBOL(snd_pcm_hw_constraint_pow2);
2659 EXPORT_SYMBOL(snd_pcm_hw_rule_add);
2660 EXPORT_SYMBOL(snd_pcm_set_ops);
2661 EXPORT_SYMBOL(snd_pcm_set_sync);
2662 EXPORT_SYMBOL(snd_pcm_lib_ioctl);
2663 EXPORT_SYMBOL(snd_pcm_playback_ready);
2664 EXPORT_SYMBOL(snd_pcm_capture_ready);
2665 EXPORT_SYMBOL(snd_pcm_playback_data);
2666 EXPORT_SYMBOL(snd_pcm_capture_empty);
2667 EXPORT_SYMBOL(snd_pcm_stop);
2668 EXPORT_SYMBOL(snd_pcm_period_elapsed);
2669 EXPORT_SYMBOL(snd_pcm_lib_write);
2670 EXPORT_SYMBOL(snd_pcm_lib_read);
2671 EXPORT_SYMBOL(snd_pcm_lib_writev);
2672 EXPORT_SYMBOL(snd_pcm_lib_readv);
2673 EXPORT_SYMBOL(snd_pcm_lib_buffer_bytes);
2674 EXPORT_SYMBOL(snd_pcm_lib_period_bytes);
2676 EXPORT_SYMBOL(snd_pcm_lib_preallocate_free);
2677 EXPORT_SYMBOL(snd_pcm_lib_preallocate_free_for_all);
2678 EXPORT_SYMBOL(snd_pcm_lib_preallocate_pages);
2679 EXPORT_SYMBOL(snd_pcm_lib_preallocate_pages_for_all);
2680 EXPORT_SYMBOL(snd_pcm_sgbuf_ops_page);
2681 EXPORT_SYMBOL(snd_pcm_lib_malloc_pages);
2682 EXPORT_SYMBOL(snd_pcm_lib_free_pages);