66#include "miniaudio.h"
77
88#include "ma_audio_system.h"
9+ #include "data_win.h"
910#include "utils.h"
1011
1112#include <stdio.h>
1213#include <stdlib.h>
1314#include <string.h>
15+ #include "stb_ds.h"
1416
1517// ===[ Helpers ]===
1618
@@ -74,7 +76,7 @@ static char* resolveExternalPath(MaAudioSystem* ma, Sound* sound) {
7476
7577static void maInit (AudioSystem * audio , DataWin * dataWin , FileSystem * fileSystem ) {
7678 MaAudioSystem * ma = (MaAudioSystem * ) audio ;
77- ma -> base .dataWin = dataWin ;
79+ arrput ( ma -> base .audioGroups , dataWin ) ;
7880 ma -> fileSystem = fileSystem ;
7981
8082 ma_engine_config config = ma_engine_config_init ();
@@ -141,7 +143,7 @@ static void maUpdate(AudioSystem* audio, float deltaTime) {
141143
142144static int32_t maPlaySound (AudioSystem * audio , int32_t soundIndex , int32_t priority , bool loop ) {
143145 MaAudioSystem * ma = (MaAudioSystem * ) audio ;
144- DataWin * dw = ma -> base .dataWin ;
146+ DataWin * dw = ma -> base .audioGroups [ 0 ]; // Audio Group 0 should always be data.win
145147
146148 if (0 > soundIndex || (uint32_t ) soundIndex >= dw -> sond .count ) {
147149 fprintf (stderr , "Audio: Invalid sound index %d\n" , soundIndex );
@@ -162,12 +164,12 @@ static int32_t maPlaySound(AudioSystem* audio, int32_t soundIndex, int32_t prior
162164
163165 if (isEmbedded ) {
164166 // Embedded audio: decode from AUDO chunk memory
165- if (0 > sound -> audioFile || (uint32_t ) sound -> audioFile >= dw -> audo .count ) {
167+ if (0 > sound -> audioFile || (uint32_t ) sound -> audioFile >= ma -> base . audioGroups [ sound -> audioGroup ] -> audo .count ) {
166168 fprintf (stderr , "Audio: Invalid audio file index %d for sound '%s'\n" , sound -> audioFile , sound -> name );
167169 return -1 ;
168170 }
169171
170- AudioEntry * entry = & dw -> audo .entries [sound -> audioFile ];
172+ AudioEntry * entry = & ma -> base . audioGroups [ sound -> audioGroup ] -> audo .entries [sound -> audioFile ];
171173
172174 ma_decoder_config decoderConfig = ma_decoder_config_init_default ();
173175 result = ma_decoder_init_memory (entry -> data , entry -> dataSize , & decoderConfig , & slot -> decoder );
@@ -491,14 +493,22 @@ static void maSetChannelCount([[maybe_unused]] AudioSystem* audio, [[maybe_unuse
491493 // miniaudio handles channel management internally, this is a no-op
492494}
493495
494- static void maGroupLoad ([[maybe_unused ]] AudioSystem * audio , [[maybe_unused ]] int32_t groupIndex ) {
495- // Group 0 is already loaded (AUDO chunk), external sounds are loaded on demand
496- // Full audiogroup*.dat parsing can be added later if needed
496+ static void maGroupLoad (AudioSystem * audio , int32_t groupIndex ) {
497+ if (groupIndex > 0 )
498+ {
499+ int sz = snprintf (NULL , 0 , "audiogroup%d.dat" , groupIndex );
500+ char buf [sz + 1 ];
501+ snprintf (buf , sizeof (buf ), "audiogroup%d.dat" , groupIndex );
502+ DataWin * audioGroup = DataWin_parse (((MaAudioSystem * )audio )-> fileSystem -> vtable -> resolvePath (((MaAudioSystem * )audio )-> fileSystem , buf ),
503+ (DataWinParserOptions ) {
504+ .parseAudo = true,
505+ });
506+ arrput (audio -> audioGroups , audioGroup );
507+ }
497508}
498509
499510static bool maGroupIsLoaded ([[maybe_unused ]] AudioSystem * audio , [[maybe_unused ]] int32_t groupIndex ) {
500- // Always report loaded -- group 0 is embedded, external files load on demand
501- return true;
511+ return (arrlen (audio -> audioGroups ) > groupIndex );
502512}
503513
504514// ===[ Vtable ]===
0 commit comments