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
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 @@
/* Returns a human readable reason for the last error */
const char *pcm_get_error(struct pcm *pcm);
+/* Returns the sample size in bits for a PCM format.
+ * As with ALSA formats, this is the storage size for the format, whereas the
+ * format represents the number of significant bits. For example,
+ * PCM_FORMAT_S24_LE uses 32 bits of storage.
+ */
+unsigned int pcm_format_to_bits(enum pcm_format format);
+
/* Returns the buffer size (int frames) that should be used for pcm_write. */
unsigned int pcm_get_buffer_size(struct pcm *pcm);
unsigned int pcm_frames_to_bytes(struct pcm *pcm, unsigned int frames);
diff --git a/pcm.c b/pcm.c
index 4b31c4d..3006d6b 100644
--- a/pcm.c
+++ b/pcm.c
@@ -213,10 +213,11 @@
};
}
-static unsigned int pcm_format_to_bits(enum pcm_format format)
+unsigned int pcm_format_to_bits(enum pcm_format format)
{
switch (format) {
case PCM_FORMAT_S32_LE:
+ case PCM_FORMAT_S24_LE:
return 32;
default:
case PCM_FORMAT_S16_LE:
diff --git a/tinycap.c b/tinycap.c
index be289d4..7429750 100644
--- a/tinycap.c
+++ b/tinycap.c
@@ -60,7 +60,7 @@
unsigned int capture_sample(FILE *file, unsigned int card, unsigned int device,
unsigned int channels, unsigned int rate,
- unsigned int bits, unsigned int period_size,
+ enum pcm_format format, unsigned int period_size,
unsigned int period_count);
void sigint_handler(int sig)
@@ -80,6 +80,7 @@
unsigned int frames;
unsigned int period_size = 1024;
unsigned int period_count = 4;
+ enum pcm_format format;
if (argc < 2) {
fprintf(stderr, "Usage: %s file.wav [-D card] [-d device] [-c channels] "
@@ -137,7 +138,23 @@
header.audio_format = FORMAT_PCM;
header.num_channels = channels;
header.sample_rate = rate;
- header.bits_per_sample = bits;
+
+ switch (bits) {
+ case 32:
+ format = PCM_FORMAT_S32_LE;
+ break;
+ case 24:
+ format = PCM_FORMAT_S24_LE;
+ break;
+ case 16:
+ format = PCM_FORMAT_S16_LE;
+ break;
+ default:
+ fprintf(stderr, "%d bits is not supported.\n", bits);
+ return 1;
+ }
+
+ header.bits_per_sample = pcm_format_to_bits(format);
header.byte_rate = (header.bits_per_sample / 8) * channels * rate;
header.block_align = channels * (header.bits_per_sample / 8);
header.data_id = ID_DATA;
@@ -148,7 +165,7 @@
/* install signal handler and begin capturing */
signal(SIGINT, sigint_handler);
frames = capture_sample(file, card, device, header.num_channels,
- header.sample_rate, header.bits_per_sample,
+ header.sample_rate, format,
period_size, period_count);
printf("Captured %d frames\n", frames);
@@ -165,7 +182,7 @@
unsigned int capture_sample(FILE *file, unsigned int card, unsigned int device,
unsigned int channels, unsigned int rate,
- unsigned int bits, unsigned int period_size,
+ enum pcm_format format, unsigned int period_size,
unsigned int period_count)
{
struct pcm_config config;
@@ -178,10 +195,7 @@
config.rate = rate;
config.period_size = period_size;
config.period_count = period_count;
- if (bits == 32)
- config.format = PCM_FORMAT_S32_LE;
- else if (bits == 16)
- config.format = PCM_FORMAT_S16_LE;
+ config.format = format;
config.start_threshold = 0;
config.stop_threshold = 0;
config.silence_threshold = 0;
@@ -202,7 +216,8 @@
return 0;
}
- printf("Capturing sample: %u ch, %u hz, %u bit\n", channels, rate, bits);
+ printf("Capturing sample: %u ch, %u hz, %u bit\n", channels, rate,
+ pcm_format_to_bits(format));
while (capturing && !pcm_read(pcm, buffer, size)) {
if (fwrite(buffer, 1, size, file) != size) {
@@ -214,6 +229,6 @@
free(buffer);
pcm_close(pcm);
- return bytes_read / ((bits / 8) * channels);
+ return pcm_bytes_to_frames(pcm, bytes_read);
}
diff --git a/tinymix.c b/tinymix.c
index da0c463..afc2fee 100644
--- a/tinymix.c
+++ b/tinymix.c
@@ -61,16 +61,17 @@
return EXIT_FAILURE;
}
- printf("Mixer name: '%s'\n", mixer_get_name(mixer));
- if (argc == 1)
+ if (argc == 1) {
+ printf("Mixer name: '%s'\n", mixer_get_name(mixer));
tinymix_list_controls(mixer);
- else if (argc == 2)
+ } else if (argc == 2) {
tinymix_detail_control(mixer, argv[1], 1);
- else if (argc >= 3)
+ } else if (argc >= 3) {
tinymix_set_value(mixer, argv[1], &argv[2], argc - 2);
- else
+ } else {
printf("Usage: tinymix [-D card] [control id] [value to set]\n");
+ }
mixer_close(mixer);