Compare commits
No commits in common. "main" and "master" have entirely different histories.
Binary file not shown.
BIN
AudioRender/.vs/AudioRender/v17/.suo
Normal file
BIN
AudioRender/.vs/AudioRender/v17/.suo
Normal file
Binary file not shown.
BIN
AudioRender/.vs/AudioRender/v17/Browse.VC.db
Normal file
BIN
AudioRender/.vs/AudioRender/v17/Browse.VC.db
Normal file
Binary file not shown.
12
AudioRender/.vs/AudioRender/v17/DocumentLayout.json
Normal file
12
AudioRender/.vs/AudioRender/v17/DocumentLayout.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"Version": 1,
|
||||||
|
"WorkspaceRootPath": "D:\\Project\\AudioRender\\AudioRender\\",
|
||||||
|
"Documents": [],
|
||||||
|
"DocumentGroupContainers": [
|
||||||
|
{
|
||||||
|
"Orientation": 0,
|
||||||
|
"VerticalTabListWidth": 256,
|
||||||
|
"DocumentGroups": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -6,9 +6,15 @@
|
|||||||
#include "IAudioRender.h"
|
#include "IAudioRender.h"
|
||||||
|
|
||||||
static std::unique_ptr<IAudioRender> audiosRender_;
|
static std::unique_ptr<IAudioRender> audiosRender_;
|
||||||
bool __stdcall Initialize(const char* sender_name, const char* receiver_name) {
|
bool __stdcall Initialize(callback_t cb) {
|
||||||
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(const char* sender_name, const char* receiver_name);
|
AUDIO_RENDER_EXPORT bool __stdcall Initialize(callback_t cb);
|
||||||
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>Application</ConfigurationType>
|
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<PlatformToolset>v143</PlatformToolset>
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
@ -120,6 +120,8 @@
|
|||||||
<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,7 +1,22 @@
|
|||||||
#include "AudioRenderStd.h"
|
#include "AudioRenderStd.h"
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#include "Windows/WavAudioRender.h"
|
#include "Windows/WavAudioRender.h"
|
||||||
|
|
||||||
IAudioRender* IAudioRender::Create() {
|
IAudioRender* IAudioRender::Create(LogCallback callback) {
|
||||||
return new WavAudioRender;
|
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()));
|
||||||
|
}
|
||||||
|
@ -1,12 +1,25 @@
|
|||||||
#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,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
using int8 = char;
|
using int8 = char;
|
||||||
using uint8 = unsigned char;
|
using uint8 = unsigned char;
|
||||||
@ -20,7 +21,8 @@ struct AudioFrame {
|
|||||||
|
|
||||||
class IAudioRender {
|
class IAudioRender {
|
||||||
public:
|
public:
|
||||||
static IAudioRender* Create();
|
using LogCallback = std::function<void(int32, const int8*, uint32)>;
|
||||||
|
static IAudioRender* Create(LogCallback callback);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~IAudioRender() = default;
|
virtual ~IAudioRender() = default;
|
||||||
|
@ -30,7 +30,8 @@ static void FreeBlocks(WAVEHDR* blockArray) {
|
|||||||
HeapFree(GetProcessHeap(), 0, blockArray);
|
HeapFree(GetProcessHeap(), 0, blockArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
WavAudioRender::WavAudioRender() noexcept {
|
WavAudioRender::WavAudioRender(LogCallback callback) noexcept
|
||||||
|
: AudioRenderStd(callback){
|
||||||
HWAVEOUT hWaveOut = nullptr;
|
HWAVEOUT hWaveOut = nullptr;
|
||||||
|
|
||||||
waveBlocks_ = AllocateBlocks(BlockSize_, BlockCount_);
|
waveBlocks_ = AllocateBlocks(BlockSize_, BlockCount_);
|
||||||
@ -52,15 +53,20 @@ WavAudioRender::WavAudioRender() 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_);
|
||||||
@ -83,10 +89,13 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,9 +125,12 @@ bool WavAudioRender::Write(const AudioFrame& audioFrame) {
|
|||||||
--freeBlockCounter_;
|
--freeBlockCounter_;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!freeBlockCounter_) {
|
while (!freeBlockCounter_ && initialized_) {
|
||||||
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() noexcept;
|
explicit WavAudioRender(LogCallback callback) 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_{ 6400 };
|
static constexpr int BlockSize_{ 3200 };
|
||||||
static constexpr int BlockCount_{ 10 };
|
static constexpr int BlockCount_{ 10 };
|
||||||
|
|
||||||
SectionLock lock_;
|
SectionLock lock_;
|
||||||
@ -28,4 +28,5 @@ private:
|
|||||||
|
|
||||||
WAVEHDR* waveBlocks_{ nullptr };
|
WAVEHDR* waveBlocks_{ nullptr };
|
||||||
HWAVEOUT hWavout_{ nullptr };
|
HWAVEOUT hWavout_{ nullptr };
|
||||||
|
bool initialized_{ false };
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user