5 #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__linux__) || defined(_WIN32) || defined(__HAIKU__)
29 using std::unique_ptr;
41 bool Sound::isPlaying()
44 alGetSourcei(
alSourceId, AL_SOURCE_STATE, &state);
45 return (state == AL_PLAYING);
54 if (alGetError() != AL_NO_ERROR) {
55 Console::println(
string(
"Audio sound: '" +
id +
"': Could not rewind"));
67 if (alGetError() != AL_NO_ERROR) {
68 Console::println(
string(
"Audio sound: '" +
id +
"': Could not play"));
78 if (alGetError() != AL_NO_ERROR) {
79 Console::println(
string(
"Audio sound: '" +
id+
"': Could not pause"));
89 if (alGetError() != AL_NO_ERROR) {
90 Console::println(
string(
"Audio sound: '" +
id +
"': Could not stop"));
102 if (alGetError() != AL_NO_ERROR) {
103 Console::println(
string(
"Audio sound: '" +
id +
"': Could not generate buffer"));
113 unique_ptr<ByteBuffer> data;
123 " bits per sample, " +
132 case(1): format = AL_FORMAT_MONO16;
break;
133 case(2): format = AL_FORMAT_STEREO16;
break;
135 Console::println(
string(
"Audio sound: '" +
id +
"': Unsupported number of channels"));
137 data = unique_ptr<ByteBuffer>(ByteBuffer::allocate(2 * 2 * decoder.
getSamples()));
147 to_string(data->getPosition()) +
152 Console::println(
string(
"Audio sound: '" + (
id) +
"': " + fse.what()));
157 Console::println(
string(
"Audio sound: '" + (
id) +
"': " + ade.what()));
164 if (format == -1 || frequency == -1) {
165 Console::println(
string(
"Audio sound: '" +
id +
"': Format or frequency invalid"));
170 alBufferData(
alBufferId, format, data->getBuffer(), data->getPosition(), frequency);
171 if (alGetError() != AL_NO_ERROR) {
172 Console::println(
string(
"Audio sound: '" +
id +
"': Could not upload buffer data"));
182 if (alGetError() != AL_NO_ERROR) {
183 Console::println(
string(
"Audio sound: '" +
id +
"': Could not generate source"));
207 alSourcef(
alSourceId, AL_ROLLOFF_FACTOR, 0.0f);
208 alSourcei(
alSourceId, AL_SOURCE_RELATIVE, AL_TRUE);
210 alSourcef(
alSourceId, AL_ROLLOFF_FACTOR, 1.0f);
211 alSourcei(
alSourceId, AL_SOURCE_RELATIVE, AL_FALSE);
219 if (alGetError() != AL_NO_ERROR) {
220 Console::println(
string(
"Audio sound: '" +
id +
"': Could not delete source"));
226 if (alGetError() != AL_NO_ERROR) {
227 Console::println(
string(
"Audio sound: '" +
id +
"': Could not delete buffers"));
Managed audio buffer entity.
AudioBufferManager_AudioBufferManaged * addAudioBuffer(const string &id)
Adds a audio buffer to manager / open al stack.
Interface to audio module.
static constexpr uint32_t ALSOURCEID_NONE
static constexpr uint32_t ALBUFFERID_NONE
static STATIC_DLL_IMPEXT Audio * instance
AudioBufferManager audioBufferManager
Sound audio entity implementation.
void play() override
Plays this audio entity.
void rewind() override
Rewinds this audio entity.
void dispose() override
Dispose this entity from OpenAL.
void update() override
Commits properties to OpenAl.
bool initialize() override
Initiates this OpenAL entity to OpenAl.
void stop() override
Stops this audio entity.
void pause() override
Pauses this audio entity.
uint8_t getChannels() const
uint8_t getBitsPerSample() const
uint64_t getSamples() const
uint32_t getSampleRate() const
OGG/Vorbis audio decoder.
void close() override
Closes the audio file.
int64_t readFromStream(ByteBuffer *data) override
Read raw PCM data from stream.
void openFile(const string &pathName, const string &fileName) override
Open a local file.
Vector3 class representing vector3 mathematical structure and operations with x, y,...
const array< float, 3 > & getArray() const