|
|
@@ -26,37 +26,37 @@ AudioSource::AudioSource(AudioBuffer* buffer, const SLObjectItf& player)
|
|
|
{
|
|
|
// Get the different interfaces for the OpenSL audio player that we need.
|
|
|
SLresult result = (*_playerObject)->GetInterface(_playerObject, SL_IID_3DDOPPLER, &_playerDoppler);
|
|
|
- if(result != SL_RESULT_SUCCESS)
|
|
|
+ if (result != SL_RESULT_SUCCESS)
|
|
|
{
|
|
|
WARN("AudioSource::AudioSource() - Failed to get 3D doppler interface for OpenSL audio player.");
|
|
|
}
|
|
|
|
|
|
result = (*_playerObject)->GetInterface(_playerObject, SL_IID_3DLOCATION, &_playerLocation);
|
|
|
- if(result != SL_RESULT_SUCCESS)
|
|
|
+ if (result != SL_RESULT_SUCCESS)
|
|
|
{
|
|
|
WARN("AudioSource::AudioSource() - Failed to get 3D location interface for OpenSL audio player.");
|
|
|
}
|
|
|
|
|
|
result = (*_playerObject)->GetInterface(_playerObject, SL_IID_PLAY, &_playerPlay);
|
|
|
- if(result != SL_RESULT_SUCCESS)
|
|
|
+ if (result != SL_RESULT_SUCCESS)
|
|
|
{
|
|
|
WARN("AudioSource::AudioSource() - Failed to get play interface for OpenSL audio player.");
|
|
|
}
|
|
|
|
|
|
result = (*_playerObject)->GetInterface(_playerObject, SL_IID_PITCH, &_playerPitch);
|
|
|
- if(result != SL_RESULT_SUCCESS)
|
|
|
+ if (result != SL_RESULT_SUCCESS)
|
|
|
{
|
|
|
WARN("AudioSource::AudioSource() - Failed to get rate pitch interface for OpenSL audio player.");
|
|
|
}
|
|
|
|
|
|
result = (*_playerObject)->GetInterface(_playerObject, SL_IID_SEEK, &_playerSeek);
|
|
|
- if(result != SL_RESULT_SUCCESS)
|
|
|
+ if (result != SL_RESULT_SUCCESS)
|
|
|
{
|
|
|
WARN("AudioSource::AudioSource() - Failed to get seek interface for OpenSL audio player.");
|
|
|
}
|
|
|
|
|
|
result = (*_playerObject)->GetInterface(_playerObject, SL_IID_VOLUME, &_playerVolume);
|
|
|
- if(result != SL_RESULT_SUCCESS)
|
|
|
+ if (result != SL_RESULT_SUCCESS)
|
|
|
{
|
|
|
WARN("AudioSource::AudioSource() - Failed to get volume interface for OpenSL audio player.");
|
|
|
}
|
|
|
@@ -159,7 +159,7 @@ AudioSource* AudioSource::create(const char* path)
|
|
|
}
|
|
|
|
|
|
result = (*player)->Realize(player, SL_BOOLEAN_FALSE);
|
|
|
- if(result != SL_RESULT_SUCCESS)
|
|
|
+ if (result != SL_RESULT_SUCCESS)
|
|
|
{
|
|
|
WARN("AudioSource::create - Failed to realize OpenSL audio player.");
|
|
|
}
|
|
|
@@ -454,6 +454,8 @@ void AudioSource::setNode(Node* node)
|
|
|
if (_node)
|
|
|
{
|
|
|
_node->addListener(this);
|
|
|
+ // Update the audio source position.
|
|
|
+ transformChanged(_node, 0);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -461,7 +463,8 @@ void AudioSource::setNode(Node* node)
|
|
|
void AudioSource::transformChanged(Transform* transform, long cookie)
|
|
|
{
|
|
|
#ifndef __ANDROID__
|
|
|
- alSourcefv(_alSource, AL_POSITION, (const ALfloat*)&transform->getTranslation());
|
|
|
+ if (_node)
|
|
|
+ alSourcefv(_alSource, AL_POSITION, (const ALfloat*)&_node->getTranslationWorld());
|
|
|
#else
|
|
|
if (_playerLocation)
|
|
|
{
|
|
|
@@ -478,4 +481,36 @@ void AudioSource::transformChanged(Transform* transform, long cookie)
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
+AudioSource* AudioSource::clone(CloneContext &context) const
|
|
|
+{
|
|
|
+#ifndef __ANDROID__
|
|
|
+ ALuint alSource = 0;
|
|
|
+ alGenSources(1, &alSource);
|
|
|
+ if (alGetError() != AL_NO_ERROR)
|
|
|
+ {
|
|
|
+ LOG_ERROR("AudioSource::createAudioSource - Error generating audio source.");
|
|
|
+ return NULL;
|
|
|
+ }
|
|
|
+ AudioSource* audioClone = new AudioSource(_buffer, alSource);
|
|
|
+#else
|
|
|
+ // TODO: Implement cloning audio source for Android
|
|
|
+ AudioSource* audioClone = new AudioSource(AudioBuffer* buffer, const SLObjectItf& player);
|
|
|
+
|
|
|
+#endif
|
|
|
+
|
|
|
+ audioClone->setLooped(isLooped());
|
|
|
+ audioClone->setGain(getGain());
|
|
|
+ audioClone->setPitch(getPitch());
|
|
|
+ audioClone->setVelocity(getVelocity());
|
|
|
+ if (Node* node = audioClone->getNode())
|
|
|
+ {
|
|
|
+ Node* clonedNode = context.findClonedNode(node);
|
|
|
+ if (clonedNode)
|
|
|
+ {
|
|
|
+ audioClone->setNode(clonedNode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return audioClone;
|
|
|
+}
|
|
|
+
|
|
|
}
|