Doxybook2 Example
AudioBuffer.hpp
Go to the documentation of this file.
1 #pragma once
2 #include "../Utils/ArrayView.hpp"
3 
4 namespace Engine {
5  namespace Audio {
6  class AudioManager;
7  class AudioBuffer;
8 
15  typedef int (*Callback)(AudioBuffer& buffer, size_t offset);
16 
23  using Callback2 = int (*)(AudioBuffer& buffer, size_t offset, void* user);
24 
28  extern void doSomething(AudioBuffer& buffer);
29 
60  class AudioBuffer {
61  public:
65  enum class Type {
69  UNKNOWN = 0,
73  INT_8 = 1 << 1,
77  INT_16 = 1 << 2,
81  INT_24 = 1 << 3,
85  INT_32 = 1 << 4,
89  FLOAT_32 = 1 << 5
90  };
91  template <typename T> using AudioData = Utils::ArrayView<T>;
96  struct TypedAudioData {
99  };
103  explicit AudioBuffer(const std::string& filename);
107  virtual ~AudioBuffer() = default;
113  void play(AudioManager& manager) const;
119  void stop(AudioManager& manager) const;
126  void loop(AudioManager& manager) const;
127  void setData(const TypedAudioData& data);
128 
129  template <size_t Size> void setDataMultiple(const TypedAudioData data[Size]) {
130  }
131 
136  void setData(const TypedAudioData data[], size_t size);
137 
138  friend class AudioManager;
139  friend void Audio::doSomething(AudioBuffer& buffer);
140 
147  void setCallback(Callback callback);
148 
154  void setCallback2(Callback2 callback, void* user);
155 
156  protected:
157  float* getData();
158  bool playing{false};
159  };
160  } // namespace Audio
161 } // namespace Engine
Engine::Audio::Callback
int(* Callback)(AudioBuffer &buffer, size_t offset)
Some callback function pointer type definition.
Definition: AudioBuffer.hpp:15
Engine::Audio::AudioBuffer::setData
void setData(const TypedAudioData &data)
Engine::Audio::AudioBuffer::Type
Type
Different type of audio formats.
Definition: AudioBuffer.hpp:65
Engine::Audio::AudioBuffer::AudioBuffer
AudioBuffer(const std::string &filename)
Constructor for Audio::AudioBuffer.
Engine::Audio::AudioBuffer::playing
bool playing
Definition: AudioBuffer.hpp:158
Engine::Utils::ArrayView
Filesystem path utility functions.
Definition: ArrayView.hpp:11
Engine::Audio::AudioBuffer::TypedAudioData::buffer
AudioData8U buffer
Definition: AudioBuffer.hpp:97
Engine::Audio::doSomething
void doSomething(AudioBuffer &buffer)
Do something with the buffer.
Engine::Audio::AudioBuffer::Type::UNKNOWN
@ UNKNOWN
Engine::Audio::AudioBuffer::setCallback
void setCallback(Callback callback)
Set the callback function.
Engine::Audio::AudioBuffer::TypedAudioData::type
Type type
Definition: AudioBuffer.hpp:98
Engine::Audio::AudioBuffer::loop
void loop(AudioManager &manager) const
Loop this buffer forever.
Engine::Audio::AudioBuffer::setDataMultiple
void setDataMultiple(const TypedAudioData data[Size])
Definition: AudioBuffer.hpp:129
Engine::Audio::AudioBuffer::play
void play(AudioManager &manager) const
Play this buffer.
Engine::Audio::AudioBuffer::Type::INT_32
@ INT_32
Engine::Audio::AudioBuffer::AudioData8U
AudioData< uint8_t > AudioData8U
Definition: AudioBuffer.hpp:92
Engine::Audio::AudioBuffer::setCallback2
void setCallback2(Callback2 callback, void *user)
Set the callback function.
Engine::Audio::AudioBuffer
A simple audio buffer to hold PCM samples
Definition: AudioBuffer.hpp:60
Engine::Audio::AudioBuffer::getData
float * getData()
Engine::Audio::AudioBuffer::Type::FLOAT_32
@ FLOAT_32
Engine::Audio::AudioBuffer::stop
void stop(AudioManager &manager) const
Stop this buffer playing.
Engine::Audio::AudioBuffer::TypedAudioData
Use this to populate the buffer.
Definition: AudioBuffer.hpp:96
Engine::Audio::AudioBuffer::Type::INT_8
@ INT_8
Engine::Audio::AudioBuffer::~AudioBuffer
virtual ~AudioBuffer()=default
Audio::AudioBuffer destructor.
Engine
This namespace contains all of the necessary engine components.
Definition: Asset.hpp:5
Engine::Audio::AudioManager
An audio manager that accepts multiple Audio::AudioBuffer instances.
Definition: AudioManager.hpp:17
Engine::Audio::Callback2
int(*)(AudioBuffer &buffer, size_t offset, void *user) Callback2
Some callback function pointer type definition.
Definition: AudioBuffer.hpp:23
Engine::Audio::AudioBuffer::Type::INT_24
@ INT_24
Engine::Audio::AudioBuffer::Type::INT_16
@ INT_16