Commit | Line | Data |
---|---|---|
3719602c PC |
1 | /* Copyright (C) 2010-2020 The RetroArch team |
2 | * | |
3 | * --------------------------------------------------------------------------------------- | |
4 | * The following license statement only applies to this file (rwav.h). | |
5 | * --------------------------------------------------------------------------------------- | |
6 | * | |
7 | * Permission is hereby granted, free of charge, | |
8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), | |
9 | * to deal in the Software without restriction, including without limitation the rights to | |
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, | |
11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |
12 | * | |
13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | |
16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | |
19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
21 | */ | |
22 | ||
23 | #ifndef __LIBRETRO_SDK_FORMAT_RWAV_H__ | |
24 | #define __LIBRETRO_SDK_FORMAT_RWAV_H__ | |
25 | ||
26 | #include <retro_common_api.h> | |
27 | #include <stdint.h> | |
28 | ||
29 | RETRO_BEGIN_DECLS | |
30 | ||
31 | typedef struct | |
32 | { | |
33 | /* bits per sample */ | |
34 | unsigned int bitspersample; | |
35 | ||
36 | /* number of channels */ | |
37 | unsigned int numchannels; | |
38 | ||
39 | /* sample rate */ | |
40 | unsigned int samplerate; | |
41 | ||
42 | /* number of *samples* */ | |
43 | size_t numsamples; | |
44 | ||
45 | /* number of *bytes* in the pointer below, i.e. numsamples * numchannels * bitspersample/8 */ | |
46 | size_t subchunk2size; | |
47 | ||
48 | /* PCM data */ | |
49 | const void* samples; | |
50 | } rwav_t; | |
51 | ||
52 | enum rwav_state | |
53 | { | |
54 | RWAV_ITERATE_ERROR = -1, | |
55 | RWAV_ITERATE_MORE = 0, | |
56 | RWAV_ITERATE_DONE = 1, | |
57 | RWAV_ITERATE_BUF_SIZE = 4096 | |
58 | }; | |
59 | ||
60 | typedef struct rwav_iterator rwav_iterator_t; | |
61 | ||
62 | /** | |
63 | * Initializes the iterator to fill the out structure with data parsed from buf. | |
64 | */ | |
65 | void rwav_init(rwav_iterator_t* iter, rwav_t* out, const void* buf, size_t size); | |
66 | ||
67 | /** | |
68 | * Parses a piece of the data. Continue calling as long as it returns RWAV_ITERATE_MORE. | |
69 | * Stop calling otherwise, and check for errors. If RWAV_ITERATE_DONE is returned, | |
70 | * the rwav_t structure passed to rwav_init is ready to be used. The iterator does not | |
71 | * have to be freed. | |
72 | */ | |
73 | enum rwav_state rwav_iterate(rwav_iterator_t *iter); | |
74 | ||
75 | /** | |
76 | * Loads the entire data in one go. | |
77 | */ | |
78 | enum rwav_state rwav_load(rwav_t* out, const void* buf, size_t size); | |
79 | ||
80 | /** | |
81 | * Frees parsed wave data. | |
82 | */ | |
83 | void rwav_free(rwav_t *rwav); | |
84 | ||
85 | RETRO_END_DECLS | |
86 | ||
87 | #endif |