loading sounds, changing and reloading them

Just starting out? Need help? Post your questions and find answers here.
User avatar
TheAutomator
Enthusiast
Enthusiast
Posts: 112
Joined: Tue Dec 01, 2020 8:33 pm

loading sounds, changing and reloading them

Post by TheAutomator »

Hi :)

Quick question(s) about the inner workings of the sound system:

If I load a sound and want to replace/reload it afterwards while the program is running, do I first need to unload e.g. sound '0' to replace it?

Code: Select all

LoadSound(0, "a.wav")
LoadSound(0, "b.wav")
I also wonder if continuously changing the frequency damages the sound quality (like resampling again and again) in memory or not?

Code: Select all

for i = 1 to 999
    SetSoundFrequency(0, #FreHigh)
    SetSoundFrequency(0, #FreLow)
next
BarryG
Addict
Addict
Posts: 4262
Joined: Thu Apr 18, 2019 8:17 am

Re: loading sounds, changing and reloading them

Post by BarryG »

You can re-use the same sound number to auto-free the old one and load the new, yes. It works that way for images and gadgets too.

As for the sound quality with frequency, I'm not sure about that. I would record the sounds with Audacity and compare waveforms to view the before/after of the changes.
User avatar
TheAutomator
Enthusiast
Enthusiast
Posts: 112
Joined: Tue Dec 01, 2020 8:33 pm

Re: loading sounds, changing and reloading them

Post by TheAutomator »

Okay, so how do you know it 'auto unloads' the file actually?
The help file is very limited about such things...
BarryG
Addict
Addict
Posts: 4262
Joined: Thu Apr 18, 2019 8:17 am

Re: loading sounds, changing and reloading them

Post by BarryG »

PureBasic Manual wrote:An object that is associated with an index is automatically freed when reusing that index.
It's under "PureBasic Objects" -> https://www.purebasic.com/documentation ... jects.html

You can also use the debugger's Library Viewer to view object info to see that something's changed/freed.
User avatar
TheAutomator
Enthusiast
Enthusiast
Posts: 112
Joined: Tue Dec 01, 2020 8:33 pm

Re: loading sounds, changing and reloading them

Post by TheAutomator »

Nice, thanks :)
Didn't see that in the helpfile first for some reason :shock:
BarryG
Addict
Addict
Posts: 4262
Joined: Thu Apr 18, 2019 8:17 am

Re: loading sounds, changing and reloading them

Post by BarryG »

No problem.
Post Reply