// // Copyright (c) 2008-2017 the Urho3D project. // // 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 "../Precompiled.h" #include "../Audio/Audio.h" #include "../Audio/AudioEvents.h" #include "../Audio/Sound.h" #include "../Audio/SoundSource.h" #include "../Audio/SoundStream.h" #include "../Core/Context.h" #include "../IO/Log.h" #include "../Resource/ResourceCache.h" #include "../Scene/Node.h" #include "../Scene/ReplicationState.h" #include "../DebugNew.h" namespace Atomic { #define INC_POS_LOOPED() \ pos += intAdd; \ fractPos += fractAdd; \ if (fractPos > 65535) \ { \ fractPos &= 65535; \ ++pos; \ } \ while (pos >= end) \ pos -= (end - repeat); \ #define INC_POS_ONESHOT() \ pos += intAdd; \ fractPos += fractAdd; \ if (fractPos > 65535) \ { \ fractPos &= 65535; \ ++pos; \ } \ if (pos >= end) \ { \ pos = 0; \ break; \ } \ #define INC_POS_STEREO_LOOPED() \ pos += (intAdd << 1); \ fractPos += fractAdd; \ if (fractPos > 65535) \ { \ fractPos &= 65535; \ pos += 2; \ } \ while (pos >= end) \ pos -= (end - repeat); \ #define INC_POS_STEREO_ONESHOT() \ pos += (intAdd << 1); \ fractPos += fractAdd; \ if (fractPos > 65535) \ { \ fractPos &= 65535; \ pos += 2; \ } \ if (pos >= end) \ { \ pos = 0; \ break; \ } \ #define GET_IP_SAMPLE() (((((int)pos[1] - (int)pos[0]) * fractPos) / 65536) + (int)pos[0]) #define GET_IP_SAMPLE_LEFT() (((((int)pos[2] - (int)pos[0]) * fractPos) / 65536) + (int)pos[0]) #define GET_IP_SAMPLE_RIGHT() (((((int)pos[3] - (int)pos[1]) * fractPos) / 65536) + (int)pos[1]) static const int STREAM_SAFETY_SAMPLES = 4; extern const char* AUDIO_CATEGORY; extern const char* autoRemoveModeNames[]; SoundSource::SoundSource(Context* context) : Component(context), soundType_(SOUND_EFFECT), frequency_(0.0f), gain_(1.0f), attenuation_(1.0f), panning_(0.0f), sendFinishedEvent_(false), autoRemove_(REMOVE_DISABLED), position_(0), fractPosition_(0), timePosition_(0.0f), unusedStreamSize_(0) { audio_ = GetSubsystem