Mountain  1.0.0
Simple C++ 2D Game Framework
audio_track.hpp
1 #pragma once
2 
3 #include "Mountain/core.hpp"
4 #include "Mountain/audio/audio_buffer.hpp"
6 
7 namespace Mountain
8 {
9  enum class MOUNTAIN_API AudioTrackFormat : uint8_t
10  {
11  Wavefront,
12  OggVorbis,
13  Mp3
14  };
15 
16  class AudioTrack : public Resource
17  {
18  public:
20  MOUNTAIN_API static constexpr std::array FileExtensions
21  {
22  ".wav",
23  ".wave",
24  ".mp3",
25  ".ogg"
26  };
27 
28  // Same constructor from base class
29  using Resource::Resource;
30 
31  MOUNTAIN_API ~AudioTrack() override;
32 
33  DELETE_COPY_MOVE_OPERATIONS(AudioTrack)
34 
35  // We keep both function overloads and only override one
36  using Resource::SetSourceData;
37 
38  MOUNTAIN_API bool_t SetSourceData(const uint8_t* buffer, int64_t length) override;
39 
40  MOUNTAIN_API void Load() override;
41 
42  MOUNTAIN_API void Unload() override;
43 
44  MOUNTAIN_API void ResetSourceData() override;
45 
49  template <typename T = uint8_t>
50  [[nodiscard]]
51  const T* GetData() const;
52 
56  template <typename T = uint8_t>
57  [[nodiscard]]
58  T* GetData();
59 
60  [[nodiscard]]
61  MOUNTAIN_API int32_t GetDataSize() const;
62 
63  [[nodiscard]]
64  MOUNTAIN_API uint16_t GetChannels() const;
65 
66  [[nodiscard]]
67  MOUNTAIN_API int32_t GetSampleRate() const;
68 
69  [[nodiscard]]
70  MOUNTAIN_API uint16_t GetBitDepth() const;
71 
72  [[nodiscard]]
73  MOUNTAIN_API const AudioBuffer* GetBuffer() const;
74 
75  [[nodiscard]]
76  MOUNTAIN_API AudioTrackFormat GetFormat() const;
77 
78  private:
80  uint8_t* m_Data = nullptr;
82  int32_t m_DataSize = 0;
84  uint16_t m_Channels = 0;
86  int32_t m_SampleRate = 0;
88  uint16_t m_BitDepth = 0;
89 
90  AudioBuffer* m_Buffer = nullptr;
91 
92  AudioTrackFormat m_Format;
93 
94  MOUNTAIN_API bool_t LoadWavefront(const uint8_t* buffer, int64_t length);
95  MOUNTAIN_API int64_t LoadWavefrontFormat(const uint8_t* data);
96  MOUNTAIN_API int64_t LoadWavefrontData(const uint8_t* data);
97 
98  MOUNTAIN_API bool_t LoadOggVorbis(const uint8_t* buffer, int64_t length);
99  MOUNTAIN_API bool_t LoadMp3(const uint8_t* buffer, int64_t length);
100  };
101 }
102 
103 #include "Mountain/resource/audio_track.inl"
Defines the Mountain::Resource class.
Contains all declarations of the Mountain Framework.
Definition: audio.hpp:22