Skip to content

Instantly share code, notes, and snippets.

@jdarge
Created April 28, 2024 16:29
Show Gist options
  • Save jdarge/17656309b7a42a8a37b78f1623e1f6c2 to your computer and use it in GitHub Desktop.
Save jdarge/17656309b7a42a8a37b78f1623e1f6c2 to your computer and use it in GitHub Desktop.
/*
taken from:
MOC (music on console), alsa.c
*/
static snd_pcm_hw_params_t *alsa_open_device (const char *device)
{
int rc;
snd_pcm_hw_params_t *result;
assert (!handle);
rc = snd_pcm_open (&handle, device, SND_PCM_STREAM_PLAYBACK,
SND_PCM_NONBLOCK);
if (rc < 0) {
error_errno ("Can't open audio", rc);
goto err1;
}
rc = snd_pcm_hw_params_malloc (&result);
if (rc < 0) {
error_errno ("Can't allocate hardware parameters structure", rc);
goto err2;
}
rc = snd_pcm_hw_params_any (handle, result);
if (rc < 0) {
error_errno ("Can't initialize hardware parameters structure", rc);
goto err3;
}
if (0) {
err3:
snd_pcm_hw_params_free (result);
err2:
snd_pcm_close (handle);
err1:
result = NULL;
handle = NULL;
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment