Page 1 of 1

loading sounds, changing and reloading them

Posted: Thu Nov 10, 2022 10:25 pm
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

Re: loading sounds, changing and reloading them

Posted: Fri Nov 11, 2022 12:00 am
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.

Re: loading sounds, changing and reloading them

Posted: Fri Nov 11, 2022 1:32 am
by TheAutomator
Okay, so how do you know it 'auto unloads' the file actually?
The help file is very limited about such things...

Re: loading sounds, changing and reloading them

Posted: Fri Nov 11, 2022 1:58 am
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.

Re: loading sounds, changing and reloading them

Posted: Fri Nov 11, 2022 2:27 am
by TheAutomator
Nice, thanks :)
Didn't see that in the helpfile first for some reason :shock:

Re: loading sounds, changing and reloading them

Posted: Fri Nov 11, 2022 3:23 am
by BarryG
No problem.