mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-01 22:58:47 -04:00
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
This commit is contained in:
parent
b8eb0c088d
commit
f2e08d53d0
3 changed files with 42 additions and 13 deletions
|
|
@ -25,6 +25,11 @@ struct userdata {
|
||||||
static const char* const valid_modargs[] = {
|
static const char* const valid_modargs[] = {
|
||||||
"device",
|
"device",
|
||||||
"sink_name",
|
"sink_name",
|
||||||
|
"format",
|
||||||
|
"channels",
|
||||||
|
"rate",
|
||||||
|
"fragments",
|
||||||
|
"fragment_size",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -124,15 +129,40 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
|
||||||
const char *dev;
|
const char *dev;
|
||||||
struct pollfd *pfds, *ppfd;
|
struct pollfd *pfds, *ppfd;
|
||||||
struct pa_sample_spec ss;
|
struct pa_sample_spec ss;
|
||||||
unsigned i, periods;
|
unsigned i, periods, fragsize;
|
||||||
snd_pcm_uframes_t buffer_size;
|
snd_pcm_uframes_t buffer_size;
|
||||||
void ** ios;
|
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))) {
|
if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
|
||||||
fprintf(stderr, __FILE__": failed to parse module arguments\n");
|
fprintf(stderr, __FILE__": failed to parse module arguments\n");
|
||||||
goto fail;
|
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));
|
u = malloc(sizeof(struct userdata));
|
||||||
assert(u);
|
assert(u);
|
||||||
memset(u, 0, sizeof(struct userdata));
|
memset(u, 0, sizeof(struct userdata));
|
||||||
|
|
@ -143,17 +173,10 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
|
||||||
goto fail;
|
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);
|
snd_pcm_hw_params_alloca(&hwparams);
|
||||||
if (snd_pcm_hw_params_any(u->pcm_handle, hwparams) < 0 ||
|
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_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_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_channels(u->pcm_handle, hwparams, ss.channels) < 0 ||
|
||||||
snd_pcm_hw_params_set_periods_near(u->pcm_handle, hwparams, &periods, NULL) < 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);
|
free(pfds);
|
||||||
|
|
||||||
u->frame_size = pa_sample_size(&ss);
|
u->frame_size = frame_size;
|
||||||
u->fragment_size = buffer_size*u->frame_size/periods;
|
u->fragment_size = buffer_size*u->frame_size/periods;
|
||||||
|
|
||||||
fprintf(stderr, __FILE__": using %u fragments of size %u bytes.\n", periods, u->fragment_size);
|
fprintf(stderr, __FILE__": using %u fragments of size %u bytes.\n", periods, u->fragment_size);
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,8 @@ size_t pa_sample_size(const struct pa_sample_spec *spec) {
|
||||||
case PA_SAMPLE_S16BE:
|
case PA_SAMPLE_S16BE:
|
||||||
b = 2;
|
b = 2;
|
||||||
break;
|
break;
|
||||||
case PA_SAMPLE_FLOAT32:
|
case PA_SAMPLE_FLOAT32LE:
|
||||||
|
case PA_SAMPLE_FLOAT32BE:
|
||||||
b = 4;
|
b = 4;
|
||||||
break;
|
break;
|
||||||
default:
|
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_ULAW] = "ULAW",
|
||||||
[PA_SAMPLE_S16LE] = "S16LE",
|
[PA_SAMPLE_S16LE] = "S16LE",
|
||||||
[PA_SAMPLE_S16BE] = "S16BE",
|
[PA_SAMPLE_S16BE] = "S16BE",
|
||||||
[PA_SAMPLE_FLOAT32] = "FLOAT32",
|
[PA_SAMPLE_FLOAT32LE] = "FLOAT32LE",
|
||||||
|
[PA_SAMPLE_FLOAT32BE] = "FLOAT32BE",
|
||||||
};
|
};
|
||||||
|
|
||||||
assert(pa_sample_spec_valid(spec));
|
assert(pa_sample_spec_valid(spec));
|
||||||
|
|
|
||||||
|
|
@ -10,15 +10,19 @@ enum pa_sample_format {
|
||||||
PA_SAMPLE_ULAW,
|
PA_SAMPLE_ULAW,
|
||||||
PA_SAMPLE_S16LE,
|
PA_SAMPLE_S16LE,
|
||||||
PA_SAMPLE_S16BE,
|
PA_SAMPLE_S16BE,
|
||||||
PA_SAMPLE_FLOAT32,
|
PA_SAMPLE_FLOAT32LE,
|
||||||
|
PA_SAMPLE_FLOAT32BE,
|
||||||
PA_SAMPLE_MAX
|
PA_SAMPLE_MAX
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef WORDS_BIGENDIAN
|
#ifdef WORDS_BIGENDIAN
|
||||||
#define PA_SAMPLE_S16NE PA_SAMPLE_S16BE
|
#define PA_SAMPLE_S16NE PA_SAMPLE_S16BE
|
||||||
|
#define PA_SAMPLE_FLOAT32NE PA_SAMPLE_FLOAT32BE
|
||||||
#else
|
#else
|
||||||
#define PA_SAMPLE_S16NE PA_SAMPLE_S16LE
|
#define PA_SAMPLE_S16NE PA_SAMPLE_S16LE
|
||||||
|
#define PA_SAMPLE_FLOAT32NE PA_SAMPLE_FLOAT32LE
|
||||||
#endif
|
#endif
|
||||||
|
#define PA_SAMPLE_FLOAT32 PA_SAMPLE_FLOAT32NE
|
||||||
|
|
||||||
struct pa_sample_spec {
|
struct pa_sample_spec {
|
||||||
enum pa_sample_format format;
|
enum pa_sample_format format;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue