// // Copyright (c) 2008-2013 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.h" #include "Context.h" #include "ResourceCache.h" #include "Sound.h" #include "SoundSource.h" #include #include "DebugNew.h" namespace Urho3D { #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 char* typeNames[] = { "Effect", "Ambient", "Voice", "Music", 0 }; static const float AUTOREMOVE_DELAY = 0.25f; extern const char* AUDIO_CATEGORY; SoundSource::SoundSource(Context* context) : Component(context), soundType_(SOUND_EFFECT), frequency_(0.0f), gain_(1.0f), attenuation_(1.0f), panning_(0.0f), autoRemoveTimer_(0.0f), autoRemove_(false), position_(0), fractPosition_(0), timePosition_(0.0f), decoder_(0), decodePosition_(0) { audio_ = GetSubsystem