2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* event_stream_chibi.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:11:45 +00:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2018-01-02 10:27:24 +00:00
|
|
|
/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 01:10:30 +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. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#include "event_stream_chibi.h"
|
|
|
|
#include "cp_loader_it.h"
|
|
|
|
#include "cp_loader_mod.h"
|
2017-03-18 23:36:26 +00:00
|
|
|
#include "cp_loader_s3m.h"
|
|
|
|
#include "cp_loader_xm.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
static CPSampleManagerImpl *sample_manager;
|
|
|
|
static ResourceFormatLoaderChibi *resource_loader;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
CPSample_ID CPSampleManagerImpl::create(bool p_16bits, bool p_stereo, int32_t p_len) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
AudioServer::SampleFormat sf = p_16bits ? AudioServer::SAMPLE_FORMAT_PCM16 : AudioServer::SAMPLE_FORMAT_PCM8;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
SampleData *sd = memnew(SampleData);
|
|
|
|
sd->rid = AudioServer::get_singleton()->sample_create(sf, p_stereo, p_len);
|
|
|
|
sd->stereo = p_stereo;
|
|
|
|
sd->len = p_len;
|
|
|
|
sd->is16 = p_16bits;
|
|
|
|
sd->mixfreq = 44100;
|
|
|
|
sd->loop_begin = 0;
|
|
|
|
sd->loop_end = 0;
|
|
|
|
sd->loop_type = CP_LOOP_NONE;
|
|
|
|
sd->locks = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
valid.insert(sd);
|
|
|
|
#endif
|
|
|
|
CPSample_ID sid;
|
2017-03-18 23:36:26 +00:00
|
|
|
sid._private = sd;
|
2014-02-10 01:10:30 +00:00
|
|
|
return sid;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void CPSampleManagerImpl::recreate(CPSample_ID p_id, bool p_16bits, bool p_stereo, int32_t p_len) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
AudioServer::SampleFormat sf = p_16bits ? AudioServer::SAMPLE_FORMAT_PCM16 : AudioServer::SAMPLE_FORMAT_PCM8;
|
|
|
|
SampleData *sd = _getsd(p_id);
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
ERR_FAIL_COND(!valid.has(sd));
|
|
|
|
#endif
|
|
|
|
AudioServer::get_singleton()->free(sd->rid);
|
2017-03-18 23:36:26 +00:00
|
|
|
sd->rid = AudioServer::get_singleton()->sample_create(sf, p_stereo, p_len);
|
|
|
|
sd->stereo = p_stereo;
|
|
|
|
sd->len = p_len;
|
|
|
|
sd->is16 = p_16bits;
|
|
|
|
sd->mixfreq = 44100;
|
|
|
|
sd->loop_begin = 0;
|
|
|
|
sd->loop_end = 0;
|
|
|
|
sd->loop_type = CP_LOOP_NONE;
|
|
|
|
}
|
|
|
|
void CPSampleManagerImpl::destroy(CPSample_ID p_id) {
|
|
|
|
|
|
|
|
SampleData *sd = _getsd(p_id);
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
ERR_FAIL_COND(!valid.has(sd));
|
|
|
|
valid.erase(sd);
|
|
|
|
#endif
|
|
|
|
AudioServer::get_singleton()->free(sd->rid);
|
|
|
|
|
|
|
|
memdelete(sd);
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
bool CPSampleManagerImpl::check(CPSample_ID p_id) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
SampleData *sd = _getsd(p_id);
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
return valid.has(sd);
|
|
|
|
#else
|
2017-03-18 23:36:26 +00:00
|
|
|
return _getsd(p_id) != NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void CPSampleManagerImpl::set_c5_freq(CPSample_ID p_id, int32_t p_freq) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
SampleData *sd = _getsd(p_id);
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
ERR_FAIL_COND(!valid.has(sd));
|
|
|
|
#endif
|
2017-03-18 23:36:26 +00:00
|
|
|
sd->mixfreq = p_freq;
|
|
|
|
AudioServer::get_singleton()->sample_set_mix_rate(sd->rid, p_freq);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
void CPSampleManagerImpl::set_loop_begin(CPSample_ID p_id, int32_t p_begin) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
SampleData *sd = _getsd(p_id);
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
ERR_FAIL_COND(!valid.has(sd));
|
|
|
|
#endif
|
2017-03-18 23:36:26 +00:00
|
|
|
sd->loop_begin = p_begin;
|
|
|
|
AudioServer::get_singleton()->sample_set_loop_begin(sd->rid, p_begin);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
void CPSampleManagerImpl::set_loop_end(CPSample_ID p_id, int32_t p_end) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
SampleData *sd = _getsd(p_id);
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
ERR_FAIL_COND(!valid.has(sd));
|
|
|
|
#endif
|
2017-03-18 23:36:26 +00:00
|
|
|
sd->loop_end = p_end;
|
|
|
|
AudioServer::get_singleton()->sample_set_loop_end(sd->rid, p_end);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
void CPSampleManagerImpl::set_loop_type(CPSample_ID p_id, CPSample_Loop_Type p_type) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
SampleData *sd = _getsd(p_id);
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
ERR_FAIL_COND(!valid.has(sd));
|
|
|
|
#endif
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
sd->loop_type = p_type;
|
|
|
|
AudioServer::get_singleton()->sample_set_loop_format(sd->rid, AudioServer::SampleLoopFormat(p_type));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
void CPSampleManagerImpl::set_chunk(CPSample_ID p_id, int32_t p_index, void *p_data, int p_data_len) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
SampleData *sd = _getsd(p_id);
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
ERR_FAIL_COND(!valid.has(sd));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ERR_FAIL();
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int32_t CPSampleManagerImpl::get_loop_begin(CPSample_ID p_id) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
SampleData *sd = _getsd(p_id);
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(!valid.has(sd), 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return sd->loop_begin;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
int32_t CPSampleManagerImpl::get_loop_end(CPSample_ID p_id) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
SampleData *sd = _getsd(p_id);
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(!valid.has(sd), 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return sd->loop_end;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
CPSample_Loop_Type CPSampleManagerImpl::get_loop_type(CPSample_ID p_id) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
SampleData *sd = _getsd(p_id);
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(!valid.has(sd), CP_LOOP_NONE);
|
2014-02-10 01:10:30 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return sd->loop_type;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
int32_t CPSampleManagerImpl::get_c5_freq(CPSample_ID p_id) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
SampleData *sd = _getsd(p_id);
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(!valid.has(sd), 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return sd->mixfreq;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
int32_t CPSampleManagerImpl::get_size(CPSample_ID p_id) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
SampleData *sd = _getsd(p_id);
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(!valid.has(sd), 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return sd->len;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
bool CPSampleManagerImpl::is_16bits(CPSample_ID p_id) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
SampleData *sd = _getsd(p_id);
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(!valid.has(sd), false);
|
2014-02-10 01:10:30 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return sd->is16;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
bool CPSampleManagerImpl::is_stereo(CPSample_ID p_id) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
SampleData *sd = _getsd(p_id);
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(!valid.has(sd), false);
|
2014-02-10 01:10:30 +00:00
|
|
|
#endif
|
|
|
|
return sd->stereo;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
bool CPSampleManagerImpl::lock_data(CPSample_ID p_id) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
SampleData *sd = _getsd(p_id);
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(!valid.has(sd), 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
sd->locks++;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (sd->locks == 1) {
|
|
|
|
sd->lock = AudioServer::get_singleton()->sample_get_data(sd->rid);
|
|
|
|
sd->w = sd->lock.write();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
void *CPSampleManagerImpl::get_data(CPSample_ID p_id) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
SampleData *sd = _getsd(p_id);
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(!valid.has(sd), 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
#endif
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(sd->locks == 0, 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
return sd->w.ptr();
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int16_t CPSampleManagerImpl::get_data(CPSample_ID p_id, int p_sample, int p_channel) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
SampleData *sd = _getsd(p_id);
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(!valid.has(sd), 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
ERR_FAIL_V(0);
|
|
|
|
lock_data(p_id);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int sofs = sd->stereo ? 2 : 1;
|
|
|
|
uint16_t v = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (sd->is16) {
|
2017-03-18 23:36:26 +00:00
|
|
|
int16_t *p = (int16_t *)sd->w.ptr();
|
|
|
|
v = p[p_sample * sofs + p_channel];
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
int8_t *p = (int8_t *)sd->w.ptr();
|
|
|
|
v = p[p_sample * sofs + p_channel];
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unlock_data(p_id);
|
|
|
|
|
|
|
|
return v;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
void CPSampleManagerImpl::set_data(CPSample_ID p_id, int p_sample, int16_t p_data, int p_channel) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
SampleData *sd = _getsd(p_id);
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
ERR_FAIL_COND(!valid.has(sd));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ERR_FAIL();
|
|
|
|
lock_data(p_id);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int sofs = sd->stereo ? 2 : 1;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (sd->is16) {
|
2017-03-18 23:36:26 +00:00
|
|
|
int16_t *p = (int16_t *)sd->w.ptr();
|
|
|
|
p[p_sample * sofs + p_channel] = p_data;
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
int8_t *p = (int8_t *)sd->w.ptr();
|
|
|
|
p[p_sample * sofs + p_channel] = p_data;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unlock_data(p_id);
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
void CPSampleManagerImpl::unlock_data(CPSample_ID p_id) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
SampleData *sd = _getsd(p_id);
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
ERR_FAIL_COND(!valid.has(sd));
|
|
|
|
#endif
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND(sd->locks == 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
sd->locks--;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (sd->locks == 0) {
|
|
|
|
sd->w = DVector<uint8_t>::Write();
|
|
|
|
AudioServer::get_singleton()->sample_set_data(sd->rid, sd->lock);
|
|
|
|
sd->lock = DVector<uint8_t>();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void CPSampleManagerImpl::get_chunk(CPSample_ID p_id, int32_t p_index, void *p_data, int p_data_len) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
SampleData *sd = _getsd(p_id);
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
ERR_FAIL_COND(!valid.has(sd));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ERR_FAIL();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** MIXER **/
|
|
|
|
|
|
|
|
void CPMixerImpl::set_callback_interval(int p_interval_us) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
callback_interval = p_interval_us;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void CPMixerImpl::set_callback(void (*p_callback)(void *), void *p_userdata) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
callback = p_callback;
|
|
|
|
userdata = p_userdata;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void CPMixerImpl::setup_voice(int p_voice_index, CPSample_ID p_sample_id, int32_t p_start_index) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Voice &v = voices[p_voice_index];
|
|
|
|
if (v.channel != AudioMixer::INVALID_CHANNEL) {
|
2014-02-10 01:10:30 +00:00
|
|
|
mixer->channel_free(v.channel);
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
v.channel = mixer->channel_alloc(sample_manager->get_rid(p_sample_id));
|
|
|
|
v.freq_mult = sample_manager->get_c5_freq(p_sample_id) / 261.6255653006;
|
2014-02-10 01:10:30 +00:00
|
|
|
v.sample = p_sample_id;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void CPMixerImpl::stop_voice(int p_voice_index) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Voice &v = voices[p_voice_index];
|
|
|
|
if (v.channel == AudioMixer::INVALID_CHANNEL)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
mixer->channel_free(v.channel);
|
2017-03-18 23:36:26 +00:00
|
|
|
v.channel = AudioMixer::INVALID_CHANNEL;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void CPMixerImpl::set_voice_frequency(int p_voice_index, int32_t p_freq) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Voice &v = voices[p_voice_index];
|
|
|
|
ERR_FAIL_COND(v.channel == AudioMixer::INVALID_CHANNEL);
|
2014-02-10 01:10:30 +00:00
|
|
|
float f = p_freq / 256.0;
|
2017-03-18 23:36:26 +00:00
|
|
|
f *= pitch_scale;
|
|
|
|
mixer->channel_set_mix_rate(v.channel, f * v.freq_mult);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void CPMixerImpl::set_voice_panning(int p_voice_index, int p_pan) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Voice &v = voices[p_voice_index];
|
|
|
|
ERR_FAIL_COND(v.channel == AudioMixer::INVALID_CHANNEL);
|
|
|
|
if (p_pan == CP_PAN_SURROUND)
|
|
|
|
p_pan = CP_PAN_CENTER;
|
2014-02-10 01:10:30 +00:00
|
|
|
float p = p_pan / 256.0;
|
2017-03-18 23:36:26 +00:00
|
|
|
mixer->channel_set_pan(v.channel, p);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void CPMixerImpl::set_voice_volume(int p_voice_index, int p_vol) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Voice &v = voices[p_voice_index];
|
|
|
|
ERR_FAIL_COND(v.channel == AudioMixer::INVALID_CHANNEL);
|
|
|
|
float vol = p_vol / 512.0;
|
|
|
|
vol *= voice_scale;
|
|
|
|
mixer->channel_set_volume(v.channel, vol);
|
|
|
|
mixer->channel_set_reverb(v.channel, reverb_type, vol * v.reverb);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void CPMixerImpl::set_voice_filter(int p_voice_index, bool p_enabled, uint8_t p_cutoff, uint8_t p_resonance) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Voice &v = voices[p_voice_index];
|
|
|
|
ERR_FAIL_COND(v.channel == AudioMixer::INVALID_CHANNEL);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void CPMixerImpl::set_voice_reverb_send(int p_voice_index, int p_reverb) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Voice &v = voices[p_voice_index];
|
|
|
|
ERR_FAIL_COND(v.channel == AudioMixer::INVALID_CHANNEL);
|
|
|
|
v.reverb = p_reverb / 255.0;
|
2014-02-10 01:10:30 +00:00
|
|
|
//mixer->channel_set_reverb(v.channel,reverb_type,p_reverb/255.0);
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void CPMixerImpl::set_voice_chorus_send(int p_voice_index, int p_chorus) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Voice &v = voices[p_voice_index];
|
|
|
|
ERR_FAIL_COND(v.channel == AudioMixer::INVALID_CHANNEL);
|
|
|
|
mixer->channel_set_chorus(v.channel, p_chorus / 255.0);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void CPMixerImpl::set_reverb_mode(ReverbMode p_mode) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
// Voice &v=voices[p_voice_index];
|
|
|
|
// ERR_FAIL_COND(v.channel==AudioMixer::INVALID_CHANNEL);
|
|
|
|
switch (p_mode) {
|
|
|
|
case CPMixer::REVERB_MODE_STUDIO_SMALL: reverb_type = AudioMixer::REVERB_SMALL; break;
|
|
|
|
case CPMixer::REVERB_MODE_STUDIO_MEDIUM: reverb_type = AudioMixer::REVERB_MEDIUM; break;
|
|
|
|
case CPMixer::REVERB_MODE_STUDIO_LARGE: reverb_type = AudioMixer::REVERB_LARGE; break;
|
|
|
|
case CPMixer::REVERB_MODE_HALL: reverb_type = AudioMixer::REVERB_HALL; break;
|
|
|
|
default: reverb_type = AudioMixer::REVERB_SMALL; break;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void CPMixerImpl::set_chorus_params(unsigned int p_delay_ms, unsigned int p_separation_ms, unsigned int p_depth_ms10, unsigned int p_speed_hz10) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
// Voice &v=voices[p_voice_index];
|
|
|
|
// ERR_FAIL_COND(v.channel==AudioMixer::INVALID_CHANNEL);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Info retrieving */
|
|
|
|
|
|
|
|
int32_t CPMixerImpl::get_voice_sample_pos_index(int p_voice_index) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Voice &v = voices[p_voice_index];
|
|
|
|
ERR_FAIL_COND_V(v.channel == AudioMixer::INVALID_CHANNEL, 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CPMixerImpl::get_voice_panning(int p_voice_index) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Voice &v = voices[p_voice_index];
|
|
|
|
ERR_FAIL_COND_V(!is_voice_active(p_voice_index), 0);
|
|
|
|
return mixer->channel_get_pan(v.channel) * CP_PAN_RIGHT;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int CPMixerImpl::get_voice_volume(int p_voice_index) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Voice &v = voices[p_voice_index];
|
|
|
|
ERR_FAIL_COND_V(!is_voice_active(p_voice_index), 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
return mixer->channel_get_volume(v.channel);
|
|
|
|
}
|
|
|
|
|
|
|
|
CPSample_ID CPMixerImpl::get_voice_sample_id(int p_voice_index) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Voice &v = voices[p_voice_index];
|
|
|
|
ERR_FAIL_COND_V(v.channel == AudioMixer::INVALID_CHANNEL, CPSample_ID());
|
2014-02-10 01:10:30 +00:00
|
|
|
return v.sample;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool CPMixerImpl::is_voice_active(int p_voice_index) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Voice &v = voices[p_voice_index];
|
|
|
|
if (v.channel == AudioMixer::INVALID_CHANNEL)
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
|
|
|
if (!mixer->channel_is_valid(v.channel))
|
2017-03-18 23:36:26 +00:00
|
|
|
v.channel = AudioMixer::INVALID_CHANNEL;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
return v.channel != AudioMixer::INVALID_CHANNEL;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void CPMixerImpl::process_usecs(int p_usec, float p_volume, float p_pitch_scale, float p_tempo_scale) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND(callback_interval == 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
//update this somewhere
|
2017-03-18 23:36:26 +00:00
|
|
|
pitch_scale = p_pitch_scale;
|
|
|
|
tempo_scale = p_tempo_scale;
|
|
|
|
voice_scale = AudioServer::get_singleton()->get_event_voice_global_volume_scale() * p_volume;
|
|
|
|
while (p_usec) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_usec >= callback_timeout) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
p_usec -= callback_timeout;
|
|
|
|
callback_timeout = 0;
|
2014-09-17 23:03:10 +00:00
|
|
|
if (callback) {
|
2014-02-10 01:10:30 +00:00
|
|
|
callback(userdata);
|
2014-09-17 23:03:10 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
callback_timeout = callback_interval * (1.0 / p_tempo_scale);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
callback_timeout -= p_usec;
|
|
|
|
p_usec = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CPMixerImpl::CPMixerImpl(AudioMixer *p_mixer) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
callback_interval = 1;
|
|
|
|
callback_timeout = 0;
|
|
|
|
userdata = 0;
|
|
|
|
callback = 0;
|
|
|
|
tempo_scale = 1.0;
|
|
|
|
pitch_scale = 1.0;
|
|
|
|
mixer = p_mixer;
|
2014-02-10 01:10:30 +00:00
|
|
|
voice_scale = AudioServer::get_singleton()->get_event_voice_global_volume_scale();
|
|
|
|
reverb_type = AudioMixer::REVERB_SMALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** FILE ACCESS WRAPPER **/
|
|
|
|
|
|
|
|
CPFileAccessWrapperImpl::Error CPFileAccessWrapperImpl::open(const char *p_filename, int p_mode_flags) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(p_mode_flags & WRITE, ERROR_WRITING_FILE);
|
2014-02-10 01:10:30 +00:00
|
|
|
close();
|
2017-03-18 23:36:26 +00:00
|
|
|
f = FileAccess::open(String::utf8(p_filename), p_mode_flags);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!f)
|
|
|
|
return ERROR_FILE_NOT_FOUND;
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void CPFileAccessWrapperImpl::close() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (f)
|
|
|
|
memdelete(f);
|
2017-03-18 23:36:26 +00:00
|
|
|
f = NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void CPFileAccessWrapperImpl::seek(uint32_t p_position) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
f->seek(p_position);
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
void CPFileAccessWrapperImpl::seek_end() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
f->seek_end();
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
uint32_t CPFileAccessWrapperImpl::get_pos() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return f->get_pos();
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool CPFileAccessWrapperImpl::eof_reached() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return f->eof_reached();
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
uint8_t CPFileAccessWrapperImpl::get_byte() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return f->get_8();
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
void CPFileAccessWrapperImpl::get_byte_array(uint8_t *p_dest, int p_elements) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
f->get_buffer(p_dest, p_elements);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
void CPFileAccessWrapperImpl::get_word_array(uint16_t *p_dest, int p_elements) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < p_elements; i++) {
|
|
|
|
p_dest[i] = f->get_16();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
uint16_t CPFileAccessWrapperImpl::get_word() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return f->get_16();
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
uint32_t CPFileAccessWrapperImpl::get_dword() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return f->get_32();
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void CPFileAccessWrapperImpl::set_endian_conversion(bool p_swap) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
f->set_endian_swap(p_swap);
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
bool CPFileAccessWrapperImpl::is_open() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
return f != NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
CPFileAccessWrapperImpl::Error CPFileAccessWrapperImpl::get_error() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
return (f->get_error() != ::OK) ? ERROR_READING_FILE : OK;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void CPFileAccessWrapperImpl::store_byte(uint8_t p_dest) {
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
void CPFileAccessWrapperImpl::store_byte_array(const uint8_t *p_dest, int p_elements) {
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void CPFileAccessWrapperImpl::store_word(uint16_t p_dest) {
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
void CPFileAccessWrapperImpl::store_dword(uint32_t p_dest) {
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////
|
|
|
|
|
|
|
|
Error EventStreamPlaybackChibi::_play() {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
last_order = 0;
|
|
|
|
loops = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
player->play_start_song();
|
2017-03-18 23:36:26 +00:00
|
|
|
total_usec = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool EventStreamPlaybackChibi::_update(AudioMixer *p_mixer, uint64_t p_usec) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
total_usec += p_usec;
|
|
|
|
mixer.process_usecs(p_usec, volume, pitch_scale, tempo_scale);
|
|
|
|
int order = player->get_current_order();
|
|
|
|
if (order < last_order) {
|
2016-06-20 17:43:20 +00:00
|
|
|
if (!loop) {
|
|
|
|
stop();
|
|
|
|
} else {
|
|
|
|
loops++;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
last_order = order;
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
void EventStreamPlaybackChibi::_stop() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
player->play_stop();
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void EventStreamPlaybackChibi::set_paused(bool p_paused) {
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
bool EventStreamPlaybackChibi::is_paused() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
void EventStreamPlaybackChibi::set_loop(bool p_loop) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
loop = p_loop;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
bool EventStreamPlaybackChibi::is_loop_enabled() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return loop;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int EventStreamPlaybackChibi::get_loop_count() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
//return player->is
|
|
|
|
return loops;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
float EventStreamPlaybackChibi::get_pos() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
return double(total_usec) / 1000000.0;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
void EventStreamPlaybackChibi::seek_pos(float p_time) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
WARN_PRINT("seek_pos unimplemented.");
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventStreamPlaybackChibi::set_volume(float p_volume) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
volume = p_volume;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
float EventStreamPlaybackChibi::get_volume() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return volume;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventStreamPlaybackChibi::set_pitch_scale(float p_pitch_scale) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
pitch_scale = p_pitch_scale;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
float EventStreamPlaybackChibi::get_pitch_scale() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return pitch_scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventStreamPlaybackChibi::set_tempo_scale(float p_tempo_scale) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
tempo_scale = p_tempo_scale;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
float EventStreamPlaybackChibi::get_tempo_scale() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return tempo_scale;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void EventStreamPlaybackChibi::set_channel_volume(int p_channel, float p_volume) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_channel >= 64)
|
2014-09-17 23:03:10 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
player->set_channel_global_volume(p_channel, p_volume * 256);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
float EventStreamPlaybackChibi::get_channel_volume(int p_channel) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
return player->get_channel_global_volume(p_channel) / 256.0;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float EventStreamPlaybackChibi::get_last_note_time(int p_channel) const {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
double v = (player->get_channel_last_note_time_usec(p_channel)) / 1000000.0;
|
|
|
|
if (v < 0)
|
|
|
|
v = -1;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2017-12-11 14:31:49 +00:00
|
|
|
EventStreamPlaybackChibi::EventStreamPlaybackChibi(Ref<EventStreamChibi> p_stream) :
|
|
|
|
mixer(_get_mixer()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
stream = p_stream;
|
|
|
|
player = memnew(CPPlayer(&mixer, &p_stream->song));
|
|
|
|
loop = false;
|
|
|
|
last_order = 0;
|
|
|
|
loops = 0;
|
|
|
|
volume = 1.0;
|
|
|
|
pitch_scale = 1.0;
|
|
|
|
tempo_scale = 1.0;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
EventStreamPlaybackChibi::~EventStreamPlaybackChibi() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
player->play_stop();
|
|
|
|
memdelete(player);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
Ref<EventStreamPlayback> EventStreamChibi::instance_playback() {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
return Ref<EventStreamPlayback>(memnew(EventStreamPlaybackChibi(Ref<EventStreamChibi>(this))));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String EventStreamChibi::get_stream_name() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return song.get_name();
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
float EventStreamChibi::get_length() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
EventStreamChibi::EventStreamChibi() {
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
RES ResourceFormatLoaderChibi::load(const String &p_path, const String &p_original_path, Error *r_error) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-08-23 23:15:56 +00:00
|
|
|
if (r_error)
|
2017-03-18 23:36:26 +00:00
|
|
|
*r_error = ERR_FILE_CANT_OPEN;
|
2014-02-10 01:10:30 +00:00
|
|
|
String el = p_path.extension().to_lower();
|
|
|
|
|
|
|
|
CPFileAccessWrapperImpl f;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (el == "it") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Ref<EventStreamChibi> esc(memnew(EventStreamChibi));
|
2014-02-10 01:10:30 +00:00
|
|
|
CPLoader_IT loader(&f);
|
2017-03-18 23:36:26 +00:00
|
|
|
CPLoader::Error err = loader.load_song(p_path.utf8().get_data(), &esc->song, false);
|
|
|
|
ERR_FAIL_COND_V(err != CPLoader::FILE_OK, RES());
|
2015-08-23 23:15:56 +00:00
|
|
|
if (r_error)
|
2017-03-18 23:36:26 +00:00
|
|
|
*r_error = OK;
|
2014-09-17 23:03:10 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
return esc;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (el == "xm") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Ref<EventStreamChibi> esc(memnew(EventStreamChibi));
|
2014-02-10 01:10:30 +00:00
|
|
|
CPLoader_XM loader(&f);
|
2017-03-18 23:36:26 +00:00
|
|
|
CPLoader::Error err = loader.load_song(p_path.utf8().get_data(), &esc->song, false);
|
|
|
|
ERR_FAIL_COND_V(err != CPLoader::FILE_OK, RES());
|
2015-08-23 23:15:56 +00:00
|
|
|
if (r_error)
|
2017-03-18 23:36:26 +00:00
|
|
|
*r_error = OK;
|
2014-02-10 01:10:30 +00:00
|
|
|
return esc;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (el == "s3m") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Ref<EventStreamChibi> esc(memnew(EventStreamChibi));
|
2014-02-10 01:10:30 +00:00
|
|
|
CPLoader_S3M loader(&f);
|
2017-03-18 23:36:26 +00:00
|
|
|
CPLoader::Error err = loader.load_song(p_path.utf8().get_data(), &esc->song, false);
|
|
|
|
ERR_FAIL_COND_V(err != CPLoader::FILE_OK, RES());
|
2015-08-23 23:15:56 +00:00
|
|
|
if (r_error)
|
2017-03-18 23:36:26 +00:00
|
|
|
*r_error = OK;
|
2015-08-23 23:15:56 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
return esc;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (el == "mod") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Ref<EventStreamChibi> esc(memnew(EventStreamChibi));
|
2014-02-10 01:10:30 +00:00
|
|
|
CPLoader_MOD loader(&f);
|
2017-03-18 23:36:26 +00:00
|
|
|
CPLoader::Error err = loader.load_song(p_path.utf8().get_data(), &esc->song, false);
|
|
|
|
ERR_FAIL_COND_V(err != CPLoader::FILE_OK, RES());
|
2015-08-23 23:15:56 +00:00
|
|
|
if (r_error)
|
2017-03-18 23:36:26 +00:00
|
|
|
*r_error = OK;
|
2014-02-10 01:10:30 +00:00
|
|
|
return esc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return RES();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResourceFormatLoaderChibi::get_recognized_extensions(List<String> *p_extensions) const {
|
|
|
|
|
|
|
|
p_extensions->push_back("it");
|
|
|
|
p_extensions->push_back("xm");
|
|
|
|
p_extensions->push_back("s3m");
|
|
|
|
p_extensions->push_back("mod");
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
bool ResourceFormatLoaderChibi::handles_type(const String &p_type) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
return (p_type == "EventStreamChibi" || p_type == "EventStream");
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String ResourceFormatLoaderChibi::get_resource_type(const String &p_path) const {
|
|
|
|
String el = p_path.extension().to_lower();
|
2017-03-18 23:36:26 +00:00
|
|
|
if (el == "it" || el == "s3m" || el == "xm" || el == "mod")
|
2014-02-10 01:10:30 +00:00
|
|
|
return "EventStreamChibi";
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
void initialize_chibi() {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
sample_manager = memnew(CPSampleManagerImpl);
|
|
|
|
resource_loader = memnew(ResourceFormatLoaderChibi);
|
2014-02-10 01:10:30 +00:00
|
|
|
ObjectTypeDB::register_type<EventStreamChibi>();
|
2017-03-18 23:36:26 +00:00
|
|
|
ResourceLoader::add_resource_format_loader(resource_loader);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void finalize_chibi() {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
memdelete(sample_manager);
|
|
|
|
memdelete(resource_loader);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|