//------------------------------------------------------------------------------
// Lamp : Open source game middleware
// Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//------------------------------------------------------------------------------

/** @file
 * ストリーム3Dサウンド実装
 * @author Junpee
 */

#include "LampBasic.h"
#include "Sound/3D/StreamSound3D.h"
#include "Sound/Reader/SoundReader.h"
#include "Sound/Utility/StreamPlayer.h"
#include "Sound/System/LampSound.h"
#include "Sound/System/SoundManager.h"

namespace Lamp{

//------------------------------------------------------------------------------
// コンストラクタ
StreamSound3D::StreamSound3D(DirectSoundBuffer* soundBuffer) :
	Sound3D(soundBuffer), soundReader_(NULL), streamPlayer_(NULL){
}
//------------------------------------------------------------------------------
// デストラクタ
StreamSound3D::~StreamSound3D(){
	SafeDelete(streamPlayer_);
	SafeDelete(soundReader_);
}
//------------------------------------------------------------------------------
// サウンドリーダの設定
void StreamSound3D::setSoundReader(SoundReader* soundReader){
	Assert(soundReader_ == NULL);
	soundReader_ = soundReader;
	Assert(soundReader_ != NULL);
	// 最低バッファ長のサウンドを必要とする
	Assert(getSize() >= (getBufferSize() / 2));
	// ストリームプレーヤ初期化
	streamPlayer_ = new StreamPlayer();
	streamPlayer_->initialize(this, soundReader_);
}
//------------------------------------------------------------------------------
// サイズの取得
u_int StreamSound3D::getSize() const{
	Assert(soundReader_ != NULL);
	return soundReader_->getSize();
}
//------------------------------------------------------------------------------
// 再生
//------------------------------------------------------------------------------
// 停止
void StreamSound3D::stop(){
	SoundBuffer::stop();
	// バッファの開始位置をずらしてストリームプレーヤをリセットする
	SoundBuffer::setCursor(0);
	streamPlayer_->reset();
}
//------------------------------------------------------------------------------
// 再生位置
//------------------------------------------------------------------------------
// 再生位置設定
void StreamSound3D::setCursor(u_int cursor){
	Assert(streamPlayer_ != NULL);
	streamPlayer_->setCursor(cursor);
}
//------------------------------------------------------------------------------
// 再生位置取得
u_int StreamSound3D::getCursor() const{
	Assert(streamPlayer_ != NULL);
	return streamPlayer_->getCursor();
}
//------------------------------------------------------------------------------
// ループ
//------------------------------------------------------------------------------
// ループ位置の設定
void StreamSound3D::setLoopCursor(u_int loopCursor){
	Assert(streamPlayer_ != NULL);
	streamPlayer_->setLoopCursor(loopCursor);
}
//------------------------------------------------------------------------------
// ループ位置の取得
u_int StreamSound3D::getLoopCursor() const{
	Assert(streamPlayer_ != NULL);
	return streamPlayer_->getLoopCursor();
}
//------------------------------------------------------------------------------
} // End of namespace Lamp
//------------------------------------------------------------------------------
