2024-09-16 06:07:01 +00:00
|
|
|
#ifndef TWN_AUDIO_C_H
|
|
|
|
#define TWN_AUDIO_C_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>
|
|
|
|
|
|
|
|
|
2024-10-11 17:21:02 +00:00
|
|
|
#define AUDIO_FREQUENCY 48000
|
|
|
|
|
2025-01-13 16:56:20 +00:00
|
|
|
/* TODO: specify which PCM formats are usable with WAV */
|
|
|
|
/* TODO: specify limitations of libxm */
|
|
|
|
/* TODO: specify limitations of stb_vorbis */
|
2024-09-23 17:43:16 +00:00
|
|
|
typedef enum AudioFileType {
|
2024-10-01 09:59:01 +00:00
|
|
|
AUDIO_FILE_TYPE_OGG,
|
2025-01-13 16:56:20 +00:00
|
|
|
AUDIO_FILE_TYPE_WAV,
|
2024-10-01 09:59:01 +00:00
|
|
|
AUDIO_FILE_TYPE_XM,
|
|
|
|
AUDIO_FILE_TYPE_COUNT,
|
|
|
|
AUDIO_FILE_TYPE_UNKNOWN,
|
2024-09-23 17:43:16 +00:00
|
|
|
} AudioFileType;
|
2024-07-08 06:46:12 +00:00
|
|
|
|
|
|
|
|
2024-09-23 17:43:16 +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
|
|
|
|
2025-01-13 16:56:20 +00:00
|
|
|
struct {
|
|
|
|
void *samples;
|
|
|
|
SDL_AudioSpec spec;
|
|
|
|
size_t position;
|
|
|
|
} wav;
|
|
|
|
|
2024-07-08 13:58:23 +00:00
|
|
|
struct {
|
|
|
|
xm_context_t *handle;
|
|
|
|
} xm;
|
2024-07-08 06:46:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2024-09-23 17:43:16 +00:00
|
|
|
typedef struct AudioChannel {
|
|
|
|
AudioFileType file_type;
|
|
|
|
union AudioContext context; /* interpreted by `file_type` value */
|
2025-01-30 01:30:20 +00:00
|
|
|
char *path;
|
2024-10-07 12:21:44 +00:00
|
|
|
bool repeat;
|
|
|
|
float volume;
|
|
|
|
float panning;
|
2025-01-13 16:56:20 +00:00
|
|
|
bool finished;
|
2024-09-23 17:43:16 +00:00
|
|
|
} AudioChannel;
|
2024-07-08 06:46:12 +00:00
|
|
|
|
|
|
|
|
2024-09-23 17:43:16 +00:00
|
|
|
typedef struct AudioChannelItem {
|
2024-07-08 06:46:12 +00:00
|
|
|
char *key;
|
2024-09-23 17:43:16 +00:00
|
|
|
struct AudioChannel value;
|
|
|
|
} AudioChannelItem;
|
2024-07-08 06:46:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
void audio_callback(void *userdata, uint8_t *stream, int len);
|
|
|
|
|
|
|
|
#endif
|