audio/madplay: Add sndio backend and option [1]

While here

- Follow WWW redirect
- Fix license

Obtained from:	OpenBSD Ports [1]
This commit is contained in:
Tobias Kortkamp 2018-09-18 10:10:54 +00:00
parent 08cabccbc8
commit 89f9209f99
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=480006
5 changed files with 227 additions and 5 deletions

View file

@ -11,7 +11,8 @@ MASTER_SITES= SF/mad/${PORTNAME}/${PORTVERSION} \
MAINTAINER= ports@FreeBSD.org MAINTAINER= ports@FreeBSD.org
COMMENT= Madplay MP3 player (part of MAD project) COMMENT= Madplay MP3 player (part of MAD project)
LICENSE= GPLv2 LICENSE= GPLv2+
LICENSE_FILE= ${WRKSRC}/COPYRIGHT
LIB_DEPENDS= libmad.so:audio/libmad \ LIB_DEPENDS= libmad.so:audio/libmad \
libid3tag.so:audio/libid3tag libid3tag.so:audio/libid3tag
@ -23,12 +24,18 @@ CONFIGURE_ARGS= --without-esd
LDFLAGS+= -lz LDFLAGS+= -lz
ALL_TARGET= all madtime ALL_TARGET= all madtime
OPTIONS_DEFINE= NLS OPTIONS_DEFINE= NLS SNDIO
OPTIONS_SUB= yes OPTIONS_SUB= yes
NLS_USES= gettext NLS_USES= gettext
NLS_CONFIGURE_ENABLE= nls NLS_CONFIGURE_ENABLE= nls
SNDIO_CONFIGURE_WITH= sndio
SNDIO_LIB_DEPENDS= libsndio.so:audio/sndio
post-extract-SNDIO-on:
@${CP} ${FILESDIR}/audio_sndio.c ${WRKSRC}
post-install: post-install:
${INSTALL_PROGRAM} ${WRKSRC}/madtime ${STAGEDIR}${PREFIX}/bin ${INSTALL_PROGRAM} ${WRKSRC}/madtime ${STAGEDIR}${PREFIX}/bin

View file

@ -0,0 +1,160 @@
/* $OpenBSD: audio_sndio.c,v 1.2 2009/06/20 14:56:18 martynas Exp $ */
/*
* Copyright (c) 2009 Martynas Venckus <martynas@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "global.h"
#include "gettext.h"
#include "audio.h"
#include <sndio.h>
static audio_pcmfunc_t *audio_pcm;
static struct sio_hdl *hdl;
static int sio_started;
static int
init(struct audio_init *init)
{
hdl = sio_open((char *)init->path, SIO_PLAY, 0);
if (hdl == NULL) {
audio_error = ":";
return (-1);
}
return (0);
}
static int
config(struct audio_config *config)
{
struct sio_par par;
unsigned int bitdepth;
bitdepth = config->precision & ~7;
if (bitdepth == 0) {
bitdepth = 16;
} else if (bitdepth > 32) {
bitdepth = 32;
}
sio_initpar(&par);
par.bits = bitdepth;
par.le = SIO_LE_NATIVE;
par.pchan = config->channels;
par.rate = config->speed;
par.sig = (par.bits == 8) ? 0 : 1;
if (sio_started) {
sio_stop(hdl);
sio_started = 0;
}
if (!sio_setpar(hdl, &par) || !sio_getpar(hdl, &par) ||
!sio_start(hdl)) {
audio_error = ":sio_setpar";
sio_close(hdl);
return (-1);
}
sio_started = 1;
switch(par.bits) {
case 8:
audio_pcm = audio_pcm_u8;
break;
case 16:
audio_pcm = par.le ? audio_pcm_s16le : audio_pcm_s16be;
break;
case 24:
audio_pcm = par.le ? audio_pcm_s32le : audio_pcm_s32be;
break;
case 32:
audio_pcm = par.le ? audio_pcm_s32le : audio_pcm_s32be;
break;
default:
audio_error = _("no supported audio format available");
sio_close(hdl);
return (-1);
}
config->channels = par.pchan;
config->precision = par.bits;
config->speed = par.rate;
return (0);
}
static int
play(struct audio_play *play)
{
unsigned char data[MAX_NSAMPLES * 4 * 2];
unsigned int len;
int count;
len = audio_pcm(data, play->nsamples, play->samples[0],
play->samples[1], play->mode, play->stats);
count = (int)sio_write(hdl, data, len);
if (count == 0 && sio_eof(hdl))
return (-1);
return (count);
}
static int
stop(struct audio_stop *stop)
{
return (0);
}
static int
finish(struct audio_finish *finish)
{
sio_close(hdl);
return (0);
}
int
audio_sndio(union audio_control *control)
{
audio_error = 0;
switch (control->command) {
case AUDIO_COMMAND_INIT:
return (init(&control->init));
case AUDIO_COMMAND_CONFIG:
return (config(&control->config));
case AUDIO_COMMAND_PLAY:
return (play(&control->play));
case AUDIO_COMMAND_STOP:
return (stop(&control->stop));
case AUDIO_COMMAND_FINISH:
return (finish(&control->finish));
}
return (0);
}

View file

@ -0,0 +1,11 @@
$OpenBSD: patch-audio_h,v 1.1 2009/03/28 16:26:46 martynas Exp $
--- audio.h.orig 2004-01-23 09:41:31 UTC
+++ audio.h
@@ -98,6 +98,7 @@ audio_ctlfunc_t audio_jaguar;
audio_ctlfunc_t audio_nas;
audio_ctlfunc_t audio_oss;
audio_ctlfunc_t audio_qnx;
+audio_ctlfunc_t audio_sndio;
audio_ctlfunc_t audio_sun;
audio_ctlfunc_t audio_win32;

View file

@ -0,0 +1,46 @@
Do the bare minimum to provide a toggle for sndio support
--- configure.orig 2004-02-23 21:36:21 UTC
+++ configure
@@ -27912,7 +27912,30 @@ echo "$as_me: error: cannot use both --with-$audio and
fi;
+want_sndio=yes
+# Check whether --with-esd or --without-esd was given.
+if test "${with_sndio+set}" = set; then
+ withval="$with_sndio"
+
+ case "$withval" in
+ yes)
+ if test "$audio" = unknown
+ then
+ audio="sndio"
+ else
+ { { echo "$as_me:$LINENO: error: cannot use both --with-$audio and --with-esd" >&5
+echo "$as_me: error: cannot use both --with-$audio and --with-esd" >&2;}
+ { (exit 1); exit 1; }; }
+ fi
+ ;;
+ no)
+ want_sndio=no
+ ;;
+ esac
+
+fi;
+
if test "$audio" = unknown
then
case "$host" in
@@ -28252,6 +28275,10 @@ else
fi
fi
+if test "$audio" = sndio && test "$want_sndio" = yes
+then
+ ldadd_audio="$ldadd_audio -lsndio"
+fi
if test "$audio" = unknown
then

View file

@ -5,6 +5,4 @@ fully implemented.
This is madplay (MP3-player) which is part of the project This is madplay (MP3-player) which is part of the project
LICENSE: GPL2 or later WWW: https://www.underbit.com/products/mad/
WWW: http://mad.sourceforge.net/