minor refactor

This commit is contained in:
MihailRis
2024-05-17 15:46:54 +03:00
parent 2a8b750ad7
commit 8ff629e1cd
15 changed files with 120 additions and 107 deletions
+8 -9
View File
@@ -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() {