* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA
*/
-#include "stdafx.h"
-
-#include "externals.h"
+#include <stdlib.h>
#include <SDL.h>
+#include "out.h"
#define BUFFER_SIZE 22050
}
}
-void SetupSound(void) {
+static int sdl_init(void) {
SDL_AudioSpec spec;
- if (pSndBuffer != NULL) return;
+ if (pSndBuffer != NULL) return -1;
InitSDL();
if (SDL_OpenAudio(&spec, NULL) < 0) {
DestroySDL();
- return;
+ return -1;
}
iBufSize = BUFFER_SIZE;
pSndBuffer = (short *)malloc(iBufSize * sizeof(short));
if (pSndBuffer == NULL) {
SDL_CloseAudio();
- return;
+ return -1;
}
iReadPos = 0;
iWritePos = 0;
SDL_PauseAudio(0);
+ return 0;
}
-void RemoveSound(void) {
+static void sdl_finish(void) {
if (pSndBuffer == NULL) return;
SDL_CloseAudio();
pSndBuffer = NULL;
}
-unsigned long SoundGetBytesBuffered(void) {
+static int sdl_busy(void) {
int size;
- if (pSndBuffer == NULL) return SOUNDSIZE;
+ if (pSndBuffer == NULL) return 1;
size = iReadPos - iWritePos;
if (size <= 0) size += iBufSize;
- if (size < iBufSize / 2) return SOUNDSIZE;
+ if (size < iBufSize / 2) return 1;
return 0;
}
-void SoundFeedStreamData(unsigned char *pSound, long lBytes) {
+static void sdl_feed(void *pSound, int lBytes) {
short *p = (short *)pSound;
if (pSndBuffer == NULL) return;
lBytes -= sizeof(short);
}
}
+
+void out_register_sdl(struct out_driver *drv)
+{
+ drv->name = "sdl";
+ drv->init = sdl_init;
+ drv->finish = sdl_finish;
+ drv->busy = sdl_busy;
+ drv->feed = sdl_feed;
+}