medfall

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

audio.h (1080B)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef _AUDIO_H_
#define _AUDIO_H_

#include <glm/glm.hpp>

#include "intrinsics.h"
#include "assets.h"
#include "memory_arena.h"

union Volume {
	struct {
		u16 left;
		u16 right;
	};

	u32 combined;
};

// TODO: cache friendly layout
struct SoundState {
	SoundData data;

	// TODO: make this signed so we can delay sounds?
	u32 num_played_samples;
	volatile bool stopped;
	bool loop;

	Volume volume;

	bool positional;
	glm::vec3 position;

	u32 generation;

	SoundState * volatile next;
	SoundState * volatile next_free;
	volatile bool freelisted;
};

struct Sound {
	SoundState * state;
	u32 generation;
};

struct AudioOutputBuffer {
	// num_channels?
	u32 sample_rate;
	u32 num_samples;

	s16 * samples;
};

struct PlaySoundOptions {
	bool loop;
};

void audio_init( MemoryArena * arena );

Sound audio_play_sound( MemoryArena * arena, SoundData data, bool loop = false );
void audio_stop_sound( Sound sound );

void audio_set_volume( Sound sound, float left, float right = -1.0f );

void audio_mix( MemoryArena * arena, AudioOutputBuffer * buffer );

#endif // _AUDIO_H_