This commit is contained in:
Arron David Nelson 2024-09-30 20:24:25 -07:00
parent fc8b771026
commit dfa260b87c
2 changed files with 12 additions and 34 deletions

View File

@ -33,8 +33,6 @@ namespace ehs
AudioDevice& operator=(const AudioDevice& device); AudioDevice& operator=(const AudioDevice& device);
void Release() override;
void OpenStream() override; void OpenStream() override;
void CloseStream() override; void CloseStream() override;
@ -57,6 +55,8 @@ namespace ehs
Str_8 GetName_8() const; Str_8 GetName_8() const;
bool IsStreaming() const override;
bool IsValid() const override; bool IsValid() const override;
static AudioDevice GetDefault(const AudioDeviceType type); static AudioDevice GetDefault(const AudioDeviceType type);

View File

@ -68,34 +68,6 @@ namespace ehs
return *this; return *this;
} }
void AudioDevice::Release()
{
if (captureClient)
{
captureClient->Release();
captureClient = nullptr;
}
if (playbackClient)
{
playbackClient->Release();
playbackClient = nullptr;
}
if (hdl)
{
HRESULT r = client->Stop();
if (FAILED(r))
{
EHS_LOG_INT(LogType::ERR, 0, "Failed to stop audio with error #" + Str_8::FromNum(r) + ".");
return;
}
hdl->Release();
hdl = nullptr;
}
}
void AudioDevice::OpenStream() void AudioDevice::OpenStream()
{ {
if (streaming) if (streaming)
@ -298,7 +270,7 @@ namespace ehs
void AudioDevice::CloseStream() void AudioDevice::CloseStream()
{ {
if (!streaming) if (!IsStreaming())
return; return;
if (playbackClient) if (playbackClient)
@ -324,14 +296,15 @@ namespace ehs
client->Release(); client->Release();
client = nullptr; client = nullptr;
}
streaming = false; hdl->Release();
hdl = nullptr;
}
} }
UInt_64 AudioDevice::GetAvailFrames() const UInt_64 AudioDevice::GetAvailFrames() const
{ {
if (!IsValid() || !streaming) if (!IsValid() || !IsStreaming())
return 0; return 0;
UInt_32 sampleSize = 0; UInt_32 sampleSize = 0;
@ -484,6 +457,11 @@ namespace ehs
return UTF::To_8(GetName_16()); return UTF::To_8(GetName_16());
} }
bool AudioDevice::IsStreaming() const
{
return hdl && client && (playbackClient || captureClient);
}
bool AudioDevice::IsValid() const bool AudioDevice::IsValid() const
{ {
return hdl; return hdl;