5#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__linux__) || defined(_WIN32) || defined(__HAIKU__)
47 if (this->
data !=
nullptr)
delete data;
48 this->
data = ByteBuffer::allocate(bufferSize);
53 alGetSourcei(
alSourceId, AL_SOURCE_STATE, &state);
54 return state == AL_PLAYING;
76 ALsizei buffersToPlay = 0;
85 if (alGetError() != AL_NO_ERROR) {
86 Console::println(
string(
"AudioStream::play(): '"+
id +
"': Could not upload buffer"));
92 if (alGetError() != AL_NO_ERROR) {
93 Console::println(
string(
"AudioStream::play(): '" +
id +
"': Could not queue buffers"));
96 if (alGetError() != AL_NO_ERROR) {
97 Console::println(
string(
"AudioStream::play(): '"+
id +
"': Could not play source"));
110 if (alGetError() != AL_NO_ERROR) {
111 Console::println(
string(
"AudioStream::pause(): '" +
id +
"': Could not pause"));
121 if (alGetError() != AL_NO_ERROR) {
122 Console::println(
string(
"AudioStream::stop(): '" +
id +
"': Could not stop"));
126 alGetSourcei(
alSourceId, AL_BUFFERS_QUEUED, &queuedBuffers);
127 if (alGetError() != AL_NO_ERROR) {
128 Console::println(
string(
"AudioStream::stop(): '" +
id +
"': Could not determine queued buffers"));
131 if (queuedBuffers > 0) {
132 vector<uint32_t> removedBuffers;
133 removedBuffers.resize(queuedBuffers);
134 alSourceUnqueueBuffers(
alSourceId, queuedBuffers, removedBuffers.data());
135 if (alGetError() != AL_NO_ERROR) {
136 Console::println(
string(
"AudioStream::stop(): '" +
id +
"': Could not unqueue buffers"));
147 case(1):
format = AL_FORMAT_MONO16;
break;
148 case(2):
format = AL_FORMAT_STEREO16;
break;
150 Console::println(
string(
"AudioStream::initialize(): '" +
id +
"': Unsupported number of channels"));
154 if (alGetError() != AL_NO_ERROR) {
155 Console::println(
string(
"AudioStream::initialize(): '" +
id +
"': Could not generate buffer"));
160 if (alGetError() != AL_NO_ERROR) {
161 Console::println(
string(
"AudioStream::initialize(): '" +
id +
"': Could not generate source"));
177 int32_t processedBuffers;
178 alGetSourcei(
alSourceId, AL_BUFFERS_PROCESSED, &processedBuffers);
179 if (alGetError() != AL_NO_ERROR) {
180 Console::println(
string(
"AudioStream::update(): '" +
id +
"': Could not determine processed buffers"));
185 while (processedBuffers > 0) {
187 uint32_t processedBufferId;
188 alSourceUnqueueBuffers(
alSourceId, 1, &processedBufferId);
189 if (alGetError() != AL_NO_ERROR) {
190 Console::println(
string(
"AudioStream::update(): '" +
id +
"': Could not unqueue buffers"));
201 if (alGetError() != AL_NO_ERROR) {
202 Console::println(
string(
"AudioStream::update(): '" +
id +
"': Could not upload buffer"));
205 alSourceQueueBuffers(
alSourceId, 1, &processedBufferId);
206 if (alGetError() != AL_NO_ERROR) {
207 Console::println(
string(
"AudioStream::update(): '" +
id +
"': Could not queue buffer"));
231 alSourcef(
alSourceId, AL_ROLLOFF_FACTOR, 0.0f);
232 alSourcei(
alSourceId, AL_SOURCE_RELATIVE, AL_TRUE);
234 alSourcef(
alSourceId, AL_ROLLOFF_FACTOR, 1.0f);
235 alSourcei(
alSourceId, AL_SOURCE_RELATIVE, AL_FALSE);
246 if (alGetError() != AL_NO_ERROR) {
247 Console::println(
string(
"AudioStream::dispose(): '" +
id +
"': Could not delete source"));
253 if (alGetError() != AL_NO_ERROR) {
254 Console::println(
string(
"AudioStream::dispose(): '" +
id +
"': Could not delete buffers"));
259 if (
data !=
nullptr) {
virtual void play() override
Plays this audio entity.
virtual void rewind() override
Rewinds this audio entity.
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.
virtual bool isPlaying() override
array< uint32_t, 2 > alBufferIds
virtual void fillBuffer(ByteBuffer *data)=0
Fill buffer.
virtual ~AudioStream()
Destructor.
virtual void stop() override
Stops this audio entity.
virtual void pause() override
Pauses this audio entity.
Interface to audio module.
static constexpr int32_t ALSOURCEID_NONE
array< float, 3 > & getArray() const
virtual int32_t getPosition()
virtual int32_t getCapacity()