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

StereoSound.cpp

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 #include "LampBasic.h"
00026 #include "Sound/Stereo/StereoSound.h"
00027 
00028 namespace Lamp{
00029 
00030 //------------------------------------------------------------------------------
00031 // コンストラクタ
00032 StereoSound::StereoSound(DirectSoundBuffer* soundBuffer) :
00033     SoundBuffer(soundBuffer), pan_(0.f){
00034     // 初期データの取得
00035     long decibelPan;
00036     if(DirectXFailed(soundBuffer->GetPan(&decibelPan))){
00037         ErrorOut("StereoSound::StereoSound() パンの取得に失敗しました。");
00038     }
00039     int absDecibelPan = Math::abs(decibelPan);
00040     pan_ = 1.f - decibelToVolume(-absDecibelPan);
00041     if(decibelPan < 0.f){ pan_ = -pan_; }
00042 }
00043 //------------------------------------------------------------------------------
00044 // デストラクタ
00045 StereoSound::~StereoSound(){
00046 }
00047 //------------------------------------------------------------------------------
00048 // ステレオサウンドデータのコピー
00049 void StereoSound::copyStereoSoundData(StereoSound* destination){
00050     copySoundBufferData(destination);
00051 }
00052 //------------------------------------------------------------------------------
00053 // パンの設定
00054 void StereoSound::setPan(float pan){
00055     if(pan_ == pan){ return; }
00056     Assert(pan >= -1.f);
00057     Assert(pan <= 1.f);
00058     float absPan = Math::abs(pan);
00059     if(absPan <= 0.002f){// 0.002f以下はdbが0になる
00060         if(DirectXFailed(getSoundBuffer()->SetPan(DSBPAN_CENTER))){
00061             ErrorOut("StereoSound::setPan() パンの設定に失敗しました。");
00062         }
00063     }else{
00064         // Panは絶対値が0から1に近づく程、音量が下がる
00065         int db = volumeToDecibel(1.f - absPan);
00066         if(db == 0){ db = DSBPAN_LEFT; }
00067         Assert((db <= DSBPAN_CENTER) && (db >= DSBPAN_LEFT));
00068         if(pan > 0.f){ db = -db; }
00069         if(DirectXFailed(getSoundBuffer()->SetPan(db))){
00070             ErrorOut("StereoSound::setPan() パンの設定に失敗しました。");
00071         }
00072     }
00073     pan_ = pan;
00074 }
00075 //------------------------------------------------------------------------------
00076 // リセット
00077 void StereoSound::reset(Reset flags){
00078     SoundBuffer::reset(flags);
00079     if((flags & resetPan) != 0){ setPan(0.f); }
00080 }
00081 //------------------------------------------------------------------------------
00082 // 文字列への変換
00083 String StereoSound::toString() const{
00084     String result, temp;
00085     result = SoundBuffer::toString();
00086     temp.format("Pan(%.2f) BufferSize(%7dbyte)\n",
00087         getPan(), getBufferSize());
00088     result += temp;
00089     return result;
00090 }
00091 //------------------------------------------------------------------------------
00092 } // End of namespace Lamp
00093 //------------------------------------------------------------------------------

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