minor refactor
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
#include "../../debug/Logger.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
static debug::Logger logger("al-audio");
|
||||
|
||||
@@ -24,14 +23,14 @@ ALSound::~ALSound() {
|
||||
buffer = 0;
|
||||
}
|
||||
|
||||
Speaker* ALSound::newInstance(int priority, int channel) const {
|
||||
std::unique_ptr<Speaker> ALSound::newInstance(int priority, int channel) const {
|
||||
uint source = al->getFreeSource();
|
||||
if (source == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
AL_CHECK(alSourcei(source, AL_BUFFER, buffer));
|
||||
|
||||
auto speaker = new ALSpeaker(al, source, priority, channel);
|
||||
auto speaker = std::make_unique<ALSpeaker>(al, source, priority, channel);
|
||||
speaker->duration = duration;
|
||||
return speaker;
|
||||
}
|
||||
@@ -67,7 +66,7 @@ bool ALStream::preloadBuffer(uint buffer, bool loop) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Speaker* ALStream::createSpeaker(bool loop, int channel) {
|
||||
std::unique_ptr<Speaker> ALStream::createSpeaker(bool loop, int channel) {
|
||||
this->loop = loop;
|
||||
uint source = al->getFreeSource();
|
||||
if (source == 0) {
|
||||
@@ -80,7 +79,7 @@ Speaker* ALStream::createSpeaker(bool loop, int channel) {
|
||||
}
|
||||
AL_CHECK(alSourceQueueBuffers(source, 1, &buffer));
|
||||
}
|
||||
return new ALSpeaker(al, source, PRIORITY_HIGH, channel);
|
||||
return std::make_unique<ALSpeaker>(al, source, PRIORITY_HIGH, channel);
|
||||
}
|
||||
|
||||
|
||||
@@ -379,15 +378,15 @@ ALAudio::~ALAudio() {
|
||||
context = nullptr;
|
||||
}
|
||||
|
||||
Sound* ALAudio::createSound(std::shared_ptr<PCM> pcm, bool keepPCM) {
|
||||
std::unique_ptr<Sound> ALAudio::createSound(std::shared_ptr<PCM> pcm, bool keepPCM) {
|
||||
auto format = AL::to_al_format(pcm->channels, pcm->bitsPerSample);
|
||||
uint buffer = getFreeBuffer();
|
||||
AL_CHECK(alBufferData(buffer, format, pcm->data.data(), pcm->data.size(), pcm->sampleRate));
|
||||
return new ALSound(this, buffer, pcm, keepPCM);
|
||||
return std::make_unique<ALSound>(this, buffer, pcm, keepPCM);
|
||||
}
|
||||
|
||||
Stream* ALAudio::openStream(std::shared_ptr<PCMStream> stream, bool keepSource) {
|
||||
return new ALStream(this, stream, keepSource);
|
||||
std::unique_ptr<Stream> ALAudio::openStream(std::shared_ptr<PCMStream> stream, bool keepSource) {
|
||||
return std::make_unique<ALStream>(this, stream, keepSource);
|
||||
}
|
||||
|
||||
ALAudio* ALAudio::create() {
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace audio {
|
||||
return pcm;
|
||||
}
|
||||
|
||||
Speaker* newInstance(int priority, int channel) const override;
|
||||
std::unique_ptr<Speaker> newInstance(int priority, int channel) const override;
|
||||
};
|
||||
|
||||
class ALStream : public Stream {
|
||||
@@ -65,7 +65,7 @@ namespace audio {
|
||||
|
||||
std::shared_ptr<PCMStream> getSource() const override;
|
||||
void bindSpeaker(speakerid_t speaker) override;
|
||||
Speaker* createSpeaker(bool loop, int channel) override;
|
||||
std::unique_ptr<Speaker> createSpeaker(bool loop, int channel) override;
|
||||
speakerid_t getSpeaker() const override;
|
||||
void update(double delta) override;
|
||||
|
||||
@@ -148,8 +148,8 @@ namespace audio {
|
||||
|
||||
std::vector<std::string> getAvailableDevices() const;
|
||||
|
||||
Sound* createSound(std::shared_ptr<PCM> pcm, bool keepPCM) override;
|
||||
Stream* openStream(std::shared_ptr<PCMStream> stream, bool keepSource) override;
|
||||
std::unique_ptr<Sound> createSound(std::shared_ptr<PCM> pcm, bool keepPCM) override;
|
||||
std::unique_ptr<Stream> openStream(std::shared_ptr<PCMStream> stream, bool keepSource) override;
|
||||
|
||||
void setListener(
|
||||
glm::vec3 position,
|
||||
|
||||
+11
-9
@@ -1,6 +1,7 @@
|
||||
#include "alutil.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include "../../debug/Logger.hpp"
|
||||
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
@@ -14,30 +15,31 @@
|
||||
#include <AL/alc.h>
|
||||
#endif
|
||||
|
||||
static debug::Logger logger("open-al");
|
||||
|
||||
bool AL::check_errors(const std::string& filename, const std::uint_fast32_t line){
|
||||
ALenum error = alGetError();
|
||||
if(error != AL_NO_ERROR){
|
||||
std::cerr << "OpenAL ERROR (" << filename << ": " << line << ")\n" ;
|
||||
logger.error() << filename << ": " << line;
|
||||
switch(error){
|
||||
case AL_INVALID_NAME:
|
||||
std::cerr << "AL_INVALID_NAME: a bad name (ID) was passed to an OpenAL function";
|
||||
logger.error() << "a bad name (ID) was passed to an OpenAL function";
|
||||
break;
|
||||
case AL_INVALID_ENUM:
|
||||
std::cerr << "AL_INVALID_ENUM: an invalid enum value was passed to an OpenAL function";
|
||||
logger.error() << "an invalid enum value was passed to an OpenAL function";
|
||||
break;
|
||||
case AL_INVALID_VALUE:
|
||||
std::cerr << "AL_INVALID_VALUE: an invalid value was passed to an OpenAL function";
|
||||
logger.error() << "an invalid value was passed to an OpenAL function";
|
||||
break;
|
||||
case AL_INVALID_OPERATION:
|
||||
std::cerr << "AL_INVALID_OPERATION: the requested operation is not valid";
|
||||
logger.error() << "the requested operation is not valid";
|
||||
break;
|
||||
case AL_OUT_OF_MEMORY:
|
||||
std::cerr << "AL_OUT_OF_MEMORY: the requested operation resulted in OpenAL running out of memory";
|
||||
logger.error() << "the requested operation resulted in OpenAL running out of memory";
|
||||
break;
|
||||
default:
|
||||
std::cerr << "UNKNOWN AL ERROR: " << error;
|
||||
logger.error() << "UNKNOWN AL ERROR: " << error;
|
||||
}
|
||||
std::cerr << std::endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user