townengine/src/twn_audio_c.h

56 lines
973 B
C
Raw Normal View History

#ifndef TWN_AUDIO_C_H
#define TWN_AUDIO_C_H
2024-07-08 06:46:12 +00:00
#include "twn_audio.h"
2024-07-08 06:46:12 +00:00
#include <SDL2/SDL_audio.h>
#define STB_VORBIS_HEADER_ONLY
#include <stb_vorbis.c>
2024-07-08 13:58:23 +00:00
#include <xm.h>
2024-07-08 06:46:12 +00:00
#include <stdbool.h>
#include <stdint.h>
typedef enum AudioFileType {
AUDIO_FILE_TYPE_OGG,
AUDIO_FILE_TYPE_XM,
AUDIO_FILE_TYPE_COUNT,
AUDIO_FILE_TYPE_UNKNOWN,
} AudioFileType;
2024-07-08 06:46:12 +00:00
union AudioContext {
2024-07-08 06:46:12 +00:00
struct {
stb_vorbis *handle;
unsigned char *data;
int frequency;
uint8_t channel_count;
} vorbis;
2024-07-08 13:58:23 +00:00
struct {
xm_context_t *handle;
} xm;
2024-07-08 06:46:12 +00:00
};
typedef struct AudioChannel {
PlayAudioArgs args;
AudioFileType file_type;
union AudioContext context; /* interpreted by `file_type` value */
2024-07-08 06:46:12 +00:00
const char *path;
2024-07-08 15:22:40 +00:00
const char *name;
} AudioChannel;
2024-07-08 06:46:12 +00:00
typedef struct AudioChannelItem {
2024-07-08 06:46:12 +00:00
char *key;
struct AudioChannel value;
} AudioChannelItem;
2024-07-08 06:46:12 +00:00
void audio_callback(void *userdata, uint8_t *stream, int len);
#endif