MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / _resetStream

Method _resetStream

Engine/source/sfx/sfxVoice.cpp:356–420  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

354//-----------------------------------------------------------------------------
355
356void SFXVoice::_resetStream( U32 sampleStartPos, bool triggerUpdate )
357{
358 AssertFatal( mBuffer->isStreaming(), "SFXVoice::_resetStream - Not a streaming voice!" );
359
360 ThreadSafeRef< SFXBuffer::AsyncState > oldState = mBuffer->mAsyncState;
361 AssertFatal( oldState != NULL,
362 "SFXVoice::_resetStream() - streaming buffer must have valid async state" );
363
364 #ifdef DEBUG_SPEW
365 Platform::outputDebugString( "[SFXVoice] Resetting stream to %i", sampleStartPos );
366 #endif
367
368 // Rather than messing up the async code by adding repositioning (which
369 // further complicates synchronizing the various parts), just construct
370 // a complete new AsyncState and discard the old one. The only problem
371 // here is the stateful sound streams. We can't issue a new packet as long
372 // as we aren't sure there's no request pending, so we just clone the stream
373 // and leave the old one to the old AsyncState.
374
375 ThreadSafeRef< SFXStream > sfxStream = oldState->mStream->getSourceStream()->clone();
376 if( sfxStream == NULL )
377 {
378 Con::errorf( "SFXVoice::_resetStream - could not clone SFXStream" );
379 return;
380 }
381
382 IPositionable< U32 >* sfxPositionable = dynamic_cast< IPositionable< U32 >* >( sfxStream.ptr() );
383 if( !sfxPositionable )
384 {
385 Con::errorf( "SFXVoice::_resetStream - could not seek in SFXStream" );
386 return;
387 }
388
389 sfxPositionable->setPosition( sampleStartPos * sfxStream->getFormat().getBytesPerSample() );
390
391 ThreadSafeRef< SFXInternal::SFXAsyncStream > newStream =
392 new SFXInternal::SFXAsyncStream
393 ( sfxStream,
394 true,
395 oldState->mStream->getPacketDuration() / 1000,
396 oldState->mStream->getReadAhead(),
397 oldState->mStream->isLooping() );
398 newStream->setReadSilenceAtEnd( oldState->mStream->getReadSilenceAtEnd() );
399
400 AssertFatal( newStream->getPacketSize() == oldState->mStream->getPacketSize(),
401 "SFXVoice::setPosition() - packet size mismatch with new stream" );
402
403 ThreadSafeRef< SFXBuffer::AsyncState > newState =
404 new SFXBuffer::AsyncState( newStream );
405 newStream->start();
406
407 // Switch the states.
408
409 mOffset = sampleStartPos;
410 mBuffer->mAsyncState = newState;
411
412 // Stop the old state from reading more data.
413

Callers

nothing calls this directly

Calls 15

TriggerUpdateFunction · 0.85
getBytesPerSampleMethod · 0.80
getPacketDurationMethod · 0.80
getReadAheadMethod · 0.80
setReadSilenceAtEndMethod · 0.80
getReadSilenceAtEndMethod · 0.80
getPacketSizeMethod · 0.80
errorfFunction · 0.50
isStreamingMethod · 0.45
cloneMethod · 0.45
ptrMethod · 0.45
setPositionMethod · 0.45

Tested by

no test coverage detected