From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kővágó@redhat.com, Zoltán <DirtY.iCE.hu@gmail.com>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Markus Armbruster" <armbru@redhat.com>
Subject: [Qemu-devel] [PULL 03/26] coreaudio: port to the new audio backend api
Date: Thu, 19 Sep 2019 10:36:06 +0200 [thread overview]
Message-ID: <20190919083629.29998-4-kraxel@redhat.com> (raw)
In-Reply-To: <20190919083629.29998-1-kraxel@redhat.com>
From: Kővágó, Zoltán <dirty.ice.hu@gmail.com>
Signed-off-by: Kővágó, Zoltán <DirtY.iCE.hu@gmail.com>
Message-id: 60d68c051ed180c7315f7cdd6084b58b6fc9bb6d.1568574965.git.DirtY.iCE.hu@gmail.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
audio/coreaudio.c | 130 ++++++++++++++++++++++++----------------------
1 file changed, 69 insertions(+), 61 deletions(-)
diff --git a/audio/coreaudio.c b/audio/coreaudio.c
index d1be58b40aa8..5cde42f9826c 100644
--- a/audio/coreaudio.c
+++ b/audio/coreaudio.c
@@ -43,9 +43,6 @@ typedef struct coreaudioVoiceOut {
UInt32 audioDevicePropertyBufferFrameSize;
AudioStreamBasicDescription outputStreamBasicDescription;
AudioDeviceIOProcID ioprocid;
- size_t live;
- size_t decr;
- size_t rpos;
} coreaudioVoiceOut;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
@@ -397,31 +394,29 @@ static int coreaudio_unlock (coreaudioVoiceOut *core, const char *fn_name)
return 0;
}
-static size_t coreaudio_run_out(HWVoiceOut *hw, size_t live)
-{
- size_t decr;
- coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw;
-
- if (coreaudio_lock (core, "coreaudio_run_out")) {
- return 0;
+#define COREAUDIO_WRAPPER_FUNC(name, ret_type, args_decl, args) \
+ static ret_type glue(coreaudio_, name)args_decl \
+ { \
+ coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw; \
+ ret_type ret; \
+ \
+ if (coreaudio_lock(core, "coreaudio_" #name)) { \
+ return 0; \
+ } \
+ \
+ ret = glue(audio_generic_, name)args; \
+ \
+ coreaudio_unlock(core, "coreaudio_" #name); \
+ return ret; \
}
-
- if (core->decr > live) {
- ldebug ("core->decr %d live %d core->live %d\n",
- core->decr,
- live,
- core->live);
- }
-
- decr = MIN (core->decr, live);
- core->decr -= decr;
-
- core->live = live - decr;
- hw->rpos = core->rpos;
-
- coreaudio_unlock (core, "coreaudio_run_out");
- return decr;
-}
+COREAUDIO_WRAPPER_FUNC(get_buffer_out, void *, (HWVoiceOut *hw, size_t *size),
+ (hw, size))
+COREAUDIO_WRAPPER_FUNC(put_buffer_out_nowrite, size_t,
+ (HWVoiceOut *hw, void *buf, size_t size),
+ (hw, buf, size))
+COREAUDIO_WRAPPER_FUNC(write, size_t, (HWVoiceOut *hw, void *buf, size_t size),
+ (hw, buf, size))
+#undef COREAUDIO_WRAPPER_FUNC
/* callback to feed audiooutput buffer */
static OSStatus audioDeviceIOProc(
@@ -433,19 +428,11 @@ static OSStatus audioDeviceIOProc(
const AudioTimeStamp* inOutputTime,
void* hwptr)
{
- UInt32 frame, frameCount;
- float *out = outOutputData->mBuffers[0].mData;
+ UInt32 frameCount, pending_frames;
+ void *out = outOutputData->mBuffers[0].mData;
HWVoiceOut *hw = hwptr;
coreaudioVoiceOut *core = (coreaudioVoiceOut *) hwptr;
- int rpos, live;
- struct st_sample *src;
-#ifndef FLOAT_MIXENG
-#ifdef RECIPROCAL
- const float scale = 1.f / UINT_MAX;
-#else
- const float scale = UINT_MAX;
-#endif
-#endif
+ size_t len;
if (coreaudio_lock (core, "audioDeviceIOProc")) {
inInputTime = 0;
@@ -453,42 +440,51 @@ static OSStatus audioDeviceIOProc(
}
frameCount = core->audioDevicePropertyBufferFrameSize;
- live = core->live;
+ pending_frames = hw->pending_emul >> hw->info.shift;
/* if there are not enough samples, set signal and return */
- if (live < frameCount) {
+ if (pending_frames < frameCount) {
inInputTime = 0;
coreaudio_unlock (core, "audioDeviceIOProc(empty)");
return 0;
}
- rpos = core->rpos;
- src = hw->mix_buf + rpos;
+ len = frameCount << hw->info.shift;
+ while (len) {
+ size_t write_len;
+ ssize_t start = ((ssize_t) hw->pos_emul) - hw->pending_emul;
+ if (start < 0) {
+ start += hw->size_emul;
+ }
+ assert(start >= 0 && start < hw->size_emul);
- /* fill buffer */
- for (frame = 0; frame < frameCount; frame++) {
-#ifdef FLOAT_MIXENG
- *out++ = src[frame].l; /* left channel */
- *out++ = src[frame].r; /* right channel */
-#else
-#ifdef RECIPROCAL
- *out++ = src[frame].l * scale; /* left channel */
- *out++ = src[frame].r * scale; /* right channel */
-#else
- *out++ = src[frame].l / scale; /* left channel */
- *out++ = src[frame].r / scale; /* right channel */
-#endif
-#endif
+ write_len = MIN(MIN(hw->pending_emul, len),
+ hw->size_emul - start);
+
+ memcpy(out, hw->buf_emul + start, write_len);
+ hw->pending_emul -= write_len;
+ len -= write_len;
+ out += write_len;
}
- rpos = (rpos + frameCount) % hw->samples;
- core->decr += frameCount;
- core->rpos = rpos;
-
coreaudio_unlock (core, "audioDeviceIOProc");
return 0;
}
+static UInt32 coreaudio_get_flags(struct audio_pcm_info *info,
+ struct audsettings *as)
+{
+ UInt32 flags = info->sign ? kAudioFormatFlagIsSignedInteger : 0;
+ if (as->endianness) { /* 0 = little, 1 = big */
+ flags |= kAudioFormatFlagIsBigEndian;
+ }
+
+ if (flags == 0) { /* must not be 0 */
+ flags = kAudioFormatFlagsAreAllClear;
+ }
+ return flags;
+}
+
static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as,
void *drv_opaque)
{
@@ -576,6 +572,16 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as,
/* set Samplerate */
core->outputStreamBasicDescription.mSampleRate = (Float64) as->freq;
+ core->outputStreamBasicDescription.mFormatID = kAudioFormatLinearPCM;
+ core->outputStreamBasicDescription.mFormatFlags =
+ coreaudio_get_flags(&hw->info, as);
+ core->outputStreamBasicDescription.mBytesPerPacket =
+ core->outputStreamBasicDescription.mBytesPerFrame =
+ hw->info.nchannels * hw->info.bits / 8;
+ core->outputStreamBasicDescription.mFramesPerPacket = 1;
+ core->outputStreamBasicDescription.mChannelsPerFrame = hw->info.nchannels;
+ core->outputStreamBasicDescription.mBitsPerChannel = hw->info.bits;
+
status = coreaudio_set_streamformat(core->outputDeviceID,
&core->outputStreamBasicDescription);
if (status != kAudioHardwareNoError) {
@@ -686,7 +692,9 @@ static void coreaudio_audio_fini (void *opaque)
static struct audio_pcm_ops coreaudio_pcm_ops = {
.init_out = coreaudio_init_out,
.fini_out = coreaudio_fini_out,
- .run_out = coreaudio_run_out,
+ .write = coreaudio_write,
+ .get_buffer_out = coreaudio_get_buffer_out,
+ .put_buffer_out = coreaudio_put_buffer_out_nowrite,
.ctl_out = coreaudio_ctl_out
};
--
2.18.1
next prev parent reply other threads:[~2019-09-19 8:38 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-19 8:36 [Qemu-devel] [PULL 00/26] Audio 20190919 patches Gerd Hoffmann
2019-09-19 8:36 ` [Qemu-devel] [PULL 01/26] audio: api for mixeng code free backends Gerd Hoffmann
2019-09-19 8:36 ` [Qemu-devel] [PULL 02/26] alsaaudio: port to the new audio backend api Gerd Hoffmann
2019-09-19 8:36 ` Gerd Hoffmann [this message]
2019-09-19 8:36 ` [Qemu-devel] [PULL 04/26] dsoundaudio: " Gerd Hoffmann
2019-09-19 8:36 ` [Qemu-devel] [PULL 05/26] noaudio: " Gerd Hoffmann
2019-09-19 8:36 ` [Qemu-devel] [PULL 06/26] ossaudio: " Gerd Hoffmann
2019-09-19 8:36 ` [Qemu-devel] [PULL 07/26] paaudio: " Gerd Hoffmann
2019-09-19 8:36 ` [Qemu-devel] [PULL 08/26] sdlaudio: " Gerd Hoffmann
2019-09-19 8:36 ` [Qemu-devel] [PULL 09/26] spiceaudio: " Gerd Hoffmann
2019-09-19 8:36 ` [Qemu-devel] [PULL 10/26] wavaudio: " Gerd Hoffmann
2019-09-19 8:36 ` [Qemu-devel] [PULL 11/26] audio: remove remains of the old " Gerd Hoffmann
2019-09-19 8:36 ` [Qemu-devel] [PULL 12/26] audio: unify input and output mixeng buffer management Gerd Hoffmann
2019-09-19 8:36 ` [Qemu-devel] [PULL 13/26] audio: common rate control code for timer based outputs Gerd Hoffmann
2019-09-19 8:36 ` [Qemu-devel] [PULL 14/26] audio: split ctl_* functions into enable_* and volume_* Gerd Hoffmann
2019-09-19 8:36 ` [Qemu-devel] [PULL 15/26] audio: add mixeng option (documentation) Gerd Hoffmann
2019-09-19 15:27 ` Eric Blake
2019-09-19 8:36 ` [Qemu-devel] [PULL 16/26] audio: make mixeng optional Gerd Hoffmann
2019-09-19 8:36 ` [Qemu-devel] [PULL 17/26] paaudio: get/put_buffer functions Gerd Hoffmann
2019-09-19 8:36 ` [Qemu-devel] [PULL 18/26] audio: support more than two channels in volume setting Gerd Hoffmann
2019-09-19 8:36 ` [Qemu-devel] [PULL 19/26] audio: replace shift in audio_pcm_info with bytes_per_frame Gerd Hoffmann
2019-09-19 8:36 ` [Qemu-devel] [PULL 20/26] audio: basic support for multichannel audio Gerd Hoffmann
2019-09-19 8:36 ` [Qemu-devel] [PULL 21/26] paaudio: channel-map option Gerd Hoffmann
2019-09-19 8:36 ` [Qemu-devel] [PULL 22/26] usb-audio: do not count on avail bytes actually available Gerd Hoffmann
2019-09-19 8:36 ` [Qemu-devel] [PULL 23/26] usb-audio: support more than two channels of audio Gerd Hoffmann
2019-09-19 8:36 ` [Qemu-devel] [PULL 24/26] usbaudio: change playback counters to 64 bit Gerd Hoffmann
2019-09-19 8:36 ` [Qemu-devel] [PULL 25/26] audio: fix buffer-length typo in documentation Gerd Hoffmann
2019-09-19 8:36 ` [Qemu-devel] [PULL 26/26] audio: fix ALSA period-length " Gerd Hoffmann
2019-09-19 15:15 ` [Qemu-devel] [PULL 00/26] Audio 20190919 patches Peter Maydell
2019-09-19 15:28 ` Eric Blake
2019-09-19 21:26 ` Zoltán Kővágó
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190919083629.29998-4-kraxel@redhat.com \
--to=kraxel@redhat.com \
--cc=DirtY.iCE.hu@gmail.com \
--cc=Kővágó@redhat.com \
--cc=armbru@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).