//////////////////////////////////////////////////////////////////////////////
//
// Asura_Chunk_ResourceFile_PSP_SoundData.h
//
// Copyright (c) 2005 Rebellion. All rights reserved.
//
// Description:
//
//     chunk for concatenated VAG sound data, with header information at the
//     end.
//
//////////////////////////////////////////////////////////////////////////////

// B E G I N   F I L E   W R A P P E R ///////////////////////////////////////

#ifdef ASURA_USE_PRAGMA_ONCE
    #pragma once
#endif

#ifndef ___ASURA_CHUNK_RESOURCEFILE_PSP_SOUNDDATA_H___
#define ___ASURA_CHUNK_RESOURCEFILE_PSP_SOUNDDATA_H___ 1

// I N C L U D E S ///////////////////////////////////////////////////////////

// independent
#include "ChunkSystem/Asura_Chunk_ResourceFile.h"
#ifdef ASURA_RESOURCEPACKER
#include "Core/Asura_String.h"
#endif

// PSP
#include "ChunkSystem/Asura_Chunk_ResourceFile_PSP.h"

// D E F I N E S /////////////////////////////////////////////////////////////

//
// Version history:
//
//     (MH - 24.10.2005) -  0 - Initial version. 
//
//
static const u_int uASURA_PSP_SOUNDDATA_CHUNK_VERSION = 0;

class Asura_Chunk_ResourceFile_PSP_SoundData : public Asura_Chunk_ResourceFile
{

	public:

        // T Y P E S /////////////////////////////////////////////////////////

        struct HdrEntry
        {
            int iSoundID;
            u_int uSampleRate;
            u_int uUnalignedSize;	// next sound is on following 64 byte boundary
        };

        // M E T H O D S /////////////////////////////////////////////////////

        bool Process( Asura_Handle iFile );

#ifdef ASURA_RESOURCEPACKER
		static u_int GetChunkHeaderSize(const Asura_String& xName)
		{
			return sizeof(Asura_Chunk_ResourceFile) + (xName.GetSizeInInts() * 4) + (3 * sizeof(int));
		}

		static void FillChunkHeaderData(char* pcData, const Asura_String& xName, u_int uSoundDataSize, u_int uNumEntries)
		{
			u_int uResourceFileSize = (3 * sizeof(int)) + uSoundDataSize + (sizeof(HdrEntry) * uNumEntries);

			Asura_Chunk_ResourceFile* pxRscFileHeader = reinterpret_cast<Asura_Chunk_ResourceFile*>(pcData);

			// resource file stuff first
			pxRscFileHeader->ID = ASURA_CHUNK_RESOURCEFILE;
			pxRscFileHeader->Size = sizeof(Asura_Chunk_ResourceFile) + (xName.GetSizeInInts() * 4) + uResourceFileSize;
			pxRscFileHeader->Version = 1;
			pxRscFileHeader->Flags = 0;

			pxRscFileHeader->Type  = ASURA_RESOURCEFILE_TYPE_PLATFORMSPECIFIC;
			pxRscFileHeader->SubType = ASURA_RESOURCEFILE_TYPE_PSP_SOUNDDATA;
			pxRscFileHeader->FileSize = uResourceFileSize;

			// then resource file name
			u_int* puData = reinterpret_cast<u_int*>(xName.IntCopy(reinterpret_cast<int*>(pxRscFileHeader + 1)));

			// version, data size, num entries
			*puData++ = uASURA_PSP_SOUNDDATA_CHUNK_VERSION;
			*puData++ = uSoundDataSize;
			*puData++ = uNumEntries;
		}
#endif

};


// E N D   F I L E   W R A P P E R ///////////////////////////////////////////

#endif // #ifndef ___ASURA_CHUNK_RESOURCEFILE_PSP_SOUNDDATA_H___
