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