1 | /** |
2 | * Copyright (c) 2006-2023 LOVE Development Team |
3 | * |
4 | * This software is provided 'as-is', without any express or implied |
5 | * warranty. In no event will the authors be held liable for any damages |
6 | * arising from the use of this software. |
7 | * |
8 | * Permission is granted to anyone to use this software for any purpose, |
9 | * including commercial applications, and to alter it and redistribute it |
10 | * freely, subject to the following restrictions: |
11 | * |
12 | * 1. The origin of this software must not be misrepresented; you must not |
13 | * claim that you wrote the original software. If you use this software |
14 | * in a product, an acknowledgment in the product documentation would be |
15 | * appreciated but is not required. |
16 | * 2. Altered source versions must be plainly marked as such, and must not be |
17 | * misrepresented as being the original software. |
18 | * 3. This notice may not be removed or altered from any source distribution. |
19 | **/ |
20 | |
21 | #ifndef LOVE_SOUND_LULLABY_LIBMPG123_DECODER_H |
22 | #define LOVE_SOUND_LULLABY_LIBMPG123_DECODER_H |
23 | |
24 | // LOVE |
25 | #include "common/Data.h" |
26 | #include "sound/Decoder.h" |
27 | |
28 | #ifndef LOVE_NOMPG123 |
29 | |
30 | // libmpg123 |
31 | #ifdef LOVE_APPLE_USE_FRAMEWORKS |
32 | #include <mpg123/mpg123.h> |
33 | #else |
34 | #include <mpg123.h> |
35 | #endif |
36 | |
37 | namespace love |
38 | { |
39 | namespace sound |
40 | { |
41 | namespace lullaby |
42 | { |
43 | |
44 | struct DecoderFile |
45 | { |
46 | unsigned char *data; |
47 | size_t size; |
48 | size_t offset; |
49 | |
50 | DecoderFile(Data *d) |
51 | : data((unsigned char *) d->getData()) |
52 | , size(d->getSize()) |
53 | , offset(0) |
54 | {} |
55 | }; |
56 | |
57 | class Mpg123Decoder : public Decoder |
58 | { |
59 | public: |
60 | |
61 | Mpg123Decoder(Data *data, int bufferSize); |
62 | virtual ~Mpg123Decoder(); |
63 | |
64 | static bool accepts(const std::string &ext); |
65 | static void quit(); |
66 | |
67 | love::sound::Decoder *clone(); |
68 | int decode(); |
69 | bool seek(double s); |
70 | bool rewind(); |
71 | bool isSeekable(); |
72 | int getChannelCount() const; |
73 | int getBitDepth() const; |
74 | double getDuration(); |
75 | |
76 | private: |
77 | |
78 | DecoderFile decoder_file; |
79 | |
80 | mpg123_handle *handle; |
81 | static bool inited; |
82 | |
83 | int channels; |
84 | |
85 | double duration; |
86 | |
87 | }; // Decoder |
88 | |
89 | } // lullaby |
90 | } // sound |
91 | } // love |
92 | |
93 | #endif // LOVE_NOMPG123 |
94 | |
95 | #endif // LOVE_SOUND_LULLABY_LIBMPG123_DECODER_H |
96 | |