diff options
author | Alfred E. Heggestad <alfred.heggestad@gmail.com> | 2017-11-09 17:10:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-09 17:10:07 +0100 |
commit | a9e09b2c0a99efddfcc16f5e413e2d73aa0e1732 (patch) | |
tree | e53a738b94461189540bfe1a2c7b643b41ac488f /modules/pulse/recorder.c | |
parent | 4d5d9a6e4e0811b52b427602261d5e0b9bc85f21 (diff) |
add support for specifying sample format (#317)
API: ausrc and auplay
- add config items for ausrc/auplay format:
ausrc_format s16|float
auplay_format s16|float
- audio.c: convert audio samples to/from signed 16-bit
Modules:
alsa
add test for sample format FLOAT
rst: add support for FLOAT sample format
audiounit: add support for FLOAT sample format
coreaudio: check for signed 16-bit audio format
oss: check for signed 16-bit sample format
winwave: check for S16LE
pulse: add support for FLOAT sample format
sndio: check for S16 format
gst1: check sample format
aufile: check sample format
aubridge: check sample format
gst: check sample format
opensles: check for S16 sample format
jack: check sample format
alsa: remove usage of local config
test: change samples to void pointer
test: change sample type to void pointer
Diffstat (limited to 'modules/pulse/recorder.c')
-rw-r--r-- | modules/pulse/recorder.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/modules/pulse/recorder.c b/modules/pulse/recorder.c index 64df6c4..8ef1b96 100644 --- a/modules/pulse/recorder.c +++ b/modules/pulse/recorder.c @@ -18,8 +18,9 @@ struct ausrc_st { pa_simple *s; pthread_t thread; bool run; - int16_t *sampv; + void *sampv; size_t sampc; + size_t sampsz; ausrc_read_h *rh; void *arg; }; @@ -46,7 +47,7 @@ static void ausrc_destructor(void *arg) static void *read_thread(void *arg) { struct ausrc_st *st = arg; - const size_t num_bytes = st->sampc * 2; + const size_t num_bytes = st->sampc * st->sampsz; int ret, pa_error = 0; while (st->run) { @@ -65,6 +66,17 @@ static void *read_thread(void *arg) } +static int aufmt_to_pulse_format(enum aufmt fmt) +{ + switch (fmt) { + + case AUFMT_S16LE: return PA_SAMPLE_S16NE; + case AUFMT_FLOAT: return PA_SAMPLE_FLOAT32NE; + default: return 0; + } +} + + int pulse_recorder_alloc(struct ausrc_st **stp, const struct ausrc *as, struct media_ctx **ctx, struct ausrc_prm *prm, const char *device, @@ -95,14 +107,15 @@ int pulse_recorder_alloc(struct ausrc_st **stp, const struct ausrc *as, st->arg = arg; st->sampc = prm->srate * prm->ch * prm->ptime / 1000; + st->sampsz = aufmt_sample_size(prm->fmt); - st->sampv = mem_alloc(2 * st->sampc, NULL); + st->sampv = mem_alloc(st->sampsz * st->sampc, NULL); if (!st->sampv) { err = ENOMEM; goto out; } - ss.format = PA_SAMPLE_S16NE; + ss.format = aufmt_to_pulse_format(prm->fmt); ss.channels = prm->ch; ss.rate = prm->srate; |