comparison libmlk-core/mlk/core/sound.h @ 641:fcd124e513ea

core: reintroduce VFS
author David Demelier <markand@malikania.fr>
date Sun, 01 Oct 2023 09:18:01 +0200
parents 848897bfef2f
children
comparison
equal deleted inserted replaced
640:9850089c9671 641:fcd124e513ea
29 * can't be looped. 29 * can't be looped.
30 */ 30 */
31 31
32 #include <stddef.h> 32 #include <stddef.h>
33 33
34 struct mlk_vfs_file;
35
34 /** 36 /**
35 * \struct mlk_music 37 * \struct mlk_music
36 * \brief Music structure 38 * \brief Music structure
37 * 39 *
38 * This structure is non-opaque but has no public fields. 40 * This structure is non-opaque but has no public fields.
52 * 54 *
53 * \pre music != NULL 55 * \pre music != NULL
54 * \pre path != NULL 56 * \pre path != NULL
55 * \param sound the sound to initialize 57 * \param sound the sound to initialize
56 * \param path the path to the music file (e.g. .ogg, .wav, .mp3, etc) 58 * \param path the path to the music file (e.g. .ogg, .wav, .mp3, etc)
57 * \return 0 on success or an error code on failure 59 * \return 0 on success or -1 on error
58 */ 60 */
59 int 61 int
60 mlk_sound_open(struct mlk_sound *sound, const char *path); 62 mlk_sound_open(struct mlk_sound *sound, const char *path);
61 63
62 /** 64 /**
65 * The binary data must be kept alive until the sound is no longer used. 67 * The binary data must be kept alive until the sound is no longer used.
66 * 68 *
67 * \pre music != NULL 69 * \pre music != NULL
68 * \pre path != NULL 70 * \pre path != NULL
69 * \param sound the sound to initialize 71 * \param sound the sound to initialize
70 * \param data the font content 72 * \param data the sound data
71 * \param datasz the font content length 73 * \param datasz the sound data length
72 * \return 0 on success or an error code on failure 74 * \return 0 on success or -1 on error
73 */ 75 */
74 int 76 int
75 mlk_sound_openmem(struct mlk_sound *sound, const void *data, size_t datasz); 77 mlk_sound_openmem(struct mlk_sound *sound, const void *data, size_t datasz);
76 78
77 /** 79 /**
78 * Tells if the sound structure is usable. 80 * Open a sound from a virtual file system.
79 * 81 *
80 * \param sound the sound to check 82 * The VFS file can be discarded after loading the sound.
81 * \return non-zero if the sound structure is usable 83 *
84 * \pre sound != NULL
85 * \pre file != NULL
86 * \param sound the sound to initialize
87 * \param file the VFS file
88 * \return 0 on success or -1 on error
82 */ 89 */
83 int 90 int
84 mlk_sound_ok(const struct mlk_sound *sound); 91 mlk_sound_openvfs(struct mlk_sound *snd, struct mlk_vfs_file *file);
85 92
86 /** 93 /**
87 * Start playing the sound. 94 * Start playing the sound.
88 * 95 *
89 * \pre mlk_sound_ok(sound) 96 * \pre sound != NULL
90 * \param sound the sound to play 97 * \param sound the sound to play
91 * \return 0 on success or an error code on failure 98 * \return 0 on success or -1 on error
92 */ 99 */
93 int 100 int
94 mlk_sound_play(struct mlk_sound *sound); 101 mlk_sound_play(struct mlk_sound *sound);
95 102
96 /** 103 /**
97 * Pause the sound playback. 104 * Pause the sound playback.
98 * 105 *
99 * \pre mlk_sound_ok(sound) 106 * \pre sound != NULL
100 * \param sound the sound to pause 107 * \param sound the sound to pause
101 * \sa ::mlk_sound_resume 108 * \sa ::mlk_sound_resume
102 */ 109 */
103 void 110 void
104 mlk_sound_pause(struct mlk_sound *sound); 111 mlk_sound_pause(struct mlk_sound *sound);
105 112
106 /** 113 /**
107 * Resume the sound where it was stopped. 114 * Resume the sound where it was stopped.
108 * 115 *
109 * \pre mlk_sound_ok(sound) 116 * \pre sound != NULL
110 * \param sound the sound to resume 117 * \param sound the sound to resume
111 * \sa ::mlk_sound_pause 118 * \sa ::mlk_sound_pause
112 */ 119 */
113 void 120 void
114 mlk_sound_resume(struct mlk_sound *sound); 121 mlk_sound_resume(struct mlk_sound *sound);
116 /** 123 /**
117 * Stop and rewind the sound. 124 * Stop and rewind the sound.
118 * 125 *
119 * Calling ::mlk_sound_resume on it will restart from the beginning. 126 * Calling ::mlk_sound_resume on it will restart from the beginning.
120 * 127 *
121 * \pre mlk_sound_ok(sound) 128 * \pre sound != NULL
122 * \param sound the sound to stop 129 * \param sound the sound to stop
123 * \sa ::mlk_sound_resume 130 * \sa ::mlk_sound_resume
124 * \sa ::mlk_sound_play 131 * \sa ::mlk_sound_play
125 */ 132 */
126 void 133 void