2#include <audiopp/exception.h>
11 auto_play_consumed_ =
false;
15 auto_play_consumed_ =
true;
29 auto_play_consumed_ =
true;
38 source_->update(std::chrono::milliseconds(16));
39 auto pos = t.get_position();
40 auto forward = t.z_unit_axis();
41 auto up = t.y_unit_axis();
42 source_->set_position({{pos.x, pos.y, pos.z}});
43 source_->set_orientation({{forward.x, forward.y, forward.z}}, {{up.x, up.y, up.z}});
45 if(source_->is_stopped())
59 source_->set_loop(on);
64 volume_ =math::clamp(volume, 0.0f, 1.0f);
70 source_->set_volume(volume_);
75 pitch_ = math::clamp(pitch, 0.0f, 5.0f);
81 source_->set_pitch(pitch_);
86 volume_rolloff_ = math::clamp(rolloff, 0.0f, 10.0f);
92 source_->set_volume_rolloff(rolloff);
98 range_.
min = math::clamp(range_.
min, 0.0f, range_.
max);
99 range_.
max = math::clamp(range_.
max, range_.
min, std::numeric_limits<float>::max());
106 source_->set_distance(range_.
min, range_.
max);
131 return volume_rolloff_;
145 source_->set_playback_position(offset);
154 return source_->get_playback_position();
164 return source_->get_playback_duration();
177 if(source_ && sound_)
179 source_->bind(*sound_.get());
240 return source_->is_muted();
249 return source_->is_playing();
258 return source_->is_paused();
287 return source_->has_bound_sound();
290void audio_source_component::apply_all()
302auto audio_source_component::is_sound_valid() const ->
bool
307auto audio_source_component::create_source() ->
bool
311 source_ = std::make_shared<audio::source>();
315 catch(
const audio::exception& e)
auto get_range() const -> const frange_t &
Gets the range of the audio source.
void set_volume(float volume)
Sets the volume of the audio source.
void set_autoplay(bool on)
Sets whether the audio source should autoplay.
void set_clip(const asset_handle< audio_clip > &clip)
Sets the audio clip for the audio source.
void set_range(const frange_t &range)
Sets the range of the audio source.
void update(const math::transform &t, delta_t dt)
Updates the audio source with the given transform and delta time.
void set_loop(bool on)
Sets whether the audio source should loop.
auto is_playing() const -> bool
Checks if the audio source is currently playing.
auto get_clip() const -> const asset_handle< audio_clip > &
Gets the audio clip of the audio source.
void resume()
Resumes playing the audio source.
void set_mute(bool mute)
Sets whether the audio source is muted.
void on_play_begin()
Called when audio playback begins.
void stop()
Stops playing the audio source.
auto is_muted() const -> bool
Checks if the audio source is muted.
auto get_volume_rolloff() const -> float
Gets the volume rolloff factor of the audio source.
void on_play_end()
Called when audio playback ends.
auto is_paused() const -> bool
Checks if the audio source is currently paused.
auto has_bound_sound() const -> bool
Checks if the audio source has a valid sound bound.
auto get_pitch() const -> float
Gets the pitch of the audio source.
void set_volume_rolloff(float rolloff)
Sets the volume rolloff factor of the audio source.
void set_playback_position(audio::duration_t offset)
Sets the playback position of the audio source.
void set_pitch(float pitch)
Sets the pitch of the audio source.
auto get_autoplay() const -> bool
Gets whether the audio source is set to autoplay.
auto is_looping() const -> bool
Checks if the audio source is set to loop.
auto get_volume() const -> float
Gets the volume of the audio source.
auto get_playback_position() const -> audio::duration_t
Gets the playback position of the audio source.
void pause()
Pauses the audio source.
auto get_playback_duration() const -> audio::duration_t
Gets the total playback duration of the audio source.
auto play() -> bool
Starts playing the audio source.
std::chrono::duration< float > delta_t
#define APPLOG_ERROR(...)
Represents a handle to an asset, providing access and management functions.
Struct representing an audio clip.