townengine/src/twn_audio_c.h

61 lines
1.0 KiB
C

#ifndef TWN_AUDIO_C_H
#define TWN_AUDIO_C_H
#include "twn_audio.h"
#include <SDL2/SDL_audio.h>
#define STB_VORBIS_HEADER_ONLY
#include <stb_vorbis.c>
#include <xm.h>
#include <stdbool.h>
#include <stdint.h>
#define AUDIO_FREQUENCY 48000
typedef enum AudioFileType {
AUDIO_FILE_TYPE_OGG,
AUDIO_FILE_TYPE_XM,
AUDIO_FILE_TYPE_COUNT,
AUDIO_FILE_TYPE_UNKNOWN,
} AudioFileType;
union AudioContext {
struct {
stb_vorbis *handle;
unsigned char *data;
int frequency;
uint8_t channel_count;
} vorbis;
struct {
xm_context_t *handle;
} xm;
};
typedef struct AudioChannel {
AudioFileType file_type;
union AudioContext context; /* interpreted by `file_type` value */
const char *path;
const char *name;
bool repeat;
float volume;
float panning;
} AudioChannel;
typedef struct AudioChannelItem {
char *key;
struct AudioChannel value;
} AudioChannelItem;
void audio_callback(void *userdata, uint8_t *stream, int len);
#endif