aboutsummaryrefslogtreecommitdiff
path: root/curses
diff options
context:
space:
mode:
authorTakamichi Horikawa <takamichiho@gmail.com>2017-01-07 13:34:52 +0900
committerTakamichi Horikawa <takamichiho@gmail.com>2017-01-07 13:34:52 +0900
commitae5025d801c7276404ff510a37a11c5dd5a68733 (patch)
tree9a1cf5e808632bfb0e3d170a3eecf6e7c5719add /curses
parent1f6d05a5da1e2a529dca60958b8ce99588aa5488 (diff)
use portaudio instead of SDL2
Diffstat (limited to 'curses')
-rw-r--r--curses/Makefile.am4
-rw-r--r--curses/configure.ac3
-rw-r--r--curses/main.c49
3 files changed, 30 insertions, 26 deletions
diff --git a/curses/Makefile.am b/curses/Makefile.am
index 340f926..ef1a134 100644
--- a/curses/Makefile.am
+++ b/curses/Makefile.am
@@ -14,5 +14,5 @@ fmpc_SOURCES=main.c \
$(FMDRIVER_SOURCES)
fmpc_CFLAGS=-Wall -Wextra -pedantic \
- -I.. $(SDL_CFLAGS) $(NCURSES_CFLAGS)
-fmpc_LDADD=$(SDL_LIBS) $(NCURSES_LIBS)
+ -I.. $(PORTAUDIO_CFLAGS) $(NCURSES_CFLAGS)
+fmpc_LDADD=$(PORTAUDIO_LIBS) $(NCURSES_LIBS)
diff --git a/curses/configure.ac b/curses/configure.ac
index 704d32e..fd8e0cc 100644
--- a/curses/configure.ac
+++ b/curses/configure.ac
@@ -2,7 +2,8 @@ AC_INIT([fmplayer], [0.1.0])
AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects])
AC_PROG_CC_C99
-AM_PATH_SDL2([2.0.5])
+dnl AM_PATH_SDL2([2.0.5])
+PKG_CHECK_MODULES([PORTAUDIO], [portaudio-2.0])
PKG_CHECK_MODULES([NCURSES], [ncursesw >= 6])
AC_CONFIG_FILES([Makefile])
diff --git a/curses/main.c b/curses/main.c
index cbde86a..1b97584 100644
--- a/curses/main.c
+++ b/curses/main.c
@@ -1,11 +1,12 @@
#include <curses.h>
#include <stdio.h>
+#include <string.h>
#include <stdint.h>
#include "libopna/opna.h"
#include "libopna/opnatimer.h"
#include "fmdriver/fmdriver.h"
#include "fmdriver/fmdriver_fmp.h"
-#include <SDL.h>
+#include <portaudio.h>
#include <stdlib.h>
#include <locale.h>
#include <iconv.h>
@@ -17,14 +18,18 @@ enum {
SRATE = 55467,
};
-static void sdl_callback(void *userdata, Uint8 *stream, int len) {
- SDL_memset(stream, 0, len);
+static int pastream_cb(const void *inptr, void *outptr, unsigned long frames,
+ const PaStreamCallbackTimeInfo *timeinfo,
+ PaStreamCallbackFlags statusFlags,
+ void *userdata) {
struct opna_timer *timer = (struct opna_timer *)userdata;
- int16_t *buf = (int16_t *)stream;
- unsigned samples = len/2/2;
- opna_timer_mix(timer, buf, samples);
+ int16_t *buf = (int16_t *)outptr;
+ memset(outptr, 0, sizeof(int16_t)*frames*2);
+ opna_timer_mix(timer, buf, frames);
+ return paContinue;
}
+
static void opna_writereg_libopna(struct fmdriver_work *work, unsigned addr, unsigned data) {
struct opna_timer *timer = (struct opna_timer *)work->opna;
opna_timer_writereg(timer, addr, data);
@@ -394,8 +399,8 @@ err:
}
int main(int argc, char **argv) {
- if (SDL_Init(SDL_INIT_AUDIO) != 0) {
- fprintf(stderr, "cannot initialize SDL\n");
+ if (Pa_Initialize() != paNoError) {
+ fprintf(stderr, "cannot initialize pulseaudio\n");
return 1;
}
if (argc != 2) {
@@ -451,21 +456,15 @@ int main(int argc, char **argv) {
bool pvi_loaded = loadpvi(&work, &fmp, argv[1]);
bool ppz_loaded = loadppzpvi(&work, &fmp, argv[1]);
- SDL_AudioSpec as = {0};
- as.freq = SRATE;
- as.format = AUDIO_S16SYS;
- as.channels = 2;
- as.callback = sdl_callback;
- as.userdata = &timer;
- as.samples = 2048;
-
- SDL_AudioDeviceID ad = SDL_OpenAudioDevice(0, 0, &as, 0, 0);
- if (!ad) {
+ PaError pe;
+ PaStream *ps;
+ pe = Pa_OpenDefaultStream(&ps, 0, 2, paInt16, SRATE, 0,
+ pastream_cb, &timer);
+ if (pe != paNoError) {
fprintf(stderr, "cannot open audio device\n");
return 1;
}
- SDL_PauseAudioDevice(ad, 0);
-
+ Pa_StartStream(ps);
setlocale(LC_CTYPE, "");
initscr();
@@ -523,7 +522,7 @@ int main(int argc, char **argv) {
}
int cont = 1;
- int pause = 0;
+ bool pause = 0;
while (cont) {
switch (getch()) {
case 'q':
@@ -531,7 +530,11 @@ int main(int argc, char **argv) {
break;
case 'p':
pause = !pause;
- SDL_PauseAudioDevice(ad, pause);
+ if (pause) {
+ Pa_StopStream(ps);
+ } else {
+ Pa_StartStream(ps);
+ }
break;
case ERR:
update(&ppz8, &opna, &fmp);
@@ -540,7 +543,7 @@ int main(int argc, char **argv) {
}
endwin();
- SDL_Quit();
+ Pa_Terminate();
return 0;
}