1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: snd_StreamSoundFile.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_StreamSoundFile.h>
21 #include <nw/snd/snd_ElementType.h>
22
23 namespace nw {
24 namespace snd {
25 namespace internal {
26
27
28 //
29 // StreamSoundFile::FileHeader
30 //
31 const Util::ReferenceWithSize*
GetReferenceBy(u16 typeId) const32 StreamSoundFile::FileHeader::GetReferenceBy( u16 typeId ) const
33 {
34 for ( int i = 0; i < BLOCK_SIZE; i++ )
35 {
36 if ( toBlocks[ i ].typeId == typeId )
37 {
38 return &toBlocks[ i ];
39 }
40 }
41 return NULL;
42 }
43
GetInfoBlockSize() const44 u32 StreamSoundFile::FileHeader::GetInfoBlockSize() const
45 {
46 return GetReferenceBy( ElementType_StreamSoundFile_InfoBlock )->size;
47 }
GetSeekBlockSize() const48 u32 StreamSoundFile::FileHeader::GetSeekBlockSize() const
49 {
50 return GetReferenceBy( ElementType_StreamSoundFile_SeekBlock )->size;
51 }
GetDataBlockSize() const52 u32 StreamSoundFile::FileHeader::GetDataBlockSize() const
53 {
54 return GetReferenceBy( ElementType_StreamSoundFile_DataBlock )->size;
55 }
56
GetInfoBlockOffset() const57 u32 StreamSoundFile::FileHeader::GetInfoBlockOffset() const
58 {
59 return GetReferenceBy( ElementType_StreamSoundFile_InfoBlock )->offset;
60 }
GetSeekBlockOffset() const61 u32 StreamSoundFile::FileHeader::GetSeekBlockOffset() const
62 {
63 return GetReferenceBy( ElementType_StreamSoundFile_SeekBlock )->offset;
64 }
GetDataBlockOffset() const65 u32 StreamSoundFile::FileHeader::GetDataBlockOffset() const
66 {
67 return GetReferenceBy( ElementType_StreamSoundFile_DataBlock )->offset;
68 }
69
70
71 //
72 // StreamSoundFile::InfoBlockBody
73 //
74
75 const StreamSoundFile::StreamSoundInfo*
GetStreamSoundInfo() const76 StreamSoundFile::InfoBlockBody::GetStreamSoundInfo() const
77 {
78 if ( toStreamSoundInfo.typeId != ElementType_StreamSoundFile_StreamSoundInfo )
79 {
80 return NULL;
81 }
82 return static_cast<const StreamSoundInfo*>(
83 ut::AddOffsetToPtr( this, toStreamSoundInfo.offset ) );
84 }
85 const StreamSoundFile::TrackInfoTable*
GetTrackInfoTable() const86 StreamSoundFile::InfoBlockBody::GetTrackInfoTable() const
87 {
88 if ( toTrackInfoTable.typeId != ElementType_Table_ReferenceTable )
89 {
90 return NULL;
91 }
92 return static_cast<const TrackInfoTable*>(
93 ut::AddOffsetToPtr( this, toTrackInfoTable.offset ) );
94 }
95 const StreamSoundFile::ChannelInfoTable*
GetChannelInfoTable() const96 StreamSoundFile::InfoBlockBody::GetChannelInfoTable() const
97 {
98 if ( toChannelInfoTable.typeId != ElementType_Table_ReferenceTable )
99 {
100 return NULL;
101 }
102 return static_cast<const ChannelInfoTable*>(
103 ut::AddOffsetToPtr( this, toChannelInfoTable.offset ) );
104 }
105
106 //
107 // StreamSoundFile::TrackInfoTable
108 //
109 const StreamSoundFile::TrackInfo*
GetTrackInfo(u32 index) const110 StreamSoundFile::TrackInfoTable::GetTrackInfo( u32 index ) const
111 {
112 return static_cast<const TrackInfo*>(
113 table.GetReferedItem( index, ElementType_StreamSoundFile_TrackInfo ) );
114 }
115
116 //
117 // StreamSoundFile::ChannelInfoTable
118 //
119 const StreamSoundFile::ChannelInfo*
GetChannelInfo(u32 index) const120 StreamSoundFile::ChannelInfoTable::GetChannelInfo( u32 index ) const
121 {
122 NW_ASSERT( index < table.count );
123
124 return static_cast<const ChannelInfo*>(
125 table.GetReferedItem(
126 index,
127 ElementType_StreamSoundFile_ChannelInfo ) );
128 }
129
130 //
131 // StreamSoundFile::ChannlInfo
132 //
133 const StreamSoundFile::DspAdpcmChannelInfo*
GetDspAdpcmChannelInfo() const134 StreamSoundFile::ChannelInfo::GetDspAdpcmChannelInfo() const
135 {
136 if ( ! toDetailChannelInfo.IsValidTypeId( ElementType_Codec_DspAdpcmInfo ) )
137 {
138 return NULL;
139 }
140
141 return reinterpret_cast<const DspAdpcmChannelInfo*>(
142 ut::AddOffsetToPtr( this, toDetailChannelInfo.offset ) );
143 }
144
145 } // namespace nw::snd::internal
146 } // namespace nw::snd
147 } // namespace nw
148
149