Beispiel #1
0
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);

}
Beispiel #2
0
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);

}
Beispiel #3
0
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);

}
Beispiel #4
0
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;
}
Beispiel #5
0
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);

}
Beispiel #6
0
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);
    }
}
Beispiel #7
0
void SpatialStreamPlayer::stop() {

	if (!is_inside_tree())
		return;
	if (stream.is_null())
		return;

	SpatialSoundServer::get_singleton()->source_set_audio_stream(get_source_rid(),NULL);
	stream->stop();
	//set_idle_process(false);
}
Beispiel #8
0
void SpatialStreamPlayer::play() {

	if (!is_inside_tree())
		return;
	if (stream.is_null())
		return;
	if (stream->is_playing())
		stop();
	stream->play();
	SpatialSoundServer::get_singleton()->source_set_audio_stream(get_source_rid(),stream->get_audio_stream());
	//if (stream->get_update_mode()!=AudioStream::UPDATE_NONE)
	//	set_idle_process(true);

}
Beispiel #9
0
void SamplePlayer2D::_notification(int p_what) {


    switch(p_what) {

    case NOTIFICATION_ENTER_TREE: {

        SpatialSound2DServer::get_singleton()->source_set_polyphony(get_source_rid(),polyphony);


    }
    break;
    }

}