aboutsummaryrefslogtreecommitdiff
path: root/sdl
diff options
context:
space:
mode:
authorTakamichi Horikawa <takamichiho@gmail.com>2017-09-08 23:26:30 +0900
committerTakamichi Horikawa <takamichiho@gmail.com>2017-09-08 23:26:30 +0900
commit694da2ee4f6bf7dd8e5f592f9d9ecf0c5a7ceb24 (patch)
tree6dca19b69324008e67b4614efcee6fd568747689 /sdl
parent50c75c12597b230cec4d7a29559cde263025eeb2 (diff)
sdl: for testing pacc
Diffstat (limited to 'sdl')
-rw-r--r--sdl/main.c170
-rw-r--r--sdl/pacc-gl-inc.h51
-rw-r--r--sdl/unix/Makefile30
-rw-r--r--sdl/win/Makefile34
4 files changed, 285 insertions, 0 deletions
diff --git a/sdl/main.c b/sdl/main.c
new file mode 100644
index 0000000..43053a3
--- /dev/null
+++ b/sdl/main.c
@@ -0,0 +1,170 @@
+#include <SDL.h>
+#include <stdbool.h>
+#include "pacc/pacc.h"
+#include "fmdsp/fmdsp-pacc.h"
+#include "libopna/opna.h"
+#include "libopna/opnatimer.h"
+#include "fmdriver/fmdriver.h"
+#include "common/fmplayer_file.h"
+#include "common/fmplayer_common.h"
+
+bool loadgl(void);
+
+enum {
+ SRATE = 55467,
+ BUFLEN = 1024,
+};
+
+static struct {
+ struct opna opna;
+ struct opna_timer timer;
+ struct fmdriver_work work;
+ struct fmplayer_file *fmfile;
+ const char *currpath;
+ SDL_Window *win;
+ SDL_AudioDeviceID adev;
+ struct ppz8 ppz8;
+ char adpcmram[OPNA_ADPCM_RAM_SIZE];
+ struct fmdsp_pacc *fp;
+} g;
+
+static void audiocb(void *ptr, Uint8 *bufptr, int len) {
+ int frames = len / (sizeof(int16_t)*2);
+ int16_t *buf = (int16_t *)bufptr;
+ memset(buf, 0, len);
+ opna_timer_mix(&g.timer, buf, frames);
+}
+
+static void openfile(const char *path) {
+ enum fmplayer_file_error error;
+ struct fmplayer_file *file = fmplayer_file_alloc(path, &error);
+ if (!file) {
+ SDL_ShowSimpleMessageBox(
+ SDL_MESSAGEBOX_ERROR,
+ "cannot open file",
+ fmplayer_file_strerror(error),
+ g.win);
+ return;
+ }
+ SDL_LockAudioDevice(g.adev);
+ fmplayer_file_free(g.fmfile);
+ g.fmfile = file;
+ fmplayer_init_work_opna(&g.work, &g.ppz8, &g.opna, &g.timer, &g.adpcmram);
+ fmplayer_file_load(&g.work, g.fmfile, 1);
+ fmdsp_pacc_set(g.fp, &g.work, &g.opna);
+ SDL_UnlockAudioDevice(g.adev);
+ SDL_PauseAudioDevice(g.adev, 0);
+}
+
+int main(int argc, char **argv) {
+ if (__builtin_cpu_supports("sse2")) opna_ssg_sinc_calc_func = opna_ssg_sinc_calc_sse2;
+ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO)) {
+ SDL_Log("Cannot initialize SDL\n");
+ return 1;
+ }
+
+ SDL_AudioSpec aspec = {
+ .freq = SRATE,
+ .format = AUDIO_S16SYS,
+ .channels = 2,
+ .samples = BUFLEN,
+ .callback = audiocb,
+ };
+ g.adev = SDL_OpenAudioDevice(0, 0, &aspec, 0, 0);
+ if (!g.adev) {
+ SDL_Log("Cannot open audio device\n");
+ SDL_Quit();
+ return 0;
+ }
+
+ SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
+#ifdef PACC_GL_ES
+#ifdef PACC_GL_3
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
+#else
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
+#endif
+#else // PACC_GL_ES
+#ifdef PACC_GL_3
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
+#else
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY);
+#endif
+#endif // PACC_GL_ES
+ g.win = SDL_CreateWindow(
+ "FMPlayer SDL",
+ SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
+ 640*2, 400*2,
+ SDL_WINDOW_OPENGL);
+ if (!g.win) {
+ SDL_Log("Cannot create window\n");
+ SDL_Quit();
+ return 1;
+ }
+
+ SDL_GLContext glctx = SDL_GL_CreateContext(g.win);
+ if (!glctx) {
+ SDL_Log("Cannot create OpenGL context\n");
+ SDL_Quit();
+ return 1;
+ }
+
+ SDL_GL_SetSwapInterval(1);
+
+ if (!loadgl()) {
+ SDL_Log("Cannot load OpenGL functions\n");
+ SDL_Quit();
+ return 1;
+ }
+
+ struct pacc_vtable pacc;
+ struct pacc_ctx *pc = pacc_init_gl(640, 400, &pacc);
+ if (!pc) {
+ SDL_Log("Cannot initialize pacc\n");
+ SDL_Quit();
+ return 1;
+ }
+
+ g.fp = fmdsp_pacc_init(pc, &pacc);
+ if (!g.fp) {
+ SDL_Log("Cannot initialize fmdsp\n");
+ SDL_Quit();
+ return 1;
+ }
+
+ SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
+
+ SDL_Event e;
+ bool end = false;
+ while (!end) {
+ while (SDL_PollEvent(&e)) {
+ switch (e.type) {
+ case SDL_QUIT:
+ end = true;
+ break;
+ case SDL_DROPFILE:
+ openfile(e.drop.file);
+ SDL_free(e.drop.file);
+ break;
+ }
+ }
+ fmdsp_pacc_render(g.fp);
+ SDL_GL_SwapWindow(g.win);
+ }
+
+ fmdsp_pacc_release(g.fp);
+ pacc.pacc_delete(pc);
+
+ SDL_Quit();
+ return 0;
+}
diff --git a/sdl/pacc-gl-inc.h b/sdl/pacc-gl-inc.h
new file mode 100644
index 0000000..88e4aec
--- /dev/null
+++ b/sdl/pacc-gl-inc.h
@@ -0,0 +1,51 @@
+
+#ifdef PACC_GL_ES
+#ifdef PACC_GL_3
+#include <GLES3/gl3.h>
+#else
+#include <GLES2/gl2.h>
+#endif
+#else // PACC_GL_ES
+#ifdef PACC_GL_3
+#include <GL/glcorearb.h>
+#else
+#ifdef _WIN32
+#define PROC_NO_GL_1_1
+#include <GL/gl.h>
+#include <GL/glext.h>
+#else
+#define PROC_NO_GL_1_3
+#include <GL/gl.h>
+#endif
+#endif // PACC_GL_3
+#endif // PACC_GL_ES
+
+#ifdef PACC_GL_ES
+bool loadgl(void) {
+ return true;
+}
+#else // PACC_GL_ES
+#include <SDL.h>
+#define PROC(N, n) static PFNGL##N##PROC gl##n;
+#include "pacc/pacc-gl-procs.inc"
+#undef PROC
+#define PROC(N, n) \
+ gl##n = SDL_GL_GetProcAddress("gl" #n);\
+ if (!gl##n) {\
+ SDL_Log("Cannot load GL function \"gl" #n "\"\n");\
+ return false;\
+ }
+
+bool loadgl(void) {
+#include "pacc/pacc-gl-procs.inc"
+ return true;
+}
+#undef PROC
+#endif // PACC_GL_ES
+
+#ifdef PROC_NO_GL_1_1
+#undef PROC_NO_GL_1_1
+#endif
+#ifdef PROC_NO_GL_1_3
+#undef PROC_NO_GL_1_3
+#endif
diff --git a/sdl/unix/Makefile b/sdl/unix/Makefile
new file mode 100644
index 0000000..686943f
--- /dev/null
+++ b/sdl/unix/Makefile
@@ -0,0 +1,30 @@
+vpath %.c ..
+vpath %.c ../../pacc
+vpath %.c ../../fmdsp
+vpath %.c ../../libopna
+vpath %.c ../../common
+vpath %.c ../../fmdriver
+SDLCONFIG:=sdl2-config
+OBJS:=main.o
+OBJS+=pacc-gl.o
+OBJS+=fmdsp-pacc.o font_fmdsp_small.o
+OBJS+=opna.o opnafm.o opnassg.o opnadrum.o opnaadpcm.o opnatimer.o opnassg-sinc-c.o opnassg-sinc-sse2.o
+OBJS+=fmdriver_pmd.o fmdriver_fmp.o ppz8.o fmdriver_common.o
+OBJS+=fmplayer_file.o fmplayer_work_opna.o fmplayer_file_unix.o fmplayer_drumrom_unix.o
+TARGET:=fmplayersdl
+
+CFLAGS:=-Wall -Wextra -O2 -g
+CFLAGS+=-DPACC_GL_3
+#CFLAGS+=-DPACC_GL_ES
+#CFLAGS+=-DPACC_GL_ES -DPACC_GL_3
+CFLAGS+=-I.. -I../..
+CFLAGS+=$(shell $(SDLCONFIG) --cflags)
+LIBS:=-lGL
+LIBS+=$(shell $(SDLCONFIG) --libs)
+
+$(TARGET): $(OBJS)
+ $(CC) -o $@ $^ $(LIBS)
+
+clean:
+ rm -f $(TARGET) $(OBJS)
+
diff --git a/sdl/win/Makefile b/sdl/win/Makefile
new file mode 100644
index 0000000..587bac8
--- /dev/null
+++ b/sdl/win/Makefile
@@ -0,0 +1,34 @@
+vpath %.c ..
+vpath %.c ../../pacc
+vpath %.c ../../fmdsp
+vpath %.c ../../libopna
+vpath %.c ../../common
+vpath %.c ../../fmdriver
+SDLCONFIG:=i686-w64-mingw32-sdl2-config
+CC:=i686-w64-mingw32-gcc
+OBJS:=main.o
+OBJS+=pacc-gl.o
+OBJS+=fmdsp-pacc.o font_fmdsp_small.o
+OBJS+=opna.o opnafm.o opnassg.o opnadrum.o opnaadpcm.o opnatimer.o opnassg-sinc-c.o opnassg-sinc-sse2.o
+OBJS+=fmdriver_pmd.o fmdriver_fmp.o ppz8.o fmdriver_common.o
+OBJS+=fmplayer_file.o fmplayer_work_opna.o fmplayer_file_win.o fmplayer_drumrom_win.o
+TARGET:=fmplayersdl.exe
+
+CFLAGS:=-Wall -Wextra -O2
+CFLAGS+=-DFMPLAYER_FILE_WIN_UTF8
+#CFLAGS+=-DPACC_GL_3
+#CFLAGS+=-DPACC_GL_ES
+#CFLAGS+=-DPACC_GL_ES -DPACC_GL_3
+CFLAGS+=-I.. -I../..
+CFLAGS+=$(shell $(SDLCONFIG) --cflags)
+LIBS:=-lshlwapi
+LIBS+=-static $(shell $(SDLCONFIG) --static-libs) -lopengl32
+
+$(TARGET): $(OBJS)
+ $(CC) -o $@ $^ $(LIBS)
+
+clean:
+ rm -f $(TARGET) $(OBJS)
+
+opnassg-sinc-sse2.o: opnassg-sinc-sse2.c
+ $(CC) -c $< $(CFLAGS) -msse2