You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/en/manuals/sound-streaming.md
+18-35
Original file line number
Diff line number
Diff line change
@@ -7,22 +7,19 @@ brief: This manual explains how to stream sounds into the Defold game engine
7
7
8
8
While the default behaviour is to load sound data in full, it may also be beneficial to load the data in chunks, prior to their use. This is often called "streaming".
9
9
10
-
One benefit is that the runtime memory is kept low.
11
-
12
-
Another benefit is that, if you are streaming content from e.g. a http url, you can update the content at any time, and also avoid the initial download.
10
+
One benefit of sound streaming is that less runtime memory is required, another is if you are streaming content from e.g. a http url, you can update the content at any time, and also avoid the initial download.
13
11
14
12
### Example
15
13
16
-
There is an example project showcasing this setup: https://github.com/defold/example-sound-streaming
14
+
There is an example project showcasing this setup: [https://github.com/defold/example-sound-streaming](https://github.com/defold/example-sound-streaming)
17
15
18
16
## How to enable streaming sounds
19
17
20
18
### Easy way
21
19
22
-
The simplest way to use sound streaming, is by setting the `sound.stream_enabled` to true.
23
-
By simply switching on this flag, your project will start streaming the sounds.
20
+
The simplest way to use sound streaming, is by enabling the [`sound.stream_enabled` setting](https://defold.com/manuals/project-settings/#stream-enabled) in *game.project*. When this option is enabled the engine will start streaming the sounds.
24
21
25
-
Note: If you have lots of sound files loaded at the same time, you may need to up the `sound.stream_cache_size` value.
22
+
Note: If you have lots of sound files loaded at the same time, you may need to increase the `sound.stream_cache_size` value (see below).
26
23
27
24
### Runtime resources
28
25
@@ -31,13 +28,16 @@ You can also create a new sound data resource, and set it to a sound component.
31
28
You do this by:
32
29
* Load the initial part of the sound file data
33
30
* Note: This is the raw sound file, including the ogg/wav header
34
-
*Calling [resource.create_sound_data()](/ref/resource/#resource.create_sound_data) to get a resource
35
-
*Setting the resource to the sound component
31
+
*Create a new sound data resource by calling [`resource.create_sound_data()`](/ref/resource/#resource.create_sound_data).
32
+
*Set the new sound data resource to the sound component using [`go.set()`](/ref/go#go.set)
36
33
37
34
Here is an excerpt from the example project, using a `http.request()` to get the initial sound file.
38
-
Note that the web server you're loading content from has to support ranged requests.
39
35
40
-
```Lua
36
+
::: sidenote
37
+
The web server you're loading content from has to support [HTTP range requests](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Range_requests).
You can of course use other means to load the initial chunk of the sound file.
74
-
The important thing to remember is that the rest of the chunks are loaded from the resource system and our resource providers.
72
+
You can of course use other means to load the initial chunk of the sound file. The important thing to remember is that the rest of the chunks are loaded from the resource system and it's resource providers.
75
73
76
74
In this example, we have added a new file provider by adding a live update mount, by calling using [liveupdate.add_mount()](/ref/liveupdate/#liveupdate.add_mount).
77
75
78
76
79
77
## Sound chunk cache
80
78
81
-
You can control how much memory will be consumed by the sounds at runtime, by setting the size of the "sound chunk cache".
82
-
Given this limit, the loaded sound data will never exceed this limit.
83
-
84
-
Some things to note:
85
-
86
-
* Sound files smaller than the sound chunk size, aren't streamed.
87
-
* If a new chunk doesn't fit into the cache, the oldest chunk is evicted
88
-
* If the cache is too small, chunks may get evicted the same frame, and the sound won't play properly.
89
-
90
-
The initial chunk of each sound file cannot be evicted, so they will occupy the cache as long as the resources are loaded.
91
-
You can also control the size of each sound chunk. This may help you get the sound cache size down even further if you have many sound files loaded at the same time.
92
-
93
-
## Configuration
94
-
95
-
Currently, the streaming is enabled on all sound resources.
96
-
We may improve upon this in the future, allowing settings on individual sound files.
79
+
The amount of memory consumed by the sounds at runtime is controlled by the [`sound.stream_cache_size` setting](https://defold.com/manuals/project-settings/#stream-cache-size) in *game.project*. Given this limit, the loaded sound data will never exceed this limit.
97
80
98
-
The game project supports these settings:
81
+
The initial chunk of each sound file cannot be evicted and they will occupy the cache for as long as the resources are loaded. The size of the initial chunk is controlled by the [`sound.stream_preload_size` setting](https://defold.com/manuals/project-settings/#stream-preload-size) in *game.project*.
99
82
100
-
*`sound.stream_enabled` (default 0) - If enabled, enables streaming of all sound files
101
-
*`sound.stream_cache_size` (default 2097152 bytes) - The max size of the cache containing _all_ chunks.
102
-
*`sound.stream_chunk_size` (default 16384 bytes) - Determines size of each chunk that is loaded from a file at a time
103
-
*`sound.stream_preload_size` (default 16384 bytes) - Determines size of initial chunk read from each found file in the archive
83
+
You can also control the size of each sound chunk by changing the [`sound.stream_chunk_size` setting](https://defold.com/manuals/project-settings/#stream-chunk-size) in *game.project*. This may help you get the sound cache size down even further if you have many sound files loaded at the same time. Sound files smaller than the sound chunk size, aren't streamed and if a new chunk doesn't fit into the cache, the oldest chunk is evicted
104
84
85
+
::: important
86
+
The total size of the sound chunk cache should be larger than the number of loaded sound files times the stream chunk size. Otherwise, you risk evicting new chunks each frame and sounds won't play properly
0 commit comments