diff --git a/examples/RoomPersistency/RoomPersistency.nds b/examples/RoomPersistency/RoomPersistency.nds index 5b7d424..823b4fa 100644 Binary files a/examples/RoomPersistency/RoomPersistency.nds and b/examples/RoomPersistency/RoomPersistency.nds differ diff --git a/examples/RoomPersistency/source/project.c b/examples/RoomPersistency/source/project.c index b54db0f..f281580 100644 --- a/examples/RoomPersistency/source/project.c +++ b/examples/RoomPersistency/source/project.c @@ -408,6 +408,7 @@ void player_create(playerObjectInstance *me) { else { DSGM_DrawText(DSGM_TOP, 1, 5, "Room_2"); } + DSGM_PlaySound(FlatOutLies); } @@ -477,14 +478,5 @@ void player_loop(playerObjectInstance *me) { } void player_touch(playerObjectInstance *me) { - //mmStop(); - //DSGM_Sounds[FlatOutLies].loaded = false; - //DSGM_PlaySound(FlatOutLies); - //mmLoad(DSGM_Sounds[FlatOutLies].ID); - //swiWaitForVBlank(); - //mmStart(DSGM_Sounds[FlatOutLies].ID, MM_PLAY_LOOP); - DSGM_GotoNextRoom(false); - /*if(DSGM_currentRoom == Room_1) DSGM_SwitchRoom(Room_2, false); - else if(DSGM_currentRoom == Room_2) DSGM_SwitchRoom(Room_1, false);*/ } diff --git a/include/DSGM_sound.h b/include/DSGM_sound.h index 0eccc21..76bb179 100644 --- a/include/DSGM_sound.h +++ b/include/DSGM_sound.h @@ -1,6 +1,6 @@ #pragma once -#define DSGM_MAX_SOUNDS 32 +#define DSGM_MAX_SOUND_EFFECT_INSTANCES 32 #define DSGM_RESERVED_STREAMS 1 #define DSGM_SOUND_STREAM 0 @@ -28,8 +28,10 @@ typedef struct { extern int DSGM_soundStreamCount; -extern DSGM_SoundInstance DSGM_soundInstances[DSGM_MAX_SOUNDS]; -extern int DSGM_soundInstanceCount; +extern DSGM_SoundInstance DSGM_soundStreamInstance; + +extern DSGM_SoundInstance DSGM_soundEffectInstances[DSGM_MAX_SOUND_EFFECT_INSTANCES]; +extern int DSGM_soundEffectInstanceCount; void DSGM_InitSoundFull(int soundStreamCount); void DSGM_ResetSound(void); diff --git a/lib/libdsgm.a b/lib/libdsgm.a index c7bbf28..a8f838d 100644 Binary files a/lib/libdsgm.a and b/lib/libdsgm.a differ diff --git a/source/DSGM_room.c b/source/DSGM_room.c index 578bfef..0f203cb 100644 --- a/source/DSGM_room.c +++ b/source/DSGM_room.c @@ -85,9 +85,9 @@ void DSGM_LoopRoom(DSGM_Room *room) { DSGM_ValidateRoom(); //+1? - for(sound = 0; sound < DSGM_soundInstanceCount; sound++) { - DSGM_SetSoundInstanceVolumeFull(&DSGM_soundInstances[sound], DSGM_soundInstances[sound].volume); - DSGM_SetSoundInstancePanningFull(&DSGM_soundInstances[sound], DSGM_soundInstances[sound].panning); + for(sound = 0; sound < DSGM_soundEffectInstanceCount; sound++) { + DSGM_SetSoundInstanceVolumeFull(&DSGM_soundEffectInstances[sound], DSGM_soundEffectInstances[sound].volume); + DSGM_SetSoundInstancePanningFull(&DSGM_soundEffectInstances[sound], DSGM_soundEffectInstances[sound].panning); } for(screen = 0; screen < 2; screen++) { diff --git a/source/DSGM_sound.c b/source/DSGM_sound.c index aa2efb0..d9bf3e9 100644 --- a/source/DSGM_sound.c +++ b/source/DSGM_sound.c @@ -2,8 +2,10 @@ int DSGM_soundStreamCount = 0; -DSGM_SoundInstance DSGM_soundInstances[DSGM_MAX_SOUNDS]; -int DSGM_soundInstanceCount = 0; +DSGM_SoundInstance DSGM_soundStreamInstance; + +DSGM_SoundInstance DSGM_soundEffectInstances[DSGM_MAX_SOUND_EFFECT_INSTANCES]; +int DSGM_soundEffectInstanceCount = 0; void DSGM_InitSoundFull(int soundStreamCount) { mmInitDefault("nitro:/soundbank.bin"); @@ -11,29 +13,33 @@ void DSGM_InitSoundFull(int soundStreamCount) { } void DSGM_ResetSound(void) { - /*mmStop(); + mmStop(); mmEffectCancelAll(); - int i; - for(i = 0; i < DSGM_soundInstanceCount; i++) { - if(DSGM_soundInstances[i].sound->type == DSGM_SOUND_STREAM) { - // MaxMod is broken :( - //mmUnload(DSGM_soundInstances[i].sound->ID); - //DSGM_soundInstances[i].sound->loaded = false; - } - else { - //mmUnloadEffect(DSGM_soundInstances[i].sound->ID - DSGM_soundStreamCount); - //DSGM_soundInstances[i].sound->loaded = false; - } + if(DSGM_soundStreamInstance.sound) { + mmUnload(DSGM_soundStreamInstance.sound->ID); + DSGM_soundStreamInstance.sound->loaded = false; } - DSGM_soundInstanceCount = 0;*/ + int i; + for(i = 0; i < DSGM_soundEffectInstanceCount; i++) { + mmUnloadEffect(DSGM_soundEffectInstances[i].sound->ID - DSGM_soundStreamCount); + DSGM_soundEffectInstances[i].sound->loaded = false; + } + + DSGM_soundEffectInstanceCount = 0; } DSGM_SoundInstance *DSGM_AddSoundInstance(DSGM_Sound *sound) { - // still playing? - if(DSGM_soundInstanceCount == DSGM_MAX_SOUNDS) DSGM_soundInstanceCount = sound->type == DSGM_SOUND_STREAM ? 0 : DSGM_RESERVED_STREAMS; - return &DSGM_soundInstances[DSGM_soundInstanceCount++]; + if(sound->type == DSGM_SOUND_STREAM) { + DSGM_soundStreamInstance.sound = sound; + return &DSGM_soundStreamInstance; + } + else { + if(DSGM_soundEffectInstanceCount < DSGM_MAX_SOUND_EFFECT_INSTANCES) DSGM_soundEffectInstanceCount++; + DSGM_soundEffectInstances[DSGM_soundEffectInstanceCount - 1].sound = sound; + return &DSGM_soundEffectInstances[DSGM_soundEffectInstanceCount - 1]; + } } DSGM_SoundInstance *DSGM_PlaySoundFull(DSGM_Sound *sound) {