libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
audio.h
Go to the documentation of this file.
1
8#pragma once
9
13#include <promeki/core/buffer.h>
14#include <promeki/core/list.h>
15
17
35class Audio {
37 public:
40
43
46
48 Audio() = default;
49
56 Audio(const AudioDesc &desc, size_t samples,
57 const MemSpace &ms = MemSpace::Default);
58
63 bool isValid() const {
64 return _desc.isValid();
65 }
66
71 bool isNative() const {
72 return _desc.isNative();
73 }
74
79 const AudioDesc &desc() const {
80 return _desc;
81 }
82
87 size_t samples() const {
88 return _samples;
89 }
90
95 size_t maxSamples() const {
96 return _maxSamples;
97 }
98
103 size_t frames() const {
104 return _samples * _desc.channels();
105 }
106
111 const Buffer::Ptr &buffer() const {
112 return _buffer;
113 }
114
120 return _buffer;
121 }
122
124 void zero() const {
125 _buffer->fill(0);
126 return;
127 }
128
140
146 bool resize(size_t val) {
147 if(val > _maxSamples) return false;
148 _samples = val;
149 return true;
150 }
151
157 template <typename T> T *data() const {
158 return reinterpret_cast<T *>(_buffer->data());
159 }
160
161 private:
162 Buffer::Ptr _buffer;
163 AudioDesc _desc;
164 size_t _samples = 0;
165 size_t _maxSamples = 0;
166
167 bool allocate(const MemSpace &ms);
168};
169
Describes an audio format including sample type, rate, and channel count.
Definition audiodesc.h:28
unsigned int channels() const
Returns the number of audio channels.
Definition audiodesc.h:424
DataType
Enumeration of supported audio sample data types.
Definition audiodesc.h:190
bool isValid() const
Returns true if this audio description has a valid data type, sample rate, and channel count.
Definition audiodesc.h:297
bool isNative() const
Returns true if the data type is the platform's native float format.
Definition audiodesc.h:305
Object to hold some number of audio samples.
Definition audio.h:35
bool isNative() const
Returns true if the audio is in the native float32 format for this system.
Definition audio.h:71
void zero() const
Zeros out all the audio data in the buffer.
Definition audio.h:124
size_t samples() const
Returns the number of samples, irrespective of the channel count.
Definition audio.h:87
Buffer::Ptr & buffer()
Returns a mutable reference to the buffer shared pointer.
Definition audio.h:119
Audio(const AudioDesc &desc, size_t samples, const MemSpace &ms=MemSpace::Default)
Constructs an Audio object for the given descriptor and sample count.
promeki::List< Ptr > PtrList
List of shared Audio pointers.
Definition audio.h:45
const Buffer::Ptr & buffer() const
Returns a const reference to the buffer that holds the audio data.
Definition audio.h:111
T * data() const
Returns the audio data pointer cast to the given type.
Definition audio.h:157
SharedPtr< Audio > Ptr
Shared pointer type for Audio.
Definition audio.h:39
Audio convertTo(AudioDesc::DataType format) const
Converts this Audio to a different sample format.
promeki::List< Audio > List
List of Audio values.
Definition audio.h:42
size_t frames() const
Returns the total number of sample frames (samples times channels).
Definition audio.h:103
Audio()=default
Constructs an invalid Audio object.
bool resize(size_t val)
Resizes the sample count to a value between 0 and maxSamples().
Definition audio.h:146
size_t maxSamples() const
Returns the maximum number of samples this object can contain.
Definition audio.h:95
bool isValid() const
Returns true if the object is valid.
Definition audio.h:63
const AudioDesc & desc() const
Returns the AudioDesc that describes the audio contained in this object.
Definition audio.h:79
Dynamic array container wrapping std::vector.
Definition list.h:40
List()=default
Default constructor. Creates an empty list.
T * data() noexcept
Returns a pointer to the underlying contiguous storage.
Definition list.h:286
Abstraction for memory allocation in different address spaces.
Definition memspace.h:30
@ Default
Alias for System memory.
Definition memspace.h:36
#define PROMEKI_NAMESPACE_BEGIN
Starts a promeki namespace block.
Definition namespace.h:14
#define PROMEKI_NAMESPACE_END
Ends a promeki namespace block.
Definition namespace.h:19
#define PROMEKI_SHARED_FINAL(TYPE)
Macro for non-polymorphic native shared objects.
Definition sharedptr.h:88