summaryrefslogtreecommitdiff
path: root/servers/audio
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2021-09-07 17:38:51 -0300
committerGitHub <noreply@github.com>2021-09-07 17:38:51 -0300
commitca11f8ad3045c280b559adea4e2263c38c2c6df4 (patch)
treea8387f731c0a35abe224bccf8cb82e672193b645 /servers/audio
parent43c896ac6a309bca229619a6d295918a3b656d6a (diff)
parent0e3cab41ebac855fbf13b4c409e42d2661c5842b (diff)
Merge pull request #52237 from ellenhp/polyphony
Add optional polyphonic playback to built-in audio player nodes
Diffstat (limited to 'servers/audio')
-rw-r--r--servers/audio/audio_stream.cpp22
-rw-r--r--servers/audio/audio_stream.h5
-rw-r--r--servers/audio/effects/audio_stream_generator.cpp4
-rw-r--r--servers/audio/effects/audio_stream_generator.h1
4 files changed, 32 insertions, 0 deletions
diff --git a/servers/audio/audio_stream.cpp b/servers/audio/audio_stream.cpp
index e1b391b823..c098a97906 100644
--- a/servers/audio/audio_stream.cpp
+++ b/servers/audio/audio_stream.cpp
@@ -189,11 +189,21 @@ float AudioStream::get_length() const {
return 0;
}
+bool AudioStream::is_monophonic() const {
+ bool ret;
+ if (GDVIRTUAL_CALL(_is_monophonic, ret)) {
+ return ret;
+ }
+ return true;
+}
+
void AudioStream::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_length"), &AudioStream::get_length);
+ ClassDB::bind_method(D_METHOD("is_monophonic"), &AudioStream::is_monophonic);
GDVIRTUAL_BIND(_instance_playback);
GDVIRTUAL_BIND(_get_stream_name);
GDVIRTUAL_BIND(_get_length);
+ GDVIRTUAL_BIND(_is_monophonic);
}
////////////////////////////////
@@ -221,6 +231,10 @@ float AudioStreamMicrophone::get_length() const {
return 0;
}
+bool AudioStreamMicrophone::is_monophonic() const {
+ return true;
+}
+
void AudioStreamMicrophone::_bind_methods() {
}
@@ -388,6 +402,14 @@ float AudioStreamRandomPitch::get_length() const {
return 0;
}
+bool AudioStreamRandomPitch::is_monophonic() const {
+ if (audio_stream.is_valid()) {
+ return audio_stream->is_monophonic();
+ }
+
+ return true; // It doesn't really matter what we return here, but no sense instancing a many playbacks of a null stream.
+}
+
void AudioStreamRandomPitch::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_audio_stream", "stream"), &AudioStreamRandomPitch::set_audio_stream);
ClassDB::bind_method(D_METHOD("get_audio_stream"), &AudioStreamRandomPitch::get_audio_stream);
diff --git a/servers/audio/audio_stream.h b/servers/audio/audio_stream.h
index 922335508e..12d4343f5c 100644
--- a/servers/audio/audio_stream.h
+++ b/servers/audio/audio_stream.h
@@ -102,12 +102,14 @@ protected:
GDVIRTUAL0RC(Ref<AudioStreamPlayback>, _instance_playback)
GDVIRTUAL0RC(String, _get_stream_name)
GDVIRTUAL0RC(float, _get_length)
+ GDVIRTUAL0RC(bool, _is_monophonic)
public:
virtual Ref<AudioStreamPlayback> instance_playback();
virtual String get_stream_name() const;
virtual float get_length() const;
+ virtual bool is_monophonic() const;
};
// Microphone
@@ -129,6 +131,8 @@ public:
virtual float get_length() const override; //if supported, otherwise return 0
+ virtual bool is_monophonic() const override;
+
AudioStreamMicrophone();
};
@@ -187,6 +191,7 @@ public:
virtual String get_stream_name() const override;
virtual float get_length() const override; //if supported, otherwise return 0
+ virtual bool is_monophonic() const override;
AudioStreamRandomPitch();
};
diff --git a/servers/audio/effects/audio_stream_generator.cpp b/servers/audio/effects/audio_stream_generator.cpp
index edb5c6d2dd..447acf53a4 100644
--- a/servers/audio/effects/audio_stream_generator.cpp
+++ b/servers/audio/effects/audio_stream_generator.cpp
@@ -64,6 +64,10 @@ float AudioStreamGenerator::get_length() const {
return 0;
}
+bool AudioStreamGenerator::is_monophonic() const {
+ return true;
+}
+
void AudioStreamGenerator::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_mix_rate", "hz"), &AudioStreamGenerator::set_mix_rate);
ClassDB::bind_method(D_METHOD("get_mix_rate"), &AudioStreamGenerator::get_mix_rate);
diff --git a/servers/audio/effects/audio_stream_generator.h b/servers/audio/effects/audio_stream_generator.h
index 6bec744081..918589f6d0 100644
--- a/servers/audio/effects/audio_stream_generator.h
+++ b/servers/audio/effects/audio_stream_generator.h
@@ -54,6 +54,7 @@ public:
virtual String get_stream_name() const override;
virtual float get_length() const override;
+ virtual bool is_monophonic() const override;
AudioStreamGenerator();
};