Revert "aplay: try to use 16-bit format to increase capture quality"

This reverts commit 0c5948e98a.

Link: https://github.com/alsa-project/alsa-utils/issues/96
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
Jaroslav Kysela 2021-06-14 12:02:35 +02:00
parent 0e21f4d864
commit f35b66d8f1

View file

@ -32,7 +32,6 @@
#include <malloc.h> #include <malloc.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h>
#include <string.h> #include <string.h>
#include <getopt.h> #include <getopt.h>
#include <fcntl.h> #include <fcntl.h>
@ -95,7 +94,6 @@ enum {
VUMETER_STEREO VUMETER_STEREO
}; };
static snd_pcm_format_t default_format = DEFAULT_FORMAT;
static char *command; static char *command;
static snd_pcm_t *handle; static snd_pcm_t *handle;
static struct { static struct {
@ -470,24 +468,6 @@ static long parse_long(const char *str, int *err)
return val; return val;
} }
static void try_to_adjust_default_format_16bit(void)
{
snd_pcm_hw_params_t *params;
int err;
snd_pcm_hw_params_alloca(&params);
err = snd_pcm_hw_params_any(handle, params);
if (err < 0) {
error(_("Broken configuration for this PCM: no configurations available"));
prg_exit(EXIT_FAILURE);
}
if (file_type != FORMAT_AU && snd_pcm_hw_params_test_format(handle, params, SND_PCM_FORMAT_S16_LE) == 0)
rhwparams.format = default_format = SND_PCM_FORMAT_S16_LE;
else if (file_type == FORMAT_AU && snd_pcm_hw_params_test_format(handle, params, SND_PCM_FORMAT_S16_BE) == 0)
rhwparams.format = default_format = SND_PCM_FORMAT_S16_BE;
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int duration_or_sample = 0; int duration_or_sample = 0;
@ -548,7 +528,6 @@ int main(int argc, char *argv[])
int do_device_list = 0, do_pcm_list = 0; int do_device_list = 0, do_pcm_list = 0;
snd_pcm_info_t *info; snd_pcm_info_t *info;
FILE *direction; FILE *direction;
bool user_set_fmt = false;
#ifdef ENABLE_NLS #ifdef ENABLE_NLS
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
@ -583,7 +562,7 @@ int main(int argc, char *argv[])
} }
chunk_size = -1; chunk_size = -1;
rhwparams.format = default_format; rhwparams.format = DEFAULT_FORMAT;
rhwparams.rate = DEFAULT_SPEED; rhwparams.rate = DEFAULT_SPEED;
rhwparams.channels = 1; rhwparams.channels = 1;
@ -633,7 +612,6 @@ int main(int argc, char *argv[])
} }
break; break;
case 'f': case 'f':
user_set_fmt = true;
if (strcasecmp(optarg, "cd") == 0 || strcasecmp(optarg, "cdr") == 0) { if (strcasecmp(optarg, "cd") == 0 || strcasecmp(optarg, "cdr") == 0) {
if (strcasecmp(optarg, "cdr") == 0) if (strcasecmp(optarg, "cdr") == 0)
rhwparams.format = SND_PCM_FORMAT_S16_BE; rhwparams.format = SND_PCM_FORMAT_S16_BE;
@ -866,9 +844,6 @@ int main(int argc, char *argv[])
} }
} }
if (!user_set_fmt)
try_to_adjust_default_format_16bit();
chunk_size = 1024; chunk_size = 1024;
hwparams = rhwparams; hwparams = rhwparams;
@ -1089,7 +1064,7 @@ static ssize_t test_wavefile(int fd, u_char *_buffer, size_t size)
hwparams.channels = channels; hwparams.channels = channels;
switch (TO_CPU_SHORT(f->bit_p_spl, big_endian)) { switch (TO_CPU_SHORT(f->bit_p_spl, big_endian)) {
case 8: case 8:
if (hwparams.format != default_format && if (hwparams.format != DEFAULT_FORMAT &&
hwparams.format != SND_PCM_FORMAT_U8) hwparams.format != SND_PCM_FORMAT_U8)
fprintf(stderr, _("Warning: format is changed to U8\n")); fprintf(stderr, _("Warning: format is changed to U8\n"));
hwparams.format = SND_PCM_FORMAT_U8; hwparams.format = SND_PCM_FORMAT_U8;
@ -1099,7 +1074,7 @@ static ssize_t test_wavefile(int fd, u_char *_buffer, size_t size)
native_format = SND_PCM_FORMAT_S16_BE; native_format = SND_PCM_FORMAT_S16_BE;
else else
native_format = SND_PCM_FORMAT_S16_LE; native_format = SND_PCM_FORMAT_S16_LE;
if (hwparams.format != default_format && if (hwparams.format != DEFAULT_FORMAT &&
hwparams.format != native_format) hwparams.format != native_format)
fprintf(stderr, _("Warning: format is changed to %s\n"), fprintf(stderr, _("Warning: format is changed to %s\n"),
snd_pcm_format_name(native_format)); snd_pcm_format_name(native_format));
@ -1112,7 +1087,7 @@ static ssize_t test_wavefile(int fd, u_char *_buffer, size_t size)
native_format = SND_PCM_FORMAT_S24_3BE; native_format = SND_PCM_FORMAT_S24_3BE;
else else
native_format = SND_PCM_FORMAT_S24_3LE; native_format = SND_PCM_FORMAT_S24_3LE;
if (hwparams.format != default_format && if (hwparams.format != DEFAULT_FORMAT &&
hwparams.format != native_format) hwparams.format != native_format)
fprintf(stderr, _("Warning: format is changed to %s\n"), fprintf(stderr, _("Warning: format is changed to %s\n"),
snd_pcm_format_name(native_format)); snd_pcm_format_name(native_format));
@ -1123,7 +1098,7 @@ static ssize_t test_wavefile(int fd, u_char *_buffer, size_t size)
native_format = SND_PCM_FORMAT_S24_BE; native_format = SND_PCM_FORMAT_S24_BE;
else else
native_format = SND_PCM_FORMAT_S24_LE; native_format = SND_PCM_FORMAT_S24_LE;
if (hwparams.format != default_format && if (hwparams.format != DEFAULT_FORMAT &&
hwparams.format != native_format) hwparams.format != native_format)
fprintf(stderr, _("Warning: format is changed to %s\n"), fprintf(stderr, _("Warning: format is changed to %s\n"),
snd_pcm_format_name(native_format)); snd_pcm_format_name(native_format));
@ -1209,19 +1184,19 @@ static int test_au(int fd, void *buffer)
pbrec_count = BE_INT(ap->data_size); pbrec_count = BE_INT(ap->data_size);
switch (BE_INT(ap->encoding)) { switch (BE_INT(ap->encoding)) {
case AU_FMT_ULAW: case AU_FMT_ULAW:
if (hwparams.format != default_format && if (hwparams.format != DEFAULT_FORMAT &&
hwparams.format != SND_PCM_FORMAT_MU_LAW) hwparams.format != SND_PCM_FORMAT_MU_LAW)
fprintf(stderr, _("Warning: format is changed to MU_LAW\n")); fprintf(stderr, _("Warning: format is changed to MU_LAW\n"));
hwparams.format = SND_PCM_FORMAT_MU_LAW; hwparams.format = SND_PCM_FORMAT_MU_LAW;
break; break;
case AU_FMT_LIN8: case AU_FMT_LIN8:
if (hwparams.format != default_format && if (hwparams.format != DEFAULT_FORMAT &&
hwparams.format != SND_PCM_FORMAT_U8) hwparams.format != SND_PCM_FORMAT_U8)
fprintf(stderr, _("Warning: format is changed to U8\n")); fprintf(stderr, _("Warning: format is changed to U8\n"));
hwparams.format = SND_PCM_FORMAT_U8; hwparams.format = SND_PCM_FORMAT_U8;
break; break;
case AU_FMT_LIN16: case AU_FMT_LIN16:
if (hwparams.format != default_format && if (hwparams.format != DEFAULT_FORMAT &&
hwparams.format != SND_PCM_FORMAT_S16_BE) hwparams.format != SND_PCM_FORMAT_S16_BE)
fprintf(stderr, _("Warning: format is changed to S16_BE\n")); fprintf(stderr, _("Warning: format is changed to S16_BE\n"));
hwparams.format = SND_PCM_FORMAT_S16_BE; hwparams.format = SND_PCM_FORMAT_S16_BE;
@ -2390,7 +2365,7 @@ static void voc_play(int fd, int ofs, char *name)
prg_exit(EXIT_FAILURE); prg_exit(EXIT_FAILURE);
} }
} }
hwparams.format = default_format; hwparams.format = DEFAULT_FORMAT;
hwparams.channels = 1; hwparams.channels = 1;
hwparams.rate = DEFAULT_SPEED; hwparams.rate = DEFAULT_SPEED;
set_params(); set_params();