Use return value optimization for getSec/SampleOffsetLatency
[alure.git] / src / buffer.h
blob6b28acfd382065522900dd0ac29de1edd63968a9
1 #ifndef BUFFER_H
2 #define BUFFER_H
4 #include "main.h"
6 #include <algorithm>
8 #include "al.h"
10 #include "refcount.h"
12 namespace alure {
14 class ContextImpl;
16 ALenum GetFormat(ChannelConfig chans, SampleType type);
18 class BufferImpl {
19 ContextImpl *const mContext;
20 ALuint mId;
22 ALuint mFrequency;
23 ChannelConfig mChannelConfig;
24 SampleType mSampleType;
26 BufferLoadStatus mLoadStatus;
27 std::atomic<bool> mIsLoaded;
29 Vector<Source> mSources;
31 const String mName;
33 public:
34 BufferImpl(ContextImpl *context, ALuint id, ALuint freq, ChannelConfig config, SampleType type, bool preloaded, const String &name)
35 : mContext(context), mId(id), mFrequency(freq), mChannelConfig(config), mSampleType(type),
36 mLoadStatus(preloaded ? BufferLoadStatus::Ready : BufferLoadStatus::Pending),
37 mIsLoaded(preloaded), mName(name)
38 { }
40 void cleanup();
42 ContextImpl *getContext() { return mContext; }
43 ALuint getId() const { return mId; }
45 void addSource(Source source) { mSources.push_back(source); }
46 void removeSource(Source source)
48 auto iter = std::find(mSources.cbegin(), mSources.cend(), source);
49 if(iter != mSources.cend()) mSources.erase(iter);
52 void load(ALuint frames, ALenum format, SharedPtr<Decoder> decoder, const String &name, ContextImpl *ctx);
54 bool isReady() const { return mLoadStatus == BufferLoadStatus::Ready; }
56 ALuint getLength() const;
58 ALuint getFrequency() const { return mFrequency; }
59 ChannelConfig getChannelConfig() const { return mChannelConfig; }
60 SampleType getSampleType() const { return mSampleType; }
62 ALuint getSize() const;
64 void setLoopPoints(ALuint start, ALuint end);
65 std::pair<ALuint,ALuint> getLoopPoints() const;
67 Vector<Source> getSources() const { return mSources; }
69 BufferLoadStatus getLoadStatus();
71 const String &getName() const { return mName; }
73 bool isInUse() const { return (mSources.size() > 0); }
76 } // namespace alure
78 #endif /* BUFFER_H */