#include "xaudiopacketaligned.h"

XAudioPacketAligned::XAudioPacketAligned()
    : XAsset()
    , mBuffer()
    , mBufferSize(0)
    , mLoopCount(0)
    , aXmaLoop()
    , mContext()
{
    SetName("Audio Packet Aligned");
}

XAudioPacketAligned::~XAudioPacketAligned()
{
    
}

void XAudioPacketAligned::ParseData(XDataStream *aStream)
{
    qint32 bufferPtr = aStream->ParseInt32(QString("%1 buffer ptr").arg(GetName()));
    mBufferSize = aStream->ParseUInt32(QString("%1 buffer size").arg(GetName()));
    mLoopCount = aStream->ParseUInt32(QString("%1 loop count").arg(GetName()));

    for (int i = 0; i < 6; i++)
    {
        XAudioXmaLoopRegion loop;
        loop.ParseData(aStream);
    }

    qint32 contextPtr = aStream->ParseInt32(QString("%1 context ptr").arg(GetName()));

    if (bufferPtr)
    {
        aStream->readRawData(mBuffer.data(), mBufferSize);
    }

    if (contextPtr)
    {
        mContext = aStream->ParseInt8(QString("%1 context").arg(GetName()));
    }
}

void XAudioPacketAligned::Clear()
{
    mBuffer.clear();
    mBufferSize = 0;
    mLoopCount = 0;
    aXmaLoop.clear();
    mContext = '\0';
}
