#include <assert.h>
#include <stdio.h>
+
+#ifdef HAVE_SYS_POLL_H
#include <sys/poll.h>
+#else
+#include "poll.h"
+#endif
#include <asoundlib.h>
PA_MODULE_VERSION(PACKAGE_VERSION)
PA_MODULE_USAGE("sink_name=<name for the sink> device=<ALSA device> format=<sample format> channels=<number of channels> rate=<sample rate> fragments=<number of fragments> fragment_size=<fragment size>")
+#define PA_TYPEID_ALSA PA_TYPEID_MAKE('A', 'L', 'S', 'A')
+
struct userdata {
snd_pcm_t *pcm_handle;
struct pa_sink *sink;
};
#define DEFAULT_SINK_NAME "alsa_output"
-#define DEFAULT_DEVICE "plughw:0,0"
+#define DEFAULT_DEVICE "default"
static void update_usage(struct userdata *u) {
pa_module_set_used(u->module,
struct userdata *u = NULL;
const char *dev;
struct pa_sample_spec ss;
- unsigned periods, fragsize;
- snd_pcm_uframes_t buffer_size;
+ uint32_t periods, fragsize;
+ snd_pcm_uframes_t period_size;
size_t frame_size;
if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
}
frame_size = pa_frame_size(&ss);
- periods = 12;
+ periods = 8;
fragsize = 1024;
if (pa_modargs_get_value_u32(ma, "fragments", &periods) < 0 || pa_modargs_get_value_u32(ma, "fragment_size", &fragsize) < 0) {
pa_log(__FILE__": failed to parse buffer metrics\n");
goto fail;
}
- buffer_size = fragsize/frame_size*periods;
+ period_size = fragsize;
u = pa_xmalloc0(sizeof(struct userdata));
m->userdata = u;
u->module = m;
+ snd_config_update_free_global();
if (snd_pcm_open(&u->pcm_handle, dev = pa_modargs_get_value(ma, "device", DEFAULT_DEVICE), SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK) < 0) {
pa_log(__FILE__": Error opening PCM device %s\n", dev);
goto fail;
}
- if (pa_alsa_set_hw_params(u->pcm_handle, &ss, &periods, &buffer_size) < 0) {
+ if (pa_alsa_set_hw_params(u->pcm_handle, &ss, &periods, &period_size) < 0) {
pa_log(__FILE__": Failed to set hardware parameters\n");
goto fail;
}
- u->sink = pa_sink_new(c, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME), 0, &ss);
+ u->sink = pa_sink_new(c, PA_TYPEID_ALSA, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME), 0, &ss);
assert(u->sink);
u->sink->get_latency = sink_get_latency_cb;
}
u->frame_size = frame_size;
- u->fragment_size = buffer_size*u->frame_size/periods;
+ u->fragment_size = period_size;
pa_log(__FILE__": using %u fragments of size %u bytes.\n", periods, u->fragment_size);