wip/pcaudiolib: Add code to achieve the hardcoded latency in netbsd.c and clean up
authoradr <adr@sdf.org>
Tue, 30 Jan 2024 02:09:20 +0000 (02:09 +0000)
committeradr <adr@sdf.org>
Tue, 30 Jan 2024 02:11:14 +0000 (02:11 +0000)
pcaudiolib/COMMIT_MSG
pcaudiolib/Makefile
pcaudiolib/distinfo
pcaudiolib/options.mk
pcaudiolib/patches/patch-Makefile.am
pcaudiolib/patches/patch-configure.ac
pcaudiolib/patches/patch-src_audio.c
pcaudiolib/patches/patch-src_audio__priv.h
pcaudiolib/patches/patch-src_netbsd.c [moved from pcaudiolib/patches/patch-src_sun.c with 63% similarity]
sonic/buildlink3.mk

index 96969711830ea22a59951a3552f4e32e29b28a71..b8337f08867d8a4d699d1bcf1627acf8751cbb66 100644 (file)
@@ -1,3 +1,3 @@
 audio/pcaudiolib: Add pcaudiolib version 1.2
 
-Packaged in wip by adr
\ No newline at end of file
+Packaged in wip by adr
index a81940317a5c88840d4cd6fa04ad7fe587143c35..968cb3772c97758085cc44e85f13144b2867a0e3 100644 (file)
@@ -16,6 +16,20 @@ USE_LIBTOOL= yes
 USE_LANGUAGES= c c++
 USE_TOOLS+=    automake autoconf autoreconf pkg-config
 
+.include "../../mk/bsd.prefs.mk"
+
+.if ${OPSYS} == "NetBSD"
+CONFIGURE_ARGS+=       --with-netbsd
+.else
+CONFIGURE_ARGS+=       --without-netbsd
+.endif
+
+.if ${OPSYS} == "Darwin"
+CONFIGURE_ARGS+=       --with-coreaudio
+.else
+CONFIGURE_ARGS+=       --without-coreaudio
+.endif
+
 .include "../../mk/oss.buildlink3.mk"
 .if ${OSS_TYPE} != "none"
 SUBST_CLASSES+=         oss
index a655b2fd98f8c77a26ad87defcf17efa08b4160a..c0271ca0a1a20e701f26844fb68ea27b5024941e 100644 (file)
@@ -3,8 +3,8 @@ $NetBSD$
 BLAKE2s (pcaudiolib-1.2.tar.gz) = 11dc27e944fb2edba51c0b4f1da100e7279e44e24821941e3fdd222c85b2da94
 SHA512 (pcaudiolib-1.2.tar.gz) = 803e8c36646f780b9e9a98600092af366ad47ecf9cb447b9b6c82b75eb316ee65674832fc0cbfa56ee4d508ae1d0f69890f5885817e6df3e2ecef54571b936d6
 Size (pcaudiolib-1.2.tar.gz) = 377066 bytes
-SHA1 (patch-Makefile.am) = 880ffb94a684952451b40aa34db94300119cbeeb
-SHA1 (patch-configure.ac) = 88238b7703d6ced3f7ed0934d507364d174941c3
-SHA1 (patch-src_audio.c) = b15ab14dac93cf10a282e488a17585f2999e58fe
-SHA1 (patch-src_audio__priv.h) = d9712a2d0a66e4f4f96ca8f8de4020beeffac828
-SHA1 (patch-src_sun.c) = f6f83d11f39f8c6d43894210813dcd5f551aa8a4
+SHA1 (patch-Makefile.am) = 3b43eb33eedcc72e5db3fd979b1ed063027e35fa
+SHA1 (patch-configure.ac) = b63548a43ba29e090533d1465917241afdfcfc06
+SHA1 (patch-src_audio.c) = 60151f3351d2edba425f2e83947c1177bde46c50
+SHA1 (patch-src_audio__priv.h) = 7c99cffc279d31b00deadd0a4690627bd7331863
+SHA1 (patch-src_netbsd.c) = b188ed04fef7aa55a5e41c5c8d54aa7c9cdb69db
index 8d948e8485f4e1c7430b80383c0f7e778cb20bc9..6da95636deac9dda036a2bc793ef335590fa704b 100644 (file)
@@ -2,19 +2,11 @@
 
 PKG_OPTIONS_VAR=               PKG_OPTIONS.pcaudiolib
 
-PKG_SUPPORTED_OPTIONS+=                alsa pulseaudio sun
+PKG_SUPPORTED_OPTIONS+=                alsa pulseaudio
 PKG_SUGGESTED_OPTIONS.Linux+=  alsa
-PKG_SUGGESTED_OPTIONS.NetBSD+= sun
 
 .include "../../mk/bsd.options.mk"
 
-.if !empty(PKG_OPTIONS:Msun)
-CONFIGURE_ARGS+=       --with-sun
-CFLAGS+=               -D_SUNAUDIO
-.else
-CONFIGURE_ARGS+=       --without-sun
-.endif
-
 .if !empty(PKG_OPTIONS:Malsa)
 .  include "../../audio/alsa-lib/buildlink3.mk"
 CONFIGURE_ARGS+=       --with-alsa
index ec83ed2649f7d58a01cce5c5c358089baa7cd57b..3e5717bb67c84d32307fe278498745174b8f4839 100644 (file)
@@ -9,8 +9,8 @@ Add sun.c to the source list when Sun audio is enabled
        src/TPCircularBuffer/TPCircularBuffer.podspec
  endif
 +
-+# Sun audio support
-+if HAVE_SUN
++# NetBSD audio support
++if HAVE_NETBSD
 +src_libpcaudio_la_SOURCES += \
-+      src/sun.c
++      src/netbsd.c
 +endif
index 732c2deba39d0bf18f276084277e338dad6ee837..d545dab0efd35f71adb0af99a20d21896592b1b3 100644 (file)
@@ -8,27 +8,27 @@ Add Sun audio support
  fi
  
  dnl ================================================================
-+dnl Sun checks.
++dnl NetBSD checks.
 +dnl ================================================================
 +
-+AC_ARG_WITH([sun],
-+    [AS_HELP_STRING([--with-sun], [support for Sun audio output @<:@default=no@:>@])],
++AC_ARG_WITH([netbsd],
++    [AS_HELP_STRING([--with-netbsd], [support for NetBSD audio output @<:@default=no@:>@])],
 +    [])
 +
-+if test "$with_sun" = "no"; then
-+    echo "Disabling Sun audio output support"
-+    have_sun=no
++if test "$with_netbsd" = "no"; then
++    echo "Disabling NetBSD audio output support"
++    have_netbsd=no
 +else
 +    case $host_os in
 +        *netbsd*)
-+            have_sun=yes
++            have_netbsd=yes
 +          ;;
 +        *)
-+            have_sun=no
++            have_netbsd=no
 +            ;;
 +    esac
 +fi
-+AM_CONDITIONAL([HAVE_SUN], [test "x${have_sun}" = "xyes"])
++AM_CONDITIONAL([HAVE_NETBSD], [test "x${have_netbsd}" = "xyes"])
 +
 +dnl ================================================================
  dnl Generate output.
@@ -38,5 +38,5 @@ Add Sun audio support
        QSA support:                   ${have_qsa}
        Coreaudio support:             ${have_coreaudio} 
        OSS support:                   ${have_oss}
-+      Sun support:                   ${have_sun}
++      NetBSD support:                ${have_netbsd}
  ])
index 3bde6a0cdefd5ae556ddf36f1b6911b28aea6503..16963466e313f410eedbe61043ee5ee781959717 100644 (file)
@@ -10,8 +10,8 @@ Add Sun audio support
                return object;
 -
 +#else
-+#if defined(_SUNAUDIO)       
-+      if ((object = create_sun_object(device, application_name, description)) != NULL)
++#if defined(__NetBSD__)       
++      if ((object = create_netbsd_object(device, application_name, description)) != NULL)
 +              return object;
  #else
        if ((object = create_pulseaudio_object(device, application_name, description)) != NULL)
index ad98dc830d286482419f82fbce4b570409a2f84f..1e33f3b088031db00905ee127583e7470f18b3ca 100644 (file)
@@ -4,15 +4,29 @@ Add Sun audio support
 
 --- src/audio_priv.h.orig      2021-07-30 08:54:26.000000000 +0000
 +++ src/audio_priv.h
-@@ -115,6 +115,11 @@ create_oss_object(const char *device,
-                   const char *application_name,
-                   const char *description);
+@@ -86,6 +86,15 @@ create_xaudio2_object(const char *device
+         const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
+         (type *)( (char *)__mptr - offsetof(type,member) );})
  
++#ifdef __NetBSD__
++
 +struct audio_object *
-+create_sun_object(const char *device,
++create_netbsd_object(const char *device,
 +                  const char *application_name,
 +                  const char *description);
 +
++#else
++
+ #ifdef __APPLE__
+ struct audio_object *
+@@ -117,7 +126,8 @@ create_oss_object(const char *device,
  #endif
  #endif
+-
++#endif
++  
+ #ifdef __cplusplus
+ }
+ #endif
similarity index 63%
rename from pcaudiolib/patches/patch-src_sun.c
rename to pcaudiolib/patches/patch-src_netbsd.c
index 7f6eb806cd829a4222354ba412ba6169e505f673..1a8e9dcc35f987eadcbe2b1df1ec4eadbd0da37c 100644 (file)
@@ -1,11 +1,9 @@
 $NetBSD$
 
-Add Sun audio support
-
---- src/sun.c.orig     2024-01-26 01:42:30.586543911 +0000
-+++ src/sun.c
-@@ -0,0 +1,195 @@
-+/* Sun Output.
+--- src/netbsd.c.orig  2024-01-30 01:47:27.652017641 +0000
++++ src/netbsd.c
+@@ -0,0 +1,198 @@
++/* Netbsd Output.
 + *
 + * Based on Oss Output by Reece H. Dunn
 + *
@@ -37,7 +35,7 @@ Add Sun audio support
 +#include <sys/ioctl.h>
 +#include <unistd.h>
 +
-+struct sun_object
++struct netbsd_object
 +{
 +      struct audio_object vtable;
 +      int fd;
@@ -46,15 +44,15 @@ Add Sun audio support
 +
 +};
 +
-+#define to_sun_object(object) container_of(object, struct sun_object, vtable)
++#define to_netbsd_object(object) container_of(object, struct netbsd_object, vtable)
 +
 +int
-+sun_object_open(struct audio_object *object,
++netbsd_object_open(struct audio_object *object,
 +                enum audio_object_format format,
 +                uint32_t rate,
 +                uint8_t channels)
 +{
-+      struct sun_object *self = to_sun_object(object);
++      struct netbsd_object *self = to_netbsd_object(object);
 +              
 +      if (self->fd != -1)
 +              return EEXIST;
@@ -62,10 +60,10 @@ Add Sun audio support
 +      struct aformat_sun
 +      {
 +              int audio_object_format;
-+              int sun_format;
-+              int sun_precision;
++              int netbsd_format;
++              int netbsd_precision;
 +      };
-+      struct aformat_sun aformat_sun_tbl[] = {
++      struct aformat_sun aformat_netbsd_tbl[] = {
 +              {AUDIO_OBJECT_FORMAT_ALAW, AUDIO_ENCODING_ALAW, 8},
 +              {AUDIO_OBJECT_FORMAT_ULAW, AUDIO_ENCODING_ULAW, 8},
 +              {AUDIO_OBJECT_FORMAT_S8, AUDIO_ENCODING_SLINEAR, 8},
@@ -92,57 +90,60 @@ Add Sun audio support
 +              {AUDIO_OBJECT_FORMAT_U32BE, AUDIO_ENCODING_ULINEAR_BE, 32},
 +              {AUDIO_OBJECT_FORMAT_ADPCM, AUDIO_ENCODING_ADPCM, 8},
 +      };
-+#define SUNFORMATS (sizeof(aformat_sun_tbl)/sizeof(aformat_sun_tbl[0]))
++#define NETBSDFORMATS (sizeof(aformat_netbsd_tbl)/sizeof(aformat_netbsd_tbl[0]))
 +      int i;
-+      for(i=0; i < SUNFORMATS; i++)
-+              if(aformat_sun_tbl[i].audio_object_format == format)
++      for(i=0; i < NETBSDFORMATS; i++)
++              if(aformat_netbsd_tbl[i].audio_object_format == format)
 +                      break;
-+      if(i >= SUNFORMATS)
++      if(i >= NETBSDFORMATS)
 +              return EINVAL;
 +
-+      int data;
 +      audio_info_t audioinfo;
 +      if ((self->fd = open(self->device ? self->device : "/dev/audio", O_WRONLY, 0)) == -1)
 +              return errno;
-+      AUDIO_INITINFO(&audioinfo);
++      if (ioctl(self->fd, AUDIO_GETINFO, &audioinfo) == -1)
++              goto error;
 +      audioinfo.play.sample_rate = rate;
 +      audioinfo.play.channels = channels;
-+      audioinfo.play.precision = aformat_sun_tbl[i].sun_precision;
-+      audioinfo.play.encoding = aformat_sun_tbl[i].sun_format;        
++      audioinfo.play.precision = aformat_netbsd_tbl[i].netbsd_precision;
++      audioinfo.play.encoding = aformat_netbsd_tbl[i].netbsd_format;
++      /* Use the high and low water marks to achieve the desired latency (LATENCY is in ms) */
++      audioinfo.hiwat = (rate * channels * audioinfo.play.precision * LATENCY) / (1000 * audioinfo.blocksize);
++      audioinfo.lowat = (audioinfo.hiwat * 70) / 100;
 +      if (ioctl(self->fd, AUDIO_SETINFO, &audioinfo) == -1)
 +              goto error;
++      ioctl(self->fd, AUDIO_GETINFO, &audioinfo);
 +      return 0;
 +error:
-+      data = errno;
 +      close(self->fd);
 +      self->fd = -1;
-+      return data;
++      return errno;
 +}
 +
 +void
-+sun_object_close(struct audio_object *object)
++netbsd_object_close(struct audio_object *object)
 +{
-+      struct sun_object *self = to_sun_object(object);
++      struct netbsd_object *self = to_netbsd_object(object);
 +
-+      if (self->fd == -1) {
++      if (self->fd != -1) {
 +              close(self->fd);
 +              self->fd = -1;
 +      }
 +}
 +
 +void
-+sun_object_destroy(struct audio_object *object)
++netbsd_object_destroy(struct audio_object *object)
 +{
-+      struct sun_object *self = to_sun_object(object);
++      struct netbsd_object *self = to_netbsd_object(object);
 +
 +      free(self->device);
 +      free(self);
 +}
 +
 +int
-+sun_object_drain(struct audio_object *object)
++netbsd_object_drain(struct audio_object *object)
 +{
-+      struct sun_object *self = to_sun_object(object);
++      struct netbsd_object *self = to_netbsd_object(object);
 +
 +      if (ioctl(self->fd, AUDIO_DRAIN, NULL) == -1)
 +              return errno;
@@ -150,21 +151,21 @@ Add Sun audio support
 +}
 +
 +int
-+sun_object_flush(struct audio_object *object)
++netbsd_object_flush(struct audio_object *object)
 +{
-+      struct sun_object *self = to_sun_object(object);
++      struct netbsd_object *self = to_netbsd_object(object);
 +
-+      if (ioctl(self->fd, AUDIO_FLUSH, NULL) == -1)
++              if (ioctl(self->fd, AUDIO_FLUSH, NULL) == -1)
 +              return errno;
 +      return 0;
 +}
 +
 +int
-+sun_object_write(struct audio_object *object,
++netbsd_object_write(struct audio_object *object,
 +                 const void *data,
 +                 size_t bytes)
 +{
-+      struct sun_object *self = to_sun_object(object);
++      struct netbsd_object *self = to_netbsd_object(object);
 +
 +      if (write(self->fd, data, bytes) == -1)
 +              return errno;
@@ -172,31 +173,31 @@ Add Sun audio support
 +}
 +
 +const char *
-+sun_object_strerror(struct audio_object *object,
++netbsd_object_strerror(struct audio_object *object,
 +                    int error)
 +{
 +      return strerror(error);
 +}
 +
 +struct audio_object *
-+create_sun_object(const char *device,
++create_netbsd_object(const char *device,
 +                  const char *application_name,
 +                  const char *description)
 +{
-+      struct sun_object *self = malloc(sizeof(struct sun_object));
++      struct netbsd_object *self = malloc(sizeof(struct netbsd_object));
 +      if (!self)
 +              return NULL;
 +
 +      self->fd = -1;
 +      self->device = device ? strdup(device) : NULL;
 +
-+      self->vtable.open = sun_object_open;
-+      self->vtable.close = sun_object_close;
-+      self->vtable.destroy = sun_object_destroy;
-+      self->vtable.write = sun_object_write;
-+      self->vtable.drain = sun_object_drain;
-+      self->vtable.flush = sun_object_flush;
-+      self->vtable.strerror = sun_object_strerror;
++      self->vtable.open = netbsd_object_open;
++      self->vtable.close = netbsd_object_close;
++      self->vtable.destroy = netbsd_object_destroy;
++      self->vtable.write = netbsd_object_write;
++      self->vtable.drain = netbsd_object_drain;
++      self->vtable.flush = netbsd_object_flush;
++      self->vtable.strerror = netbsd_object_strerror;
 +
 +      return &self->vtable;
 +}
index 9abba908d9b8b28b28f4a58221c99dfa52dfc16c..b0998fa6d925d94f4745fe83bdd99a34926d4f3b 100644 (file)
@@ -5,8 +5,8 @@ BUILDLINK_TREE+=        sonic
 .if !defined(SONIC_BUILDLINK3_MK)
 SONIC_BUILDLINK3_MK:=
 
-BUILDLINK_API_DEPENDS.sonic+=  sonic>=0.2.0
-BUILDLINK_ABI_DEPENDS.sonic+=  sonic>=0.2.0
+BUILDLINK_API_DEPENDS.sonic+=  sonic>=0.0.0.225
+BUILDLINK_ABI_DEPENDS.sonic+=  sonic>=0.0.0.225
 BUILDLINK_PKGSRCDIR.sonic?=    ../../audio/sonic
 
 .endif # SONIC_BUILDLINK3_MK