Skip to content

Commit

Permalink
Merge pull request #2 from grejppi/master
Browse files Browse the repository at this point in the history
Pulseaudio plugout
  • Loading branch information
ranma committed Jul 15, 2015
2 parents 4076a79 + 3fd0aa1 commit ec7cfb3
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 4 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ endif
ifeq ($(plugout_midi),yes)
objs_gbsplay += plugout_midi.o
endif
ifeq ($(plugout_pulse),yes)
objs_gbsplay += plugout_pulse.o
GBSPLAYLDFLAGS += -lpulse-simple -lpulse
endif

# install contrib files?
ifeq ($(build_contrib),yes)
Expand Down
11 changes: 10 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -501,12 +501,13 @@ Output Plugins:
--disable-alsa omit ALSA sound output plugin
--disable-midi omit MIDI file writer plugin
--disable-nas omit NAS sound output plugin
--disable-pulse omit PulseAudio sound output plugin
--disable-stdout omit stdout file writer plugin
EOF
exit $1
}

OPTS="build_contrib build_test build_xmmsplugin use_i18n use_sharedlibgbs use_regparm use_ssp use_debug use_stdout use_devdsp use_alsa use_nas use_midi"
OPTS="build_contrib build_test build_xmmsplugin use_i18n use_sharedlibgbs use_regparm use_ssp use_debug use_stdout use_devdsp use_alsa use_nas use_pulse use_midi"
for OPT in $OPTS; do
eval "${OPT}="
done
Expand Down Expand Up @@ -633,6 +634,11 @@ if [ "$use_alsa" != no ]; then
use_alsa=$have_alsa_asoundlib_h
fi

if [ "$use_pulse" != no ]; then
check_include pulse/simple.h
use_pulse=$have_pulse_simple_h
fi

if [ "$use_nas" != no ]; then
check_include audio/audiolib.h "/usr/X11R6/include"
retval1=$?
Expand Down Expand Up @@ -808,6 +814,7 @@ setdefault use_debug no

setdefault use_midi yes
setdefault use_stdout yes
setdefault use_pulse yes

printoptional modules build
printoptional features use
Expand Down Expand Up @@ -865,6 +872,7 @@ __EOF__
echo plugout_alsa := $use_alsa
echo plugout_midi := $use_midi
echo plugout_nas := $use_nas
echo plugout_pulse := $use_pulse
echo plugout_stdout := $use_stdout
) > config.mk

Expand All @@ -878,6 +886,7 @@ __EOF__
plugout_x ALSA
plugout_x MIDI
plugout_x NAS
plugout_x PULSE
plugout_x STDOUT
use_x I18N
use_x REGPARM
Expand Down
6 changes: 3 additions & 3 deletions gbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ regparm long gbs_step(struct gbs *gbs, long time_to_work)

regparm void gbs_printinfo(struct gbs *gbs, long verbose)
{
printf(_("GBSVersion: %ld\n"
printf(_("GBSVersion: %u\n"
"Title: \"%s\"\n"
"Author: \"%s\"\n"
"Copyright: \"%s\"\n"
Expand All @@ -200,8 +200,8 @@ regparm void gbs_printinfo(struct gbs *gbs, long verbose)
"Stack pointer: 0x%04x\n"
"File size: 0x%08x\n"
"ROM size: 0x%08lx (%ld banks)\n"
"Subsongs: %ld\n"
"Default subsong: %ld\n"),
"Subsongs: %u\n"
"Default subsong: %u\n"),
gbs->version,
gbs->title,
gbs->author,
Expand Down
6 changes: 6 additions & 0 deletions plugout.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ extern const struct output_plugin plugout_alsa;
#ifdef PLUGOUT_NAS
extern const struct output_plugin plugout_nas;
#endif
#ifdef PLUGOUT_PULSE
extern const struct output_plugin plugout_pulse;
#endif
#ifdef PLUGOUT_STDOUT
extern const struct output_plugin plugout_stdout;
#endif
Expand All @@ -45,6 +48,9 @@ static output_plugin_const_t plugouts[] = {
#ifdef PLUGOUT_STDOUT
&plugout_stdout,
#endif
#ifdef PLUGOUT_PULSE
&plugout_pulse,
#endif
#ifdef PLUGOUT_MIDI
&plugout_midi,
#endif
Expand Down
63 changes: 63 additions & 0 deletions plugout_pulse.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* gbsplay is a Gameboy sound player
*
* 2006 (C) by Tobias Diedrich <ranma+gbsplay@tdiedrich.de>
*
* Licensed under GNU GPL.
*/

#include "common.h"

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>

#include <pulse/error.h>
#include <pulse/simple.h>

#include "plugout.h"

pa_simple *pulse_handle;
pa_sample_spec pulse_spec;

static long regparm pulse_open(enum plugout_endian endian, long rate)
{
int err;

switch (endian) {
case PLUGOUT_ENDIAN_BIG: pulse_spec.format = PA_SAMPLE_S16BE; break;
case PLUGOUT_ENDIAN_LITTLE: pulse_spec.format = PA_SAMPLE_S16LE; break;
case PLUGOUT_ENDIAN_NATIVE: pulse_spec.format = PA_SAMPLE_S16NE; break;
}
pulse_spec.rate = rate;
pulse_spec.channels = 2;

pulse_handle = pa_simple_new(NULL, "gbsplay", PA_STREAM_PLAYBACK, NULL, "gbsplay", &pulse_spec, NULL, NULL, &err);
if (!pulse_handle) {
fprintf(stderr, "pulse: %s\n", pa_strerror(err));
return -1;
}

return 0;
}

static ssize_t regparm pulse_write(const void *buf, size_t count)
{
return pa_simple_write(pulse_handle, buf, count, NULL);
}

static void regparm pulse_close()
{
pa_simple_free(pulse_handle);
}

const struct output_plugin plugout_pulse = {
.name = "pulse",
.description = "PulseAudio sound driver",
.open = pulse_open,
.write = pulse_write,
.close = pulse_close,
};

0 comments on commit ec7cfb3

Please sign in to comment.