| 117 | } |
| 118 | |
| 119 | void AudioSource::Play() |
| 120 | { |
| 121 | auto state = _state; |
| 122 | if (state == States::Playing) |
| 123 | return; |
| 124 | PROFILE_CPU(); |
| 125 | if (Clip == nullptr || Clip->WaitForLoaded()) |
| 126 | { |
| 127 | LOG(Warning, "Cannot play audio source without a clip ({0})", GetNamePath()); |
| 128 | return; |
| 129 | } |
| 130 | |
| 131 | if (SourceID == 0) |
| 132 | { |
| 133 | // Create audio source |
| 134 | SourceID = AudioBackend::Source::Add(Clip->Info(), GetPosition(), GetOrientation(), GetVolume(), GetPitch(), GetPan(), GetIsLooping() && !UseStreaming(), Is3D(), GetAttenuation(), GetMinDistance(), GetDopplerFactor()); |
| 135 | if (SourceID == 0) |
| 136 | { |
| 137 | LOG(Warning, "Cannot create audio source ({0})", GetNamePath()); |
| 138 | return; |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | _state = States::Playing; |
| 143 | _isActuallyPlayingSth = false; |
| 144 | |
| 145 | // Audio clips with disabled streaming are controlled by audio source, otherwise streaming manager will play it |
| 146 | if (Clip->IsStreamable()) |
| 147 | { |
| 148 | if (state == States::Paused) |
| 149 | { |
| 150 | // Resume |
| 151 | PlayInternal(); |
| 152 | } |
| 153 | else |
| 154 | { |
| 155 | // Request faster streaming update |
| 156 | Clip->RequestStreamingUpdate(); |
| 157 | |
| 158 | // If we are looping and streaming also update streaming buffers |
| 159 | if (_loop || state == States::Stopped) |
| 160 | RequestStreamingBuffersUpdate(); |
| 161 | } |
| 162 | } |
| 163 | else if (SourceID) |
| 164 | { |
| 165 | // Play it right away |
| 166 | AudioBackend::Source::SetNonStreamingBuffer(SourceID, Clip->Buffers[0]); |
| 167 | PlayInternal(); |
| 168 | } |
| 169 | else |
| 170 | { |
| 171 | // Source was not properly added to the Audio Backend |
| 172 | LOG(Warning, "Cannot play uninitialized audio source."); |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | void AudioSource::Pause() |
no test coverage detected