Skip to content

Commit

Permalink
out_alsa, out_oss: simplified pcmname
Browse files Browse the repository at this point in the history
  • Loading branch information
sezero committed Mar 31, 2024
1 parent 826eacd commit 4923dae
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
17 changes: 6 additions & 11 deletions src/player/out_alsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,16 @@ static snd_pcm_t *pcm = NULL;

static void close_alsa_output(void);

static int open_alsa_output(const char * output, unsigned int *rate) {
static int open_alsa_output(const char *pcmname, unsigned int *rate) {
snd_pcm_hw_params_t *hw;
snd_pcm_sw_params_t *sw;
int err;
unsigned int alsa_buffer_time;
unsigned int alsa_period_time;
unsigned int r;
char pcmname[1024];
const unsigned int r = *rate;
int err;

if (!output[0]) {
strcpy(pcmname, "default");
} else {
strcpy(pcmname, output);
if (!pcmname || !*pcmname) {
pcmname = "default";
}

if ((err = snd_pcm_open(&pcm, pcmname, SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
Expand All @@ -59,8 +56,7 @@ static int open_alsa_output(const char * output, unsigned int *rate) {
snd_pcm_hw_params_alloca(&hw);

if ((err = snd_pcm_hw_params_any(pcm, hw)) < 0) {
fprintf(stderr, "ERROR: No configuration available for playback: %s\r\n",
snd_strerror(err));
fprintf(stderr, "ERROR: No configuration available for playback: %s\r\n", snd_strerror(err));
goto fail;
}

Expand All @@ -79,7 +75,6 @@ static int open_alsa_output(const char * output, unsigned int *rate) {
goto fail;
}

r = *rate;
if (snd_pcm_hw_params_set_rate_near(pcm, hw, rate, 0) < 0) {
fprintf(stderr, "ALSA does not support %uHz for your soundcard\r\n", r);
goto fail;
Expand Down
13 changes: 4 additions & 9 deletions src/player/out_oss.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,13 @@ static void pause_oss_output(void) {
}
static void resume_oss_output(void) {}

static int open_oss_output(const char *output, unsigned int *rate) {
static int open_oss_output(const char *pcmname, unsigned int *rate) {
const unsigned int r = *rate;
int tmp;
unsigned int r;
char pcmname[1024];

if (!output[0]) {
strcpy(pcmname, "/dev/dsp");
} else {
strcpy(pcmname, output);
if (!pcmname || !*pcmname) {
pcmname = "/dev/dsp";
}

if ((audio_fd = open(pcmname, O_WRONLY)) < 0) {
fprintf(stderr, "ERROR: Unable to open %s (%s)\r\n", pcmname, strerror(errno));
return (-1);
Expand All @@ -89,7 +85,6 @@ static int open_oss_output(const char *output, unsigned int *rate) {
goto fail;
}

r = *rate;
if (ioctl(audio_fd, SNDCTL_DSP_SPEED, rate) < 0) {
fprintf(stderr, "ERROR: Unable to set %uHz sample rate\r\n", r);
goto fail;
Expand Down

0 comments on commit 4923dae

Please sign in to comment.