Ejemplo n.º 1
0
	//-------------------------------------------------------------------------------------------------------
	//
	void dsound_audio_buffer::load(const audio_buffer_desc& desc, const dsound_ptr ds) {
		WAVEFORMATEX wfx={};
		build_wav_format_ex(&wfx, desc.waveFormat);

		DSBUFFERDESC bufferDesc = {};
		build_dsound_buffer_desc(&bufferDesc, wfx);

		//サウンドバッファの生成
		LPDIRECTSOUNDBUFFER primaryBuffer;
		HRESULT hr = ds->CreateSoundBuffer(&bufferDesc, &primaryBuffer, NULL);
		if (FAILED(hr)) {
			debug_out::trace("DirectSoundオーディオのプライマリバッファの作成に失敗しました。[%s:%d]", __FILE__, __LINE__);
			throw com_exception("DirectSoundオーディオのプライマリバッファの作成に失敗しました。", hr);
		}

		LPDIRECTSOUNDBUFFER8 soundBuffer;
		hr = primaryBuffer->QueryInterface(IID_IDirectSoundBuffer8 , (void**)&soundBuffer);
		if (FAILED(hr)) {
			debug_out::trace("DirectSoundオーディオのセカンダリバッファの作成に失敗しました。[%s:%d]", __FILE__, __LINE__);
			throw com_exception("DirectSoundオーディオのセカンダリバッファの作成に失敗しました。", hr);
		}

		//スマートポインタの管理下に置く
		soundBuffer_ = dsound_buffer_ptr(soundBuffer);
	}
Ejemplo n.º 2
0
	//-------------------------------------------------------------------------------------------------------
	//
	void dsound_audio_buffer::stop() {
		NYX_ASSERT(soundBuffer_ != nullptr);
		HRESULT hr = soundBuffer_->Stop();
		if (FAILED(hr)) {
			debug_out::trace("DirectSoundオーディオバッファを停止出来ませんでした。[%s:%d]", __FILE__, __LINE__);
			throw com_exception("DirectSoundオーディオバッファを停止出来ませんでした。", hr);
		}
	}
Ejemplo n.º 3
0
	//-------------------------------------------------------------------------------------------------------
	//
	void dsound_3d_audio_buffer::set_min_distance(float minDistance) {
		NYX_ASSERT(buffer_ != nullptr);
		HRESULT hr = buffer_->SetMinDistance(minDistance, NULL);
		if (FAILED(hr)) {
			debug_out::trace("音源の最小距離の設定に失敗しました。[%s,%d]",__FILE__, __LINE__);
			throw com_exception("音源の最小距離の設定に失敗しました。", hr);
		}
	}
Ejemplo n.º 4
0
	//-------------------------------------------------------------------------------------------------------
	//
	void dsound_3d_audio_buffer::set_position(const vector3f& pos) {
		NYX_ASSERT(buffer_ != nullptr);
		HRESULT hr = buffer_->SetPosition(pos.x, pos.y, pos.z, NULL);
		if (FAILED(hr)) {
			debug_out::trace("音源の位置の設定に失敗しました。[%s, %n]", __FILE__, __LINE__);
			throw com_exception("音源の位置の設定に失敗しました。", hr);
		}
	}
Ejemplo n.º 5
0
	//-------------------------------------------------------------------------------------------------------
	//
	void dsound_3d_audio_buffer::set_velocity(const vector3f& velocity) {
		NYX_ASSERT(buffer_ != nullptr);
		HRESULT hr = buffer_->SetVelocity(velocity.x, velocity.y, velocity.z, NULL);
		if (FAILED(hr)) {
			debug_out::trace("音源の速度の設定に失敗しました。[%s, %n]", __FILE__, __LINE__);
			throw com_exception("音源の速度の設定に失敗しました。", hr);
		}
	}
Ejemplo n.º 6
0
	//-------------------------------------------------------------------------------------------------------
	//
	void dsound_audio_buffer::play(bool isLoop) {
		NYX_ASSERT(soundBuffer_ != nullptr);
		isLoop_ = isLoop;
		HRESULT hr = soundBuffer_->Play(0, 0, isLoop_);
		if (FAILED(hr)) {
			debug_out::trace("DirectSoundオーディオバッファを再生出来ませんでした。[%s:%d]", __FILE__, __LINE__);
			throw com_exception("DirectSoundオーディオバッファを再生出来ませんでした。", hr);
		}
	}
Ejemplo n.º 7
0
	//-------------------------------------------------------------------------------------------------------
	//
	void dsound_audio_buffer::set_volume(long volume) {
		NYX_ASSERT(soundBuffer_ != nullptr);
		long decibel = volume_to_decibel(volume);
		HRESULT hr = soundBuffer_->SetVolume(decibel);
		if (FAILED(hr)) {
			debug_out::trace("DirectSoundオーディオバッファのデシベル値の設定に失敗しました。[%s:%d]", __FILE__, __LINE__);
			throw com_exception("DirectSoundオーディオバッファのデシベル値の設定に失敗しました。", hr);
		}
	}
Ejemplo n.º 8
0
	//-------------------------------------------------------------------------------------------------------
	//
	uint64_t dsound_audio_buffer::get_status() const {
		NYX_ASSERT(soundBuffer_ != nullptr);
		uint64_t status;
		HRESULT hr = soundBuffer_->GetStatus(&status);
		if (FAILED(hr)) {
			debug_out::trace("DirectSoundオーディオバッファのステータスコードを取得出来ませんでした。[%s:%d]", __FILE__, __LINE__);
			throw com_exception("DirectSoundオーディオバッファのステータスコードを取得出来ませんでした。", hr);
		}
		return status;
	}
Ejemplo n.º 9
0
	//-------------------------------------------------------------------------------------------------------
	//
	float dsound_3d_audio_buffer::get_max_distance() const {
		float distance;
		NYX_ASSERT(buffer_ != nullptr);
		HRESULT hr = buffer_->GetMaxDistance(&distance);
		if (FAILED(hr)) {
			debug_out::trace("音源の最大距離の取得に失敗しました。[%s, %d]",__FILE__, __LINE__);
			throw com_exception("音源の最大距離の取得に失敗しました。", hr);
		}
		return distance;
	}
Ejemplo n.º 10
0
	//-------------------------------------------------------------------------------------------------------
	//
	void dsound_audio_buffer::reset() {
		NYX_ASSERT(soundBuffer_ != nullptr);

		HRESULT hr = soundBuffer_->SetCurrentPosition(0);
		if (FAILED(hr)) {
			debug_out::trace("DirectSoundオーディオバッファの再生位置をリセット出来ませんでした。[%s:%d]", __FILE__, __LINE__);
			throw com_exception("DirectSoundオーディオバッファの再生位置をリセット出来ませんでした。", hr);
		}

	}
Ejemplo n.º 11
0
	//-------------------------------------------------------------------------------------------------------
	//
	vector3f dsound_3d_audio_buffer::get_velocity() const {
		NYX_ASSERT(buffer_ != nullptr);
		D3DXVECTOR3 velocity;
		HRESULT hr = buffer_->GetVelocity(&velocity);
		if (FAILED(hr)) {
			debug_out::trace("音源の速度の取得に失敗しました。[%s, %n]", __FILE__, __LINE__);
			throw com_exception("音源の速度の取得に失敗しました。", hr);
		}
		return vector3f(velocity.x, velocity.y, velocity.z);
	}
Ejemplo n.º 12
0
	//-------------------------------------------------------------------------------------------------------
	//
	vector3f dsound_3d_audio_buffer::get_position() const {
		NYX_ASSERT(buffer_ != nullptr);
		D3DXVECTOR3 pos;
		HRESULT hr = buffer_->GetPosition(&pos);
		if (FAILED(hr)) {
			debug_out::trace("音源の位置の取得に失敗しました。[%s,%n]", __FILE__, __LINE__);
			throw com_exception("音源の位置の取得に失敗しました。", hr);
		}
		return vector3f(pos.x, pos.y, pos.z);
	}
Ejemplo n.º 13
0
	//-------------------------------------------------------------------------------------------------------
	//
	long dsound_audio_buffer::get_volume() const {
		NYX_ASSERT(soundBuffer_ != nullptr);
		long decibel;
		HRESULT hr = soundBuffer_->GetVolume(&decibel);
		if (FAILED(hr)) {
			debug_out::trace("DirectSoundオーディオバッファのデシベル値の取得に失敗しました。[%s:%d]", __FILE__, __LINE__);
			throw com_exception("DirectSoundオーディオバッファのデシベル値の取得に失敗しました。", hr);
		}

		return decibel_to_volume(decibel);
	}
Ejemplo n.º 14
0
	//-------------------------------------------------------------------------------------------------------
	//
	void dsound_audio_buffer::resume() {
		NYX_ASSERT(soundBuffer_ != nullptr);
		//再生中なら処理しない
		auto state = get_audio_state();
		if (state.isPlaying) {
			return;
		} 
		if (state.isBufferLost) {
			HRESULT hr = soundBuffer_->Restore();
			if (FAILED(hr)) {
				debug_out::trace("DirectSoundオーディオバッファをレジューム出来ませんでした。[%s:%d]", __FILE__, __LINE__);
				throw com_exception("DirectSoundオーディオバッファをレジューム出来ませんでした。", hr);
			}
		}
		//レジュームする
		HRESULT hr = soundBuffer_->Play(0, 0, isLoop_);
		if (FAILED(hr)) {
			debug_out::trace("DirectSoundオーディオバッファをレジューム出来ませんでした。[%s:%d]", __FILE__, __LINE__);
			throw com_exception("DirectSoundオーディオバッファをレジューム出来ませんでした。", hr);
		}
	}
Ejemplo n.º 15
0
    /// Initialises an instance from another
    ///
    /// In the case of the <code>BSTR</code> type, this involves calling
    /// <code>SysAllocString()</code>
    ///
    /// \exception comstl::com_exception If exception support is enabled,
    ///   an instance of <code>comstl::com_exception</code> will be thrown
    ///   if the copy cannot be made
    static void copy(value_type* dest, value_type const* src)
    {
        *dest = ::SysAllocString(*src);

#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
        if( NULL == *dest &&
            NULL != *src &&
            L'\0' != (*src)[0])
        {
            throw com_exception("failed to copy BSTR", E_OUTOFMEMORY);
        }
#endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
    }
Ejemplo n.º 16
0
	//-------------------------------------------------------------------------------------------------------
	//
	void dsound_audio_buffer::reset_effect() {
		uint64_t status = get_status();
		if (status & DSBSTATUS_PLAYING) {
			stop();
		}

		HRESULT hr = soundBuffer_->SetFX(0, NULL, NULL);
		if (FAILED(hr)) {
			debug_out::trace("エフェクトのリセットに失敗しました。[%s:%d]", __FILE__, __LINE__);
			throw com_exception("エフェクトのリセットに失敗しました。", hr);
		}

		resume();
	}
Ejemplo n.º 17
0
	//-------------------------------------------------------------------------------------------------------
	//
	void  dsound_3d_audio_buffer::create_3d_buffer() {
		auto handle = get_handle();
		NYX_ASSERT(handle != nullptr);
		
		IDirectSound3DBuffer8* buffer;
		HRESULT hr = handle->QueryInterface(IID_IDirectSound3DBuffer8, reinterpret_cast<void**>(&buffer));
		if (FAILED(hr)) {
			debug_out::trace("IDirectSound3DBuffer8の取得に失敗しました。[%s,%d]",__FILE__, __LINE__);
			throw com_exception("IDirectSound3DBuffer8の取得に失敗しました。", hr);
		}

		//スマートポインタの管理下に置く
		buffer_ = buffer;
	}
Ejemplo n.º 18
0
	//-------------------------------------------------------------------------------------------------------
	//
	void dsound_audio_buffer::set_reverb_effect(const audio_effect_desc& effectDesc) {
		effectDesc;
		uint64_t status = get_status();
		if (status & DSBSTATUS_PLAYING) {
			stop();
		}

		uint64_t result;
		DSEFFECTDESC desc;
		ZeroMemory(&desc, sizeof(DSEFFECTDESC));
		desc.dwSize  = sizeof(DSEFFECTDESC);
		desc.dwFlags = NULL;
		desc.guidDSFXClass = GUID_DSFX_WAVES_REVERB;

		HRESULT hr = soundBuffer_->SetFX(1, &desc, &result);
		if (FAILED(hr)) {
			debug_out::trace("リバーブエフェクトの設定に失敗しました。[%s:%d]", __FILE__, __LINE__);
			throw com_exception("リバーブエフェクトの設定に失敗しました。", hr);
		}
		resume();
	}