| 261 | //----------------------------------------------------------------------------- |
| 262 | |
| 263 | U32 SFXVoice::getPosition() const |
| 264 | { |
| 265 | // When stopped, always return 0. |
| 266 | |
| 267 | if( getStatus() == SFXStatusStopped ) |
| 268 | return 0; |
| 269 | |
| 270 | // It depends on the device if and when it will return a count of the total samples |
| 271 | // played so far. With streaming buffers, all devices will do that. With non-streaming |
| 272 | // buffers, some may do for looping voices thus returning a number that exceeds the actual |
| 273 | // source stream size. So, clamp things into range here and also take care of any offsetting |
| 274 | // resulting from a setPosition() call. |
| 275 | |
| 276 | U32 pos = _tell() + mOffset; |
| 277 | const U32 numStreamSamples = mBuffer->getFormat().getSampleCount( mBuffer->getDuration() ); |
| 278 | |
| 279 | if( mBuffer->mIsLooping ) |
| 280 | pos %= numStreamSamples; |
| 281 | else if( pos > numStreamSamples ) |
| 282 | { |
| 283 | // Ensure we never report out-of-range positions even if the device does. |
| 284 | |
| 285 | pos = numStreamSamples; |
| 286 | } |
| 287 | |
| 288 | return pos; |
| 289 | } |
| 290 | |
| 291 | //----------------------------------------------------------------------------- |
| 292 |
no test coverage detected