aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul McLean2014-03-21 17:27:34 -0500
committerGlenn Kasten2014-03-31 15:20:20 -0500
commitb25ece4c48ed459c83320343307d8c827ebe06a4 (patch)
treeb8a48b1cb1220b07d5dc6492a264de767ab70ee0
parenta5b44d9bba0c5df52b37850bb929eb53817fb4a4 (diff)
downloadplatform-external-tinyalsa-b25ece4c48ed459c83320343307d8c827ebe06a4.tar.gz
platform-external-tinyalsa-b25ece4c48ed459c83320343307d8c827ebe06a4.tar.xz
platform-external-tinyalsa-b25ece4c48ed459c83320343307d8c827ebe06a4.zip
Add pcm_params_set_min/max and update comments
Change-Id: I40040a7e94689dcf6bf9d0bf0d182f66b151d530
-rw-r--r--include/tinyalsa/asoundlib.h14
-rw-r--r--pcm.c48
2 files changed, 52 insertions, 10 deletions
diff --git a/include/tinyalsa/asoundlib.h b/include/tinyalsa/asoundlib.h
index 03e3c13..392e497 100644
--- a/include/tinyalsa/asoundlib.h
+++ b/include/tinyalsa/asoundlib.h
@@ -70,11 +70,11 @@ struct pcm;
70 70
71/* Bit formats */ 71/* Bit formats */
72enum pcm_format { 72enum pcm_format {
73 PCM_FORMAT_S16_LE = 0, 73 PCM_FORMAT_S16_LE = 0, /* 16-bit signed */
74 PCM_FORMAT_S32_LE, 74 PCM_FORMAT_S32_LE, /* 32-bit signed */
75 PCM_FORMAT_S8, 75 PCM_FORMAT_S8, /* 8-bit signed */
76 PCM_FORMAT_S24_LE, 76 PCM_FORMAT_S24_LE, /* 24-bits in 4-bytes */
77 PCM_FORMAT_S24_3LE, 77 PCM_FORMAT_S24_3LE, /* 24-bits in 3-bytes */
78 78
79 PCM_FORMAT_MAX, 79 PCM_FORMAT_MAX,
80}; 80};
@@ -161,8 +161,12 @@ struct pcm_mask *pcm_params_get_mask(struct pcm_params *pcm_params,
161 enum pcm_param param); 161 enum pcm_param param);
162unsigned int pcm_params_get_min(struct pcm_params *pcm_params, 162unsigned int pcm_params_get_min(struct pcm_params *pcm_params,
163 enum pcm_param param); 163 enum pcm_param param);
164void pcm_params_set_min(struct pcm_params *pcm_params,
165 enum pcm_param param, unsigned int val);
164unsigned int pcm_params_get_max(struct pcm_params *pcm_params, 166unsigned int pcm_params_get_max(struct pcm_params *pcm_params,
165 enum pcm_param param); 167 enum pcm_param param);
168void pcm_params_set_max(struct pcm_params *pcm_params,
169 enum pcm_param param, unsigned int val);
166 170
167/* Set and get config */ 171/* Set and get config */
168int pcm_get_config(struct pcm *pcm, struct pcm_config *config); 172int pcm_get_config(struct pcm *pcm, struct pcm_config *config);
diff --git a/pcm.c b/pcm.c
index 7c05a87..662e8a1 100644
--- a/pcm.c
+++ b/pcm.c
@@ -102,6 +102,14 @@ static unsigned int param_get_min(struct snd_pcm_hw_params *p, int n)
102 return 0; 102 return 0;
103} 103}
104 104
105static void param_set_max(struct snd_pcm_hw_params *p, int n, unsigned int val)
106{
107 if (param_is_interval(n)) {
108 struct snd_interval *i = param_to_interval(p, n);
109 i->max = val;
110 }
111}
112
105static unsigned int param_get_max(struct snd_pcm_hw_params *p, int n) 113static unsigned int param_get_max(struct snd_pcm_hw_params *p, int n)
106{ 114{
107 if (param_is_interval(n)) { 115 if (param_is_interval(n)) {
@@ -595,6 +603,22 @@ unsigned int pcm_params_get_min(struct pcm_params *pcm_params,
595 return param_get_min(params, p); 603 return param_get_min(params, p);
596} 604}
597 605
606void pcm_params_set_min(struct pcm_params *pcm_params,
607 enum pcm_param param, unsigned int val)
608{
609 struct snd_pcm_hw_params *params = (struct snd_pcm_hw_params *)pcm_params;
610 int p;
611
612 if (!params)
613 return;
614
615 p = pcm_param_to_alsa(param);
616 if (p < 0)
617 return;
618
619 param_set_min(params, p, val);
620}
621
598unsigned int pcm_params_get_max(struct pcm_params *pcm_params, 622unsigned int pcm_params_get_max(struct pcm_params *pcm_params,
599 enum pcm_param param) 623 enum pcm_param param)
600{ 624{
@@ -611,6 +635,22 @@ unsigned int pcm_params_get_max(struct pcm_params *pcm_params,
611 return param_get_max(params, p); 635 return param_get_max(params, p);
612} 636}
613 637
638void pcm_params_set_max(struct pcm_params *pcm_params,
639 enum pcm_param param, unsigned int val)
640{
641 struct snd_pcm_hw_params *params = (struct snd_pcm_hw_params *)pcm_params;
642 int p;
643
644 if (!params)
645 return;
646
647 p = pcm_param_to_alsa(param);
648 if (p < 0)
649 return;
650
651 param_set_max(params, p, val);
652}
653
614int pcm_close(struct pcm *pcm) 654int pcm_close(struct pcm *pcm)
615{ 655{
616 if (pcm == &bad_pcm) 656 if (pcm == &bad_pcm)
@@ -679,7 +719,6 @@ struct pcm *pcm_open(unsigned int card, unsigned int device,
679 param_set_int(&params, SNDRV_PCM_HW_PARAM_RATE, config->rate); 719 param_set_int(&params, SNDRV_PCM_HW_PARAM_RATE, config->rate);
680 720
681 if (flags & PCM_NOIRQ) { 721 if (flags & PCM_NOIRQ) {
682
683 if (!(flags & PCM_MMAP)) { 722 if (!(flags & PCM_MMAP)) {
684 oops(pcm, -EINVAL, "noirq only currently supported with mmap()."); 723 oops(pcm, -EINVAL, "noirq only currently supported with mmap().");
685 goto fail; 724 goto fail;
@@ -691,10 +730,10 @@ struct pcm *pcm_open(unsigned int card, unsigned int device,
691 730
692 if (flags & PCM_MMAP) 731 if (flags & PCM_MMAP)
693 param_set_mask(&params, SNDRV_PCM_HW_PARAM_ACCESS, 732 param_set_mask(&params, SNDRV_PCM_HW_PARAM_ACCESS,
694 SNDRV_PCM_ACCESS_MMAP_INTERLEAVED); 733 SNDRV_PCM_ACCESS_MMAP_INTERLEAVED);
695 else 734 else
696 param_set_mask(&params, SNDRV_PCM_HW_PARAM_ACCESS, 735 param_set_mask(&params, SNDRV_PCM_HW_PARAM_ACCESS,
697 SNDRV_PCM_ACCESS_RW_INTERLEAVED); 736 SNDRV_PCM_ACCESS_RW_INTERLEAVED);
698 737
699 if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_HW_PARAMS, &params)) { 738 if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_HW_PARAMS, &params)) {
700 oops(pcm, errno, "cannot set hw params"); 739 oops(pcm, errno, "cannot set hw params");
@@ -716,7 +755,6 @@ struct pcm *pcm_open(unsigned int card, unsigned int device,
716 } 755 }
717 } 756 }
718 757
719
720 memset(&sparams, 0, sizeof(sparams)); 758 memset(&sparams, 0, sizeof(sparams));
721 sparams.tstamp_mode = SNDRV_PCM_TSTAMP_ENABLE; 759 sparams.tstamp_mode = SNDRV_PCM_TSTAMP_ENABLE;
722 sparams.period_step = 1; 760 sparams.period_step = 1;
@@ -756,7 +794,7 @@ struct pcm *pcm_open(unsigned int card, unsigned int device,
756 pcm->boundary = sparams.boundary = pcm->buffer_size; 794 pcm->boundary = sparams.boundary = pcm->buffer_size;
757 795
758 while (pcm->boundary * 2 <= INT_MAX - pcm->buffer_size) 796 while (pcm->boundary * 2 <= INT_MAX - pcm->buffer_size)
759 pcm->boundary *= 2; 797 pcm->boundary *= 2;
760 798
761 if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_SW_PARAMS, &sparams)) { 799 if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_SW_PARAMS, &sparams)) {
762 oops(pcm, errno, "cannot set sw params"); 800 oops(pcm, errno, "cannot set sw params");