Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/audio libao-sun: convert 24-bit samples to 32-bit samples



details:   https://anonhg.NetBSD.org/pkgsrc/rev/e5e66b5c861a
branches:  trunk
changeset: 432992:e5e66b5c861a
user:      nia <nia%pkgsrc.org@localhost>
date:      Thu May 28 19:30:45 2020 +0000

description:
libao-sun: convert 24-bit samples to 32-bit samples

working around the inability of the netbsd 9 kernel (at least) to
handle 24-bit lpcm directly in its default configuration. this
fixes problems playing 24-bit flac in cmus, at least.

with the kernel compiled with AUDIO_SUPPORT_LINEAR24 this is not
actually necessary and we should maybe consider doing that by default.

diffstat:

 audio/libao-sun/Makefile                            |   3 +-
 audio/libao/distinfo                                |   4 +-
 audio/libao/patches/patch-src_plugins_sun_ao__sun.c |  91 ++++++++++++++++++++-
 3 files changed, 92 insertions(+), 6 deletions(-)

diffs (135 lines):

diff -r ea9fe3e5e1c9 -r e5e66b5c861a audio/libao-sun/Makefile
--- a/audio/libao-sun/Makefile  Thu May 28 16:22:58 2020 +0000
+++ b/audio/libao-sun/Makefile  Thu May 28 19:30:45 2020 +0000
@@ -1,8 +1,9 @@
-# $NetBSD: Makefile,v 1.11 2019/11/24 00:35:57 nia Exp $
+# $NetBSD: Makefile,v 1.12 2020/05/28 19:30:45 nia Exp $
 
 .include "../../audio/libao/Makefile.common"
 
 PKGNAME=       ${DISTNAME:S/libao/libao-sun/}
+PKGREVISION=   1
 
 COMMENT+=      (Sun audio plugin)
 
diff -r ea9fe3e5e1c9 -r e5e66b5c861a audio/libao/distinfo
--- a/audio/libao/distinfo      Thu May 28 16:22:58 2020 +0000
+++ b/audio/libao/distinfo      Thu May 28 19:30:45 2020 +0000
@@ -1,8 +1,8 @@
-$NetBSD: distinfo,v 1.26 2019/11/24 00:35:56 nia Exp $
+$NetBSD: distinfo,v 1.27 2020/05/28 19:30:45 nia Exp $
 
 SHA1 (libao-1.2.2.tar.gz) = aa2a6ac0df63c702e46477ea5ce4a9b32e0d4306
 RMD160 (libao-1.2.2.tar.gz) = d65fa3dc31b591d22bb8a47c71a91615cc1919cf
 SHA512 (libao-1.2.2.tar.gz) = d2736d25b60862e7d7469611ce31b1df40a4366ab160e2ff1b46919ae91692d1596c8468e4f016303b306fc3ac1bddc7b727f535a362f403c3fe7c6532e9045a
 Size (libao-1.2.2.tar.gz) = 96134 bytes
 SHA1 (patch-src_plugins_alsa_ao__alsa.c) = 9047608f232c4e4bfd5e4b3fcac3831750b0eef3
-SHA1 (patch-src_plugins_sun_ao__sun.c) = 6ba6d6ae4311a8a48dd7bb55e33d4516ac68b607
+SHA1 (patch-src_plugins_sun_ao__sun.c) = b1e9b11a4b5211e69172cc3d6418ec8e35d014f2
diff -r ea9fe3e5e1c9 -r e5e66b5c861a audio/libao/patches/patch-src_plugins_sun_ao__sun.c
--- a/audio/libao/patches/patch-src_plugins_sun_ao__sun.c       Thu May 28 16:22:58 2020 +0000
+++ b/audio/libao/patches/patch-src_plugins_sun_ao__sun.c       Thu May 28 19:30:45 2020 +0000
@@ -1,15 +1,100 @@
-$NetBSD: patch-src_plugins_sun_ao__sun.c,v 1.1 2019/11/24 00:35:56 nia Exp $
+$NetBSD: patch-src_plugins_sun_ao__sun.c,v 1.2 2020/05/28 19:30:45 nia Exp $
 
-Fix device selection.
+- Fix device selection on NetBSD.
+- Support 24-bit playback on NetBSD.
 
 --- src/plugins/sun/ao_sun.c.orig      2016-11-14 08:03:30.000000000 +0000
 +++ src/plugins/sun/ao_sun.c
-@@ -160,7 +160,7 @@ int ao_plugin_open(ao_device *device, ao
+@@ -78,6 +78,9 @@ typedef struct ao_sun_internal {
+       char *dev;
+         int id;
+       int fd;
++      int linear24;
++      void *convbuf;
++      size_t convbuf_sz;
+ } ao_sun_internal;
+ 
+ 
+@@ -160,7 +163,11 @@ int ao_plugin_open(ao_device *device, ao
  
          if(internal->dev==NULL){
            char buf[80];
 -          sprintf(buf,"/dev/sound/%d",internal->id);
++#ifdef __sun
 +          snprintf(buf,sizeof(buf),"/dev/audio%d",internal->id);
++#else
++          snprintf(buf,sizeof(buf),"/dev/sound/%d",internal->id);
++#endif
            internal->dev=strdup(buf);
          }
  
+@@ -172,7 +179,12 @@ int ao_plugin_open(ao_device *device, ao
+       info.mode = AUMODE_PLAY;
+ #endif
+       info.play.encoding = AUDIO_ENCODING_SLINEAR;
+-      info.play.precision = format->bits;
++      if (format->bits == 24) {
++              info.play.precision = 32;
++              internal->linear24 = 1;
++      } else {
++              info.play.precision = format->bits;
++      }
+       info.play.sample_rate = format->rate;
+       info.play.channels = device->output_channels;
+ 
+@@ -198,8 +210,46 @@ int ao_plugin_play(ao_device *device, co
+               uint_32 num_bytes)
+ {
+       ao_sun_internal *internal = (ao_sun_internal *) device->internal;
++      void *out;
++
++      /* convert 24-bit linear to 32-bit linear for NetBSD compat */
++      if (internal->linear24) {
++              unsigned char *srcp = (unsigned char *)output_samples;
++              size_t nsamples = num_bytes / 3;
++              size_t bufsz = nsamples * 4;
++              sint_32 *outp, temp;
++
++              if (internal->convbuf_sz < bufsz) {
++                      internal->convbuf = realloc(internal->convbuf, bufsz);
++                      if (!internal->convbuf)
++                              return 1;
++                      internal->convbuf_sz = bufsz;
++              }
++              outp = internal->convbuf;
++              if (device->driver_byte_format != AO_FMT_BIG) {
++                      while (nsamples--) {
++                              temp = (((sint_32)srcp[0]) << 8);
++                              temp = temp | (((sint_32)srcp[1]) << 16);
++                              temp = temp | (((sint_32)srcp[2]) << 24);
++                              *(outp++) = temp;
++                              srcp += 3;
++                      }
++              } else {
++                      while (nsamples--) {
++                              temp = (((sint_32)srcp[0]) << 24);
++                              temp = temp | (((sint_32)srcp[1]) << 16);
++                              temp = temp | (((sint_32)srcp[2]) << 8);
++                              *(outp++) = temp;
++                              srcp += 3;
++                      }
++              }
++              num_bytes = bufsz;
++              out = internal->convbuf;
++      } else {
++              out = (void *)output_samples;
++      }
+ 
+-      if (write(internal->fd, output_samples, num_bytes) < 0)
++      if (write(internal->fd, out, num_bytes) < 0)
+               return 0;
+       else
+               return 1;
+@@ -224,6 +274,7 @@ void ao_plugin_device_clear(ao_device *d
+ 
+         if(internal->dev)
+           free(internal->dev);
++      free(internal->convbuf);
+       free(internal);
+         device->internal=NULL;
+ }



Home | Main Index | Thread Index | Old Index