Compare commits
2 Commits
64b5a8af29
...
146bd49b36
Author | SHA1 | Date | |
---|---|---|---|
146bd49b36 | |||
71e4ff9317 |
@@ -28,11 +28,14 @@ public:
|
||||
|
||||
private:
|
||||
Sound(class Engine *engine);
|
||||
void init(std::string additionalErrorMessage = "");
|
||||
static void onSoundFinish(void *customData, ma_sound *);
|
||||
|
||||
class Engine *baseEngine;
|
||||
ma_sound maSound;
|
||||
ma_sound_config maConfig;
|
||||
SoundState state = SoundState::Idle;
|
||||
|
||||
friend class Engine;
|
||||
};
|
||||
|
||||
@@ -40,6 +43,8 @@ class Listener {
|
||||
public:
|
||||
void SetEnabled(bool isEnabled);
|
||||
bool GetEnabled();
|
||||
void SetDirection(Magnum::Vector3 position);
|
||||
Magnum::Vector3 GetDirection();
|
||||
void SetPosition(Magnum::Vector3 position);
|
||||
Magnum::Vector3 GetPosition();
|
||||
|
||||
|
@@ -20,20 +20,13 @@ Engine::Engine() {
|
||||
|
||||
Engine::~Engine() { ma_engine_uninit(&maEngine); }
|
||||
|
||||
Containers::Pointer<Sound> Engine::CreateSound(std::string filepath) {
|
||||
Containers::Pointer<Sound> Engine::CreateSound(const std::string filepath) {
|
||||
auto sound = Containers::Pointer<Sound>(new Sound(this));
|
||||
maResponse = ma_sound_init_from_file(&maEngine, filepath.c_str(), 0, NULL,
|
||||
NULL, &sound->maSound);
|
||||
sound->maSound.endCallback = Sound::onSoundFinish;
|
||||
sound->maSound.pEndCallbackUserData = sound.get();
|
||||
|
||||
if (maResponse != MA_SUCCESS) {
|
||||
Utility::Error{} << "Failed to create the sound from the file: "
|
||||
<< filepath.c_str() << " (" << maResponse << ")";
|
||||
throw new std::runtime_error(
|
||||
"Failed to create the sound from file. Check STDERR for more info.");
|
||||
}
|
||||
|
||||
sound->maConfig.pFilePath = filepath.c_str();
|
||||
sound->maConfig.flags = 0;
|
||||
sound->maConfig.pInitialAttachment = NULL;
|
||||
sound->maConfig.pDoneFence = NULL;
|
||||
sound->init("Failed to create the sound from the file: " + filepath);
|
||||
return sound;
|
||||
}
|
||||
|
||||
|
@@ -1,4 +1,5 @@
|
||||
#include "ChargeAudio.hpp"
|
||||
#include <Magnum/Magnum.h>
|
||||
#include <Magnum/Math/Vector3.h>
|
||||
|
||||
using namespace ChargeAudio;
|
||||
@@ -13,6 +14,18 @@ void Listener::SetEnabled(bool isEnabled) {
|
||||
bool Listener::GetEnabled() {
|
||||
return ma_engine_listener_is_enabled(&baseEngine->maEngine, listenerID);
|
||||
}
|
||||
|
||||
void Listener::SetDirection(Magnum::Vector3 position) {
|
||||
ma_engine_listener_set_direction(&baseEngine->maEngine, listenerID,
|
||||
position.x(), position.y(), position.z());
|
||||
}
|
||||
|
||||
Magnum::Vector3 Listener::GetDirection() {
|
||||
ma_vec3f dir =
|
||||
ma_engine_listener_get_direction(&baseEngine->maEngine, listenerID);
|
||||
return Magnum::Vector3{dir.x, dir.y, dir.z};
|
||||
}
|
||||
|
||||
void Listener::SetPosition(Magnum::Vector3 position) {
|
||||
ma_engine_listener_set_position(&baseEngine->maEngine, listenerID,
|
||||
position.x(), position.y(), position.z());
|
||||
|
@@ -1,14 +1,31 @@
|
||||
#include "ChargeAudio.hpp"
|
||||
#include <Magnum/Magnum.h>
|
||||
#include <Magnum/Math/Vector3.h>
|
||||
#include <stdexcept>
|
||||
|
||||
using namespace ChargeAudio;
|
||||
Sound::Sound(Engine *engine) : baseEngine(engine) {}
|
||||
Sound::Sound(Engine *engine) : baseEngine(engine) {
|
||||
maConfig = ma_sound_config_init_2(&baseEngine->maEngine);
|
||||
maConfig.endCallback = Sound::onSoundFinish;
|
||||
maConfig.pEndCallbackUserData = this;
|
||||
}
|
||||
|
||||
Sound::~Sound() { ma_sound_uninit(&maSound); }
|
||||
|
||||
Sound::SoundState Sound::GetState() { return state; }
|
||||
|
||||
void Sound::init(std::string additionalErrorMessage) {
|
||||
ma_result maResponse =
|
||||
ma_sound_init_ex(&baseEngine->maEngine, &maConfig, &maSound);
|
||||
if (maResponse != MA_SUCCESS) {
|
||||
Utility::Error{} << "Failed to create a new sound" << " (" << maResponse
|
||||
<< ")";
|
||||
throw new std::runtime_error(
|
||||
"Failed to create a new sound. Check STDERR for more info.\n" +
|
||||
additionalErrorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
// Controls
|
||||
void Sound::Play() {
|
||||
ma_sound_start(&maSound);
|
||||
|
Reference in New Issue
Block a user