diff pwplib/snd-sdl.c @ 0:acb5694e93d9

Initial import.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 18 May 2010 04:25:44 +0300
parents
children e2f028bf775a
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pwplib/snd-sdl.c	Tue May 18 04:25:44 2010 +0300
@@ -0,0 +1,70 @@
+/*
+ * pwplib SDL (Simple Directmedia Layer) audio "driver"
+ * (C) Copyright 2010 ccr/TNSP^PWP <ccr@tnsp.org>
+ *
+ * This file and other changes are distributed under same
+ * license as pwplib itself.
+ */
+
+#include "config.h"
+
+#ifdef DRIVE_SDL
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <SDL.h>
+
+#include "pwplib.h"
+
+#define TIMERHZ 72
+
+
+extern void gb_sound(int, int, int, int);
+
+
+static void pwp_sdlaudio_fill(void *udata, Uint8 * buf, int len)
+{
+    pwplib.player();
+    gb_genwave(buf, len);
+}
+
+static void pwp_sdlaudio_loopflush(void)
+{
+    /* Dummy */
+}
+
+static void pwp_sdlaudio_close(void)
+{
+    SDL_CloseAudio();
+}
+
+int pwp_sdlaudio_init()
+{
+    SDL_AudioSpec fmt;
+
+    fmt.freq = 44100;
+    fmt.format = AUDIO_U8;
+    fmt.channels = 1;
+    fmt.samples = fmt.freq / TIMERHZ;
+    fmt.callback = pwp_sdlaudio_fill;
+
+    if (SDL_OpenAudio(&fmt, NULL) < 0)
+    {
+        pwpwrite("* SDL: Could not get desired audio format.\n");
+        return 0;
+    }
+
+    pwpwrite("* SDL sound\n");
+
+    pwplib.sound = gb_sound;
+    pwplib.loopflush = pwp_sdlaudio_loopflush;
+    gb_init(fmt.freq);
+
+    SDL_PauseAudio(0);
+
+    pwp_regdestr(pwp_sdlaudio_close);
+
+    return 1;
+}
+#endif