Skip to content

Commit c64f13a

Browse files
committed
use bit sets in miniaudio for flags
1 parent 8b1c9b0 commit c64f13a

File tree

7 files changed

+90
-61
lines changed

7 files changed

+90
-61
lines changed

vendor/miniaudio/device_io_types.odin

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,13 @@ device_id :: struct #raw_union {
351351
nullbackend: c.int, /* The null backend uses an integer for device IDs. */
352352
}
353353

354+
data_format_flag :: enum c.int {
355+
EXCLUSIVE_MODE = 1, /* If set, this is supported in exclusive mode. Otherwise not natively supported by exclusive mode. */
356+
}
357+
358+
data_format_flags :: bit_set[data_format_flag; u32]
354359

355-
DATA_FORMAT_FLAG_EXCLUSIVE_MODE :: 1 << 1 /* If set, this is supported in exclusive mode. Otherwise not natively supported by exclusive mode. */
360+
DATA_FORMAT_FLAG_EXCLUSIVE_MODE :: data_format_flags{.EXCLUSIVE_MODE}
356361

357362
MAX_DEVICE_NAME_LENGTH :: 255
358363

@@ -364,10 +369,10 @@ device_info :: struct {
364369

365370
nativeDataFormatCount: u32,
366371
nativeDataFormats: [/*len(format_count) * standard_sample_rate.rate_count * MAX_CHANNELS*/ 64]struct { /* Not sure how big to make this. There can be *many* permutations for virtual devices which can support anything. */
367-
format: format, /* Sample format. If set to ma_format_unknown, all sample formats are supported. */
368-
channels: u32, /* If set to 0, all channels are supported. */
369-
sampleRate: u32, /* If set to 0, all sample rates are supported. */
370-
flags: u32, /* A combination of MA_DATA_FORMAT_FLAG_* flags. */
372+
format: format, /* Sample format. If set to ma_format_unknown, all sample formats are supported. */
373+
channels: u32, /* If set to 0, all channels are supported. */
374+
sampleRate: u32, /* If set to 0, all sample rates are supported. */
375+
flags: data_format_flags, /* A combination of MA_DATA_FORMAT_FLAG_* flags. */
371376
},
372377
}
373378

vendor/miniaudio/engine.odin

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,22 @@ Engine
1111
************************************************************************************************************************************************************/
1212

1313
/* Sound flags. */
14-
sound_flags :: enum c.int {
14+
sound_flag :: enum c.int {
1515
/* Resource manager flags. */
16-
STREAM = 0x00000001, /* MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_STREAM */
17-
DECODE = 0x00000002, /* MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_DECODE */
18-
ASYNC = 0x00000004, /* MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_ASYNC */
19-
WAIT_INIT = 0x00000008, /* MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_WAIT_INIT */
20-
UNKNOWN_LENGTH = 0x00000010, /* MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_UNKNOWN_LENGTH */
16+
STREAM = 0, /* MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_STREAM */
17+
DECODE = 1, /* MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_DECODE */
18+
ASYNC = 2, /* MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_ASYNC */
19+
WAIT_INIT = 3, /* MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_WAIT_INIT */
20+
UNKNOWN_LENGTH = 4, /* MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_UNKNOWN_LENGTH */
2121

2222
/* ma_sound specific flags. */
23-
NO_DEFAULT_ATTACHMENT = 0x00001000, /* Do not attach to the endpoint by default. Useful for when setting up nodes in a complex graph system. */
24-
NO_PITCH = 0x00002000, /* Disable pitch shifting with ma_sound_set_pitch() and ma_sound_group_set_pitch(). This is an optimization. */
25-
NO_SPATIALIZATION = 0x00004000, /* Disable spatialization. */
23+
NO_DEFAULT_ATTACHMENT = 12, /* Do not attach to the endpoint by default. Useful for when setting up nodes in a complex graph system. */
24+
NO_PITCH = 13, /* Disable pitch shifting with ma_sound_set_pitch() and ma_sound_group_set_pitch(). This is an optimization. */
25+
NO_SPATIALIZATION = 14, /* Disable spatialization. */
2626
}
2727

28+
sound_flags :: bit_set[sound_flag; u32]
29+
2830
ENGINE_MAX_LISTENERS :: 4
2931

3032
LISTENER_INDEX_CLOSEST :: 255
@@ -81,7 +83,7 @@ engine_node :: struct {
8183

8284
@(default_calling_convention="c", link_prefix="ma_")
8385
foreign lib {
84-
engine_node_config_init :: proc(pEngine: ^engine, type: engine_node_type, flags: u32) -> engine_node_config ---
86+
engine_node_config_init :: proc(pEngine: ^engine, type: engine_node_type, flags: sound_flags) -> engine_node_config ---
8587

8688
engine_node_get_heap_size :: proc(pConfig: ^engine_node_config, pHeapSizeInBytes: ^c.size_t) -> result ---
8789
engine_node_init_preallocated :: proc(pConfig: ^engine_node_config, pHeap: rawptr, pEngineNode: ^engine_node) -> result ---
@@ -96,17 +98,17 @@ SOUND_SOURCE_CHANNEL_COUNT :: 0xFFFFFFFF
9698
sound_end_proc :: #type proc "c" (pUserData: rawptr, pSound: ^sound)
9799

98100
sound_config :: struct {
99-
pFilePath: cstring, /* Set this to load from the resource manager. */
100-
pFilePathW: [^]c.wchar_t, /* Set this to load from the resource manager. */
101-
pDataSource: ^data_source, /* Set this to load from an existing data source. */
102-
pInitialAttachment: ^node, /* If set, the sound will be attached to an input of this node. This can be set to a ma_sound. If set to NULL, the sound will be attached directly to the endpoint unless MA_SOUND_FLAG_NO_DEFAULT_ATTACHMENT is set in `flags`. */
103-
initialAttachmentInputBusIndex: u32, /* The index of the input bus of pInitialAttachment to attach the sound to. */
104-
channelsIn: u32, /* Ignored if using a data source as input (the data source's channel count will be used always). Otherwise, setting to 0 will cause the engine's channel count to be used. */
105-
channelsOut: u32, /* Set this to 0 (default) to use the engine's channel count. Set to MA_SOUND_SOURCE_CHANNEL_COUNT to use the data source's channel count (only used if using a data source as input). */
101+
pFilePath: cstring, /* Set this to load from the resource manager. */
102+
pFilePathW: [^]c.wchar_t, /* Set this to load from the resource manager. */
103+
pDataSource: ^data_source, /* Set this to load from an existing data source. */
104+
pInitialAttachment: ^node, /* If set, the sound will be attached to an input of this node. This can be set to a ma_sound. If set to NULL, the sound will be attached directly to the endpoint unless MA_SOUND_FLAG_NO_DEFAULT_ATTACHMENT is set in `flags`. */
105+
initialAttachmentInputBusIndex: u32, /* The index of the input bus of pInitialAttachment to attach the sound to. */
106+
channelsIn: u32, /* Ignored if using a data source as input (the data source's channel count will be used always). Otherwise, setting to 0 will cause the engine's channel count to be used. */
107+
channelsOut: u32, /* Set this to 0 (default) to use the engine's channel count. Set to MA_SOUND_SOURCE_CHANNEL_COUNT to use the data source's channel count (only used if using a data source as input). */
106108
monoExpansionMode: mono_expansion_mode, /* Controls how the mono channel should be expanded to other channels when spatialization is disabled on a sound. */
107-
flags: u32, /* A combination of MA_SOUND_FLAG_* flags. */
108-
volumeSmoothTimeInPCMFrames: u32, /* The number of frames to smooth over volume changes. Defaults to 0 in which case no smoothing is used. */
109-
initialSeekPointInPCMFrames: u64, /* Initializes the sound such that it's seeked to this location by default. */
109+
flags: sound_flags, /* A combination of MA_SOUND_FLAG_* flags. */
110+
volumeSmoothTimeInPCMFrames: u32, /* The number of frames to smooth over volume changes. Defaults to 0 in which case no smoothing is used. */
111+
initialSeekPointInPCMFrames: u64, /* Initializes the sound such that it's seeked to this location by default. */
110112
rangeBegInPCMFrames: u64,
111113
rangeEndInPCMFrames: u64,
112114
loopPointBegInPCMFrames: u64,
@@ -152,10 +154,10 @@ foreign lib {
152154
sound_config_init :: proc() -> sound_config ---
153155
sound_config_init2 :: proc(pEngine: ^engine) -> sound_config --- /* Will be renamed to sound_config_init() in version 0.12. */
154156

155-
sound_init_from_file :: proc(pEngine: ^engine, pFilePath: cstring, flags: u32, pGroup: ^sound_group, pDoneFence: ^fence, pSound: ^sound) -> result ---
156-
sound_init_from_file_w :: proc(pEngine: ^engine, pFilePath: [^]c.wchar_t, flags: u32, pGroup: ^sound_group, pDoneFence: ^fence, pSound: ^sound) -> result ---
157-
sound_init_copy :: proc(pEngine: ^engine, pExistingSound: ^sound, flags: u32, pGroup: ^sound_group, pSound: ^sound) -> result ---
158-
sound_init_from_data_source :: proc(pEngine: ^engine, pDataSource: ^data_source, flags: u32, pGroup: ^sound_group, pSound: ^sound) -> result ---
157+
sound_init_from_file :: proc(pEngine: ^engine, pFilePath: cstring, flags: sound_flags, pGroup: ^sound_group, pDoneFence: ^fence, pSound: ^sound) -> result ---
158+
sound_init_from_file_w :: proc(pEngine: ^engine, pFilePath: [^]c.wchar_t, flags: sound_flags, pGroup: ^sound_group, pDoneFence: ^fence, pSound: ^sound) -> result ---
159+
sound_init_copy :: proc(pEngine: ^engine, pExistingSound: ^sound, flags: sound_flags, pGroup: ^sound_group, pSound: ^sound) -> result ---
160+
sound_init_from_data_source :: proc(pEngine: ^engine, pDataSource: ^data_source, flags: sound_flags, pGroup: ^sound_group, pSound: ^sound) -> result ---
159161
sound_init_ex :: proc(pEngine: ^engine, pConfig: ^sound_config, pSound: ^sound) -> result ---
160162
sound_uninit :: proc(pSound: ^sound) ---
161163
sound_get_engine :: proc(pSound: ^sound) -> ^engine ---
@@ -243,7 +245,7 @@ foreign lib {
243245
sound_group_config_init :: proc() -> sound_group_config ---
244246
sound_group_config_init2 :: proc(pEngine: ^engine) -> sound_group_config ---
245247

246-
sound_group_init :: proc(pEngine: ^engine, flags: u32, pParentGroup, pGroup: ^sound_group) -> result ---
248+
sound_group_init :: proc(pEngine: ^engine, flags: sound_flags, pParentGroup, pGroup: ^sound_group) -> result ---
247249
sound_group_init_ex :: proc(pEngine: ^engine, pConfig: ^sound_group_config, pGroup: ^sound_group) -> result ---
248250
sound_group_uninit :: proc(pGroup: ^sound_group) ---
249251
sound_group_get_engine :: proc(pGroup: ^sound_group) -> ^engine ---

vendor/miniaudio/job_queue.odin

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ job :: struct {
108108
pDataBufferNode: rawptr /*ma_resource_manager_data_buffer_node**/,
109109
pFilePath: cstring,
110110
pFilePathW: [^]c.wchar_t,
111-
flags: u32, /* Resource manager data source flags that were used when initializing the data buffer. */
111+
flags: resource_manager_data_source_flags, /* Resource manager data source flags that were used when initializing the data buffer. */
112112
pInitNotification: ^async_notification, /* Signalled when the data buffer has been initialized and the format/channels/rate can be retrieved. */
113113
pDoneNotification: ^async_notification, /* Signalled when the data buffer has been fully decoded. Will be passed through to MA_JOB_TYPE_RESOURCE_MANAGER_PAGE_DATA_BUFFER_NODE when decoding. */
114114
pInitFence: ^fence, /* Released when initialization of the decoder is complete. */
@@ -194,19 +194,21 @@ ma_job_queue_post(). ma_job_queue_next() will return MA_NO_DATA_AVAILABLE if not
194194
195195
This flag should always be used for platforms that do not support multithreading.
196196
*/
197-
job_queue_flags :: enum c.int {
198-
NON_BLOCKING = 0x00000001,
197+
job_queue_flag :: enum c.int {
198+
NON_BLOCKING = 0,
199199
}
200200

201+
job_queue_flags :: bit_set[job_queue_flag; u32]
202+
201203
job_queue_config :: struct {
202-
flags: u32,
204+
flags: job_queue_flags,
203205
capacity: u32, /* The maximum number of jobs that can fit in the queue at a time. */
204206
}
205207

206208
USE_EXPERIMENTAL_LOCK_FREE_JOB_QUEUE :: false
207209

208210
job_queue :: struct {
209-
flags: u32, /* Flags passed in at initialization time. */
211+
flags: job_queue_flags, /* Flags passed in at initialization time. */
210212
capacity: u32, /* The maximum number of jobs that can fit in the queue at a time. Set by the config. */
211213
head: u64, /*atomic*/ /* The first item in the list. Required for removing from the top of the list. */
212214
tail: u64, /*atomic*/ /* The last item in the list. Required for appending to the end of the list. */
@@ -222,7 +224,7 @@ job_queue :: struct {
222224

223225
@(default_calling_convention="c", link_prefix="ma_")
224226
foreign lib {
225-
job_queue_config_init :: proc(flags, capacity: u32) -> job_queue_config ---
227+
job_queue_config_init :: proc(flags: job_queue_flags, capacity: u32) -> job_queue_config ---
226228

227229
job_queue_get_heap_size :: proc(pConfig: ^job_queue_config, pHeapSizeInBytes: ^c.size_t) -> result ---
228230
job_queue_init_preallocated :: proc(pConfig: ^job_queue_config, pHeap: rawptr, pQueue: ^job_queue) -> result ---

vendor/miniaudio/node_graph.odin

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ NODE_BUS_COUNT_UNKNOWN :: 255
2222
node :: struct {}
2323

2424
/* Node flags. */
25-
node_flags :: enum c.int {
26-
PASSTHROUGH = 0x00000001,
27-
CONTINUOUS_PROCESSING = 0x00000002,
28-
ALLOW_NULL_INPUT = 0x00000004,
29-
DIFFERENT_PROCESSING_RATES = 0x00000008,
30-
SILENT_OUTPUT = 0x00000010,
25+
node_flag :: enum c.int {
26+
PASSTHROUGH = 0,
27+
CONTINUOUS_PROCESSING = 1,
28+
ALLOW_NULL_INPUT = 2,
29+
DIFFERENT_PROCESSING_RATES = 3,
30+
SILENT_OUTPUT = 4,
3131
}
3232

33+
node_flags :: bit_set[node_flag; u32]
34+
3335
/* The playback state of a node. Either started or stopped. */
3436
node_state :: enum c.int {
3537
started = 0,
@@ -75,7 +77,7 @@ node_vtable :: struct {
7577
Flags describing characteristics of the node. This is currently just a placeholder for some
7678
ideas for later on.
7779
*/
78-
flags: u32,
80+
flags: node_flags,
7981
}
8082

8183
node_config :: struct {
@@ -87,6 +89,12 @@ node_config :: struct {
8789
pOutputChannels: ^u32, /* The number of elements are determined by the output bus count as determined by the vtable, or `outputBusCount` if the vtable specifies `MA_NODE_BUS_COUNT_UNKNOWN`. */
8890
}
8991

92+
node_output_bus_flag :: enum c.int {
93+
HAS_READ = 0, /* 0x01 */
94+
}
95+
96+
node_output_bus_flags :: bit_set[node_output_bus_flag; u32]
97+
9098
/*
9199
A node has multiple output buses. An output bus is attached to an input bus as an item in a linked
92100
list. Think of the input bus as a linked list, with the output bus being an item in that list.
@@ -99,7 +107,7 @@ node_output_bus :: struct {
99107

100108
/* Mutable via multiple threads. Must be used atomically. The weird ordering here is for packing reasons. */
101109
inputNodeInputBusIndex: u8, /* The index of the input bus on the input. Required for detaching. Will only be used in the spinlock so does not need to be atomic. */
102-
flags: u32, /*atomic*/ /* Some state flags for tracking the read state of the output buffer. A combination of MA_NODE_OUTPUT_BUS_FLAG_*. */
110+
flags: node_output_bus_flags, /*atomic*/ /* Some state flags for tracking the read state of the output buffer. A combination of MA_NODE_OUTPUT_BUS_FLAG_*. */
103111
refCount: u32, /*atomic*/ /* Reference count for some thread-safety when detaching. */
104112
isAttached: b32, /*atomic*/ /* This is used to prevent iteration of nodes that are in the middle of being detached. Used for thread safety. */
105113
lock: spinlock, /*atomic*/ /* Unfortunate lock, but significantly simplifies the implementation. Required for thread-safe attaching and detaching. */

vendor/miniaudio/resource_manager.odin

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ Resource Manager
1010
1111
************************************************************************************************************************************************************/
1212

13-
resource_manager_data_source_flags :: enum c.int {
14-
STREAM = 0x00000001, /* When set, does not load the entire data source in memory. Disk I/O will happen on job threads. */
15-
DECODE = 0x00000002, /* Decode data before storing in memory. When set, decoding is done at the resource manager level rather than the mixing thread. Results in faster mixing, but higher memory usage. */
16-
ASYNC = 0x00000004, /* When set, the resource manager will load the data source asynchronously. */
17-
WAIT_INIT = 0x00000008, /* When set, waits for initialization of the underlying data source before returning from ma_resource_manager_data_source_init(). */
18-
UNKNOWN_LENGTH = 0x00000010, /* Gives the resource manager a hint that the length of the data source is unknown and calling `ma_data_source_get_length_in_pcm_frames()` should be avoided. */
13+
resource_manager_data_source_flag :: enum c.int {
14+
STREAM = 0, /* When set, does not load the entire data source in memory. Disk I/O will happen on job threads. */
15+
DECODE = 1, /* Decode data before storing in memory. When set, decoding is done at the resource manager level rather than the mixing thread. Results in faster mixing, but higher memory usage. */
16+
ASYNC = 2, /* When set, the resource manager will load the data source asynchronously. */
17+
WAIT_INIT = 3, /* When set, waits for initialization of the underlying data source before returning from ma_resource_manager_data_source_init(). */
18+
UNKNOWN_LENGTH = 4, /* Gives the resource manager a hint that the length of the data source is unknown and calling `ma_data_source_get_length_in_pcm_frames()` should be avoided. */
1919
}
2020

21+
resource_manager_data_source_flags :: bit_set[resource_manager_data_source_flag; u32]
22+
2123
/*
2224
Pipeline notifications used by the resource manager. Made up of both an async notification and a fence, both of which are optional.
2325
*/
@@ -58,14 +60,16 @@ resource_manager_job_queue_next :: job_queue_next
5860
/* Maximum job thread count will be restricted to this, but this may be removed later and replaced with a heap allocation thereby removing any limitation. */
5961
RESOURCE_MANAGER_MAX_JOB_THREAD_COUNT :: 64
6062

61-
resource_manager_flags :: enum c.int {
63+
resource_manager_flag :: enum c.int {
6264
/* Indicates ma_resource_manager_next_job() should not block. Only valid when the job thread count is 0. */
6365
NON_BLOCKING = 0x00000001,
6466

6567
/* Disables any kind of multithreading. Implicitly enables MA_RESOURCE_MANAGER_FLAG_NON_BLOCKING. */
6668
NO_THREADING = 0x00000002,
6769
}
6870

71+
resource_manager_flags :: bit_set[resource_manager_flag; u32]
72+
6973
resource_manager_data_source_config :: struct {
7074
pFilePath: cstring,
7175
pFilePathW: [^]c.wchar_t,
@@ -126,7 +130,7 @@ resource_manager_data_buffer :: struct {
126130
ds: data_source_base, /* Base data source. A data buffer is a data source. */
127131
pResourceManager: ^resource_manager, /* A pointer to the resource manager that owns this buffer. */
128132
pNode: ^resource_manager_data_buffer_node, /* The data node. This is reference counted and is what supplies the data. */
129-
flags: u32, /* The flags that were passed used to initialize the buffer. */
133+
flags: resource_manager_flags, /* The flags that were passed used to initialize the buffer. */
130134
executionCounter: u32, /*atomic*/ /* For allocating execution orders for jobs. */
131135
executionPointer: u32, /*atomic*/ /* For managing the order of execution for asynchronous jobs relating to this object. Incremented as jobs complete processing. */
132136
seekTargetInPCMFrames: u64, /* Only updated by the public API. Never written nor read from the job thread. */

0 commit comments

Comments
 (0)