convert to sndio(7), which allows this port to be used with all
non-"isdn bullshit" audio devices OpenBSD currently (and most likely ever will) supports. sndio(7) doesn't support audioamd(4) (which is an isdn device), but the audio(4) backend here didn't support that device either. tested on a 195 MHz r10k O2 extracting install tarballs + 'cvs co ports' + repeatedly compiling tracker in a loop + 'find /', all running simultaneously over the built-in mec0 NIC, a zaurus with hw.setperf set to 0 + 'find /' running on the console + tracker and an audio device monitoring program run from an ssh session through a wi(4) pcmcia card, a 233MHz Toshiba Tecra 8000 with wss(4), and various other machines.
This commit is contained in:
parent
92d44aef56
commit
56cbd2c6ca
@ -1,8 +1,8 @@
|
||||
# $OpenBSD: Makefile,v 1.25 2008/01/04 17:48:33 espie Exp $
|
||||
# $OpenBSD: Makefile,v 1.26 2010/06/30 11:50:51 jakemsr Exp $
|
||||
|
||||
COMMENT= MOD player
|
||||
DISTNAME= tracker-5.3
|
||||
PKGNAME= ${DISTNAME}p0
|
||||
PKGNAME= ${DISTNAME}p1
|
||||
CATEGORIES= audio
|
||||
|
||||
MASTER_SITES= ftp://ftp.uni-trier.de/pub/unix/audio/tracker/
|
||||
@ -16,11 +16,12 @@ PERMIT_PACKAGE_CDROM= Yes
|
||||
PERMIT_PACKAGE_FTP= Yes
|
||||
PERMIT_DISTFILES_CDROM= Yes
|
||||
PERMIT_DISTFILES_FTP= Yes
|
||||
WANTLIB= c m
|
||||
WANTLIB= c m sndio
|
||||
|
||||
WRKDIST= ${WRKDIR}/tracker
|
||||
MAKE_FLAGS= MACHINE=openbsd CC=$(CC) INSTALL="$(INSTALL)" \
|
||||
CFLAGS_openbsd='-O3 -funroll-loops -finline-functions ${COPTS}' \
|
||||
LIBS_openbsd='-lm -lsndio' \
|
||||
INST_BIN_OPT="-c -s -m $(BINMODE) -o $(BINOWN) -g $(BINGRP)" \
|
||||
INST_MAN_OPT="-c -m 644 -o $(BINOWN) -g $(BINGRP)" \
|
||||
COMPRESSION_FILE='$${DESTDIR}${SYSCONFDIR}/compression_methods' \
|
||||
|
@ -1,16 +1,14 @@
|
||||
/* openbsd/audio.c
|
||||
vi:ts=3 sw=3:
|
||||
*/
|
||||
/* Native BSD interface */
|
||||
/* sndio(7) interface */
|
||||
|
||||
#include "defs.h"
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include "extern.h"
|
||||
#include "prefs.h"
|
||||
#include "autoinit.h"
|
||||
#include "watched_var.h"
|
||||
#include <sys/ioctl.h>
|
||||
struct options_set *port_options=0;
|
||||
|
||||
#define DEFAULT_BUFFERS
|
||||
@ -20,117 +18,56 @@ struct options_set *port_options=0;
|
||||
#define NEW_FUNCS
|
||||
|
||||
/* fine-tune to get the scrolling display in sync with the music */
|
||||
#define ADVANCE_TAGS 20000
|
||||
#define ADVANCE_TAGS 20000
|
||||
|
||||
#include "Arch/common.c"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/audioio.h>
|
||||
|
||||
|
||||
|
||||
|
||||
ID("$Id: audio.c,v 1.4 2010/05/17 18:10:05 espie Exp $")
|
||||
#include <sndio.h>
|
||||
|
||||
LOCAL unsigned long samples_max;
|
||||
LOCAL int audio;
|
||||
LOCAL long long realpos;
|
||||
LOCAL struct sio_hdl *hdl;
|
||||
LOCAL unsigned long current_freq;
|
||||
|
||||
unsigned long total;
|
||||
|
||||
LOCAL int dsp_samplesize = 0;
|
||||
|
||||
static void
|
||||
movecb(void *arg, int delta)
|
||||
{
|
||||
realpos += delta * dsize * (stereo ? 2 : 1);
|
||||
}
|
||||
|
||||
unsigned long open_audio(unsigned long f, int s)
|
||||
{
|
||||
struct sio_par par;
|
||||
int buf_max;
|
||||
unsigned long possible, current;
|
||||
|
||||
audio = open("/dev/audio", O_WRONLY, 0);
|
||||
if (audio == -1)
|
||||
hdl = sio_open(NULL, SIO_PLAY, 0);
|
||||
if (hdl == NULL)
|
||||
end_all("Error opening audio device");
|
||||
|
||||
/* iterate and find true native formats */
|
||||
{
|
||||
struct audio_encoding query;
|
||||
for (query.index = 0;
|
||||
ioctl(audio, AUDIO_GETENC, &query) != -1;
|
||||
query.index++)
|
||||
{
|
||||
if (query.flags & AUDIO_ENCODINGFLAG_EMULATED)
|
||||
continue;
|
||||
if (query.precision == 16 &&
|
||||
(query.encoding == AUDIO_ENCODING_SLINEAR_BE ||
|
||||
query.encoding == AUDIO_ENCODING_SLINEAR_LE))
|
||||
dsp_samplesize = 16;
|
||||
if (!dsp_samplesize && query.precision == 8 &&
|
||||
query.encoding == AUDIO_ENCODING_ULINEAR)
|
||||
dsp_samplesize = 8;
|
||||
}
|
||||
}
|
||||
if (dsp_samplesize == 0)
|
||||
realpos = 0;
|
||||
sio_onmove(hdl, movecb, NULL);
|
||||
|
||||
sio_initpar(&par);
|
||||
par.rate = f ? f : 22050;
|
||||
if (!sio_setpar(hdl, &par) || !sio_getpar(hdl, &par) || !sio_start(hdl) ||
|
||||
(par.bits != 8 && par.bits != 16))
|
||||
end_all("Sorry, no audio format supported by this binary is available");
|
||||
|
||||
if (!f)
|
||||
f = 22050;
|
||||
buf_max = par.appbufsz * par.bps * par.pchan;
|
||||
current_freq = par.rate;
|
||||
stereo = par.pchan == 2 ? 1 : 0;
|
||||
|
||||
{
|
||||
struct audio_info current;
|
||||
AUDIO_INITINFO(¤t);
|
||||
dsp_samplesize = par.bits;
|
||||
dsize = par.bps;
|
||||
buffer = malloc(buf_max);
|
||||
buffer16 = (short *)buffer;
|
||||
|
||||
switch(dsp_samplesize)
|
||||
{
|
||||
case 8:
|
||||
dsize = 1;
|
||||
current.play.encoding = AUDIO_ENCODING_ULINEAR;
|
||||
current.play.precision= 8;
|
||||
break;
|
||||
case 16:
|
||||
dsize = 2;
|
||||
current.play.encoding = AUDIO_ENCODING_SLINEAR;
|
||||
current.play.precision= 16;
|
||||
break;
|
||||
default:
|
||||
end_all("Error: unknown dsp_samplesize");
|
||||
}
|
||||
current.play.sample_rate = f;
|
||||
current.play.channels = s ? 2 : 1;
|
||||
|
||||
{
|
||||
int ok = ioctl(audio, AUDIO_SETINFO, ¤t);
|
||||
/* maybe we are trying some stunt our card can't do ?
|
||||
* Try lowering our expectations
|
||||
*/
|
||||
if (ok == -1 && current.play.channels == 2 && current.play.sample_rate > 22050)
|
||||
{
|
||||
current.play.sample_rate = 22050;
|
||||
ok = ioctl(audio, AUDIO_SETINFO, ¤t);
|
||||
}
|
||||
if (ok == -1 && current.play.channels == 2)
|
||||
{
|
||||
current.play.channels = 1;
|
||||
ok = ioctl(audio, AUDIO_SETINFO, ¤t);
|
||||
}
|
||||
while (ok == -1 && current.play.sample_rate > 8000)
|
||||
{
|
||||
current.play.sample_rate /= 2;
|
||||
ok = ioctl(audio, AUDIO_SETINFO, ¤t);
|
||||
}
|
||||
if (ok == -1)
|
||||
end_all("Can't find a suitable format");
|
||||
|
||||
if (ioctl(audio, AUDIO_GETINFO, ¤t) == -1)
|
||||
end_all("Error retrieving format");
|
||||
}
|
||||
|
||||
buf_max = current.blocksize;
|
||||
current_freq = current.play.sample_rate;
|
||||
stereo = current.play.channels == 2 ? 1 : 0;
|
||||
}
|
||||
|
||||
buffer = malloc(buf_max);
|
||||
buffer16 = (short *)buffer;
|
||||
idx = 0;
|
||||
samples_max = buf_max / dsize;
|
||||
idx = 0;
|
||||
samples_max = buf_max / dsize / par.pchan;
|
||||
set_watched_scalar(FREQUENCY, current_freq);
|
||||
total = 0;
|
||||
return current_freq;
|
||||
@ -139,12 +76,11 @@ unsigned long open_audio(unsigned long f, int s)
|
||||
/* synchronize stuff with audio output */
|
||||
LOCAL struct tagged
|
||||
{
|
||||
struct tagged *next; /* simply linked list */
|
||||
struct tagged *next; /* simply linked list */
|
||||
void (*f)(GENERIC p); /* function to call */
|
||||
void (*f2)(GENERIC p); /* function to call for flush */
|
||||
GENERIC p; /* and parameter */
|
||||
unsigned long when; /* number of bytes to let go before
|
||||
calling */
|
||||
GENERIC p; /* and parameter */
|
||||
unsigned long when; /* number of bytes to let go before calling */
|
||||
}
|
||||
*start, /* what still to output */
|
||||
*end; /* where to add new tags */
|
||||
@ -154,12 +90,9 @@ LOCAL struct tagged
|
||||
/* flush_tags: use tags that have gone by recently */
|
||||
LOCAL void flush_tags(void)
|
||||
{
|
||||
audio_offset_t off;
|
||||
if (audio != -1)
|
||||
ioctl(audio, AUDIO_GETOOFFS, &off);
|
||||
if (start)
|
||||
{
|
||||
while (start && start->when <= off.samples + ADVANCE_TAGS)
|
||||
while (start && start->when <= realpos + ADVANCE_TAGS)
|
||||
{
|
||||
struct tagged *tofree;
|
||||
|
||||
@ -189,7 +122,7 @@ void sync_audio(void (*function)(void *p), void (*f2)(void *p), void *parameter)
|
||||
{
|
||||
struct tagged *t;
|
||||
|
||||
if (audio != -1)
|
||||
if (hdl)
|
||||
{
|
||||
t = malloc(sizeof(struct tagged));
|
||||
if (!t)
|
||||
@ -224,7 +157,7 @@ LOCAL void actually_flush_buffer(void)
|
||||
if (idx)
|
||||
{
|
||||
total += idx * dsize;
|
||||
write(audio, buffer, dsize * idx);
|
||||
sio_write(hdl, buffer, dsize * idx);
|
||||
}
|
||||
idx = 0;
|
||||
}
|
||||
@ -258,7 +191,7 @@ void flush_buffer(void)
|
||||
void close_audio(void)
|
||||
{
|
||||
actually_flush_buffer();
|
||||
close(audio);
|
||||
sio_close(hdl);
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
@ -269,8 +202,6 @@ unsigned long update_frequency(void)
|
||||
|
||||
void discard_buffer(void)
|
||||
{
|
||||
if (audio)
|
||||
ioctl(audio, AUDIO_FLUSH, 0);
|
||||
remove_pending_tags();
|
||||
total = 0;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
@comment $OpenBSD: PLIST,v 1.9 2005/12/23 15:08:37 espie Exp $
|
||||
bin/randomize
|
||||
bin/tracker
|
||||
@comment $OpenBSD: PLIST,v 1.10 2010/06/30 11:50:51 jakemsr Exp $
|
||||
@bin bin/randomize
|
||||
@bin bin/tracker
|
||||
@info info/tracker.info
|
||||
lib/tracker/
|
||||
lib/tracker/compression_methods.sample
|
||||
|
Loading…
Reference in New Issue
Block a user