aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/tinyalsa/asoundlib.h5
-rw-r--r--mixer.c6
-rw-r--r--pcm.c17
-rw-r--r--tinymix.c49
-rw-r--r--tinyplay.c1
5 files changed, 52 insertions, 26 deletions
diff --git a/include/tinyalsa/asoundlib.h b/include/tinyalsa/asoundlib.h
index e65403e..5894257 100644
--- a/include/tinyalsa/asoundlib.h
+++ b/include/tinyalsa/asoundlib.h
@@ -70,6 +70,8 @@ struct pcm;
enum pcm_format {
PCM_FORMAT_S16_LE = 0,
PCM_FORMAT_S32_LE,
+ PCM_FORMAT_S8,
+ PCM_FORMAT_S24_LE,
PCM_FORMAT_MAX,
};
@@ -157,6 +159,9 @@ int pcm_mmap_commit(struct pcm *pcm, unsigned int offset, unsigned int frames);
int pcm_start(struct pcm *pcm);
int pcm_stop(struct pcm *pcm);
+/* Interrupt driven API */
+int pcm_wait(struct pcm *pcm, int timeout);
+
/*
* MIXER API
diff --git a/mixer.c b/mixer.c
index 9514528..58d4fb5 100644
--- a/mixer.c
+++ b/mixer.c
@@ -353,8 +353,6 @@ int mixer_ctl_set_value(struct mixer_ctl *ctl, unsigned int id, int value)
int mixer_ctl_get_range_min(struct mixer_ctl *ctl)
{
- int ret;
-
if (!ctl || (ctl->info->type != SNDRV_CTL_ELEM_TYPE_INTEGER))
return -EINVAL;
@@ -363,8 +361,6 @@ int mixer_ctl_get_range_min(struct mixer_ctl *ctl)
int mixer_ctl_get_range_max(struct mixer_ctl *ctl)
{
- int ret;
-
if (!ctl || (ctl->info->type != SNDRV_CTL_ELEM_TYPE_INTEGER))
return -EINVAL;
@@ -382,8 +378,6 @@ unsigned int mixer_ctl_get_num_enums(struct mixer_ctl *ctl)
const char *mixer_ctl_get_enum_string(struct mixer_ctl *ctl,
unsigned int enum_id)
{
- int ret;
-
if (!ctl || (ctl->info->type != SNDRV_CTL_ELEM_TYPE_ENUMERATED) ||
(enum_id >= ctl->info->value.enumerated.items))
return NULL;
diff --git a/pcm.c b/pcm.c
index af175f2..00befe3 100644
--- a/pcm.c
+++ b/pcm.c
@@ -189,6 +189,10 @@ static unsigned int pcm_format_to_alsa(enum pcm_format format)
switch (format) {
case PCM_FORMAT_S32_LE:
return SNDRV_PCM_FORMAT_S32_LE;
+ case PCM_FORMAT_S8:
+ return SNDRV_PCM_FORMAT_S8;
+ case PCM_FORMAT_S24_LE:
+ return SNDRV_PCM_FORMAT_S24_LE;
default:
case PCM_FORMAT_S16_LE:
return SNDRV_PCM_FORMAT_S16_LE;
@@ -538,10 +542,13 @@ struct pcm *pcm_open(unsigned int card, unsigned int device,
sparams.period_step = 1;
sparams.avail_min = 1;
- if (!config->start_threshold)
- pcm->config.start_threshold = sparams.start_threshold =
- config->period_count * config->period_size / 2;
- else
+ if (!config->start_threshold) {
+ if (pcm->flags & PCM_IN)
+ pcm->config.start_threshold = sparams.start_threshold = 1;
+ else
+ pcm->config.start_threshold = sparams.start_threshold =
+ config->period_count * config->period_size / 2;
+ } else
sparams.start_threshold = config->start_threshold;
/* pick a high stop threshold - todo: does this need further tuning */
@@ -712,7 +719,6 @@ int pcm_state(struct pcm *pcm)
int pcm_wait(struct pcm *pcm, int timeout)
{
struct pollfd pfd;
- unsigned short revents = 0;
int err;
pfd.fd = pcm->fd;
@@ -825,6 +831,5 @@ int pcm_mmap_write(struct pcm *pcm, const void *buffer, unsigned int bytes)
count -= frames;
}
-_end:
return 0;
}
diff --git a/tinymix.c b/tinymix.c
index 6427a02..c22bbb2 100644
--- a/tinymix.c
+++ b/tinymix.c
@@ -35,7 +35,7 @@ static void tinymix_list_controls(struct mixer *mixer);
static void tinymix_detail_control(struct mixer *mixer, unsigned int id,
int print_all);
static void tinymix_set_value(struct mixer *mixer, unsigned int id,
- char *value);
+ char **values, unsigned int num_values);
static void tinymix_print_enum(struct mixer_ctl *ctl, int print_all);
int main(int argc, char **argv)
@@ -64,8 +64,8 @@ int main(int argc, char **argv)
tinymix_list_controls(mixer);
else if (argc == 2)
tinymix_detail_control(mixer, atoi(argv[1]), 1);
- else if (argc == 3)
- tinymix_set_value(mixer, atoi(argv[1]), argv[2]);
+ else if (argc >= 3)
+ tinymix_set_value(mixer, atoi(argv[1]), &argv[2], argc - 2);
else
printf("Usage: tinymix [-D card] [control id] [value to set]\n");
@@ -169,29 +169,50 @@ static void tinymix_detail_control(struct mixer *mixer, unsigned int id,
}
static void tinymix_set_value(struct mixer *mixer, unsigned int id,
- char *string)
+ char **values, unsigned int num_values)
{
struct mixer_ctl *ctl;
enum mixer_ctl_type type;
- unsigned int num_values;
+ unsigned int num_ctl_values;
unsigned int i;
ctl = mixer_get_ctl(mixer, id);
type = mixer_ctl_get_type(ctl);
- num_values = mixer_ctl_get_num_values(ctl);
-
- if (isdigit(string[0])) {
- int value = atoi(string);
-
- for (i = 0; i < num_values; i++) {
- if (mixer_ctl_set_value(ctl, i, value)) {
- fprintf(stderr, "Error: invalid value\n");
+ num_ctl_values = mixer_ctl_get_num_values(ctl);
+
+ if (isdigit(values[0][0])) {
+ if (num_values == 1) {
+ /* Set all values the same */
+ int value = atoi(values[0]);
+
+ for (i = 0; i < num_ctl_values; i++) {
+ if (mixer_ctl_set_value(ctl, i, value)) {
+ fprintf(stderr, "Error: invalid value\n");
+ return;
+ }
+ }
+ } else {
+ /* Set multiple values */
+ if (num_values > num_ctl_values) {
+ fprintf(stderr,
+ "Error: %d values given, but control only takes %d\n",
+ num_values, num_ctl_values);
return;
}
+ for (i = 0; i < num_values; i++) {
+ if (mixer_ctl_set_value(ctl, i, atoi(values[i]))) {
+ fprintf(stderr, "Error: invalid value for index %d\n", i);
+ return;
+ }
+ }
}
} else {
if (type == MIXER_CTL_TYPE_ENUM) {
- if (mixer_ctl_set_enum_by_string(ctl, string))
+ if (num_values != 1) {
+ fprintf(stderr, "Enclose strings in quotes and try again\n");
+ return;
+ }
+ if (mixer_ctl_set_enum_by_string(ctl, values[0]))
fprintf(stderr, "Error: invalid enum value\n");
} else {
fprintf(stderr, "Error: only enum types can be set with strings\n");
diff --git a/tinyplay.c b/tinyplay.c
index 3f76cc6..cc35170 100644
--- a/tinyplay.c
+++ b/tinyplay.c
@@ -30,6 +30,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
+#include <string.h>
#define ID_RIFF 0x46464952
#define ID_WAVE 0x45564157