Added positioning for Sound also fixed cmake
This commit is contained in:
@@ -19,7 +19,8 @@ pkg_check_modules(AVCODEC REQUIRED libavcodec)
|
|||||||
pkg_check_modules(AVUTIL REQUIRED libavutil)
|
pkg_check_modules(AVUTIL REQUIRED libavutil)
|
||||||
pkg_check_modules(SWRESAMPLE REQUIRED libswresample)
|
pkg_check_modules(SWRESAMPLE REQUIRED libswresample)
|
||||||
|
|
||||||
add_library(ChargeAudio SHARED "src/ChargeAudio.hpp" "src/Audio.cpp")
|
add_library(ChargeAudio SHARED "src/ChargeAudio.hpp" "src/Engine.cpp"
|
||||||
|
"src/Sound.cpp")
|
||||||
|
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
ChargeAudio
|
ChargeAudio
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
#include "../lib/miniaudio/miniaudio.c"
|
|
||||||
#include "../lib/miniaudio/miniaudio.h"
|
#include "../lib/miniaudio/miniaudio.h"
|
||||||
|
#include <Magnum/Magnum.h>
|
||||||
|
#include <Magnum/Math/Vector.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace ChargeAudio {
|
namespace ChargeAudio {
|
||||||
@@ -9,6 +10,8 @@ public:
|
|||||||
void Play();
|
void Play();
|
||||||
void Pause();
|
void Pause();
|
||||||
void Reset();
|
void Reset();
|
||||||
|
void SetPosition(Magnum::Vector3 position);
|
||||||
|
Magnum::Vector3 GetPosition();
|
||||||
void SetVolume(float value);
|
void SetVolume(float value);
|
||||||
float GetVolume();
|
float GetVolume();
|
||||||
|
|
||||||
|
37
src/Engine.cpp
Normal file
37
src/Engine.cpp
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#include "ChargeAudio.hpp"
|
||||||
|
#include <Corrade/Utility/Debug.h>
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
using namespace ChargeAudio;
|
||||||
|
using namespace Corrade;
|
||||||
|
|
||||||
|
Engine::Engine() {
|
||||||
|
if ((maResponse = ma_engine_init(NULL, &maEngine)) != MA_SUCCESS) {
|
||||||
|
Utility::Error{} << "Could not init miniaudio (" << maResponse << ")";
|
||||||
|
throw new std::runtime_error(
|
||||||
|
"Failed to init miniaudio engine. Check STDERR for more info.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Sound Engine::CreateSound(std::string filepath) {
|
||||||
|
Sound sound;
|
||||||
|
sound.baseEngine = this;
|
||||||
|
|
||||||
|
maResponse = ma_sound_init_from_file(&maEngine, filepath.c_str(), 0, NULL,
|
||||||
|
NULL, &sound.maSound);
|
||||||
|
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.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return sound;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Controls
|
||||||
|
void Engine::SetVolume(float value) { ma_engine_set_volume(&maEngine, value); }
|
||||||
|
float Engine::GetVolume() { return ma_engine_get_volume(&maEngine); }
|
22
src/Sound.cpp
Normal file
22
src/Sound.cpp
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#include "ChargeAudio.hpp"
|
||||||
|
#include <Magnum/Magnum.h>
|
||||||
|
#include <Magnum/Math/Vector3.h>
|
||||||
|
|
||||||
|
using namespace ChargeAudio;
|
||||||
|
Sound::~Sound() { ma_sound_uninit(&maSound); }
|
||||||
|
|
||||||
|
// Controls
|
||||||
|
void Sound::Play() { ma_sound_start(&maSound); }
|
||||||
|
void Sound::Pause() { ma_sound_stop(&maSound); }
|
||||||
|
void Sound::Reset() { ma_sound_seek_to_pcm_frame(&maSound, 0); }
|
||||||
|
|
||||||
|
void Sound::SetPosition(Magnum::Vector3 position) {
|
||||||
|
ma_sound_set_position(&maSound, position.x(), position.y(), position.z());
|
||||||
|
}
|
||||||
|
Magnum::Vector3 Sound::GetPosition() {
|
||||||
|
ma_vec3f pos = ma_sound_get_position(&maSound);
|
||||||
|
Magnum::Vector3 position(pos.x, pos.y, pos.z);
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
void Sound::SetVolume(float value) { ma_sound_set_volume(&maSound, value); }
|
||||||
|
float Sound::GetVolume() { return ma_sound_get_volume(&maSound); }
|
Reference in New Issue
Block a user