Use StringViews to reference buffers and decoders
[alure.git] / src / buffer.h
blob5ccbc5bbabcbb7f9197a4705a4b5259247cc56d9
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 Vector<Source> mSources;
28 const String mName;
30 public:
31 BufferImpl(ContextImpl *context, ALuint id, ALuint freq, ChannelConfig config, SampleType type, StringView name)
32 : mContext(context), mId(id), mFrequency(freq), mChannelConfig(config), mSampleType(type)
33 , mName(String(name))
34 { }
36 void cleanup();
38 ContextImpl *getContext() { return mContext; }
39 ALuint getId() const { return mId; }
41 void addSource(Source source) { mSources.push_back(source); }
42 void removeSource(Source source)
44 auto iter = std::find(mSources.cbegin(), mSources.cend(), source);
45 if(iter != mSources.cend()) mSources.erase(iter);
48 void load(ALuint frames, ALenum format, SharedPtr<Decoder> decoder, ContextImpl *ctx);
50 ALuint getLength() const;
52 ALuint getFrequency() const { return mFrequency; }
53 ChannelConfig getChannelConfig() const { return mChannelConfig; }
54 SampleType getSampleType() const { return mSampleType; }
56 ALuint getSize() const;
58 void setLoopPoints(ALuint start, ALuint end);
59 std::pair<ALuint,ALuint> getLoopPoints() const;
61 Vector<Source> getSources() const { return mSources; }
63 const String &getName() const { return mName; }
65 bool isInUse() const { return (mSources.size() > 0); }
68 } // namespace alure
70 #endif /* BUFFER_H */