rework audio system to be able to call it from anywhere, rather than having to have access to the audio data.

This commit is contained in:
2025-06-27 12:39:04 +02:00
parent c4905f2da3
commit 21aca01cba
3 changed files with 95 additions and 83 deletions

View File

@@ -3,18 +3,31 @@
#include <SDL_audio.h>
#include <stdint.h>
#include "../util/types.h"
#define AUDIO_MAX 4 // maximum number of sound effects that are allowed to play at once
struct audiodata {
uint8_t* buf; // pointer to the audio buffer
uint32_t len; // length in bytes of the audio buffer
uint32_t ms; // length in miliseconds of the audio buffer
u8 const* buf; // pointer to the audio buffer
u32 len; // length in bytes of the audio buffer
u32 ms; // length in miliseconds of the audio buffer
};
typedef struct audiodata audiodata;
int audio_device_init(int, SDL_AudioFormat, uint8_t, uint16_t);
void audio_device_free(void);
void audio_play(audiodata const*);
enum audio_id {
AUDIO_ID_MUSIC,
AUDIO_ID_PLACE,
audiodata audio_wav_load(char const*);
void audio_wav_unload(audiodata*);
// leave at end, will contain count
AUDIO_ID_COUNT,
};
extern struct audiodata audio_dat[AUDIO_ID_COUNT];
/* loads the audio to be played, unless `AUDIO_MAX` has been reached, then this call will fail */
void audio_play(u32);
/* initialises the audio device, then loads the audio data */
int audio_init(int freq, SDL_AudioFormat fmt, u8 ch, u16 samples);
/* frees up resources held by the audio device and audio buffers */
void audio_free(void);