snd_sfx_load and unload, garbled sfx

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
PrOfUnD Darkness
DCEmu Freak
DCEmu Freak
Posts: 71
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Thu Feb 20, 2003 11:46 am
Has thanked: 1 time
Been thanked: 0
Contact:

snd_sfx_load and unload, garbled sfx

Post by PrOfUnD Darkness »

My code looks like this (simplified):
int sfx;
int c = 1;

main()
{
while (1) {

if (c==1) sfx = snd_sfx_load("/rd/1.wav")
else if (c==2) sfx = snd_sfx_load("/rd/2.wav")
else if (c==3) sfx = snd_sfx_load("/rd/3.wav")

c=playgame();

snd_sfx_unload(sfx);

}
}

int playgame() {

// do a bunch of stuff here
snd_sfx_play(sfx);

// do a bunch of more stuff here

return random; //random is between 1 and 3
}

The first snd_sfx_play works just fine, but after that the sfx comes out garbled. Is there any problem in keeping unloading and loading the way I'm doing?
User avatar
BB Hood
DC Developer
DC Developer
Posts: 189
Joined: Fri Mar 30, 2007 12:09 am
Has thanked: 41 times
Been thanked: 10 times

Re: snd_sfx_load and unload, garbled sfx

Post by BB Hood »

In my personal opinion it is not a good idea to unload sfx continuously. Just load all the files upfront and depending on the value of 'c', play the correct sfx.
PrOfUnD Darkness
DCEmu Freak
DCEmu Freak
Posts: 71
Joined: Thu Feb 20, 2003 11:46 am
Has thanked: 1 time
Been thanked: 0
Contact:

Re: snd_sfx_load and unload, garbled sfx

Post by PrOfUnD Darkness »

BB Hood wrote: Fri Aug 14, 2020 10:33 am In my personal opinion it is not a good idea to unload sfx continuously. Just load all the files upfront and depending on the value of 'c', play the correct sfx.
Yep that's how I fixed it, my concern is that we have less than 2Mb of memory to work with and I'd like to streamline the memory usage. Thank you for your response.
User avatar
BB Hood
DC Developer
DC Developer
Posts: 189
Joined: Fri Mar 30, 2007 12:09 am
Has thanked: 41 times
Been thanked: 10 times

Re: snd_sfx_load and unload, garbled sfx

Post by BB Hood »

I dont think that is something you have to worry about too much. You have to have a ton of sfx for that to happen. Glad it works for you :)
Post Reply