aboutsummaryrefslogtreecommitdiff
path: root/sdl
diff options
context:
space:
mode:
Diffstat (limited to 'sdl')
-rw-r--r--sdl/main.c22
-rw-r--r--sdl/osx/Makefile2
-rw-r--r--sdl/unix/Makefile4
-rw-r--r--sdl/win/Makefile2
4 files changed, 27 insertions, 3 deletions
diff --git a/sdl/main.c b/sdl/main.c
index 410ed88..39ead1b 100644
--- a/sdl/main.c
+++ b/sdl/main.c
@@ -1,5 +1,6 @@
#include <SDL.h>
#include <stdbool.h>
+#include <stdatomic.h>
#include "pacc/pacc.h"
#include "fmdsp/fmdsp-pacc.h"
#include "libopna/opna.h"
@@ -7,6 +8,7 @@
#include "fmdriver/fmdriver.h"
#include "common/fmplayer_file.h"
#include "common/fmplayer_common.h"
+#include "fft/fft.h"
bool loadgl(void);
@@ -20,19 +22,29 @@ static struct {
struct opna_timer timer;
struct fmdriver_work work;
struct fmplayer_file *fmfile;
+ struct fmplayer_fft_data fftdata;
+ struct fmplayer_fft_input_data fftin;
const char *currpath;
SDL_Window *win;
SDL_AudioDeviceID adev;
struct ppz8 ppz8;
char adpcmram[OPNA_ADPCM_RAM_SIZE];
struct fmdsp_pacc *fp;
-} g;
+ atomic_flag fftdata_flag;
+} g = {
+ .fftdata_flag = ATOMIC_FLAG_INIT,
+};
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);
+ if (!atomic_flag_test_and_set_explicit(
+ &g.fftdata_flag, memory_order_acquire)) {
+ fft_write(&g.fftdata, buf, frames);
+ atomic_flag_clear_explicit(&g.fftdata_flag, memory_order_release);
+ }
}
static void openfile(const char *path) {
@@ -57,6 +69,7 @@ static void openfile(const char *path) {
int main(int argc, char **argv) {
if (__builtin_cpu_supports("sse2")) opna_ssg_sinc_calc_func = opna_ssg_sinc_calc_sse2;
+ fft_init_table();
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO)) {
SDL_Log("Cannot initialize SDL\n");
return 1;
@@ -140,7 +153,7 @@ int main(int argc, char **argv) {
SDL_Quit();
return 1;
}
- fmdsp_pacc_set(g.fp, &g.work, &g.opna);
+ fmdsp_pacc_set(g.fp, &g.work, &g.opna, &g.fftin);
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
@@ -206,6 +219,11 @@ int main(int argc, char **argv) {
}
}
}
+ if (!atomic_flag_test_and_set_explicit(
+ &g.fftdata_flag, memory_order_acquire)) {
+ memcpy(&g.fftin.fdata, &g.fftdata, sizeof(g.fftdata));
+ atomic_flag_clear_explicit(&g.fftdata_flag, memory_order_release);
+ }
fmdsp_pacc_render(g.fp);
SDL_GL_SwapWindow(g.win);
}
diff --git a/sdl/osx/Makefile b/sdl/osx/Makefile
index c2035fd..18ae005 100644
--- a/sdl/osx/Makefile
+++ b/sdl/osx/Makefile
@@ -4,6 +4,7 @@ vpath %.c ../../fmdsp
vpath %.c ../../libopna
vpath %.c ../../common
vpath %.c ../../fmdriver
+vpath %.c ../../fft
XCRUN:=xcrun --sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/
CC:=$(XCRUN) cc
OBJS:=main.o
@@ -12,6 +13,7 @@ OBJS+=fmdsp-pacc.o font_fmdsp_small.o fmdsp_platform_mach.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
+OBJS+=fft.o
TARGET:=fmplayersdl
CFLAGS:=-Wall -Wextra -O2 -g
CFLAGS+=-DPACC_GL_3
diff --git a/sdl/unix/Makefile b/sdl/unix/Makefile
index 9786031..ea22098 100644
--- a/sdl/unix/Makefile
+++ b/sdl/unix/Makefile
@@ -4,6 +4,7 @@ vpath %.c ../../fmdsp
vpath %.c ../../libopna
vpath %.c ../../common
vpath %.c ../../fmdriver
+vpath %.c ../../fft
SDLCONFIG:=sdl2-config
OBJS:=main.o
OBJS+=pacc-gl.o
@@ -11,6 +12,7 @@ OBJS+=fmdsp-pacc.o font_fmdsp_small.o fmdsp_platform_unix.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
+OBJS+=fft.o
TARGET:=fmplayersdl
CFLAGS:=-Wall -Wextra -O2 -g
@@ -19,7 +21,7 @@ CFLAGS+=-DPACC_GL_3
#CFLAGS+=-DPACC_GL_ES -DPACC_GL_3
CFLAGS+=-I.. -I../..
CFLAGS+=$(shell $(SDLCONFIG) --cflags)
-LIBS:=-lGL
+LIBS:=-lGL -lm
LIBS+=$(shell $(SDLCONFIG) --libs)
$(TARGET): $(OBJS)
diff --git a/sdl/win/Makefile b/sdl/win/Makefile
index e804dfc..0f63d19 100644
--- a/sdl/win/Makefile
+++ b/sdl/win/Makefile
@@ -4,6 +4,7 @@ vpath %.c ../../fmdsp
vpath %.c ../../libopna
vpath %.c ../../common
vpath %.c ../../fmdriver
+vpath %.c ../../fft
SDLCONFIG:=i686-w64-mingw32-sdl2-config
CC:=i686-w64-mingw32-gcc
OBJS:=main.o
@@ -12,6 +13,7 @@ OBJS+=fmdsp-pacc.o font_fmdsp_small.o fmdsp_platform_win.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
+OBJS+=fft.o
TARGET:=fmplayersdl.exe
CFLAGS:=-Wall -Wextra -O2