Skip to content

Commit

Permalink
Add get_inner_stream_playback.
Browse files Browse the repository at this point in the history
  • Loading branch information
stechyo committed Jun 11, 2024
1 parent 3c00684 commit 2fa5984
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
void SteamAudioPlayer::_bind_methods() {
ClassDB::bind_method(D_METHOD("play_stream", "stream", "from_offset", "volume_db", "pitch_scale"), &SteamAudioPlayer::play_stream, DEFVAL(0), DEFVAL(0), DEFVAL(1.0));
ClassDB::bind_method(D_METHOD("get_inner_stream"), &SteamAudioPlayer::get_inner_stream);
ClassDB::bind_method(D_METHOD("get_inner_stream_playback"), &SteamAudioPlayer::get_inner_stream_playback);

ClassDB::bind_method(D_METHOD("is_dist_attn_on"), &SteamAudioPlayer::is_dist_attn_on);
ClassDB::bind_method(D_METHOD("set_dist_attn_on", "p_dist_attn_on"), &SteamAudioPlayer::set_dist_attn_on);
Expand Down Expand Up @@ -263,6 +264,18 @@ Ref<AudioStream> SteamAudioPlayer::get_inner_stream() {
return str->get_stream();
}

Ref<AudioStreamPlayback> SteamAudioPlayer::get_inner_stream_playback() {
auto spb = dynamic_cast<SteamAudioStreamPlayback *>(get_stream_playback().ptr());
if (spb == nullptr) {
SteamAudio::log(SteamAudio::log_warn,
"Tried to get an inner stream playback from a SteamAudioPlayer, but its outer stream playback is not a SteamAudioStreamPlayback (or the player may not be playing audio). Returning null.");
Ref<AudioStream> null_pb;
return null_pb;
}

return spb->get_stream_playback();
}

float SteamAudioPlayer::get_occlusion_radius() { return cfg.occ_radius; }
void SteamAudioPlayer::set_occlusion_radius(float p_occlusion_radius) { cfg.occ_radius = p_occlusion_radius; }
int SteamAudioPlayer::get_occlusion_samples() { return cfg.occ_samples; }
Expand Down
1 change: 1 addition & 0 deletions src/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class SteamAudioPlayer : public AudioStreamPlayer3D {

void play_stream(const Ref<AudioStream> &p_stream, float p_from_offset, float p_volume_db, float p_pitch_scale);
Ref<AudioStream> get_inner_stream();
Ref<AudioStreamPlayback> get_inner_stream_playback();

PackedStringArray _get_configuration_warnings() const override;
};
Expand Down
1 change: 1 addition & 0 deletions src/stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,4 @@ void SteamAudioStreamPlayback::_stop() {

bool SteamAudioStreamPlayback::_is_playing() const { return is_active; }
void SteamAudioStreamPlayback::set_stream(Ref<AudioStream> p_stream) { stream = p_stream; }
Ref<AudioStreamPlayback> SteamAudioStreamPlayback::get_stream_playback() { return this->stream_playback; }
1 change: 1 addition & 0 deletions src/stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class SteamAudioStreamPlayback : public AudioStreamPlayback {
~SteamAudioStreamPlayback();

void set_stream(Ref<AudioStream> p_stream);
Ref<AudioStreamPlayback> get_stream_playback();

virtual int32_t _mix(AudioFrame *buffer, double rate_scale,
int32_t frames) override;
Expand Down

0 comments on commit 2fa5984

Please sign in to comment.