mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-08 17:57:02 +08:00
feat(audio): add pitch control to audio sources
Implement set_pitch method that clamps pitch between 0.0 and 1.0 and applies it via AL_PITCH. Includes minor whitespace cleanup in audio_engine.cpp.
This commit is contained in:
@@ -17,7 +17,7 @@ public:
|
||||
void set_buffer_3d(const AudioBuffer& buffer, const glm::vec3& vec3);
|
||||
void set_loop(bool on = true);
|
||||
void set_volume(float volume);
|
||||
|
||||
void set_pitch(float pitch);
|
||||
void play();
|
||||
void play_2d(const AudioBuffer& buffer);
|
||||
void play_3d(const AudioBuffer& buffer, const glm::vec3& pos);
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "Cubed/tools/log.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
namespace Cubed {
|
||||
AudioEngine::AudioEngine() {};
|
||||
|
||||
@@ -194,12 +195,14 @@ void AudioEngine::underwater_change(bool underwater) {
|
||||
for (auto& source : m_pool->sources()) {
|
||||
if (m_underwater) {
|
||||
source.set_filter(*m_low_pass_filter);
|
||||
|
||||
} else {
|
||||
source.clear_filter();
|
||||
}
|
||||
}
|
||||
if (underwater) {
|
||||
m_bgm->set_filter(*m_low_pass_filter);
|
||||
|
||||
} else {
|
||||
m_bgm->clear_filter();
|
||||
}
|
||||
|
||||
@@ -74,6 +74,11 @@ void AudioSource::set_volume(float volume) {
|
||||
alSourcef(m_source, AL_GAIN, volume);
|
||||
}
|
||||
|
||||
void AudioSource::set_pitch(float pitch) {
|
||||
pitch = std::clamp(pitch, 0.0f, 1.0f);
|
||||
alSourcef(m_source, AL_PITCH, pitch);
|
||||
}
|
||||
|
||||
void AudioSource::play() { alSourcePlay(m_source); }
|
||||
|
||||
void AudioSource::play_2d(const AudioBuffer& buffer) {
|
||||
|
||||
Reference in New Issue
Block a user