KRAudioSource now using KRNodeProperty
This commit is contained in:
@@ -42,15 +42,15 @@ using namespace hydra;
|
|||||||
void KRAudioSource::InitNodeInfo(KrNodeInfo* nodeInfo)
|
void KRAudioSource::InitNodeInfo(KrNodeInfo* nodeInfo)
|
||||||
{
|
{
|
||||||
KRNode::InitNodeInfo(nodeInfo);
|
KRNode::InitNodeInfo(nodeInfo);
|
||||||
nodeInfo->audio_source.enable_obstruction = true;
|
nodeInfo->audio_source.enable_obstruction = decltype(m_enable_obstruction)::defaultVal;
|
||||||
nodeInfo->audio_source.enable_occlusion = true;
|
nodeInfo->audio_source.enable_occlusion = decltype(m_enable_occlusion)::defaultVal;
|
||||||
nodeInfo->audio_source.gain = 1.0f;
|
nodeInfo->audio_source.gain = decltype(m_gain)::defaultVal;
|
||||||
nodeInfo->audio_source.is_3d = true;
|
nodeInfo->audio_source.is_3d = true;
|
||||||
nodeInfo->audio_source.looping = false;
|
nodeInfo->audio_source.looping = decltype(m_looping)::defaultVal;
|
||||||
nodeInfo->audio_source.pitch = 1.0f;
|
nodeInfo->audio_source.pitch = decltype(m_pitch)::defaultVal;
|
||||||
nodeInfo->audio_source.reference_distance = 1.0f;
|
nodeInfo->audio_source.reference_distance = decltype(m_referenceDistance)::defaultVal;
|
||||||
nodeInfo->audio_source.reverb = 0.0f;
|
nodeInfo->audio_source.reverb = decltype(m_reverb)::defaultVal;
|
||||||
nodeInfo->audio_source.rolloff_factor = 2.0f;
|
nodeInfo->audio_source.rolloff_factor = decltype(m_rolloffFactor)::defaultVal;
|
||||||
nodeInfo->audio_source.sample = -1;
|
nodeInfo->audio_source.sample = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,17 +58,7 @@ KRAudioSource::KRAudioSource(KRScene& scene, std::string name) : KRNode(scene, n
|
|||||||
{
|
{
|
||||||
m_currentBufferFrame = 0;
|
m_currentBufferFrame = 0;
|
||||||
m_playing = false;
|
m_playing = false;
|
||||||
m_is3d = true;
|
|
||||||
m_isPrimed = false;
|
m_isPrimed = false;
|
||||||
m_gain = 1.0f;
|
|
||||||
m_pitch = 1.0f;
|
|
||||||
m_looping = false;
|
|
||||||
|
|
||||||
m_referenceDistance = 1.0f;
|
|
||||||
m_reverb = 0.0f;
|
|
||||||
m_rolloffFactor = 2.0f;
|
|
||||||
m_enable_occlusion = true;
|
|
||||||
m_enable_obstruction = true;
|
|
||||||
|
|
||||||
m_start_audio_frame = -1;
|
m_start_audio_frame = -1;
|
||||||
m_paused_audio_frame = 0;
|
m_paused_audio_frame = 0;
|
||||||
@@ -90,79 +80,31 @@ std::string KRAudioSource::getElementName()
|
|||||||
tinyxml2::XMLElement* KRAudioSource::saveXML(tinyxml2::XMLNode* parent)
|
tinyxml2::XMLElement* KRAudioSource::saveXML(tinyxml2::XMLNode* parent)
|
||||||
{
|
{
|
||||||
tinyxml2::XMLElement* e = KRNode::saveXML(parent);
|
tinyxml2::XMLElement* e = KRNode::saveXML(parent);
|
||||||
e->SetAttribute("sample", m_sample.getName().c_str());
|
m_sample.save(e);
|
||||||
e->SetAttribute("gain", m_gain);
|
m_gain.save(e);
|
||||||
e->SetAttribute("pitch", m_pitch);
|
m_pitch.save(e);
|
||||||
e->SetAttribute("looping", m_looping ? "true" : "false");
|
m_looping.save(e);
|
||||||
e->SetAttribute("is3d", m_is3d ? "true" : "false");
|
m_is3d.save(e);
|
||||||
e->SetAttribute("reference_distance", m_referenceDistance);
|
m_referenceDistance.save(e);
|
||||||
e->SetAttribute("reverb", m_reverb);
|
m_reverb.save(e);
|
||||||
e->SetAttribute("rolloff_factor", m_rolloffFactor);
|
m_rolloffFactor.save(e);
|
||||||
e->SetAttribute("enable_occlusion", m_enable_occlusion ? "true" : "false");
|
m_enable_occlusion.save(e);
|
||||||
e->SetAttribute("enable_obstruction", m_enable_obstruction ? "true" : "false");
|
m_enable_obstruction.save(e);
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRAudioSource::loadXML(tinyxml2::XMLElement* e)
|
void KRAudioSource::loadXML(tinyxml2::XMLElement* e)
|
||||||
{
|
{
|
||||||
const char* szAudioSampleName = e->Attribute("sample");
|
m_sample.load(e);
|
||||||
if (szAudioSampleName == nullptr) {
|
m_gain.load(e);
|
||||||
m_sample.clear();
|
m_pitch.load(e);
|
||||||
} else {
|
m_looping.load(e);
|
||||||
m_sample.set(szAudioSampleName);
|
m_is3d.load(e);
|
||||||
}
|
m_referenceDistance.load(e);
|
||||||
|
m_reverb.load(e);
|
||||||
float gain = 1.0f;
|
m_rolloffFactor.load(e);
|
||||||
if (e->QueryFloatAttribute("gain", &gain) != tinyxml2::XML_SUCCESS) {
|
m_enable_obstruction.load(e);
|
||||||
gain = 1.0f;
|
m_enable_occlusion.load(e);
|
||||||
}
|
|
||||||
setGain(gain);
|
|
||||||
|
|
||||||
float pitch = 1.0f;
|
|
||||||
if (e->QueryFloatAttribute("pitch", &pitch) != tinyxml2::XML_SUCCESS) {
|
|
||||||
pitch = 1.0f;
|
|
||||||
}
|
|
||||||
setPitch(m_pitch);
|
|
||||||
|
|
||||||
bool looping = false;
|
|
||||||
if (e->QueryBoolAttribute("looping", &looping) != tinyxml2::XML_SUCCESS) {
|
|
||||||
looping = false;
|
|
||||||
}
|
|
||||||
setLooping(looping);
|
|
||||||
|
|
||||||
bool is3d = true;
|
|
||||||
if (e->QueryBoolAttribute("is3d", &is3d) != tinyxml2::XML_SUCCESS) {
|
|
||||||
is3d = true;
|
|
||||||
}
|
|
||||||
setIs3D(is3d);
|
|
||||||
|
|
||||||
float reference_distance = 1.0f;
|
|
||||||
if (e->QueryFloatAttribute("reference_distance", &reference_distance) != tinyxml2::XML_SUCCESS) {
|
|
||||||
reference_distance = 1.0f;
|
|
||||||
}
|
|
||||||
setReferenceDistance(reference_distance);
|
|
||||||
|
|
||||||
float reverb = 0.0f;
|
|
||||||
if (e->QueryFloatAttribute("reverb", &reverb) != tinyxml2::XML_SUCCESS) {
|
|
||||||
reverb = 0.0f;
|
|
||||||
}
|
|
||||||
setReverb(reverb);
|
|
||||||
|
|
||||||
float rolloff_factor = 2.0f;
|
|
||||||
if (e->QueryFloatAttribute("rolloff_factor", &rolloff_factor) != tinyxml2::XML_SUCCESS) {
|
|
||||||
rolloff_factor = 2.0f;
|
|
||||||
}
|
|
||||||
setRolloffFactor(rolloff_factor);
|
|
||||||
|
|
||||||
m_enable_obstruction = true;
|
|
||||||
if (e->QueryBoolAttribute("enable_obstruction", &m_enable_obstruction) != tinyxml2::XML_SUCCESS) {
|
|
||||||
m_enable_obstruction = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_enable_occlusion = true;
|
|
||||||
if (e->QueryBoolAttribute("enable_occlusion", &m_enable_occlusion) != tinyxml2::XML_SUCCESS) {
|
|
||||||
m_enable_occlusion = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
KRNode::loadXML(e);
|
KRNode::loadXML(e);
|
||||||
}
|
}
|
||||||
@@ -170,8 +112,8 @@ void KRAudioSource::loadXML(tinyxml2::XMLElement* e)
|
|||||||
void KRAudioSource::prime()
|
void KRAudioSource::prime()
|
||||||
{
|
{
|
||||||
if (!m_isPrimed) {
|
if (!m_isPrimed) {
|
||||||
m_sample.bind(&getContext());
|
m_sample.val.bind(&getContext());
|
||||||
if (m_sample.isBound()) {
|
if (m_sample.val.isBound()) {
|
||||||
// Prime the buffer queue
|
// Prime the buffer queue
|
||||||
m_nextBufferIndex = 0;
|
m_nextBufferIndex = 0;
|
||||||
for (int i = 0; i < KRENGINE_AUDIO_BUFFERS_PER_SOURCE; i++) {
|
for (int i = 0; i < KRENGINE_AUDIO_BUFFERS_PER_SOURCE; i++) {
|
||||||
@@ -185,9 +127,9 @@ void KRAudioSource::prime()
|
|||||||
|
|
||||||
void KRAudioSource::queueBuffer()
|
void KRAudioSource::queueBuffer()
|
||||||
{
|
{
|
||||||
KRAudioBuffer* buffer = m_sample.get()->getBuffer(m_nextBufferIndex);
|
KRAudioBuffer* buffer = m_sample.val.get()->getBuffer(m_nextBufferIndex);
|
||||||
m_audioBuffers.push(buffer);
|
m_audioBuffers.push(buffer);
|
||||||
m_nextBufferIndex = (m_nextBufferIndex + 1) % m_sample.get()->getBufferCount();
|
m_nextBufferIndex = (m_nextBufferIndex + 1) % m_sample.val.get()->getBufferCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRAudioSource::render(RenderInfo& ri)
|
void KRAudioSource::render(RenderInfo& ri)
|
||||||
@@ -364,18 +306,18 @@ bool KRAudioSource::isPlaying()
|
|||||||
|
|
||||||
void KRAudioSource::setSample(const std::string& sound_name)
|
void KRAudioSource::setSample(const std::string& sound_name)
|
||||||
{
|
{
|
||||||
m_sample.set(sound_name);
|
m_sample.val.set(sound_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string KRAudioSource::getSample()
|
std::string KRAudioSource::getSample()
|
||||||
{
|
{
|
||||||
return m_sample.getName();
|
return m_sample.val.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
KRAudioSample* KRAudioSource::getAudioSample()
|
KRAudioSample* KRAudioSource::getAudioSample()
|
||||||
{
|
{
|
||||||
m_sample.bind(&getContext());
|
m_sample.val.bind(&getContext());
|
||||||
return m_sample.get();
|
return m_sample.val.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRAudioSource::advanceFrames(int frame_count)
|
void KRAudioSource::advanceFrames(int frame_count)
|
||||||
|
|||||||
@@ -133,24 +133,24 @@ private:
|
|||||||
int m_currentBufferFrame; // Siren Audio Engine frame number within current buffer
|
int m_currentBufferFrame; // Siren Audio Engine frame number within current buffer
|
||||||
void advanceBuffer();
|
void advanceBuffer();
|
||||||
|
|
||||||
KRAudioSampleBinding m_sample;
|
KRNODE_PROPERTY(KRAudioSampleBinding, m_sample, nullptr, "sample");
|
||||||
unsigned int m_sourceID;
|
KRNODE_PROPERTY(float, m_gain, 1.f, "gain");
|
||||||
float m_gain;
|
KRNODE_PROPERTY(float, m_pitch, 1.f, "pitch");
|
||||||
float m_pitch;
|
KRNODE_PROPERTY(bool, m_looping, false, "looping");
|
||||||
bool m_looping;
|
KRNODE_PROPERTY(bool, m_is3d, true, "is3d");
|
||||||
|
|
||||||
|
// 3d only properties:
|
||||||
|
KRNODE_PROPERTY(float, m_referenceDistance, 1.f, "reference_distance");
|
||||||
|
KRNODE_PROPERTY(float, m_reverb, 0.f, "reverb"); // 0.0 (dry) - 1.0 (wet) (0-100% dry/wet mix, 0.0 default)
|
||||||
|
KRNODE_PROPERTY(float, m_rolloffFactor, 2.f, "rolloff_factor");
|
||||||
|
KRNODE_PROPERTY(bool, m_enable_occlusion, true, "enable_occlusion");
|
||||||
|
KRNODE_PROPERTY(bool, m_enable_obstruction, true, "enable_obstruction");
|
||||||
|
|
||||||
std::queue<KRAudioBuffer*> m_audioBuffers;
|
std::queue<KRAudioBuffer*> m_audioBuffers;
|
||||||
int m_nextBufferIndex;
|
int m_nextBufferIndex;
|
||||||
bool m_playing;
|
bool m_playing;
|
||||||
bool m_is3d;
|
|
||||||
bool m_isPrimed;
|
bool m_isPrimed;
|
||||||
|
|
||||||
void prime();
|
void prime();
|
||||||
void queueBuffer();
|
void queueBuffer();
|
||||||
|
|
||||||
// 3d only properties:
|
|
||||||
float m_referenceDistance;
|
|
||||||
float m_reverb; // type ALfloat 0.0 (dry) - 1.0 (wet) (0-100% dry/wet mix, 0.0 default)
|
|
||||||
float m_rolloffFactor;
|
|
||||||
bool m_enable_occlusion;
|
|
||||||
bool m_enable_obstruction;
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user