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/audiounit/player.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/audiounit/player.c')
-rw-r--r-- | modules/audiounit/player.c | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/modules/audiounit/player.c b/modules/audiounit/player.c index 372f139..230b1ad 100644 --- a/modules/audiounit/player.c +++ b/modules/audiounit/player.c @@ -7,6 +7,7 @@ #include <AudioToolbox/AudioToolbox.h> #include <pthread.h> #include <re.h> +#include <rem.h> #include <baresip.h> #include "audiounit.h" @@ -18,6 +19,7 @@ struct auplay_st { pthread_mutex_t mutex; auplay_write_h *wh; void *arg; + uint32_t sampsz; }; @@ -68,7 +70,7 @@ static OSStatus output_callback(void *inRefCon, AudioBuffer *ab = &ioData->mBuffers[i]; - wh(ab->mData, ab->mDataByteSize/2, arg); + wh(ab->mData, ab->mDataByteSize/st->sampsz, arg); } return 0; @@ -86,6 +88,17 @@ static void interrupt_handler(bool interrupted, void *arg) } +static uint32_t aufmt_to_formatflags(enum aufmt fmt) +{ + switch (fmt) { + + case AUFMT_S16LE: return kLinearPCMFormatFlagIsSignedInteger; + case AUFMT_FLOAT: return kLinearPCMFormatFlagIsFloat; + default: return 0; + } +} + + int audiounit_player_alloc(struct auplay_st **stp, const struct auplay *ap, struct auplay_prm *prm, const char *device, auplay_write_h *wh, void *arg) @@ -130,21 +143,23 @@ int audiounit_player_alloc(struct auplay_st **stp, const struct auplay *ap, goto out; } + st->sampsz = (uint32_t)aufmt_sample_size(prm->fmt); + fmt.mSampleRate = prm->srate; fmt.mFormatID = kAudioFormatLinearPCM; #if TARGET_OS_IPHONE - fmt.mFormatFlags = kAudioFormatFlagIsSignedInteger + fmt.mFormatFlags = aufmt_to_formatflags(prm->fmt) | kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked; #else - fmt.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger - | kLinearPCMFormatFlagIsPacked; + fmt.mFormatFlags = aufmt_to_formatflags(prm->fmt) + | kAudioFormatFlagIsPacked; #endif - fmt.mBitsPerChannel = 16; + fmt.mBitsPerChannel = 8 * st->sampsz; fmt.mChannelsPerFrame = prm->ch; - fmt.mBytesPerFrame = 2 * prm->ch; + fmt.mBytesPerFrame = st->sampsz * prm->ch; fmt.mFramesPerPacket = 1; - fmt.mBytesPerPacket = 2 * prm->ch; + fmt.mBytesPerPacket = st->sampsz * prm->ch; ret = AudioUnitInitialize(st->au); if (ret) |