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