161 lines
3 KiB
C++
161 lines
3 KiB
C++
#include "Precompiled.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "RakiTests/Sounds/PCMDataProvider.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "RakiEngine/Data/Stream/AsyncReadStreamer.h"
|
|
#include "RakiEngine/Data/Stream/SeekableStream.h"
|
|
|
|
|
|
|
|
|
|
|
|
namespace raki
|
|
{
|
|
|
|
|
|
PCMDataProvider::PCMDataProvider( AsyncReadStreamer * _asyncReadStreamer, void * _clientData, const u64 bytesPerSample, const u32 _nbChannels, const bool _isLooping )
|
|
: SoundStreamDataProvider( _nbChannels )
|
|
, m_bytesPerSample( bytesPerSample )
|
|
, m_asyncReadStreamer( _asyncReadStreamer )
|
|
, m_clientData( _clientData )
|
|
, m_nextStream( NULL )
|
|
, m_nextClientData( NULL )
|
|
{
|
|
RAKI_ASSERT( m_asyncReadStreamer );
|
|
}
|
|
|
|
|
|
|
|
|
|
u64 PCMDataProvider::pullData( void * const _buffer, const u64 _sizeToRead )
|
|
{
|
|
RAKI_ASSERT( m_asyncReadStreamer );
|
|
|
|
return m_asyncReadStreamer->stream( _buffer, _sizeToRead );
|
|
}
|
|
|
|
|
|
u64 PCMDataProvider::getRemainingByteSize() const
|
|
{
|
|
if ( m_asyncReadStreamer )
|
|
{
|
|
u64 size = m_asyncReadStreamer->getSize();
|
|
u64 position = m_asyncReadStreamer->getCurrentPos();
|
|
|
|
RAKI_ASSERT( position <= size );
|
|
|
|
return ( size - position );
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
SoundStreamDataProvider * PCMDataProvider::getNextDataProvider()
|
|
{
|
|
if ( m_nextStream )
|
|
{
|
|
m_nextStream->m_stream->seekBeginning();
|
|
|
|
m_nextStream->m_isFirstBuffer = true;
|
|
|
|
return m_nextStream;
|
|
}
|
|
|
|
m_stream->seekBeginning();
|
|
|
|
m_isFirstBuffer = true;
|
|
|
|
return this;
|
|
}
|
|
*/
|
|
|
|
void PCMDataProvider::update( bool /*_launchNewReadRequests*/ )
|
|
{
|
|
}
|
|
|
|
|
|
void PCMDataProvider::prefetchNextStream()
|
|
{
|
|
if ( m_asyncReadStreamer && m_nextStream )
|
|
{
|
|
if ( m_nextStream )
|
|
m_nextStream->seek( 0, SeekableStream::fromBeginning );
|
|
|
|
m_asyncReadStreamer->setStreamData( NULL, 0, m_nextStream, m_nextClientData );
|
|
}
|
|
}
|
|
|
|
|
|
void PCMDataProvider::setNextStreamNow()
|
|
{
|
|
m_asyncReadStreamer->seekBeginning();
|
|
/*
|
|
if ( m_nextStream )
|
|
{
|
|
m_nextStream->seekBeginning();
|
|
|
|
m_stream = m_nextStream;
|
|
m_clientData = m_nextClientData;
|
|
|
|
m_nextStream = NULL;
|
|
m_nextClientData = NULL;
|
|
}
|
|
else
|
|
{
|
|
m_stream = NULL;
|
|
m_clientData = NULL;
|
|
}*/
|
|
}
|
|
|
|
|
|
u64 PCMDataProvider::getEntireSampleSize() const
|
|
{
|
|
return getEntireByteSize() / m_bytesPerSample;
|
|
}
|
|
|
|
|
|
u64 PCMDataProvider::getEntireByteSize() const
|
|
{
|
|
return m_asyncReadStreamer ? m_asyncReadStreamer->getSize() : 0;
|
|
}
|
|
|
|
|
|
void PCMDataProvider::setNextStream( SeekableStream * _nextStream, void * _nextClientData )
|
|
{
|
|
m_nextStream = _nextStream;
|
|
m_nextClientData = _nextClientData;
|
|
}
|
|
|
|
|
|
u64 PCMDataProvider::getCurrentSamplePosition() const
|
|
{
|
|
u64 position = m_asyncReadStreamer ? m_asyncReadStreamer->getCurrentPos() : 0;
|
|
|
|
return position / m_bytesPerSample;
|
|
}
|
|
|
|
|
|
const void * PCMDataProvider::getClientData() const
|
|
{
|
|
return m_clientData;
|
|
}
|
|
|
|
|
|
u64 PCMDataProvider::getByteBlockPosition( const u64 _startSamplePosition ) const
|
|
{
|
|
return _startSamplePosition * 2 * getNbChannels();
|
|
}
|
|
|
|
|
|
|
|
} // namespace raki
|
|
|