aboutsummaryrefslogtreecommitdiff
path: root/pd/src/s_audio_alsa.c
diff options
context:
space:
mode:
Diffstat (limited to 'pd/src/s_audio_alsa.c')
-rw-r--r--pd/src/s_audio_alsa.c39
1 files changed, 24 insertions, 15 deletions
diff --git a/pd/src/s_audio_alsa.c b/pd/src/s_audio_alsa.c
index a5034c8d..cf731109 100644
--- a/pd/src/s_audio_alsa.c
+++ b/pd/src/s_audio_alsa.c
@@ -90,9 +90,17 @@ static int alsaio_canmmap(t_alsa_dev *dev)
return ((err1 < 0) && (err2 >= 0));
}
+static void check_setup_error(int err, int out, const char *why) {
+ char bf[256];
+ snprintf(bf, sizeof bf, "%s (%s)", why, out ? "output" : "input");
+ check_error(err, bf);
+}
+
static int alsaio_setup(t_alsa_dev *dev, int out, int *channels, int *rate,
int nfrags, int frag_size)
{
+#define CHECK_ERROR(why_) check_setup_error(err, out, why_)
+
int bufsizeforthis, err;
snd_pcm_hw_params_t* hw_params;
unsigned int tmp_uint;
@@ -110,14 +118,14 @@ static int alsaio_setup(t_alsa_dev *dev, int out, int *channels, int *rate,
/* get the default params */
err = snd_pcm_hw_params_any(dev->a_handle, hw_params);
- check_error(err, "snd_pcm_hw_params_any");
+ CHECK_ERROR("snd_pcm_hw_params_any");
/* try to set interleaved access */
err = snd_pcm_hw_params_set_access(dev->a_handle,
hw_params, SND_PCM_ACCESS_RW_INTERLEAVED);
if (err < 0)
return (-1);
- check_error(err, "snd_pcm_hw_params_set_access");
+ CHECK_ERROR("snd_pcm_hw_params_set_access");
#if 0 /* enable this to print out which formats are available */
{
int i;
@@ -141,7 +149,7 @@ static int alsaio_setup(t_alsa_dev *dev, int out, int *channels, int *rate,
"PD-ALSA: 32/24 bit format not available - using 16\n"); */
err = snd_pcm_hw_params_set_format(dev->a_handle, hw_params,
SND_PCM_FORMAT_S16);
- check_error(err, "snd_pcm_hw_params_set_format");
+ CHECK_ERROR("_pcm_hw_params_set_format");
dev->a_sampwidth = 2;
}
else dev->a_sampwidth = 3;
@@ -154,22 +162,22 @@ static int alsaio_setup(t_alsa_dev *dev, int out, int *channels, int *rate,
/* set the subformat */
err = snd_pcm_hw_params_set_subformat(dev->a_handle,
hw_params, SND_PCM_SUBFORMAT_STD);
- check_error(err, "snd_pcm_hw_params_set_subformat");
+ CHECK_ERROR("snd_pcm_hw_params_set_subformat");
/* set the number of channels */
tmp_uint = *channels;
err = snd_pcm_hw_params_set_channels_min(dev->a_handle,
hw_params, &tmp_uint);
- check_error(err, "snd_pcm_hw_params_set_channels");
+ CHECK_ERROR("snd_pcm_hw_params_set_channels");
if (tmp_uint != (unsigned)*channels)
post("ALSA: set %s channels to %d", (out?"output":"input"), tmp_uint);
*channels = tmp_uint;
dev->a_channels = *channels;
/* set the sampling rate */
- err = snd_pcm_hw_params_set_rate_min(dev->a_handle, hw_params,
+ err = snd_pcm_hw_params_set_rate_near(dev->a_handle, hw_params,
(unsigned int *)rate, 0);
- check_error(err, "snd_pcm_hw_params_set_rate_min (input)");
+ CHECK_ERROR("snd_pcm_hw_params_set_rate_min");
#if 0
err = snd_pcm_hw_params_get_rate(hw_params, &subunitdir);
post("input sample rate %d", err);
@@ -185,7 +193,7 @@ static int alsaio_setup(t_alsa_dev *dev, int out, int *channels, int *rate,
err = snd_pcm_hw_params_set_period_size_near(dev->a_handle,
hw_params, &tmp_snd_pcm_uframes, 0);
#endif
- check_error(err, "snd_pcm_hw_params_set_period_size_near (input)");
+ CHECK_ERROR("snd_pcm_hw_params_set_period_size_near");
/* set the buffer size */
#ifdef ALSAAPI9
@@ -196,10 +204,10 @@ static int alsaio_setup(t_alsa_dev *dev, int out, int *channels, int *rate,
err = snd_pcm_hw_params_set_buffer_size_near(dev->a_handle,
hw_params, &tmp_snd_pcm_uframes);
#endif
- check_error(err, "snd_pcm_hw_params_set_buffer_size_near (input)");
+ CHECK_ERROR("snd_pcm_hw_params_set_buffer_size_near");
err = snd_pcm_hw_params(dev->a_handle, hw_params);
- check_error(err, "snd_pcm_hw_params (input)");
+ CHECK_ERROR("snd_pcm_hw_params");
/* set up the buffer */
bufsizeforthis = DEFDACBLKSIZE * dev->a_sampwidth * *channels;
@@ -227,18 +235,19 @@ static int alsaio_setup(t_alsa_dev *dev, int out, int *channels, int *rate,
alsa_snd_bufsize = bufsizeforthis;
}
return (1);
+#undef CHECK_ERROR
}
/* return 0 on success */
int alsa_open_audio(int naudioindev, int *audioindev, int nchindev,
int *chindev, int naudiooutdev, int *audiooutdev, int nchoutdev,
- int *choutdev, int rate)
+ int *choutdev, int rate, int blocksize)
{
int err, inchans = 0, outchans = 0, subunitdir;
char devname[512];
snd_output_t* out;
- int frag_size = (sys_blocksize ? sys_blocksize : ALSA_DEFFRAGSIZE);
+ int frag_size = (blocksize ? blocksize : ALSA_DEFFRAGSIZE);
int nfrags, i, iodev, dev2;
int wantinchans, wantoutchans, device;
@@ -292,7 +301,7 @@ int alsa_open_audio(int naudioindev, int *audioindev, int nchindev,
if (alsa_usemmap)
{
post("using mmap audio interface");
- if (alsamm_open_audio(rate))
+ if (alsamm_open_audio(rate, blocksize))
goto blewit;
else return (0);
}
@@ -469,7 +478,7 @@ int alsa_send_dacs(void)
((char *)(alsa_snd_buf))[3*j+1] = ((s>>8) & 255);
((char *)(alsa_snd_buf))[3*j+2] = ((s>>16) & 255);
#else
- fprintf(stderr("big endian 24-bit not supported");
+ fprintf(stderr, "big endian 24-bit not supported");
#endif
}
for (; i < thisdevchans; i++, ch++)
@@ -581,7 +590,7 @@ int alsa_send_dacs(void)
* (1./ INT32_MAX);
}
#else
- fprintf(stderr("big endian 24-bit not supported");
+ fprintf(stderr, "big endian 24-bit not supported");
#endif
}
else