Oops! Audio engine has vanished :D
This commit is contained in:
@@ -1,263 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* sample_player_2d.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include "sample_player_2d.h"
|
||||
|
||||
#include "servers/audio_server.h"
|
||||
#include "servers/audio_server.h"
|
||||
#include "servers/spatial_sound_server.h"
|
||||
|
||||
|
||||
bool SamplePlayer2D::_set(const StringName& p_name, const Variant& p_value) {
|
||||
|
||||
String name=p_name;
|
||||
|
||||
if (name=="play/play") {
|
||||
if (library.is_valid()) {
|
||||
|
||||
String what=p_value;
|
||||
if (what=="")
|
||||
stop_all();
|
||||
else
|
||||
play(what);
|
||||
|
||||
played_back=what;
|
||||
}
|
||||
} else
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SamplePlayer2D::_get(const StringName& p_name,Variant &r_ret) const {
|
||||
|
||||
|
||||
String name=p_name;
|
||||
|
||||
if (name=="play/play") {
|
||||
r_ret=played_back;
|
||||
} else
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void SamplePlayer2D::_get_property_list(List<PropertyInfo> *p_list) const {
|
||||
|
||||
String en="";
|
||||
if (library.is_valid()) {
|
||||
List<StringName> samples;
|
||||
Ref<SampleLibrary> ncl=library;
|
||||
ncl->get_sample_list(&samples);
|
||||
for (List<StringName>::Element *E=samples.front();E;E=E->next()) {
|
||||
|
||||
en+=",";
|
||||
en+=E->get();
|
||||
}
|
||||
}
|
||||
|
||||
p_list->push_back( PropertyInfo( Variant::STRING, "play/play", PROPERTY_HINT_ENUM, en,PROPERTY_USAGE_EDITOR|PROPERTY_USAGE_ANIMATE_AS_TRIGGER));
|
||||
}
|
||||
|
||||
void SamplePlayer2D::_notification(int p_what) {
|
||||
|
||||
|
||||
switch(p_what) {
|
||||
|
||||
case NOTIFICATION_ENTER_TREE: {
|
||||
|
||||
SpatialSound2DServer::get_singleton()->source_set_polyphony(get_source_rid(),polyphony);
|
||||
|
||||
|
||||
} break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SamplePlayer2D::set_sample_library(const Ref<SampleLibrary>& p_library) {
|
||||
|
||||
library=p_library;
|
||||
_change_notify();
|
||||
update_configuration_warning();
|
||||
}
|
||||
|
||||
Ref<SampleLibrary> SamplePlayer2D::get_sample_library() const {
|
||||
|
||||
return library;
|
||||
}
|
||||
|
||||
void SamplePlayer2D::set_polyphony(int p_voice_count) {
|
||||
|
||||
ERR_FAIL_COND(p_voice_count<0 || p_voice_count>64);
|
||||
polyphony=p_voice_count;
|
||||
if (get_source_rid().is_valid())
|
||||
SpatialSound2DServer::get_singleton()->source_set_polyphony(get_source_rid(),polyphony);
|
||||
|
||||
}
|
||||
|
||||
int SamplePlayer2D::get_polyphony() const {
|
||||
|
||||
return polyphony;
|
||||
}
|
||||
|
||||
SamplePlayer2D::VoiceID SamplePlayer2D::play(const String& p_sample,int p_voice) {
|
||||
|
||||
if (!get_source_rid().is_valid())
|
||||
return INVALID_VOICE;
|
||||
if (library.is_null())
|
||||
return INVALID_VOICE;
|
||||
if (!library->has_sample(p_sample))
|
||||
return INVALID_VOICE;
|
||||
Ref<Sample> sample = library->get_sample(p_sample);
|
||||
float vol_change = library->sample_get_volume_db(p_sample);
|
||||
float pitch_change = library->sample_get_pitch_scale(p_sample);
|
||||
|
||||
VoiceID vid = SpatialSound2DServer::get_singleton()->source_play_sample(get_source_rid(),sample->get_rid(),sample->get_mix_rate()*pitch_change,p_voice);
|
||||
if (vol_change)
|
||||
SpatialSound2DServer::get_singleton()->source_voice_set_volume_scale_db(get_source_rid(),vid,vol_change);
|
||||
|
||||
|
||||
if (random_pitch_scale) {
|
||||
float ps = Math::random(-random_pitch_scale,random_pitch_scale);
|
||||
if (ps>0)
|
||||
ps=1.0+ps;
|
||||
else
|
||||
ps=1.0/(1.0-ps);
|
||||
SpatialSound2DServer::get_singleton()->source_voice_set_pitch_scale(get_source_rid(),vid,ps*pitch_change);
|
||||
|
||||
}
|
||||
|
||||
return vid;
|
||||
}
|
||||
//voices
|
||||
void SamplePlayer2D::voice_set_pitch_scale(VoiceID p_voice, float p_pitch_scale) {
|
||||
|
||||
if (!get_source_rid().is_valid())
|
||||
return;
|
||||
|
||||
SpatialSound2DServer::get_singleton()->source_voice_set_pitch_scale(get_source_rid(),p_voice,p_pitch_scale);
|
||||
|
||||
}
|
||||
|
||||
void SamplePlayer2D::voice_set_volume_scale_db(VoiceID p_voice, float p_volume_db) {
|
||||
|
||||
if (!get_source_rid().is_valid())
|
||||
return;
|
||||
SpatialSound2DServer::get_singleton()->source_voice_set_volume_scale_db(get_source_rid(),p_voice,p_volume_db);
|
||||
|
||||
}
|
||||
|
||||
bool SamplePlayer2D::is_voice_active(VoiceID p_voice) const {
|
||||
|
||||
if (!get_source_rid().is_valid())
|
||||
return false;
|
||||
return SpatialSound2DServer::get_singleton()->source_is_voice_active(get_source_rid(),p_voice);
|
||||
|
||||
}
|
||||
|
||||
void SamplePlayer2D::stop_voice(VoiceID p_voice) {
|
||||
|
||||
if (!get_source_rid().is_valid())
|
||||
return;
|
||||
SpatialSound2DServer::get_singleton()->source_stop_voice(get_source_rid(),p_voice);
|
||||
|
||||
}
|
||||
|
||||
void SamplePlayer2D::stop_all() {
|
||||
|
||||
if (!get_source_rid().is_valid())
|
||||
return;
|
||||
|
||||
for(int i=0;i<polyphony;i++) {
|
||||
|
||||
SpatialSound2DServer::get_singleton()->source_stop_voice(get_source_rid(),i);
|
||||
}
|
||||
}
|
||||
|
||||
void SamplePlayer2D::set_random_pitch_scale(float p_scale) {
|
||||
random_pitch_scale=p_scale;
|
||||
}
|
||||
|
||||
float SamplePlayer2D::get_random_pitch_scale() const {
|
||||
|
||||
return random_pitch_scale;
|
||||
}
|
||||
|
||||
String SamplePlayer2D::get_configuration_warning() const {
|
||||
|
||||
if (library.is_null()) {
|
||||
return TTR("A SampleLibrary resource must be created or set in the 'samples' property in order for SamplePlayer to play sound.");
|
||||
}
|
||||
|
||||
return String();
|
||||
}
|
||||
|
||||
void SamplePlayer2D::_bind_methods() {
|
||||
|
||||
|
||||
ClassDB::bind_method(_MD("set_sample_library","library:SampleLibrary"),&SamplePlayer2D::set_sample_library);
|
||||
ClassDB::bind_method(_MD("get_sample_library:SampleLibrary"),&SamplePlayer2D::get_sample_library);
|
||||
|
||||
ClassDB::bind_method(_MD("set_polyphony","max_voices"),&SamplePlayer2D::set_polyphony);
|
||||
ClassDB::bind_method(_MD("get_polyphony"),&SamplePlayer2D::get_polyphony);
|
||||
|
||||
ClassDB::bind_method(_MD("play","sample","voice"),&SamplePlayer2D::play,DEFVAL(NEXT_VOICE));
|
||||
//voices,DEV
|
||||
ClassDB::bind_method(_MD("voice_set_pitch_scale","voice","ratio"),&SamplePlayer2D::voice_set_pitch_scale);
|
||||
ClassDB::bind_method(_MD("voice_set_volume_scale_db","voice","db"),&SamplePlayer2D::voice_set_volume_scale_db);
|
||||
|
||||
ClassDB::bind_method(_MD("is_voice_active","voice"),&SamplePlayer2D::is_voice_active);
|
||||
ClassDB::bind_method(_MD("stop_voice","voice"),&SamplePlayer2D::stop_voice);
|
||||
ClassDB::bind_method(_MD("stop_all"),&SamplePlayer2D::stop_all);
|
||||
|
||||
ClassDB::bind_method(_MD("set_random_pitch_scale","val"),&SamplePlayer2D::set_random_pitch_scale);
|
||||
ClassDB::bind_method(_MD("get_random_pitch_scale"),&SamplePlayer2D::get_random_pitch_scale);
|
||||
|
||||
BIND_CONSTANT( INVALID_VOICE );
|
||||
BIND_CONSTANT( NEXT_VOICE );
|
||||
|
||||
ADD_GROUP("Config","");
|
||||
ADD_PROPERTY( PropertyInfo( Variant::INT, "polyphony", PROPERTY_HINT_RANGE, "1,64,1"),_SCS("set_polyphony"),_SCS("get_polyphony"));
|
||||
ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "samples", PROPERTY_HINT_RESOURCE_TYPE,"SampleLibrary"),_SCS("set_sample_library"),_SCS("get_sample_library"));
|
||||
ADD_PROPERTY( PropertyInfo( Variant::REAL, "pitch_random", PROPERTY_HINT_RESOURCE_TYPE,"SampleLibrary"),_SCS("set_random_pitch_scale"),_SCS("get_random_pitch_scale"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
SamplePlayer2D::SamplePlayer2D() {
|
||||
|
||||
polyphony=1;
|
||||
random_pitch_scale=0;
|
||||
|
||||
}
|
||||
|
||||
SamplePlayer2D::~SamplePlayer2D() {
|
||||
|
||||
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* sample_player_2d.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#ifndef SAMPLE_PLAYER_2D_H
|
||||
#define SAMPLE_PLAYER_2D_H
|
||||
|
||||
#include "scene/2d/sound_player_2d.h"
|
||||
#include "scene/resources/sample_library.h"
|
||||
|
||||
class SamplePlayer2D : public SoundPlayer2D {
|
||||
|
||||
GDCLASS(SamplePlayer2D,SoundPlayer2D);
|
||||
public:
|
||||
|
||||
enum {
|
||||
|
||||
INVALID_VOICE=SpatialSoundServer::SOURCE_INVALID_VOICE,
|
||||
NEXT_VOICE=SpatialSoundServer::SOURCE_NEXT_VOICE
|
||||
};
|
||||
|
||||
typedef int VoiceID;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
Ref<SampleLibrary> library;
|
||||
int polyphony;
|
||||
String played_back;
|
||||
float random_pitch_scale;
|
||||
|
||||
protected:
|
||||
|
||||
bool _set(const StringName& p_name, const Variant& p_value);
|
||||
bool _get(const StringName& p_name,Variant &r_ret) const;
|
||||
void _get_property_list(List<PropertyInfo> *p_list) const;
|
||||
|
||||
void _notification(int p_what);
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
|
||||
void set_sample_library(const Ref<SampleLibrary>& p_library);
|
||||
Ref<SampleLibrary> get_sample_library() const;
|
||||
|
||||
void set_polyphony(int p_voice_count);
|
||||
int get_polyphony() const;
|
||||
|
||||
VoiceID play(const String& p_sample,int p_voice=NEXT_VOICE);
|
||||
//voices
|
||||
void voice_set_pitch_scale(VoiceID p_voice, float p_pitch_scale);
|
||||
void voice_set_volume_scale_db(VoiceID p_voice, float p_volume_db);
|
||||
|
||||
bool is_voice_active(VoiceID p_voice) const;
|
||||
void stop_voice(VoiceID p_voice);
|
||||
void stop_all();
|
||||
|
||||
void set_random_pitch_scale(float p_scale);
|
||||
float get_random_pitch_scale() const;
|
||||
|
||||
String get_configuration_warning() const;
|
||||
|
||||
SamplePlayer2D();
|
||||
~SamplePlayer2D();
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // SAMPLE_PLAYER_2D_H
|
||||
@@ -1,125 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* sound_player_2d.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include "sound_player_2d.h"
|
||||
|
||||
#include "servers/audio_server.h"
|
||||
|
||||
#include "servers/spatial_sound_2d_server.h"
|
||||
#include "scene/resources/surface_tool.h"
|
||||
|
||||
|
||||
void SoundPlayer2D::_notification(int p_what) {
|
||||
|
||||
|
||||
switch(p_what) {
|
||||
|
||||
case NOTIFICATION_ENTER_TREE: {
|
||||
//find the sound space
|
||||
|
||||
source_rid = SpatialSound2DServer::get_singleton()->source_create(get_world_2d()->get_sound_space());
|
||||
|
||||
for(int i=0;i<PARAM_MAX;i++)
|
||||
set_param(Param(i),params[i]);
|
||||
|
||||
SpatialSound2DServer::get_singleton()->source_set_transform(source_rid,get_global_transform());
|
||||
|
||||
|
||||
} break;
|
||||
case NOTIFICATION_TRANSFORM_CHANGED: {
|
||||
|
||||
SpatialSound2DServer::get_singleton()->source_set_transform(source_rid,get_global_transform());
|
||||
|
||||
} break;
|
||||
case NOTIFICATION_EXIT_TREE: {
|
||||
|
||||
if (source_rid.is_valid())
|
||||
SpatialSound2DServer::get_singleton()->free(source_rid);
|
||||
|
||||
} break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void SoundPlayer2D::set_param( Param p_param, float p_value) {
|
||||
|
||||
ERR_FAIL_INDEX(p_param,PARAM_MAX);
|
||||
params[p_param]=p_value;
|
||||
if (source_rid.is_valid())
|
||||
SpatialSound2DServer::get_singleton()->source_set_param(source_rid,(SpatialSound2DServer::SourceParam)p_param,p_value);
|
||||
|
||||
}
|
||||
|
||||
float SoundPlayer2D::get_param( Param p_param) const {
|
||||
|
||||
ERR_FAIL_INDEX_V(p_param,PARAM_MAX,0);
|
||||
return params[p_param];
|
||||
|
||||
}
|
||||
|
||||
|
||||
void SoundPlayer2D::_bind_methods() {
|
||||
|
||||
|
||||
ClassDB::bind_method(_MD("set_param","param","value"),&SoundPlayer2D::set_param);
|
||||
ClassDB::bind_method(_MD("get_param","param"),&SoundPlayer2D::get_param);
|
||||
|
||||
BIND_CONSTANT( PARAM_VOLUME_DB );
|
||||
BIND_CONSTANT( PARAM_PITCH_SCALE );
|
||||
BIND_CONSTANT( PARAM_ATTENUATION_MIN_DISTANCE );
|
||||
BIND_CONSTANT( PARAM_ATTENUATION_MAX_DISTANCE );
|
||||
BIND_CONSTANT( PARAM_ATTENUATION_DISTANCE_EXP );
|
||||
BIND_CONSTANT( PARAM_MAX );
|
||||
|
||||
ADD_GROUP("Parameters","");
|
||||
ADD_PROPERTYI( PropertyInfo( Variant::REAL, "volume_db",PROPERTY_HINT_RANGE, "-80,24,0.01"),_SCS("set_param"),_SCS("get_param"),PARAM_VOLUME_DB);
|
||||
ADD_PROPERTYI( PropertyInfo( Variant::REAL, "pitch_scale",PROPERTY_HINT_RANGE, "0.001,32,0.001"),_SCS("set_param"),_SCS("get_param"),PARAM_PITCH_SCALE);
|
||||
ADD_GROUP("Attenuation","attenuation_");
|
||||
ADD_PROPERTYI( PropertyInfo( Variant::REAL, "attenuation_min_distance",PROPERTY_HINT_EXP_RANGE, "16,16384,1"),_SCS("set_param"),_SCS("get_param"),PARAM_ATTENUATION_MIN_DISTANCE);
|
||||
ADD_PROPERTYI( PropertyInfo( Variant::REAL, "attenuation_max_distance",PROPERTY_HINT_EXP_RANGE, "16,16384,1"),_SCS("set_param"),_SCS("get_param"),PARAM_ATTENUATION_MAX_DISTANCE);
|
||||
ADD_PROPERTYI( PropertyInfo( Variant::REAL, "attenuation_distance_exp",PROPERTY_HINT_EXP_EASING, "attenuation"),_SCS("set_param"),_SCS("get_param"),PARAM_ATTENUATION_DISTANCE_EXP);
|
||||
|
||||
}
|
||||
|
||||
|
||||
SoundPlayer2D::SoundPlayer2D() {
|
||||
|
||||
params[PARAM_VOLUME_DB]=0.0;
|
||||
params[PARAM_PITCH_SCALE]=1.0;
|
||||
params[PARAM_ATTENUATION_MIN_DISTANCE]=1;
|
||||
params[PARAM_ATTENUATION_MAX_DISTANCE]=2048;
|
||||
params[PARAM_ATTENUATION_DISTANCE_EXP]=1.0; //linear (and not really good)
|
||||
|
||||
set_notify_transform(true);
|
||||
}
|
||||
|
||||
SoundPlayer2D::~SoundPlayer2D() {
|
||||
|
||||
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* sound_player_2d.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#ifndef SOUND_PLAYER_2D_H
|
||||
#define SOUND_PLAYER_2D_H
|
||||
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
#include "scene/resources/sample_library.h"
|
||||
#include "servers/spatial_sound_2d_server.h"
|
||||
#include "scene/main/viewport.h"
|
||||
|
||||
class SoundPlayer2D : public Node2D {
|
||||
|
||||
GDCLASS(SoundPlayer2D,Node2D);
|
||||
public:
|
||||
|
||||
|
||||
enum Param {
|
||||
|
||||
PARAM_VOLUME_DB=SpatialSound2DServer::SOURCE_PARAM_VOLUME_DB,
|
||||
PARAM_PITCH_SCALE=SpatialSound2DServer::SOURCE_PARAM_PITCH_SCALE,
|
||||
PARAM_ATTENUATION_MIN_DISTANCE=SpatialSound2DServer::SOURCE_PARAM_ATTENUATION_MIN_DISTANCE,
|
||||
PARAM_ATTENUATION_MAX_DISTANCE=SpatialSound2DServer::SOURCE_PARAM_ATTENUATION_MAX_DISTANCE,
|
||||
PARAM_ATTENUATION_DISTANCE_EXP=SpatialSound2DServer::SOURCE_PARAM_ATTENUATION_DISTANCE_EXP,
|
||||
PARAM_MAX=SpatialSound2DServer::SOURCE_PARAM_MAX
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
float params[PARAM_MAX];
|
||||
RID source_rid;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
_FORCE_INLINE_ RID get_source_rid() const { return source_rid; }
|
||||
|
||||
void _notification(int p_what);
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
|
||||
void set_param( Param p_param, float p_value);
|
||||
float get_param( Param p_param) const;
|
||||
|
||||
|
||||
SoundPlayer2D();
|
||||
~SoundPlayer2D();
|
||||
|
||||
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST(SoundPlayer2D::Param );
|
||||
|
||||
#endif // SOUND_PLAYER_2D_H
|
||||
@@ -56,17 +56,11 @@ void Room::_notification(int p_what) {
|
||||
}
|
||||
|
||||
|
||||
if (sound_enabled)
|
||||
SpatialSoundServer::get_singleton()->room_set_space(sound_room,get_world()->get_sound_space());
|
||||
|
||||
} break;
|
||||
case NOTIFICATION_TRANSFORM_CHANGED: {
|
||||
SpatialSoundServer::get_singleton()->room_set_transform(sound_room,get_global_transform());
|
||||
} break;
|
||||
case NOTIFICATION_EXIT_WORLD: {
|
||||
|
||||
if (sound_enabled)
|
||||
SpatialSoundServer::get_singleton()->room_set_space(sound_room,RID());
|
||||
|
||||
|
||||
} break;
|
||||
@@ -158,39 +152,12 @@ void Room::_parse_node_faces(PoolVector<Face3> &all_faces,const Node *p_node) co
|
||||
|
||||
|
||||
|
||||
void Room::set_simulate_acoustics(bool p_enable) {
|
||||
|
||||
if (sound_enabled==p_enable)
|
||||
return;
|
||||
|
||||
sound_enabled=p_enable;
|
||||
if (!is_inside_world())
|
||||
return; //nothing to do
|
||||
|
||||
if (sound_enabled)
|
||||
SpatialSoundServer::get_singleton()->room_set_space(sound_room,get_world()->get_sound_space());
|
||||
else
|
||||
SpatialSoundServer::get_singleton()->room_set_space(sound_room,RID());
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Room::_bounds_changed() {
|
||||
|
||||
update_gizmo();
|
||||
}
|
||||
|
||||
bool Room::is_simulating_acoustics() const {
|
||||
|
||||
return sound_enabled;
|
||||
}
|
||||
|
||||
|
||||
|
||||
RID Room::get_sound_room() const {
|
||||
|
||||
return RID();
|
||||
}
|
||||
|
||||
void Room::_bind_methods() {
|
||||
|
||||
@@ -198,21 +165,14 @@ void Room::_bind_methods() {
|
||||
ClassDB::bind_method(_MD("get_room:Room"),&Room::get_room );
|
||||
|
||||
|
||||
|
||||
ClassDB::bind_method(_MD("set_simulate_acoustics","enable"),&Room::set_simulate_acoustics );
|
||||
ClassDB::bind_method(_MD("is_simulating_acoustics"),&Room::is_simulating_acoustics );
|
||||
|
||||
|
||||
|
||||
ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "room/room", PROPERTY_HINT_RESOURCE_TYPE, "Area" ), _SCS("set_room"), _SCS("get_room") );
|
||||
ADD_PROPERTY( PropertyInfo( Variant::BOOL, "room/simulate_acoustics"), _SCS("set_simulate_acoustics"), _SCS("is_simulating_acoustics") );
|
||||
|
||||
}
|
||||
|
||||
|
||||
Room::Room() {
|
||||
|
||||
sound_enabled=false;
|
||||
sound_room=SpatialSoundServer::get_singleton()->room_create();
|
||||
// sound_enabled=false;
|
||||
|
||||
level=0;
|
||||
|
||||
@@ -222,6 +182,6 @@ Room::Room() {
|
||||
|
||||
Room::~Room() {
|
||||
|
||||
SpatialSoundServer::get_singleton()->free(sound_room);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
#include "scene/3d/visual_instance.h"
|
||||
#include "scene/resources/room.h"
|
||||
#include "servers/spatial_sound_server.h"
|
||||
|
||||
/**
|
||||
@author Juan Linietsky <reduzio@gmail.com>
|
||||
*/
|
||||
@@ -58,9 +58,6 @@ public:
|
||||
private:
|
||||
Ref<RoomBounds> room;
|
||||
|
||||
RID sound_room;
|
||||
|
||||
bool sound_enabled;
|
||||
|
||||
int level;
|
||||
void _parse_node_faces(PoolVector<Face3> &all_faces,const Node *p_node) const;
|
||||
@@ -88,11 +85,6 @@ public:
|
||||
void set_room( const Ref<RoomBounds>& p_room );
|
||||
Ref<RoomBounds> get_room() const;
|
||||
|
||||
void set_simulate_acoustics(bool p_enable);
|
||||
bool is_simulating_acoustics() const;
|
||||
|
||||
|
||||
RID get_sound_room() const;
|
||||
|
||||
Room();
|
||||
~Room();
|
||||
|
||||
@@ -1,135 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* spatial_player.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include "spatial_player.h"
|
||||
|
||||
#include "servers/audio_server.h"
|
||||
#include "camera.h"
|
||||
#include "servers/spatial_sound_server.h"
|
||||
#include "scene/resources/surface_tool.h"
|
||||
|
||||
|
||||
void SpatialPlayer::_notification(int p_what) {
|
||||
|
||||
|
||||
switch(p_what) {
|
||||
|
||||
case NOTIFICATION_ENTER_WORLD: {
|
||||
//find the sound space
|
||||
|
||||
source_rid = SpatialSoundServer::get_singleton()->source_create(get_world()->get_sound_space());
|
||||
for(int i=0;i<PARAM_MAX;i++)
|
||||
set_param(Param(i),params[i]);
|
||||
|
||||
|
||||
} break;
|
||||
case NOTIFICATION_TRANSFORM_CHANGED: {
|
||||
|
||||
SpatialSoundServer::get_singleton()->source_set_transform(source_rid,get_global_transform());
|
||||
|
||||
} break;
|
||||
case NOTIFICATION_EXIT_WORLD: {
|
||||
|
||||
if (source_rid.is_valid())
|
||||
SpatialSoundServer::get_singleton()->free(source_rid);
|
||||
|
||||
} break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void SpatialPlayer::set_param( Param p_param, float p_value) {
|
||||
|
||||
ERR_FAIL_INDEX(p_param,PARAM_MAX);
|
||||
params[p_param]=p_value;
|
||||
if (p_param==PARAM_EMISSION_CONE_DEGREES) {
|
||||
update_gizmo();
|
||||
}
|
||||
if (source_rid.is_valid())
|
||||
SpatialSoundServer::get_singleton()->source_set_param(source_rid,(SpatialSoundServer::SourceParam)p_param,p_value);
|
||||
|
||||
}
|
||||
|
||||
float SpatialPlayer::get_param( Param p_param) const {
|
||||
|
||||
ERR_FAIL_INDEX_V(p_param,PARAM_MAX,0);
|
||||
return params[p_param];
|
||||
|
||||
}
|
||||
|
||||
bool SpatialPlayer::_can_gizmo_scale() const {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void SpatialPlayer::_bind_methods() {
|
||||
|
||||
|
||||
ClassDB::bind_method(_MD("set_param","param","value"),&SpatialPlayer::set_param);
|
||||
ClassDB::bind_method(_MD("get_param","param"),&SpatialPlayer::get_param);
|
||||
|
||||
BIND_CONSTANT( PARAM_VOLUME_DB );
|
||||
BIND_CONSTANT( PARAM_PITCH_SCALE );
|
||||
BIND_CONSTANT( PARAM_ATTENUATION_MIN_DISTANCE );
|
||||
BIND_CONSTANT( PARAM_ATTENUATION_MAX_DISTANCE );
|
||||
BIND_CONSTANT( PARAM_ATTENUATION_DISTANCE_EXP );
|
||||
BIND_CONSTANT( PARAM_EMISSION_CONE_DEGREES );
|
||||
BIND_CONSTANT( PARAM_EMISSION_CONE_ATTENUATION_DB );
|
||||
BIND_CONSTANT( PARAM_MAX );
|
||||
|
||||
ADD_PROPERTYI( PropertyInfo( Variant::REAL, "volume_db",PROPERTY_HINT_RANGE, "-80,24,0.01"),_SCS("set_param"),_SCS("get_param"),PARAM_VOLUME_DB);
|
||||
ADD_PROPERTYI( PropertyInfo( Variant::REAL, "pitch_scale",PROPERTY_HINT_RANGE, "0.001,32,0.001"),_SCS("set_param"),_SCS("get_param"),PARAM_PITCH_SCALE);
|
||||
ADD_GROUP("Attenuation","attenuation_");
|
||||
ADD_PROPERTYI( PropertyInfo( Variant::REAL, "attenuation_min_distance",PROPERTY_HINT_RANGE, "0.01,4096,0.01"),_SCS("set_param"),_SCS("get_param"),PARAM_ATTENUATION_MIN_DISTANCE);
|
||||
ADD_PROPERTYI( PropertyInfo( Variant::REAL, "attenuation_max_distance",PROPERTY_HINT_RANGE, "0.01,4096,0.01"),_SCS("set_param"),_SCS("get_param"),PARAM_ATTENUATION_MAX_DISTANCE);
|
||||
ADD_PROPERTYI( PropertyInfo( Variant::REAL, "attenuation_distance_exp",PROPERTY_HINT_EXP_EASING, "attenuation"),_SCS("set_param"),_SCS("get_param"),PARAM_ATTENUATION_DISTANCE_EXP);
|
||||
ADD_GROUP("Emission Cone","emission_cone_");
|
||||
ADD_PROPERTYI( PropertyInfo( Variant::REAL, "emission_cone_degrees",PROPERTY_HINT_RANGE, "0,180,0.01"),_SCS("set_param"),_SCS("get_param"),PARAM_EMISSION_CONE_DEGREES);
|
||||
ADD_PROPERTYI( PropertyInfo( Variant::REAL, "emission_cone_attenuation_db",PROPERTY_HINT_RANGE, "-80,24,0.01"),_SCS("set_param"),_SCS("get_param"),PARAM_EMISSION_CONE_ATTENUATION_DB);
|
||||
|
||||
}
|
||||
|
||||
|
||||
SpatialPlayer::SpatialPlayer() {
|
||||
|
||||
params[PARAM_VOLUME_DB]=0.0;
|
||||
params[PARAM_PITCH_SCALE]=1.0;
|
||||
params[PARAM_ATTENUATION_MIN_DISTANCE]=1;
|
||||
params[PARAM_ATTENUATION_MAX_DISTANCE]=100;
|
||||
params[PARAM_ATTENUATION_DISTANCE_EXP]=1.0; //linear (and not really good)
|
||||
params[PARAM_EMISSION_CONE_DEGREES]=180.0; //cone disabled
|
||||
params[PARAM_EMISSION_CONE_ATTENUATION_DB]=-6.0; //minus 6 db attenuation
|
||||
set_notify_transform(true);
|
||||
|
||||
}
|
||||
|
||||
SpatialPlayer::~SpatialPlayer() {
|
||||
|
||||
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* spatial_player.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#ifndef SPATIAL_PLAYER_H
|
||||
#define SPATIAL_PLAYER_H
|
||||
|
||||
|
||||
#include "scene/3d/spatial.h"
|
||||
#include "scene/main/node.h"
|
||||
#include "scene/resources/sample_library.h"
|
||||
#include "servers/spatial_sound_server.h"
|
||||
#include "scene/main/viewport.h"
|
||||
|
||||
class SpatialPlayer : public Spatial {
|
||||
|
||||
GDCLASS(SpatialPlayer,Spatial);
|
||||
public:
|
||||
|
||||
|
||||
enum Param {
|
||||
|
||||
PARAM_VOLUME_DB=SpatialSoundServer::SOURCE_PARAM_VOLUME_DB,
|
||||
PARAM_PITCH_SCALE=SpatialSoundServer::SOURCE_PARAM_PITCH_SCALE,
|
||||
PARAM_ATTENUATION_MIN_DISTANCE=SpatialSoundServer::SOURCE_PARAM_ATTENUATION_MIN_DISTANCE,
|
||||
PARAM_ATTENUATION_MAX_DISTANCE=SpatialSoundServer::SOURCE_PARAM_ATTENUATION_MAX_DISTANCE,
|
||||
PARAM_ATTENUATION_DISTANCE_EXP=SpatialSoundServer::SOURCE_PARAM_ATTENUATION_DISTANCE_EXP,
|
||||
PARAM_EMISSION_CONE_DEGREES=SpatialSoundServer::SOURCE_PARAM_EMISSION_CONE_DEGREES,
|
||||
PARAM_EMISSION_CONE_ATTENUATION_DB=SpatialSoundServer::SOURCE_PARAM_EMISSION_CONE_ATTENUATION_DB,
|
||||
PARAM_MAX=SpatialSoundServer::SOURCE_PARAM_MAX
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
float params[PARAM_MAX];
|
||||
RID source_rid;
|
||||
|
||||
virtual bool _can_gizmo_scale() const;
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
_FORCE_INLINE_ RID get_source_rid() const { return source_rid; }
|
||||
|
||||
void _notification(int p_what);
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
|
||||
void set_param( Param p_param, float p_value);
|
||||
float get_param( Param p_param) const;
|
||||
|
||||
|
||||
SpatialPlayer();
|
||||
~SpatialPlayer();
|
||||
|
||||
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST( SpatialPlayer::Param );
|
||||
#endif // SPATIAL_PLAYER_H
|
||||
@@ -1,241 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* spatial_sample_player.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include "spatial_sample_player.h"
|
||||
|
||||
#include "servers/audio_server.h"
|
||||
#include "camera.h"
|
||||
#include "servers/spatial_sound_server.h"
|
||||
#include "scene/scene_string_names.h"
|
||||
|
||||
bool SpatialSamplePlayer::_set(const StringName& p_name, const Variant& p_value) {
|
||||
|
||||
String name=p_name;
|
||||
|
||||
if (name==SceneStringNames::get_singleton()->play_play) {
|
||||
if (library.is_valid()) {
|
||||
|
||||
String what=p_value;
|
||||
if (what=="")
|
||||
stop_all();
|
||||
else
|
||||
play(what);
|
||||
|
||||
played_back=what;
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SpatialSamplePlayer::_get(const StringName& p_name,Variant &r_ret) const {
|
||||
|
||||
|
||||
String name=p_name;
|
||||
|
||||
if (name==SceneStringNames::get_singleton()->play_play) {
|
||||
r_ret=played_back;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void SpatialSamplePlayer::_get_property_list(List<PropertyInfo> *p_list) const {
|
||||
|
||||
String en="";
|
||||
if (library.is_valid()) {
|
||||
List<StringName> samples;
|
||||
Ref<SampleLibrary> ncl=library;
|
||||
ncl->get_sample_list(&samples);
|
||||
for (List<StringName>::Element *E=samples.front();E;E=E->next()) {
|
||||
|
||||
en+=",";
|
||||
en+=E->get();
|
||||
}
|
||||
}
|
||||
|
||||
p_list->push_back( PropertyInfo( Variant::STRING, "play/play", PROPERTY_HINT_ENUM, en,PROPERTY_USAGE_EDITOR|PROPERTY_USAGE_ANIMATE_AS_TRIGGER));
|
||||
|
||||
}
|
||||
void SpatialSamplePlayer::_notification(int p_what) {
|
||||
|
||||
|
||||
switch(p_what) {
|
||||
|
||||
case NOTIFICATION_ENTER_WORLD: {
|
||||
|
||||
SpatialSoundServer::get_singleton()->source_set_polyphony(get_source_rid(),polyphony);
|
||||
|
||||
|
||||
} break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SpatialSamplePlayer::set_sample_library(const Ref<SampleLibrary>& p_library) {
|
||||
|
||||
library=p_library;
|
||||
_change_notify();
|
||||
update_configuration_warning();
|
||||
}
|
||||
|
||||
Ref<SampleLibrary> SpatialSamplePlayer::get_sample_library() const {
|
||||
|
||||
return library;
|
||||
}
|
||||
|
||||
void SpatialSamplePlayer::set_polyphony(int p_voice_count) {
|
||||
|
||||
ERR_FAIL_COND(p_voice_count<0 || p_voice_count>64);
|
||||
polyphony=p_voice_count;
|
||||
if (get_source_rid().is_valid())
|
||||
SpatialSoundServer::get_singleton()->source_set_polyphony(get_source_rid(),polyphony);
|
||||
|
||||
}
|
||||
|
||||
int SpatialSamplePlayer::get_polyphony() const {
|
||||
|
||||
return polyphony;
|
||||
}
|
||||
|
||||
SpatialSamplePlayer::VoiceID SpatialSamplePlayer::play(const String& p_sample,int p_voice) {
|
||||
|
||||
if (!get_source_rid().is_valid())
|
||||
return INVALID_VOICE;
|
||||
if (library.is_null())
|
||||
return INVALID_VOICE;
|
||||
if (!library->has_sample(p_sample))
|
||||
return INVALID_VOICE;
|
||||
Ref<Sample> sample = library->get_sample(p_sample);
|
||||
float vol_change = library->sample_get_volume_db(p_sample);
|
||||
float pitch_change = library->sample_get_pitch_scale(p_sample);
|
||||
|
||||
VoiceID vid = SpatialSoundServer::get_singleton()->source_play_sample(get_source_rid(),sample->get_rid(),sample->get_mix_rate()*pitch_change,p_voice);
|
||||
if (vol_change)
|
||||
SpatialSoundServer::get_singleton()->source_voice_set_volume_scale_db(get_source_rid(),vid,vol_change);
|
||||
|
||||
return vid;
|
||||
|
||||
|
||||
}
|
||||
//voices
|
||||
void SpatialSamplePlayer::voice_set_pitch_scale(VoiceID p_voice, float p_pitch_scale) {
|
||||
|
||||
if (!get_source_rid().is_valid())
|
||||
return;
|
||||
|
||||
SpatialSoundServer::get_singleton()->source_voice_set_pitch_scale(get_source_rid(),p_voice,p_pitch_scale);
|
||||
|
||||
}
|
||||
|
||||
void SpatialSamplePlayer::voice_set_volume_scale_db(VoiceID p_voice, float p_volume_db) {
|
||||
|
||||
if (!get_source_rid().is_valid())
|
||||
return;
|
||||
SpatialSoundServer::get_singleton()->source_voice_set_volume_scale_db(get_source_rid(),p_voice,p_volume_db);
|
||||
|
||||
}
|
||||
|
||||
bool SpatialSamplePlayer::is_voice_active(VoiceID p_voice) const {
|
||||
|
||||
if (!get_source_rid().is_valid())
|
||||
return false;
|
||||
return SpatialSoundServer::get_singleton()->source_is_voice_active(get_source_rid(),p_voice);
|
||||
|
||||
}
|
||||
|
||||
void SpatialSamplePlayer::stop_voice(VoiceID p_voice) {
|
||||
|
||||
if (!get_source_rid().is_valid())
|
||||
return;
|
||||
SpatialSoundServer::get_singleton()->source_stop_voice(get_source_rid(),p_voice);
|
||||
|
||||
}
|
||||
|
||||
void SpatialSamplePlayer::stop_all() {
|
||||
|
||||
if (!get_source_rid().is_valid())
|
||||
return;
|
||||
|
||||
for(int i=0;i<polyphony;i++) {
|
||||
|
||||
SpatialSoundServer::get_singleton()->source_stop_voice(get_source_rid(),i);
|
||||
}
|
||||
}
|
||||
|
||||
String SpatialSamplePlayer::get_configuration_warning() const {
|
||||
|
||||
if (library.is_null()) {
|
||||
return TTR("A SampleLibrary resource must be created or set in the 'samples' property in order for SpatialSamplePlayer to play sound.");
|
||||
}
|
||||
|
||||
return String();
|
||||
}
|
||||
|
||||
|
||||
void SpatialSamplePlayer::_bind_methods() {
|
||||
|
||||
|
||||
ClassDB::bind_method(_MD("set_sample_library","library:SampleLibrary"),&SpatialSamplePlayer::set_sample_library);
|
||||
ClassDB::bind_method(_MD("get_sample_library:SampleLibrary"),&SpatialSamplePlayer::get_sample_library);
|
||||
|
||||
ClassDB::bind_method(_MD("set_polyphony","voices"),&SpatialSamplePlayer::set_polyphony);
|
||||
ClassDB::bind_method(_MD("get_polyphony"),&SpatialSamplePlayer::get_polyphony);
|
||||
|
||||
ClassDB::bind_method(_MD("play","sample","voice"),&SpatialSamplePlayer::play,DEFVAL(NEXT_VOICE));
|
||||
//voices,DEV
|
||||
ClassDB::bind_method(_MD("voice_set_pitch_scale","voice","ratio"),&SpatialSamplePlayer::voice_set_pitch_scale);
|
||||
ClassDB::bind_method(_MD("voice_set_volume_scale_db","voice","db"),&SpatialSamplePlayer::voice_set_volume_scale_db);
|
||||
|
||||
ClassDB::bind_method(_MD("is_voice_active","voice"),&SpatialSamplePlayer::is_voice_active);
|
||||
ClassDB::bind_method(_MD("stop_voice","voice"),&SpatialSamplePlayer::stop_voice);
|
||||
ClassDB::bind_method(_MD("stop_all"),&SpatialSamplePlayer::stop_all);
|
||||
|
||||
BIND_CONSTANT( INVALID_VOICE );
|
||||
BIND_CONSTANT( NEXT_VOICE );
|
||||
|
||||
ADD_PROPERTY( PropertyInfo( Variant::INT, "polyphony", PROPERTY_HINT_RANGE, "1,64,1"),_SCS("set_polyphony"),_SCS("get_polyphony"));
|
||||
ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "samples", PROPERTY_HINT_RESOURCE_TYPE,"SampleLibrary"),_SCS("set_sample_library"),_SCS("get_sample_library"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
SpatialSamplePlayer::SpatialSamplePlayer() {
|
||||
|
||||
polyphony=1;
|
||||
|
||||
}
|
||||
|
||||
SpatialSamplePlayer::~SpatialSamplePlayer() {
|
||||
|
||||
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* spatial_sample_player.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#ifndef SPATIAL_SAMPLE_PLAYER_H
|
||||
#define SPATIAL_SAMPLE_PLAYER_H
|
||||
|
||||
#include "scene/3d/spatial_player.h"
|
||||
#include "scene/resources/sample_library.h"
|
||||
#include "servers/spatial_sound_server.h"
|
||||
|
||||
class SpatialSamplePlayer : public SpatialPlayer {
|
||||
|
||||
GDCLASS(SpatialSamplePlayer,SpatialPlayer);
|
||||
public:
|
||||
|
||||
enum {
|
||||
|
||||
INVALID_VOICE=SpatialSoundServer::SOURCE_INVALID_VOICE,
|
||||
NEXT_VOICE=SpatialSoundServer::SOURCE_NEXT_VOICE
|
||||
};
|
||||
|
||||
typedef int VoiceID;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
Ref<SampleLibrary> library;
|
||||
int polyphony;
|
||||
String played_back;
|
||||
protected:
|
||||
|
||||
bool _set(const StringName& p_name, const Variant& p_value);
|
||||
bool _get(const StringName& p_name,Variant &r_ret) const;
|
||||
void _get_property_list(List<PropertyInfo> *p_list) const;
|
||||
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
|
||||
void set_sample_library(const Ref<SampleLibrary>& p_library);
|
||||
Ref<SampleLibrary> get_sample_library() const;
|
||||
|
||||
void set_polyphony(int p_voice_count);
|
||||
int get_polyphony() const;
|
||||
|
||||
VoiceID play(const String& p_sample,int p_voice=NEXT_VOICE);
|
||||
//voices
|
||||
void voice_set_pitch_scale(VoiceID p_voice, float p_pitch_scale);
|
||||
void voice_set_volume_scale_db(VoiceID p_voice, float p_volume_db);
|
||||
|
||||
bool is_voice_active(VoiceID p_voice) const;
|
||||
void stop_voice(VoiceID p_voice);
|
||||
void stop_all();
|
||||
|
||||
String get_configuration_warning() const;
|
||||
|
||||
SpatialSamplePlayer();
|
||||
~SpatialSamplePlayer();
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // SPATIAL_SAMPLE_PLAYER_H
|
||||
@@ -1,407 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* spatial_stream_player.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include "spatial_stream_player.h"
|
||||
|
||||
|
||||
|
||||
int SpatialStreamPlayer::InternalStream::get_channel_count() const {
|
||||
|
||||
return player->sp_get_channel_count();
|
||||
}
|
||||
void SpatialStreamPlayer::InternalStream::set_mix_rate(int p_rate){
|
||||
|
||||
return player->sp_set_mix_rate(p_rate);
|
||||
}
|
||||
bool SpatialStreamPlayer::InternalStream::mix(int32_t *p_buffer,int p_frames){
|
||||
|
||||
return player->sp_mix(p_buffer,p_frames);
|
||||
}
|
||||
void SpatialStreamPlayer::InternalStream::update(){
|
||||
|
||||
player->sp_update();
|
||||
}
|
||||
|
||||
|
||||
int SpatialStreamPlayer::sp_get_channel_count() const {
|
||||
|
||||
return playback->get_channels();
|
||||
}
|
||||
|
||||
void SpatialStreamPlayer::sp_set_mix_rate(int p_rate){
|
||||
|
||||
server_mix_rate=p_rate;
|
||||
}
|
||||
|
||||
bool SpatialStreamPlayer::sp_mix(int32_t *p_buffer,int p_frames) {
|
||||
|
||||
if (resampler.is_ready() && !paused) {
|
||||
return resampler.mix(p_buffer,p_frames);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void SpatialStreamPlayer::sp_update() {
|
||||
|
||||
_THREAD_SAFE_METHOD_
|
||||
if (!paused && resampler.is_ready() && playback.is_valid()) {
|
||||
|
||||
if (!playback->is_playing()) {
|
||||
//stream depleted data, but there's still audio in the ringbuffer
|
||||
//check that all this audio has been flushed before stopping the stream
|
||||
int to_mix = resampler.get_total() - resampler.get_todo();
|
||||
if (to_mix==0) {
|
||||
stop();
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int todo =resampler.get_todo();
|
||||
int wrote = playback->mix(resampler.get_write_buffer(),todo);
|
||||
resampler.write(wrote);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SpatialStreamPlayer::_notification(int p_what) {
|
||||
|
||||
switch(p_what) {
|
||||
|
||||
case NOTIFICATION_ENTER_TREE: {
|
||||
|
||||
//set_idle_process(false); //don't annoy
|
||||
if (stream.is_valid() && autoplay && !get_tree()->is_editor_hint())
|
||||
play();
|
||||
} break;
|
||||
case NOTIFICATION_EXIT_TREE: {
|
||||
|
||||
stop(); //wathever it may be doing, stop
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SpatialStreamPlayer::set_stream(const Ref<AudioStream> &p_stream) {
|
||||
|
||||
stop();
|
||||
|
||||
stream=p_stream;
|
||||
|
||||
if (!stream.is_null()) {
|
||||
playback=stream->instance_playback();
|
||||
playback->set_loop(loops);
|
||||
playback->set_loop_restart_time(loop_point);
|
||||
AudioServer::get_singleton()->lock();
|
||||
resampler.setup(playback->get_channels(),playback->get_mix_rate(),server_mix_rate,buffering_ms,playback->get_minimum_buffer_size());
|
||||
AudioServer::get_singleton()->unlock();
|
||||
} else {
|
||||
AudioServer::get_singleton()->lock();
|
||||
resampler.clear();
|
||||
playback.unref();
|
||||
AudioServer::get_singleton()->unlock();
|
||||
}
|
||||
}
|
||||
|
||||
Ref<AudioStream> SpatialStreamPlayer::get_stream() const {
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
void SpatialStreamPlayer::play(float p_from_offset) {
|
||||
|
||||
ERR_FAIL_COND(!is_inside_tree());
|
||||
if (playback.is_null())
|
||||
return;
|
||||
if (playback->is_playing())
|
||||
stop();
|
||||
|
||||
_THREAD_SAFE_METHOD_
|
||||
playback->play(p_from_offset);
|
||||
//feed the ringbuffer as long as no update callback is going on
|
||||
sp_update();
|
||||
|
||||
SpatialSoundServer::get_singleton()->source_set_audio_stream(get_source_rid(),&internal_stream);
|
||||
|
||||
/*
|
||||
AudioServer::get_singleton()->stream_set_active(stream_rid,true);
|
||||
AudioServer::get_singleton()->stream_set_volume_scale(stream_rid,volume);
|
||||
if (stream->get_update_mode()!=AudioStream::UPDATE_NONE)
|
||||
set_idle_process(true);
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
void SpatialStreamPlayer::stop() {
|
||||
|
||||
if (!is_inside_tree())
|
||||
return;
|
||||
if (playback.is_null())
|
||||
return;
|
||||
|
||||
_THREAD_SAFE_METHOD_
|
||||
//AudioServer::get_singleton()->stream_set_active(stream_rid,false);
|
||||
SpatialSoundServer::get_singleton()->source_set_audio_stream(get_source_rid(),NULL);
|
||||
playback->stop();
|
||||
resampler.flush();
|
||||
//set_idle_process(false);
|
||||
}
|
||||
|
||||
bool SpatialStreamPlayer::is_playing() const {
|
||||
|
||||
if (playback.is_null())
|
||||
return false;
|
||||
|
||||
return playback->is_playing();
|
||||
}
|
||||
|
||||
void SpatialStreamPlayer::set_loop(bool p_enable) {
|
||||
|
||||
loops=p_enable;
|
||||
if (playback.is_null())
|
||||
return;
|
||||
playback->set_loop(loops);
|
||||
|
||||
}
|
||||
bool SpatialStreamPlayer::has_loop() const {
|
||||
|
||||
return loops;
|
||||
}
|
||||
|
||||
void SpatialStreamPlayer::set_volume(float p_vol) {
|
||||
|
||||
volume=p_vol;
|
||||
if (stream_rid.is_valid())
|
||||
AudioServer::get_singleton()->stream_set_volume_scale(stream_rid,volume);
|
||||
}
|
||||
|
||||
float SpatialStreamPlayer::get_volume() const {
|
||||
|
||||
return volume;
|
||||
}
|
||||
|
||||
void SpatialStreamPlayer::set_loop_restart_time(float p_secs) {
|
||||
|
||||
loop_point=p_secs;
|
||||
if (playback.is_valid())
|
||||
playback->set_loop_restart_time(p_secs);
|
||||
}
|
||||
|
||||
float SpatialStreamPlayer::get_loop_restart_time() const {
|
||||
|
||||
return loop_point;
|
||||
}
|
||||
|
||||
|
||||
void SpatialStreamPlayer::set_volume_db(float p_db) {
|
||||
|
||||
if (p_db<-79)
|
||||
set_volume(0);
|
||||
else
|
||||
set_volume(Math::db2linear(p_db));
|
||||
}
|
||||
|
||||
float SpatialStreamPlayer::get_volume_db() const {
|
||||
|
||||
if (volume==0)
|
||||
return -80;
|
||||
else
|
||||
return Math::linear2db(volume);
|
||||
}
|
||||
|
||||
|
||||
String SpatialStreamPlayer::get_stream_name() const {
|
||||
|
||||
if (stream.is_null())
|
||||
return "<No Stream>";
|
||||
return stream->get_name();
|
||||
|
||||
}
|
||||
|
||||
int SpatialStreamPlayer::get_loop_count() const {
|
||||
|
||||
if (playback.is_null())
|
||||
return 0;
|
||||
return playback->get_loop_count();
|
||||
|
||||
}
|
||||
|
||||
float SpatialStreamPlayer::get_pos() const {
|
||||
|
||||
if (playback.is_null())
|
||||
return 0;
|
||||
return playback->get_pos();
|
||||
|
||||
}
|
||||
|
||||
float SpatialStreamPlayer::get_length() const {
|
||||
|
||||
if (playback.is_null())
|
||||
return 0;
|
||||
return playback->get_length();
|
||||
}
|
||||
void SpatialStreamPlayer::seek_pos(float p_time) {
|
||||
|
||||
if (playback.is_null())
|
||||
return;
|
||||
return playback->seek_pos(p_time);
|
||||
|
||||
}
|
||||
|
||||
void SpatialStreamPlayer::set_autoplay(bool p_enable) {
|
||||
|
||||
autoplay=p_enable;
|
||||
}
|
||||
|
||||
bool SpatialStreamPlayer::has_autoplay() const {
|
||||
|
||||
return autoplay;
|
||||
}
|
||||
|
||||
void SpatialStreamPlayer::set_paused(bool p_paused) {
|
||||
|
||||
paused=p_paused;
|
||||
/*
|
||||
if (stream.is_valid())
|
||||
stream->set_paused(p_paused);
|
||||
*/
|
||||
}
|
||||
|
||||
bool SpatialStreamPlayer::is_paused() const {
|
||||
|
||||
return paused;
|
||||
}
|
||||
|
||||
void SpatialStreamPlayer::_set_play(bool p_play) {
|
||||
|
||||
_play=p_play;
|
||||
if (is_inside_tree()) {
|
||||
if(_play)
|
||||
play();
|
||||
else
|
||||
stop();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool SpatialStreamPlayer::_get_play() const{
|
||||
|
||||
return _play;
|
||||
}
|
||||
|
||||
void SpatialStreamPlayer::set_buffering_msec(int p_msec) {
|
||||
|
||||
buffering_ms=p_msec;
|
||||
}
|
||||
|
||||
int SpatialStreamPlayer::get_buffering_msec() const{
|
||||
|
||||
return buffering_ms;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SpatialStreamPlayer::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(_MD("set_stream","stream:AudioStream"),&SpatialStreamPlayer::set_stream);
|
||||
ClassDB::bind_method(_MD("get_stream:AudioStream"),&SpatialStreamPlayer::get_stream);
|
||||
|
||||
ClassDB::bind_method(_MD("play","offset"),&SpatialStreamPlayer::play,DEFVAL(0));
|
||||
ClassDB::bind_method(_MD("stop"),&SpatialStreamPlayer::stop);
|
||||
|
||||
ClassDB::bind_method(_MD("is_playing"),&SpatialStreamPlayer::is_playing);
|
||||
|
||||
ClassDB::bind_method(_MD("set_paused","paused"),&SpatialStreamPlayer::set_paused);
|
||||
ClassDB::bind_method(_MD("is_paused"),&SpatialStreamPlayer::is_paused);
|
||||
|
||||
ClassDB::bind_method(_MD("set_loop","enabled"),&SpatialStreamPlayer::set_loop);
|
||||
ClassDB::bind_method(_MD("has_loop"),&SpatialStreamPlayer::has_loop);
|
||||
|
||||
ClassDB::bind_method(_MD("set_volume","volume"),&SpatialStreamPlayer::set_volume);
|
||||
ClassDB::bind_method(_MD("get_volume"),&SpatialStreamPlayer::get_volume);
|
||||
|
||||
ClassDB::bind_method(_MD("set_volume_db","db"),&SpatialStreamPlayer::set_volume_db);
|
||||
ClassDB::bind_method(_MD("get_volume_db"),&SpatialStreamPlayer::get_volume_db);
|
||||
|
||||
ClassDB::bind_method(_MD("set_buffering_msec","msec"),&SpatialStreamPlayer::set_buffering_msec);
|
||||
ClassDB::bind_method(_MD("get_buffering_msec"),&SpatialStreamPlayer::get_buffering_msec);
|
||||
|
||||
ClassDB::bind_method(_MD("set_loop_restart_time","secs"),&SpatialStreamPlayer::set_loop_restart_time);
|
||||
ClassDB::bind_method(_MD("get_loop_restart_time"),&SpatialStreamPlayer::get_loop_restart_time);
|
||||
|
||||
ClassDB::bind_method(_MD("get_stream_name"),&SpatialStreamPlayer::get_stream_name);
|
||||
ClassDB::bind_method(_MD("get_loop_count"),&SpatialStreamPlayer::get_loop_count);
|
||||
|
||||
ClassDB::bind_method(_MD("get_pos"),&SpatialStreamPlayer::get_pos);
|
||||
ClassDB::bind_method(_MD("seek_pos","time"),&SpatialStreamPlayer::seek_pos);
|
||||
|
||||
ClassDB::bind_method(_MD("set_autoplay","enabled"),&SpatialStreamPlayer::set_autoplay);
|
||||
ClassDB::bind_method(_MD("has_autoplay"),&SpatialStreamPlayer::has_autoplay);
|
||||
|
||||
ClassDB::bind_method(_MD("get_length"),&SpatialStreamPlayer::get_length);
|
||||
|
||||
ClassDB::bind_method(_MD("_set_play","play"),&SpatialStreamPlayer::_set_play);
|
||||
ClassDB::bind_method(_MD("_get_play"),&SpatialStreamPlayer::_get_play);
|
||||
|
||||
ADD_PROPERTY( PropertyInfo(Variant::OBJECT, "stream", PROPERTY_HINT_RESOURCE_TYPE,"AudioStream"), _SCS("set_stream"), _SCS("get_stream") );
|
||||
ADD_PROPERTY( PropertyInfo(Variant::BOOL, "play"), _SCS("_set_play"), _SCS("_get_play") );
|
||||
ADD_PROPERTY( PropertyInfo(Variant::BOOL, "loop"), _SCS("set_loop"), _SCS("has_loop") );
|
||||
ADD_PROPERTY( PropertyInfo(Variant::REAL, "volume_db", PROPERTY_HINT_RANGE,"-80,24,0.01"), _SCS("set_volume_db"), _SCS("get_volume_db") );
|
||||
ADD_PROPERTY( PropertyInfo(Variant::BOOL, "autoplay"), _SCS("set_autoplay"), _SCS("has_autoplay") );
|
||||
ADD_PROPERTY( PropertyInfo(Variant::BOOL, "paused"), _SCS("set_paused"), _SCS("is_paused") );
|
||||
ADD_PROPERTY( PropertyInfo(Variant::INT, "loop_restart_time"), _SCS("set_loop_restart_time"), _SCS("get_loop_restart_time") );
|
||||
ADD_PROPERTY( PropertyInfo(Variant::INT, "buffering_ms"), _SCS("set_buffering_msec"), _SCS("get_buffering_msec") );
|
||||
}
|
||||
|
||||
|
||||
SpatialStreamPlayer::SpatialStreamPlayer() {
|
||||
|
||||
volume=1;
|
||||
loops=false;
|
||||
paused=false;
|
||||
autoplay=false;
|
||||
_play=false;
|
||||
server_mix_rate=1;
|
||||
internal_stream.player=this;
|
||||
stream_rid=AudioServer::get_singleton()->audio_stream_create(&internal_stream);
|
||||
buffering_ms=500;
|
||||
loop_point=0;
|
||||
|
||||
}
|
||||
|
||||
SpatialStreamPlayer::~SpatialStreamPlayer() {
|
||||
AudioServer::get_singleton()->free(stream_rid);
|
||||
resampler.clear();
|
||||
|
||||
|
||||
}
|
||||
@@ -1,120 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* spatial_stream_player.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#ifndef SPATIAL_STREAM_PLAYER_H
|
||||
#define SPATIAL_STREAM_PLAYER_H
|
||||
|
||||
#include "scene/resources/audio_stream.h"
|
||||
#include "scene/3d/spatial_player.h"
|
||||
#include "servers/audio/audio_rb_resampler.h"
|
||||
|
||||
class SpatialStreamPlayer : public SpatialPlayer {
|
||||
|
||||
GDCLASS(SpatialStreamPlayer,SpatialPlayer);
|
||||
|
||||
_THREAD_SAFE_CLASS_
|
||||
|
||||
struct InternalStream : public AudioServer::AudioStream {
|
||||
SpatialStreamPlayer *player;
|
||||
virtual int get_channel_count() const;
|
||||
virtual void set_mix_rate(int p_rate); //notify the stream of the mix rate
|
||||
virtual bool mix(int32_t *p_buffer,int p_frames);
|
||||
virtual void update();
|
||||
};
|
||||
|
||||
|
||||
InternalStream internal_stream;
|
||||
Ref<AudioStreamPlayback> playback;
|
||||
Ref<AudioStream> stream;
|
||||
|
||||
int sp_get_channel_count() const;
|
||||
void sp_set_mix_rate(int p_rate); //notify the stream of the mix rate
|
||||
bool sp_mix(int32_t *p_buffer,int p_frames);
|
||||
void sp_update();
|
||||
|
||||
int server_mix_rate;
|
||||
|
||||
RID stream_rid;
|
||||
bool paused;
|
||||
bool autoplay;
|
||||
bool loops;
|
||||
float volume;
|
||||
float loop_point;
|
||||
int buffering_ms;
|
||||
|
||||
AudioRBResampler resampler;
|
||||
|
||||
bool _play;
|
||||
void _set_play(bool p_play);
|
||||
bool _get_play() const;
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
|
||||
static void _bind_methods();
|
||||
public:
|
||||
|
||||
void set_stream(const Ref<AudioStream> &p_stream);
|
||||
Ref<AudioStream> get_stream() const;
|
||||
|
||||
void play(float p_from_offset=0);
|
||||
void stop();
|
||||
bool is_playing() const;
|
||||
|
||||
void set_paused(bool p_paused);
|
||||
bool is_paused() const;
|
||||
|
||||
void set_loop(bool p_enable);
|
||||
bool has_loop() const;
|
||||
|
||||
void set_volume(float p_vol);
|
||||
float get_volume() const;
|
||||
|
||||
void set_loop_restart_time(float p_secs);
|
||||
float get_loop_restart_time() const;
|
||||
|
||||
void set_volume_db(float p_db);
|
||||
float get_volume_db() const;
|
||||
|
||||
String get_stream_name() const;
|
||||
|
||||
int get_loop_count() const;
|
||||
|
||||
float get_pos() const;
|
||||
void seek_pos(float p_time);
|
||||
float get_length() const;
|
||||
void set_autoplay(bool p_vol);
|
||||
bool has_autoplay() const;
|
||||
|
||||
void set_buffering_msec(int p_msec);
|
||||
int get_buffering_msec() const;
|
||||
|
||||
SpatialStreamPlayer();
|
||||
~SpatialStreamPlayer();
|
||||
};
|
||||
|
||||
#endif // SPATIAL_STREAM_PLAYER_H
|
||||
@@ -1,357 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* event_player.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include "event_player.h"
|
||||
|
||||
|
||||
void EventPlayer::_notification(int p_what) {
|
||||
|
||||
switch(p_what) {
|
||||
|
||||
case NOTIFICATION_ENTER_TREE: {
|
||||
|
||||
//set_idle_process(false); //don't annoy
|
||||
if (playback.is_valid() && autoplay && !get_tree()->is_editor_hint())
|
||||
play();
|
||||
} break;
|
||||
case NOTIFICATION_EXIT_TREE: {
|
||||
|
||||
stop(); //wathever it may be doing, stop
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void EventPlayer::set_stream(const Ref<EventStream> &p_stream) {
|
||||
|
||||
stop();
|
||||
stream=p_stream;
|
||||
if (stream.is_valid())
|
||||
playback=stream->instance_playback();
|
||||
else
|
||||
playback.unref();
|
||||
|
||||
if (playback.is_valid()) {
|
||||
|
||||
playback->set_loop(loops);
|
||||
playback->set_paused(paused);
|
||||
playback->set_volume(volume);
|
||||
for(int i=0;i<(MIN(MAX_CHANNELS,stream->get_channel_count()));i++)
|
||||
playback->set_channel_volume(i,channel_volume[i]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Ref<EventStream> EventPlayer::get_stream() const {
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
void EventPlayer::play() {
|
||||
|
||||
ERR_FAIL_COND(!is_inside_tree());
|
||||
if (playback.is_null()) {
|
||||
return;
|
||||
}
|
||||
if (playback->is_playing()) {
|
||||
AudioServer::get_singleton()->lock();
|
||||
stop();
|
||||
AudioServer::get_singleton()->unlock();
|
||||
}
|
||||
|
||||
AudioServer::get_singleton()->lock();
|
||||
playback->play();
|
||||
AudioServer::get_singleton()->unlock();
|
||||
|
||||
}
|
||||
|
||||
void EventPlayer::stop() {
|
||||
|
||||
if (!is_inside_tree())
|
||||
return;
|
||||
if (playback.is_null())
|
||||
return;
|
||||
|
||||
AudioServer::get_singleton()->lock();
|
||||
playback->stop();
|
||||
AudioServer::get_singleton()->unlock();
|
||||
}
|
||||
|
||||
bool EventPlayer::is_playing() const {
|
||||
|
||||
if (playback.is_null())
|
||||
return false;
|
||||
|
||||
return playback->is_playing();
|
||||
}
|
||||
|
||||
void EventPlayer::set_loop(bool p_enable) {
|
||||
|
||||
loops=p_enable;
|
||||
if (playback.is_null())
|
||||
return;
|
||||
playback->set_loop(loops);
|
||||
|
||||
}
|
||||
bool EventPlayer::has_loop() const {
|
||||
|
||||
return loops;
|
||||
}
|
||||
|
||||
void EventPlayer::set_volume(float p_volume) {
|
||||
|
||||
volume=p_volume;
|
||||
if (playback.is_valid())
|
||||
playback->set_volume(volume);
|
||||
}
|
||||
|
||||
float EventPlayer::get_volume() const {
|
||||
|
||||
return volume;
|
||||
}
|
||||
|
||||
|
||||
void EventPlayer::set_volume_db(float p_db) {
|
||||
|
||||
if (p_db<-79)
|
||||
set_volume(0);
|
||||
else
|
||||
set_volume(Math::db2linear(p_db));
|
||||
}
|
||||
|
||||
float EventPlayer::get_volume_db() const {
|
||||
|
||||
if (volume==0)
|
||||
return -80;
|
||||
else
|
||||
return Math::linear2db(volume);
|
||||
}
|
||||
|
||||
void EventPlayer::set_pitch_scale(float p_pitch_scale) {
|
||||
|
||||
pitch_scale=p_pitch_scale;
|
||||
if (playback.is_valid())
|
||||
playback->set_pitch_scale(pitch_scale);
|
||||
}
|
||||
|
||||
float EventPlayer::get_pitch_scale() const {
|
||||
|
||||
return pitch_scale;
|
||||
}
|
||||
|
||||
void EventPlayer::set_tempo_scale(float p_tempo_scale) {
|
||||
|
||||
tempo_scale=p_tempo_scale;
|
||||
if (playback.is_valid())
|
||||
playback->set_tempo_scale(tempo_scale);
|
||||
}
|
||||
|
||||
float EventPlayer::get_tempo_scale() const {
|
||||
|
||||
return tempo_scale;
|
||||
}
|
||||
|
||||
|
||||
String EventPlayer::get_stream_name() const {
|
||||
|
||||
if (stream.is_null())
|
||||
return "<No Stream>";
|
||||
return stream->get_name();
|
||||
|
||||
}
|
||||
|
||||
int EventPlayer::get_loop_count() const {
|
||||
|
||||
if (playback.is_null())
|
||||
return 0;
|
||||
return playback->get_loop_count();
|
||||
|
||||
}
|
||||
|
||||
float EventPlayer::get_pos() const {
|
||||
|
||||
if (playback.is_null())
|
||||
return 0;
|
||||
return playback->get_pos();
|
||||
|
||||
}
|
||||
|
||||
float EventPlayer::get_length() const {
|
||||
|
||||
if (stream.is_null())
|
||||
return 0;
|
||||
return stream->get_length();
|
||||
}
|
||||
void EventPlayer::seek_pos(float p_time) {
|
||||
|
||||
if (playback.is_null())
|
||||
return;
|
||||
return playback->seek_pos(p_time);
|
||||
|
||||
}
|
||||
|
||||
void EventPlayer::set_autoplay(bool p_enable) {
|
||||
|
||||
autoplay=p_enable;
|
||||
}
|
||||
|
||||
bool EventPlayer::has_autoplay() const {
|
||||
|
||||
return autoplay;
|
||||
}
|
||||
|
||||
void EventPlayer::set_paused(bool p_paused) {
|
||||
|
||||
paused=p_paused;
|
||||
if (playback.is_valid())
|
||||
playback->set_paused(p_paused);
|
||||
}
|
||||
|
||||
bool EventPlayer::is_paused() const {
|
||||
|
||||
return paused;
|
||||
}
|
||||
|
||||
void EventPlayer::_set_play(bool p_play) {
|
||||
|
||||
_play=p_play;
|
||||
if (is_inside_tree()) {
|
||||
if(_play)
|
||||
play();
|
||||
else
|
||||
stop();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool EventPlayer::_get_play() const{
|
||||
|
||||
return _play;
|
||||
}
|
||||
|
||||
void EventPlayer::set_channel_volume(int p_channel,float p_volume) {
|
||||
|
||||
ERR_FAIL_INDEX(p_channel,MAX_CHANNELS);
|
||||
channel_volume[p_channel]=p_volume;
|
||||
if (playback.is_valid())
|
||||
playback->set_channel_volume(p_channel,p_volume);
|
||||
}
|
||||
|
||||
float EventPlayer::get_channel_volume(int p_channel) const{
|
||||
|
||||
ERR_FAIL_INDEX_V(p_channel,MAX_CHANNELS,0);
|
||||
return channel_volume[p_channel];
|
||||
|
||||
}
|
||||
|
||||
float EventPlayer::get_channel_last_note_time(int p_channel) const {
|
||||
|
||||
if (playback.is_valid())
|
||||
return playback->get_last_note_time(p_channel);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void EventPlayer::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(_MD("set_stream","stream:EventStream"),&EventPlayer::set_stream);
|
||||
ClassDB::bind_method(_MD("get_stream:EventStream"),&EventPlayer::get_stream);
|
||||
|
||||
ClassDB::bind_method(_MD("play"),&EventPlayer::play);
|
||||
ClassDB::bind_method(_MD("stop"),&EventPlayer::stop);
|
||||
|
||||
ClassDB::bind_method(_MD("is_playing"),&EventPlayer::is_playing);
|
||||
|
||||
ClassDB::bind_method(_MD("set_paused","paused"),&EventPlayer::set_paused);
|
||||
ClassDB::bind_method(_MD("is_paused"),&EventPlayer::is_paused);
|
||||
|
||||
ClassDB::bind_method(_MD("set_loop","enabled"),&EventPlayer::set_loop);
|
||||
ClassDB::bind_method(_MD("has_loop"),&EventPlayer::has_loop);
|
||||
|
||||
ClassDB::bind_method(_MD("set_volume","volume"),&EventPlayer::set_volume);
|
||||
ClassDB::bind_method(_MD("get_volume"),&EventPlayer::get_volume);
|
||||
|
||||
ClassDB::bind_method(_MD("set_pitch_scale","pitch_scale"),&EventPlayer::set_pitch_scale);
|
||||
ClassDB::bind_method(_MD("get_pitch_scale"),&EventPlayer::get_pitch_scale);
|
||||
|
||||
ClassDB::bind_method(_MD("set_tempo_scale","tempo_scale"),&EventPlayer::set_tempo_scale);
|
||||
ClassDB::bind_method(_MD("get_tempo_scale"),&EventPlayer::get_tempo_scale);
|
||||
|
||||
ClassDB::bind_method(_MD("set_volume_db","db"),&EventPlayer::set_volume_db);
|
||||
ClassDB::bind_method(_MD("get_volume_db"),&EventPlayer::get_volume_db);
|
||||
|
||||
ClassDB::bind_method(_MD("get_stream_name"),&EventPlayer::get_stream_name);
|
||||
ClassDB::bind_method(_MD("get_loop_count"),&EventPlayer::get_loop_count);
|
||||
|
||||
ClassDB::bind_method(_MD("get_pos"),&EventPlayer::get_pos);
|
||||
ClassDB::bind_method(_MD("seek_pos","time"),&EventPlayer::seek_pos);
|
||||
|
||||
ClassDB::bind_method(_MD("get_length"),&EventPlayer::get_length);
|
||||
|
||||
ClassDB::bind_method(_MD("set_autoplay","enabled"),&EventPlayer::set_autoplay);
|
||||
ClassDB::bind_method(_MD("has_autoplay"),&EventPlayer::has_autoplay);
|
||||
|
||||
ClassDB::bind_method(_MD("set_channel_volume","channel","channel_volume"),&EventPlayer::set_channel_volume);
|
||||
ClassDB::bind_method(_MD("get_channel_volume","channel"),&EventPlayer::get_channel_volume);
|
||||
ClassDB::bind_method(_MD("get_channel_last_note_time","channel"),&EventPlayer::get_channel_last_note_time);
|
||||
|
||||
ClassDB::bind_method(_MD("_set_play","play"),&EventPlayer::_set_play);
|
||||
ClassDB::bind_method(_MD("_get_play"),&EventPlayer::_get_play);
|
||||
|
||||
ADD_PROPERTY( PropertyInfo(Variant::OBJECT, "stream", PROPERTY_HINT_RESOURCE_TYPE,"EventStream"), _SCS("set_stream"), _SCS("get_stream") );
|
||||
ADD_PROPERTY( PropertyInfo(Variant::BOOL, "play"), _SCS("_set_play"), _SCS("_get_play") );
|
||||
ADD_PROPERTY( PropertyInfo(Variant::BOOL, "loop"), _SCS("set_loop"), _SCS("has_loop") );
|
||||
ADD_PROPERTY( PropertyInfo(Variant::REAL, "volume_db", PROPERTY_HINT_RANGE,"-80,24,0.01"), _SCS("set_volume_db"), _SCS("get_volume_db") );
|
||||
ADD_PROPERTY( PropertyInfo(Variant::REAL, "pitch_scale", PROPERTY_HINT_RANGE,"0.001,16,0.001"), _SCS("set_pitch_scale"), _SCS("get_pitch_scale") );
|
||||
ADD_PROPERTY( PropertyInfo(Variant::REAL, "tempo_scale", PROPERTY_HINT_RANGE,"0.001,16,0.001"), _SCS("set_tempo_scale"), _SCS("get_tempo_scale") );
|
||||
ADD_PROPERTY( PropertyInfo(Variant::BOOL, "autoplay"), _SCS("set_autoplay"), _SCS("has_autoplay") );
|
||||
ADD_PROPERTY( PropertyInfo(Variant::BOOL, "paused"), _SCS("set_paused"), _SCS("is_paused") );
|
||||
}
|
||||
|
||||
|
||||
EventPlayer::EventPlayer() {
|
||||
|
||||
volume=1;
|
||||
loops=false;
|
||||
paused=false;
|
||||
autoplay=false;
|
||||
_play=false;
|
||||
pitch_scale=1.0;
|
||||
tempo_scale=1.0;
|
||||
for(int i=0;i<MAX_CHANNELS;i++)
|
||||
channel_volume[i]=1.0;
|
||||
|
||||
}
|
||||
|
||||
EventPlayer::~EventPlayer() {
|
||||
|
||||
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* event_player.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#ifndef EVENT_PLAYER_H
|
||||
#define EVENT_PLAYER_H
|
||||
|
||||
|
||||
#include "scene/main/node.h"
|
||||
#include "scene/resources/event_stream.h"
|
||||
class EventPlayer : public Node {
|
||||
|
||||
GDCLASS(EventPlayer,Node);
|
||||
|
||||
|
||||
enum {
|
||||
MAX_CHANNELS=256
|
||||
};
|
||||
|
||||
Ref<EventStreamPlayback> playback;
|
||||
Ref<EventStream> stream;
|
||||
bool paused;
|
||||
bool autoplay;
|
||||
bool loops;
|
||||
float volume;
|
||||
|
||||
float tempo_scale;
|
||||
float pitch_scale;
|
||||
|
||||
float channel_volume[MAX_CHANNELS];
|
||||
bool _play;
|
||||
void _set_play(bool p_play);
|
||||
bool _get_play() const;
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
|
||||
void set_stream(const Ref<EventStream> &p_stream);
|
||||
Ref<EventStream> get_stream() const;
|
||||
|
||||
void play();
|
||||
void stop();
|
||||
bool is_playing() const;
|
||||
|
||||
void set_paused(bool p_paused);
|
||||
bool is_paused() const;
|
||||
|
||||
void set_loop(bool p_enable);
|
||||
bool has_loop() const;
|
||||
|
||||
void set_volume(float p_vol);
|
||||
float get_volume() const;
|
||||
|
||||
void set_volume_db(float p_db);
|
||||
float get_volume_db() const;
|
||||
|
||||
void set_pitch_scale(float p_scale);
|
||||
float get_pitch_scale() const;
|
||||
|
||||
void set_tempo_scale(float p_scale);
|
||||
float get_tempo_scale() const;
|
||||
|
||||
String get_stream_name() const;
|
||||
|
||||
int get_loop_count() const;
|
||||
|
||||
float get_pos() const;
|
||||
void seek_pos(float p_time);
|
||||
float get_length() const;
|
||||
void set_autoplay(bool p_vol);
|
||||
bool has_autoplay() const;
|
||||
|
||||
void set_channel_volume(int p_channel,float p_volume);
|
||||
float get_channel_volume(int p_channel) const;
|
||||
|
||||
float get_channel_last_note_time(int p_channel) const;
|
||||
|
||||
EventPlayer();
|
||||
~EventPlayer();
|
||||
};
|
||||
|
||||
#endif // EVENT_PLAYER_H
|
||||
@@ -1,718 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* sample_player.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include "sample_player.h"
|
||||
|
||||
#include "servers/audio_server.h"
|
||||
|
||||
|
||||
bool SamplePlayer::_set(const StringName& p_name, const Variant& p_value) {
|
||||
|
||||
String name=p_name;
|
||||
|
||||
if (name=="play/play") {
|
||||
if (library.is_valid()) {
|
||||
|
||||
String what=p_value;
|
||||
if (what=="")
|
||||
stop_all();
|
||||
else
|
||||
play(what);
|
||||
|
||||
played_back=what;
|
||||
}
|
||||
} else if (name=="config/samples")
|
||||
set_sample_library(p_value);
|
||||
else if (name=="config/polyphony")
|
||||
set_polyphony(p_value);
|
||||
else if (name.begins_with("default/")) {
|
||||
|
||||
String what=name.right(8);
|
||||
|
||||
if (what=="volume_db")
|
||||
set_default_volume_db(p_value);
|
||||
else if (what=="pitch_scale")
|
||||
set_default_pitch_scale(p_value);
|
||||
else if (what=="pan")
|
||||
_default.pan=p_value;
|
||||
else if (what=="depth")
|
||||
_default.depth=p_value;
|
||||
else if (what=="height")
|
||||
_default.height=p_value;
|
||||
else if (what=="filter/type")
|
||||
_default.filter_type=FilterType(p_value.operator int());
|
||||
else if (what=="filter/cutoff")
|
||||
_default.filter_cutoff=p_value;
|
||||
else if (what=="filter/resonance")
|
||||
_default.filter_resonance=p_value;
|
||||
else if (what=="filter/gain")
|
||||
_default.filter_gain=p_value;
|
||||
else if (what=="reverb_room")
|
||||
_default.reverb_room=ReverbRoomType(p_value.operator int());
|
||||
else if (what=="reverb_send")
|
||||
_default.reverb_send=p_value;
|
||||
else if (what=="chorus_send")
|
||||
_default.chorus_send=p_value;
|
||||
else
|
||||
return false;
|
||||
|
||||
|
||||
} else
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SamplePlayer::_get(const StringName& p_name,Variant &r_ret) const {
|
||||
|
||||
|
||||
String name=p_name;
|
||||
|
||||
if (name=="play/play") {
|
||||
r_ret=played_back;
|
||||
} else if (name=="config/polyphony") {
|
||||
r_ret= get_polyphony();
|
||||
} else if (name=="config/samples") {
|
||||
|
||||
r_ret= get_sample_library();
|
||||
} else if (name.begins_with("default/")) {
|
||||
|
||||
String what=name.right(8);
|
||||
|
||||
if (what=="volume_db")
|
||||
r_ret= get_default_volume_db();
|
||||
else if (what=="pitch_scale")
|
||||
r_ret= get_default_pitch_scale();
|
||||
else if (what=="pan")
|
||||
r_ret= _default.pan;
|
||||
else if (what=="depth")
|
||||
r_ret= _default.depth;
|
||||
else if (what=="height")
|
||||
r_ret= _default.height;
|
||||
else if (what=="filter/type")
|
||||
r_ret= _default.filter_type;
|
||||
else if (what=="filter/cutoff")
|
||||
r_ret= _default.filter_cutoff;
|
||||
else if (what=="filter/resonance")
|
||||
r_ret= _default.filter_resonance;
|
||||
else if (what=="filter/gain")
|
||||
r_ret= _default.filter_gain;
|
||||
else if (what=="reverb_room")
|
||||
r_ret= _default.reverb_room;
|
||||
else if (what=="reverb_send")
|
||||
r_ret= _default.reverb_send;
|
||||
else if (what=="chorus_send")
|
||||
r_ret= _default.chorus_send;
|
||||
else
|
||||
return false;
|
||||
|
||||
|
||||
} else
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void SamplePlayer::_get_property_list(List<PropertyInfo> *p_list) const {
|
||||
|
||||
String en="";
|
||||
if (library.is_valid()) {
|
||||
List<StringName> samples;
|
||||
Ref<SampleLibrary> ncl=library;
|
||||
ncl->get_sample_list(&samples);
|
||||
for (List<StringName>::Element *E=samples.front();E;E=E->next()) {
|
||||
|
||||
en+=",";
|
||||
en+=E->get();
|
||||
}
|
||||
}
|
||||
|
||||
p_list->push_back( PropertyInfo( Variant::STRING, "play/play", PROPERTY_HINT_ENUM, en,PROPERTY_USAGE_EDITOR|PROPERTY_USAGE_ANIMATE_AS_TRIGGER));
|
||||
p_list->push_back( PropertyInfo( Variant::INT, "config/polyphony", PROPERTY_HINT_RANGE, "1,256,1"));
|
||||
p_list->push_back( PropertyInfo( Variant::OBJECT, "config/samples", PROPERTY_HINT_RESOURCE_TYPE, "SampleLibrary"));
|
||||
p_list->push_back( PropertyInfo( Variant::REAL, "default/volume_db", PROPERTY_HINT_RANGE, "-80,24,0.01"));
|
||||
p_list->push_back( PropertyInfo( Variant::REAL, "default/pitch_scale", PROPERTY_HINT_RANGE, "0.01,48,0.01"));
|
||||
p_list->push_back( PropertyInfo( Variant::REAL, "default/pan", PROPERTY_HINT_RANGE, "-1,1,0.01"));
|
||||
p_list->push_back( PropertyInfo( Variant::REAL, "default/depth", PROPERTY_HINT_RANGE, "-1,1,0.01"));
|
||||
p_list->push_back( PropertyInfo( Variant::REAL, "default/height", PROPERTY_HINT_RANGE, "-1,1,0.01"));
|
||||
p_list->push_back( PropertyInfo( Variant::INT, "default/filter/type", PROPERTY_HINT_ENUM, "Disabled,Lowpass,Bandpass,Highpass,Notch,Peak,BandLimit,LowShelf,HighShelf"));
|
||||
p_list->push_back( PropertyInfo( Variant::REAL, "default/filter/cutoff", PROPERTY_HINT_RANGE, "20,16384.0,0.01"));
|
||||
p_list->push_back( PropertyInfo( Variant::REAL, "default/filter/resonance", PROPERTY_HINT_RANGE, "0,4,0.01"));
|
||||
p_list->push_back( PropertyInfo( Variant::REAL, "default/filter/gain", PROPERTY_HINT_RANGE, "0,2,0.01"));
|
||||
p_list->push_back( PropertyInfo( Variant::INT, "default/reverb_room", PROPERTY_HINT_ENUM, "Small,Medium,Large,Hall"));
|
||||
p_list->push_back( PropertyInfo( Variant::REAL, "default/reverb_send", PROPERTY_HINT_RANGE, "0,1,0.01"));
|
||||
p_list->push_back( PropertyInfo( Variant::REAL, "default/chorus_send", PROPERTY_HINT_RANGE, "0,1,0.01"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
SamplePlayer::Voice::Voice() {
|
||||
|
||||
voice=AudioServer::get_singleton()->voice_create();
|
||||
clear();
|
||||
}
|
||||
|
||||
|
||||
void SamplePlayer::Voice::clear() {
|
||||
|
||||
check=0;
|
||||
|
||||
mix_rate=44100;
|
||||
volume=1;
|
||||
pan=0;
|
||||
pan_depth=0;
|
||||
pan_height=0;
|
||||
filter_type=FILTER_NONE;
|
||||
filter_cutoff=0;
|
||||
filter_resonance=0;
|
||||
chorus_send=0;
|
||||
reverb_room=REVERB_HALL;
|
||||
reverb_send=0;
|
||||
active=false;
|
||||
|
||||
}
|
||||
SamplePlayer::Voice::~Voice() {
|
||||
|
||||
AudioServer::get_singleton()->free(voice);
|
||||
}
|
||||
|
||||
|
||||
void SamplePlayer::set_polyphony(int p_voice_count) {
|
||||
|
||||
ERR_FAIL_COND( p_voice_count <1 || p_voice_count >0xFFFE );
|
||||
|
||||
voices.resize(p_voice_count);
|
||||
}
|
||||
|
||||
int SamplePlayer::get_polyphony() const {
|
||||
|
||||
return voices.size();
|
||||
}
|
||||
|
||||
SamplePlayer::VoiceID SamplePlayer::play(const String& p_name,bool unique) {
|
||||
|
||||
if (library.is_null())
|
||||
return INVALID_VOICE_ID;
|
||||
ERR_FAIL_COND_V( !library->has_sample(p_name), INVALID_VOICE_ID );
|
||||
|
||||
Ref<Sample> sample = library->get_sample(p_name);
|
||||
float vol_change = library->sample_get_volume_db(p_name);
|
||||
float pitch_change = library->sample_get_pitch_scale(p_name);
|
||||
|
||||
last_check++;
|
||||
last_id = (last_id + 1) % voices.size();
|
||||
|
||||
Voice&v = voices[last_id];
|
||||
v.clear();
|
||||
|
||||
|
||||
v.mix_rate=sample->get_mix_rate()*(_default.pitch_scale*pitch_change);
|
||||
v.sample_mix_rate=sample->get_mix_rate();
|
||||
v.check=last_check;
|
||||
v.volume=Math::db2linear(_default.volume_db+vol_change);
|
||||
v.pan=_default.pan;
|
||||
v.pan_depth=_default.depth;
|
||||
v.pan_height=_default.height;
|
||||
v.filter_type=_default.filter_type;
|
||||
v.filter_cutoff=_default.filter_cutoff;
|
||||
v.filter_resonance=_default.filter_resonance;
|
||||
v.filter_gain=_default.filter_gain;
|
||||
v.chorus_send=_default.chorus_send;
|
||||
v.reverb_room=_default.reverb_room;
|
||||
v.reverb_send=_default.reverb_send;
|
||||
|
||||
AudioServer::get_singleton()->voice_play(v.voice,sample->get_rid());
|
||||
AudioServer::get_singleton()->voice_set_mix_rate(v.voice,v.mix_rate);
|
||||
AudioServer::get_singleton()->voice_set_volume(v.voice,v.volume);
|
||||
AudioServer::get_singleton()->voice_set_pan(v.voice,v.pan,v.pan_depth,v.pan_height);
|
||||
AudioServer::get_singleton()->voice_set_filter(v.voice,(AudioServer::FilterType)v.filter_type,v.filter_cutoff,v.filter_resonance,v.filter_gain);
|
||||
AudioServer::get_singleton()->voice_set_chorus(v.voice,v.chorus_send);
|
||||
AudioServer::get_singleton()->voice_set_reverb(v.voice,(AudioServer::ReverbRoomType)v.reverb_room,v.reverb_send);
|
||||
|
||||
v.active=true;
|
||||
|
||||
if (unique) {
|
||||
|
||||
for(int i=0;i<voices.size();i++) {
|
||||
|
||||
if (!voices[i].active || uint32_t(i)==last_id)
|
||||
continue;
|
||||
|
||||
AudioServer::get_singleton()->voice_stop(voices[i].voice);
|
||||
|
||||
voices[i].clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return last_id | (last_check<<16);
|
||||
}
|
||||
|
||||
void SamplePlayer::stop_all() {
|
||||
|
||||
|
||||
for(int i=0;i<voices.size();i++) {
|
||||
|
||||
if (!voices[i].active)
|
||||
continue;
|
||||
|
||||
AudioServer::get_singleton()->voice_stop(voices[i].voice);
|
||||
voices[i].clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#define _GET_VOICE\
|
||||
uint32_t voice=p_voice&0xFFFF;\
|
||||
ERR_FAIL_COND(voice >= (uint32_t)voices.size());\
|
||||
Voice &v=voices[voice];\
|
||||
if (v.check!=uint32_t(p_voice>>16))\
|
||||
return;\
|
||||
ERR_FAIL_COND(!v.active);
|
||||
|
||||
void SamplePlayer::stop(VoiceID p_voice) {
|
||||
|
||||
_GET_VOICE
|
||||
|
||||
AudioServer::get_singleton()->voice_stop(v.voice);
|
||||
v.active=false;
|
||||
|
||||
}
|
||||
|
||||
void SamplePlayer::set_mix_rate(VoiceID p_voice, int p_mix_rate) {
|
||||
|
||||
_GET_VOICE
|
||||
|
||||
v.mix_rate=p_mix_rate;
|
||||
AudioServer::get_singleton()->voice_set_mix_rate(v.voice,v.mix_rate);
|
||||
|
||||
}
|
||||
void SamplePlayer::set_pitch_scale(VoiceID p_voice, float p_pitch_scale) {
|
||||
|
||||
_GET_VOICE
|
||||
|
||||
v.mix_rate=v.sample_mix_rate*p_pitch_scale;
|
||||
AudioServer::get_singleton()->voice_set_mix_rate(v.voice,v.mix_rate);
|
||||
|
||||
}
|
||||
void SamplePlayer::set_volume(VoiceID p_voice, float p_volume) {
|
||||
|
||||
|
||||
_GET_VOICE
|
||||
v.volume=p_volume;
|
||||
AudioServer::get_singleton()->voice_set_volume(v.voice,v.volume);
|
||||
|
||||
}
|
||||
|
||||
void SamplePlayer::set_volume_db(VoiceID p_voice, float p_db) {
|
||||
|
||||
//@TODO handle 0 volume as -80db or something
|
||||
_GET_VOICE
|
||||
v.volume=Math::db2linear(p_db);
|
||||
AudioServer::get_singleton()->voice_set_volume(v.voice,v.volume);
|
||||
|
||||
}
|
||||
|
||||
void SamplePlayer::set_pan(VoiceID p_voice, float p_pan,float p_pan_depth,float p_pan_height) {
|
||||
|
||||
_GET_VOICE
|
||||
v.pan=p_pan;
|
||||
v.pan_depth=p_pan_depth;
|
||||
v.pan_height=p_pan_height;
|
||||
|
||||
AudioServer::get_singleton()->voice_set_pan(v.voice,v.pan,v.pan_depth,v.pan_height);
|
||||
|
||||
}
|
||||
|
||||
void SamplePlayer::set_filter(VoiceID p_voice,FilterType p_filter,float p_cutoff,float p_resonance,float p_gain) {
|
||||
|
||||
_GET_VOICE
|
||||
v.filter_type=p_filter;
|
||||
v.filter_cutoff=p_cutoff;
|
||||
v.filter_resonance=p_resonance;
|
||||
v.filter_gain=p_gain;
|
||||
|
||||
AudioServer::get_singleton()->voice_set_filter(v.voice,(AudioServer::FilterType)p_filter,p_cutoff,p_resonance);
|
||||
|
||||
}
|
||||
void SamplePlayer::set_chorus(VoiceID p_voice,float p_send) {
|
||||
|
||||
_GET_VOICE
|
||||
v.chorus_send=p_send;
|
||||
|
||||
AudioServer::get_singleton()->voice_set_chorus(v.voice,p_send);
|
||||
|
||||
}
|
||||
void SamplePlayer::set_reverb(VoiceID p_voice,ReverbRoomType p_room,float p_send) {
|
||||
|
||||
_GET_VOICE
|
||||
v.reverb_room=p_room;
|
||||
v.reverb_send=p_send;
|
||||
|
||||
AudioServer::get_singleton()->voice_set_reverb(v.voice,(AudioServer::ReverbRoomType)p_room,p_send);
|
||||
|
||||
}
|
||||
|
||||
#define _GET_VOICE_V(m_ret)\
|
||||
uint32_t voice=p_voice&0xFFFF;\
|
||||
ERR_FAIL_COND_V(voice >= (uint32_t)voices.size(),m_ret);\
|
||||
const Voice &v=voices[voice];\
|
||||
if (v.check!=(p_voice>>16))\
|
||||
return m_ret;\
|
||||
ERR_FAIL_COND_V(!v.active,m_ret);
|
||||
|
||||
|
||||
int SamplePlayer::get_mix_rate(VoiceID p_voice) const {
|
||||
|
||||
_GET_VOICE_V(0);
|
||||
|
||||
return v.mix_rate;
|
||||
}
|
||||
float SamplePlayer::get_pitch_scale(VoiceID p_voice) const {
|
||||
|
||||
_GET_VOICE_V(0);
|
||||
return v.sample_mix_rate/(float)v.mix_rate;
|
||||
}
|
||||
float SamplePlayer::get_volume(VoiceID p_voice) const {
|
||||
|
||||
_GET_VOICE_V(0);
|
||||
return v.volume;
|
||||
}
|
||||
|
||||
|
||||
float SamplePlayer::get_volume_db(VoiceID p_voice) const {
|
||||
|
||||
_GET_VOICE_V(0);
|
||||
return Math::linear2db(v.volume);
|
||||
}
|
||||
|
||||
float SamplePlayer::get_pan(VoiceID p_voice) const {
|
||||
|
||||
_GET_VOICE_V(0);
|
||||
return v.pan;
|
||||
}
|
||||
float SamplePlayer::get_pan_depth(VoiceID p_voice) const {
|
||||
|
||||
|
||||
_GET_VOICE_V(0);
|
||||
return v.pan_depth;
|
||||
}
|
||||
float SamplePlayer::get_pan_height(VoiceID p_voice) const {
|
||||
|
||||
_GET_VOICE_V(0);
|
||||
|
||||
return v.pan_height;
|
||||
}
|
||||
SamplePlayer::FilterType SamplePlayer::get_filter_type(VoiceID p_voice) const {
|
||||
|
||||
_GET_VOICE_V(FILTER_NONE);
|
||||
|
||||
return v.filter_type;
|
||||
}
|
||||
float SamplePlayer::get_filter_cutoff(VoiceID p_voice) const {
|
||||
|
||||
_GET_VOICE_V(0);
|
||||
|
||||
return v.filter_cutoff;
|
||||
}
|
||||
float SamplePlayer::get_filter_resonance(VoiceID p_voice) const {
|
||||
|
||||
_GET_VOICE_V(0);
|
||||
|
||||
return v.filter_resonance;
|
||||
}
|
||||
|
||||
float SamplePlayer::get_filter_gain(VoiceID p_voice) const {
|
||||
|
||||
_GET_VOICE_V(0);
|
||||
|
||||
return v.filter_gain;
|
||||
}
|
||||
float SamplePlayer::get_chorus(VoiceID p_voice) const {
|
||||
|
||||
_GET_VOICE_V(0);
|
||||
|
||||
return v.chorus_send;
|
||||
}
|
||||
SamplePlayer::ReverbRoomType SamplePlayer::get_reverb_room(VoiceID p_voice) const {
|
||||
|
||||
_GET_VOICE_V(REVERB_SMALL);
|
||||
|
||||
return v.reverb_room;
|
||||
}
|
||||
|
||||
float SamplePlayer::get_reverb(VoiceID p_voice) const {
|
||||
|
||||
_GET_VOICE_V(0);
|
||||
|
||||
return v.reverb_send;
|
||||
}
|
||||
|
||||
bool SamplePlayer::is_voice_active(VoiceID p_voice) const {
|
||||
|
||||
_GET_VOICE_V(false);
|
||||
return v.active && AudioServer::get_singleton()->voice_is_active(v.voice);
|
||||
|
||||
}
|
||||
bool SamplePlayer::is_active() const {
|
||||
|
||||
for(int i=0;i<voices.size();i++) {
|
||||
|
||||
if (voices[i].active && AudioServer::get_singleton()->voice_is_active(voices[i].voice))
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SamplePlayer::set_sample_library(const Ref<SampleLibrary>& p_library) {
|
||||
|
||||
library=p_library;
|
||||
_change_notify();
|
||||
}
|
||||
|
||||
Ref<SampleLibrary> SamplePlayer::get_sample_library() const {
|
||||
|
||||
return library;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SamplePlayer::set_default_pitch_scale(float p_pitch_scale) {
|
||||
|
||||
_default.pitch_scale=p_pitch_scale;
|
||||
}
|
||||
void SamplePlayer::set_default_volume(float p_volume) {
|
||||
|
||||
_default.volume_db=Math::linear2db(p_volume);
|
||||
}
|
||||
void SamplePlayer::set_default_volume_db(float p_db) {
|
||||
|
||||
_default.volume_db=p_db;
|
||||
}
|
||||
void SamplePlayer::set_default_pan(float p_pan,float p_pan_depth,float p_pan_height) {
|
||||
|
||||
_default.pan=p_pan;
|
||||
_default.depth=p_pan_depth;
|
||||
_default.height=p_pan_height;
|
||||
|
||||
}
|
||||
void SamplePlayer::set_default_filter(FilterType p_filter,float p_cutoff,float p_resonance,float p_gain) {
|
||||
|
||||
_default.filter_type=p_filter;
|
||||
_default.filter_cutoff=p_cutoff;
|
||||
_default.filter_resonance=p_resonance;
|
||||
_default.filter_gain=p_gain;
|
||||
}
|
||||
void SamplePlayer::set_default_chorus(float p_send) {
|
||||
|
||||
_default.chorus_send=p_send;
|
||||
|
||||
}
|
||||
void SamplePlayer::set_default_reverb(ReverbRoomType p_room,float p_send) {
|
||||
|
||||
_default.reverb_room=p_room;
|
||||
_default.reverb_send=p_send;
|
||||
}
|
||||
|
||||
float SamplePlayer::get_default_volume() const {
|
||||
|
||||
return Math::db2linear(_default.volume_db);
|
||||
}
|
||||
float SamplePlayer::get_default_volume_db() const {
|
||||
|
||||
return _default.volume_db;
|
||||
}
|
||||
float SamplePlayer::get_default_pitch_scale() const {
|
||||
|
||||
return _default.pitch_scale;
|
||||
}
|
||||
|
||||
|
||||
float SamplePlayer::get_default_pan() const {
|
||||
|
||||
return _default.pan;
|
||||
}
|
||||
float SamplePlayer::get_default_pan_depth() const {
|
||||
|
||||
return _default.depth;
|
||||
}
|
||||
float SamplePlayer::get_default_pan_height() const {
|
||||
|
||||
return _default.height;
|
||||
}
|
||||
SamplePlayer::FilterType SamplePlayer::get_default_filter_type() const {
|
||||
|
||||
return _default.filter_type;
|
||||
}
|
||||
float SamplePlayer::get_default_filter_cutoff() const {
|
||||
|
||||
return _default.filter_cutoff;
|
||||
}
|
||||
float SamplePlayer::get_default_filter_resonance() const {
|
||||
|
||||
return _default.filter_resonance;
|
||||
}
|
||||
float SamplePlayer::get_default_filter_gain() const {
|
||||
|
||||
return _default.filter_gain;
|
||||
}
|
||||
float SamplePlayer::get_default_chorus() const {
|
||||
|
||||
return _default.chorus_send;
|
||||
}
|
||||
SamplePlayer::ReverbRoomType SamplePlayer::get_default_reverb_room() const {
|
||||
|
||||
return _default.reverb_room;
|
||||
}
|
||||
float SamplePlayer::get_default_reverb() const {
|
||||
|
||||
return _default.reverb_send;
|
||||
}
|
||||
|
||||
String SamplePlayer::get_configuration_warning() const {
|
||||
|
||||
if (library.is_null()) {
|
||||
return TTR("A SampleLibrary resource must be created or set in the 'samples' property in order for SamplePlayer to play sound.");
|
||||
}
|
||||
|
||||
return String();
|
||||
}
|
||||
|
||||
void SamplePlayer::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(_MD("set_sample_library","library:SampleLibrary"),&SamplePlayer::set_sample_library );
|
||||
ClassDB::bind_method(_MD("get_sample_library:SampleLibrary"),&SamplePlayer::get_sample_library );
|
||||
|
||||
ClassDB::bind_method(_MD("set_polyphony","max_voices"),&SamplePlayer::set_polyphony );
|
||||
ClassDB::bind_method(_MD("get_polyphony"),&SamplePlayer::get_polyphony );
|
||||
|
||||
ClassDB::bind_method(_MD("play","name","unique"),&SamplePlayer::play, DEFVAL(false) );
|
||||
ClassDB::bind_method(_MD("stop","voice"),&SamplePlayer::stop );
|
||||
ClassDB::bind_method(_MD("stop_all"),&SamplePlayer::stop_all );
|
||||
|
||||
ClassDB::bind_method(_MD("set_mix_rate","voice","hz"),&SamplePlayer::set_mix_rate );
|
||||
ClassDB::bind_method(_MD("set_pitch_scale","voice","ratio"),&SamplePlayer::set_pitch_scale );
|
||||
ClassDB::bind_method(_MD("set_volume","voice","volume"),&SamplePlayer::set_volume );
|
||||
ClassDB::bind_method(_MD("set_volume_db","voice","db"),&SamplePlayer::set_volume_db );
|
||||
ClassDB::bind_method(_MD("set_pan","voice","pan","depth","height"),&SamplePlayer::set_pan,DEFVAL(0),DEFVAL(0) );
|
||||
ClassDB::bind_method(_MD("set_filter","voice","type","cutoff_hz","resonance","gain"),&SamplePlayer::set_filter,DEFVAL(0) );
|
||||
ClassDB::bind_method(_MD("set_chorus","voice","send"),&SamplePlayer::set_chorus );
|
||||
ClassDB::bind_method(_MD("set_reverb","voice","room_type","send"),&SamplePlayer::set_reverb );
|
||||
|
||||
ClassDB::bind_method(_MD("get_mix_rate","voice"),&SamplePlayer::get_mix_rate );
|
||||
ClassDB::bind_method(_MD("get_pitch_scale","voice"),&SamplePlayer::get_pitch_scale );
|
||||
ClassDB::bind_method(_MD("get_volume","voice"),&SamplePlayer::get_volume );
|
||||
ClassDB::bind_method(_MD("get_volume_db","voice"),&SamplePlayer::get_volume_db );
|
||||
ClassDB::bind_method(_MD("get_pan","voice"),&SamplePlayer::get_pan );
|
||||
ClassDB::bind_method(_MD("get_pan_depth","voice"),&SamplePlayer::get_pan_depth );
|
||||
ClassDB::bind_method(_MD("get_pan_height","voice"),&SamplePlayer::get_pan_height );
|
||||
ClassDB::bind_method(_MD("get_filter_type","voice"),&SamplePlayer::get_filter_type );
|
||||
ClassDB::bind_method(_MD("get_filter_cutoff","voice"),&SamplePlayer::get_filter_cutoff );
|
||||
ClassDB::bind_method(_MD("get_filter_resonance","voice"),&SamplePlayer::get_filter_resonance );
|
||||
ClassDB::bind_method(_MD("get_filter_gain","voice"),&SamplePlayer::get_filter_gain );
|
||||
ClassDB::bind_method(_MD("get_chorus","voice"),&SamplePlayer::get_chorus );
|
||||
ClassDB::bind_method(_MD("get_reverb_room","voice"),&SamplePlayer::get_reverb_room );
|
||||
ClassDB::bind_method(_MD("get_reverb","voice"),&SamplePlayer::get_reverb );
|
||||
|
||||
ClassDB::bind_method(_MD("set_default_pitch_scale","ratio"),&SamplePlayer::set_default_pitch_scale );
|
||||
ClassDB::bind_method(_MD("set_default_volume","volume"),&SamplePlayer::set_default_volume );
|
||||
ClassDB::bind_method(_MD("set_default_volume_db","db"),&SamplePlayer::set_default_volume_db );
|
||||
ClassDB::bind_method(_MD("set_default_pan","pan","depth","height"),&SamplePlayer::set_default_pan,DEFVAL(0),DEFVAL(0) );
|
||||
ClassDB::bind_method(_MD("set_default_filter","type","cutoff_hz","resonance","gain"),&SamplePlayer::set_default_filter,DEFVAL(0) );
|
||||
ClassDB::bind_method(_MD("set_default_chorus","send"),&SamplePlayer::set_default_chorus );
|
||||
ClassDB::bind_method(_MD("set_default_reverb","room_type","send"),&SamplePlayer::set_default_reverb );
|
||||
|
||||
ClassDB::bind_method(_MD("get_default_pitch_scale"),&SamplePlayer::get_default_pitch_scale );
|
||||
ClassDB::bind_method(_MD("get_default_volume"),&SamplePlayer::get_default_volume );
|
||||
ClassDB::bind_method(_MD("get_default_volume_db"),&SamplePlayer::get_default_volume_db );
|
||||
ClassDB::bind_method(_MD("get_default_pan"),&SamplePlayer::get_default_pan );
|
||||
ClassDB::bind_method(_MD("get_default_pan_depth"),&SamplePlayer::get_default_pan_depth );
|
||||
ClassDB::bind_method(_MD("get_default_pan_height"),&SamplePlayer::get_default_pan_height );
|
||||
ClassDB::bind_method(_MD("get_default_filter_type"),&SamplePlayer::get_default_filter_type );
|
||||
ClassDB::bind_method(_MD("get_default_filter_cutoff"),&SamplePlayer::get_default_filter_cutoff );
|
||||
ClassDB::bind_method(_MD("get_default_filter_resonance"),&SamplePlayer::get_default_filter_resonance );
|
||||
ClassDB::bind_method(_MD("get_default_filter_gain"),&SamplePlayer::get_default_filter_gain );
|
||||
ClassDB::bind_method(_MD("get_default_chorus"),&SamplePlayer::get_default_chorus );
|
||||
ClassDB::bind_method(_MD("get_default_reverb_room"),&SamplePlayer::get_default_reverb_room );
|
||||
ClassDB::bind_method(_MD("get_default_reverb"),&SamplePlayer::get_default_reverb );
|
||||
|
||||
ClassDB::bind_method(_MD("is_active"),&SamplePlayer::is_active );
|
||||
ClassDB::bind_method(_MD("is_voice_active","voice"),&SamplePlayer::is_voice_active );
|
||||
|
||||
BIND_CONSTANT( FILTER_NONE);
|
||||
BIND_CONSTANT( FILTER_LOWPASS);
|
||||
BIND_CONSTANT( FILTER_BANDPASS);
|
||||
BIND_CONSTANT( FILTER_HIPASS);
|
||||
BIND_CONSTANT( FILTER_NOTCH);
|
||||
BIND_CONSTANT( FILTER_PEAK);
|
||||
BIND_CONSTANT( FILTER_BANDLIMIT); ///< cutoff is LP resonace is HP
|
||||
BIND_CONSTANT( FILTER_LOW_SHELF);
|
||||
BIND_CONSTANT( FILTER_HIGH_SHELF);
|
||||
|
||||
BIND_CONSTANT( REVERB_SMALL );
|
||||
BIND_CONSTANT( REVERB_MEDIUM );
|
||||
BIND_CONSTANT( REVERB_LARGE );
|
||||
BIND_CONSTANT( REVERB_HALL );
|
||||
|
||||
BIND_CONSTANT( INVALID_VOICE_ID );
|
||||
|
||||
}
|
||||
|
||||
|
||||
SamplePlayer::SamplePlayer() {
|
||||
|
||||
voices.resize(1);
|
||||
|
||||
_default.pitch_scale=1;
|
||||
_default.volume_db=0;
|
||||
_default.pan=0;
|
||||
_default.depth=0;
|
||||
_default.height=0;
|
||||
_default.filter_type=FILTER_NONE;
|
||||
_default.filter_cutoff=5000;
|
||||
_default.filter_resonance=1;
|
||||
_default.filter_gain=1;
|
||||
_default.chorus_send=0;
|
||||
_default.reverb_room=REVERB_LARGE;
|
||||
_default.reverb_send=0;
|
||||
last_id=0;
|
||||
last_check=0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
SamplePlayer::~SamplePlayer() {
|
||||
|
||||
|
||||
}
|
||||
@@ -1,200 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* sample_player.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#ifndef SAMPLE_PLAYER_H
|
||||
#define SAMPLE_PLAYER_H
|
||||
|
||||
#include "scene/main/node.h"
|
||||
#include "scene/resources/sample_library.h"
|
||||
|
||||
class SamplePlayer : public Node {
|
||||
|
||||
GDCLASS( SamplePlayer, Node );
|
||||
OBJ_CATEGORY("Audio Nodes");
|
||||
public:
|
||||
|
||||
|
||||
enum FilterType {
|
||||
FILTER_NONE,
|
||||
FILTER_LOWPASS,
|
||||
FILTER_BANDPASS,
|
||||
FILTER_HIPASS,
|
||||
FILTER_NOTCH,
|
||||
FILTER_PEAK,
|
||||
FILTER_BANDLIMIT, ///< cutoff is LP resonace is HP
|
||||
FILTER_LOW_SHELF,
|
||||
FILTER_HIGH_SHELF,
|
||||
};
|
||||
|
||||
enum ReverbRoomType {
|
||||
|
||||
REVERB_SMALL,
|
||||
REVERB_MEDIUM,
|
||||
REVERB_LARGE,
|
||||
REVERB_HALL
|
||||
};
|
||||
|
||||
enum {
|
||||
|
||||
INVALID_VOICE_ID=0xFFFFFFFF
|
||||
};
|
||||
|
||||
typedef uint32_t VoiceID;
|
||||
|
||||
private:
|
||||
|
||||
Ref<SampleLibrary> library;
|
||||
|
||||
struct Voice {
|
||||
|
||||
RID voice;
|
||||
uint32_t check;
|
||||
bool active;
|
||||
|
||||
int sample_mix_rate;
|
||||
int mix_rate;
|
||||
float volume;
|
||||
float pan;
|
||||
float pan_depth;
|
||||
float pan_height;
|
||||
FilterType filter_type;
|
||||
float filter_cutoff;
|
||||
float filter_resonance;
|
||||
float filter_gain;
|
||||
float chorus_send;
|
||||
ReverbRoomType reverb_room;
|
||||
float reverb_send;
|
||||
|
||||
void clear();
|
||||
Voice();
|
||||
~Voice();
|
||||
};
|
||||
|
||||
Vector<Voice> voices;
|
||||
|
||||
struct Default {
|
||||
|
||||
float reverb_send;
|
||||
float pitch_scale;
|
||||
float volume_db;
|
||||
float pan;
|
||||
float depth;
|
||||
float height;
|
||||
FilterType filter_type;
|
||||
float filter_cutoff;
|
||||
float filter_resonance;
|
||||
float filter_gain;
|
||||
float chorus_send;
|
||||
ReverbRoomType reverb_room;
|
||||
|
||||
} _default;
|
||||
|
||||
uint32_t last_id;
|
||||
uint16_t last_check;
|
||||
String played_back;
|
||||
protected:
|
||||
|
||||
bool _set(const StringName& p_name, const Variant& p_value);
|
||||
bool _get(const StringName& p_name,Variant &r_ret) const;
|
||||
void _get_property_list(List<PropertyInfo> *p_list) const;
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
|
||||
void set_sample_library(const Ref<SampleLibrary>& p_library);
|
||||
Ref<SampleLibrary> get_sample_library() const;
|
||||
|
||||
void set_polyphony(int p_voice_count);
|
||||
int get_polyphony() const;
|
||||
|
||||
VoiceID play(const String& p_name,bool unique=false);
|
||||
void stop(VoiceID p_voice);
|
||||
void stop_all();
|
||||
bool is_voice_active(VoiceID) const;
|
||||
bool is_active() const;
|
||||
|
||||
void set_mix_rate(VoiceID p_voice, int p_mix_rate);
|
||||
void set_pitch_scale(VoiceID p_voice, float p_pitch_scale);
|
||||
void set_volume(VoiceID p_voice, float p_volume);
|
||||
void set_volume_db(VoiceID p_voice, float p_db);
|
||||
void set_pan(VoiceID p_voice, float p_pan,float p_pan_depth=0,float p_pan_height=0);
|
||||
void set_filter(VoiceID p_voice,FilterType p_filter,float p_cutoff,float p_resonance,float p_gain);
|
||||
void set_chorus(VoiceID p_voice,float p_send);
|
||||
void set_reverb(VoiceID p_voice,ReverbRoomType p_room,float p_send);
|
||||
|
||||
int get_mix_rate(VoiceID p_voice) const;
|
||||
float get_pitch_scale(VoiceID p_voice) const;
|
||||
float get_volume(VoiceID p_voice) const;
|
||||
float get_volume_db(VoiceID p_voice) const;
|
||||
|
||||
float get_pan(VoiceID p_voice) const;
|
||||
float get_pan_depth(VoiceID p_voice) const;
|
||||
float get_pan_height(VoiceID p_voice) const;
|
||||
FilterType get_filter_type(VoiceID p_voice) const;
|
||||
float get_filter_cutoff(VoiceID p_voice) const;
|
||||
float get_filter_resonance(VoiceID p_voice) const;
|
||||
float get_filter_gain(VoiceID p_voice) const;
|
||||
float get_chorus(VoiceID p_voice) const;
|
||||
ReverbRoomType get_reverb_room(VoiceID p_voice) const;
|
||||
float get_reverb(VoiceID p_voice) const;
|
||||
|
||||
|
||||
|
||||
void set_default_pitch_scale(float p_pitch_scale);
|
||||
void set_default_volume(float p_volume);
|
||||
void set_default_volume_db(float p_db);
|
||||
void set_default_pan(float p_pan,float p_pan_depth=0,float p_pan_height=0);
|
||||
void set_default_filter(FilterType p_filter,float p_cutoff,float p_resonance,float p_gain);
|
||||
void set_default_chorus(float p_send);
|
||||
void set_default_reverb(ReverbRoomType p_room,float p_send);
|
||||
|
||||
float get_default_volume() const;
|
||||
float get_default_volume_db() const;
|
||||
float get_default_pitch_scale() const;
|
||||
float get_default_pan() const;
|
||||
float get_default_pan_depth() const;
|
||||
float get_default_pan_height() const;
|
||||
FilterType get_default_filter_type() const;
|
||||
float get_default_filter_cutoff() const;
|
||||
float get_default_filter_resonance() const;
|
||||
float get_default_filter_gain() const;
|
||||
float get_default_chorus() const;
|
||||
ReverbRoomType get_default_reverb_room() const;
|
||||
float get_default_reverb() const;
|
||||
|
||||
String get_configuration_warning() const;
|
||||
|
||||
SamplePlayer();
|
||||
~SamplePlayer();
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST( SamplePlayer::FilterType );
|
||||
VARIANT_ENUM_CAST( SamplePlayer::ReverbRoomType );
|
||||
|
||||
#endif // SAMPLE_PLAYER_H
|
||||
@@ -1,180 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* sound_room_params.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include "sound_room_params.h"
|
||||
|
||||
#include "scene/main/viewport.h"
|
||||
|
||||
#ifndef _3D_DISABLED
|
||||
void SoundRoomParams::_update_sound_room() {
|
||||
|
||||
if (!room.is_valid())
|
||||
return;
|
||||
|
||||
for(int i=0;i<PARAM_MAX;i++) {
|
||||
|
||||
SpatialSoundServer::get_singleton()->room_set_param(room,SpatialSoundServer::RoomParam(i),params[i]);
|
||||
|
||||
}
|
||||
|
||||
SpatialSoundServer::get_singleton()->room_set_reverb(room,SpatialSoundServer::RoomReverb(reverb));
|
||||
SpatialSoundServer::get_singleton()->room_set_force_params_to_all_sources(room,force_params_for_all_sources);
|
||||
}
|
||||
|
||||
|
||||
void SoundRoomParams::_notification(int p_what) {
|
||||
|
||||
|
||||
switch(p_what) {
|
||||
|
||||
|
||||
case NOTIFICATION_ENTER_TREE: {
|
||||
//#if 0
|
||||
Node *n=this;
|
||||
Room *room_instance=NULL;
|
||||
while(n) {
|
||||
|
||||
room_instance=n->cast_to<Room>();
|
||||
if (room_instance) {
|
||||
|
||||
break;
|
||||
}
|
||||
if (n->cast_to<Viewport>())
|
||||
break;
|
||||
|
||||
n=n->get_parent();
|
||||
}
|
||||
|
||||
|
||||
if (room_instance) {
|
||||
room=room_instance->get_sound_room();
|
||||
} else {
|
||||
room=get_viewport()->find_world()->get_sound_space();
|
||||
}
|
||||
|
||||
_update_sound_room();
|
||||
//#endif
|
||||
|
||||
} break;
|
||||
case NOTIFICATION_EXIT_TREE: {
|
||||
|
||||
room=RID();
|
||||
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SoundRoomParams::set_param(Params p_param, float p_value) {
|
||||
|
||||
ERR_FAIL_INDEX(p_param,PARAM_MAX);
|
||||
params[p_param]=p_value;
|
||||
if (room.is_valid())
|
||||
SpatialSoundServer::get_singleton()->room_set_param(room,SpatialSoundServer::RoomParam(p_param),p_value);
|
||||
}
|
||||
|
||||
float SoundRoomParams::get_param(Params p_param) const {
|
||||
|
||||
ERR_FAIL_INDEX_V(p_param,PARAM_MAX,0);
|
||||
return params[p_param];
|
||||
}
|
||||
|
||||
|
||||
void SoundRoomParams::set_reverb_mode(Reverb p_mode) {
|
||||
|
||||
ERR_FAIL_INDEX(p_mode,4);
|
||||
reverb=p_mode;
|
||||
if (room.is_valid())
|
||||
SpatialSoundServer::get_singleton()->room_set_reverb(room,SpatialSoundServer::RoomReverb(p_mode));
|
||||
}
|
||||
|
||||
SoundRoomParams::Reverb SoundRoomParams::get_reverb_mode() const {
|
||||
|
||||
return reverb;
|
||||
}
|
||||
|
||||
|
||||
void SoundRoomParams::set_force_params_to_all_sources(bool p_force) {
|
||||
|
||||
force_params_for_all_sources=p_force;
|
||||
if (room.is_valid())
|
||||
SpatialSoundServer::get_singleton()->room_set_force_params_to_all_sources(room,p_force);
|
||||
}
|
||||
|
||||
bool SoundRoomParams::is_forcing_params_to_all_sources() {
|
||||
|
||||
return force_params_for_all_sources;
|
||||
}
|
||||
|
||||
|
||||
void SoundRoomParams::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(_MD("set_param","param","value"),&SoundRoomParams::set_param );
|
||||
ClassDB::bind_method(_MD("get_param","param"),&SoundRoomParams::get_param );
|
||||
|
||||
ClassDB::bind_method(_MD("set_reverb_mode","reverb_mode","value"),&SoundRoomParams::set_reverb_mode );
|
||||
ClassDB::bind_method(_MD("get_reverb_mode","reverb_mode"),&SoundRoomParams::get_reverb_mode );
|
||||
|
||||
ClassDB::bind_method(_MD("set_force_params_to_all_sources","enabled"),&SoundRoomParams::set_force_params_to_all_sources );
|
||||
ClassDB::bind_method(_MD("is_forcing_params_to_all_sources"),&SoundRoomParams::is_forcing_params_to_all_sources );
|
||||
|
||||
|
||||
ADD_PROPERTY( PropertyInfo( Variant::INT, "reverb/mode", PROPERTY_HINT_ENUM, "Small,Medium,Large,Hall"), _SCS("set_reverb_mode"), _SCS("get_reverb_mode") );
|
||||
ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/speed_of_scale", PROPERTY_HINT_RANGE, "0.01,16,0.01"), _SCS("set_param"), _SCS("get_param"), PARAM_SPEED_OF_SOUND_SCALE);
|
||||
ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/doppler_factor",PROPERTY_HINT_RANGE, "0.01,16,0.01"), _SCS("set_param"), _SCS("get_param"), PARAM_DOPPLER_FACTOR );
|
||||
ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/pitch_scale",PROPERTY_HINT_RANGE, "0.01,32,0.01"), _SCS("set_param"), _SCS("get_param"), PARAM_PITCH_SCALE );
|
||||
ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/volume_scale_db",PROPERTY_HINT_RANGE, "-80,24,0.01"), _SCS("set_param"), _SCS("get_param"), PARAM_VOLUME_SCALE_DB );
|
||||
ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/reverb_send",PROPERTY_HINT_RANGE, "0,1,0.01"), _SCS("set_param"), _SCS("get_param"), PARAM_REVERB_SEND );
|
||||
ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/chorus_send",PROPERTY_HINT_RANGE, "0,1,0.01"), _SCS("set_param"), _SCS("get_param"), PARAM_CHORUS_SEND );
|
||||
ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/attenuation_scale",PROPERTY_HINT_RANGE, "0.01,32,0.01"), _SCS("set_param"), _SCS("get_param"), PARAM_ATTENUATION_SCALE );
|
||||
ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/attenuation_hf_cutoff",PROPERTY_HINT_RANGE, "30,16384,1"), _SCS("set_param"), _SCS("get_param"), PARAM_ATTENUATION_HF_CUTOFF );
|
||||
ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/attenuation_hf_floor_db",PROPERTY_HINT_RANGE, "-80,24,0.01"), _SCS("set_param"), _SCS("get_param"), PARAM_ATTENUATION_HF_FLOOR_DB );
|
||||
ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/attenuation_hf_ratio_exp",PROPERTY_HINT_RANGE, "0.01,32,0.01"), _SCS("set_param"), _SCS("get_param"), PARAM_ATTENUATION_HF_RATIO_EXP );
|
||||
ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/attenuation_reverb_scale",PROPERTY_HINT_RANGE, "0.01,32,0.01"), _SCS("set_param"), _SCS("get_param"), PARAM_ATTENUATION_REVERB_SCALE );
|
||||
ADD_PROPERTY( PropertyInfo( Variant::BOOL, "force_to_all_sources"),_SCS("set_force_params_to_all_sources"),_SCS("is_forcing_params_to_all_sources") );
|
||||
|
||||
}
|
||||
|
||||
|
||||
SoundRoomParams::SoundRoomParams() {
|
||||
|
||||
reverb=REVERB_HALL;
|
||||
params[PARAM_SPEED_OF_SOUND_SCALE]=1;
|
||||
params[PARAM_DOPPLER_FACTOR]=1.0;
|
||||
params[PARAM_PITCH_SCALE]=1.0;
|
||||
params[PARAM_VOLUME_SCALE_DB]=0;
|
||||
params[PARAM_REVERB_SEND]=0;
|
||||
params[PARAM_CHORUS_SEND]=0;
|
||||
params[PARAM_ATTENUATION_SCALE]=1.0;
|
||||
params[PARAM_ATTENUATION_HF_CUTOFF]=5000;
|
||||
params[PARAM_ATTENUATION_HF_FLOOR_DB]=-24.0;
|
||||
params[PARAM_ATTENUATION_HF_RATIO_EXP]=1.0;
|
||||
params[PARAM_ATTENUATION_REVERB_SCALE]=0.0;
|
||||
force_params_for_all_sources=false;
|
||||
}
|
||||
#endif
|
||||
@@ -1,100 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* sound_room_params.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#ifndef SOUND_ROOM_PARAMS_H
|
||||
#define SOUND_ROOM_PARAMS_H
|
||||
|
||||
#include "scene/main/node.h"
|
||||
#include "servers/spatial_sound_server.h"
|
||||
|
||||
|
||||
#ifndef _3D_DISABLED
|
||||
|
||||
#include "scene/3d/room_instance.h"
|
||||
class SoundRoomParams : public Node {
|
||||
|
||||
GDCLASS( SoundRoomParams, Node );
|
||||
public:
|
||||
|
||||
enum Params {
|
||||
PARAM_SPEED_OF_SOUND_SCALE=SpatialSoundServer::ROOM_PARAM_SPEED_OF_SOUND_SCALE,
|
||||
PARAM_DOPPLER_FACTOR=SpatialSoundServer::ROOM_PARAM_DOPPLER_FACTOR,
|
||||
PARAM_PITCH_SCALE=SpatialSoundServer::ROOM_PARAM_PITCH_SCALE,
|
||||
PARAM_VOLUME_SCALE_DB=SpatialSoundServer::ROOM_PARAM_VOLUME_SCALE_DB,
|
||||
PARAM_REVERB_SEND=SpatialSoundServer::ROOM_PARAM_REVERB_SEND,
|
||||
PARAM_CHORUS_SEND=SpatialSoundServer::ROOM_PARAM_CHORUS_SEND,
|
||||
PARAM_ATTENUATION_SCALE=SpatialSoundServer::ROOM_PARAM_ATTENUATION_SCALE,
|
||||
PARAM_ATTENUATION_HF_CUTOFF=SpatialSoundServer::ROOM_PARAM_ATTENUATION_HF_CUTOFF,
|
||||
PARAM_ATTENUATION_HF_FLOOR_DB=SpatialSoundServer::ROOM_PARAM_ATTENUATION_HF_FLOOR_DB,
|
||||
PARAM_ATTENUATION_HF_RATIO_EXP=SpatialSoundServer::ROOM_PARAM_ATTENUATION_HF_RATIO_EXP,
|
||||
PARAM_ATTENUATION_REVERB_SCALE=SpatialSoundServer::ROOM_PARAM_ATTENUATION_REVERB_SCALE,
|
||||
PARAM_MAX=SpatialSoundServer::ROOM_PARAM_MAX
|
||||
};
|
||||
|
||||
enum Reverb {
|
||||
REVERB_SMALL,
|
||||
REVERB_MEDIUM,
|
||||
REVERB_LARGE,
|
||||
REVERB_HALL
|
||||
};
|
||||
private:
|
||||
|
||||
RID room;
|
||||
|
||||
float params[PARAM_MAX];
|
||||
Reverb reverb;
|
||||
bool force_params_for_all_sources;
|
||||
void _update_sound_room();
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
|
||||
|
||||
void set_param(Params p_param, float p_value);
|
||||
float get_param(Params p_param) const;
|
||||
|
||||
void set_reverb_mode(Reverb p_mode);
|
||||
Reverb get_reverb_mode() const;
|
||||
|
||||
void set_force_params_to_all_sources(bool p_force);
|
||||
bool is_forcing_params_to_all_sources();
|
||||
|
||||
SoundRoomParams();
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST(SoundRoomParams::Params);
|
||||
VARIANT_ENUM_CAST(SoundRoomParams::Reverb);
|
||||
|
||||
#endif
|
||||
|
||||
#endif // SOUND_ROOM_PARAMS_H
|
||||
@@ -1,428 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* stream_player.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include "stream_player.h"
|
||||
|
||||
int StreamPlayer::InternalStream::get_channel_count() const {
|
||||
|
||||
return player->sp_get_channel_count();
|
||||
}
|
||||
void StreamPlayer::InternalStream::set_mix_rate(int p_rate){
|
||||
|
||||
return player->sp_set_mix_rate(p_rate);
|
||||
}
|
||||
bool StreamPlayer::InternalStream::mix(int32_t *p_buffer,int p_frames){
|
||||
|
||||
return player->sp_mix(p_buffer,p_frames);
|
||||
}
|
||||
void StreamPlayer::InternalStream::update(){
|
||||
|
||||
player->sp_update();
|
||||
}
|
||||
|
||||
|
||||
int StreamPlayer::sp_get_channel_count() const {
|
||||
|
||||
return playback->get_channels();
|
||||
}
|
||||
|
||||
void StreamPlayer::sp_set_mix_rate(int p_rate){
|
||||
|
||||
server_mix_rate=p_rate;
|
||||
}
|
||||
|
||||
bool StreamPlayer::sp_mix(int32_t *p_buffer,int p_frames) {
|
||||
|
||||
if (resampler.is_ready() && !paused) {
|
||||
return resampler.mix(p_buffer,p_frames);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void StreamPlayer::sp_update() {
|
||||
|
||||
//_THREAD_SAFE_METHOD_
|
||||
if (!paused && resampler.is_ready() && playback.is_valid()) {
|
||||
|
||||
if (!playback->is_playing()) {
|
||||
//stream depleted data, but there's still audio in the ringbuffer
|
||||
//check that all this audio has been flushed before stopping the stream
|
||||
int to_mix = resampler.get_total() - resampler.get_todo();
|
||||
if (to_mix==0) {
|
||||
if (!stop_request) {
|
||||
stop_request=true;
|
||||
call_deferred("_do_stop");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int todo =resampler.get_todo();
|
||||
int wrote = playback->mix(resampler.get_write_buffer(),todo);
|
||||
resampler.write(wrote);
|
||||
}
|
||||
}
|
||||
|
||||
void StreamPlayer::_do_stop() {
|
||||
stop();
|
||||
emit_signal("finished");
|
||||
}
|
||||
|
||||
void StreamPlayer::_notification(int p_what) {
|
||||
|
||||
switch(p_what) {
|
||||
|
||||
case NOTIFICATION_ENTER_TREE: {
|
||||
|
||||
//set_idle_process(false); //don't annoy
|
||||
if (stream.is_valid() && !get_tree()->is_editor_hint()) {
|
||||
if (resume_pos>=0) {
|
||||
play(resume_pos);
|
||||
resume_pos=-1;
|
||||
} else if (autoplay) {
|
||||
play();
|
||||
autoplay = false; //this line fix autoplay issues
|
||||
}
|
||||
}
|
||||
|
||||
} break;
|
||||
case NOTIFICATION_EXIT_TREE: {
|
||||
|
||||
if (is_playing()) {
|
||||
resume_pos=get_pos();
|
||||
}
|
||||
stop(); //wathever it may be doing, stop
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void StreamPlayer::set_stream(const Ref<AudioStream> &p_stream) {
|
||||
|
||||
stop();
|
||||
|
||||
stream=p_stream;
|
||||
|
||||
if (!stream.is_null()) {
|
||||
playback=stream->instance_playback();
|
||||
playback->set_loop(loops);
|
||||
playback->set_loop_restart_time(loop_point);
|
||||
AudioServer::get_singleton()->lock();
|
||||
resampler.setup(playback->get_channels(),playback->get_mix_rate(),server_mix_rate,buffering_ms,playback->get_minimum_buffer_size());
|
||||
AudioServer::get_singleton()->unlock();
|
||||
} else {
|
||||
AudioServer::get_singleton()->lock();
|
||||
resampler.clear();
|
||||
playback.unref();
|
||||
AudioServer::get_singleton()->unlock();
|
||||
}
|
||||
}
|
||||
|
||||
Ref<AudioStream> StreamPlayer::get_stream() const {
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
void StreamPlayer::play(float p_from_offset) {
|
||||
|
||||
ERR_FAIL_COND(!is_inside_tree());
|
||||
if (playback.is_null())
|
||||
return;
|
||||
//if (is_playing())
|
||||
stop();
|
||||
|
||||
//_THREAD_SAFE_METHOD_
|
||||
playback->play(p_from_offset);
|
||||
//feed the ringbuffer as long as no update callback is going on
|
||||
sp_update();
|
||||
AudioServer::get_singleton()->stream_set_active(stream_rid,true);
|
||||
AudioServer::get_singleton()->stream_set_volume_scale(stream_rid,volume);
|
||||
/*
|
||||
if (stream->get_update_mode()!=AudioStream::UPDATE_NONE)
|
||||
set_idle_process(true);
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
void StreamPlayer::stop() {
|
||||
|
||||
if (!is_inside_tree())
|
||||
return;
|
||||
if (playback.is_null())
|
||||
return;
|
||||
|
||||
//_THREAD_SAFE_METHOD_
|
||||
AudioServer::get_singleton()->stream_set_active(stream_rid,false);
|
||||
stop_request=false;
|
||||
playback->stop();
|
||||
resampler.flush();
|
||||
|
||||
|
||||
//set_idle_process(false);
|
||||
}
|
||||
|
||||
bool StreamPlayer::is_playing() const {
|
||||
|
||||
if (playback.is_null())
|
||||
return false;
|
||||
|
||||
return playback->is_playing() || resampler.has_data();
|
||||
}
|
||||
|
||||
void StreamPlayer::set_loop(bool p_enable) {
|
||||
|
||||
loops=p_enable;
|
||||
if (playback.is_null())
|
||||
return;
|
||||
playback->set_loop(loops);
|
||||
|
||||
}
|
||||
bool StreamPlayer::has_loop() const {
|
||||
|
||||
return loops;
|
||||
}
|
||||
|
||||
void StreamPlayer::set_volume(float p_vol) {
|
||||
|
||||
volume=p_vol;
|
||||
if (stream_rid.is_valid())
|
||||
AudioServer::get_singleton()->stream_set_volume_scale(stream_rid,volume);
|
||||
}
|
||||
|
||||
float StreamPlayer::get_volume() const {
|
||||
|
||||
return volume;
|
||||
}
|
||||
|
||||
void StreamPlayer::set_loop_restart_time(float p_secs) {
|
||||
|
||||
loop_point=p_secs;
|
||||
if (playback.is_valid())
|
||||
playback->set_loop_restart_time(p_secs);
|
||||
}
|
||||
|
||||
float StreamPlayer::get_loop_restart_time() const {
|
||||
|
||||
return loop_point;
|
||||
}
|
||||
|
||||
|
||||
void StreamPlayer::set_volume_db(float p_db) {
|
||||
|
||||
if (p_db<-79)
|
||||
set_volume(0);
|
||||
else
|
||||
set_volume(Math::db2linear(p_db));
|
||||
}
|
||||
|
||||
float StreamPlayer::get_volume_db() const {
|
||||
|
||||
if (volume==0)
|
||||
return -80;
|
||||
else
|
||||
return Math::linear2db(volume);
|
||||
}
|
||||
|
||||
|
||||
String StreamPlayer::get_stream_name() const {
|
||||
|
||||
if (stream.is_null())
|
||||
return "<No Stream>";
|
||||
return stream->get_name();
|
||||
|
||||
}
|
||||
|
||||
int StreamPlayer::get_loop_count() const {
|
||||
|
||||
if (playback.is_null())
|
||||
return 0;
|
||||
return playback->get_loop_count();
|
||||
|
||||
}
|
||||
|
||||
float StreamPlayer::get_pos() const {
|
||||
|
||||
if (playback.is_null())
|
||||
return 0;
|
||||
return playback->get_pos();
|
||||
|
||||
}
|
||||
|
||||
float StreamPlayer::get_length() const {
|
||||
|
||||
if (playback.is_null())
|
||||
return 0;
|
||||
return playback->get_length();
|
||||
}
|
||||
void StreamPlayer::seek_pos(float p_time) {
|
||||
|
||||
if (playback.is_null())
|
||||
return;
|
||||
//works better...
|
||||
stop();
|
||||
playback->play(p_time);
|
||||
|
||||
}
|
||||
|
||||
void StreamPlayer::set_autoplay(bool p_enable) {
|
||||
|
||||
autoplay=p_enable;
|
||||
}
|
||||
|
||||
bool StreamPlayer::has_autoplay() const {
|
||||
|
||||
return autoplay;
|
||||
}
|
||||
|
||||
void StreamPlayer::set_paused(bool p_paused) {
|
||||
|
||||
paused=p_paused;
|
||||
/*
|
||||
if (stream.is_valid())
|
||||
stream->set_paused(p_paused);
|
||||
*/
|
||||
}
|
||||
|
||||
bool StreamPlayer::is_paused() const {
|
||||
|
||||
return paused;
|
||||
}
|
||||
|
||||
void StreamPlayer::_set_play(bool p_play) {
|
||||
|
||||
_play=p_play;
|
||||
if (is_inside_tree()) {
|
||||
if(_play)
|
||||
play();
|
||||
else
|
||||
stop();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool StreamPlayer::_get_play() const{
|
||||
|
||||
return _play;
|
||||
}
|
||||
|
||||
void StreamPlayer::set_buffering_msec(int p_msec) {
|
||||
|
||||
buffering_ms=p_msec;
|
||||
}
|
||||
|
||||
int StreamPlayer::get_buffering_msec() const{
|
||||
|
||||
return buffering_ms;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void StreamPlayer::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(_MD("set_stream","stream:AudioStream"),&StreamPlayer::set_stream);
|
||||
ClassDB::bind_method(_MD("get_stream:AudioStream"),&StreamPlayer::get_stream);
|
||||
|
||||
ClassDB::bind_method(_MD("play","offset"),&StreamPlayer::play,DEFVAL(0));
|
||||
ClassDB::bind_method(_MD("stop"),&StreamPlayer::stop);
|
||||
|
||||
ClassDB::bind_method(_MD("is_playing"),&StreamPlayer::is_playing);
|
||||
|
||||
ClassDB::bind_method(_MD("set_paused","paused"),&StreamPlayer::set_paused);
|
||||
ClassDB::bind_method(_MD("is_paused"),&StreamPlayer::is_paused);
|
||||
|
||||
ClassDB::bind_method(_MD("set_loop","enabled"),&StreamPlayer::set_loop);
|
||||
ClassDB::bind_method(_MD("has_loop"),&StreamPlayer::has_loop);
|
||||
|
||||
ClassDB::bind_method(_MD("set_volume","volume"),&StreamPlayer::set_volume);
|
||||
ClassDB::bind_method(_MD("get_volume"),&StreamPlayer::get_volume);
|
||||
|
||||
ClassDB::bind_method(_MD("set_volume_db","db"),&StreamPlayer::set_volume_db);
|
||||
ClassDB::bind_method(_MD("get_volume_db"),&StreamPlayer::get_volume_db);
|
||||
|
||||
ClassDB::bind_method(_MD("set_buffering_msec","msec"),&StreamPlayer::set_buffering_msec);
|
||||
ClassDB::bind_method(_MD("get_buffering_msec"),&StreamPlayer::get_buffering_msec);
|
||||
|
||||
ClassDB::bind_method(_MD("set_loop_restart_time","secs"),&StreamPlayer::set_loop_restart_time);
|
||||
ClassDB::bind_method(_MD("get_loop_restart_time"),&StreamPlayer::get_loop_restart_time);
|
||||
|
||||
ClassDB::bind_method(_MD("get_stream_name"),&StreamPlayer::get_stream_name);
|
||||
ClassDB::bind_method(_MD("get_loop_count"),&StreamPlayer::get_loop_count);
|
||||
|
||||
ClassDB::bind_method(_MD("get_pos"),&StreamPlayer::get_pos);
|
||||
ClassDB::bind_method(_MD("seek_pos","time"),&StreamPlayer::seek_pos);
|
||||
|
||||
ClassDB::bind_method(_MD("set_autoplay","enabled"),&StreamPlayer::set_autoplay);
|
||||
ClassDB::bind_method(_MD("has_autoplay"),&StreamPlayer::has_autoplay);
|
||||
|
||||
ClassDB::bind_method(_MD("get_length"),&StreamPlayer::get_length);
|
||||
|
||||
ClassDB::bind_method(_MD("_set_play","play"),&StreamPlayer::_set_play);
|
||||
ClassDB::bind_method(_MD("_get_play"),&StreamPlayer::_get_play);
|
||||
ClassDB::bind_method(_MD("_do_stop"),&StreamPlayer::_do_stop);
|
||||
|
||||
ADD_PROPERTY( PropertyInfo(Variant::OBJECT, "stream", PROPERTY_HINT_RESOURCE_TYPE,"AudioStream"), _SCS("set_stream"), _SCS("get_stream") );
|
||||
ADD_PROPERTY( PropertyInfo(Variant::BOOL, "play"), _SCS("_set_play"), _SCS("_get_play") );
|
||||
ADD_PROPERTY( PropertyInfo(Variant::BOOL, "loop"), _SCS("set_loop"), _SCS("has_loop") );
|
||||
ADD_PROPERTY( PropertyInfo(Variant::REAL, "volume_db", PROPERTY_HINT_RANGE,"-80,24,0.01"), _SCS("set_volume_db"), _SCS("get_volume_db") );
|
||||
ADD_PROPERTY( PropertyInfo(Variant::BOOL, "autoplay"), _SCS("set_autoplay"), _SCS("has_autoplay") );
|
||||
ADD_PROPERTY( PropertyInfo(Variant::BOOL, "paused"), _SCS("set_paused"), _SCS("is_paused") );
|
||||
ADD_PROPERTY( PropertyInfo(Variant::REAL, "loop_restart_time"), _SCS("set_loop_restart_time"), _SCS("get_loop_restart_time") );
|
||||
ADD_PROPERTY( PropertyInfo(Variant::INT, "buffering_ms"), _SCS("set_buffering_msec"), _SCS("get_buffering_msec") );
|
||||
|
||||
ADD_SIGNAL(MethodInfo("finished"));
|
||||
}
|
||||
|
||||
|
||||
StreamPlayer::StreamPlayer() {
|
||||
|
||||
volume=1;
|
||||
loops=false;
|
||||
paused=false;
|
||||
autoplay=false;
|
||||
_play=false;
|
||||
server_mix_rate=1;
|
||||
internal_stream.player=this;
|
||||
stream_rid=AudioServer::get_singleton()->audio_stream_create(&internal_stream);
|
||||
buffering_ms=500;
|
||||
loop_point=0;
|
||||
stop_request=false;
|
||||
resume_pos=-1;
|
||||
|
||||
}
|
||||
|
||||
StreamPlayer::~StreamPlayer() {
|
||||
AudioServer::get_singleton()->free(stream_rid);
|
||||
resampler.clear();
|
||||
|
||||
|
||||
}
|
||||
@@ -1,124 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* stream_player.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#ifndef STREAM_PLAYER_H
|
||||
#define STREAM_PLAYER_H
|
||||
|
||||
#include "scene/resources/audio_stream.h"
|
||||
#include "scene/main/node.h"
|
||||
#include "servers/audio/audio_rb_resampler.h"
|
||||
|
||||
class StreamPlayer : public Node {
|
||||
|
||||
GDCLASS(StreamPlayer,Node);
|
||||
|
||||
//_THREAD_SAFE_CLASS_
|
||||
|
||||
struct InternalStream : public AudioServer::AudioStream {
|
||||
StreamPlayer *player;
|
||||
virtual int get_channel_count() const;
|
||||
virtual void set_mix_rate(int p_rate); //notify the stream of the mix rate
|
||||
virtual bool mix(int32_t *p_buffer,int p_frames);
|
||||
virtual void update();
|
||||
};
|
||||
|
||||
|
||||
InternalStream internal_stream;
|
||||
Ref<AudioStreamPlayback> playback;
|
||||
Ref<AudioStream> stream;
|
||||
|
||||
int sp_get_channel_count() const;
|
||||
void sp_set_mix_rate(int p_rate); //notify the stream of the mix rate
|
||||
bool sp_mix(int32_t *p_buffer,int p_frames);
|
||||
void sp_update();
|
||||
|
||||
int server_mix_rate;
|
||||
|
||||
RID stream_rid;
|
||||
bool paused;
|
||||
bool autoplay;
|
||||
bool loops;
|
||||
float volume;
|
||||
float loop_point;
|
||||
int buffering_ms;
|
||||
volatile bool stop_request;
|
||||
float resume_pos;
|
||||
|
||||
AudioRBResampler resampler;
|
||||
|
||||
void _do_stop();
|
||||
|
||||
bool _play;
|
||||
void _set_play(bool p_play);
|
||||
bool _get_play() const;
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
|
||||
static void _bind_methods();
|
||||
public:
|
||||
|
||||
void set_stream(const Ref<AudioStream> &p_stream);
|
||||
Ref<AudioStream> get_stream() const;
|
||||
|
||||
void play(float p_from_offset=0);
|
||||
void stop();
|
||||
bool is_playing() const;
|
||||
|
||||
void set_paused(bool p_paused);
|
||||
bool is_paused() const;
|
||||
|
||||
void set_loop(bool p_enable);
|
||||
bool has_loop() const;
|
||||
|
||||
void set_volume(float p_vol);
|
||||
float get_volume() const;
|
||||
|
||||
void set_loop_restart_time(float p_secs);
|
||||
float get_loop_restart_time() const;
|
||||
|
||||
void set_volume_db(float p_db);
|
||||
float get_volume_db() const;
|
||||
|
||||
String get_stream_name() const;
|
||||
|
||||
int get_loop_count() const;
|
||||
|
||||
float get_pos() const;
|
||||
void seek_pos(float p_time);
|
||||
float get_length() const;
|
||||
void set_autoplay(bool p_vol);
|
||||
bool has_autoplay() const;
|
||||
|
||||
void set_buffering_msec(int p_msec);
|
||||
int get_buffering_msec() const;
|
||||
|
||||
StreamPlayer();
|
||||
~StreamPlayer();
|
||||
};
|
||||
|
||||
#endif // AUDIO_STREAM_PLAYER_H
|
||||
@@ -28,7 +28,7 @@
|
||||
/*************************************************************************/
|
||||
#include "video_player.h"
|
||||
#include "os/os.h"
|
||||
|
||||
/*
|
||||
|
||||
int VideoPlayer::InternalStream::get_channel_count() const {
|
||||
|
||||
@@ -46,7 +46,7 @@ void VideoPlayer::InternalStream::update(){
|
||||
|
||||
player->sp_update();
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
int VideoPlayer::sp_get_channel_count() const {
|
||||
|
||||
@@ -234,8 +234,8 @@ void VideoPlayer::play() {
|
||||
playback->stop();
|
||||
playback->play();
|
||||
set_process_internal(true);
|
||||
AudioServer::get_singleton()->stream_set_active(stream_rid,true);
|
||||
AudioServer::get_singleton()->stream_set_volume_scale(stream_rid,volume);
|
||||
// AudioServer::get_singleton()->stream_set_active(stream_rid,true);
|
||||
// AudioServer::get_singleton()->stream_set_volume_scale(stream_rid,volume);
|
||||
last_audio_time=0;
|
||||
};
|
||||
|
||||
@@ -247,7 +247,7 @@ void VideoPlayer::stop() {
|
||||
return;
|
||||
|
||||
playback->stop();
|
||||
AudioServer::get_singleton()->stream_set_active(stream_rid,false);
|
||||
// AudioServer::get_singleton()->stream_set_active(stream_rid,false);
|
||||
resampler.flush();
|
||||
set_process_internal(false);
|
||||
last_audio_time=0;
|
||||
@@ -416,16 +416,16 @@ VideoPlayer::VideoPlayer() {
|
||||
buffering_ms=500;
|
||||
server_mix_rate=44100;
|
||||
|
||||
internal_stream.player=this;
|
||||
stream_rid=AudioServer::get_singleton()->audio_stream_create(&internal_stream);
|
||||
// internal_stream.player=this;
|
||||
// stream_rid=AudioServer::get_singleton()->audio_stream_create(&internal_stream);
|
||||
last_audio_time=0;
|
||||
|
||||
};
|
||||
|
||||
VideoPlayer::~VideoPlayer() {
|
||||
|
||||
if (stream_rid.is_valid())
|
||||
AudioServer::get_singleton()->free(stream_rid);
|
||||
// if (stream_rid.is_valid())
|
||||
// AudioServer::get_singleton()->free(stream_rid);
|
||||
resampler.clear(); //Not necessary here, but make in consistent with other "stream_player" classes
|
||||
};
|
||||
|
||||
|
||||
@@ -37,16 +37,16 @@ class VideoPlayer : public Control {
|
||||
|
||||
GDCLASS(VideoPlayer,Control);
|
||||
|
||||
struct InternalStream : public AudioServer::AudioStream {
|
||||
/* struct InternalStream : public AudioServer::AudioStream {
|
||||
VideoPlayer *player;
|
||||
virtual int get_channel_count() const;
|
||||
virtual void set_mix_rate(int p_rate); //notify the stream of the mix rate
|
||||
virtual bool mix(int32_t *p_buffer,int p_frames);
|
||||
virtual void update();
|
||||
};
|
||||
*/
|
||||
|
||||
|
||||
InternalStream internal_stream;
|
||||
// InternalStream internal_stream;
|
||||
Ref<VideoStreamPlayback> playback;
|
||||
Ref<VideoStream> stream;
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#if 0
|
||||
#include "resource_format_wav.h"
|
||||
#include "os/file_access.h"
|
||||
#include "scene/resources/sample.h"
|
||||
@@ -272,3 +273,4 @@ String ResourceFormatLoaderWAV::get_resource_type(const String &p_path) const {
|
||||
return "";
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#ifndef RESOURCE_FORMAT_WAV_H
|
||||
#define RESOURCE_FORMAT_WAV_H
|
||||
|
||||
#if 0
|
||||
#include "io/resource_loader.h"
|
||||
|
||||
class ResourceFormatLoaderWAV : public ResourceFormatLoader {
|
||||
@@ -40,4 +41,5 @@ public:
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // RESOURCE_FORMAT_WAV_H
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
#include "globals.h"
|
||||
#include <stdio.h>
|
||||
#include "os/keyboard.h"
|
||||
#include "servers/spatial_sound_2d_server.h"
|
||||
//#include "servers/spatial_sound_2d_server.h"
|
||||
#include "servers/physics_2d_server.h"
|
||||
#include "servers/physics_server.h"
|
||||
#include "scene/scene_string_names.h"
|
||||
|
||||
+18
-18
@@ -33,8 +33,7 @@
|
||||
#include "servers/physics_2d_server.h"
|
||||
//#include "scene/3d/camera.h"
|
||||
|
||||
#include "servers/spatial_sound_server.h"
|
||||
#include "servers/spatial_sound_2d_server.h"
|
||||
|
||||
#include "scene/gui/control.h"
|
||||
#include "scene/3d/camera.h"
|
||||
#include "scene/3d/listener.h"
|
||||
@@ -468,7 +467,7 @@ void Viewport::_notification(int p_what) {
|
||||
*/
|
||||
|
||||
VisualServer::get_singleton()->viewport_set_scenario(viewport,RID());
|
||||
SpatialSoundServer::get_singleton()->listener_set_space(internal_listener, RID());
|
||||
// SpatialSoundServer::get_singleton()->listener_set_space(internal_listener, RID());
|
||||
VisualServer::get_singleton()->viewport_remove_canvas(viewport,current_canvas);
|
||||
if (contact_2d_debug.is_valid()) {
|
||||
VisualServer::get_singleton()->free(contact_2d_debug);
|
||||
@@ -783,23 +782,24 @@ Size2 Viewport::get_size() const {
|
||||
|
||||
|
||||
void Viewport::_update_listener() {
|
||||
|
||||
/*
|
||||
if (is_inside_tree() && audio_listener && (camera || listener) && (!get_parent() || (get_parent()->cast_to<Control>() && get_parent()->cast_to<Control>()->is_visible_in_tree()))) {
|
||||
SpatialSoundServer::get_singleton()->listener_set_space(internal_listener, find_world()->get_sound_space());
|
||||
} else {
|
||||
SpatialSoundServer::get_singleton()->listener_set_space(internal_listener, RID());
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
void Viewport::_update_listener_2d() {
|
||||
|
||||
/*
|
||||
if (is_inside_tree() && audio_listener && (!get_parent() || (get_parent()->cast_to<Control>() && get_parent()->cast_to<Control>()->is_visible_in_tree())))
|
||||
SpatialSound2DServer::get_singleton()->listener_set_space(internal_listener_2d, find_world_2d()->get_sound_space());
|
||||
else
|
||||
SpatialSound2DServer::get_singleton()->listener_set_space(internal_listener_2d, RID());
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
@@ -842,12 +842,12 @@ void Viewport::set_canvas_transform(const Transform2D& p_transform) {
|
||||
|
||||
Transform2D xform = (global_canvas_transform * canvas_transform).affine_inverse();
|
||||
Size2 ss = get_visible_rect().size;
|
||||
SpatialSound2DServer::get_singleton()->listener_set_transform(internal_listener_2d, Transform2D(0, xform.xform(ss*0.5)));
|
||||
/*SpatialSound2DServer::get_singleton()->listener_set_transform(internal_listener_2d, Transform2D(0, xform.xform(ss*0.5)));
|
||||
Vector2 ss2 = ss*xform.get_scale();
|
||||
float panrange = MAX(ss2.x,ss2.y);
|
||||
|
||||
SpatialSound2DServer::get_singleton()->listener_set_param(internal_listener_2d, SpatialSound2DServer::LISTENER_PARAM_PAN_RANGE, panrange);
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
@@ -867,12 +867,12 @@ void Viewport::_update_global_transform() {
|
||||
|
||||
Transform2D xform = (sxform * canvas_transform).affine_inverse();
|
||||
Size2 ss = get_visible_rect().size;
|
||||
SpatialSound2DServer::get_singleton()->listener_set_transform(internal_listener_2d, Transform2D(0, xform.xform(ss*0.5)));
|
||||
/*SpatialSound2DServer::get_singleton()->listener_set_transform(internal_listener_2d, Transform2D(0, xform.xform(ss*0.5)));
|
||||
Vector2 ss2 = ss*xform.get_scale();
|
||||
float panrange = MAX(ss2.x,ss2.y);
|
||||
|
||||
SpatialSound2DServer::get_singleton()->listener_set_param(internal_listener_2d, SpatialSound2DServer::LISTENER_PARAM_PAN_RANGE, panrange);
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
@@ -893,8 +893,8 @@ Transform2D Viewport::get_global_canvas_transform() const{
|
||||
void Viewport::_listener_transform_changed_notify() {
|
||||
|
||||
#ifndef _3D_DISABLED
|
||||
if (listener)
|
||||
SpatialSoundServer::get_singleton()->listener_set_transform(internal_listener, listener->get_listener_transform());
|
||||
//if (listener)
|
||||
// SpatialSoundServer::get_singleton()->listener_set_transform(internal_listener, listener->get_listener_transform());
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -957,8 +957,8 @@ void Viewport::_camera_transform_changed_notify() {
|
||||
|
||||
#ifndef _3D_DISABLED
|
||||
// If there is an active listener in the scene, it takes priority over the camera
|
||||
if (camera && !listener)
|
||||
SpatialSoundServer::get_singleton()->listener_set_transform(internal_listener, camera->get_camera_transform());
|
||||
// if (camera && !listener)
|
||||
// SpatialSoundServer::get_singleton()->listener_set_transform(internal_listener, camera->get_camera_transform());
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -2861,9 +2861,9 @@ Viewport::Viewport() {
|
||||
default_texture->vp=const_cast<Viewport*>(this);
|
||||
viewport_textures.insert(default_texture.ptr());
|
||||
|
||||
internal_listener = SpatialSoundServer::get_singleton()->listener_create();
|
||||
//internal_listener = SpatialSoundServer::get_singleton()->listener_create();
|
||||
audio_listener=false;
|
||||
internal_listener_2d = SpatialSound2DServer::get_singleton()->listener_create();
|
||||
//internal_listener_2d = SpatialSound2DServer::get_singleton()->listener_create();
|
||||
audio_listener_2d=false;
|
||||
transparent_bg=false;
|
||||
parent=NULL;
|
||||
@@ -2930,8 +2930,8 @@ Viewport::~Viewport() {
|
||||
E->get()->vp=NULL;
|
||||
}
|
||||
VisualServer::get_singleton()->free( viewport );
|
||||
SpatialSoundServer::get_singleton()->free(internal_listener);
|
||||
SpatialSound2DServer::get_singleton()->free(internal_listener_2d);
|
||||
//SpatialSoundServer::get_singleton()->free(internal_listener);
|
||||
//SpatialSound2DServer::get_singleton()->free(internal_listener_2d);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -109,8 +109,8 @@
|
||||
#include "scene/2d/collision_polygon_2d.h"
|
||||
#include "scene/2d/parallax_background.h"
|
||||
#include "scene/2d/parallax_layer.h"
|
||||
#include "scene/2d/sound_player_2d.h"
|
||||
#include "scene/2d/sample_player_2d.h"
|
||||
//#include "scene/2d/sound_player_2d.h"
|
||||
//#include "scene/2d/sample_player_2d.h"
|
||||
#include "scene/2d/screen_button.h"
|
||||
#include "scene/2d/remote_transform_2d.h"
|
||||
#include "scene/2d/y_sort.h"
|
||||
@@ -139,9 +139,9 @@
|
||||
|
||||
#include "scene/main/timer.h"
|
||||
|
||||
#include "scene/audio/stream_player.h"
|
||||
#include "scene/audio/event_player.h"
|
||||
#include "scene/audio/sound_room_params.h"
|
||||
//#include "scene/audio/stream_player.h"
|
||||
//#include "scene/audio/event_player.h"
|
||||
//#include "scene/audio/sound_room_params.h"
|
||||
#include "scene/resources/sphere_shape.h"
|
||||
#include "scene/resources/ray_shape.h"
|
||||
#include "scene/resources/box_shape.h"
|
||||
@@ -163,8 +163,8 @@
|
||||
|
||||
#include "scene/resources/polygon_path_finder.h"
|
||||
|
||||
#include "scene/resources/sample.h"
|
||||
#include "scene/audio/sample_player.h"
|
||||
//#include "scene/resources/sample.h"
|
||||
//#include "scene/audio/sample_player.h"
|
||||
#include "scene/resources/texture.h"
|
||||
#include "scene/resources/sky_box.h"
|
||||
#include "scene/resources/material.h"
|
||||
@@ -176,7 +176,7 @@
|
||||
#include "scene/resources/world.h"
|
||||
#include "scene/resources/world_2d.h"
|
||||
|
||||
#include "scene/resources/sample_library.h"
|
||||
//#include "scene/resources/sample_library.h"
|
||||
#include "scene/resources/audio_stream.h"
|
||||
#include "scene/resources/gibberish_stream.h"
|
||||
#include "scene/resources/bit_mask.h"
|
||||
@@ -220,8 +220,8 @@
|
||||
#include "scene/3d/ray_cast.h"
|
||||
#include "scene/3d/immediate_geometry.h"
|
||||
#include "scene/3d/sprite_3d.h"
|
||||
#include "scene/3d/spatial_sample_player.h"
|
||||
#include "scene/3d/spatial_stream_player.h"
|
||||
//#include "scene/3d/spatial_sample_player.h"
|
||||
//#include "scene/3d/spatial_stream_player.h"
|
||||
#include "scene/3d/proximity_group.h"
|
||||
#include "scene/3d/navigation_mesh.h"
|
||||
#include "scene/3d/navigation.h"
|
||||
@@ -231,7 +231,7 @@
|
||||
#include "scene/resources/scene_format_text.h"
|
||||
|
||||
static ResourceFormatLoaderImage *resource_loader_image=NULL;
|
||||
static ResourceFormatLoaderWAV *resource_loader_wav=NULL;
|
||||
//static ResourceFormatLoaderWAV *resource_loader_wav=NULL;
|
||||
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
@@ -258,8 +258,8 @@ void register_scene_types() {
|
||||
resource_loader_image = memnew( ResourceFormatLoaderImage );
|
||||
ResourceLoader::add_resource_format_loader( resource_loader_image );
|
||||
|
||||
resource_loader_wav = memnew( ResourceFormatLoaderWAV );
|
||||
ResourceLoader::add_resource_format_loader( resource_loader_wav );
|
||||
//resource_loader_wav = memnew( ResourceFormatLoaderWAV );
|
||||
//ResourceLoader::add_resource_format_loader( resource_loader_wav );
|
||||
resource_loader_dynamic_font = memnew( ResourceFormatLoaderDynamicFont );
|
||||
ResourceLoader::add_resource_format_loader( resource_loader_dynamic_font );
|
||||
|
||||
@@ -474,18 +474,12 @@ void register_scene_types() {
|
||||
|
||||
OS::get_singleton()->yield(); //may take time to init
|
||||
|
||||
ClassDB::register_class<SpatialSamplePlayer>();
|
||||
ClassDB::register_class<SpatialStreamPlayer>();
|
||||
ClassDB::register_class<SoundRoomParams>();
|
||||
|
||||
|
||||
#endif
|
||||
ClassDB::register_class<MeshLibrary>();
|
||||
AcceptDialog::set_swap_ok_cancel( GLOBAL_DEF("gui/common/swap_ok_cancel",bool(OS::get_singleton()->get_swap_ok_cancel())) );
|
||||
|
||||
ClassDB::register_class<SamplePlayer>();
|
||||
ClassDB::register_class<StreamPlayer>();
|
||||
ClassDB::register_class<EventPlayer>();
|
||||
|
||||
|
||||
ClassDB::register_class<CanvasItemMaterial>();
|
||||
@@ -527,8 +521,6 @@ void register_scene_types() {
|
||||
ClassDB::register_class<TileMap>();
|
||||
ClassDB::register_class<ParallaxBackground>();
|
||||
ClassDB::register_class<ParallaxLayer>();
|
||||
ClassDB::register_virtual_class<SoundPlayer2D>();
|
||||
ClassDB::register_class<SamplePlayer2D>();
|
||||
ClassDB::register_class<TouchScreenButton>();
|
||||
ClassDB::register_class<RemoteTransform2D>();
|
||||
|
||||
@@ -600,8 +592,6 @@ void register_scene_types() {
|
||||
|
||||
OS::get_singleton()->yield(); //may take time to init
|
||||
|
||||
ClassDB::register_class<Sample>();
|
||||
ClassDB::register_class<SampleLibrary>();
|
||||
ClassDB::register_virtual_class<AudioStream>();
|
||||
ClassDB::register_virtual_class<AudioStreamPlayback>();
|
||||
//TODO: Adapt to the new AudioStream API or drop (GH-3307)
|
||||
@@ -657,7 +647,7 @@ void unregister_scene_types() {
|
||||
clear_default_theme();
|
||||
|
||||
memdelete( resource_loader_image );
|
||||
memdelete( resource_loader_wav );
|
||||
// memdelete( resource_loader_wav );
|
||||
memdelete( resource_loader_dynamic_font );
|
||||
|
||||
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* event_stream.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include "event_stream.h"
|
||||
|
||||
|
||||
Error EventStreamPlayback::play() {
|
||||
if (stream.is_valid())
|
||||
stop();
|
||||
|
||||
Error err = _play();
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
|
||||
playing=true;
|
||||
AudioServer::get_singleton()->stream_set_active(stream,true);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
void EventStreamPlayback::stop(){
|
||||
|
||||
if (!playing)
|
||||
return;
|
||||
|
||||
AudioServer::get_singleton()->stream_set_active(stream,false);
|
||||
_stop();
|
||||
playing=false;
|
||||
|
||||
|
||||
}
|
||||
bool EventStreamPlayback::is_playing() const{
|
||||
|
||||
return playing;
|
||||
}
|
||||
|
||||
|
||||
EventStreamPlayback::EventStreamPlayback() {
|
||||
|
||||
playing=false;
|
||||
estream.playback=this;
|
||||
stream=AudioServer::get_singleton()->event_stream_create(&estream);
|
||||
|
||||
}
|
||||
|
||||
EventStreamPlayback::~EventStreamPlayback() {
|
||||
|
||||
AudioServer::get_singleton()->free(stream);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
EventStream::EventStream()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,118 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* event_stream.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#ifndef EVENT_STREAM_H
|
||||
#define EVENT_STREAM_H
|
||||
|
||||
#include "resource.h"
|
||||
#include "servers/audio_server.h"
|
||||
|
||||
class EventStreamPlayback : public Reference {
|
||||
|
||||
GDCLASS(EventStreamPlayback,Reference);
|
||||
|
||||
class InternalEventStream : public AudioServer::EventStream {
|
||||
public:
|
||||
AudioMixer *_get_mixer(){ return get_mixer(); }
|
||||
EventStreamPlayback *playback;
|
||||
virtual void update(uint64_t p_usec) {
|
||||
|
||||
playback->_update(get_mixer(),p_usec);
|
||||
}
|
||||
|
||||
|
||||
virtual ~InternalEventStream() {}
|
||||
};
|
||||
|
||||
|
||||
InternalEventStream estream;
|
||||
|
||||
RID stream;
|
||||
bool playing;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
virtual AudioMixer* _get_mixer() { return estream._get_mixer(); }
|
||||
virtual Error _play()=0;
|
||||
virtual bool _update(AudioMixer* p_mixer, uint64_t p_usec)=0;
|
||||
virtual void _stop()=0;
|
||||
public:
|
||||
|
||||
virtual Error play();
|
||||
virtual void stop();
|
||||
virtual bool is_playing() const;
|
||||
|
||||
virtual void set_paused(bool p_paused)=0;
|
||||
virtual bool is_paused() const=0;
|
||||
|
||||
virtual void set_loop(bool p_loop)=0;
|
||||
virtual bool is_loop_enabled() const=0;
|
||||
|
||||
virtual int get_loop_count() const=0;
|
||||
|
||||
virtual float get_pos() const=0;
|
||||
virtual void seek_pos(float p_time)=0;
|
||||
|
||||
virtual void set_volume(float p_vol)=0;
|
||||
virtual float get_volume() const=0;
|
||||
|
||||
virtual void set_pitch_scale(float p_pitch_scale)=0;
|
||||
virtual float get_pitch_scale() const=0;
|
||||
|
||||
virtual void set_tempo_scale(float p_tempo_scale)=0;
|
||||
virtual float get_tempo_scale() const=0;
|
||||
|
||||
virtual void set_channel_volume(int p_channel,float p_volume)=0;
|
||||
virtual float get_channel_volume(int p_channel) const=0;
|
||||
|
||||
virtual float get_last_note_time(int p_channel) const=0;
|
||||
EventStreamPlayback();
|
||||
~EventStreamPlayback();
|
||||
|
||||
};
|
||||
|
||||
class EventStream : public Resource {
|
||||
|
||||
GDCLASS(EventStream,Resource);
|
||||
OBJ_SAVE_TYPE( EventStream ); //children are all saved as EventStream, so they can be exchanged
|
||||
|
||||
public:
|
||||
|
||||
virtual Ref<EventStreamPlayback> instance_playback()=0;
|
||||
|
||||
virtual String get_stream_name() const=0;
|
||||
virtual float get_length() const=0;
|
||||
virtual int get_channel_count() const=0;
|
||||
|
||||
|
||||
|
||||
EventStream();
|
||||
};
|
||||
|
||||
#endif // EVENT_STREAM_H
|
||||
@@ -1,248 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* sample.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include "sample.h"
|
||||
|
||||
|
||||
void Sample::_set_data(const Dictionary& p_data) {
|
||||
|
||||
ERR_FAIL_COND(!p_data.has("packing"));
|
||||
String packing = p_data["packing"];
|
||||
|
||||
if (packing=="raw") {
|
||||
|
||||
ERR_FAIL_COND( !p_data.has("stereo"));
|
||||
ERR_FAIL_COND( !p_data.has("format"));
|
||||
ERR_FAIL_COND( !p_data.has("length"));
|
||||
bool stereo=p_data["stereo"];
|
||||
int length=p_data["length"];
|
||||
Format fmt;
|
||||
String fmtstr=p_data["format"];
|
||||
if (fmtstr=="pcm8")
|
||||
fmt=FORMAT_PCM8;
|
||||
else if (fmtstr=="pcm16")
|
||||
fmt=FORMAT_PCM16;
|
||||
else if (fmtstr=="ima_adpcm")
|
||||
fmt=FORMAT_IMA_ADPCM;
|
||||
else {
|
||||
ERR_EXPLAIN("Invalid format for sample: "+fmtstr);
|
||||
ERR_FAIL();
|
||||
}
|
||||
|
||||
ERR_FAIL_COND(!p_data.has("data"));
|
||||
|
||||
create(fmt,stereo,length);
|
||||
set_data(p_data["data"]);
|
||||
} else {
|
||||
|
||||
ERR_EXPLAIN("Invalid packing for sample data: "+packing);
|
||||
ERR_FAIL();
|
||||
}
|
||||
}
|
||||
|
||||
Dictionary Sample::_get_data() const {
|
||||
|
||||
Dictionary d;
|
||||
switch(get_format()) {
|
||||
|
||||
case FORMAT_PCM8: d["format"]="pcm8"; break;
|
||||
case FORMAT_PCM16: d["format"]="pcm16"; break;
|
||||
case FORMAT_IMA_ADPCM: d["format"]="ima_adpcm"; break;
|
||||
}
|
||||
|
||||
d["stereo"]=is_stereo();
|
||||
d["length"]=get_length();
|
||||
d["packing"]="raw";
|
||||
d["data"]=get_data();
|
||||
return d;
|
||||
|
||||
}
|
||||
|
||||
void Sample::create(Format p_format, bool p_stereo, int p_length) {
|
||||
|
||||
if (p_length<1)
|
||||
return;
|
||||
|
||||
if (sample.is_valid())
|
||||
AudioServer::get_singleton()->free(sample);
|
||||
|
||||
|
||||
mix_rate=44100;
|
||||
stereo=p_stereo;
|
||||
length=p_length;
|
||||
format=p_format;
|
||||
loop_format=LOOP_NONE;
|
||||
loop_begin=0;
|
||||
loop_end=0;
|
||||
|
||||
sample=AudioServer::get_singleton()->sample_create((AudioServer::SampleFormat)p_format,p_stereo,p_length);
|
||||
}
|
||||
|
||||
|
||||
Sample::Format Sample::get_format() const {
|
||||
|
||||
return format;
|
||||
}
|
||||
bool Sample::is_stereo() const {
|
||||
|
||||
|
||||
return stereo;
|
||||
}
|
||||
int Sample::get_length() const {
|
||||
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
void Sample::set_data(const PoolVector<uint8_t>& p_buffer) {
|
||||
|
||||
if (sample.is_valid())
|
||||
AudioServer::get_singleton()->sample_set_data(sample,p_buffer);
|
||||
|
||||
}
|
||||
PoolVector<uint8_t> Sample::get_data() const {
|
||||
|
||||
if (sample.is_valid())
|
||||
return AudioServer::get_singleton()->sample_get_data(sample);
|
||||
|
||||
return PoolVector<uint8_t>();
|
||||
|
||||
}
|
||||
|
||||
void Sample::set_mix_rate(int p_rate) {
|
||||
|
||||
mix_rate=p_rate;
|
||||
if (sample.is_valid())
|
||||
return AudioServer::get_singleton()->sample_set_mix_rate(sample,mix_rate);
|
||||
|
||||
}
|
||||
int Sample::get_mix_rate() const {
|
||||
|
||||
return mix_rate;
|
||||
}
|
||||
|
||||
void Sample::set_loop_format(LoopFormat p_format) {
|
||||
|
||||
if (sample.is_valid())
|
||||
AudioServer::get_singleton()->sample_set_loop_format(sample,(AudioServer::SampleLoopFormat)p_format);
|
||||
loop_format=p_format;
|
||||
}
|
||||
|
||||
Sample::LoopFormat Sample::get_loop_format() const {
|
||||
|
||||
return loop_format;
|
||||
}
|
||||
|
||||
void Sample::set_loop_begin(int p_pos) {
|
||||
|
||||
if (sample.is_valid())
|
||||
AudioServer::get_singleton()->sample_set_loop_begin(sample,p_pos);
|
||||
loop_begin=p_pos;
|
||||
|
||||
}
|
||||
int Sample::get_loop_begin() const {
|
||||
|
||||
return loop_begin;
|
||||
}
|
||||
|
||||
void Sample::set_loop_end(int p_pos) {
|
||||
|
||||
if (sample.is_valid())
|
||||
AudioServer::get_singleton()->sample_set_loop_end(sample,p_pos);
|
||||
loop_end=p_pos;
|
||||
}
|
||||
|
||||
int Sample::get_loop_end() const {
|
||||
|
||||
return loop_end;
|
||||
}
|
||||
|
||||
RID Sample::get_rid() const {
|
||||
|
||||
return sample;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Sample::_bind_methods(){
|
||||
|
||||
|
||||
ClassDB::bind_method(_MD("create","format","stereo","length"),&Sample::create);
|
||||
ClassDB::bind_method(_MD("get_format"),&Sample::get_format);
|
||||
ClassDB::bind_method(_MD("is_stereo"),&Sample::is_stereo);
|
||||
ClassDB::bind_method(_MD("get_length"),&Sample::get_length);
|
||||
ClassDB::bind_method(_MD("set_data","data"),&Sample::set_data);
|
||||
ClassDB::bind_method(_MD("get_data"),&Sample::get_data);
|
||||
ClassDB::bind_method(_MD("set_mix_rate","hz"),&Sample::set_mix_rate);
|
||||
ClassDB::bind_method(_MD("get_mix_rate"),&Sample::get_mix_rate);
|
||||
ClassDB::bind_method(_MD("set_loop_format","format"),&Sample::set_loop_format);
|
||||
ClassDB::bind_method(_MD("get_loop_format"),&Sample::get_loop_format);
|
||||
ClassDB::bind_method(_MD("set_loop_begin","pos"),&Sample::set_loop_begin);
|
||||
ClassDB::bind_method(_MD("get_loop_begin"),&Sample::get_loop_begin);
|
||||
ClassDB::bind_method(_MD("set_loop_end","pos"),&Sample::set_loop_end);
|
||||
ClassDB::bind_method(_MD("get_loop_end"),&Sample::get_loop_end);
|
||||
|
||||
ClassDB::bind_method(_MD("_set_data"),&Sample::_set_data);
|
||||
ClassDB::bind_method(_MD("_get_data"),&Sample::_get_data);
|
||||
|
||||
ADD_PROPERTY( PropertyInfo( Variant::DICTIONARY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), _SCS("_set_data"), _SCS("_get_data") );
|
||||
ADD_PROPERTY( PropertyInfo( Variant::BOOL, "stereo"), _SCS(""), _SCS("is_stereo") );
|
||||
ADD_PROPERTY( PropertyInfo( Variant::INT, "length",PROPERTY_HINT_RANGE,"0,999999999"), _SCS(""), _SCS("get_length") );
|
||||
ADD_PROPERTY( PropertyInfo( Variant::INT, "mix_rate", PROPERTY_HINT_RANGE,"1,192000,1" ), _SCS("set_mix_rate"), _SCS("get_mix_rate") );
|
||||
ADD_PROPERTY( PropertyInfo( Variant::INT, "loop_format", PROPERTY_HINT_ENUM,"None,Forward,PingPong" ), _SCS("set_loop_format"), _SCS("get_loop_format") );
|
||||
ADD_PROPERTY( PropertyInfo( Variant::INT, "loop_begin", PROPERTY_HINT_RANGE,"0,"+itos(999999999)+",1"), _SCS("set_loop_begin"), _SCS("get_loop_begin") );
|
||||
ADD_PROPERTY( PropertyInfo( Variant::INT, "loop_end", PROPERTY_HINT_RANGE,"0,"+itos(999999999)+",1"), _SCS("set_loop_end"), _SCS("get_loop_end") );
|
||||
|
||||
BIND_CONSTANT( FORMAT_PCM8 );
|
||||
BIND_CONSTANT( FORMAT_PCM16 );
|
||||
BIND_CONSTANT( FORMAT_IMA_ADPCM );
|
||||
|
||||
BIND_CONSTANT( LOOP_NONE );
|
||||
BIND_CONSTANT( LOOP_FORWARD );
|
||||
BIND_CONSTANT( LOOP_PING_PONG );
|
||||
|
||||
}
|
||||
|
||||
Sample::Sample() {
|
||||
|
||||
format=FORMAT_PCM8;
|
||||
length=0;
|
||||
stereo=false;
|
||||
|
||||
loop_format=LOOP_NONE;
|
||||
loop_begin=0;
|
||||
loop_end=0;
|
||||
mix_rate=44100;
|
||||
|
||||
}
|
||||
|
||||
Sample::~Sample() {
|
||||
|
||||
if (sample.is_valid())
|
||||
AudioServer::get_singleton()->free(sample);
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* sample.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#ifndef SAMPLE_H
|
||||
#define SAMPLE_H
|
||||
|
||||
#include "servers/audio_server.h"
|
||||
#include "resource.h"
|
||||
|
||||
class Sample : public Resource {
|
||||
|
||||
GDCLASS(Sample, Resource );
|
||||
RES_BASE_EXTENSION("smp");
|
||||
public:
|
||||
|
||||
enum Format {
|
||||
|
||||
FORMAT_PCM8,
|
||||
FORMAT_PCM16,
|
||||
FORMAT_IMA_ADPCM
|
||||
};
|
||||
|
||||
enum LoopFormat {
|
||||
LOOP_NONE,
|
||||
LOOP_FORWARD,
|
||||
LOOP_PING_PONG // not supported in every platform
|
||||
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
Format format;
|
||||
int length;
|
||||
bool stereo;
|
||||
|
||||
LoopFormat loop_format;
|
||||
int loop_begin;
|
||||
int loop_end;
|
||||
int mix_rate;
|
||||
|
||||
RID sample;
|
||||
|
||||
|
||||
void _set_data(const Dictionary& p_data);
|
||||
Dictionary _get_data() const;
|
||||
|
||||
protected:
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
|
||||
|
||||
void create(Format p_format, bool p_stereo, int p_length);
|
||||
|
||||
Format get_format() const;
|
||||
bool is_stereo() const;
|
||||
int get_length() const;
|
||||
|
||||
void set_data(const PoolVector<uint8_t>& p_buffer);
|
||||
PoolVector<uint8_t> get_data() const;
|
||||
|
||||
void set_mix_rate(int p_rate);
|
||||
int get_mix_rate() const;
|
||||
|
||||
void set_loop_format(LoopFormat p_format);
|
||||
LoopFormat get_loop_format() const;
|
||||
|
||||
void set_loop_begin(int p_pos);
|
||||
int get_loop_begin() const;
|
||||
|
||||
void set_loop_end(int p_pos);
|
||||
int get_loop_end() const;
|
||||
|
||||
virtual RID get_rid() const;
|
||||
Sample();
|
||||
~Sample();
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST( Sample::Format );
|
||||
VARIANT_ENUM_CAST( Sample::LoopFormat );
|
||||
|
||||
#endif // SAMPLE_H
|
||||
@@ -1,215 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* sample_library.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include "sample_library.h"
|
||||
|
||||
|
||||
bool SampleLibrary::_set(const StringName& p_name, const Variant& p_value) {
|
||||
|
||||
|
||||
if (String(p_name).begins_with("samples/")) {
|
||||
|
||||
String name=String(p_name).get_slicec('/',1);
|
||||
if (p_value.get_type()==Variant::NIL)
|
||||
sample_map.erase(name);
|
||||
else {
|
||||
SampleData sd;
|
||||
|
||||
if (p_value.get_type()==Variant::OBJECT)
|
||||
sd.sample=p_value;
|
||||
else if (p_value.get_type()==Variant::DICTIONARY) {
|
||||
|
||||
Dictionary d = p_value;
|
||||
ERR_FAIL_COND_V(!d.has("sample"),false);
|
||||
ERR_FAIL_COND_V(!d.has("pitch"),false);
|
||||
ERR_FAIL_COND_V(!d.has("db"),false);
|
||||
sd.sample=d["sample"];
|
||||
sd.pitch_scale=d["pitch"];
|
||||
sd.db=d["db"];
|
||||
}
|
||||
|
||||
sample_map[name]=sd;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SampleLibrary::_get(const StringName& p_name,Variant &r_ret) const {
|
||||
|
||||
if (String(p_name).begins_with("samples/")) {
|
||||
|
||||
String name=String(p_name).get_slicec('/',1);
|
||||
if(sample_map.has(name)) {
|
||||
Dictionary d;
|
||||
d["sample"]=sample_map[name].sample;
|
||||
d["pitch"]=sample_map[name].pitch_scale;
|
||||
d["db"]=sample_map[name].db;
|
||||
r_ret=d;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void SampleLibrary::add_sample(const StringName& p_name, const Ref<Sample>& p_sample) {
|
||||
|
||||
ERR_FAIL_COND(p_sample.is_null());
|
||||
|
||||
SampleData sd;
|
||||
sd.sample=p_sample;
|
||||
sample_map[p_name]=sd;
|
||||
}
|
||||
|
||||
Ref<Sample> SampleLibrary::get_sample(const StringName& p_name) const {
|
||||
|
||||
ERR_FAIL_COND_V(!sample_map.has(p_name),Ref<Sample>());
|
||||
|
||||
return sample_map[p_name].sample;
|
||||
}
|
||||
|
||||
void SampleLibrary::remove_sample(const StringName& p_name) {
|
||||
|
||||
sample_map.erase(p_name);
|
||||
}
|
||||
|
||||
void SampleLibrary::get_sample_list(List<StringName> *p_samples) const {
|
||||
|
||||
for(const Map<StringName,SampleData >::Element *E=sample_map.front();E;E=E->next()) {
|
||||
|
||||
p_samples->push_back(E->key());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool SampleLibrary::has_sample(const StringName& p_name) const {
|
||||
|
||||
return sample_map.has(p_name);
|
||||
}
|
||||
|
||||
void SampleLibrary::_get_property_list(List<PropertyInfo> *p_list) const {
|
||||
|
||||
|
||||
List<PropertyInfo> tpl;
|
||||
for(Map<StringName,SampleData>::Element *E=sample_map.front();E;E=E->next()) {
|
||||
|
||||
tpl.push_back( PropertyInfo( Variant::DICTIONARY, "samples/"+E->key(),PROPERTY_HINT_RESOURCE_TYPE,"Sample",PROPERTY_USAGE_NOEDITOR ) );
|
||||
}
|
||||
|
||||
tpl.sort();
|
||||
//sort so order is kept
|
||||
for(List<PropertyInfo>::Element *E=tpl.front();E;E=E->next()) {
|
||||
p_list->push_back(E->get());
|
||||
}
|
||||
}
|
||||
|
||||
StringName SampleLibrary::get_sample_idx(int p_idx) const {
|
||||
|
||||
int idx=0;
|
||||
for (Map<StringName, SampleData >::Element *E=sample_map.front();E;E=E->next()) {
|
||||
|
||||
if (p_idx==idx)
|
||||
return E->key();
|
||||
idx++;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
void SampleLibrary::sample_set_volume_db(const StringName& p_name, float p_db) {
|
||||
|
||||
ERR_FAIL_COND( !sample_map.has(p_name) );
|
||||
sample_map[p_name].db=p_db;
|
||||
|
||||
}
|
||||
|
||||
float SampleLibrary::sample_get_volume_db(const StringName& p_name) const{
|
||||
|
||||
ERR_FAIL_COND_V( !sample_map.has(p_name),0 );
|
||||
|
||||
return sample_map[p_name].db;
|
||||
}
|
||||
|
||||
void SampleLibrary::sample_set_pitch_scale(const StringName& p_name, float p_pitch){
|
||||
|
||||
ERR_FAIL_COND( !sample_map.has(p_name) );
|
||||
|
||||
sample_map[p_name].pitch_scale=p_pitch;
|
||||
}
|
||||
|
||||
float SampleLibrary::sample_get_pitch_scale(const StringName& p_name) const{
|
||||
|
||||
ERR_FAIL_COND_V( !sample_map.has(p_name),0 );
|
||||
|
||||
return sample_map[p_name].pitch_scale;
|
||||
}
|
||||
|
||||
Array SampleLibrary::_get_sample_list() const {
|
||||
|
||||
List<StringName> snames;
|
||||
get_sample_list(&snames);
|
||||
|
||||
snames.sort_custom<StringName::AlphCompare>();
|
||||
|
||||
Array ret;
|
||||
for (List<StringName>::Element *E=snames.front();E;E=E->next()) {
|
||||
ret.push_back(E->get());
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void SampleLibrary::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(_MD("add_sample","name","sample:Sample"),&SampleLibrary::add_sample );
|
||||
ClassDB::bind_method(_MD("get_sample:Sample","name"),&SampleLibrary::get_sample );
|
||||
ClassDB::bind_method(_MD("has_sample","name"),&SampleLibrary::has_sample );
|
||||
ClassDB::bind_method(_MD("remove_sample","name"),&SampleLibrary::remove_sample );
|
||||
|
||||
ClassDB::bind_method(_MD("get_sample_list"),&SampleLibrary::_get_sample_list );
|
||||
|
||||
ClassDB::bind_method(_MD("sample_set_volume_db","name","db"),&SampleLibrary::sample_set_volume_db );
|
||||
ClassDB::bind_method(_MD("sample_get_volume_db","name"),&SampleLibrary::sample_get_volume_db );
|
||||
|
||||
ClassDB::bind_method(_MD("sample_set_pitch_scale","name","pitch"),&SampleLibrary::sample_set_pitch_scale );
|
||||
ClassDB::bind_method(_MD("sample_get_pitch_scale","name"),&SampleLibrary::sample_get_pitch_scale );
|
||||
|
||||
|
||||
}
|
||||
|
||||
SampleLibrary::SampleLibrary()
|
||||
{
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* sample_library.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#ifndef SAMPLE_LIBRARY_H
|
||||
#define SAMPLE_LIBRARY_H
|
||||
|
||||
#include "resource.h"
|
||||
#include "scene/resources/sample.h"
|
||||
#include "map.h"
|
||||
|
||||
class SampleLibrary : public Resource {
|
||||
|
||||
GDCLASS(SampleLibrary,Resource);
|
||||
|
||||
struct SampleData {
|
||||
|
||||
Ref<Sample> sample;
|
||||
float db;
|
||||
float pitch_scale;
|
||||
|
||||
SampleData() { db=0; pitch_scale=1; }
|
||||
};
|
||||
|
||||
Map<StringName,SampleData > sample_map;
|
||||
|
||||
Array _get_sample_list() const;
|
||||
protected:
|
||||
|
||||
bool _set(const StringName& p_name, const Variant& p_value);
|
||||
bool _get(const StringName& p_name,Variant &r_ret) const;
|
||||
void _get_property_list(List<PropertyInfo> *p_list) const;
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
void add_sample(const StringName& p_name, const Ref<Sample>& p_sample);
|
||||
bool has_sample(const StringName& p_name) const;
|
||||
void sample_set_volume_db(const StringName& p_name, float p_db);
|
||||
float sample_get_volume_db(const StringName& p_name) const;
|
||||
void sample_set_pitch_scale(const StringName& p_name, float p_pitch);
|
||||
float sample_get_pitch_scale(const StringName& p_name) const;
|
||||
Ref<Sample> get_sample(const StringName& p_name) const;
|
||||
void get_sample_list(List<StringName> *p_samples) const;
|
||||
void remove_sample(const StringName& p_name);
|
||||
StringName get_sample_idx(int p_idx) const;
|
||||
|
||||
SampleLibrary();
|
||||
};
|
||||
|
||||
#endif // SAMPLE_LIBRARY_H
|
||||
@@ -287,10 +287,6 @@ RID World::get_scenario() const{
|
||||
|
||||
return scenario;
|
||||
}
|
||||
RID World::get_sound_space() const{
|
||||
|
||||
return sound_space;
|
||||
}
|
||||
|
||||
void World::set_environment(const Ref<Environment>& p_environment) {
|
||||
|
||||
@@ -316,7 +312,6 @@ void World::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(_MD("get_space"),&World::get_space);
|
||||
ClassDB::bind_method(_MD("get_scenario"),&World::get_scenario);
|
||||
ClassDB::bind_method(_MD("get_sound_space"),&World::get_sound_space);
|
||||
ClassDB::bind_method(_MD("set_environment","env:Environment"),&World::set_environment);
|
||||
ClassDB::bind_method(_MD("get_environment:Environment"),&World::get_environment);
|
||||
ClassDB::bind_method(_MD("get_direct_space_state:PhysicsDirectSpaceState"),&World::get_direct_space_state);
|
||||
@@ -329,7 +324,6 @@ World::World() {
|
||||
|
||||
space = PhysicsServer::get_singleton()->space_create();
|
||||
scenario = VisualServer::get_singleton()->scenario_create();
|
||||
sound_space = SpatialSoundServer::get_singleton()->space_create();
|
||||
|
||||
PhysicsServer::get_singleton()->space_set_active(space,true);
|
||||
PhysicsServer::get_singleton()->area_set_param(space,PhysicsServer::AREA_PARAM_GRAVITY,GLOBAL_DEF("physics/3d/default_gravity",9.8));
|
||||
@@ -348,7 +342,6 @@ World::~World() {
|
||||
|
||||
PhysicsServer::get_singleton()->free(space);
|
||||
VisualServer::get_singleton()->free(scenario);
|
||||
SpatialSoundServer::get_singleton()->free(sound_space);
|
||||
|
||||
#ifndef _3D_DISABLED
|
||||
memdelete( indexer );
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
#include "resource.h"
|
||||
#include "servers/physics_server.h"
|
||||
#include "servers/visual_server.h"
|
||||
#include "servers/spatial_sound_server.h"
|
||||
#include "scene/resources/environment.h"
|
||||
|
||||
class SpatialIndexer;
|
||||
@@ -45,7 +44,6 @@ class World : public Resource {
|
||||
private:
|
||||
RID space;
|
||||
RID scenario;
|
||||
RID sound_space;
|
||||
SpatialIndexer* indexer;
|
||||
Ref<Environment> environment;
|
||||
|
||||
@@ -71,7 +69,6 @@ public:
|
||||
|
||||
RID get_space() const;
|
||||
RID get_scenario() const;
|
||||
RID get_sound_space() const;
|
||||
void set_environment(const Ref<Environment>& p_environment);
|
||||
Ref<Environment> get_environment() const;
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include "world_2d.h"
|
||||
#include "servers/visual_server.h"
|
||||
#include "servers/physics_2d_server.h"
|
||||
#include "servers/spatial_sound_2d_server.h"
|
||||
//#include "servers/spatial_sound_2d_server.h"
|
||||
#include "globals.h"
|
||||
#include "scene/2d/visibility_notifier_2d.h"
|
||||
#include "scene/main/viewport.h"
|
||||
@@ -400,7 +400,6 @@ World2D::World2D() {
|
||||
|
||||
canvas = VisualServer::get_singleton()->canvas_create();
|
||||
space = Physics2DServer::get_singleton()->space_create();
|
||||
sound_space = SpatialSound2DServer::get_singleton()->space_create();
|
||||
|
||||
//set space2D to be more friendly with pixels than meters, by adjusting some constants
|
||||
Physics2DServer::get_singleton()->space_set_active(space,true);
|
||||
@@ -417,6 +416,5 @@ World2D::~World2D() {
|
||||
|
||||
VisualServer::get_singleton()->free(canvas);
|
||||
Physics2DServer::get_singleton()->free(space);
|
||||
SpatialSound2DServer::get_singleton()->free(sound_space);
|
||||
memdelete(indexer);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user