From nobody Wed Nov 12 06:52:12 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1568576179; cv=none; d=zoho.com; s=zohoarc; b=hw1c4nUzduaW+ojAh06BwfqGIfyj/DF9ZYsYE7bxwNj6pJWqaiDntMCQo5cCJRd2iiG+3wJpXPP3NznCDsUEnZFFGTd5Zxgh8VR/ZzCP6RZH1zlEVl0/Fa8q/aCSt0kO6h85fj1c8g8bnG24J2B0yXgrmE3VGKZ2noFmu1+p64w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568576179; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=P1Yx/dZ4rieO/0gJLGQ3xdgMx3pyBcyEnZuiP7yaO78=; b=mPBU9pzX0APwD8r2iYPLHo7O//Cp4dvHilRGBY1oW9Hd9H5PG4R5cD9eGJTlXslwOyFxHCqX1pd1Xkk4cMO/UzRC+FhSf6NSPi1YxpPJtI3u1sGAZyTO3Qi2bZVtFFuU2CEmrKgKgRYCTPuBTKdTa0akaIbAzp2fLQ8gxCwIEc8= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568576179382914.1451739150236; Sun, 15 Sep 2019 12:36:19 -0700 (PDT) Received: from localhost ([::1]:56644 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i9aJl-0000i4-Ec for importer@patchew.org; Sun, 15 Sep 2019 15:36:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39940) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i9a7d-0005y6-4b for qemu-devel@nongnu.org; Sun, 15 Sep 2019 15:23:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i9a7b-0001xK-Ih for qemu-devel@nongnu.org; Sun, 15 Sep 2019 15:23:45 -0400 Received: from mail-ed1-x541.google.com ([2a00:1450:4864:20::541]:39683) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i9a7b-0001xC-CG for qemu-devel@nongnu.org; Sun, 15 Sep 2019 15:23:43 -0400 Received: by mail-ed1-x541.google.com with SMTP id g12so5559714eds.6 for ; Sun, 15 Sep 2019 12:23:43 -0700 (PDT) Received: from nullptr.home.dirty-ice.org (2a01-036c-0113-74ef-0000-0000-0000-0005.pool6.digikabel.hu. [2a01:36c:113:74ef::5]) by smtp.gmail.com with ESMTPSA id j20sm6480562edy.95.2019.09.15.12.23.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Sep 2019 12:23:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=P1Yx/dZ4rieO/0gJLGQ3xdgMx3pyBcyEnZuiP7yaO78=; b=SpDlm6aOx60ZNNYoMDHN0RdDvqSzLV1SkAYsoj8AiEFeBrzcH/Gl/bP7ujTQMX77lT fsP8CPUmI0XQKn41svTMOgqEocJxaQTbMty1w3D1nzt2x+pK9PsOawsl7ALaYbh3Xw0s mNkitxr4E2UZIOGeHhptbDFIJh9e6TAHduLwqOum7gzC/W3H4cJT9k/WrZYf05isQtI4 pv9ZC0BtYvb/a+yJ+8goIZX4q8fQoOKsb6Mu75e7vStdQhMsgI0BydPDXkmVOiD31nTY Uxu4rF0oQWT4I/uMmXbFW4MyMwqNFx6Jx2O9ggBnSGmJGtZyVSU15sGH2v+pVmyH0AtW BJkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=P1Yx/dZ4rieO/0gJLGQ3xdgMx3pyBcyEnZuiP7yaO78=; b=aKoE5z60ncTT6o+xW0+daT055iuOp5colFAYpkecnMXTc9WC9ikro88skRhasQhvsr gsnqP25Ep6DkrvkTsANn9pZxLr4u2F2TXfcc8zwCXez5+cGELkzMNQQ2dr07Ci+CL8p1 so+QOJeMn04LbTw0ShXNda9Qlf/1gfoTyaYhAJHQGw2M9OSkeQ0bjmLS88HGh7ANc5jG l+oVDYc91rsCN04WGgvdu53YjyJjxg1uH49ZIsQSkHaQrFFkx9gGl+ZUin5SpWzp0iW3 I2QZRJKgKWcPrmrGyzEFpxRhy5yj1X0DOTl/SfIvaJdNRtWMU7WTKT2z1qL/1OzZ8mpH uPDA== X-Gm-Message-State: APjAAAVrHwE8y6c7Z7DZUKlW9mvr8Z26LpEm1EibJmTXs8SZXL+5kIU2 gS5Jr50UWcacnYRi6YXcEV+bGIVV X-Google-Smtp-Source: APXvYqwMIaJRN2CztljPdRwO77ENwMB9297JKVM3XB41K13/StznmXHvqyoNuF2WG8jGLr+9a7tVCA== X-Received: by 2002:a17:906:81d9:: with SMTP id e25mr48463538ejx.37.1568575421769; Sun, 15 Sep 2019 12:23:41 -0700 (PDT) From: "=?UTF-8?q?K=C5=91v=C3=A1g=C3=B3=2C=20Zolt=C3=A1n?=" X-Google-Original-From: =?UTF-8?q?K=C5=91v=C3=A1g=C3=B3=2C=20Zolt=C3=A1n?= To: qemu-devel@nongnu.org Date: Sun, 15 Sep 2019 21:23:19 +0200 Message-Id: <60d68c051ed180c7315f7cdd6084b58b6fc9bb6d.1568574965.git.DirtY.iCE.hu@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::541 Subject: [Qemu-devel] [PATCH v3 03/24] coreaudio: port to the new audio backend api X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Signed-off-by: K=C5=91v=C3=A1g=C3=B3, Zolt=C3=A1n --- audio/coreaudio.c | 130 ++++++++++++++++++++++++---------------------- 1 file changed, 69 insertions(+), 61 deletions(-) diff --git a/audio/coreaudio.c b/audio/coreaudio.c index d1be58b40a..5cde42f982 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; =20 #if MAC_OS_X_VERSION_MAX_ALLOWED >=3D MAC_OS_X_VERSION_10_6 @@ -397,31 +394,29 @@ static int coreaudio_unlock (coreaudioVoiceOut *core,= const char *fn_name) return 0; } =20 -static size_t coreaudio_run_out(HWVoiceOut *hw, size_t live) -{ - size_t decr; - coreaudioVoiceOut *core =3D (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 =3D (coreaudioVoiceOut *) hw; \ + ret_type ret; \ + \ + if (coreaudio_lock(core, "coreaudio_" #name)) { \ + return 0; \ + } \ + \ + ret =3D 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 =3D MIN (core->decr, live); - core->decr -=3D decr; - - core->live =3D live - decr; - hw->rpos =3D core->rpos; - - coreaudio_unlock (core, "coreaudio_run_out"); - return decr; -} +COREAUDIO_WRAPPER_FUNC(get_buffer_out, void *, (HWVoiceOut *hw, size_t *si= ze), + (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 s= ize), + (hw, buf, size)) +#undef COREAUDIO_WRAPPER_FUNC =20 /* 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 =3D outOutputData->mBuffers[0].mData; + UInt32 frameCount, pending_frames; + void *out =3D outOutputData->mBuffers[0].mData; HWVoiceOut *hw =3D hwptr; coreaudioVoiceOut *core =3D (coreaudioVoiceOut *) hwptr; - int rpos, live; - struct st_sample *src; -#ifndef FLOAT_MIXENG -#ifdef RECIPROCAL - const float scale =3D 1.f / UINT_MAX; -#else - const float scale =3D UINT_MAX; -#endif -#endif + size_t len; =20 if (coreaudio_lock (core, "audioDeviceIOProc")) { inInputTime =3D 0; @@ -453,42 +440,51 @@ static OSStatus audioDeviceIOProc( } =20 frameCount =3D core->audioDevicePropertyBufferFrameSize; - live =3D core->live; + pending_frames =3D hw->pending_emul >> hw->info.shift; =20 /* if there are not enough samples, set signal and return */ - if (live < frameCount) { + if (pending_frames < frameCount) { inInputTime =3D 0; coreaudio_unlock (core, "audioDeviceIOProc(empty)"); return 0; } =20 - rpos =3D core->rpos; - src =3D hw->mix_buf + rpos; + len =3D frameCount << hw->info.shift; + while (len) { + size_t write_len; + ssize_t start =3D ((ssize_t) hw->pos_emul) - hw->pending_emul; + if (start < 0) { + start +=3D hw->size_emul; + } + assert(start >=3D 0 && start < hw->size_emul); =20 - /* fill buffer */ - for (frame =3D 0; frame < frameCount; frame++) { -#ifdef FLOAT_MIXENG - *out++ =3D src[frame].l; /* left channel */ - *out++ =3D src[frame].r; /* right channel */ -#else -#ifdef RECIPROCAL - *out++ =3D src[frame].l * scale; /* left channel */ - *out++ =3D src[frame].r * scale; /* right channel */ -#else - *out++ =3D src[frame].l / scale; /* left channel */ - *out++ =3D src[frame].r / scale; /* right channel */ -#endif -#endif - } + write_len =3D MIN(MIN(hw->pending_emul, len), + hw->size_emul - start); =20 - rpos =3D (rpos + frameCount) % hw->samples; - core->decr +=3D frameCount; - core->rpos =3D rpos; + memcpy(out, hw->buf_emul + start, write_len); + hw->pending_emul -=3D write_len; + len -=3D write_len; + out +=3D write_len; + } =20 coreaudio_unlock (core, "audioDeviceIOProc"); return 0; } =20 +static UInt32 coreaudio_get_flags(struct audio_pcm_info *info, + struct audsettings *as) +{ + UInt32 flags =3D info->sign ? kAudioFormatFlagIsSignedInteger : 0; + if (as->endianness) { /* 0 =3D little, 1 =3D big */ + flags |=3D kAudioFormatFlagIsBigEndian; + } + + if (flags =3D=3D 0) { /* must not be 0 */ + flags =3D 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 a= udsettings *as, =20 /* set Samplerate */ core->outputStreamBasicDescription.mSampleRate =3D (Float64) as->freq; + core->outputStreamBasicDescription.mFormatID =3D kAudioFormatLinearPCM; + core->outputStreamBasicDescription.mFormatFlags =3D + coreaudio_get_flags(&hw->info, as); + core->outputStreamBasicDescription.mBytesPerPacket =3D + core->outputStreamBasicDescription.mBytesPerFrame =3D + hw->info.nchannels * hw->info.bits / 8; + core->outputStreamBasicDescription.mFramesPerPacket =3D 1; + core->outputStreamBasicDescription.mChannelsPerFrame =3D hw->info.ncha= nnels; + core->outputStreamBasicDescription.mBitsPerChannel =3D hw->info.bits; + status =3D coreaudio_set_streamformat(core->outputDeviceID, &core->outputStreamBasicDescriptio= n); if (status !=3D kAudioHardwareNoError) { @@ -686,7 +692,9 @@ static void coreaudio_audio_fini (void *opaque) static struct audio_pcm_ops coreaudio_pcm_ops =3D { .init_out =3D coreaudio_init_out, .fini_out =3D coreaudio_fini_out, - .run_out =3D coreaudio_run_out, + .write =3D coreaudio_write, + .get_buffer_out =3D coreaudio_get_buffer_out, + .put_buffer_out =3D coreaudio_put_buffer_out_nowrite, .ctl_out =3D coreaudio_ctl_out }; =20 --=20 2.23.0