summaryrefslogtreecommitdiff
path: root/modules/audiounit
diff options
context:
space:
mode:
authorAlfred E. Heggestad <alfred.heggestad@gmail.com>2017-11-09 17:10:07 +0100
committerGitHub <noreply@github.com>2017-11-09 17:10:07 +0100
commita9e09b2c0a99efddfcc16f5e413e2d73aa0e1732 (patch)
treee53a738b94461189540bfe1a2c7b643b41ac488f /modules/audiounit
parent4d5d9a6e4e0811b52b427602261d5e0b9bc85f21 (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')
-rw-r--r--modules/audiounit/player.c29
-rw-r--r--modules/audiounit/recorder.c30
2 files changed, 45 insertions, 14 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)
diff --git a/modules/audiounit/recorder.c b/modules/audiounit/recorder.c
index cf6a1af..b66ba07 100644
--- a/modules/audiounit/recorder.c
+++ b/modules/audiounit/recorder.c
@@ -8,6 +8,7 @@
#include <TargetConditionals.h>
#include <pthread.h>
#include <re.h>
+#include <rem.h>
#include <baresip.h>
#include "audiounit.h"
@@ -20,6 +21,7 @@ struct ausrc_st {
int ch;
ausrc_read_h *rh;
void *arg;
+ uint32_t sampsz;
};
@@ -67,7 +69,7 @@ static OSStatus input_callback(void *inRefCon,
abl.mNumberBuffers = 1;
abl.mBuffers[0].mNumberChannels = st->ch;
abl.mBuffers[0].mData = NULL;
- abl.mBuffers[0].mDataByteSize = inNumberFrames * 2;
+ abl.mBuffers[0].mDataByteSize = inNumberFrames * st->sampsz;
ret = AudioUnitRender(st->au,
ioActionFlags,
@@ -80,7 +82,8 @@ static OSStatus input_callback(void *inRefCon,
return ret;
}
- rh(abl.mBuffers[0].mData, abl.mBuffers[0].mDataByteSize/2, arg);
+ rh(abl.mBuffers[0].mData,
+ abl.mBuffers[0].mDataByteSize/st->sampsz, arg);
return 0;
}
@@ -97,6 +100,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_recorder_alloc(struct ausrc_st **stp, const struct ausrc *as,
struct media_ctx **ctx,
struct ausrc_prm *prm, const char *device,
@@ -178,21 +192,23 @@ int audiounit_recorder_alloc(struct ausrc_st **stp, const struct ausrc *as,
goto out;
#endif
+ 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
+ fmt.mFormatFlags = aufmt_to_formatflags(prm->fmt)
| kLinearPCMFormatFlagIsPacked;
#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;
fmt.mReserved = 0;
ret = AudioUnitSetProperty(st->au, kAudioUnitProperty_StreamFormat,