// Copyright (c) 2008-2023 the Urho3D project // License: MIT #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 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 += ((unsigned)intAdd << 1u); \ fractPos += fractAdd; \ if (fractPos > 65535) \ { \ fractPos &= 65535; \ pos += 2; \ } \ while (pos >= end) \ pos -= (end - repeat); \ #define INC_POS_STEREO_ONESHOT() \ pos += ((unsigned)intAdd << 1u); \ 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_(nullptr), fractPosition_(0), timePosition_(0.0f), unusedStreamSize_(0) { audio_ = GetSubsystem