1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     snd_SequenceSoundFileReader.cpp
4 
5   Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Revision: 13145 $
14  *---------------------------------------------------------------------------*/
15 
16 #include "precompiled.h"
17 
18 #include <nw/snd/snd_SequenceSoundFileReader.h>
19 
20 namespace nw {
21 namespace snd {
22 namespace internal {
23 
24 namespace
25 {
26 
27 const u32 SIGNATURE_DATA_BLOCK  = NW_UT_MAKE_SIGWORD( 'D', 'A', 'T', 'A' );
28 const u32 SIGNATURE_LABEL_BLOCK = NW_UT_MAKE_SIGWORD( 'L', 'A', 'B', 'L' );
29 
30 const u32 SUPPORTED_FILE_VERSION = 0x01000000;
31 const u32 CURRENT_FILE_VERSION   = 0x01000000;
32 
IsValidFileHeader(const void * sequenceFile)33 bool IsValidFileHeader( const void* sequenceFile )
34 {
35     const ut::BinaryFileHeader* header =
36         reinterpret_cast<const ut::BinaryFileHeader*>( sequenceFile );
37 
38     // シグニチャ確認
39     NW_ASSERTMSG( header->signature == SequenceSoundFileReader::SIGNATURE_FILE,
40             "invalid file signature. sequence file is not available." );
41     if ( header->signature != SequenceSoundFileReader::SIGNATURE_FILE )
42     {
43         return false;
44     }
45 
46     // バージョン確認
47     NW_ASSERTMSG( header->version >= SUPPORTED_FILE_VERSION,
48             "sequence file is not supported version.\n"
49             "please reconvert file using new version tools.\n"
50             "(SUPPORTED_FILE_VERSION:0x%08x >= your version:0x%08x)\n",
51             SUPPORTED_FILE_VERSION, header->version
52     );
53     if ( header->version < SUPPORTED_FILE_VERSION ) return false;
54 
55     NW_ASSERTMSG( header->version <= CURRENT_FILE_VERSION,
56             "sequence file is not supported version.\n"
57             "please reconvert file using new version tools.\n"
58             "(CURRENT_FILE_VERSION:0x%08x >= your version:0x%08x)\n",
59             CURRENT_FILE_VERSION, header->version
60     );
61     if ( header->version > CURRENT_FILE_VERSION ) return false;
62 
63     return true;
64 }
65 
66 } // anonymous namespace
67 
68 
SequenceSoundFileReader(const void * sequenceFile)69 SequenceSoundFileReader::SequenceSoundFileReader( const void* sequenceFile )
70 : m_pHeader( NULL ),
71   m_pDataBlockBody( NULL ),
72   m_pLabelBlockBody( NULL )
73 {
74     NW_NULL_ASSERT( sequenceFile );
75 
76     if ( ! IsValidFileHeader( sequenceFile ) ) return;
77 
78     m_pHeader = reinterpret_cast<const SequenceSoundFile::FileHeader*>( sequenceFile );
79 
80     const SequenceSoundFile::DataBlock* dataBlock = m_pHeader->GetDataBlock();
81     NW_NULL_ASSERT( dataBlock );
82     NW_ASSERT( dataBlock->header.kind == SIGNATURE_DATA_BLOCK );
83     m_pDataBlockBody = &dataBlock->body;
84 
85     const SequenceSoundFile::LabelBlock* labelBlock = m_pHeader->GetLabelBlock();
86     NW_NULL_ASSERT( labelBlock );
87     NW_ASSERT( labelBlock->header.kind == SIGNATURE_LABEL_BLOCK );
88     m_pLabelBlockBody = &labelBlock->body;
89 }
90 
GetSequenceData() const91 const void* SequenceSoundFileReader::GetSequenceData() const
92 {
93     NW_NULL_ASSERT( m_pDataBlockBody );
94     return m_pDataBlockBody->GetSequenceData();
95 }
96 
GetOffsetByLabel(const char * label,u32 * offsetPtr) const97 bool SequenceSoundFileReader::GetOffsetByLabel( const char* label, u32* offsetPtr ) const
98 {
99     NW_NULL_ASSERT( m_pLabelBlockBody );
100     return m_pLabelBlockBody->GetOffsetByLabel( label, offsetPtr );
101 }
102 
GetLabelByOffset(u32 offset) const103 const char* SequenceSoundFileReader::GetLabelByOffset( u32 offset ) const
104 {
105     NW_NULL_ASSERT( m_pLabelBlockBody );
106     return m_pLabelBlockBody->GetLabelByOffset( offset );
107 }
108 
109 } // namespace nw::snd::internal
110 } // namespace nw::snd
111 } // namespace nw
112 
113