summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2004-07-16 14:43:25 +0000
committerLennart Poettering <lennart@poettering.net>2004-07-16 14:43:25 +0000
commitf2e08d53d03303376da4491559a5af6296bbfea8 (patch)
tree51a56950f3c67cde0444b8bbd9db179f9c4cdaec
parentb8eb0c088df2c5a0495cf43f8991977693258d5b (diff)
split PA_SAMPLE_FLOAT32 into PA_SAMPLE_FLOAT{LE,BE}
add more configuration arguments to alsa sink git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@75 fefdeb5f-60dc-0310-8127-8f9354f1896f
-rw-r--r--src/module-alsa-sink.c43
-rw-r--r--src/sample.c6
-rw-r--r--src/sample.h6
3 files changed, 42 insertions, 13 deletions
diff --git a/src/module-alsa-sink.c b/src/module-alsa-sink.c
index 7afd24fd..16571a2c 100644
--- a/src/module-alsa-sink.c
+++ b/src/module-alsa-sink.c
@@ -25,6 +25,11 @@ struct userdata {
static const char* const valid_modargs[] = {
"device",
"sink_name",
+ "format",
+ "channels",
+ "rate",
+ "fragments",
+ "fragment_size",
NULL
};
@@ -124,14 +129,39 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
const char *dev;
struct pollfd *pfds, *ppfd;
struct pa_sample_spec ss;
- unsigned i, periods;
+ unsigned i, periods, fragsize;
snd_pcm_uframes_t buffer_size;
void ** ios;
+ size_t frame_size;
+ static const snd_pcm_format_t format_trans[] = {
+ [PA_SAMPLE_U8] = SND_PCM_FORMAT_U8,
+ [PA_SAMPLE_ALAW] = SND_PCM_FORMAT_A_LAW,
+ [PA_SAMPLE_ULAW] = SND_PCM_FORMAT_MU_LAW,
+ [PA_SAMPLE_S16LE] = SND_PCM_FORMAT_S16_LE,
+ [PA_SAMPLE_S16BE] = SND_PCM_FORMAT_S16_BE,
+ [PA_SAMPLE_FLOAT32LE] = SND_PCM_FORMAT_FLOAT_LE,
+ [PA_SAMPLE_FLOAT32BE] = SND_PCM_FORMAT_FLOAT_BE,
+ };
if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
fprintf(stderr, __FILE__": failed to parse module arguments\n");
goto fail;
}
+
+ ss = c->default_sample_spec;
+ if (pa_modargs_get_sample_spec(ma, &ss) < 0) {
+ fprintf(stderr, __FILE__": failed to parse sample specification\n");
+ goto fail;
+ }
+ frame_size = pa_sample_size(&ss);
+
+ periods = 12;
+ fragsize = 1024;
+ if (pa_modargs_get_value_u32(ma, "fragments", &periods) < 0 || pa_modargs_get_value_u32(ma, "fragment_size", &fragsize) < 0) {
+ fprintf(stderr, __FILE__": failed to parse buffer metrics\n");
+ goto fail;
+ }
+ buffer_size = fragsize/frame_size*periods;
u = malloc(sizeof(struct userdata));
assert(u);
@@ -142,18 +172,11 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
fprintf(stderr, "Error opening PCM device %s\n", dev);
goto fail;
}
-
- ss.format = PA_SAMPLE_S16LE;
- ss.rate = 44100;
- ss.channels = 2;
-
- periods = 12;
- buffer_size = periods*256;
snd_pcm_hw_params_alloca(&hwparams);
if (snd_pcm_hw_params_any(u->pcm_handle, hwparams) < 0 ||
snd_pcm_hw_params_set_access(u->pcm_handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED) < 0 ||
- snd_pcm_hw_params_set_format(u->pcm_handle, hwparams, SND_PCM_FORMAT_S16_LE) < 0 ||
+ snd_pcm_hw_params_set_format(u->pcm_handle, hwparams, format_trans[ss.format]) < 0 ||
snd_pcm_hw_params_set_rate_near(u->pcm_handle, hwparams, &ss.rate, NULL) < 0 ||
snd_pcm_hw_params_set_channels(u->pcm_handle, hwparams, ss.channels) < 0 ||
snd_pcm_hw_params_set_periods_near(u->pcm_handle, hwparams, &periods, NULL) < 0 ||
@@ -193,7 +216,7 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
free(pfds);
- u->frame_size = pa_sample_size(&ss);
+ u->frame_size = frame_size;
u->fragment_size = buffer_size*u->frame_size/periods;
fprintf(stderr, __FILE__": using %u fragments of size %u bytes.\n", periods, u->fragment_size);
diff --git a/src/sample.c b/src/sample.c
index 20142a23..2cdc9e72 100644
--- a/src/sample.c
+++ b/src/sample.c
@@ -17,7 +17,8 @@ size_t pa_sample_size(const struct pa_sample_spec *spec) {
case PA_SAMPLE_S16BE:
b = 2;
break;
- case PA_SAMPLE_FLOAT32:
+ case PA_SAMPLE_FLOAT32LE:
+ case PA_SAMPLE_FLOAT32BE:
b = 4;
break;
default:
@@ -64,7 +65,8 @@ void pa_sample_snprint(char *s, size_t l, const struct pa_sample_spec *spec) {
[PA_SAMPLE_ULAW] = "ULAW",
[PA_SAMPLE_S16LE] = "S16LE",
[PA_SAMPLE_S16BE] = "S16BE",
- [PA_SAMPLE_FLOAT32] = "FLOAT32",
+ [PA_SAMPLE_FLOAT32LE] = "FLOAT32LE",
+ [PA_SAMPLE_FLOAT32BE] = "FLOAT32BE",
};
assert(pa_sample_spec_valid(spec));
diff --git a/src/sample.h b/src/sample.h
index df12924b..a755b76d 100644
--- a/src/sample.h
+++ b/src/sample.h
@@ -10,15 +10,19 @@ enum pa_sample_format {
PA_SAMPLE_ULAW,
PA_SAMPLE_S16LE,
PA_SAMPLE_S16BE,
- PA_SAMPLE_FLOAT32,
+ PA_SAMPLE_FLOAT32LE,
+ PA_SAMPLE_FLOAT32BE,
PA_SAMPLE_MAX
};
#ifdef WORDS_BIGENDIAN
#define PA_SAMPLE_S16NE PA_SAMPLE_S16BE
+#define PA_SAMPLE_FLOAT32NE PA_SAMPLE_FLOAT32BE
#else
#define PA_SAMPLE_S16NE PA_SAMPLE_S16LE
+#define PA_SAMPLE_FLOAT32NE PA_SAMPLE_FLOAT32LE
#endif
+#define PA_SAMPLE_FLOAT32 PA_SAMPLE_FLOAT32NE
struct pa_sample_spec {
enum pa_sample_format format;