2017-03-05 14:47:28 +00:00
|
|
|
/*************************************************************************/
|
2019-02-12 16:18:13 +00:00
|
|
|
/* audio_stream_player.cpp */
|
2017-03-05 14:47:28 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2017-03-05 14:47:28 +00:00
|
|
|
/*************************************************************************/
|
2020-01-01 10:16:22 +00:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2017-03-05 14:47:28 +00:00
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/*************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2019-02-12 16:18:13 +00:00
|
|
|
#include "audio_stream_player.h"
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2018-09-11 16:13:45 +00:00
|
|
|
#include "core/engine.h"
|
2017-08-18 23:02:56 +00:00
|
|
|
|
2019-05-20 11:51:51 +00:00
|
|
|
void AudioStreamPlayer::_mix_to_bus(const AudioFrame *p_frames, int p_amount) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2019-04-27 15:58:22 +00:00
|
|
|
int bus_index = AudioServer::get_singleton()->thread_find_bus_index(bus);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-08-22 21:27:17 +00:00
|
|
|
AudioFrame *targets[4] = { NULL, NULL, NULL, NULL };
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (AudioServer::get_singleton()->get_speaker_mode() == AudioServer::SPEAKER_MODE_STEREO) {
|
|
|
|
targets[0] = AudioServer::get_singleton()->thread_get_channel_mix_buffer(bus_index, 0);
|
2017-01-21 22:00:25 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (mix_target) {
|
2017-01-21 22:00:25 +00:00
|
|
|
case MIX_TARGET_STEREO: {
|
2017-08-22 21:27:17 +00:00
|
|
|
targets[0] = AudioServer::get_singleton()->thread_get_channel_mix_buffer(bus_index, 0);
|
2017-01-21 22:00:25 +00:00
|
|
|
} break;
|
|
|
|
case MIX_TARGET_SURROUND: {
|
2017-08-22 21:27:17 +00:00
|
|
|
for (int i = 0; i < AudioServer::get_singleton()->get_channel_count(); i++) {
|
|
|
|
targets[i] = AudioServer::get_singleton()->thread_get_channel_mix_buffer(bus_index, i);
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case MIX_TARGET_CENTER: {
|
2017-08-22 21:27:17 +00:00
|
|
|
targets[0] = AudioServer::get_singleton()->thread_get_channel_mix_buffer(bus_index, 1);
|
2017-01-21 22:00:25 +00:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-22 21:27:17 +00:00
|
|
|
for (int c = 0; c < 4; c++) {
|
2017-01-21 22:00:25 +00:00
|
|
|
if (!targets[c])
|
|
|
|
break;
|
2019-04-27 15:58:22 +00:00
|
|
|
for (int i = 0; i < p_amount; i++) {
|
|
|
|
targets[c][i] += p_frames[i];
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-27 15:58:22 +00:00
|
|
|
void AudioStreamPlayer::_mix_internal(bool p_fadeout) {
|
|
|
|
|
|
|
|
//get data
|
|
|
|
AudioFrame *buffer = mix_buffer.ptrw();
|
|
|
|
int buffer_size = mix_buffer.size();
|
|
|
|
|
|
|
|
if (p_fadeout) {
|
|
|
|
// Short fadeout ramp
|
|
|
|
buffer_size = MIN(buffer_size, 128);
|
|
|
|
}
|
|
|
|
|
|
|
|
stream_playback->mix(buffer, pitch_scale, buffer_size);
|
|
|
|
|
|
|
|
//multiply volume interpolating to avoid clicks if this changes
|
|
|
|
float target_volume = p_fadeout ? -80.0 : volume_db;
|
|
|
|
float vol = Math::db2linear(mix_volume_db);
|
|
|
|
float vol_inc = (Math::db2linear(target_volume) - vol) / float(buffer_size);
|
|
|
|
|
|
|
|
for (int i = 0; i < buffer_size; i++) {
|
|
|
|
buffer[i] *= vol;
|
|
|
|
vol += vol_inc;
|
|
|
|
}
|
|
|
|
|
|
|
|
//set volume for next mix
|
|
|
|
mix_volume_db = target_volume;
|
|
|
|
|
2019-05-20 11:51:51 +00:00
|
|
|
_mix_to_bus(buffer, buffer_size);
|
2019-04-27 15:58:22 +00:00
|
|
|
}
|
|
|
|
|
2017-11-12 14:11:45 +00:00
|
|
|
void AudioStreamPlayer::_mix_audio() {
|
|
|
|
|
2019-04-27 15:58:22 +00:00
|
|
|
if (use_fadeout) {
|
2019-05-20 11:51:51 +00:00
|
|
|
_mix_to_bus(fadeout_buffer.ptr(), fadeout_buffer.size());
|
|
|
|
use_fadeout = false;
|
2019-04-27 15:58:22 +00:00
|
|
|
}
|
|
|
|
|
2019-03-05 14:02:21 +00:00
|
|
|
if (!stream_playback.is_valid() || !active ||
|
2019-04-27 15:58:22 +00:00
|
|
|
(stream_paused && !stream_paused_fade)) {
|
2018-07-09 00:30:26 +00:00
|
|
|
return;
|
2019-03-05 14:02:21 +00:00
|
|
|
}
|
2018-07-09 00:30:26 +00:00
|
|
|
|
2019-04-27 15:17:54 +00:00
|
|
|
if (stream_paused) {
|
|
|
|
if (stream_paused_fade) {
|
|
|
|
_mix_internal(true);
|
|
|
|
stream_paused_fade = false;
|
2018-07-09 00:30:26 +00:00
|
|
|
}
|
2017-11-12 14:11:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-27 15:58:22 +00:00
|
|
|
if (setstop) {
|
|
|
|
_mix_internal(true);
|
|
|
|
stream_playback->stop();
|
2019-05-20 11:51:51 +00:00
|
|
|
setstop = false;
|
2019-04-27 17:05:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (setseek >= 0.0 && !stop_has_priority) {
|
2017-11-12 14:11:45 +00:00
|
|
|
if (stream_playback->is_playing()) {
|
|
|
|
|
|
|
|
//fade out to avoid pops
|
|
|
|
_mix_internal(true);
|
|
|
|
}
|
2019-04-27 18:28:20 +00:00
|
|
|
|
2017-11-12 14:11:45 +00:00
|
|
|
stream_playback->start(setseek);
|
|
|
|
setseek = -1.0; //reset seek
|
|
|
|
mix_volume_db = volume_db; //reset ramp
|
|
|
|
}
|
|
|
|
|
2019-04-27 17:05:16 +00:00
|
|
|
stop_has_priority = false;
|
|
|
|
|
2017-11-12 14:11:45 +00:00
|
|
|
_mix_internal(false);
|
|
|
|
}
|
|
|
|
|
2017-06-19 00:07:32 +00:00
|
|
|
void AudioStreamPlayer::_notification(int p_what) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_what == NOTIFICATION_ENTER_TREE) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
AudioServer::get_singleton()->add_callback(_mix_audios, this);
|
2017-08-18 23:02:56 +00:00
|
|
|
if (autoplay && !Engine::get_singleton()->is_editor_hint()) {
|
2017-01-21 22:00:25 +00:00
|
|
|
play();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-25 14:58:21 +00:00
|
|
|
if (p_what == NOTIFICATION_INTERNAL_PROCESS) {
|
|
|
|
|
|
|
|
if (!active || (setseek < 0 && !stream_playback->is_playing())) {
|
2019-05-20 11:51:51 +00:00
|
|
|
active = false;
|
2017-08-25 14:58:21 +00:00
|
|
|
set_process_internal(false);
|
2018-01-20 21:22:00 +00:00
|
|
|
emit_signal("finished");
|
2017-08-25 14:58:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_what == NOTIFICATION_EXIT_TREE) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
AudioServer::get_singleton()->remove_callback(_mix_audios, this);
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
2018-05-27 18:29:10 +00:00
|
|
|
|
|
|
|
if (p_what == NOTIFICATION_PAUSED) {
|
|
|
|
if (!can_process()) {
|
|
|
|
// Node can't process so we start fading out to silence
|
|
|
|
set_stream_paused(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p_what == NOTIFICATION_UNPAUSED) {
|
|
|
|
set_stream_paused(false);
|
|
|
|
}
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
|
2017-06-19 00:07:32 +00:00
|
|
|
void AudioStreamPlayer::set_stream(Ref<AudioStream> p_stream) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
AudioServer::get_singleton()->lock();
|
|
|
|
|
2019-04-27 15:58:22 +00:00
|
|
|
if (active && stream_playback.is_valid() && !stream_paused) {
|
|
|
|
//changing streams out of the blue is not a great idea, but at least
|
|
|
|
//lets try to somehow avoid a click
|
|
|
|
|
|
|
|
AudioFrame *buffer = fadeout_buffer.ptrw();
|
|
|
|
int buffer_size = fadeout_buffer.size();
|
|
|
|
|
|
|
|
stream_playback->mix(buffer, pitch_scale, buffer_size);
|
|
|
|
|
|
|
|
//multiply volume interpolating to avoid clicks if this changes
|
|
|
|
float target_volume = -80.0;
|
|
|
|
float vol = Math::db2linear(mix_volume_db);
|
|
|
|
float vol_inc = (Math::db2linear(target_volume) - vol) / float(buffer_size);
|
|
|
|
|
|
|
|
for (int i = 0; i < buffer_size; i++) {
|
|
|
|
buffer[i] *= vol;
|
|
|
|
vol += vol_inc;
|
|
|
|
}
|
|
|
|
|
2019-05-20 11:51:51 +00:00
|
|
|
use_fadeout = true;
|
2019-04-27 15:58:22 +00:00
|
|
|
}
|
|
|
|
|
2017-01-21 22:00:25 +00:00
|
|
|
mix_buffer.resize(AudioServer::get_singleton()->thread_get_mix_buffer_size());
|
|
|
|
|
|
|
|
if (stream_playback.is_valid()) {
|
|
|
|
stream_playback.unref();
|
|
|
|
stream.unref();
|
2017-03-05 15:44:50 +00:00
|
|
|
active = false;
|
|
|
|
setseek = -1;
|
2019-04-27 15:58:22 +00:00
|
|
|
setstop = false;
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
|
2017-09-27 13:30:08 +00:00
|
|
|
if (p_stream.is_valid()) {
|
|
|
|
stream = p_stream;
|
|
|
|
stream_playback = p_stream->instance_playback();
|
|
|
|
}
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-09-01 19:42:50 +00:00
|
|
|
AudioServer::get_singleton()->unlock();
|
|
|
|
|
2017-09-27 13:30:08 +00:00
|
|
|
if (p_stream.is_valid() && stream_playback.is_null()) {
|
2017-01-21 22:00:25 +00:00
|
|
|
stream.unref();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-19 00:07:32 +00:00
|
|
|
Ref<AudioStream> AudioStreamPlayer::get_stream() const {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
2017-06-19 00:07:32 +00:00
|
|
|
void AudioStreamPlayer::set_volume_db(float p_volume) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
volume_db = p_volume;
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
2017-06-19 00:07:32 +00:00
|
|
|
float AudioStreamPlayer::get_volume_db() const {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
return volume_db;
|
|
|
|
}
|
|
|
|
|
2018-01-01 21:23:16 +00:00
|
|
|
void AudioStreamPlayer::set_pitch_scale(float p_pitch_scale) {
|
2018-08-20 08:25:48 +00:00
|
|
|
ERR_FAIL_COND(p_pitch_scale <= 0.0);
|
2018-01-01 21:23:16 +00:00
|
|
|
pitch_scale = p_pitch_scale;
|
|
|
|
}
|
|
|
|
float AudioStreamPlayer::get_pitch_scale() const {
|
|
|
|
return pitch_scale;
|
|
|
|
}
|
|
|
|
|
2017-06-19 00:07:32 +00:00
|
|
|
void AudioStreamPlayer::play(float p_from_pos) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
if (stream_playback.is_valid()) {
|
2017-11-12 14:11:45 +00:00
|
|
|
//mix_volume_db = volume_db; do not reset volume ramp here, can cause clicks
|
2017-03-05 15:44:50 +00:00
|
|
|
setseek = p_from_pos;
|
2019-05-20 11:51:51 +00:00
|
|
|
stop_has_priority = false;
|
2017-03-05 15:44:50 +00:00
|
|
|
active = true;
|
2017-08-25 14:58:21 +00:00
|
|
|
set_process_internal(true);
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-19 00:07:32 +00:00
|
|
|
void AudioStreamPlayer::seek(float p_seconds) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
if (stream_playback.is_valid()) {
|
2017-03-05 15:44:50 +00:00
|
|
|
setseek = p_seconds;
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-19 00:07:32 +00:00
|
|
|
void AudioStreamPlayer::stop() {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2019-04-27 15:58:22 +00:00
|
|
|
if (stream_playback.is_valid() && active) {
|
2019-05-20 11:51:51 +00:00
|
|
|
setstop = true;
|
|
|
|
stop_has_priority = true;
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-19 00:07:32 +00:00
|
|
|
bool AudioStreamPlayer::is_playing() const {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
if (stream_playback.is_valid()) {
|
2019-04-27 15:58:22 +00:00
|
|
|
return active && !setstop; //&& stream_playback->is_playing();
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-09-21 03:31:36 +00:00
|
|
|
float AudioStreamPlayer::get_playback_position() {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
if (stream_playback.is_valid()) {
|
2017-09-21 03:31:36 +00:00
|
|
|
return stream_playback->get_playback_position();
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-06-19 00:07:32 +00:00
|
|
|
void AudioStreamPlayer::set_bus(const StringName &p_bus) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
//if audio is active, must lock this
|
|
|
|
AudioServer::get_singleton()->lock();
|
2017-03-05 15:44:50 +00:00
|
|
|
bus = p_bus;
|
2017-01-21 22:00:25 +00:00
|
|
|
AudioServer::get_singleton()->unlock();
|
|
|
|
}
|
2017-06-19 00:07:32 +00:00
|
|
|
StringName AudioStreamPlayer::get_bus() const {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
|
|
|
|
if (AudioServer::get_singleton()->get_bus_name(i) == bus) {
|
2017-01-21 22:00:25 +00:00
|
|
|
return bus;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "Master";
|
|
|
|
}
|
|
|
|
|
2017-06-19 00:07:32 +00:00
|
|
|
void AudioStreamPlayer::set_autoplay(bool p_enable) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
autoplay = p_enable;
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
2017-06-19 00:07:32 +00:00
|
|
|
bool AudioStreamPlayer::is_autoplay_enabled() {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
return autoplay;
|
|
|
|
}
|
|
|
|
|
2017-06-19 00:07:32 +00:00
|
|
|
void AudioStreamPlayer::set_mix_target(MixTarget p_target) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
mix_target = p_target;
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
|
2017-06-19 00:07:32 +00:00
|
|
|
AudioStreamPlayer::MixTarget AudioStreamPlayer::get_mix_target() const {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
return mix_target;
|
|
|
|
}
|
|
|
|
|
2017-06-19 00:07:32 +00:00
|
|
|
void AudioStreamPlayer::_set_playing(bool p_enable) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
if (p_enable)
|
|
|
|
play();
|
|
|
|
else
|
|
|
|
stop();
|
|
|
|
}
|
2017-06-19 00:07:32 +00:00
|
|
|
bool AudioStreamPlayer::_is_active() const {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
return active;
|
|
|
|
}
|
|
|
|
|
2018-05-27 18:29:10 +00:00
|
|
|
void AudioStreamPlayer::set_stream_paused(bool p_pause) {
|
|
|
|
|
|
|
|
if (p_pause != stream_paused) {
|
|
|
|
stream_paused = p_pause;
|
2019-06-26 13:08:25 +00:00
|
|
|
stream_paused_fade = p_pause;
|
2018-05-27 18:29:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AudioStreamPlayer::get_stream_paused() const {
|
|
|
|
|
|
|
|
return stream_paused;
|
|
|
|
}
|
|
|
|
|
2017-06-19 00:07:32 +00:00
|
|
|
void AudioStreamPlayer::_validate_property(PropertyInfo &property) const {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (property.name == "bus") {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
String options;
|
2019-05-20 11:51:51 +00:00
|
|
|
for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
|
2017-03-05 15:44:50 +00:00
|
|
|
if (i > 0)
|
|
|
|
options += ",";
|
2017-01-21 22:00:25 +00:00
|
|
|
String name = AudioServer::get_singleton()->get_bus_name(i);
|
2017-03-05 15:44:50 +00:00
|
|
|
options += name;
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
property.hint_string = options;
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-19 00:07:32 +00:00
|
|
|
void AudioStreamPlayer::_bus_layout_changed() {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
_change_notify();
|
|
|
|
}
|
|
|
|
|
2019-04-10 15:57:03 +00:00
|
|
|
Ref<AudioStreamPlayback> AudioStreamPlayer::get_stream_playback() {
|
|
|
|
return stream_playback;
|
|
|
|
}
|
|
|
|
|
2017-06-19 00:07:32 +00:00
|
|
|
void AudioStreamPlayer::_bind_methods() {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-08-09 11:19:41 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_stream", "stream"), &AudioStreamPlayer::set_stream);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_stream"), &AudioStreamPlayer::get_stream);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-06-19 00:07:32 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_volume_db", "volume_db"), &AudioStreamPlayer::set_volume_db);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_volume_db"), &AudioStreamPlayer::get_volume_db);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2018-01-01 21:23:16 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_pitch_scale", "pitch_scale"), &AudioStreamPlayer::set_pitch_scale);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_pitch_scale"), &AudioStreamPlayer::get_pitch_scale);
|
|
|
|
|
2017-09-10 13:37:49 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("play", "from_position"), &AudioStreamPlayer::play, DEFVAL(0.0));
|
|
|
|
ClassDB::bind_method(D_METHOD("seek", "to_position"), &AudioStreamPlayer::seek);
|
2017-06-19 00:07:32 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("stop"), &AudioStreamPlayer::stop);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-06-19 00:07:32 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("is_playing"), &AudioStreamPlayer::is_playing);
|
2017-09-21 03:31:36 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_playback_position"), &AudioStreamPlayer::get_playback_position);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-06-19 00:07:32 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_bus", "bus"), &AudioStreamPlayer::set_bus);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_bus"), &AudioStreamPlayer::get_bus);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-06-19 00:07:32 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_autoplay", "enable"), &AudioStreamPlayer::set_autoplay);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_autoplay_enabled"), &AudioStreamPlayer::is_autoplay_enabled);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-06-19 00:07:32 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_mix_target", "mix_target"), &AudioStreamPlayer::set_mix_target);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_mix_target"), &AudioStreamPlayer::get_mix_target);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-06-19 00:07:32 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("_set_playing", "enable"), &AudioStreamPlayer::_set_playing);
|
|
|
|
ClassDB::bind_method(D_METHOD("_is_active"), &AudioStreamPlayer::_is_active);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2018-05-27 18:29:10 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_stream_paused", "pause"), &AudioStreamPlayer::set_stream_paused);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_stream_paused"), &AudioStreamPlayer::get_stream_paused);
|
|
|
|
|
2019-04-10 15:57:03 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_stream_playback"), &AudioStreamPlayer::get_stream_playback);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "stream", PROPERTY_HINT_RESOURCE_TYPE, "AudioStream"), "set_stream", "get_stream");
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volume_db", PROPERTY_HINT_RANGE, "-80,24"), "set_volume_db", "get_volume_db");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "pitch_scale", PROPERTY_HINT_RANGE, "0.01,4,0.01,or_greater"), "set_pitch_scale", "get_pitch_scale");
|
2017-09-13 11:40:41 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "playing", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "_set_playing", "is_playing");
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "autoplay"), "set_autoplay", "is_autoplay_enabled");
|
2018-05-27 18:29:10 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "stream_paused", PROPERTY_HINT_NONE, ""), "set_stream_paused", "get_stream_paused");
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "mix_target", PROPERTY_HINT_ENUM, "Stereo,Surround,Center"), "set_mix_target", "get_mix_target");
|
2020-02-20 21:58:05 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "bus", PROPERTY_HINT_ENUM, ""), "set_bus", "get_bus");
|
2017-08-25 14:58:21 +00:00
|
|
|
|
|
|
|
ADD_SIGNAL(MethodInfo("finished"));
|
2017-09-12 19:09:06 +00:00
|
|
|
|
|
|
|
BIND_ENUM_CONSTANT(MIX_TARGET_STEREO);
|
|
|
|
BIND_ENUM_CONSTANT(MIX_TARGET_SURROUND);
|
|
|
|
BIND_ENUM_CONSTANT(MIX_TARGET_CENTER);
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
|
2017-06-19 00:07:32 +00:00
|
|
|
AudioStreamPlayer::AudioStreamPlayer() {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
mix_volume_db = 0;
|
2018-01-01 21:23:16 +00:00
|
|
|
pitch_scale = 1.0;
|
2017-03-05 15:44:50 +00:00
|
|
|
volume_db = 0;
|
|
|
|
autoplay = false;
|
|
|
|
setseek = -1;
|
|
|
|
active = false;
|
2018-05-27 18:29:10 +00:00
|
|
|
stream_paused = false;
|
2019-04-27 15:17:54 +00:00
|
|
|
stream_paused_fade = false;
|
2017-03-05 15:44:50 +00:00
|
|
|
mix_target = MIX_TARGET_STEREO;
|
2019-04-27 15:58:22 +00:00
|
|
|
fadeout_buffer.resize(512);
|
2019-05-20 11:51:51 +00:00
|
|
|
setstop = false;
|
|
|
|
use_fadeout = false;
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2020-02-21 17:28:45 +00:00
|
|
|
AudioServer::get_singleton()->connect("bus_layout_changed", callable_mp(this, &AudioStreamPlayer::_bus_layout_changed));
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
|
2017-06-19 00:07:32 +00:00
|
|
|
AudioStreamPlayer::~AudioStreamPlayer() {
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|