Sound Bakery  v0.1.0
Open-source audio middleware for games
Loading...
Searching...
No Matches
sound_chef_common.h
1#ifndef SOUND_CHEF_COMMON
2#define SOUND_CHEF_COMMON
3
4#ifdef sound_chef_shared_EXPORTS
5 #define SC_DLL
6 #define MA_DLL
7#endif
8
9#include "miniaudio.h"
10
11#include <assert.h>
12#include <string.h>
13
14#if defined(_WIN32)
15 #define SC_CALL __stdcall
16#else
17 #define SC_CALL
18#endif
19
20#if defined(_WIN32)
21 #define SC_DLL_IMPORT __declspec(dllimport)
22 #define SC_DLL_EXPORT __declspec(dllexport)
23 #define SC_DLL_PRIVATE static
24#elif defined(__APPLE__) || defined(__ANDROID__) || defined(__linux__)
25 #define SC_DLL_IMPORT __attribute__((visibility("default")))
26 #define SC_DLL_EXPORT __attribute__((visibility("default")))
27 #define SC_DLL_PRIVATE __attribute__((visibility("hidden")))
28#else
29 #define SC_DLL_IMPORT
30 #define SC_DLL_EXPORT
31 #define SC_DLL_PRIVATE
32#endif
33
34#ifdef SC_DLL
35 #define SC_API SC_DLL_EXPORT SC_CALL
36 #define SC_CLASS SC_DLL_EXPORT
37#else
38 #define SC_API SC_CALL
39 #define SC_CLASS
40#endif
41
42#define SC_CHECK(condition, result) \
43 if ((condition) == MA_FALSE) \
44 return (result)
45#define SC_CHECK_RESULT(result) \
46 if ((result) != MA_SUCCESS) \
47 return (result)
48#define SC_CHECK_ARG(condition) \
49 if ((condition) == MA_FALSE) \
50 return MA_INVALID_ARGS
51#define SC_CHECK_MEM(ptr) \
52 if ((ptr) == NULL) \
53 return MA_OUT_OF_MEMORY
54#define SC_CHECK_MEM_FREE(ptr, freePtr) \
55 if ((ptr) == NULL) \
56 { \
57 ma_free((freePtr), NULL); \
58 return MA_OUT_OF_MEMORY; \
59 }
60
61#define SC_ZERO_OBJECT(p) memset((p), 0, sizeof(*(p)))
62
63#ifdef __cplusplus
64extern "C"
65{
66#endif
67
68typedef ma_bool32 sc_bool;
69typedef ma_result sc_result;
70
71typedef struct sc_system sc_system;
72
73typedef struct sc_sound sc_sound;
74typedef struct sc_sound sc_sound_instance;
75
76typedef struct sc_node_group sc_node_group;
77
78typedef struct sc_dsp sc_dsp;
79typedef struct sc_dsp_state sc_dsp_state;
80typedef struct sc_dsp_config sc_dsp_config;
82typedef struct sc_dsp_vtable sc_dsp_vtable;
83
84typedef enum sc_sound_mode
85{
86 SC_SOUND_MODE_DEFAULT = 0x00000000, //< Creates a sound in memory and decompresses during runtime
87 SC_SOUND_MODE_DECODE = 0x00000001, //< Decodes the sound upon loading, instead of runtime
88 SC_SOUND_MODE_ASYNC = 0x00000002, //< Loads the sound in a background thread
89 SC_SOUND_MODE_STREAM = 0x00000004, //< Streams parts of the sound from disk during runtime
90} sc_sound_mode;
91
92typedef enum sc_dsp_type
93{
94 SC_DSP_TYPE_UNKOWN, //< User created
95 SC_DSP_TYPE_FADER,
96 SC_DSP_TYPE_LOWPASS,
97 SC_DSP_TYPE_HIGHPASS,
98 SC_DSP_TYPE_DELAY
99} sc_dsp_type;
100
101typedef enum sc_dsp_index
102{
103 SC_DSP_INDEX_TAIL = -2, //< Left/back of the chain and becomes the new input
104 SC_DSP_INDEX_HEAD = -1 //< Right/top of the chain and becomes the new output
105} sc_dsp_index;
106
107
108typedef sc_result(SC_CALL* SC_DSP_CREATE_CALLBACK)(sc_dsp_state* dspState);
109typedef sc_result(SC_CALL* SC_DSP_RELEASE_CALLBACK)(sc_dsp_state* dspState);
110typedef sc_result(SC_CALL* SC_DSP_SET_PARAM_FLOAT_CALLBACK)(sc_dsp_state* dspState, int index, float value);
111typedef sc_result(SC_CALL* SC_DSP_GET_PARAM_FLOAT_CALLBACK)(sc_dsp_state* dspState, int index, float* value);
112
114{
115 SC_DSP_CREATE_CALLBACK create;
116 SC_DSP_RELEASE_CALLBACK release;
117 SC_DSP_SET_PARAM_FLOAT_CALLBACK setFloat;
118 SC_DSP_GET_PARAM_FLOAT_CALLBACK getFloat;
119
120 sc_dsp_parameter** params;
121 int numParams;
122};
123
132{
133 void* instance; //< points to the current sc_dsp object
134 void* userData; //< points to uer created object, likely some type of
135 // ma_node
136 void* system; //< points to the owning sc_system object
137};
138
140{
141 sc_dsp_type type;
142 sc_dsp_vtable* vtable;
143};
144
151struct sc_dsp
152{
153 sc_dsp_state* state; //< holds the instance data for the dsp
154 sc_dsp_vtable* vtable; //< holds the functions for interacting with the underlying node type. Must be not null
155 sc_dsp_type type;
156 sc_dsp* next; //< when in a node group, the parent/next dsp. Can be null if the head node
157 sc_dsp* prev; //< when in a node group, the child/previous dsp. Can be null if the tail node
158};
159
161{
162 ma_sound sound;
163 sc_sound_mode mode;
164};
165
177{
178 sc_dsp* tail; //< Left/bottom most node. Sounds and child groups connect to this
179 sc_dsp* fader; //< Controls the volume and more of the group. Exists at start
180 sc_dsp* head; //< Right/top most node. Nodes in the group route to this. The head then outputs to a parent
181};
182
198{
199 ma_engine engine;
200
201 ma_resource_manager resourceManager; //< We need a custom resource manager for custom decoders
202
203 ma_log log;
204};
205
206#ifdef __cplusplus
207}
208#endif
209
210#endif
Definition sound_chef_common.h:140
Definition sound_chef_dsp.h:34
Holds instance data for a single sc_dsp.
Definition sound_chef_common.h:132
Definition sound_chef_common.h:114
ma_node with an additional enum descriptor.
Definition sound_chef_common.h:152
Groups nodes/DSPs together into one.
Definition sound_chef_common.h:177
Definition sound_chef_common.h:161
Object that manages the node graph, sounds, output etc.
Definition sound_chef_common.h:198