Files
LookingGlass/idd/LGAudio/Formats.h
Geoffrey McRae efc9952e74 [idd] audio: support 32-bit and common channel layouts
Advertise signed and floating-point 32-bit formats across mono,
stereo, quad, surround, 5.1, and 7.1 at every supported rate.

Carry sample encoding through the broker and LGMP protocol so integer
and floating-point streams remain distinct.

Expand packet, shared-memory, and ring capacity for eight-channel
32-bit audio.
2026-11-06 14:34:25 +11:00

145 lines
4.5 KiB
C++

/**
* Looking Glass
* Copyright © 2017-2026 The Looking Glass Authors
* https://looking-glass.io
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., 59
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#pragma once
#include <portcls.h>
#include <ks.h>
#include <ksmedia.h>
namespace LGAudio
{
enum class SampleFormat : ULONG
{
Unknown = 0,
S16LE = 1,
S24LE = 2,
S32LE = 3,
F32LE = 4
};
enum class EndpointKind : UCHAR
{
Render,
Capture
};
struct FormatFingerprint
{
SampleFormat sampleFormat;
ULONG sampleRate;
ULONG channelMask;
USHORT channels;
USHORT containerBits;
USHORT validBits;
USHORT blockAlign;
};
constexpr ULONG kSampleRate = 48000;
constexpr ULONG kSampleRateCount = 6;
constexpr ULONG kRenderFormatsPerRate = 24;
constexpr ULONG kCaptureFormatsPerRate = 24;
constexpr ULONG kRenderDataRangesPerRate = 20;
constexpr ULONG kCaptureDataRangesPerRate = 20;
constexpr ULONG kRenderFormatCount =
kSampleRateCount * kRenderFormatsPerRate;
constexpr ULONG kCaptureFormatCount =
kSampleRateCount * kCaptureFormatsPerRate;
constexpr ULONG kRenderDataRangeCount =
kSampleRateCount * kRenderDataRangesPerRate;
constexpr ULONG kCaptureDataRangeCount =
kSampleRateCount * kCaptureDataRangesPerRate;
constexpr ULONG kMaximumSampleRate = 192000;
constexpr ULONG kMaximumBlockAlign =
8 * 4;
constexpr ULONG kMaximumBytesPerSecond =
kMaximumSampleRate * kMaximumBlockAlign;
extern KSDATAFORMAT_WAVEFORMATEXTENSIBLE
g_renderFormats[kRenderFormatCount];
extern KSDATAFORMAT_WAVEFORMATEXTENSIBLE
g_captureFormats[kCaptureFormatCount];
extern KSDATARANGE_AUDIO g_renderDataRanges[kRenderDataRangeCount];
extern KSDATARANGE_AUDIO g_captureDataRanges[kCaptureDataRangeCount];
extern PKSDATARANGE g_renderDataRangePointers[kRenderDataRangeCount];
extern PKSDATARANGE g_captureDataRangePointers[kCaptureDataRangeCount];
/**
* Validate an instantiated WaveRT format against the endpoint's exact
* discrete format list.
*/
_IRQL_requires_max_(DISPATCH_LEVEL)
NTSTATUS ValidateFormat(
_In_ EndpointKind endpoint,
_In_ const KSDATAFORMAT * dataFormat,
_Outptr_opt_result_maybenull_
const KSDATAFORMAT_WAVEFORMATEXTENSIBLE ** matchedFormat);
/**
* Select the exact WAVEFORMATEXTENSIBLE result for an IMiniport data-range
* intersection request.
*/
_IRQL_requires_max_(DISPATCH_LEVEL)
NTSTATUS SelectFormatIntersection(
_In_ EndpointKind endpoint,
_In_ const KSDATARANGE * clientDataRange,
_In_ const KSDATARANGE * driverDataRange,
_In_ ULONG outputBufferLength,
_Out_writes_bytes_to_opt_(outputBufferLength, *resultantFormatLength)
PVOID resultantFormat,
_Out_ PULONG resultantFormatLength);
_IRQL_requires_max_(DISPATCH_LEVEL)
NTSTATUS GetFormatFingerprint(
_In_ const KSDATAFORMAT_WAVEFORMATEXTENSIBLE * dataFormat,
_Out_ FormatFingerprint * fingerprint);
_IRQL_requires_max_(DISPATCH_LEVEL)
bool EqualFormatFingerprint(
_In_ const FormatFingerprint & left,
_In_ const FormatFingerprint & right);
}
// The rest of the driver uses these as its shared, unqualified audio types.
using LGAudio::EndpointKind;
using LGAudio::FormatFingerprint;
using LGAudio::SampleFormat;
using LGAudio::EqualFormatFingerprint;
using LGAudio::GetFormatFingerprint;
using LGAudio::SelectFormatIntersection;
using LGAudio::ValidateFormat;
using LGAudio::g_captureDataRangePointers;
using LGAudio::g_captureDataRanges;
using LGAudio::g_captureFormats;
using LGAudio::g_renderDataRangePointers;
using LGAudio::g_renderDataRanges;
using LGAudio::g_renderFormats;
using LGAudio::kCaptureFormatCount;
using LGAudio::kCaptureDataRangeCount;
using LGAudio::kMaximumBlockAlign;
using LGAudio::kMaximumBytesPerSecond;
using LGAudio::kMaximumSampleRate;
using LGAudio::kRenderFormatCount;
using LGAudio::kRenderDataRangeCount;
using LGAudio::kSampleRate;
using LGAudio::kSampleRateCount;