Commit e430d8e5 authored by Pascal Palenda's avatar Pascal Palenda
Browse files

Add serialization helper for ITA classes - WIP

parent b21baa40
#include "serialization_helper.h"
// std includes
#include <cassert>
// ITA includes
#include <ITASampleFrame.h>
#include <ITASampleBuffer.h>
// Vista includes
#include <VistaAspects/VistaSerializer.h>
#include <VistaAspects/VistaDeSerializer.h>
int ITA::simulation_scheduler::room_acoustics::SerializationHelper::writeITASampleFrame ( IVistaSerializer& pSerializer,
const ITASampleFrame* pSampleFrame, const int iLength, const int iOffset )
{
int returnVal = 0;
assert ( iOffset >= 0 );
assert ( iLength >= 0 );
assert ( iLength + iOffset <= pSampleFrame->length ( ) );
const int iNumChannels = pSampleFrame->channels ( );
returnVal += pSerializer.WriteInt32 ( iNumChannels );
returnVal += pSerializer.WriteInt32 ( iLength );
for ( int i = 0; i < iNumChannels; i++ )
returnVal += writeITASampleBuffer ( pSerializer, &( *pSampleFrame ) [i], iLength, iOffset );
return returnVal;
}
int ITA::simulation_scheduler::room_acoustics::SerializationHelper::readITASampleFrame (
IVistaDeSerializer& pDeserializer, ITASampleFrame& pSampleFrame )
{
int returnVal = 0;
int iNumChannels;
returnVal += pDeserializer.ReadInt32 ( iNumChannels );
int iLength;
returnVal += pDeserializer.ReadInt32 ( iLength );
assert ( iNumChannels >= 0 );
assert ( iLength >= 0 );
pSampleFrame.init ( iNumChannels, iLength, false );
for ( int i = 0; i < iNumChannels; i++ )
returnVal += readITASampleBuffer ( pDeserializer, pSampleFrame [i] );
return returnVal;
}
int ITA::simulation_scheduler::room_acoustics::SerializationHelper::writeITASampleBuffer ( IVistaSerializer& pSerializer,
const ITASampleBuffer* pBuffer, const int iLength, const int iOffset )
{
int returnVal = 0;
assert ( iOffset >= 0 );
assert ( iLength >= 0 );
assert ( iLength + iOffset <= pBuffer->GetLength ( ) );
returnVal += pSerializer.WriteInt32 ( iLength );
for ( int i = 0; i < iLength; i++ )
returnVal += pSerializer.WriteFloat32 ( ( *pBuffer ) [i + iOffset] );
return returnVal;
}
int ITA::simulation_scheduler::room_acoustics::SerializationHelper::readITASampleBuffer (
IVistaDeSerializer& pDeserializer, ITASampleBuffer& pBuffer )
{
int returnVal = 0;
int iLength;
returnVal += pDeserializer.ReadInt32 ( iLength );
assert ( iLength >= 0 );
for ( int i = 0; i < iLength; i++ )
returnVal += pDeserializer.ReadFloat32 ( pBuffer [i] );
return returnVal;
}
#ifndef INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_ROOM_ACOUSTICS_SERIALIZATION_HELPER
#define INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_ROOM_ACOUSTICS_SERIALIZATION_HELPER
class ITASampleFrame;
class ITASampleBuffer;
class IVistaSerializer;
class IVistaDeSerializer;
namespace ITA
{
namespace simulation_scheduler
{
namespace room_acoustics
{
struct SerializationHelper
{
///
/// \brief Write an ITASampleFrame to the given IVistaSerializer.
/// \param pSerializer the IVistaSerializer to write to.
/// \param pSampleFrame pointer to the ITASampleFrame that shall be written.
/// \param iLength number of samples that shall be written.
/// \param iOffset number of samples that shall be skipped before the requested samples begin.
/// \return the number of bytes written or -1 on failure.
///
static int writeITASampleFrame ( IVistaSerializer& pSerializer, const ITASampleFrame* pSampleFrame, const int iLength, const int iOffset );
///
/// \brief Read an ITASampleFrame from the given IVistaDeSerializer.
/// \param pDeserializer the IVistaDeSerializer to read from.
/// \param pSampleFrame the ITASampleFrame to save into.
/// \return the number of bytes written or -1 on failure.
///
static int readITASampleFrame ( IVistaDeSerializer& pDeserializer, ITASampleFrame& pSampleFrame );
///
/// \brief Write an ITASampleFrame to the given IVistaSerializer.
/// \param pSerializer the IVistaSerializer to write to.
/// \param pBuffer pointer to the ITASampleBuffer that shall be written.
/// \param iLength number of samples that shall be written.
/// \param iOffset number of samples that shall be skipped before the requested samples begin.
/// \return the number of bytes written or -1 on failure.
///
static int writeITASampleBuffer ( IVistaSerializer& pSerializer, const ITASampleBuffer* pBuffer, const int iLength, const int iOffset );
///
/// \brief Read an ITASampleBuffer from the given IVistaDeSerializer.
/// \param pDeserializer the IVistaDeSerializer to read from.
/// \param pBuffer the ITASampleBuffer to save into.
/// \return the number of bytes written or -1 on failure.
///
static int readITASampleBuffer ( IVistaDeSerializer& pDeserializer, ITASampleBuffer& pBuffer );
};
} // namespace room_acoustics
} // namespace simulation_scheduler
} // namespace ITA
#endif // INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_ROOM_ACOUSTICS_SERIALIZATION_HELPER
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment