Streaming music


I’ve read the sound documentation , and i wonder if i could stream music that i generate on the fly.

It seems difficult , because you can only play .wav and .ogg files.
May be generate a wav when level starts.
As i want a 3 or 4mn long music.

At 44100hz, during 4 minutes, on 16 bits samples (2 bytes), with mono output, it would need:

44100 * (4*60) * 2 / 2^20 = 20 mb (5mb/minutes)

seems doable, even on mobile devices (on PC, i could even allocate more memory for stereo rendering, which would give 10mb/mn).

But the idea of music generation was also to cut the music and play another pattern when certain events occurs. Of course i could generate some patterns, and switch from one to another with differents sound components (one per music pattern).

Is it the way to go ?

Thank for reading.

The sound component uses static sound resources (ogg or wav files). The only way to use those would be to have a preset of sounds and build patterns with them.

Alternatively you can build a native extension that plays sound. Check out these sound extensions:


Ok i see.

So the solution for me is to use OpenAL Extension.

I hope i can write a file somewhere , when the defold game is running.

If i can, i just have to load it with :

resource - resource that represents a WAV file.

I will give a try… later :slight_smile:

OpenAL supports streaming as well if you really want to generate the music on the fly and conserve memory.