1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: snd_WaveSoundFileReader.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: 32399 $
16 *---------------------------------------------------------------------------*/
17
18 #include "precompiled.h"
19 #include <nw/snd/snd_WaveSoundFileReader.h>
20
21 namespace nw {
22 namespace snd {
23 namespace internal {
24
25 namespace
26 {
27
28 const u32 SIGNATURE_INFO_BLOCK = NW_UT_MAKE_SIGWORD( 'I', 'N', 'F', 'O' );
29
30 const u32 SUPPORTED_FILE_VERSION = 0x01000000; // ライブラリがサポートする最低バージョン
31 const u32 CURRENT_FILE_VERSION = 0x01000000; // ライブラリがサポートする最新バージョン
32
IsValidFileHeader(const void * waveSoundFile)33 bool IsValidFileHeader( const void* waveSoundFile )
34 {
35 const ut::BinaryFileHeader& header =
36 *reinterpret_cast<const ut::BinaryFileHeader*>( waveSoundFile );
37
38 // シグニチャ確認
39 NW_ASSERTMSG( header.signature == WaveSoundFileReader::SIGNATURE_FILE,
40 "invalid file signature." );
41 if ( header.signature != WaveSoundFileReader::SIGNATURE_FILE )
42 {
43 return false;
44 }
45
46 // バージョン確認
47 NW_ASSERTMSG(
48 header.version >= SUPPORTED_FILE_VERSION,
49 "wavesound file is not supported version.\n"
50 "please reconvert file using new version tools.\n"
51 "(SUPPORTED_FILE_VERSION:0x%08x >= your version:0x%08x)\n",
52 SUPPORTED_FILE_VERSION, header.version
53 );
54 if ( header.version < SUPPORTED_FILE_VERSION )
55 {
56 return false;
57 }
58 NW_ASSERTMSG(
59 header.version <= CURRENT_FILE_VERSION,
60 "wavesound file is not supported version.\n"
61 "please reconvert file using new version tools.\n"
62 "(CURRENT_FILE_VERSION:0x%08x <= your version:0x%08x)\n",
63 CURRENT_FILE_VERSION, header.version
64 );
65 if ( header.version > CURRENT_FILE_VERSION )
66 {
67 return false;
68 }
69 return true;
70 }
71
72 } // anonymous namespace
73
WaveSoundFileReader(const void * waveSoundFile)74 WaveSoundFileReader::WaveSoundFileReader( const void* waveSoundFile )
75 : m_pHeader( NULL ),
76 m_pInfoBlockBody( NULL )
77 {
78 NW_NULL_ASSERT( waveSoundFile );
79
80 if ( ! IsValidFileHeader( waveSoundFile ) ) return;
81
82 m_pHeader = reinterpret_cast<const WaveSoundFile::FileHeader*>( waveSoundFile );
83
84 // INFO ブロックチェック
85 const WaveSoundFile::InfoBlock* infoBlock = m_pHeader->GetInfoBlock();
86
87 NW_NULL_ASSERT( infoBlock );
88 if ( infoBlock == NULL ) return;
89
90 // シグニチャチェック
91 NW_ASSERTMSG( infoBlock->header.kind == SIGNATURE_INFO_BLOCK, "invalid block signature." );
92 m_pInfoBlockBody = &infoBlock->body;
93 }
94
GetWaveSoundCount() const95 u32 WaveSoundFileReader::GetWaveSoundCount() const
96 {
97 NW_NULL_ASSERT( m_pInfoBlockBody );
98 return m_pInfoBlockBody->GetWaveSoundCount();
99 }
100
GetNoteInfoCount(u32 index) const101 u32 WaveSoundFileReader::GetNoteInfoCount( u32 index ) const
102 {
103 NW_NULL_ASSERT( m_pInfoBlockBody );
104 NW_ASSERT( index < GetWaveSoundCount() );
105
106 const WaveSoundFile::WaveSoundData& wsdData =
107 m_pInfoBlockBody->GetWaveSoundData( index );
108 return wsdData.GetNoteCount();
109 }
110
GetTrackInfoCount(u32 index) const111 u32 WaveSoundFileReader::GetTrackInfoCount( u32 index ) const
112 {
113 NW_NULL_ASSERT( m_pInfoBlockBody );
114 NW_ASSERT( index < GetWaveSoundCount() );
115
116 const WaveSoundFile::WaveSoundData& wsdData =
117 m_pInfoBlockBody->GetWaveSoundData( index );
118 return wsdData.GetTrackCount();
119 }
120
ReadWaveSoundInfo(WaveSoundInfo * dst,u32 index) const121 bool WaveSoundFileReader::ReadWaveSoundInfo( WaveSoundInfo* dst, u32 index ) const
122 {
123 NW_NULL_ASSERT( m_pInfoBlockBody );
124 NW_NULL_ASSERT( dst );
125
126 const WaveSoundFile::WaveSoundInfo& src =
127 m_pInfoBlockBody->GetWaveSoundData( index ).GetWaveSoundInfo();
128
129 dst->pitch = src.GetPitch();
130 dst->pan = src.GetPan();
131 dst->surroundPan = src.GetSurroundPan();
132 src.GetSendValue( &dst->mainSend, dst->fxSend, AUX_BUS_NUM );
133 dst->adshr = src.GetAdshrCurve();
134
135 return true;
136 }
137
ReadNoteInfo(WaveSoundNoteInfo * dst,u32 index,u32 noteIndex) const138 bool WaveSoundFileReader::ReadNoteInfo(
139 WaveSoundNoteInfo* dst,
140 u32 index,
141 u32 noteIndex ) const
142 {
143 NW_NULL_ASSERT( m_pInfoBlockBody );
144 NW_NULL_ASSERT( dst );
145
146 const WaveSoundFile::NoteInfo& src =
147 m_pInfoBlockBody->GetWaveSoundData( index ).GetNoteInfo( noteIndex );
148
149 const Util::WaveId* pWaveId =
150 m_pInfoBlockBody->GetWaveIdTable().GetWaveId( src.waveIdTableIndex );
151
152 if ( pWaveId == NULL )
153 {
154 return false;
155 }
156
157 dst->waveArchiveId = pWaveId->waveArchiveId;
158 dst->waveIndex = pWaveId->waveIndex;
159 dst->pitch = src.GetPitch();
160 dst->adshr = src.GetAdshrCurve();
161 dst->originalKey = src.GetOriginalKey();
162 dst->pan = src.GetPan();
163 dst->surroundPan = src.GetSurroundPan();
164 dst->volume = src.GetVolume();
165 return true;
166 }
167
168
169 } // namespace nw::snd::internal
170 } // namespace nw::snd
171 } // namespace nw
172