summaryrefslogtreecommitdiffstats
path: root/scene/audio/audio_stream_player_internal.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/audio/audio_stream_player_internal.cpp')
-rw-r--r--scene/audio/audio_stream_player_internal.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/scene/audio/audio_stream_player_internal.cpp b/scene/audio/audio_stream_player_internal.cpp
index a7b8faaaae..853638e47f 100644
--- a/scene/audio/audio_stream_player_internal.cpp
+++ b/scene/audio/audio_stream_player_internal.cpp
@@ -141,6 +141,24 @@ Ref<AudioStreamPlayback> AudioStreamPlayerInternal::play_basic() {
stream_playback->set_parameter(K.value.path, K.value.value);
}
+ // Sample handling.
+ if (_is_sample()) {
+ if (stream->can_be_sampled()) {
+ stream_playback->set_is_sample(true);
+ if (stream_playback->get_is_sample() && stream_playback->get_sample_playback().is_null()) {
+ if (!AudioServer::get_singleton()->is_stream_registered_as_sample(stream)) {
+ AudioServer::get_singleton()->register_stream_as_sample(stream);
+ }
+ Ref<AudioSamplePlayback> sample_playback;
+ sample_playback.instantiate();
+ sample_playback->stream = stream;
+ stream_playback->set_sample_playback(sample_playback);
+ }
+ } else if (!stream->is_meta_stream()) {
+ WARN_PRINT(vformat(R"(%s is trying to play a sample from a stream that cannot be sampled.)", node->get_path()));
+ }
+ }
+
stream_playbacks.push_back(stream_playback);
active.set();
_set_process(true);
@@ -151,6 +169,9 @@ void AudioStreamPlayerInternal::set_stream_paused(bool p_pause) {
// TODO this does not have perfect recall, fix that maybe? If there are zero playbacks registered with the AudioServer, this bool isn't persisted.
for (Ref<AudioStreamPlayback> &playback : stream_playbacks) {
AudioServer::get_singleton()->set_playback_paused(playback, p_pause);
+ if (_is_sample() && playback->get_sample_playback().is_valid()) {
+ AudioServer::get_singleton()->set_sample_playback_pause(playback->get_sample_playback(), p_pause);
+ }
}
}
@@ -240,8 +261,12 @@ void AudioStreamPlayerInternal::seek(float p_seconds) {
void AudioStreamPlayerInternal::stop() {
for (Ref<AudioStreamPlayback> &playback : stream_playbacks) {
AudioServer::get_singleton()->stop_playback_stream(playback);
+ if (_is_sample() && playback->get_sample_playback().is_valid()) {
+ AudioServer::get_singleton()->stop_sample_playback(playback->get_sample_playback());
+ }
}
stream_playbacks.clear();
+
active.clear();
_set_process(false);
}
@@ -251,6 +276,9 @@ bool AudioStreamPlayerInternal::is_playing() const {
if (AudioServer::get_singleton()->is_playback_active(playback)) {
return true;
}
+ if (AudioServer::get_singleton()->is_sample_playback_active(playback)) {
+ return true;
+ }
}
return false;
}
@@ -299,6 +327,14 @@ Ref<AudioStreamPlayback> AudioStreamPlayerInternal::get_stream_playback() {
return stream_playbacks[stream_playbacks.size() - 1];
}
+void AudioStreamPlayerInternal::set_playback_type(AudioServer::PlaybackType p_playback_type) {
+ playback_type = p_playback_type;
+}
+
+AudioServer::PlaybackType AudioStreamPlayerInternal::get_playback_type() const {
+ return playback_type;
+}
+
StringName AudioStreamPlayerInternal::get_bus() const {
const String bus_name = bus;
for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {