Distance-based sound effects with stereo panning for explosions, impacts, and pickups. Spacecraft entity with full state machine (fly-in, land, take off, fly-out), engine/synth sound loops, thruster particles, and PNG spritesheet. Moon level intro defers player spawn until ship lands. Also untrack build/ objects that were committed by mistake.
45 lines
1.5 KiB
C
45 lines
1.5 KiB
C
#ifndef JNR_AUDIO_H
|
|
#define JNR_AUDIO_H
|
|
|
|
#include <stdbool.h>
|
|
#include "util/vec2.h"
|
|
|
|
typedef struct Sound {
|
|
void *chunk; /* Mix_Chunk* */
|
|
} Sound;
|
|
|
|
typedef struct Music {
|
|
void *music; /* Mix_Music* */
|
|
} Music;
|
|
|
|
bool audio_init(void);
|
|
Sound audio_load_sound(const char *path);
|
|
Music audio_load_music(const char *path);
|
|
void audio_play_sound(Sound s, int volume); /* 0-128, fire and forget */
|
|
void audio_play_music(Music m, bool loop);
|
|
void audio_stop_music(void);
|
|
void audio_free_music(Music *m);
|
|
void audio_set_music_volume(int volume); /* 0-128 */
|
|
void audio_shutdown(void);
|
|
|
|
/* ── Looping sounds ────────────────────────────── */
|
|
|
|
/* Play a sound on loop, returns the channel number (or -1 on failure).
|
|
* Use audio_stop_channel() to stop it later. */
|
|
int audio_play_sound_loop(Sound s, int volume);
|
|
|
|
/* Stop a specific channel (from audio_play_sound_loop). No-op if ch < 0. */
|
|
void audio_stop_channel(int ch);
|
|
|
|
/* ── Positional / spatial audio ────────────────── */
|
|
|
|
/* Set the listener position (call once per frame, typically from camera center) */
|
|
void audio_set_listener(Vec2 pos);
|
|
|
|
/* Play a sound at a world position. Volume is attenuated by distance from the
|
|
* listener and stereo-panned based on horizontal offset. Sounds beyond
|
|
* max_dist are inaudible. Pass max_dist <= 0 for a sensible default. */
|
|
void audio_play_sound_at(Sound s, int base_volume, Vec2 world_pos, float max_dist);
|
|
|
|
#endif /* JNR_AUDIO_H */
|