mirror of
https://github.com/alsa-project/alsa-utils
synced 2024-11-10 00:25:43 +01:00
Added I/O classes
This commit is contained in:
parent
be058e4a04
commit
025a1c8d26
2 changed files with 31 additions and 24 deletions
|
@ -916,7 +916,8 @@ static int save_state(char *file, const char *cardname)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
snd_config_t *config;
|
snd_config_t *config;
|
||||||
FILE *fp;
|
snd_input_t *in;
|
||||||
|
snd_output_t *out;
|
||||||
int stdio;
|
int stdio;
|
||||||
|
|
||||||
err = snd_config_top(&config);
|
err = snd_config_top(&config);
|
||||||
|
@ -925,10 +926,9 @@ static int save_state(char *file, const char *cardname)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
stdio = !strcmp(file, "-");
|
stdio = !strcmp(file, "-");
|
||||||
if (!stdio && (fp = fopen(file, "r"))) {
|
if (!stdio && (err = snd_input_stdio_open(&in, file)) >= 0) {
|
||||||
err = snd_config_load(config, fp);
|
err = snd_config_load(config, in);
|
||||||
if (!stdio)
|
snd_input_close(in);
|
||||||
fclose(fp);
|
|
||||||
#if 0
|
#if 0
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
error("snd_config_load error: %s", snd_strerror(err));
|
error("snd_config_load error: %s", snd_strerror(err));
|
||||||
|
@ -969,17 +969,16 @@ static int save_state(char *file, const char *cardname)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stdio)
|
if (stdio)
|
||||||
fp = stdout;
|
err = snd_output_stdio_attach(&out, stdout, 0);
|
||||||
else
|
else
|
||||||
fp = fopen(file, "w");
|
err = snd_output_stdio_open(&out, file);
|
||||||
if (!fp) {
|
if (err < 0) {
|
||||||
error("Cannot open %s for writing", file);
|
error("Cannot open %s for writing", file);
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
err = snd_config_save(config, fp);
|
err = snd_config_save(config, out);
|
||||||
if (!stdio)
|
snd_output_close(out);
|
||||||
fclose(fp);
|
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
error("snd_config_save: %s", snd_strerror(err));
|
error("snd_config_save: %s", snd_strerror(err));
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -990,7 +989,7 @@ static int load_state(char *file, const char *cardname)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
snd_config_t *config;
|
snd_config_t *config;
|
||||||
FILE *fp;
|
snd_input_t *in;
|
||||||
int stdio;
|
int stdio;
|
||||||
|
|
||||||
err = snd_config_top(&config);
|
err = snd_config_top(&config);
|
||||||
|
@ -1000,13 +999,12 @@ static int load_state(char *file, const char *cardname)
|
||||||
}
|
}
|
||||||
stdio = !strcmp(file, "-");
|
stdio = !strcmp(file, "-");
|
||||||
if (stdio)
|
if (stdio)
|
||||||
fp = stdin;
|
err = snd_input_stdio_attach(&in, stdin, 0);
|
||||||
else
|
else
|
||||||
fp = fopen(file, "r");
|
err = snd_input_stdio_open(&in, file);
|
||||||
if (fp) {
|
if (err >= 0) {
|
||||||
err = snd_config_load(config, fp);
|
err = snd_config_load(config, in);
|
||||||
if (!stdio)
|
snd_input_close(in);
|
||||||
fclose(fp);
|
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
error("snd_config_load error: %s", snd_strerror(err));
|
error("snd_config_load error: %s", snd_strerror(err));
|
||||||
return err;
|
return err;
|
||||||
|
|
|
@ -86,6 +86,7 @@ static size_t bits_per_sample, bits_per_frame;
|
||||||
static size_t chunk_bytes;
|
static size_t chunk_bytes;
|
||||||
static int digtype = SND_CONTROL_TYPE_NONE;
|
static int digtype = SND_CONTROL_TYPE_NONE;
|
||||||
static snd_digital_audio_t diga;
|
static snd_digital_audio_t diga;
|
||||||
|
static snd_output_t *log;
|
||||||
|
|
||||||
static int count;
|
static int count;
|
||||||
static int vocmajor, vocminor;
|
static int vocmajor, vocminor;
|
||||||
|
@ -235,14 +236,18 @@ static void device_list(void)
|
||||||
static void pcm_list(void)
|
static void pcm_list(void)
|
||||||
{
|
{
|
||||||
snd_config_t *conf;
|
snd_config_t *conf;
|
||||||
|
snd_output_t *out;
|
||||||
int err = snd_config_update();
|
int err = snd_config_update();
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
error("snd_pcm_update: %s", snd_strerror(err));
|
error("snd_pcm_update: %s", snd_strerror(err));
|
||||||
|
err = snd_output_stdio_attach(&out, stderr, 0);
|
||||||
|
assert(err >= 0);
|
||||||
err = snd_config_search(snd_config, "pcm", &conf);
|
err = snd_config_search(snd_config, "pcm", &conf);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return;
|
return;
|
||||||
fprintf(stderr, "PCM list:");
|
fprintf(stderr, "PCM list:");
|
||||||
snd_config_save(conf, stderr);
|
snd_config_save(conf, out);
|
||||||
|
snd_output_close(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void version(void)
|
static void version(void)
|
||||||
|
@ -285,6 +290,9 @@ int main(int argc, char *argv[])
|
||||||
char *pcm_name = "plug:0,0";
|
char *pcm_name = "plug:0,0";
|
||||||
int tmp, err, c;
|
int tmp, err, c;
|
||||||
|
|
||||||
|
err = snd_output_stdio_attach(&log, stderr, 0);
|
||||||
|
assert(err >= 0);
|
||||||
|
|
||||||
command = argv[0];
|
command = argv[0];
|
||||||
file_type = FORMAT_DEFAULT;
|
file_type = FORMAT_DEFAULT;
|
||||||
if (strstr(argv[0], "arecord")) {
|
if (strstr(argv[0], "arecord")) {
|
||||||
|
@ -517,6 +525,7 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
snd_pcm_close(handle);
|
snd_pcm_close(handle);
|
||||||
free(audiobuf);
|
free(audiobuf);
|
||||||
|
snd_output_close(log);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -774,7 +783,7 @@ static void set_params(void)
|
||||||
err = snd_pcm_hw_params(handle, ¶ms);
|
err = snd_pcm_hw_params(handle, ¶ms);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
fprintf(stderr, "Unable to install hw params:\n");
|
fprintf(stderr, "Unable to install hw params:\n");
|
||||||
snd_pcm_hw_params_dump(¶ms, stderr);
|
snd_pcm_hw_params_dump(¶ms, log);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
chunk_size = snd_pcm_hw_param_value(¶ms, SND_PCM_HW_PARAM_PERIOD_SIZE, 0);
|
chunk_size = snd_pcm_hw_param_value(¶ms, SND_PCM_HW_PARAM_PERIOD_SIZE, 0);
|
||||||
|
@ -798,7 +807,7 @@ static void set_params(void)
|
||||||
assert(err >= 0);
|
assert(err >= 0);
|
||||||
if (snd_pcm_sw_params(handle, &swparams) < 0) {
|
if (snd_pcm_sw_params(handle, &swparams) < 0) {
|
||||||
error("unable to install sw params:");
|
error("unable to install sw params:");
|
||||||
snd_pcm_sw_params_dump(&swparams, stderr);
|
snd_pcm_sw_params_dump(&swparams, log);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
if (snd_pcm_prepare(handle) < 0) {
|
if (snd_pcm_prepare(handle) < 0) {
|
||||||
|
@ -807,7 +816,7 @@ static void set_params(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
snd_pcm_dump(handle, stderr);
|
snd_pcm_dump(handle, log);
|
||||||
|
|
||||||
bits_per_sample = snd_pcm_format_physical_width(hwparams.format);
|
bits_per_sample = snd_pcm_format_physical_width(hwparams.format);
|
||||||
bits_per_frame = bits_per_sample * hwparams.channels;
|
bits_per_frame = bits_per_sample * hwparams.channels;
|
||||||
|
@ -839,7 +848,7 @@ void xrun(void)
|
||||||
fprintf(stderr, "xrun!!! (at least %.3f ms long)\n", diff.tv_sec * 1000 + diff.tv_usec / 1000.0);
|
fprintf(stderr, "xrun!!! (at least %.3f ms long)\n", diff.tv_sec * 1000 + diff.tv_usec / 1000.0);
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
fprintf(stderr, "Status:\n");
|
fprintf(stderr, "Status:\n");
|
||||||
snd_pcm_status_dump(&status, stderr);
|
snd_pcm_status_dump(&status, log);
|
||||||
}
|
}
|
||||||
if ((res = snd_pcm_prepare(handle))<0) {
|
if ((res = snd_pcm_prepare(handle))<0) {
|
||||||
error("xrun: prepare error: %s", snd_strerror(res));
|
error("xrun: prepare error: %s", snd_strerror(res));
|
||||||
|
|
Loading…
Reference in a new issue