diff options
author | Simon Wilson | 2013-07-17 13:10:45 -0500 |
---|---|---|
committer | Simon Wilson | 2013-07-17 13:10:45 -0500 |
commit | 36ea2d824e5d8af550c139da9da20e73f82a9ae1 (patch) | |
tree | e36fb98822052e1f269fbc3acef598cf5c9f48c6 | |
parent | 7e8a656722b3b19d499ad89c9c1e46b8be3da896 (diff) | |
download | platform-external-tinyalsa-36ea2d824e5d8af550c139da9da20e73f82a9ae1.tar.gz platform-external-tinyalsa-36ea2d824e5d8af550c139da9da20e73f82a9ae1.tar.xz platform-external-tinyalsa-36ea2d824e5d8af550c139da9da20e73f82a9ae1.zip |
Update to latest tinyalsa
782bfda tinymix: only print mixer name for full mixer dump
4f49678 tinycap: support 24 bit capture
7136cf7 pcm: support S24_LE format
Change-Id: Icf48dfe16883771e9ab9d14c5ec24f7d8a907bac
-rw-r--r-- | include/tinyalsa/asoundlib.h | 7 | ||||
-rw-r--r-- | pcm.c | 3 | ||||
-rw-r--r-- | tinycap.c | 35 | ||||
-rw-r--r-- | tinymix.c | 11 |
4 files changed, 40 insertions, 16 deletions
diff --git a/include/tinyalsa/asoundlib.h b/include/tinyalsa/asoundlib.h index 4dfffd9..9c23e6e 100644 --- a/include/tinyalsa/asoundlib.h +++ b/include/tinyalsa/asoundlib.h | |||
@@ -156,6 +156,13 @@ int pcm_set_config(struct pcm *pcm, struct pcm_config *config); | |||
156 | /* Returns a human readable reason for the last error */ | 156 | /* Returns a human readable reason for the last error */ |
157 | const char *pcm_get_error(struct pcm *pcm); | 157 | const char *pcm_get_error(struct pcm *pcm); |
158 | 158 | ||
159 | /* Returns the sample size in bits for a PCM format. | ||
160 | * As with ALSA formats, this is the storage size for the format, whereas the | ||
161 | * format represents the number of significant bits. For example, | ||
162 | * PCM_FORMAT_S24_LE uses 32 bits of storage. | ||
163 | */ | ||
164 | unsigned int pcm_format_to_bits(enum pcm_format format); | ||
165 | |||
159 | /* Returns the buffer size (int frames) that should be used for pcm_write. */ | 166 | /* Returns the buffer size (int frames) that should be used for pcm_write. */ |
160 | unsigned int pcm_get_buffer_size(struct pcm *pcm); | 167 | unsigned int pcm_get_buffer_size(struct pcm *pcm); |
161 | unsigned int pcm_frames_to_bytes(struct pcm *pcm, unsigned int frames); | 168 | unsigned int pcm_frames_to_bytes(struct pcm *pcm, unsigned int frames); |
@@ -213,10 +213,11 @@ static unsigned int pcm_format_to_alsa(enum pcm_format format) | |||
213 | }; | 213 | }; |
214 | } | 214 | } |
215 | 215 | ||
216 | static unsigned int pcm_format_to_bits(enum pcm_format format) | 216 | unsigned int pcm_format_to_bits(enum pcm_format format) |
217 | { | 217 | { |
218 | switch (format) { | 218 | switch (format) { |
219 | case PCM_FORMAT_S32_LE: | 219 | case PCM_FORMAT_S32_LE: |
220 | case PCM_FORMAT_S24_LE: | ||
220 | return 32; | 221 | return 32; |
221 | default: | 222 | default: |
222 | case PCM_FORMAT_S16_LE: | 223 | case PCM_FORMAT_S16_LE: |
@@ -60,7 +60,7 @@ int capturing = 1; | |||
60 | 60 | ||
61 | unsigned int capture_sample(FILE *file, unsigned int card, unsigned int device, | 61 | unsigned int capture_sample(FILE *file, unsigned int card, unsigned int device, |
62 | unsigned int channels, unsigned int rate, | 62 | unsigned int channels, unsigned int rate, |
63 | unsigned int bits, unsigned int period_size, | 63 | enum pcm_format format, unsigned int period_size, |
64 | unsigned int period_count); | 64 | unsigned int period_count); |
65 | 65 | ||
66 | void sigint_handler(int sig) | 66 | void sigint_handler(int sig) |
@@ -80,6 +80,7 @@ int main(int argc, char **argv) | |||
80 | unsigned int frames; | 80 | unsigned int frames; |
81 | unsigned int period_size = 1024; | 81 | unsigned int period_size = 1024; |
82 | unsigned int period_count = 4; | 82 | unsigned int period_count = 4; |
83 | enum pcm_format format; | ||
83 | 84 | ||
84 | if (argc < 2) { | 85 | if (argc < 2) { |
85 | fprintf(stderr, "Usage: %s file.wav [-D card] [-d device] [-c channels] " | 86 | fprintf(stderr, "Usage: %s file.wav [-D card] [-d device] [-c channels] " |
@@ -137,7 +138,23 @@ int main(int argc, char **argv) | |||
137 | header.audio_format = FORMAT_PCM; | 138 | header.audio_format = FORMAT_PCM; |
138 | header.num_channels = channels; | 139 | header.num_channels = channels; |
139 | header.sample_rate = rate; | 140 | header.sample_rate = rate; |
140 | header.bits_per_sample = bits; | 141 | |
142 | switch (bits) { | ||
143 | case 32: | ||
144 | format = PCM_FORMAT_S32_LE; | ||
145 | break; | ||
146 | case 24: | ||
147 | format = PCM_FORMAT_S24_LE; | ||
148 | break; | ||
149 | case 16: | ||
150 | format = PCM_FORMAT_S16_LE; | ||
151 | break; | ||
152 | default: | ||
153 | fprintf(stderr, "%d bits is not supported.\n", bits); | ||
154 | return 1; | ||
155 | } | ||
156 | |||
157 | header.bits_per_sample = pcm_format_to_bits(format); | ||
141 | header.byte_rate = (header.bits_per_sample / 8) * channels * rate; | 158 | header.byte_rate = (header.bits_per_sample / 8) * channels * rate; |
142 | header.block_align = channels * (header.bits_per_sample / 8); | 159 | header.block_align = channels * (header.bits_per_sample / 8); |
143 | header.data_id = ID_DATA; | 160 | header.data_id = ID_DATA; |
@@ -148,7 +165,7 @@ int main(int argc, char **argv) | |||
148 | /* install signal handler and begin capturing */ | 165 | /* install signal handler and begin capturing */ |
149 | signal(SIGINT, sigint_handler); | 166 | signal(SIGINT, sigint_handler); |
150 | frames = capture_sample(file, card, device, header.num_channels, | 167 | frames = capture_sample(file, card, device, header.num_channels, |
151 | header.sample_rate, header.bits_per_sample, | 168 | header.sample_rate, format, |
152 | period_size, period_count); | 169 | period_size, period_count); |
153 | printf("Captured %d frames\n", frames); | 170 | printf("Captured %d frames\n", frames); |
154 | 171 | ||
@@ -165,7 +182,7 @@ int main(int argc, char **argv) | |||
165 | 182 | ||
166 | unsigned int capture_sample(FILE *file, unsigned int card, unsigned int device, | 183 | unsigned int capture_sample(FILE *file, unsigned int card, unsigned int device, |
167 | unsigned int channels, unsigned int rate, | 184 | unsigned int channels, unsigned int rate, |
168 | unsigned int bits, unsigned int period_size, | 185 | enum pcm_format format, unsigned int period_size, |
169 | unsigned int period_count) | 186 | unsigned int period_count) |
170 | { | 187 | { |
171 | struct pcm_config config; | 188 | struct pcm_config config; |
@@ -178,10 +195,7 @@ unsigned int capture_sample(FILE *file, unsigned int card, unsigned int device, | |||
178 | config.rate = rate; | 195 | config.rate = rate; |
179 | config.period_size = period_size; | 196 | config.period_size = period_size; |
180 | config.period_count = period_count; | 197 | config.period_count = period_count; |
181 | if (bits == 32) | 198 | config.format = format; |
182 | config.format = PCM_FORMAT_S32_LE; | ||
183 | else if (bits == 16) | ||
184 | config.format = PCM_FORMAT_S16_LE; | ||
185 | config.start_threshold = 0; | 199 | config.start_threshold = 0; |
186 | config.stop_threshold = 0; | 200 | config.stop_threshold = 0; |
187 | config.silence_threshold = 0; | 201 | config.silence_threshold = 0; |
@@ -202,7 +216,8 @@ unsigned int capture_sample(FILE *file, unsigned int card, unsigned int device, | |||
202 | return 0; | 216 | return 0; |
203 | } | 217 | } |
204 | 218 | ||
205 | printf("Capturing sample: %u ch, %u hz, %u bit\n", channels, rate, bits); | 219 | printf("Capturing sample: %u ch, %u hz, %u bit\n", channels, rate, |
220 | pcm_format_to_bits(format)); | ||
206 | 221 | ||
207 | while (capturing && !pcm_read(pcm, buffer, size)) { | 222 | while (capturing && !pcm_read(pcm, buffer, size)) { |
208 | if (fwrite(buffer, 1, size, file) != size) { | 223 | if (fwrite(buffer, 1, size, file) != size) { |
@@ -214,6 +229,6 @@ unsigned int capture_sample(FILE *file, unsigned int card, unsigned int device, | |||
214 | 229 | ||
215 | free(buffer); | 230 | free(buffer); |
216 | pcm_close(pcm); | 231 | pcm_close(pcm); |
217 | return bytes_read / ((bits / 8) * channels); | 232 | return pcm_bytes_to_frames(pcm, bytes_read); |
218 | } | 233 | } |
219 | 234 | ||
@@ -61,16 +61,17 @@ int main(int argc, char **argv) | |||
61 | return EXIT_FAILURE; | 61 | return EXIT_FAILURE; |
62 | } | 62 | } |
63 | 63 | ||
64 | printf("Mixer name: '%s'\n", mixer_get_name(mixer)); | ||
65 | 64 | ||
66 | if (argc == 1) | 65 | if (argc == 1) { |
66 | printf("Mixer name: '%s'\n", mixer_get_name(mixer)); | ||
67 | tinymix_list_controls(mixer); | 67 | tinymix_list_controls(mixer); |
68 | else if (argc == 2) | 68 | } else if (argc == 2) { |
69 | tinymix_detail_control(mixer, argv[1], 1); | 69 | tinymix_detail_control(mixer, argv[1], 1); |
70 | else if (argc >= 3) | 70 | } else if (argc >= 3) { |
71 | tinymix_set_value(mixer, argv[1], &argv[2], argc - 2); | 71 | tinymix_set_value(mixer, argv[1], &argv[2], argc - 2); |
72 | else | 72 | } else { |
73 | printf("Usage: tinymix [-D card] [control id] [value to set]\n"); | 73 | printf("Usage: tinymix [-D card] [control id] [value to set]\n"); |
74 | } | ||
74 | 75 | ||
75 | mixer_close(mixer); | 76 | mixer_close(mixer); |
76 | 77 | ||