1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: snd_StreamSoundFile.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_StreamSoundFile.h>
19 #include <nw/snd/snd_ElementType.h>
20
21 namespace nw {
22 namespace snd {
23 namespace internal {
24
25
26 //
27 // StreamSoundFile::FileHeader
28 //
29 const Util::ReferenceWithSize*
GetReferenceBy(u16 typeId) const30 StreamSoundFile::FileHeader::GetReferenceBy( u16 typeId ) const
31 {
32 for ( int i = 0; i < BLOCK_SIZE; i++ )
33 {
34 if ( toBlocks[ i ].typeId == typeId )
35 {
36 return &toBlocks[ i ];
37 }
38 }
39 return NULL;
40 }
41
GetInfoBlockSize() const42 u32 StreamSoundFile::FileHeader::GetInfoBlockSize() const
43 {
44 return GetReferenceBy( ElementType_StreamSoundFile_InfoBlock )->size;
45 }
GetSeekBlockSize() const46 u32 StreamSoundFile::FileHeader::GetSeekBlockSize() const
47 {
48 return GetReferenceBy( ElementType_StreamSoundFile_SeekBlock )->size;
49 }
GetDataBlockSize() const50 u32 StreamSoundFile::FileHeader::GetDataBlockSize() const
51 {
52 return GetReferenceBy( ElementType_StreamSoundFile_DataBlock )->size;
53 }
54
GetInfoBlockOffset() const55 u32 StreamSoundFile::FileHeader::GetInfoBlockOffset() const
56 {
57 return GetReferenceBy( ElementType_StreamSoundFile_InfoBlock )->offset;
58 }
GetSeekBlockOffset() const59 u32 StreamSoundFile::FileHeader::GetSeekBlockOffset() const
60 {
61 return GetReferenceBy( ElementType_StreamSoundFile_SeekBlock )->offset;
62 }
GetDataBlockOffset() const63 u32 StreamSoundFile::FileHeader::GetDataBlockOffset() const
64 {
65 return GetReferenceBy( ElementType_StreamSoundFile_DataBlock )->offset;
66 }
67
68
69 //
70 // StreamSoundFile::InfoBlockBody
71 //
72
73 const StreamSoundFile::StreamSoundInfo*
GetStreamSoundInfo() const74 StreamSoundFile::InfoBlockBody::GetStreamSoundInfo() const
75 {
76 if ( toStreamSoundInfo.typeId != ElementType_StreamSoundFile_StreamSoundInfo )
77 {
78 return NULL;
79 }
80 return static_cast<const StreamSoundInfo*>(
81 ut::AddOffsetToPtr( this, toStreamSoundInfo.offset ) );
82 }
83 const StreamSoundFile::TrackInfoTable*
GetTrackInfoTable() const84 StreamSoundFile::InfoBlockBody::GetTrackInfoTable() const
85 {
86 if ( toTrackInfoTable.typeId != ElementType_Table_ReferenceTable )
87 {
88 return NULL;
89 }
90 return static_cast<const TrackInfoTable*>(
91 ut::AddOffsetToPtr( this, toTrackInfoTable.offset ) );
92 }
93 const StreamSoundFile::ChannelInfoTable*
GetChannelInfoTable() const94 StreamSoundFile::InfoBlockBody::GetChannelInfoTable() const
95 {
96 if ( toChannelInfoTable.typeId != ElementType_Table_ReferenceTable )
97 {
98 return NULL;
99 }
100 return static_cast<const ChannelInfoTable*>(
101 ut::AddOffsetToPtr( this, toChannelInfoTable.offset ) );
102 }
103
104 //
105 // StreamSoundFile::TrackInfoTable
106 //
107 const StreamSoundFile::TrackInfo*
GetTrackInfo(u32 index) const108 StreamSoundFile::TrackInfoTable::GetTrackInfo( u32 index ) const
109 {
110 return static_cast<const TrackInfo*>(
111 table.GetReferedItem( index, ElementType_StreamSoundFile_TrackInfo ) );
112 }
113
114 //
115 // StreamSoundFile::ChannelInfoTable
116 //
117 const StreamSoundFile::ChannelInfo*
GetChannelInfo(u32 index) const118 StreamSoundFile::ChannelInfoTable::GetChannelInfo( u32 index ) const
119 {
120 NW_ASSERT( index < table.count );
121
122 return static_cast<const ChannelInfo*>(
123 table.GetReferedItem(
124 index,
125 ElementType_StreamSoundFile_ChannelInfo ) );
126 }
127
128 //
129 // StreamSoundFile::ChannlInfo
130 //
131 const StreamSoundFile::DspAdpcmChannelInfo*
GetDspAdpcmChannelInfo() const132 StreamSoundFile::ChannelInfo::GetDspAdpcmChannelInfo() const
133 {
134 if ( ! toDetailChannelInfo.IsValidTypeId( ElementType_Codec_DspAdpcmInfo ) )
135 {
136 return NULL;
137 }
138
139 return reinterpret_cast<const DspAdpcmChannelInfo*>(
140 ut::AddOffsetToPtr( this, toDetailChannelInfo.offset ) );
141 }
142
143 } // namespace nw::snd::internal
144 } // namespace nw::snd
145 } // namespace nw
146
147