fix SoundPlayer
This commit is contained in:
parent
a4d4c3a10f
commit
2345e22792
|
|
@ -12,6 +12,7 @@
|
||||||
<ClInclude Include="..\src\kiwano\2d\Frame.h" />
|
<ClInclude Include="..\src\kiwano\2d\Frame.h" />
|
||||||
<ClInclude Include="..\src\kiwano\2d\GifSprite.h" />
|
<ClInclude Include="..\src\kiwano\2d\GifSprite.h" />
|
||||||
<ClInclude Include="..\src\kiwano\base\Director.h" />
|
<ClInclude Include="..\src\kiwano\base\Director.h" />
|
||||||
|
<ClInclude Include="..\src\kiwano\base\win32\ComPtr.hpp" />
|
||||||
<ClInclude Include="..\src\kiwano\core\basic_json.hpp" />
|
<ClInclude Include="..\src\kiwano\core\basic_json.hpp" />
|
||||||
<ClInclude Include="..\src\kiwano\core\function.hpp" />
|
<ClInclude Include="..\src\kiwano\core\function.hpp" />
|
||||||
<ClInclude Include="..\src\kiwano\core\core.h" />
|
<ClInclude Include="..\src\kiwano\core\core.h" />
|
||||||
|
|
@ -54,13 +55,13 @@
|
||||||
<ClInclude Include="..\src\kiwano\base\TimerManager.h" />
|
<ClInclude Include="..\src\kiwano\base\TimerManager.h" />
|
||||||
<ClInclude Include="..\src\kiwano\base\time.h" />
|
<ClInclude Include="..\src\kiwano\base\time.h" />
|
||||||
<ClInclude Include="..\src\kiwano\base\Window.h" />
|
<ClInclude Include="..\src\kiwano\base\Window.h" />
|
||||||
<ClInclude Include="..\src\kiwano\math\constants.hpp" />
|
<ClInclude Include="..\src\kiwano\math\constants.h" />
|
||||||
<ClInclude Include="..\src\kiwano\math\ease.hpp" />
|
<ClInclude Include="..\src\kiwano\math\ease.h" />
|
||||||
<ClInclude Include="..\src\kiwano\math\math.h" />
|
<ClInclude Include="..\src\kiwano\math\math.h" />
|
||||||
<ClInclude Include="..\src\kiwano\math\Matrix.hpp" />
|
<ClInclude Include="..\src\kiwano\math\Matrix.hpp" />
|
||||||
<ClInclude Include="..\src\kiwano\math\rand.h" />
|
<ClInclude Include="..\src\kiwano\math\rand.h" />
|
||||||
<ClInclude Include="..\src\kiwano\math\Rect.hpp" />
|
<ClInclude Include="..\src\kiwano\math\Rect.hpp" />
|
||||||
<ClInclude Include="..\src\kiwano\math\scalar.hpp" />
|
<ClInclude Include="..\src\kiwano\math\scalar.h" />
|
||||||
<ClInclude Include="..\src\kiwano\math\Vec2.hpp" />
|
<ClInclude Include="..\src\kiwano\math\Vec2.hpp" />
|
||||||
<ClInclude Include="..\src\kiwano\platform\Application.h" />
|
<ClInclude Include="..\src\kiwano\platform\Application.h" />
|
||||||
<ClInclude Include="..\src\kiwano\platform\modules.h" />
|
<ClInclude Include="..\src\kiwano\platform\modules.h" />
|
||||||
|
|
@ -77,7 +78,6 @@
|
||||||
<ClInclude Include="..\src\kiwano\renderer\Renderer.h" />
|
<ClInclude Include="..\src\kiwano\renderer\Renderer.h" />
|
||||||
<ClInclude Include="..\src\kiwano\renderer\RenderTarget.h" />
|
<ClInclude Include="..\src\kiwano\renderer\RenderTarget.h" />
|
||||||
<ClInclude Include="..\src\kiwano\renderer\TextLayout.h" />
|
<ClInclude Include="..\src\kiwano\renderer\TextLayout.h" />
|
||||||
<ClInclude Include="..\src\kiwano\renderer\win32\ComPtr.hpp" />
|
|
||||||
<ClInclude Include="..\src\kiwano\renderer\win32\D2DDeviceResources.h" />
|
<ClInclude Include="..\src\kiwano\renderer\win32\D2DDeviceResources.h" />
|
||||||
<ClInclude Include="..\src\kiwano\renderer\win32\D3D10DeviceResources.h" />
|
<ClInclude Include="..\src\kiwano\renderer\win32\D3D10DeviceResources.h" />
|
||||||
<ClInclude Include="..\src\kiwano\renderer\win32\D3D11DeviceResources.h" />
|
<ClInclude Include="..\src\kiwano\renderer\win32\D3D11DeviceResources.h" />
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,9 @@
|
||||||
<Filter Include="renderer\win32">
|
<Filter Include="renderer\win32">
|
||||||
<UniqueIdentifier>{30333461-e9bc-4709-84bd-ce6e0e1a3079}</UniqueIdentifier>
|
<UniqueIdentifier>{30333461-e9bc-4709-84bd-ce6e0e1a3079}</UniqueIdentifier>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
<Filter Include="base\win32">
|
||||||
|
<UniqueIdentifier>{192a47a9-9df6-4f40-a7d3-888eb00c53ac}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\src\kiwano\ui\Button.h">
|
<ClInclude Include="..\src\kiwano\ui\Button.h">
|
||||||
|
|
@ -93,12 +96,6 @@
|
||||||
<ClInclude Include="..\src\kiwano\base\time.h">
|
<ClInclude Include="..\src\kiwano\base\time.h">
|
||||||
<Filter>base</Filter>
|
<Filter>base</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\src\kiwano\math\constants.hpp">
|
|
||||||
<Filter>math</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\src\kiwano\math\ease.hpp">
|
|
||||||
<Filter>math</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\src\kiwano\math\Matrix.hpp">
|
<ClInclude Include="..\src\kiwano\math\Matrix.hpp">
|
||||||
<Filter>math</Filter>
|
<Filter>math</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
|
@ -108,9 +105,6 @@
|
||||||
<ClInclude Include="..\src\kiwano\math\Rect.hpp">
|
<ClInclude Include="..\src\kiwano\math\Rect.hpp">
|
||||||
<Filter>math</Filter>
|
<Filter>math</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\src\kiwano\math\scalar.hpp">
|
|
||||||
<Filter>math</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\src\kiwano\platform\Application.h">
|
<ClInclude Include="..\src\kiwano\platform\Application.h">
|
||||||
<Filter>platform</Filter>
|
<Filter>platform</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
|
@ -264,9 +258,6 @@
|
||||||
<ClInclude Include="..\src\kiwano\renderer\TextLayout.h">
|
<ClInclude Include="..\src\kiwano\renderer\TextLayout.h">
|
||||||
<Filter>renderer</Filter>
|
<Filter>renderer</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\src\kiwano\renderer\win32\ComPtr.hpp">
|
|
||||||
<Filter>renderer\win32</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\src\kiwano\renderer\win32\D2DDeviceResources.h">
|
<ClInclude Include="..\src\kiwano\renderer\win32\D2DDeviceResources.h">
|
||||||
<Filter>renderer\win32</Filter>
|
<Filter>renderer\win32</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
|
@ -309,6 +300,18 @@
|
||||||
<ClInclude Include="..\src\kiwano\renderer\Brush.h">
|
<ClInclude Include="..\src\kiwano\renderer\Brush.h">
|
||||||
<Filter>renderer</Filter>
|
<Filter>renderer</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\src\kiwano\math\constants.h">
|
||||||
|
<Filter>math</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\src\kiwano\math\ease.h">
|
||||||
|
<Filter>math</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\src\kiwano\math\scalar.h">
|
||||||
|
<Filter>math</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\src\kiwano\base\win32\ComPtr.hpp">
|
||||||
|
<Filter>base\win32</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\src\kiwano\ui\Button.cpp">
|
<ClCompile Include="..\src\kiwano\ui\Button.cpp">
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ namespace kiwano
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
hr = Audio::GetInstance()->CreateVoice(&voice_, transcoder_.GetBuffer().format);
|
hr = Audio::GetInstance()->CreateVoice(&voice_, transcoder_.GetBuffer());
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
{
|
{
|
||||||
Close();
|
Close();
|
||||||
|
|
@ -101,7 +101,7 @@ namespace kiwano
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
hr = Audio::GetInstance()->CreateVoice(&voice_, transcoder_.GetBuffer().format);
|
hr = Audio::GetInstance()->CreateVoice(&voice_, transcoder_.GetBuffer());
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
{
|
{
|
||||||
Close();
|
Close();
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,6 @@ namespace kiwano
|
||||||
{
|
{
|
||||||
KGE_DECLARE_SMART_PTR(Sound);
|
KGE_DECLARE_SMART_PTR(Sound);
|
||||||
|
|
||||||
// 音乐对象
|
|
||||||
class KGE_API Sound
|
class KGE_API Sound
|
||||||
: public ObjectBase
|
: public ObjectBase
|
||||||
{
|
{
|
||||||
|
|
@ -87,9 +86,10 @@ namespace kiwano
|
||||||
);
|
);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool opened_;
|
bool opened_;
|
||||||
bool playing_;
|
bool playing_;
|
||||||
Transcoder transcoder_;
|
Transcoder transcoder_;
|
||||||
|
|
||||||
IXAudio2SourceVoice* voice_;
|
IXAudio2SourceVoice* voice_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ namespace kiwano
|
||||||
{
|
{
|
||||||
UInt32 hash_code = file_path.hash();
|
UInt32 hash_code = file_path.hash();
|
||||||
if (sound_cache_.end() != sound_cache_.find(hash_code))
|
if (sound_cache_.end() != sound_cache_.find(hash_code))
|
||||||
return true;
|
return hash_code;
|
||||||
|
|
||||||
SoundPtr sound = new (std::nothrow) Sound;
|
SoundPtr sound = new (std::nothrow) Sound;
|
||||||
|
|
||||||
|
|
@ -48,17 +48,17 @@ namespace kiwano
|
||||||
{
|
{
|
||||||
sound->SetVolume(volume_);
|
sound->SetVolume(volume_);
|
||||||
sound_cache_.insert(std::make_pair(hash_code, sound));
|
sound_cache_.insert(std::make_pair(hash_code, sound));
|
||||||
return true;
|
return hash_code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt32 SoundPlayer::Load(Resource const& res)
|
UInt32 SoundPlayer::Load(Resource const& res)
|
||||||
{
|
{
|
||||||
UInt32 hash_code = res.GetId();
|
UInt32 hash_code = res.GetId();
|
||||||
if (sound_cache_.end() != sound_cache_.find(hash_code))
|
if (sound_cache_.end() != sound_cache_.find(hash_code))
|
||||||
return true;
|
return hash_code;
|
||||||
|
|
||||||
SoundPtr sound = new (std::nothrow) Sound;
|
SoundPtr sound = new (std::nothrow) Sound;
|
||||||
|
|
||||||
|
|
@ -68,10 +68,10 @@ namespace kiwano
|
||||||
{
|
{
|
||||||
sound->SetVolume(volume_);
|
sound->SetVolume(volume_);
|
||||||
sound_cache_.insert(std::make_pair(hash_code, sound));
|
sound_cache_.insert(std::make_pair(hash_code, sound));
|
||||||
return true;
|
return hash_code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundPlayer::Play(UInt32 id, Int32 loop_count)
|
void SoundPlayer::Play(UInt32 id, Int32 loop_count)
|
||||||
|
|
|
||||||
|
|
@ -97,8 +97,8 @@ namespace kiwano
|
||||||
protected:
|
protected:
|
||||||
Float32 volume_;
|
Float32 volume_;
|
||||||
|
|
||||||
using MusicMap = Map<UInt32, SoundPtr>;
|
using SoundMap = Map<UInt32, SoundPtr>;
|
||||||
MusicMap sound_cache_;
|
SoundMap sound_cache_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@
|
||||||
#include <kiwano/core/string.hpp>
|
#include <kiwano/core/string.hpp>
|
||||||
#include <kiwano/base/Resource.h>
|
#include <kiwano/base/Resource.h>
|
||||||
#include <kiwano/base/Logger.h>
|
#include <kiwano/base/Logger.h>
|
||||||
#include <kiwano/renderer/win32/ComPtr.hpp>
|
#include <kiwano/base/win32/ComPtr.hpp>
|
||||||
#include <kiwano/platform/modules.h>
|
#include <kiwano/platform/modules.h>
|
||||||
#include "audio-modules.h"
|
#include "audio-modules.h"
|
||||||
#include "Transcoder.h"
|
#include "Transcoder.h"
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
// THE SOFTWARE.
|
// THE SOFTWARE.
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include <kiwano/base/Resource.h>
|
||||||
#include <mfapi.h>
|
#include <mfapi.h>
|
||||||
#include <mfidl.h>
|
#include <mfidl.h>
|
||||||
#include <mfreadwrite.h>
|
#include <mfreadwrite.h>
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ namespace kiwano
|
||||||
modules::MediaFoundation::Get().MFShutdown();
|
modules::MediaFoundation::Get().MFShutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT Audio::CreateVoice(IXAudio2SourceVoice** voice, const WAVEFORMATEX* wfx)
|
HRESULT Audio::CreateVoice(IXAudio2SourceVoice** voice, const Transcoder::Buffer& buffer)
|
||||||
{
|
{
|
||||||
KGE_ASSERT(x_audio2_ && "Audio engine hasn't been initialized!");
|
KGE_ASSERT(x_audio2_ && "Audio engine hasn't been initialized!");
|
||||||
|
|
||||||
|
|
@ -89,8 +89,7 @@ namespace kiwano
|
||||||
(*voice) = nullptr;
|
(*voice) = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT hr = x_audio2_->CreateSourceVoice(voice, wfx, 0, XAUDIO2_DEFAULT_FREQ_RATIO);
|
return x_audio2_->CreateSourceVoice(voice, buffer.format, 0, XAUDIO2_DEFAULT_FREQ_RATIO);
|
||||||
return hr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Audio::Open()
|
void Audio::Open()
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <kiwano/core/singleton.hpp>
|
#include <kiwano/core/singleton.hpp>
|
||||||
#include <kiwano/base/Component.h>
|
#include <kiwano/base/Component.h>
|
||||||
|
#include <kiwano/base/win32/ComPtr.hpp>
|
||||||
|
#include "Transcoder.h"
|
||||||
|
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
|
|
@ -45,7 +47,7 @@ namespace kiwano
|
||||||
|
|
||||||
HRESULT CreateVoice(
|
HRESULT CreateVoice(
|
||||||
IXAudio2SourceVoice** voice,
|
IXAudio2SourceVoice** voice,
|
||||||
const WAVEFORMATEX* wfx
|
const Transcoder::Buffer& buffer
|
||||||
);
|
);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
||||||
|
|
@ -47,9 +47,9 @@
|
||||||
// math
|
// math
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "math/constants.hpp"
|
#include "math/constants.h"
|
||||||
#include "math/scalar.hpp"
|
#include "math/scalar.h"
|
||||||
#include "math/ease.hpp"
|
#include "math/ease.h"
|
||||||
#include "math/Vec2.hpp"
|
#include "math/Vec2.hpp"
|
||||||
#include "math/rand.h"
|
#include "math/rand.h"
|
||||||
#include "math/Matrix.hpp"
|
#include "math/Matrix.hpp"
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
// THE SOFTWARE.
|
// THE SOFTWARE.
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "scalar.hpp"
|
#include "scalar.h"
|
||||||
|
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
// THE SOFTWARE.
|
// THE SOFTWARE.
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "scalar.hpp"
|
#include "scalar.h"
|
||||||
|
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
|
|
@ -20,9 +20,9 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "..\core\core.h"
|
#include "..\core\core.h"
|
||||||
#include "constants.hpp"
|
#include "constants.h"
|
||||||
#include "ease.hpp"
|
#include "ease.h"
|
||||||
#include "scalar.hpp"
|
#include "scalar.h"
|
||||||
#include "Vec2.hpp"
|
#include "Vec2.hpp"
|
||||||
#include "Rect.hpp"
|
#include "Rect.hpp"
|
||||||
#include "Matrix.hpp"
|
#include "Matrix.hpp"
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
// THE SOFTWARE.
|
// THE SOFTWARE.
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "constants.hpp"
|
#include "constants.h"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "../base/Resource.h"
|
#include "../base/Resource.h"
|
||||||
#include "win32/ComPtr.hpp"
|
#include "../base/win32/ComPtr.hpp"
|
||||||
#include <dwrite.h>
|
#include <dwrite.h>
|
||||||
|
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue