1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     snd_MemorySoundArchive.h
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:$
14  *---------------------------------------------------------------------------*/
15 
16 /**
17  * :include nw/snd/snd_MemorySoundArchive.h
18  *
19  * @file snd_MemorySoundArchive.h
20  */
21 
22 #ifndef NW_SND_MEMORY_SOUND_ARCHIVE_H_
23 #define NW_SND_MEMORY_SOUND_ARCHIVE_H_
24 
25 #include <nw/snd/snd_SoundArchiveFileReader.h>
26 #include <nw/io/io_FileStream.h>
27 
28 namespace nw {
29 namespace snd {
30 
31 //---------------------------------------------------------------------------
32 //! @brief        メモリ上にあるサウンドアーカイブを扱うクラスです。
33 //!
34 //!               MemorySoundArchive クラスでは、
35 //!               サウンドアーカイブから外部参照されているデータを扱うことができません。
36 //!               外部参照データの再生は必ず失敗します。
37 //!
38 //!               サウンドアーカイブ内に波形データ (波形アーカイブ) が含まれている場合、
39 //!               そのサウンドアーカイブはデバイスメモリ上にロードしておく必要があります。
40 //!
41 //! @date 2010/04/30 サウンドアーカイブをデバイスメモリ上にロードしておく必要がある旨、追記
42 //! @date 2010/01/15 初版
43 //---------------------------------------------------------------------------
44 class MemorySoundArchive : public SoundArchive
45 {
46   private:
47     class MemoryFileStream;
48 
49   public:
50     //----------------------------------------
51     //! @name コンストラクタ / デストラクタ
52     //@{
53     //! コンストラクタです。
54     MemorySoundArchive();
55     //! デストラクタです。
56     virtual ~MemorySoundArchive();
57     //@}
58 
59     //----------------------------------------
60     //! @name セットアップ
61     //@{
62 
63     //---------------------------------------------------------------------------
64     //! @brief    メモリ上のサウンドアーカイブデータを初期化します。
65     //!
66     //!           サウンドアーカイブ内に波形データ (波形アーカイブ) が含まれている場合、
67     //!           そのサウンドアーカイブはデバイスメモリ上にロードしておく必要があります。
68     //!
69     //! @param[in]    soundArchiveData    サウンドアーカイブデータのアドレス。
70     //!
71     //! @return 初期化に成功すれば true を、失敗すれば false を返します。
72     //!
73     //! @see Finalize
74     //!
75     //! @date 2010/11/15 返り値の記述が無かったので追記
76     //! @date 2010/04/30 サウンドアーカイブをデバイスメモリ上にロードしておく必要がある旨、追記
77     //! @date 2010/02/01 関数名変更 (Setup → Initialize)
78     //! @date 2010/01/15 初版
79     //---------------------------------------------------------------------------
80     bool Initialize( const void* soundArchiveData );
81 
82     //---------------------------------------------------------------------------
83     //! @brief    メモリ上のサウンドアーカイブデータを破棄します。
84     //!
85     //! @see Initialize
86     //!
87     //! @date 2010/02/01 関数名変更 (Shutdown → Finalize)
88     //! @date 2010/01/15 初版
89     //---------------------------------------------------------------------------
90     void Finalize();
91     //@}
92 
93     //! @details :private
94     virtual size_t detail_GetRequiredStreamBufferSize() const;
95 
96     //! @details :private
97     virtual const void* detail_GetFileAddress( FileId fileId ) const;
98 
99   protected:
100 
101     //! @details :private
102     virtual io::FileStream* OpenStream( void* buffer, int size, u32 begin, u32 length );
103 
104     //! @details :private
105     virtual io::FileStream* OpenExtStream(
106             void* buffer,
107             int size,
108             const char* extFilePath,
109             // const wchar_t* extFilePath,
110             u32 begin,
111             u32 length ) const;
112 
113   private:
114     const void* m_pData;
115     internal::SoundArchiveFileReader m_FileReader;
116 };
117 
118 //! @details :private
119 class MemorySoundArchive::MemoryFileStream : public io::FileStream
120 {
121   public:
122     MemoryFileStream( const void* buffer, u32 size );
123 
CanSeek()124     virtual bool CanSeek() const { return true; }
CanCancel()125     virtual bool CanCancel() const { return true; }
CanAsync()126     virtual bool CanAsync() const { return false; }
CanRead()127     virtual bool CanRead() const { return true; }
CanWrite()128     virtual bool CanWrite() const { return false; }
129 
130     virtual void Close();
131     virtual s32  Read( void* buf, u32 length );
132     virtual void Seek( s32 offset, u32 origin );
Tell()133     virtual u32  Tell()    const { return m_Position; }
GetSize()134     virtual u32  GetSize() const { return m_Size; }
135 
136   private:
137     const void* m_pBuffer;
138     u32 m_Size;
139     u32 m_Position;
140 };
141 
142 } // namespace nw::snd
143 } // namespace nw
144 
145 
146 #endif /* NW_SND_MEMORY_SOUND_ARCHIVE_H_ */
147 
148