All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/1] coreaudio: fix coreaudio playback
@ 2020-02-02 14:03 Volker Rümelin
  2020-02-02 14:06 ` [PATCH] " Volker Rümelin
  2020-02-02 18:16 ` [PATCH 0/1] " Howard Spoelstra
  0 siblings, 2 replies; 5+ messages in thread
From: Volker Rümelin @ 2020-02-02 14:03 UTC (permalink / raw)
  To: Gerd Hoffmann, Zoltán Kővágó,
	Howard Spoelstra, Programmingkid, Mark Cave-Ayland
  Cc: qemu Developers

Hi,

here is a new patch for the CoreAudio playback problem. This patch
is Zoltán's patch from
https://lists.nongnu.org/archive/html/qemu-devel/2020-01/msg02142.html
and a improved version of my patch squashed together.

I actually tested the changes in audio/audio_template.h,
audio/mixeng.c and audio/mixeng.h with all useful permutations of
FLOAT_MIXENG and RECIPROCAL defined/undefined.

@Howard and John
Can you please test this patch? Compared to the patches you tested
this patch is quite different.

@John
'git am exported_mail.eml' knows how to handle
Content-Transfer-Encoding: in a mail file. It's not necessary to
apply this patch by hand.

Volker Rümelin (1):
  coreaudio: fix coreaudio playback

 audio/audio_template.h |  7 +++++++
 audio/coreaudio.c      | 32 +++++++++-----------------------
 audio/mixeng.c         | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 audio/mixeng.h         |  5 +++++
 4 files changed, 69 insertions(+), 23 deletions(-)

-- 
2.16.4



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] coreaudio: fix coreaudio playback
  2020-02-02 14:03 [PATCH 0/1] coreaudio: fix coreaudio playback Volker Rümelin
@ 2020-02-02 14:06 ` Volker Rümelin
  2020-02-02 19:41   ` Zoltán Kővágó
  2020-02-06 13:38   ` Gerd Hoffmann
  2020-02-02 18:16 ` [PATCH 0/1] " Howard Spoelstra
  1 sibling, 2 replies; 5+ messages in thread
From: Volker Rümelin @ 2020-02-02 14:06 UTC (permalink / raw)
  To: Gerd Hoffmann, Zoltán Kővágó,
	Howard Spoelstra, Programmingkid, Mark Cave-Ayland
  Cc: qemu Developers

There are reports that since commit 2ceb8240fa "coreaudio: port
to the new audio backend api" audio playback with CoreAudio is
broken. This patch reverts some parts the commit.

Because of changes in the audio subsystem the audio clip
function in v4.1.0 of coreaudio.c had to be moved to mixeng.c
and the generic buffer management code needed a hint about the
size of the float type.

This patch is based on a patch from Zoltán Kővágó found at
https://lists.nongnu.org/archive/html/qemu-devel/2020-01/msg02142.html.

Fixes: 2ceb8240fa "coreaudio: port to the new audio backend api"

Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
---
 audio/audio_template.h |  7 +++++++
 audio/coreaudio.c      | 32 +++++++++-----------------------
 audio/mixeng.c         | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 audio/mixeng.h         |  5 +++++
 4 files changed, 69 insertions(+), 23 deletions(-)

diff --git a/audio/audio_template.h b/audio/audio_template.h
index 3287d7075e..0336d2670c 100644
--- a/audio/audio_template.h
+++ b/audio/audio_template.h
@@ -276,6 +276,13 @@ static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioState *s,
         goto err1;
     }
 
+    if (s->dev->driver == AUDIODEV_DRIVER_COREAUDIO) {
+#ifdef DAC
+        hw->clip = clip_natural_float_from_stereo;
+#else
+        hw->conv = conv_natural_float_to_stereo;
+#endif
+    } else
 #ifdef DAC
     hw->clip = mixeng_clip
 #else
diff --git a/audio/coreaudio.c b/audio/coreaudio.c
index 66f0f459cf..0049db97fa 100644
--- a/audio/coreaudio.c
+++ b/audio/coreaudio.c
@@ -471,20 +471,6 @@ static OSStatus 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)
 {
@@ -496,6 +482,7 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as,
     Audiodev *dev = drv_opaque;
     AudiodevCoreaudioPerDirectionOptions *cpdo = dev->u.coreaudio.out;
     int frames;
+    struct audsettings fake_as;
 
     /* create mutex */
     err = pthread_mutex_init(&core->mutex, NULL);
@@ -504,6 +491,14 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as,
         return -1;
     }
 
+    /*
+     * The canonical audio format for CoreAudio on macOS is float. Currently
+     * there is no generic code for AUDIO_FORMAT_F32 in qemu. Here we select
+     * AUDIO_FORMAT_S32 instead because only the sample size has to match.
+     */
+    fake_as = *as;
+    as = &fake_as;
+    as->fmt = AUDIO_FORMAT_S32;
     audio_pcm_init_info (&hw->info, as);
 
     status = coreaudio_get_voice(&core->outputDeviceID);
@@ -572,15 +567,6 @@ 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);
diff --git a/audio/mixeng.c b/audio/mixeng.c
index 2f5ba71381..16b646d48c 100644
--- a/audio/mixeng.c
+++ b/audio/mixeng.c
@@ -267,6 +267,54 @@ f_sample *mixeng_clip[2][2][2][3] = {
     }
 };
 
+void conv_natural_float_to_stereo(struct st_sample *dst, const void *src,
+                                  int samples)
+{
+    float *in = (float *)src;
+#ifndef FLOAT_MIXENG
+    const float scale = UINT_MAX;
+#endif
+
+    while (samples--) {
+#ifdef FLOAT_MIXENG
+        dst->l = *in++;
+        dst->r = *in++;
+#else
+        dst->l = *in++ * scale;
+        dst->r = *in++ * scale;
+#endif
+        dst++;
+    }
+}
+
+void clip_natural_float_from_stereo(void *dst, const struct st_sample *src,
+                                    int samples)
+{
+    float *out = (float *)dst;
+#ifndef FLOAT_MIXENG
+#ifdef RECIPROCAL
+    const float scale = 1.f / UINT_MAX;
+#else
+    const float scale = UINT_MAX;
+#endif
+#endif
+
+    while (samples--) {
+#ifdef FLOAT_MIXENG
+        *out++ = src->l;
+        *out++ = src->r;
+#else
+#ifdef RECIPROCAL
+        *out++ = src->l * scale;
+        *out++ = src->r * scale;
+#else
+        *out++ = src->l / scale;
+        *out++ = src->r / scale;
+#endif
+#endif
+        src++;
+    }
+}
 
 void audio_sample_to_uint64(void *samples, int pos,
                             uint64_t *left, uint64_t *right)
diff --git a/audio/mixeng.h b/audio/mixeng.h
index 18e62c7c49..7ef61763e8 100644
--- a/audio/mixeng.h
+++ b/audio/mixeng.h
@@ -41,6 +41,11 @@ typedef void (f_sample) (void *dst, const struct st_sample *src, int samples);
 extern t_sample *mixeng_conv[2][2][2][3];
 extern f_sample *mixeng_clip[2][2][2][3];
 
+void conv_natural_float_to_stereo(struct st_sample *dst, const void *src,
+                                  int samples);
+void clip_natural_float_from_stereo(void *dst, const struct st_sample *src,
+                                    int samples);
+
 void *st_rate_start (int inrate, int outrate);
 void st_rate_flow(void *opaque, st_sample *ibuf, st_sample *obuf,
                   size_t *isamp, size_t *osamp);
-- 
2.16.4



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/1] coreaudio: fix coreaudio playback
  2020-02-02 14:03 [PATCH 0/1] coreaudio: fix coreaudio playback Volker Rümelin
  2020-02-02 14:06 ` [PATCH] " Volker Rümelin
@ 2020-02-02 18:16 ` Howard Spoelstra
  1 sibling, 0 replies; 5+ messages in thread
From: Howard Spoelstra @ 2020-02-02 18:16 UTC (permalink / raw)
  To: Volker Rümelin
  Cc: qemu Developers, Programmingkid, Mark Cave-Ayland, Gerd Hoffmann,
	Zoltán Kővágó

[-- Attachment #1: Type: text/plain, Size: 1399 bytes --]

On Sun, Feb 2, 2020 at 3:03 PM Volker Rümelin <vr_qemu@t-online.de> wrote:

> Hi,
>
> here is a new patch for the CoreAudio playback problem. This patch
> is Zoltán's patch from
> https://lists.nongnu.org/archive/html/qemu-devel/2020-01/msg02142.html
> and a improved version of my patch squashed together.
>
> I actually tested the changes in audio/audio_template.h,
> audio/mixeng.c and audio/mixeng.h with all useful permutations of
> FLOAT_MIXENG and RECIPROCAL defined/undefined.
>
> @Howard and John
> Can you please test this patch? Compared to the patches you tested
> this patch is quite different.
>
> @John
> 'git am exported_mail.eml' knows how to handle
> Content-Transfer-Encoding: in a mail file. It's not necessary to
> apply this patch by hand.
>
> Volker Rümelin (1):
>   coreaudio: fix coreaudio playback
>
>  audio/audio_template.h |  7 +++++++
>  audio/coreaudio.c      | 32 +++++++++-----------------------
>  audio/mixeng.c         | 48
> ++++++++++++++++++++++++++++++++++++++++++++++++
>  audio/mixeng.h         |  5 +++++
>  4 files changed, 69 insertions(+), 23 deletions(-)
>
> --
> 2.16.4
>
> Hi,

This patch restores coreaudio for me.
I applied the patch on top of https://github.com/mcayland/qemu/tree/screamer
to test audio support in qemu-system-ppc running Mac OS 9.2 and OSX 10.5.
Host is OSX Sierra.

Thanks,
Howard

[-- Attachment #2: Type: text/html, Size: 2076 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] coreaudio: fix coreaudio playback
  2020-02-02 14:06 ` [PATCH] " Volker Rümelin
@ 2020-02-02 19:41   ` Zoltán Kővágó
  2020-02-06 13:38   ` Gerd Hoffmann
  1 sibling, 0 replies; 5+ messages in thread
From: Zoltán Kővágó @ 2020-02-02 19:41 UTC (permalink / raw)
  To: Volker Rümelin, Gerd Hoffmann, Howard Spoelstra,
	Programmingkid, Mark Cave-Ayland
  Cc: qemu Developers

On 2020-02-02 15:06, Volker Rümelin wrote:
> There are reports that since commit 2ceb8240fa "coreaudio: port
> to the new audio backend api" audio playback with CoreAudio is
> broken. This patch reverts some parts the commit.
> 
> Because of changes in the audio subsystem the audio clip
> function in v4.1.0 of coreaudio.c had to be moved to mixeng.c
> and the generic buffer management code needed a hint about the
> size of the float type.
> 
> This patch is based on a patch from Zoltán Kővágó found at
> https://lists.nongnu.org/archive/html/qemu-devel/2020-01/msg02142.html.
> 
> Fixes: 2ceb8240fa "coreaudio: port to the new audio backend api"
> 
> Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
> ---
>   audio/audio_template.h |  7 +++++++
>   audio/coreaudio.c      | 32 +++++++++-----------------------
>   audio/mixeng.c         | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
>   audio/mixeng.h         |  5 +++++
>   4 files changed, 69 insertions(+), 23 deletions(-)

Hi,

I started reviewing this patch, but then I realized that I don't really 
like that "if (s->dev->driver == AUDIODEV_DRIVER_COREAUDIO)" hack, so I 
went ahead and added (hopefully proper) float samples support to mixeng. 
  I've submitted that patch to the mailing list.  Unless it causes 
problems I think it would be the best to merge it into this patch.

Regards,
Zoltan

> 
> diff --git a/audio/audio_template.h b/audio/audio_template.h
> index 3287d7075e..0336d2670c 100644
> --- a/audio/audio_template.h
> +++ b/audio/audio_template.h
> @@ -276,6 +276,13 @@ static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioState *s,
>           goto err1;
>       }
>   
> +    if (s->dev->driver == AUDIODEV_DRIVER_COREAUDIO) {
> +#ifdef DAC
> +        hw->clip = clip_natural_float_from_stereo;
> +#else
> +        hw->conv = conv_natural_float_to_stereo;
> +#endif
> +    } else
>   #ifdef DAC
>       hw->clip = mixeng_clip
>   #else
> diff --git a/audio/coreaudio.c b/audio/coreaudio.c
> index 66f0f459cf..0049db97fa 100644
> --- a/audio/coreaudio.c
> +++ b/audio/coreaudio.c
> @@ -471,20 +471,6 @@ static OSStatus 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)
>   {
> @@ -496,6 +482,7 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as,
>       Audiodev *dev = drv_opaque;
>       AudiodevCoreaudioPerDirectionOptions *cpdo = dev->u.coreaudio.out;
>       int frames;
> +    struct audsettings fake_as;
>   
>       /* create mutex */
>       err = pthread_mutex_init(&core->mutex, NULL);
> @@ -504,6 +491,14 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as,
>           return -1;
>       }
>   
> +    /*
> +     * The canonical audio format for CoreAudio on macOS is float. Currently
> +     * there is no generic code for AUDIO_FORMAT_F32 in qemu. Here we select
> +     * AUDIO_FORMAT_S32 instead because only the sample size has to match.
> +     */
> +    fake_as = *as;
> +    as = &fake_as;
> +    as->fmt = AUDIO_FORMAT_S32;
>       audio_pcm_init_info (&hw->info, as);
>   
>       status = coreaudio_get_voice(&core->outputDeviceID);
> @@ -572,15 +567,6 @@ 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);
> diff --git a/audio/mixeng.c b/audio/mixeng.c
> index 2f5ba71381..16b646d48c 100644
> --- a/audio/mixeng.c
> +++ b/audio/mixeng.c
> @@ -267,6 +267,54 @@ f_sample *mixeng_clip[2][2][2][3] = {
>       }
>   };
>   
> +void conv_natural_float_to_stereo(struct st_sample *dst, const void *src,
> +                                  int samples)
> +{
> +    float *in = (float *)src;
> +#ifndef FLOAT_MIXENG
> +    const float scale = UINT_MAX;
> +#endif
> +
> +    while (samples--) {
> +#ifdef FLOAT_MIXENG
> +        dst->l = *in++;
> +        dst->r = *in++;
> +#else
> +        dst->l = *in++ * scale;
> +        dst->r = *in++ * scale;
> +#endif
> +        dst++;
> +    }
> +}
> +
> +void clip_natural_float_from_stereo(void *dst, const struct st_sample *src,
> +                                    int samples)
> +{
> +    float *out = (float *)dst;
> +#ifndef FLOAT_MIXENG
> +#ifdef RECIPROCAL
> +    const float scale = 1.f / UINT_MAX;
> +#else
> +    const float scale = UINT_MAX;
> +#endif
> +#endif
> +
> +    while (samples--) {
> +#ifdef FLOAT_MIXENG
> +        *out++ = src->l;
> +        *out++ = src->r;
> +#else
> +#ifdef RECIPROCAL
> +        *out++ = src->l * scale;
> +        *out++ = src->r * scale;
> +#else
> +        *out++ = src->l / scale;
> +        *out++ = src->r / scale;
> +#endif
> +#endif
> +        src++;
> +    }
> +}
>   
>   void audio_sample_to_uint64(void *samples, int pos,
>                               uint64_t *left, uint64_t *right)
> diff --git a/audio/mixeng.h b/audio/mixeng.h
> index 18e62c7c49..7ef61763e8 100644
> --- a/audio/mixeng.h
> +++ b/audio/mixeng.h
> @@ -41,6 +41,11 @@ typedef void (f_sample) (void *dst, const struct st_sample *src, int samples);
>   extern t_sample *mixeng_conv[2][2][2][3];
>   extern f_sample *mixeng_clip[2][2][2][3];
>   
> +void conv_natural_float_to_stereo(struct st_sample *dst, const void *src,
> +                                  int samples);
> +void clip_natural_float_from_stereo(void *dst, const struct st_sample *src,
> +                                    int samples);
> +
>   void *st_rate_start (int inrate, int outrate);
>   void st_rate_flow(void *opaque, st_sample *ibuf, st_sample *obuf,
>                     size_t *isamp, size_t *osamp);
> 



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] coreaudio: fix coreaudio playback
  2020-02-02 14:06 ` [PATCH] " Volker Rümelin
  2020-02-02 19:41   ` Zoltán Kővágó
@ 2020-02-06 13:38   ` Gerd Hoffmann
  1 sibling, 0 replies; 5+ messages in thread
From: Gerd Hoffmann @ 2020-02-06 13:38 UTC (permalink / raw)
  To: Volker Rümelin
  Cc: Programmingkid, Howard Spoelstra, Mark Cave-Ayland,
	qemu Developers, Zoltán Kővágó

On Sun, Feb 02, 2020 at 03:06:41PM +0100, Volker Rümelin wrote:
> There are reports that since commit 2ceb8240fa "coreaudio: port
> to the new audio backend api" audio playback with CoreAudio is
> broken. This patch reverts some parts the commit.
> 
> Because of changes in the audio subsystem the audio clip
> function in v4.1.0 of coreaudio.c had to be moved to mixeng.c
> and the generic buffer management code needed a hint about the
> size of the float type.
> 
> This patch is based on a patch from Zoltán Kővágó found at
> https://lists.nongnu.org/archive/html/qemu-devel/2020-01/msg02142.html.
> 
> Fixes: 2ceb8240fa "coreaudio: port to the new audio backend api"
> 
> Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>

Patch queued.

thanks,
  Gerd



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-02-06 13:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-02 14:03 [PATCH 0/1] coreaudio: fix coreaudio playback Volker Rümelin
2020-02-02 14:06 ` [PATCH] " Volker Rümelin
2020-02-02 19:41   ` Zoltán Kővágó
2020-02-06 13:38   ` Gerd Hoffmann
2020-02-02 18:16 ` [PATCH 0/1] " Howard Spoelstra

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.