Compare commits
No commits in common. "master" and "main" have entirely different histories.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"Version": 1,
|
|
||||||
"WorkspaceRootPath": "D:\\Project\\AudioRender\\AudioRender\\",
|
|
||||||
"Documents": [],
|
|
||||||
"DocumentGroupContainers": [
|
|
||||||
{
|
|
||||||
"Orientation": 0,
|
|
||||||
"VerticalTabListWidth": 256,
|
|
||||||
"DocumentGroups": []
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
@ -6,15 +6,9 @@
|
|||||||
#include "IAudioRender.h"
|
#include "IAudioRender.h"
|
||||||
|
|
||||||
static std::unique_ptr<IAudioRender> audiosRender_;
|
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_);
|
assert(!audiosRender_);
|
||||||
|
audiosRender_.reset(IAudioRender::Create());
|
||||||
auto logCallback = [cb](int32 level, const int8* log, uint32 length) {
|
|
||||||
if (nullptr == cb) {
|
|
||||||
cb(level, log, length);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
audiosRender_.reset(IAudioRender::Create(std::move(logCallback)));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,8 +11,8 @@
|
|||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif // __cplusplus
|
#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 bool __stdcall Write(const unsigned char* data, unsigned int len);
|
||||||
AUDIO_RENDER_EXPORT void __stdcall Uninitialize();
|
AUDIO_RENDER_EXPORT void __stdcall Uninitialize();
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@
|
|||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<PlatformToolset>v143</PlatformToolset>
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
@ -120,8 +120,6 @@
|
|||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;WIN32;AUDIO_RENDER_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>NDEBUG;_CONSOLE;WIN32;AUDIO_RENDER_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
<AdditionalIncludeDirectories>D:\Project\AudioRender\AudioRender;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
<Optimization>Disabled</Optimization>
|
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
|
@ -1,22 +1,7 @@
|
|||||||
#include "AudioRenderStd.h"
|
#include "AudioRenderStd.h"
|
||||||
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
#include "Windows/WavAudioRender.h"
|
#include "Windows/WavAudioRender.h"
|
||||||
|
|
||||||
IAudioRender* IAudioRender::Create(LogCallback callback) {
|
IAudioRender* IAudioRender::Create() {
|
||||||
return new WavAudioRender(std::move(callback));
|
return new WavAudioRender;
|
||||||
}
|
}
|
||||||
|
|
||||||
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()));
|
|
||||||
}
|
|
@ -1,25 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "IAudioRender.h"
|
#include "IAudioRender.h"
|
||||||
|
|
||||||
class AudioRenderStd : public IAudioRender {
|
class AudioRenderStd : public IAudioRender {
|
||||||
public:
|
public:
|
||||||
enum LOG_LEVEL {
|
|
||||||
DEBUG,
|
|
||||||
LOG
|
|
||||||
};
|
|
||||||
public:
|
|
||||||
explicit AudioRenderStd(LogCallback callback) noexcept;
|
|
||||||
~AudioRenderStd() override = default;
|
~AudioRenderStd() override = default;
|
||||||
uint64 GetClock() override {
|
uint64 GetClock() override {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WirteLog(int32 level, const std::string& log);
|
|
||||||
|
|
||||||
private:
|
|
||||||
LogCallback callback_{ nullptr };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <functional>
|
|
||||||
|
|
||||||
using int8 = char;
|
using int8 = char;
|
||||||
using uint8 = unsigned char;
|
using uint8 = unsigned char;
|
||||||
@ -21,8 +20,7 @@ struct AudioFrame {
|
|||||||
|
|
||||||
class IAudioRender {
|
class IAudioRender {
|
||||||
public:
|
public:
|
||||||
using LogCallback = std::function<void(int32, const int8*, uint32)>;
|
static IAudioRender* Create();
|
||||||
static IAudioRender* Create(LogCallback callback);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~IAudioRender() = default;
|
virtual ~IAudioRender() = default;
|
||||||
|
@ -30,8 +30,7 @@ static void FreeBlocks(WAVEHDR* blockArray) {
|
|||||||
HeapFree(GetProcessHeap(), 0, blockArray);
|
HeapFree(GetProcessHeap(), 0, blockArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
WavAudioRender::WavAudioRender(LogCallback callback) noexcept
|
WavAudioRender::WavAudioRender() noexcept {
|
||||||
: AudioRenderStd(callback){
|
|
||||||
HWAVEOUT hWaveOut = nullptr;
|
HWAVEOUT hWaveOut = nullptr;
|
||||||
|
|
||||||
waveBlocks_ = AllocateBlocks(BlockSize_, BlockCount_);
|
waveBlocks_ = AllocateBlocks(BlockSize_, BlockCount_);
|
||||||
@ -53,20 +52,15 @@ WavAudioRender::WavAudioRender(LogCallback callback) noexcept
|
|||||||
MMRESULT hr = waveOutOpen(&hWaveOut, WAVE_MAPPER, &waveform,
|
MMRESULT hr = waveOutOpen(&hWaveOut, WAVE_MAPPER, &waveform,
|
||||||
reinterpret_cast<DWORD_PTR>(WavAudioRender::waveOutProc),
|
reinterpret_cast<DWORD_PTR>(WavAudioRender::waveOutProc),
|
||||||
reinterpret_cast<DWORD_PTR>(this), CALLBACK_FUNCTION);
|
reinterpret_cast<DWORD_PTR>(this), CALLBACK_FUNCTION);
|
||||||
if (MMSYSERR_NOERROR != hr) {
|
if (MMSYSERR_NOERROR == hr) {
|
||||||
WirteLog(DEBUG, "init success");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
hWavout_ = std::move(hWaveOut);
|
hWavout_ = std::move(hWaveOut);
|
||||||
initialized_ = true;
|
|
||||||
WirteLog(DEBUG, "init success");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WavAudioRender::~WavAudioRender() {
|
WavAudioRender::~WavAudioRender() {
|
||||||
initialized_ = false;
|
|
||||||
if (nullptr == hWavout_) {
|
if (nullptr == hWavout_) {
|
||||||
WirteLog(DEBUG, "hWavout is nullptr");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
waveOutReset(hWavout_);
|
waveOutReset(hWavout_);
|
||||||
@ -89,13 +83,10 @@ WavAudioRender::~WavAudioRender() {
|
|||||||
}
|
}
|
||||||
} while (true);
|
} while (true);
|
||||||
FreeBlocks(waveBlocks_);
|
FreeBlocks(waveBlocks_);
|
||||||
WirteLog(DEBUG, "uninitialized success");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WavAudioRender::Write(const AudioFrame& audioFrame) {
|
bool WavAudioRender::Write(const AudioFrame& audioFrame) {
|
||||||
WirteLog(DEBUG, "WavAudioRender::Write");
|
|
||||||
if (nullptr == hWavout_) {
|
if (nullptr == hWavout_) {
|
||||||
WirteLog(DEBUG, "hWavout_ is nullptr");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,12 +116,9 @@ bool WavAudioRender::Write(const AudioFrame& audioFrame) {
|
|||||||
--freeBlockCounter_;
|
--freeBlockCounter_;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!freeBlockCounter_ && initialized_) {
|
while (!freeBlockCounter_) {
|
||||||
Sleep(1);
|
Sleep(1);
|
||||||
}
|
}
|
||||||
if (!initialized_) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
++waveCurrentBlock_;
|
++waveCurrentBlock_;
|
||||||
waveCurrentBlock_ %= BlockCount_;
|
waveCurrentBlock_ %= BlockCount_;
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
class WavAudioRender : public AudioRenderStd {
|
class WavAudioRender : public AudioRenderStd {
|
||||||
public:
|
public:
|
||||||
explicit WavAudioRender(LogCallback callback) noexcept;
|
explicit WavAudioRender() noexcept;
|
||||||
~WavAudioRender() override;
|
~WavAudioRender() override;
|
||||||
|
|
||||||
bool Write(const AudioFrame& audioFrame) override;
|
bool Write(const AudioFrame& audioFrame) override;
|
||||||
@ -19,7 +19,7 @@ private:
|
|||||||
private:
|
private:
|
||||||
int64_t audioPts_{ 0 };
|
int64_t audioPts_{ 0 };
|
||||||
|
|
||||||
static constexpr int BlockSize_{ 3200 };
|
static constexpr int BlockSize_{ 6400 };
|
||||||
static constexpr int BlockCount_{ 10 };
|
static constexpr int BlockCount_{ 10 };
|
||||||
|
|
||||||
SectionLock lock_;
|
SectionLock lock_;
|
||||||
@ -28,5 +28,4 @@ private:
|
|||||||
|
|
||||||
WAVEHDR* waveBlocks_{ nullptr };
|
WAVEHDR* waveBlocks_{ nullptr };
|
||||||
HWAVEOUT hWavout_{ nullptr };
|
HWAVEOUT hWavout_{ nullptr };
|
||||||
bool initialized_{ false };
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user