-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add audio interface. Make resource loading function pass shared point…
…er to deserialize context.
- Loading branch information
Showing
56 changed files
with
1,518 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// SPDX-FileCopyrightText: 2023 C. J. Howard | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#ifndef ANTKEEPER_AUDIO_HPP | ||
#define ANTKEEPER_AUDIO_HPP | ||
|
||
#include <engine/audio/listener.hpp> | ||
#include <engine/audio/playback-state.hpp> | ||
#include <engine/audio/sound-que.hpp> | ||
#include <engine/audio/sound-system.hpp> | ||
#include <engine/audio/sound-wave.hpp> | ||
|
||
/// Audio interface. | ||
namespace audio {} | ||
|
||
#endif // ANTKEEPER_AUDIO_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// SPDX-FileCopyrightText: 2023 C. J. Howard | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#include <engine/audio/listener.hpp> | ||
#include <AL/al.h> | ||
|
||
namespace audio { | ||
|
||
listener::listener() | ||
{} | ||
|
||
void listener::set_position(const math::fvec3& position) | ||
{ | ||
if (m_position != position) | ||
{ | ||
m_position = position; | ||
alListenerfv(AL_POSITION, m_position.data()); | ||
} | ||
} | ||
|
||
void listener::set_orientation(const math::fquat& orientation) | ||
{ | ||
if (m_orientation != orientation) | ||
{ | ||
m_orientation = orientation; | ||
|
||
// Calculate basis vectors | ||
const math::fvec3 basis[2] = | ||
{ | ||
// Forward direction vector | ||
m_orientation * math::fvec3{ 0.0f, 0.0f, -1.0f}, | ||
|
||
// Up direciton vector | ||
m_orientation * math::fvec3{ 0.0f, 1.0f, 0.0f} | ||
}; | ||
|
||
static_assert(sizeof(basis) == sizeof(float) * 6); | ||
alListenerfv(AL_ORIENTATION, basis[0].data()); | ||
} | ||
} | ||
|
||
void listener::set_velocity(const math::fvec3& velocity) | ||
{ | ||
if (m_velocity != velocity) | ||
{ | ||
m_velocity = velocity; | ||
alListenerfv(AL_VELOCITY, m_velocity.data()); | ||
} | ||
} | ||
|
||
void listener::set_gain(float gain) | ||
{ | ||
if (m_gain != gain) | ||
{ | ||
m_gain = gain; | ||
alListenerf(AL_GAIN, m_gain); | ||
} | ||
} | ||
|
||
} // namespace audio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// SPDX-FileCopyrightText: 2023 C. J. Howard | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#ifndef ANTKEEPER_AUDIO_LISTENER_HPP | ||
#define ANTKEEPER_AUDIO_LISTENER_HPP | ||
|
||
#include <engine/math/vector.hpp> | ||
#include <engine/math/quaternion.hpp> | ||
|
||
namespace audio { | ||
|
||
class sound_system; | ||
|
||
/** | ||
* Sound listener. | ||
*/ | ||
class listener | ||
{ | ||
public: | ||
/** Constructs a listener. */ | ||
listener(); | ||
|
||
/** Destructs a listener. */ | ||
~listener() = default; | ||
|
||
listener(const listener&) = delete; | ||
listener(listener&&) = delete; | ||
listener& operator=(const listener&) = delete; | ||
listener& operator=(listener&&) = delete; | ||
|
||
/** | ||
* Sets the position of the listener. | ||
* | ||
* @param position Position of the listener. | ||
*/ | ||
void set_position(const math::fvec3& position); | ||
|
||
/** | ||
* Sets the orientation of the listener. | ||
* | ||
* @param orientation Orientation of the listener. | ||
*/ | ||
void set_orientation(const math::fquat& orientation); | ||
|
||
/** | ||
* Sets the velocity of the listener. | ||
* | ||
* @param velocity Position of the listener. | ||
*/ | ||
void set_velocity(const math::fvec3& velocity); | ||
|
||
/** | ||
* Sets the gain of the listener. | ||
* | ||
* @param gain Gain of the listener. | ||
*/ | ||
void set_gain(float gain); | ||
|
||
/** Returns the position of the listener. */ | ||
[[nodiscard]] inline constexpr const auto& get_position() const noexcept | ||
{ | ||
return m_position; | ||
} | ||
|
||
/** Returns the orientation of the listener. */ | ||
[[nodiscard]] inline constexpr const auto& get_orientation() const noexcept | ||
{ | ||
return m_orientation; | ||
} | ||
|
||
/** Returns the velocity of the listener. */ | ||
[[nodiscard]] inline constexpr const auto& get_velocity() const noexcept | ||
{ | ||
return m_velocity; | ||
} | ||
|
||
/** Returns the gain of the listener. */ | ||
[[nodiscard]] inline constexpr auto get_gain() const noexcept | ||
{ | ||
return m_gain; | ||
} | ||
|
||
private: | ||
friend class sound_system; | ||
|
||
math::fvec3 m_position{}; | ||
math::fquat m_orientation{math::identity<math::fquat>}; | ||
math::fvec3 m_velocity{}; | ||
float m_gain{1.0f}; | ||
}; | ||
|
||
} // namespace audio | ||
|
||
#endif // ANTKEEPER_AUDIO_LISTENER_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// SPDX-FileCopyrightText: 2023 C. J. Howard | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#ifndef ANTKEEPER_AUDIO_PLAYBACK_STATE_HPP | ||
#define ANTKEEPER_AUDIO_PLAYBACK_STATE_HPP | ||
|
||
namespace audio { | ||
|
||
/** Playback statse of a sound queue. */ | ||
enum class playback_state | ||
{ | ||
/** Sound que is stopped. */ | ||
stopped, | ||
|
||
/** Sound que is playing. */ | ||
playing, | ||
|
||
/** Sound que is paused. */ | ||
paused | ||
}; | ||
|
||
} // namespace audio | ||
|
||
#endif // ANTKEEPER_AUDIO_PLAYBACK_STATE_HPP |
Oops, something went wrong.