Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

SoundManager.h

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 // Lamp : Open source game middleware
00003 // Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
00004 //
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 //------------------------------------------------------------------------------
00019 
00020 /** @file
00021  * サウンドマネージャヘッダ
00022  * @author Junpee
00023  */
00024 
00025 #ifndef SOUND_MANAGER_H_
00026 #define SOUND_MANAGER_H_
00027 
00028 #include <Core/Container/Deque.h>
00029 #include <Core/InputOutput/FilePath.h>
00030 #include <Sound/System/Sound.h>
00031 #include <Sound/System/SoundDefinition.h>
00032 
00033 namespace Lamp{
00034 
00035 class SoundReader;
00036 
00037 //------------------------------------------------------------------------------
00038 /**
00039  * サウンドマネージャ
00040  */
00041 class SoundManager{
00042 friend class LampSound;
00043 friend class SoundBuffer;
00044 friend class StaticSound;
00045 friend class StaticSound3D;
00046 public:
00047     //--------------------------------------------------------------------------
00048     /// 3Dサウンドアルゴリズム
00049     enum Algorithm{
00050         /// 通常の3Dサウンドアルゴリズム
00051         algorithmNormal,
00052         /// 軽量HRTF3Dサウンドアルゴリズム
00053         algorithmLightHRTF,
00054         /// フルHRTF3Dサウンドアルゴリズム
00055         algorithmFullHRTF,
00056     };
00057 
00058     //--------------------------------------------------------------------------
00059     // サウンド操作
00060     //--------------------------------------------------------------------------
00061     /**
00062      * サウンドの破棄
00063      * @param sound 破棄するサウンド
00064      */
00065     virtual void destroy(Sound* sound);
00066 
00067     /**
00068      * 全サウンドの破棄
00069      */
00070     virtual void destroyAll();
00071 
00072     /**
00073      * サウンド数の取得
00074      * @return サウンド数
00075      */
00076     virtual int getCount() const{ return sounds_.getCount(); }
00077 
00078     /**
00079      * サウンドの取得
00080      * @param index サウンドのインデックス
00081      * @return サウンド
00082      */
00083     virtual Sound* getSound(int index){ return sounds_[index]; }
00084 
00085     //--------------------------------------------------------------------------
00086     /**
00087      * 3Dアルゴリズムの設定
00088      *
00089      * 設定後に生成した3Dサウンドに対してアルゴリズムが適用されます。
00090      * @param algorithm 3Dアルゴリズム
00091      */
00092     virtual void set3DAlgorithm(Algorithm algorithm){ algorithm_ = algorithm; }
00093 
00094     /**
00095      * 3Dアルゴリズムの取得
00096      * @return 3Dアルゴリズム
00097      */
00098     virtual Algorithm get3DAlgorithm() const{ return algorithm_; }
00099 
00100     //--------------------------------------------------------------------------
00101     // 静的サウンド
00102     //--------------------------------------------------------------------------
00103     /**
00104      * 静的サウンドの作成
00105      * @param size バッファサイズ
00106      * @param sample サンプル数
00107      * @param channel チャンネル数
00108      * @param bit ビット数
00109      * @param focus フォーカス
00110      * @return 静的サウンド
00111      */
00112     virtual StaticSound* createStaticSound(
00113         u_int size, int sample, int channel, int bit,
00114         Sound::Focus focus = (Sound::Focus)SoundDefinition::defaultFocus);
00115 
00116     /**
00117      * 静的サウンドの作成
00118      * @param fileName ファイル名
00119      * @param focus フォーカス
00120      * @return 静的サウンド。失敗したらNULLを返す。
00121      */
00122     virtual StaticSound* createStaticSound(const String& fileName,
00123         Sound::Focus focus = (Sound::Focus)SoundDefinition::defaultFocus);
00124 
00125     //--------------------------------------------------------------------------
00126     // ストリームサウンド
00127     //--------------------------------------------------------------------------
00128     /**
00129      * ストリームサウンドの作成
00130      * @param size バッファサイズ
00131      * @param sample サンプル数
00132      * @param channel チャンネル数
00133      * @param bit ビット数
00134      * @param focus フォーカス
00135      * @return ストリームサウンド
00136      */
00137     virtual StreamSound* createStreamSound(
00138         u_int size, int sample, int channel, int bit,
00139         Sound::Focus focus = (Sound::Focus)SoundDefinition::defaultFocus);
00140 
00141     /**
00142      * ストリームサウンドの作成
00143      * @param fileName ファイル名
00144      * @param focus フォーカス
00145      * @return ストリームサウンド。失敗したらNULLを返す。
00146      */
00147     virtual StreamSound* createStreamSound(const String& fileName,
00148         Sound::Focus focus = (Sound::Focus)SoundDefinition::defaultFocus);
00149 
00150     //--------------------------------------------------------------------------
00151     // 静的3Dサウンド
00152     //--------------------------------------------------------------------------
00153     /**
00154      * 静的3Dサウンドの作成
00155      * @param size バッファサイズ
00156      * @param sample サンプル数
00157      * @param channel チャンネル数
00158      * @param bit ビット数
00159      * @param focus フォーカス
00160      * @return 静的3Dサウンド
00161      */
00162     virtual StaticSound3D* createStaticSound3D(
00163         u_int size, int sample, int channel, int bit,
00164         Sound::Focus focus = (Sound::Focus)SoundDefinition::defaultFocus);
00165 
00166     /**
00167      * 静的3Dサウンドの作成
00168      * @param fileName ファイル名
00169      * @param focus フォーカス
00170      * @return 静的3Dサウンド。失敗したらNULLを返す。
00171      */
00172     virtual StaticSound3D* createStaticSound3D(const String& fileName,
00173         Sound::Focus focus = (Sound::Focus)SoundDefinition::defaultFocus);
00174 
00175     //--------------------------------------------------------------------------
00176     // ストリーム3Dサウンド
00177     //--------------------------------------------------------------------------
00178     /**
00179      * ストリーム3Dサウンドの作成
00180      * @param size バッファサイズ
00181      * @param sample サンプル数
00182      * @param channel チャンネル数
00183      * @param bit ビット数
00184      * @param focus フォーカス
00185      * @return ストリーム3Dサウンド
00186      */
00187     virtual StreamSound3D* createStreamSound3D(
00188         u_int size, int sample, int channel, int bit,
00189         Sound::Focus focus = (Sound::Focus)SoundDefinition::defaultFocus);
00190 
00191     /**
00192      * ストリーム3Dサウンドの作成
00193      * @param fileName ファイル名
00194      * @param focus フォーカス
00195      * @return ストリーム3Dサウンド。失敗したらNULLを返す。
00196      */
00197     virtual StreamSound3D* createStreamSound3D(const String& fileName,
00198         Sound::Focus focus = (Sound::Focus)SoundDefinition::defaultFocus);
00199 
00200 private:
00201     //--------------------------------------------------------------------------
00202     /**
00203      * コンストラクタ
00204      * @param directSound DirectSound
00205      */
00206     SoundManager(DirectSound* directSound);
00207 
00208     /**
00209      * デストラクタ
00210      */
00211     virtual ~SoundManager();
00212 
00213     //--------------------------------------------------------------------------
00214     // 静的サウンド
00215     //--------------------------------------------------------------------------
00216     /**
00217      * 静的サウンドの作成
00218      * @param soundReader サウンドリーダ
00219      * @param name 名前
00220      * @param focus フォーカス
00221      * @return 静的サウンド。失敗したらNULLを返す。
00222      */
00223     virtual StaticSound* createStaticSound(
00224         SoundReader* soundReader, const String& name,
00225         Sound::Focus focus = (Sound::Focus)SoundDefinition::defaultFocus);
00226 
00227     /**
00228      * 静的サウンドの複製
00229      * @param staticSound 静的サウンド
00230      * @return 静的サウンド
00231      */
00232     virtual StaticSound* cloneStaticSound(StaticSound* staticSound);
00233 
00234     //--------------------------------------------------------------------------
00235     // ストリームサウンド
00236     //--------------------------------------------------------------------------
00237     /**
00238      * ストリームサウンドの作成
00239      * @param soundReader サウンドリーダ、ストリームサウンドによりdeleteされます。
00240      * @param name 名前
00241      * @param focus フォーカス
00242      * @return ストリームサウンド。失敗したらNULLを返す。
00243      */
00244     virtual StreamSound* createStreamSound(
00245         SoundReader* soundReader, const String& name,
00246         Sound::Focus focus = (Sound::Focus)SoundDefinition::defaultFocus);
00247 
00248     //--------------------------------------------------------------------------
00249     // 静的3Dサウンド
00250     //--------------------------------------------------------------------------
00251     /**
00252      * 静的3Dサウンドの作成
00253      * @param soundReader サウンドリーダ
00254      * @param name 名前
00255      * @param focus フォーカス
00256      * @return 静的3Dサウンド。失敗したらNULLを返す。
00257      */
00258     virtual StaticSound3D* createStaticSound3D(
00259         SoundReader* soundReader, const String& name,
00260         Sound::Focus focus = (Sound::Focus)SoundDefinition::defaultFocus);
00261 
00262     /**
00263      * 静的3Dサウンドの複製
00264      * @param staticSound3D 静的3Dサウンド
00265      * @return 静的3Dサウンド
00266      */
00267     virtual StaticSound3D* cloneStaticSound3D(StaticSound3D* staticSound3D);
00268 
00269     //--------------------------------------------------------------------------
00270     // ストリーム3Dサウンド
00271     //--------------------------------------------------------------------------
00272     /**
00273      * ストリーム3Dサウンドの作成
00274      * @param soundReader サウンドリーダ、ストリーム3Dサウンドによりdeleteされます。
00275      * @param name 名前
00276      * @param focus フォーカス
00277      * @return ストリーム3Dサウンド。失敗したらNULLを返す。
00278      */
00279     virtual StreamSound3D* createStreamSound3D(
00280         SoundReader* soundReader, const String& name,
00281         Sound::Focus focus = (Sound::Focus)SoundDefinition::defaultFocus);
00282 
00283     //--------------------------------------------------------------------------
00284     // サウンドバッファ
00285     //--------------------------------------------------------------------------
00286     /**
00287      * ウェーブフォーマットの構築
00288      * @param waveFormat ウェーブフォーマットへのポインタ
00289      * @param samples サンプル数
00290      * @param channels チャンネル数
00291      * @param bit ビット数
00292      */
00293     virtual void buildWaveFormat(
00294         WAVEFORMATEX* waveFormat, int sample, int channel, int bit);
00295 
00296     /**
00297      * バッファ記述の構築
00298      * @param description バッファ記述
00299      * @param waveFormat ウェーブフォーマットへのポインタ
00300      * @param size バッファサイズ
00301      * @param focus フォーカス
00302      */
00303     virtual void buildBufferDescription(DSBUFFERDESC* description,
00304         WAVEFORMATEX* waveFormat, int size, Sound::Focus focus);
00305 
00306     /**
00307      * サウンドバッファの構築
00308      * @param description バッファ記述
00309      * @return サウンドバッファ
00310      */
00311     virtual DirectSoundBuffer* buildSoundBuffer(DSBUFFERDESC* description);
00312 
00313     /**
00314      * サウンドリーダの作成
00315      * @param filePath ファイルパス
00316      * @return サウンドリーダ
00317      */
00318     virtual SoundReader* createSoundReader(const FilePath& filePath);
00319 
00320     /**
00321      * サウンドバッファの読み込み
00322      * @param soundBuffer サウンドバッファ
00323      * @param soundReader サウンドリーダ
00324      * @return 成功すればtrue
00325      */
00326     virtual bool readSoundBuffer(SoundBuffer* sound, SoundReader* soundReader);
00327 
00328     /**
00329      * サウンドバッファの複製
00330      * @param soundBuffer 複製元サウンドバッファ
00331      * @return 複製されたサウンドバッファ
00332      */
00333     virtual DirectSoundBuffer* duplicateSoundBuffer(
00334         DirectSoundBuffer* soundBuffer);
00335 
00336     //--------------------------------------------------------------------------
00337     // アップデート
00338     //--------------------------------------------------------------------------
00339     /**
00340      * アップデート
00341      */
00342     virtual void update();
00343 
00344     /**
00345      * アップデートサウンドの追加
00346      * @param sound 追加するアップデートサウンド
00347      */
00348     virtual void addUpdateSound(Sound* sound);
00349 
00350     /**
00351      * アップデートサウンドの削除
00352      * @param sound 削除するアップデートサウンド
00353      */
00354     virtual void removeUpdateSound(Sound* sound);
00355 
00356     //--------------------------------------------------------------------------
00357     // コピーコンストラクタの隠蔽
00358     SoundManager(const SoundManager& copy);
00359 
00360     // 代入コピーの隠蔽
00361     void operator =(const SoundManager& copy);
00362 
00363     //--------------------------------------------------------------------------
00364     // DirectSound
00365     DirectSound* directSound_;
00366     // サウンド配列
00367     Deque<Sound*> sounds_;
00368     // アップデートサウンド配列
00369     Deque<Sound*> updateSounds_;
00370     // 3Dアルゴリズム
00371     Algorithm algorithm_;
00372 
00373 };
00374 
00375 //------------------------------------------------------------------------------
00376 } // End of namespace Lamp
00377 #endif // End of SOUND_MANAGER_H_
00378 //------------------------------------------------------------------------------

Generated on Wed Mar 16 10:29:36 2005 for Lamp by doxygen 1.3.2