Skip to content

Commit

Permalink
[deploy] Merge pull request #72 from KiwanoEngine/dev
Browse files Browse the repository at this point in the history
Many updates
  • Loading branch information
Nomango authored Sep 24, 2023
2 parents 3596e35 + e571bf9 commit b4f1f0f
Show file tree
Hide file tree
Showing 55 changed files with 1,418 additions and 919 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Release/
.vs
.idea
._Kiwano.sln
.vscode

# vs2010
ipch/
Expand Down
34 changes: 0 additions & 34 deletions .vscode/c_cpp_properties.json

This file was deleted.

4 changes: 0 additions & 4 deletions .vscode/settings.json

This file was deleted.

4 changes: 1 addition & 3 deletions projects/kiwano/kiwano.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
<ClInclude Include="..\..\src\kiwano\platform\FileSystem.h" />
<ClInclude Include="..\..\src\kiwano\platform\Input.h" />
<ClInclude Include="..\..\src\kiwano\platform\Keys.h" />
<ClInclude Include="..\..\src\kiwano\platform\NativeObject.hpp" />
<ClInclude Include="..\..\src\kiwano\platform\Runner.h" />
<ClInclude Include="..\..\src\kiwano\platform\win32\ComPtr.hpp" />
<ClInclude Include="..\..\src\kiwano\platform\win32\libraries.h" />
Expand All @@ -96,12 +97,10 @@
<ClInclude Include="..\..\src\kiwano\render\DirectX\D3DDeviceResourcesBase.h" />
<ClInclude Include="..\..\src\kiwano\render\DirectX\FontCollectionLoader.h" />
<ClInclude Include="..\..\src\kiwano\render\DirectX\helper.h" />
<ClInclude Include="..\..\src\kiwano\render\DirectX\NativePtr.h" />
<ClInclude Include="..\..\src\kiwano\render\DirectX\RenderContextImpl.h" />
<ClInclude Include="..\..\src\kiwano\render\DirectX\RendererImpl.h" />
<ClInclude Include="..\..\src\kiwano\render\DirectX\TextRenderer.h" />
<ClInclude Include="..\..\src\kiwano\render\Font.h" />
<ClInclude Include="..\..\src\kiwano\render\NativeObject.h" />
<ClInclude Include="..\..\src\kiwano\render\Shape.h" />
<ClInclude Include="..\..\src\kiwano\render\ShapeMaker.h" />
<ClInclude Include="..\..\src\kiwano\render\GifImage.h" />
Expand Down Expand Up @@ -193,7 +192,6 @@
<ClCompile Include="..\..\src\kiwano\render\DirectX\RendererImpl.cpp" />
<ClCompile Include="..\..\src\kiwano\render\DirectX\TextRenderer.cpp" />
<ClCompile Include="..\..\src\kiwano\render\Font.cpp" />
<ClCompile Include="..\..\src\kiwano\render\NativeObject.cpp" />
<ClCompile Include="..\..\src\kiwano\render\Shape.cpp" />
<ClCompile Include="..\..\src\kiwano\render\ShapeMaker.cpp" />
<ClCompile Include="..\..\src\kiwano\render\GifImage.cpp" />
Expand Down
12 changes: 3 additions & 9 deletions projects/kiwano/kiwano.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,6 @@
<ClInclude Include="..\..\src\kiwano\core\IntrusiveList.h">
<Filter>core</Filter>
</ClInclude>
<ClInclude Include="..\..\src\kiwano\render\NativeObject.h">
<Filter>render</Filter>
</ClInclude>
<ClInclude Include="..\..\src\kiwano\render\DirectX\NativePtr.h">
<Filter>render\DirectX</Filter>
</ClInclude>
<ClInclude Include="..\..\src\kiwano\render\ShapeMaker.h">
<Filter>render</Filter>
</ClInclude>
Expand Down Expand Up @@ -411,6 +405,9 @@
<ClInclude Include="..\..\src\kiwano\render\DirectX\TextDrawingEffect.h">
<Filter>render\DirectX</Filter>
</ClInclude>
<ClInclude Include="..\..\src\kiwano\platform\NativeObject.hpp">
<Filter>platform</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\kiwano\2d\Canvas.cpp">
Expand Down Expand Up @@ -608,9 +605,6 @@
<ClCompile Include="..\..\src\kiwano\render\TextStyle.cpp">
<Filter>render</Filter>
</ClCompile>
<ClCompile Include="..\..\src\kiwano\render\NativeObject.cpp">
<Filter>render</Filter>
</ClCompile>
<ClCompile Include="..\..\src\kiwano\core\Duration.cpp">
<Filter>core</Filter>
</ClCompile>
Expand Down
97 changes: 84 additions & 13 deletions src/kiwano-audio/AudioModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,52 @@
#include <kiwano-audio/libraries.h>
#include <kiwano/core/Exception.h>
#include <kiwano/utils/Logger.h>
#include <kiwano/platform/FileSystem.h>

namespace kiwano
{
namespace audio
{

class VoiceCallback : public IXAudio2VoiceCallback
{
public:
SoundCallback* cb;

VoiceCallback(SoundCallback* cb)
: cb(cb)
{
}

~VoiceCallback() {}

STDMETHOD_(void, OnBufferStart(void* pBufferContext))
{
cb->OnStart(nullptr);
}

STDMETHOD_(void, OnLoopEnd(void* pBufferContext))
{
cb->OnLoopEnd(nullptr);
}

STDMETHOD_(void, OnBufferEnd(void* pBufferContext))
{
cb->OnEnd(nullptr);
}

STDMETHOD_(void, OnStreamEnd()) {}

STDMETHOD_(void, OnVoiceProcessingPassEnd()) {}

STDMETHOD_(void, OnVoiceProcessingPassStart(UINT32 SamplesRequired)) {}

STDMETHOD_(void, OnVoiceError(void* pBufferContext, HRESULT Error))
{
KGE_ERRORF("Voice error with HRESULT of %08X", Error);
}
};

AudioModule::AudioModule()
: x_audio2_(nullptr)
, mastering_voice_(nullptr)
Expand Down Expand Up @@ -58,6 +99,8 @@ void AudioModule::DestroyModule()
{
KGE_DEBUG_LOGF("Destroying audio resources");

TranscoderCache::GetInstance().Clear();

if (mastering_voice_)
{
mastering_voice_->DestroyVoice();
Expand All @@ -73,31 +116,60 @@ void AudioModule::DestroyModule()
dlls::MediaFoundation::Get().MFShutdown();
}

bool AudioModule::CreateSound(Sound& sound, const Transcoder::Buffer& buffer)
TranscoderPtr AudioModule::CreateTranscoder(const String& file_path)
{
if (!FileSystem::GetInstance().IsFileExists(file_path))
{
KGE_WARNF("Media file '%s' not found", file_path.c_str());
return nullptr;
}

String full_path = FileSystem::GetInstance().GetFullPathForFile(file_path);

auto ptr = MakePtr<Transcoder>();
HRESULT hr = ptr->LoadMediaFile(full_path);
if (FAILED(hr))
{
KGE_ERRORF("Load media file failed with HRESULT of %08X", hr);
return nullptr;
}
return ptr;
}

TranscoderPtr AudioModule::CreateTranscoder(const Resource& res)
{
auto ptr = MakePtr<Transcoder>();
HRESULT hr = ptr->LoadMediaResource(res);
if (FAILED(hr))
{
KGE_ERRORF("Load media resource failed with HRESULT of %08X", hr);
return nullptr;
}
return ptr;
}

bool AudioModule::CreateSound(Sound& sound, TranscoderPtr transcoder)
{
KGE_ASSERT(x_audio2_ && "AudioModule hasn't been initialized!");

HRESULT hr = S_OK;

auto buffer = transcoder->GetBuffer();
if (buffer.format == nullptr)
hr = E_INVALIDARG;

if (SUCCEEDED(hr))
{
IXAudio2SourceVoice* voice = nullptr;

hr = x_audio2_->CreateSourceVoice(&voice, buffer.format, 0, XAUDIO2_DEFAULT_FREQ_RATIO);
auto chain = sound.GetCallbackChain();
chain->SetNative(VoiceCallback{ chain.Get() });
auto callback = const_cast<VoiceCallback*>(chain->GetNative().CastPtr<VoiceCallback>());

IXAudio2SourceVoice* voice = nullptr;
hr = x_audio2_->CreateSourceVoice(&voice, buffer.format, 0, XAUDIO2_DEFAULT_FREQ_RATIO, callback);
if (SUCCEEDED(hr))
{
IXAudio2SourceVoice* old = sound.GetXAudio2Voice();
if (old)
{
old->DestroyVoice();
old = nullptr;
}

sound.SetXAudio2Voice(voice);
sound.Close();
sound.SetNative(voice);
}
}

Expand All @@ -112,7 +184,6 @@ bool AudioModule::CreateSound(Sound& sound, const Transcoder::Buffer& buffer)
void AudioModule::Open()
{
KGE_ASSERT(x_audio2_ && "AudioModule hasn't been initialized!");

if (x_audio2_)
x_audio2_->StartEngine();
}
Expand Down
12 changes: 10 additions & 2 deletions src/kiwano-audio/AudioModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,16 @@ class KGE_API AudioModule
void Close();

/// \~chinese
/// @brief 从解码器数据缓冲中创建音频对象
bool CreateSound(Sound& sound, const Transcoder::Buffer& buffer);
/// @brief 创建音频解码器
TranscoderPtr CreateTranscoder(const String& file_path);

/// \~chinese
/// @brief 创建音频解码器
TranscoderPtr CreateTranscoder(const Resource& res);

/// \~chinese
/// @brief 创建音频
bool CreateSound(Sound& sound, TranscoderPtr transcoder);

public:
void SetupModule() override;
Expand Down
Loading

0 comments on commit b4f1f0f

Please sign in to comment.