Skip to content

Commit

Permalink
Add AudioStreamPlayerInternal to unify stream players
Browse files Browse the repository at this point in the history
  • Loading branch information
KoBeWi committed Jan 17, 2024
1 parent 107f296 commit 0c7db3c
Show file tree
Hide file tree
Showing 8 changed files with 583 additions and 718 deletions.
262 changes: 50 additions & 212 deletions scene/2d/audio_stream_player_2d.cpp

Large diffs are not rendered by default.

29 changes: 6 additions & 23 deletions scene/2d/audio_stream_player_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@
#define AUDIO_STREAM_PLAYER_2D_H

#include "scene/2d/node_2d.h"
#include "scene/scene_string_names.h"
#include "servers/audio/audio_stream.h"
#include "servers/audio_server.h"

struct AudioFrame;
class AudioStream;
class AudioStreamPlayback;
class AudioStreamPlayerInternal;

class AudioStreamPlayer2D : public Node2D {
GDCLASS(AudioStreamPlayer2D, Node2D);
Expand All @@ -52,10 +54,8 @@ class AudioStreamPlayer2D : public Node2D {
Viewport *viewport = nullptr; //pointer only used for reference to previous mix
};

Vector<Ref<AudioStreamPlayback>> stream_playbacks;
Ref<AudioStream> stream;
AudioStreamPlayerInternal *internal = nullptr;

SafeFlag active{ false };
SafeNumeric<float> setplay{ -1.0 };
Ref<AudioStreamPlayback> setplayback;

Expand All @@ -64,21 +64,12 @@ class AudioStreamPlayer2D : public Node2D {
uint64_t last_mix_count = -1;
bool force_update_panning = false;

float volume_db = 0.0;
float pitch_scale = 1.0;
bool autoplay = false;
StringName default_bus = SceneStringNames::get_singleton()->Master;
int max_polyphony = 1;

void _set_playing(bool p_enable);
bool _is_active() const;

StringName _get_actual_bus();
void _update_panning();

void _on_bus_layout_changed();
void _on_bus_renamed(int p_bus_index, const StringName &p_old_name, const StringName &p_new_name);

static void _listener_changed_cb(void *self) { reinterpret_cast<AudioStreamPlayer2D *>(self)->force_update_panning = true; }

uint32_t area_mask = 1;
Expand All @@ -89,14 +80,6 @@ class AudioStreamPlayer2D : public Node2D {
float panning_strength = 1.0f;
float cached_global_panning_strength = 0.5f;

struct ParameterData {
StringName path;
Variant value;
};

HashMap<StringName, ParameterData> playback_parameters;
void _update_stream_parameters();

protected:
void _validate_property(PropertyInfo &p_property) const;
void _notification(int p_what);
Expand Down
Loading

0 comments on commit 0c7db3c

Please sign in to comment.