TDME2 1.9.121
AudioStream.h
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <string>
5
6#include <tdme/tdme.h>
10
11using std::array;
12using std::string;
13
16
17/**
18 * Audio stream
19 * @author Andreas Drewke
20 * @version $Id$
21 */
23 : public AudioEntity
24{
25 friend class Audio;
26
27private:
28 bool initiated { false };
29 array<uint32_t, 2> alBufferIds;
30 uint32_t alSourceId;
31 uint32_t sampleRate;
32 uint8_t channels;
33 ByteBuffer* data { nullptr };
34 int32_t format;
35 bool playing { false };
36
37protected:
38 /**
39 * Protected constructor
40 * @param id id
41 */
42 AudioStream(const string& id);
43
44 /**
45 * Destructor
46 */
47 virtual ~AudioStream();
48
49 // overridden methods
50 virtual bool initialize() override;
51 virtual void update() override;
52 virtual void dispose() override;
53
54 /**
55 * Fill buffer
56 * @param data data
57 */
58 virtual void fillBuffer(ByteBuffer* data) = 0;
59
60public:
61 /**
62 * Set audio initialization parameters
63 * @param sampleRate sample rate
64 * @param channels channels
65 * @param bufferSize buffer size
66 */
67 virtual void setParameters(uint32_t sampleRate, uint8_t channels, const uint32_t bufferSize = 32768);
68
69 // overridden methods
70 virtual bool isPlaying() override;
71 virtual void rewind() override;
72 virtual void play() override;
73 virtual void pause() override;
74 virtual void stop() override;
75
76private:
77 /**
78 * @return having buffers that are currently played
79 */
80 bool isPlayingBuffers();
81
82 /**
83 * Updates properties to Open AL
84 */
85 void updateProperties();
86
87};
Audio entity base class.
Definition: AudioEntity.h:20
virtual void play() override
Plays this audio entity.
Definition: AudioStream.cpp:66
virtual void rewind() override
Rewinds this audio entity.
Definition: AudioStream.cpp:62
virtual void dispose() override
Dispose this entity from OpenAL.
void updateProperties()
Updates properties to Open AL.
virtual void update() override
Commits properties to OpenAl.
virtual bool initialize() override
Initiates this OpenAL entity to OpenAl.
virtual void setParameters(uint32_t sampleRate, uint8_t channels, const uint32_t bufferSize=32768)
Set audio initialization parameters.
Definition: AudioStream.cpp:44
virtual bool isPlaying() override
Definition: AudioStream.cpp:57
array< uint32_t, 2 > alBufferIds
Definition: AudioStream.h:29
virtual void fillBuffer(ByteBuffer *data)=0
Fill buffer.
virtual ~AudioStream()
Destructor.
Definition: AudioStream.cpp:41
virtual void stop() override
Stops this audio entity.
AudioStream(const string &id)
Protected constructor.
Definition: AudioStream.cpp:31
virtual void pause() override
Pauses this audio entity.
Interface to audio module.
Definition: Audio.h:30
Byte buffer class.
Definition: ByteBuffer.h:24