aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul McLean2014-04-01 10:45:24 -0500
committerAndroid (Google) Code Review2014-04-01 10:45:24 -0500
commitc6d37224e75b68a70a852fd78f88e38124d1781c (patch)
tree9f5d8de0c7011f6f02276fd18e78614cc1296d81
parent59610d55ac18acd39cff033d21c74745ef2854b3 (diff)
parentb25ece4c48ed459c83320343307d8c827ebe06a4 (diff)
downloadplatform-external-tinyalsa-c6d37224e75b68a70a852fd78f88e38124d1781c.tar.gz
platform-external-tinyalsa-c6d37224e75b68a70a852fd78f88e38124d1781c.tar.xz
platform-external-tinyalsa-c6d37224e75b68a70a852fd78f88e38124d1781c.zip
Merge "Add pcm_params_set_min/max and update comments"
-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 1083dba..de9dde7 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/* Converts the pcm parameters to a human readable string. 171/* Converts the pcm parameters to a human readable string.
168 * The string parameter is a caller allocated buffer of size bytes, 172 * The string parameter is a caller allocated buffer of size bytes,
diff --git a/pcm.c b/pcm.c
index 5ec68ec..6d85839 100644
--- a/pcm.c
+++ b/pcm.c
@@ -180,6 +180,14 @@ static unsigned int param_get_min(struct snd_pcm_hw_params *p, int n)
180 return 0; 180 return 0;
181} 181}
182 182
183static void param_set_max(struct snd_pcm_hw_params *p, int n, unsigned int val)
184{
185 if (param_is_interval(n)) {
186 struct snd_interval *i = param_to_interval(p, n);
187 i->max = val;
188 }
189}
190
183static unsigned int param_get_max(struct snd_pcm_hw_params *p, int n) 191static unsigned int param_get_max(struct snd_pcm_hw_params *p, int n)
184{ 192{
185 if (param_is_interval(n)) { 193 if (param_is_interval(n)) {
@@ -673,6 +681,22 @@ unsigned int pcm_params_get_min(struct pcm_params *pcm_params,
673 return param_get_min(params, p); 681 return param_get_min(params, p);
674} 682}
675 683
684void pcm_params_set_min(struct pcm_params *pcm_params,
685 enum pcm_param param, unsigned int val)
686{
687 struct snd_pcm_hw_params *params = (struct snd_pcm_hw_params *)pcm_params;
688 int p;
689
690 if (!params)
691 return;
692
693 p = pcm_param_to_alsa(param);
694 if (p < 0)
695 return;
696
697 param_set_min(params, p, val);
698}
699
676unsigned int pcm_params_get_max(struct pcm_params *pcm_params, 700unsigned int pcm_params_get_max(struct pcm_params *pcm_params,
677 enum pcm_param param) 701 enum pcm_param param)
678{ 702{
@@ -689,6 +713,22 @@ unsigned int pcm_params_get_max(struct pcm_params *pcm_params,
689 return param_get_max(params, p); 713 return param_get_max(params, p);
690} 714}
691 715
716void pcm_params_set_max(struct pcm_params *pcm_params,
717 enum pcm_param param, unsigned int val)
718{
719 struct snd_pcm_hw_params *params = (struct snd_pcm_hw_params *)pcm_params;
720 int p;
721
722 if (!params)
723 return;
724
725 p = pcm_param_to_alsa(param);
726 if (p < 0)
727 return;
728
729 param_set_max(params, p, val);
730}
731
692static int pcm_mask_test(struct pcm_mask *m, unsigned int index) 732static int pcm_mask_test(struct pcm_mask *m, unsigned int index)
693{ 733{
694 const unsigned int bitshift = 5; /* for 32 bit integer */ 734 const unsigned int bitshift = 5; /* for 32 bit integer */
@@ -838,7 +878,6 @@ struct pcm *pcm_open(unsigned int card, unsigned int device,
838 param_set_int(&params, SNDRV_PCM_HW_PARAM_RATE, config->rate); 878 param_set_int(&params, SNDRV_PCM_HW_PARAM_RATE, config->rate);
839 879
840 if (flags & PCM_NOIRQ) { 880 if (flags & PCM_NOIRQ) {
841
842 if (!(flags & PCM_MMAP)) { 881 if (!(flags & PCM_MMAP)) {
843 oops(pcm, -EINVAL, "noirq only currently supported with mmap()."); 882 oops(pcm, -EINVAL, "noirq only currently supported with mmap().");
844 goto fail; 883 goto fail;
@@ -850,10 +889,10 @@ struct pcm *pcm_open(unsigned int card, unsigned int device,
850 889
851 if (flags & PCM_MMAP) 890 if (flags & PCM_MMAP)
852 param_set_mask(&params, SNDRV_PCM_HW_PARAM_ACCESS, 891 param_set_mask(&params, SNDRV_PCM_HW_PARAM_ACCESS,
853 SNDRV_PCM_ACCESS_MMAP_INTERLEAVED); 892 SNDRV_PCM_ACCESS_MMAP_INTERLEAVED);
854 else 893 else
855 param_set_mask(&params, SNDRV_PCM_HW_PARAM_ACCESS, 894 param_set_mask(&params, SNDRV_PCM_HW_PARAM_ACCESS,
856 SNDRV_PCM_ACCESS_RW_INTERLEAVED); 895 SNDRV_PCM_ACCESS_RW_INTERLEAVED);
857 896
858 if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_HW_PARAMS, &params)) { 897 if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_HW_PARAMS, &params)) {
859 oops(pcm, errno, "cannot set hw params"); 898 oops(pcm, errno, "cannot set hw params");
@@ -875,7 +914,6 @@ struct pcm *pcm_open(unsigned int card, unsigned int device,
875 } 914 }
876 } 915 }
877 916
878
879 memset(&sparams, 0, sizeof(sparams)); 917 memset(&sparams, 0, sizeof(sparams));
880 sparams.tstamp_mode = SNDRV_PCM_TSTAMP_ENABLE; 918 sparams.tstamp_mode = SNDRV_PCM_TSTAMP_ENABLE;
881 sparams.period_step = 1; 919 sparams.period_step = 1;
@@ -915,7 +953,7 @@ struct pcm *pcm_open(unsigned int card, unsigned int device,
915 pcm->boundary = sparams.boundary = pcm->buffer_size; 953 pcm->boundary = sparams.boundary = pcm->buffer_size;
916 954
917 while (pcm->boundary * 2 <= INT_MAX - pcm->buffer_size) 955 while (pcm->boundary * 2 <= INT_MAX - pcm->buffer_size)
918 pcm->boundary *= 2; 956 pcm->boundary *= 2;
919 957
920 if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_SW_PARAMS, &sparams)) { 958 if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_SW_PARAMS, &sparams)) {
921 oops(pcm, errno, "cannot set sw params"); 959 oops(pcm, errno, "cannot set sw params");