summaryrefslogtreecommitdiff
path: root/scene/audio
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2017-03-05 16:44:50 +0100
committerRémi Verschelde <rverschelde@gmail.com>2017-03-05 16:44:50 +0100
commit5dbf1809c6e3e905b94b8764e99491e608122261 (patch)
tree5e5a5360db15d86d59ec8c6e4f7eb511388c5a9a /scene/audio
parent45438e9918d421b244bfd7776a30e67dc7f2d3e3 (diff)
A Whole New World (clang-format edition)
I can show you the code Pretty, with proper whitespace Tell me, coder, now when did You last write readable code? I can open your eyes Make you see your bad indent Force you to respect the style The core devs agreed upon A whole new world A new fantastic code format A de facto standard With some sugar Enforced with clang-format A whole new world A dazzling style we all dreamed of And when we read it through It's crystal clear That now we're in a whole new world of code
Diffstat (limited to 'scene/audio')
-rw-r--r--scene/audio/audio_player.cpp184
-rw-r--r--scene/audio/audio_player.h16
2 files changed, 90 insertions, 110 deletions
diff --git a/scene/audio/audio_player.cpp b/scene/audio/audio_player.cpp
index 97eaea70b1..1ee31a94d8 100644
--- a/scene/audio/audio_player.cpp
+++ b/scene/audio/audio_player.cpp
@@ -28,7 +28,6 @@
/*************************************************************************/
#include "audio_player.h"
-
void AudioPlayer::_mix_audio() {
if (!stream_playback.is_valid()) {
@@ -39,10 +38,9 @@ void AudioPlayer::_mix_audio() {
return;
}
- if (setseek>=0.0) {
+ if (setseek >= 0.0) {
stream_playback->start(setseek);
- setseek=-1.0; //reset seek
-
+ setseek = -1.0; //reset seek
}
int bus_index = AudioServer::get_singleton()->thread_find_bus_index(bus);
@@ -52,67 +50,63 @@ void AudioPlayer::_mix_audio() {
int buffer_size = mix_buffer.size();
//mix
- stream_playback->mix(buffer,1.0,buffer_size);
+ stream_playback->mix(buffer, 1.0, buffer_size);
//multiply volume interpolating to avoid clicks if this changes
float vol = Math::db2linear(mix_volume_db);
- float vol_inc = (Math::db2linear(volume_db) - vol)/float(buffer_size);
+ float vol_inc = (Math::db2linear(volume_db) - vol) / float(buffer_size);
- for(int i=0;i<buffer_size;i++) {
- buffer[i]*=vol;
- vol+=vol_inc;
+ for (int i = 0; i < buffer_size; i++) {
+ buffer[i] *= vol;
+ vol += vol_inc;
}
//set volume for next mix
mix_volume_db = volume_db;
- AudioFrame * targets[3]={NULL,NULL,NULL};
+ AudioFrame *targets[3] = { NULL, NULL, NULL };
- if (AudioServer::get_singleton()->get_speaker_mode()==AudioServer::SPEAKER_MODE_STEREO) {
- targets[0] = AudioServer::get_singleton()->thread_get_channel_mix_buffer(bus_index,0);
+ if (AudioServer::get_singleton()->get_speaker_mode() == AudioServer::SPEAKER_MODE_STEREO) {
+ targets[0] = AudioServer::get_singleton()->thread_get_channel_mix_buffer(bus_index, 0);
} else {
- switch(mix_target) {
+ switch (mix_target) {
case MIX_TARGET_STEREO: {
- targets[0]=AudioServer::get_singleton()->thread_get_channel_mix_buffer(bus_index,1);
+ targets[0] = AudioServer::get_singleton()->thread_get_channel_mix_buffer(bus_index, 1);
} break;
case MIX_TARGET_SURROUND: {
- targets[0]=AudioServer::get_singleton()->thread_get_channel_mix_buffer(bus_index,1);
- targets[1]=AudioServer::get_singleton()->thread_get_channel_mix_buffer(bus_index,2);
- if (AudioServer::get_singleton()->get_speaker_mode()==AudioServer::SPEAKER_SURROUND_71) {
- targets[2]=AudioServer::get_singleton()->thread_get_channel_mix_buffer(bus_index,3);
+ targets[0] = AudioServer::get_singleton()->thread_get_channel_mix_buffer(bus_index, 1);
+ targets[1] = AudioServer::get_singleton()->thread_get_channel_mix_buffer(bus_index, 2);
+ if (AudioServer::get_singleton()->get_speaker_mode() == AudioServer::SPEAKER_SURROUND_71) {
+ targets[2] = AudioServer::get_singleton()->thread_get_channel_mix_buffer(bus_index, 3);
}
} break;
case MIX_TARGET_CENTER: {
- targets[0]=AudioServer::get_singleton()->thread_get_channel_mix_buffer(bus_index,0);
+ targets[0] = AudioServer::get_singleton()->thread_get_channel_mix_buffer(bus_index, 0);
} break;
-
}
}
- for(int c=0;c<3;c++) {
+ for (int c = 0; c < 3; c++) {
if (!targets[c])
break;
- for(int i=0;i<buffer_size;i++) {
- targets[c][i]+=buffer[i];
+ for (int i = 0; i < buffer_size; i++) {
+ targets[c][i] += buffer[i];
}
}
-
-
}
void AudioPlayer::_notification(int p_what) {
- if (p_what==NOTIFICATION_ENTER_TREE) {
+ if (p_what == NOTIFICATION_ENTER_TREE) {
- AudioServer::get_singleton()->add_callback(_mix_audios,this);
+ AudioServer::get_singleton()->add_callback(_mix_audios, this);
if (autoplay && !get_tree()->is_editor_hint()) {
play();
}
}
- if (p_what==NOTIFICATION_EXIT_TREE) {
-
- AudioServer::get_singleton()->remove_callback(_mix_audios,this);
+ if (p_what == NOTIFICATION_EXIT_TREE) {
+ AudioServer::get_singleton()->remove_callback(_mix_audios, this);
}
}
@@ -125,12 +119,12 @@ void AudioPlayer::set_stream(Ref<AudioStream> p_stream) {
if (stream_playback.is_valid()) {
stream_playback.unref();
stream.unref();
- active=false;
- setseek=-1;
+ active = false;
+ setseek = -1;
}
- stream=p_stream;
- stream_playback=p_stream->instance_playback();
+ stream = p_stream;
+ stream_playback = p_stream->instance_playback();
if (stream_playback.is_null()) {
stream.unref();
@@ -138,7 +132,6 @@ void AudioPlayer::set_stream(Ref<AudioStream> p_stream) {
}
AudioServer::get_singleton()->unlock();
-
}
Ref<AudioStream> AudioPlayer::get_stream() const {
@@ -148,7 +141,7 @@ Ref<AudioStream> AudioPlayer::get_stream() const {
void AudioPlayer::set_volume_db(float p_volume) {
- volume_db=p_volume;
+ volume_db = p_volume;
}
float AudioPlayer::get_volume_db() const {
@@ -158,26 +151,24 @@ float AudioPlayer::get_volume_db() const {
void AudioPlayer::play(float p_from_pos) {
if (stream_playback.is_valid()) {
- mix_volume_db=volume_db; //reset volume ramp
- setseek=p_from_pos;
- active=true;
+ mix_volume_db = volume_db; //reset volume ramp
+ setseek = p_from_pos;
+ active = true;
}
}
void AudioPlayer::seek(float p_seconds) {
if (stream_playback.is_valid()) {
- setseek=p_seconds;
+ setseek = p_seconds;
}
}
-void AudioPlayer::stop() {
+void AudioPlayer::stop() {
if (stream_playback.is_valid()) {
- active=false;
+ active = false;
}
-
-
}
bool AudioPlayer::is_playing() const {
@@ -189,7 +180,7 @@ bool AudioPlayer::is_playing() const {
return false;
}
-float AudioPlayer::get_pos() {
+float AudioPlayer::get_pos() {
if (stream_playback.is_valid()) {
return stream_playback->get_pos();
@@ -198,39 +189,38 @@ float AudioPlayer::get_pos() {
return 0;
}
-void AudioPlayer::set_bus(const StringName& p_bus) {
+void AudioPlayer::set_bus(const StringName &p_bus) {
//if audio is active, must lock this
AudioServer::get_singleton()->lock();
- bus=p_bus;
+ bus = p_bus;
AudioServer::get_singleton()->unlock();
-
}
StringName AudioPlayer::get_bus() const {
- for(int i=0;i<AudioServer::get_singleton()->get_bus_count();i++) {
- if (AudioServer::get_singleton()->get_bus_name(i)==bus) {
+ for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
+ if (AudioServer::get_singleton()->get_bus_name(i) == bus) {
return bus;
}
}
return "Master";
}
-void AudioPlayer::set_autoplay(bool p_enable) {
+void AudioPlayer::set_autoplay(bool p_enable) {
- autoplay=p_enable;
+ autoplay = p_enable;
}
-bool AudioPlayer::is_autoplay_enabled() {
+bool AudioPlayer::is_autoplay_enabled() {
return autoplay;
}
void AudioPlayer::set_mix_target(MixTarget p_target) {
- mix_target=p_target;
+ mix_target = p_target;
}
-AudioPlayer::MixTarget AudioPlayer::get_mix_target() const{
+AudioPlayer::MixTarget AudioPlayer::get_mix_target() const {
return mix_target;
}
@@ -247,20 +237,19 @@ bool AudioPlayer::_is_active() const {
return active;
}
+void AudioPlayer::_validate_property(PropertyInfo &property) const {
-void AudioPlayer::_validate_property(PropertyInfo& property) const {
-
- if (property.name=="bus") {
+ if (property.name == "bus") {
String options;
- for(int i=0;i<AudioServer::get_singleton()->get_bus_count();i++) {
- if (i>0)
- options+=",";
+ for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
+ if (i > 0)
+ options += ",";
String name = AudioServer::get_singleton()->get_bus_name(i);
- options+=name;
+ options += name;
}
- property.hint_string=options;
+ property.hint_string = options;
}
}
@@ -271,59 +260,52 @@ void AudioPlayer::_bus_layout_changed() {
void AudioPlayer::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_stream","stream:AudioStream"),&AudioPlayer::set_stream);
- ClassDB::bind_method(D_METHOD("get_stream"),&AudioPlayer::get_stream);
-
- ClassDB::bind_method(D_METHOD("set_volume_db","volume_db"),&AudioPlayer::set_volume_db);
- ClassDB::bind_method(D_METHOD("get_volume_db"),&AudioPlayer::get_volume_db);
+ ClassDB::bind_method(D_METHOD("set_stream", "stream:AudioStream"), &AudioPlayer::set_stream);
+ ClassDB::bind_method(D_METHOD("get_stream"), &AudioPlayer::get_stream);
- ClassDB::bind_method(D_METHOD("play","from_pos"),&AudioPlayer::play,DEFVAL(0.0));
- ClassDB::bind_method(D_METHOD("seek","to_pos"),&AudioPlayer::seek);
- ClassDB::bind_method(D_METHOD("stop"),&AudioPlayer::stop);
+ ClassDB::bind_method(D_METHOD("set_volume_db", "volume_db"), &AudioPlayer::set_volume_db);
+ ClassDB::bind_method(D_METHOD("get_volume_db"), &AudioPlayer::get_volume_db);
- ClassDB::bind_method(D_METHOD("is_playing"),&AudioPlayer::is_playing);
- ClassDB::bind_method(D_METHOD("get_pos"),&AudioPlayer::get_pos);
+ ClassDB::bind_method(D_METHOD("play", "from_pos"), &AudioPlayer::play, DEFVAL(0.0));
+ ClassDB::bind_method(D_METHOD("seek", "to_pos"), &AudioPlayer::seek);
+ ClassDB::bind_method(D_METHOD("stop"), &AudioPlayer::stop);
- ClassDB::bind_method(D_METHOD("set_bus","bus"),&AudioPlayer::set_bus);
- ClassDB::bind_method(D_METHOD("get_bus"),&AudioPlayer::get_bus);
+ ClassDB::bind_method(D_METHOD("is_playing"), &AudioPlayer::is_playing);
+ ClassDB::bind_method(D_METHOD("get_pos"), &AudioPlayer::get_pos);
- ClassDB::bind_method(D_METHOD("set_autoplay","enable"),&AudioPlayer::set_autoplay);
- ClassDB::bind_method(D_METHOD("is_autoplay_enabled"),&AudioPlayer::is_autoplay_enabled);
+ ClassDB::bind_method(D_METHOD("set_bus", "bus"), &AudioPlayer::set_bus);
+ ClassDB::bind_method(D_METHOD("get_bus"), &AudioPlayer::get_bus);
- ClassDB::bind_method(D_METHOD("set_mix_target","mix_target"),&AudioPlayer::set_mix_target);
- ClassDB::bind_method(D_METHOD("get_mix_target"),&AudioPlayer::get_mix_target);
+ ClassDB::bind_method(D_METHOD("set_autoplay", "enable"), &AudioPlayer::set_autoplay);
+ ClassDB::bind_method(D_METHOD("is_autoplay_enabled"), &AudioPlayer::is_autoplay_enabled);
- ClassDB::bind_method(D_METHOD("_set_playing","enable"),&AudioPlayer::_set_playing);
- ClassDB::bind_method(D_METHOD("_is_active"),&AudioPlayer::_is_active);
+ ClassDB::bind_method(D_METHOD("set_mix_target", "mix_target"), &AudioPlayer::set_mix_target);
+ ClassDB::bind_method(D_METHOD("get_mix_target"), &AudioPlayer::get_mix_target);
- ClassDB::bind_method(D_METHOD("_bus_layout_changed"),&AudioPlayer::_bus_layout_changed);
+ ClassDB::bind_method(D_METHOD("_set_playing", "enable"), &AudioPlayer::_set_playing);
+ ClassDB::bind_method(D_METHOD("_is_active"), &AudioPlayer::_is_active);
+ ClassDB::bind_method(D_METHOD("_bus_layout_changed"), &AudioPlayer::_bus_layout_changed);
- ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"stream",PROPERTY_HINT_RESOURCE_TYPE,"AudioStream"),"set_stream","get_stream") ;
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"volume_db",PROPERTY_HINT_RANGE,"-80,24"),"set_volume_db","get_volume_db") ;
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"playing",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_EDITOR),"_set_playing","_is_active" );
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"autoplay"),"set_autoplay","is_autoplay_enabled") ;
- ADD_PROPERTY( PropertyInfo(Variant::INT,"mix_target",PROPERTY_HINT_ENUM,"Stereo,Surround,Center"),"set_mix_target","get_mix_target");
- ADD_PROPERTY( PropertyInfo(Variant::STRING,"bus",PROPERTY_HINT_ENUM,""),"set_bus","get_bus");
-
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "stream", PROPERTY_HINT_RESOURCE_TYPE, "AudioStream"), "set_stream", "get_stream");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "volume_db", PROPERTY_HINT_RANGE, "-80,24"), "set_volume_db", "get_volume_db");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "playing", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "_set_playing", "_is_active");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "autoplay"), "set_autoplay", "is_autoplay_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "mix_target", PROPERTY_HINT_ENUM, "Stereo,Surround,Center"), "set_mix_target", "get_mix_target");
+ ADD_PROPERTY(PropertyInfo(Variant::STRING, "bus", PROPERTY_HINT_ENUM, ""), "set_bus", "get_bus");
}
AudioPlayer::AudioPlayer() {
- mix_volume_db=0;
- volume_db=0;
- autoplay=false;
- setseek=-1;
- active=false;
- mix_target=MIX_TARGET_STEREO;
+ mix_volume_db = 0;
+ volume_db = 0;
+ autoplay = false;
+ setseek = -1;
+ active = false;
+ mix_target = MIX_TARGET_STEREO;
- AudioServer::get_singleton()->connect("bus_layout_changed",this,"_bus_layout_changed");
+ AudioServer::get_singleton()->connect("bus_layout_changed", this, "_bus_layout_changed");
}
-
-
AudioPlayer::~AudioPlayer() {
-
-
}
-
diff --git a/scene/audio/audio_player.h b/scene/audio/audio_player.h
index 6e34dfce19..0d78626189 100644
--- a/scene/audio/audio_player.h
+++ b/scene/audio/audio_player.h
@@ -32,18 +32,17 @@
#include "scene/main/node.h"
#include "servers/audio/audio_stream.h"
-
class AudioPlayer : public Node {
- GDCLASS( AudioPlayer, Node )
+ GDCLASS(AudioPlayer, Node)
public:
-
enum MixTarget {
MIX_TARGET_STEREO,
MIX_TARGET_SURROUND,
MIX_TARGET_CENTER
};
+
private:
Ref<AudioStreamPlayback> stream_playback;
Ref<AudioStream> stream;
@@ -60,7 +59,7 @@ private:
MixTarget mix_target;
void _mix_audio();
- static void _mix_audios(void *self) { reinterpret_cast<AudioPlayer*>(self)->_mix_audio(); }
+ static void _mix_audios(void *self) { reinterpret_cast<AudioPlayer *>(self)->_mix_audio(); }
void _set_playing(bool p_enable);
bool _is_active() const;
@@ -68,25 +67,24 @@ private:
void _bus_layout_changed();
protected:
-
- void _validate_property(PropertyInfo& property) const;
+ void _validate_property(PropertyInfo &property) const;
void _notification(int p_what);
static void _bind_methods();
-public:
+public:
void set_stream(Ref<AudioStream> p_stream);
Ref<AudioStream> get_stream() const;
void set_volume_db(float p_volume);
float get_volume_db() const;
- void play(float p_from_pos=0.0);
+ void play(float p_from_pos = 0.0);
void seek(float p_seconds);
void stop();
bool is_playing() const;
float get_pos();
- void set_bus(const StringName& p_bus);
+ void set_bus(const StringName &p_bus);
StringName get_bus() const;
void set_autoplay(bool p_enable);