#include <string.h>
#include <stdlib.h>
-#include "text.h"
#include "config.h"
#include "audio.h"
+#include "common.h"
+#include "fs.h"
+#include "fs_ov.h"
/*---------------------------------------------------------------------------*/
static struct voice *voices = NULL;
static short *buffer = NULL;
+static ov_callbacks callbacks = {
+ fs_ov_read, fs_ov_seek, fs_ov_close, fs_ov_tell
+};
+
/*---------------------------------------------------------------------------*/
#define MIX(d, s) { \
static struct voice *voice_init(const char *filename, float a)
{
struct voice *V;
- FILE *fp;
+ fs_file fp;
/* Allocate and initialize a new voice structure. */
{
/* Note the name. */
- V->name = (char *) malloc(strlen(filename) + 1);
-
- strcpy(V->name, filename);
+ V->name = strdup(filename);
/* Attempt to open the named Ogg stream. */
- if ((fp = fopen(config_data(filename), FMODE_RB)))
+ if ((fp = fs_open(filename, "r")))
{
- if (ov_open(fp, &V->vf, NULL, 0) == 0)
+ if (ov_open_callbacks(fp, &V->vf, NULL, 0, callbacks) == 0)
{
vorbis_info *info = ov_info(&V->vf, -1);
/* The file will be closed when the Ogg is cleared. */
}
- else fclose(fp);
+ else fs_close(fp);
}
}
return V;
/* If we're already playing this sound, preempt the running copy. */
- for (V = voices; V; V = V->next)
- if (strcmp(V->name, filename) == 0)
- {
- ov_raw_seek(&V->vf, 0);
+ SDL_LockAudio();
+ {
+ for (V = voices; V; V = V->next)
+ if (strcmp(V->name, filename) == 0)
+ {
+ ov_raw_seek(&V->vf, 0);
- V->amp = a;
+ V->amp = a;
- if (V->amp > 1.0) V->amp = 1.0;
- if (V->amp < 0.0) V->amp = 0.0;
+ if (V->amp > 1.0) V->amp = 1.0;
+ if (V->amp < 0.0) V->amp = 0.0;
- return;
- }
+ SDL_UnlockAudio();
+ return;
+ }
+ }
+ SDL_UnlockAudio();
/* Create a new voice structure. */
audio_music_fade_out(t);
audio_music_queue(filename, t);
}
- else audio_music_fade_in(t);
+ else
+ {
+ /*
+ * We're fading to the current track. Chances are,
+ * whatever track is still in the queue, we don't want to
+ * hear it anymore.
+ */
+
+ if (queue)
+ {
+ voice_free(queue);
+ queue = NULL;
+ }
+
+ audio_music_fade_in(t);
+ }
}
else
{