Compare commits

...

No commits in common. "2879e634f19e9d4cb7f1d998199e1bbfa908d78f" and "main" have entirely different histories.

12 changed files with 14 additions and 77 deletions

Binary file not shown.

View File

@ -1,12 +0,0 @@
{
"Version": 1,
"WorkspaceRootPath": "D:\\Project\\AudioRender\\AudioRender\\",
"Documents": [],
"DocumentGroupContainers": [
{
"Orientation": 0,
"VerticalTabListWidth": 256,
"DocumentGroups": []
}
]
}

View File

@ -6,15 +6,9 @@
#include "IAudioRender.h"
static std::unique_ptr<IAudioRender> audiosRender_;
bool __stdcall Initialize(callback_t cb) {
bool __stdcall Initialize(const char* sender_name, const char* receiver_name) {
assert(!audiosRender_);
auto logCallback = [cb](int32 level, const int8* log, uint32 length) {
if (nullptr == cb) {
cb(level, log, length);
}
};
audiosRender_.reset(IAudioRender::Create(std::move(logCallback)));
audiosRender_.reset(IAudioRender::Create());
return true;
}

View File

@ -11,8 +11,8 @@
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
typedef void (*callback_t)(int, const char*, int);
AUDIO_RENDER_EXPORT bool __stdcall Initialize(callback_t cb);
AUDIO_RENDER_EXPORT bool __stdcall Initialize(const char* sender_name, const char* receiver_name);
AUDIO_RENDER_EXPORT bool __stdcall Write(const unsigned char* data, unsigned int len);
AUDIO_RENDER_EXPORT void __stdcall Uninitialize();

View File

@ -46,7 +46,7 @@
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
@ -120,8 +120,6 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;WIN32;AUDIO_RENDER_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>D:\Project\AudioRender\AudioRender;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<Optimization>Disabled</Optimization>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>

View File

@ -1,22 +1,7 @@
#include "AudioRenderStd.h"
#include <sstream>
#include "Windows/WavAudioRender.h"
IAudioRender* IAudioRender::Create(LogCallback callback) {
return new WavAudioRender(std::move(callback));
}
AudioRenderStd::AudioRenderStd(LogCallback callback) noexcept
: callback_(std::move(callback)){
}
void AudioRenderStd::WirteLog(int32 level, const std::string& log) {
if (nullptr == callback_) {
return;
}
callback_(level, log.c_str(), static_cast<uint32>(log.length()));
}
IAudioRender* IAudioRender::Create() {
return new WavAudioRender;
}

View File

@ -1,25 +1,12 @@
#pragma once
#include <string>
#include "IAudioRender.h"
class AudioRenderStd : public IAudioRender {
public:
enum LOG_LEVEL {
DEBUG,
LOG
};
public:
explicit AudioRenderStd(LogCallback callback) noexcept;
~AudioRenderStd() override = default;
uint64 GetClock() override {
return 0;
}
void WirteLog(int32 level, const std::string& log);
private:
LogCallback callback_{ nullptr };
};

View File

@ -1,7 +1,6 @@
#pragma once
#include <vector>
#include <functional>
using int8 = char;
using uint8 = unsigned char;
@ -21,8 +20,7 @@ struct AudioFrame {
class IAudioRender {
public:
using LogCallback = std::function<void(int32, const int8*, uint32)>;
static IAudioRender* Create(LogCallback callback);
static IAudioRender* Create();
public:
virtual ~IAudioRender() = default;

View File

@ -30,8 +30,7 @@ static void FreeBlocks(WAVEHDR* blockArray) {
HeapFree(GetProcessHeap(), 0, blockArray);
}
WavAudioRender::WavAudioRender(LogCallback callback) noexcept
: AudioRenderStd(callback){
WavAudioRender::WavAudioRender() noexcept {
HWAVEOUT hWaveOut = nullptr;
waveBlocks_ = AllocateBlocks(BlockSize_, BlockCount_);
@ -53,20 +52,15 @@ WavAudioRender::WavAudioRender(LogCallback callback) noexcept
MMRESULT hr = waveOutOpen(&hWaveOut, WAVE_MAPPER, &waveform,
reinterpret_cast<DWORD_PTR>(WavAudioRender::waveOutProc),
reinterpret_cast<DWORD_PTR>(this), CALLBACK_FUNCTION);
if (MMSYSERR_NOERROR != hr) {
WirteLog(DEBUG, "init success");
if (MMSYSERR_NOERROR == hr) {
return;
}
hWavout_ = std::move(hWaveOut);
initialized_ = true;
WirteLog(DEBUG, "init success");
}
WavAudioRender::~WavAudioRender() {
initialized_ = false;
if (nullptr == hWavout_) {
WirteLog(DEBUG, "hWavout is nullptr");
return;
}
waveOutReset(hWavout_);
@ -89,13 +83,10 @@ WavAudioRender::~WavAudioRender() {
}
} while (true);
FreeBlocks(waveBlocks_);
WirteLog(DEBUG, "uninitialized success");
}
bool WavAudioRender::Write(const AudioFrame& audioFrame) {
WirteLog(DEBUG, "WavAudioRender::Write");
if (nullptr == hWavout_) {
WirteLog(DEBUG, "hWavout_ is nullptr");
return false;
}
@ -125,12 +116,9 @@ bool WavAudioRender::Write(const AudioFrame& audioFrame) {
--freeBlockCounter_;
}
while (!freeBlockCounter_ && initialized_) {
while (!freeBlockCounter_) {
Sleep(1);
}
if (!initialized_) {
break;
}
++waveCurrentBlock_;
waveCurrentBlock_ %= BlockCount_;

View File

@ -6,7 +6,7 @@
class WavAudioRender : public AudioRenderStd {
public:
explicit WavAudioRender(LogCallback callback) noexcept;
explicit WavAudioRender() noexcept;
~WavAudioRender() override;
bool Write(const AudioFrame& audioFrame) override;
@ -19,7 +19,7 @@ private:
private:
int64_t audioPts_{ 0 };
static constexpr int BlockSize_{ 3200 };
static constexpr int BlockSize_{ 6400 };
static constexpr int BlockCount_{ 10 };
SectionLock lock_;
@ -28,5 +28,4 @@ private:
WAVEHDR* waveBlocks_{ nullptr };
HWAVEOUT hWavout_{ nullptr };
bool initialized_{ false };
};