|
1 |
| -# nene/audio.nelua |
2 |
| -## Nene.Sound (record) |
| 1 | +### Sound |
3 | 2 |
|
4 | 3 | ```lua
|
5 |
| -global Nene.Sound = @record{ |
6 |
| - _data: *Mix_Chunk, |
| 4 | +global Sound = @record{ |
| 5 | + _data: *Mix_Chunk, -- internal data, don't use it directly, use methods instead |
7 | 6 | channel: integer, -- -1 when no channel is being used
|
8 | 7 | }
|
9 | 8 | ```
|
10 | 9 |
|
11 |
| -## Nene.Sound:play (function) |
| 10 | +Wraps a (SDL_mixer) sound associated with a sound channel |
| 11 | + |
| 12 | +### Sound:get |
12 | 13 |
|
13 | 14 | ```lua
|
14 |
| -function Nene.Sound:play(loop: overload(boolean, integer, niltype)) |
| 15 | +function Sound:get(): *Mix_Chunk |
15 | 16 | ```
|
16 | 17 |
|
17 |
| -## Nene.Sound:stop (function) |
| 18 | +It checks if the internal data is `nilptr` and then returns it. |
| 19 | + |
| 20 | +Related SDL_mixer documentation: |
| 21 | +* [Mix_Chunk](https://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer_85.html#SEC85) |
| 22 | + |
| 23 | +### Sound.load |
18 | 24 |
|
19 | 25 | ```lua
|
20 |
| -function Nene.Sound:stop() |
| 26 | +function Sound.load(filename: string): (Sound, boolean) |
21 | 27 | ```
|
22 | 28 |
|
23 |
| -## Nene.Sound:free (function) |
| 29 | +try to load a sound from a file. |
| 30 | + |
| 31 | +it returns: |
| 32 | +* `Sound` value, with internal data properly initialized if load is successful |
| 33 | +* a boolean which is `true` when the load succeeds. |
| 34 | + |
| 35 | +Related MixWrapper documentation: |
| 36 | +* [MixWrapper.load_wav](wrappers/mix.md#mixwrapperload_wav) |
| 37 | + |
| 38 | +### Sound:play |
24 | 39 |
|
25 | 40 | ```lua
|
26 |
| -function Nene.Sound:free() |
| 41 | +function Sound:play(loop: overload(boolean, integer, niltype)) |
27 | 42 | ```
|
28 | 43 |
|
29 |
| -## Nene.Sound:stop_and_free (function) |
| 44 | +plays the loaded sound. |
| 45 | +* if `true` is passed on `loop` argument, the sound will loop forever; |
| 46 | +* if an `integer` is passed, the sound will loop `loop` times |
| 47 | +* if `nil` is passed, it will play only one time. |
| 48 | + |
| 49 | +When there is no sound loaded (that is, the internal data is `nilptr`), then this method |
| 50 | +does nothing, though it also `check`s if the internal is `nilptr` (unless the `nochecks` pragma is enabled) |
| 51 | + |
| 52 | +Related MixWrapper documentation: |
| 53 | +* [MixWrapper.play_channel](wrappers/mix.md#mixwrapperplay_channel) |
| 54 | + |
| 55 | +### Sound:stop |
30 | 56 |
|
31 | 57 | ```lua
|
32 |
| -function Nene.Sound:stop_and_free() |
| 58 | +function Sound:stop() |
33 | 59 | ```
|
34 | 60 |
|
35 |
| -## Nene.Music (record) |
| 61 | +Halts (stop, interrupt) the sound. |
| 62 | + |
| 63 | +Related MixWrapper documentation: |
| 64 | +* [MixWrapper.halt_channel](wrappers/mix.md#mixwrapperhalt_channel) |
| 65 | + |
| 66 | +### Sound:destroy |
36 | 67 |
|
37 | 68 | ```lua
|
38 |
| -global Nene.Music = @record{ |
| 69 | +function Sound:destroy() |
| 70 | +``` |
| 71 | + |
| 72 | +Destroy the sound and resets to zeroed state, |
| 73 | + |
| 74 | +> Note: It will first stop the sound and then free the sound's memory. |
| 75 | +
|
| 76 | +Related MixWrapper documentation: |
| 77 | +* [MixWrapper.free_chunk](wrappers/mix.md#mixwrapperfree_chunk) |
| 78 | + |
| 79 | +### Music |
| 80 | + |
| 81 | +```lua |
| 82 | +global Music = @record{ |
39 | 83 | _data: *Mix_Music,
|
40 |
| - id: usize, |
41 | 84 | }
|
42 | 85 | ```
|
43 | 86 |
|
44 |
| -## Nene.Music:free (function) |
| 87 | +Wraps a (SDL_mixer) music |
| 88 | + |
| 89 | +### Music:get |
| 90 | + |
| 91 | +```lua |
| 92 | +function Music:get(): *Mix_Music |
| 93 | +``` |
| 94 | + |
| 95 | +It checks if the internal data is `nilptr` and then returns it. |
| 96 | + |
| 97 | +Related SDL_mixer documentation: |
| 98 | +* [Mix_Music](https://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer_86.html#SEC86) |
| 99 | + |
| 100 | +### Music:play |
| 101 | + |
| 102 | +```lua |
| 103 | +function Music:play(loops: facultative(integer)) |
| 104 | +``` |
| 105 | + |
| 106 | +Plays the music (forever by default), note that this stops any playing music. |
| 107 | + |
| 108 | +You can also pass a `loop` argument, this makes the music loop `loop` times, also note that: |
| 109 | +* Passing `0` will make it play the music `0` times. |
| 110 | +* Passing `1` will make it only once. |
| 111 | +* Passing `-1` will make it looping forever, this is the default value. |
| 112 | + |
| 113 | +Related MixWrapper documentation: |
| 114 | +* [MixWrapper.play_music](wrappers/mix.md#mixwrapperplay_music) |
| 115 | +* [MixWrapper.halt_music](wrappers/mix.md#mixwrapperhalt_music) |
| 116 | + |
| 117 | +### Music.stop |
45 | 118 |
|
46 | 119 | ```lua
|
47 |
| -function Nene.Music:free() |
| 120 | +function Music.stop() |
48 | 121 | ```
|
| 122 | + |
| 123 | +Stops any playing music. |
| 124 | + |
| 125 | +Related MixWrapper documentation: |
| 126 | +* [MixWrapper.halt_music](wrappers/mix.md#mixwrapperhalt_music) |
| 127 | +* [MixWrapper.play_music](wrappers/mix.md#mixwrapperplay_music) |
| 128 | + |
| 129 | +### Music:destroy |
| 130 | + |
| 131 | +```lua |
| 132 | +function Music:destroy() |
| 133 | +``` |
| 134 | + |
| 135 | +Destroy the music and resets to zeroed state. |
| 136 | + |
| 137 | +> Note: SDL_mixer first halts the music if it's playing, it also wait if it's still fading out. |
| 138 | +
|
| 139 | +Related MixWrapper documentation: |
| 140 | +* [MixWrapper.free_music](wrappers/mix.md#mixwrapperfree_music) |
| 141 | + |
| 142 | +--- |
0 commit comments