2019-04-11 14:40:54 +08:00
|
|
|
|
// Copyright (c) 2016-2018 Kiwano - Nomango
|
2019-03-31 01:37:06 +08:00
|
|
|
|
//
|
|
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
|
|
//
|
|
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
|
|
//
|
|
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
|
// THE SOFTWARE.
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
2019-11-13 14:33:15 +08:00
|
|
|
|
#include <kiwano/core/ObjectBase.h>
|
|
|
|
|
|
#include <kiwano/core/Resource.h>
|
2019-12-31 10:37:29 +08:00
|
|
|
|
#include <kiwano/platform/win32/ComPtr.hpp>
|
2019-10-11 21:55:29 +08:00
|
|
|
|
#include <kiwano-audio/Transcoder.h>
|
2019-11-13 11:22:21 +08:00
|
|
|
|
#include <xaudio2.h>
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-04-11 14:40:54 +08:00
|
|
|
|
namespace kiwano
|
2019-03-31 01:37:06 +08:00
|
|
|
|
{
|
2019-07-30 10:46:01 +08:00
|
|
|
|
namespace audio
|
2019-03-31 01:37:06 +08:00
|
|
|
|
{
|
2019-12-31 10:37:29 +08:00
|
|
|
|
class AudioEngine;
|
|
|
|
|
|
|
2019-07-30 10:46:01 +08:00
|
|
|
|
KGE_DECLARE_SMART_PTR(Sound);
|
|
|
|
|
|
|
2019-12-31 10:37:29 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* \addtogroup Audio
|
|
|
|
|
|
* @{
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* \~chinese
|
|
|
|
|
|
* @brief <EFBFBD><EFBFBD>Ƶ
|
|
|
|
|
|
*/
|
2019-07-30 10:46:01 +08:00
|
|
|
|
class KGE_API Sound
|
2020-01-09 08:45:00 +08:00
|
|
|
|
: public virtual ObjectBase
|
2019-03-31 01:37:06 +08:00
|
|
|
|
{
|
2019-12-31 10:37:29 +08:00
|
|
|
|
friend class AudioEngine;
|
|
|
|
|
|
|
2019-07-30 10:46:01 +08:00
|
|
|
|
public:
|
|
|
|
|
|
Sound();
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-07-30 10:46:01 +08:00
|
|
|
|
virtual ~Sound();
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-12-31 10:37:29 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><EFBFBD><F2BFAAB1><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD>ļ<EFBFBD>
|
|
|
|
|
|
/// @param res <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD>ļ<EFBFBD>·<EFBFBD><C2B7>
|
|
|
|
|
|
bool Load(String const& file_path);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5>Դ
|
|
|
|
|
|
/// @param res <20><>Ƶ<EFBFBD><C6B5>Դ
|
|
|
|
|
|
bool Load(Resource const& res);
|
2019-08-18 17:49:13 +08:00
|
|
|
|
|
2019-12-31 10:37:29 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20>Ƿ<EFBFBD><C7B7><EFBFBD>Ч
|
|
|
|
|
|
bool IsValid() const;
|
2019-07-30 10:46:01 +08:00
|
|
|
|
|
2019-12-31 10:37:29 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD>
|
|
|
|
|
|
/// @param loop_count <20><><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> -1 Ϊѭ<CEAA><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
void Play(int loop_count = 0);
|
2019-07-30 10:46:01 +08:00
|
|
|
|
|
2019-12-31 10:37:29 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ͣ
|
2019-07-30 10:46:01 +08:00
|
|
|
|
void Pause();
|
|
|
|
|
|
|
2019-12-31 10:37:29 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD>
|
2019-07-30 10:46:01 +08:00
|
|
|
|
void Resume();
|
|
|
|
|
|
|
2019-12-31 10:37:29 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief ֹͣ
|
2019-07-30 10:46:01 +08:00
|
|
|
|
void Stop();
|
|
|
|
|
|
|
2019-12-31 10:37:29 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20>رղ<D8B1><D5B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ
|
2019-07-30 10:46:01 +08:00
|
|
|
|
void Close();
|
|
|
|
|
|
|
2019-12-31 10:37:29 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD>
|
2019-07-30 10:46:01 +08:00
|
|
|
|
bool IsPlaying() const;
|
|
|
|
|
|
|
2019-12-31 10:37:29 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
2019-09-29 22:23:13 +08:00
|
|
|
|
float GetVolume() const;
|
2019-07-30 10:46:01 +08:00
|
|
|
|
|
2019-12-31 10:37:29 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
/// @param volume <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1>1.0 Ϊԭʼ<D4AD><CABC><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD> 1 Ϊ<>Ŵ<EFBFBD><C5B4><EFBFBD><EFBFBD><EFBFBD>, 0 Ϊ<><CEAA>С<EFBFBD><D0A1><EFBFBD><EFBFBD>
|
|
|
|
|
|
void SetVolume(float volume);
|
2019-07-30 10:46:01 +08:00
|
|
|
|
|
2019-12-23 18:05:08 +08:00
|
|
|
|
private:
|
2019-12-31 10:37:29 +08:00
|
|
|
|
IXAudio2SourceVoice* GetXAudio2Voice() const;
|
|
|
|
|
|
|
|
|
|
|
|
void SetXAudio2Voice(IXAudio2SourceVoice* voice);
|
2019-09-10 11:50:19 +08:00
|
|
|
|
|
2019-12-31 10:37:29 +08:00
|
|
|
|
private:
|
|
|
|
|
|
bool opened_;
|
|
|
|
|
|
bool playing_;
|
|
|
|
|
|
Transcoder transcoder_;
|
2019-08-19 09:28:59 +08:00
|
|
|
|
IXAudio2SourceVoice* voice_;
|
2019-03-31 01:37:06 +08:00
|
|
|
|
};
|
2019-12-31 10:37:29 +08:00
|
|
|
|
|
|
|
|
|
|
/** @} */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline IXAudio2SourceVoice* Sound::GetXAudio2Voice() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return voice_;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void Sound::SetXAudio2Voice(IXAudio2SourceVoice* voice)
|
|
|
|
|
|
{
|
|
|
|
|
|
voice_ = voice;
|
|
|
|
|
|
}
|
2019-03-31 01:37:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|