Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SFX
#9
(02-21-2024, 04:07 PM)Marcus Wrote: ...
Nice Smile  But you're creating new sound effects every time the user presses a key. Sound effect (and other resources, such as images) aren't garbage collected (they can't be). So the program will eat more and more memory. Better create the different piano sound effects once and re-use them, or release the old sound when a new one is created ('free sound').

I made two experiments to see the memory's consumption.
I played the song "Waltzing Matilda" ten times in each experiment.
I'm glad that my computer had not exploded yet during the experiment   Cool

Waltzing Matilda, Waltzing Matilda
You'll come a waltzing Matilda with me
And he sang as he sat
And waited till his billy boiled
You'll come a waltzing Matilda with me

Just imagine, I sang it 20 times  Big Grin Big Grin 

Herewith the piece of code that makes a difference
Code:
'This function will play sound frequency x at duration b
function Piano(b,x)
    'SquareWave(duration,freq,volume)
    mytune = sfx.SquareWave(b,x,0.05)
    play sound mytune
    Pause()
    free sound mytune 'release sound from memeory
endfunc

The First Experiment (without free sound memory)
Commit (KB)             57.344
Working Set (KB)       59.164
Shareable (KB)            7.324
Private (KB)              51.840

The Second Experiment (with free sound memory)
Commit (KB)              26.816
Working Set (KB)        28.796
Shareable (KB)            7.440
Private (KB)               21.356

Thank you Marcus for your suggestion in free-ing the sound memory.
Reply


Messages In This Thread
SFX - by johnno56 - 02-19-2024, 07:02 PM
RE: SFX - by Marcus - 02-20-2024, 04:44 PM
RE: SFX - by Marcus - 02-20-2024, 05:58 PM
RE: SFX - by johnno56 - 02-20-2024, 06:52 PM
RE: SFX - by 1micha.elok - 02-21-2024, 06:38 AM
RE: SFX - by Marcus - 02-21-2024, 04:07 PM
RE: SFX - by 1micha.elok - 02-22-2024, 05:04 AM
RE: SFX - by Marcus - 02-21-2024, 06:37 AM
RE: SFX - by johnno56 - 02-21-2024, 11:37 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)