mirror of
https://github.com/kichikuou/xsystem35-sdl2.git
synced 2026-09-22 22:48:08 +03:00
Add SDL audio support
This commit is contained in:
+28
-21
@@ -179,6 +179,26 @@ fi
|
||||
AC_SUBST(SRC_MENU)
|
||||
|
||||
|
||||
dnl
|
||||
dnl SDL
|
||||
dnl
|
||||
SRC_GRAPHDEV="xcore_draw.c xcore_video.c xcore_mode.c xcore_event.c xcore_cursor.c xcore_maskupdate.c image.c"
|
||||
AC_ARG_ENABLE(sdl,
|
||||
[ --enable-sdl SDL [default=no] ],,
|
||||
[ enable_sdl=no ])
|
||||
if test "x$enable_sdl" = xyes ; then
|
||||
AM_PATH_SDL2(2.0.0,have_sdl=yes,have_sdl=no)
|
||||
AC_CHECK_LIB(SDL,SDL_NumJoysticks,have_sdljoy=yes)
|
||||
fi
|
||||
if test "x$have_sdl" = xyes ; then
|
||||
AC_DEFINE(ENABLE_SDL,1,[define this if you use SDL])
|
||||
SDL=1
|
||||
SRC_GRAPHDEV="sdl_video.c sdl_mode.c sdl_draw.c sdl_event.c sdl_image.c sdl_cursor.c image.c"
|
||||
AC_SUBST(SDL)
|
||||
fi
|
||||
AC_SUBST(SRC_GRAPHDEV)
|
||||
|
||||
|
||||
dnl
|
||||
dnl audio check
|
||||
dnl
|
||||
@@ -316,7 +336,7 @@ dnl
|
||||
DEFAULT_PLAYMODE=
|
||||
AC_ARG_WITH(default-output,
|
||||
[ --with-default-output=<mode> Specify default output mode (optional):
|
||||
default|oss|alsa|esd|sun],
|
||||
default|oss|alsa|esd|sun|sdl],
|
||||
[ if test "$enable_audio" != no; then
|
||||
DEFAULT_PLAYMODE=$withval
|
||||
eval "enable_$DEFAULT_PLAYMODE=yes"
|
||||
@@ -334,6 +354,7 @@ case ".$DEFAULT_PLAYMODE" in
|
||||
.alsa) def_am=AUDIO_PCM_ALSA ;;
|
||||
.esd) def_am=AUDIO_PCM_ESD ;;
|
||||
.sun) def_am=AUDIO_PCM_SUN ;;
|
||||
.sdl) def_am=AUDIO_PCM_SDL ;;
|
||||
*) def_am= ;;
|
||||
esac
|
||||
AC_MSG_RESULT($def_am)
|
||||
@@ -359,6 +380,9 @@ fi
|
||||
if test "x$no_esd" != xyes; then
|
||||
SRC_AUDIO="$SRC_AUDIO audio_esd.c"
|
||||
fi
|
||||
if test "x$have_sdl" = xyes; then
|
||||
SRC_AUDIO="$SRC_AUDIO audio_sdl.c"
|
||||
fi
|
||||
AC_SUBST(SRC_AUDIO)
|
||||
|
||||
dnl
|
||||
@@ -565,26 +589,6 @@ dnl
|
||||
AC_ARG_WITH(cachesize,[ --with-cachesize=# General Cache size (MB)],
|
||||
AC_DEFINE_UNQUOTED(CACHE_TOTALSIZE,$withval,[General Cache size (MB)]))
|
||||
|
||||
|
||||
dnl
|
||||
dnl SDL
|
||||
dnl
|
||||
SRC_GRAPHDEV="xcore_draw.c xcore_video.c xcore_mode.c xcore_event.c xcore_cursor.c xcore_maskupdate.c image.c"
|
||||
AC_ARG_ENABLE(sdl,
|
||||
[ --enable-sdl SDL [default=no] ],,
|
||||
[ enable_sdl=no ])
|
||||
if test "x$enable_sdl" = xyes ; then
|
||||
AM_PATH_SDL2(2.0.0,have_sdl=yes,have_sdl=no)
|
||||
AC_CHECK_LIB(SDL,SDL_NumJoysticks,have_sdljoy=yes)
|
||||
fi
|
||||
if test "x$have_sdl" = xyes ; then
|
||||
AC_DEFINE(ENABLE_SDL,1,[define this if you use SDL])
|
||||
SDL=1
|
||||
SRC_GRAPHDEV="sdl_video.c sdl_mode.c sdl_draw.c sdl_event.c sdl_image.c sdl_cursor.c image.c"
|
||||
AC_SUBST(SDL)
|
||||
fi
|
||||
AC_SUBST(SRC_GRAPHDEV)
|
||||
|
||||
dnl
|
||||
dnl joystick
|
||||
dnl
|
||||
@@ -767,6 +771,9 @@ fi
|
||||
if test "x$no_esd" != xyes; then
|
||||
echo " - esd (Enlightened Sound Daemon)"
|
||||
fi
|
||||
if test "x$have_sdl" = xyes; then
|
||||
echo " - sdl (SDL audio)"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
dnl CDROM
|
||||
|
||||
+10
-2
@@ -70,6 +70,10 @@ extern int esd_init(audiodevice_t *, char *);
|
||||
extern int sunaudio_init(audiodevice_t *dev, char *devaudio, char *devaudioctl);
|
||||
#endif /* ENABLE_SUNAUDIO */
|
||||
|
||||
#ifdef ENABLE_SDL
|
||||
extern int sdlaudio_init();
|
||||
#endif /* ENABLE_SDL */
|
||||
|
||||
int audio_init(audiodevice_t *a) {
|
||||
switch(mode) {
|
||||
case AUDIO_PCM_ANY:
|
||||
@@ -104,8 +108,8 @@ int audio_init(audiodevice_t *a) {
|
||||
#endif
|
||||
#ifdef ENABLE_SDL
|
||||
case AUDIO_PCM_SDL:
|
||||
// if (sdlaudio_initilize(a) == 0) break;
|
||||
// if (audiomode_strict) break;
|
||||
if (sdlaudio_init(a) == 0) break;
|
||||
if (mode_onlyone) break;
|
||||
#endif
|
||||
#ifdef ENABLE_ARTS
|
||||
case AUDIO_PCM_ARTS:
|
||||
@@ -132,6 +136,10 @@ void audio_set_output_device(char c) {
|
||||
/* ALSA */
|
||||
mode = AUDIO_PCM_ALSA;
|
||||
break;
|
||||
case 'd':
|
||||
/* SDL */
|
||||
mode = AUDIO_PCM_SDL;
|
||||
break;
|
||||
case '0':
|
||||
/* no audio */
|
||||
mode = AUDIO_PCM_DMY;
|
||||
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* audio_sdl.c SDL audio lowlevel acess
|
||||
*
|
||||
* Copyright (C) 2017 <KichikuouChrome@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "portab.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <SDL.h>
|
||||
|
||||
#include "system.h"
|
||||
#include "audio.h"
|
||||
#include "music_pcm.h"
|
||||
|
||||
typedef struct {
|
||||
Uint8* stream;
|
||||
int len;
|
||||
} audio_sdl_t;
|
||||
|
||||
static void audio_callback(void* userdata, Uint8* stream, int len) {
|
||||
audio_sdl_t *asdl = (audio_sdl_t*)((audiodevice_t*)userdata)->data_pcm;
|
||||
asdl->stream = stream;
|
||||
asdl->len = len;
|
||||
muspcm_write2dev();
|
||||
memset(asdl->stream, 0, asdl->len);
|
||||
asdl->stream = NULL;
|
||||
asdl->len = 0;
|
||||
}
|
||||
|
||||
static int audio_open(audiodevice_t *dev, chanfmt_t fmt) {
|
||||
SDL_AudioSpec spec;
|
||||
memset(&spec, 0, sizeof(spec));
|
||||
spec.freq = fmt.rate;
|
||||
spec.format = fmt.bit == 16 ? AUDIO_S16 : AUDIO_U8;
|
||||
spec.channels = fmt.ch;
|
||||
spec.samples = 4096;
|
||||
spec.callback = audio_callback;
|
||||
spec.userdata = dev;
|
||||
if (SDL_OpenAudio(&spec, NULL) < 0) {
|
||||
WARNING("SDL_OpenAudio failed\n");
|
||||
return NG;
|
||||
}
|
||||
dev->buf.len = spec.samples * (fmt.bit / 8) * fmt.ch;
|
||||
SDL_PauseAudio(0);
|
||||
return OK;
|
||||
}
|
||||
|
||||
static int audio_close(audiodevice_t *dev) {
|
||||
SDL_CloseAudio();
|
||||
return OK;
|
||||
}
|
||||
|
||||
static int audio_write(audiodevice_t *dev, unsigned char *buf, int cnt) {
|
||||
audio_sdl_t *asdl = (audio_sdl_t*)dev->data_pcm;
|
||||
if (cnt > asdl->len)
|
||||
cnt = asdl->len;
|
||||
memcpy(asdl->stream, buf, cnt);
|
||||
asdl->stream += cnt;
|
||||
asdl->len -= cnt;
|
||||
return cnt;
|
||||
}
|
||||
|
||||
static void mixer_set_level(audiodevice_t *dev, int ch, int level) {
|
||||
}
|
||||
|
||||
static int mixer_get_level(audiodevice_t *dev, int ch) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sdlaudio_exit(audiodevice_t *dev) {
|
||||
if (dev == NULL) return OK;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
int sdlaudio_init(audiodevice_t *dev) {
|
||||
if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0)
|
||||
return NG;
|
||||
|
||||
audio_sdl_t *asdl = calloc(1, sizeof(audio_sdl_t));
|
||||
dev->data_pcm = asdl;
|
||||
|
||||
dev->id = AUDIO_PCM_SDL;
|
||||
dev->fd = -1;
|
||||
dev->open = audio_open;
|
||||
dev->close = audio_close;
|
||||
dev->write = audio_write;
|
||||
dev->mix_set = mixer_set_level;
|
||||
dev->mix_get = mixer_get_level;
|
||||
dev->exit = sdlaudio_exit;
|
||||
|
||||
NOTICE("SDL audio initilize OK\n");
|
||||
return OK;
|
||||
}
|
||||
Reference in New Issue
Block a user