Mario Kart 64
Loading...
Searching...
No Matches
HMAS.h
Go to the documentation of this file.
1#pragma once
2
3typedef int HMAS_AudioId;
4
11
18
23
24#ifdef __cplusplus
25
26#include <string>
27#include <vector>
28#include <cstdint>
29#include <unordered_map>
30#include "audio/miniaudio.h"
31
32struct HMAS_Loop {
33 int64_t start;
34 int64_t end;
35};
36
37struct HMAS_Info {
38 HMAS_Loop loop = { -1, -1 };
39 std::string name;
40 std::string author;
41 std::string date;
42};
43
44struct HMAS_Sample {
45 ma_sound sound;
46 ma_decoder decoder;
47
48 HMAS_Info info;
49};
50
51struct HMAS_Effect {
52 HMAS_EffectType type;
53 HMAS_EffectTransition transition;
54 uint32_t numFrames;
55 float target;
56};
57
58struct HMAS_ChannelInfo {
59 ma_sound* sound;
60
61 uint64_t cursor;
62 float pitch;
63 float volume;
64
65 std::vector<HMAS_Effect> effects;
66};
67
68class HMAS {
69public:
70 HMAS();
71 ~HMAS();
72
73 void RegisterSound(HMAS_AudioId id, const std::string& filePath, HMAS_Info info = {});
74 void RegisterSound(HMAS_AudioId id, uint8_t* data, uint32_t size, HMAS_Info info = {});
75
76 void Play(HMAS_ChannelId channel, HMAS_AudioId id, bool loop = false);
77 void Stop(HMAS_ChannelId channel);
78 bool IsPlaying(HMAS_ChannelId channel);
79
80 void SetPitch(HMAS_ChannelId channel, float pitch);
81 void SetVolume(HMAS_ChannelId channel, float volume);
82 void SetPause(HMAS_ChannelId channel, bool pause);
83 void AddEffect(HMAS_ChannelId channel, HMAS_EffectType type, HMAS_EffectTransition transition, uint32_t frames, float target);
84
85 bool IsIDRegistered(HMAS_AudioId id);
86
87 void ProcessEffects();
88 void CreateBuffer(uint8_t* samples, uint32_t num_samples);
89
90 float Lerp(float a, float b, float t) {
91 return a + (b - a) * t;
92 }
93
94private:
95 ma_engine gAudioEngine;
96 HMAS_ChannelInfo gChannelSound[HMAS_MAX_CHANNELS] = { 0 };
97 std::unordered_map<HMAS_AudioId, HMAS_Sample> gRegistry;
98};
99
100extern "C" {
101#endif
102
103void HMAS_Play(enum HMAS_ChannelId channel, HMAS_AudioId id, bool loop);
104void HMAS_Stop(enum HMAS_ChannelId channel);
105bool HMAS_IsPlaying(enum HMAS_ChannelId channel);
106void HMAS_SetPitch(enum HMAS_ChannelId channel, float pitch);
107void HMAS_SetVolume(enum HMAS_ChannelId channel, float volume);
108void HMAS_SetPause(enum HMAS_ChannelId channel, bool pause);
109void HMAS_AddEffect(enum HMAS_ChannelId channel, enum HMAS_EffectType type, enum HMAS_EffectTransition transition, uint32_t frames, float target);
111
112#ifdef __cplusplus
113}
114#endif
void HMAS_Stop(enum HMAS_ChannelId channel)
Definition HMAS.cpp:242
void HMAS_SetVolume(enum HMAS_ChannelId channel, float volume)
Definition HMAS.cpp:254
HMAS_ChannelId
Definition HMAS.h:5
@ HMAS_SFX
Definition HMAS.h:7
@ HMAS_ENV
Definition HMAS.h:8
@ HMAS_MAX_CHANNELS
Definition HMAS.h:9
@ HMAS_MUSIC
Definition HMAS.h:6
void HMAS_Play(enum HMAS_ChannelId channel, HMAS_AudioId id, bool loop)
Definition HMAS.cpp:238
void HMAS_SetPause(enum HMAS_ChannelId channel, bool pause)
Definition HMAS.cpp:258
int HMAS_AudioId
Definition HMAS.h:3
void HMAS_SetPitch(enum HMAS_ChannelId channel, float pitch)
Definition HMAS.cpp:250
void HMAS_AddEffect(enum HMAS_ChannelId channel, enum HMAS_EffectType type, enum HMAS_EffectTransition transition, uint32_t frames, float target)
Definition HMAS.cpp:262
HMAS_EffectType
Definition HMAS.h:12
@ HMAS_EFFECT_PAUSE
Definition HMAS.h:15
@ HMAS_EFFECT_STOP
Definition HMAS.h:16
@ HMAS_EFFECT_VOLUME
Definition HMAS.h:13
@ HMAS_EFFECT_PITCH
Definition HMAS.h:14
bool HMAS_IsIDRegistered(HMAS_AudioId id)
Definition HMAS.cpp:266
HMAS_EffectTransition
Definition HMAS.h:19
@ HMAS_LINEAR
Definition HMAS.h:20
@ HMAS_INSTANT
Definition HMAS.h:21
bool HMAS_IsPlaying(enum HMAS_ChannelId channel)
Definition HMAS.cpp:246
static const char * frames[]
Definition Mole.cpp:246
struct ma_sound ma_sound
Definition miniaudio.h:11094
struct ma_decoder ma_decoder
Definition miniaudio.h:9936
struct ma_engine ma_engine
Definition miniaudio.h:11093
@ info
Definition portable-file-dialogs.h:92