Skip to content

Commit

Permalink
v3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
spddl committed Jul 1, 2024
1 parent a7f3795 commit cad953f
Show file tree
Hide file tree
Showing 8 changed files with 561 additions and 85 deletions.
156 changes: 137 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 14 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "LowAudioLatency"
description = ""
version = "2.0.1"
version = "3.0.0"
authors = ["spddl"]
edition = "2021"

Expand All @@ -13,24 +13,27 @@ path = "src/main.rs"
# This isn't required for development builds, but makes development
# build behavior match release builds. To enable unwinding panics
# during development, simply remove this line.
panic = "abort" # Abort on panic
panic = "abort" # Abort on panic

[profile.release]
opt-level = "z" # Optimize for size.
lto = true # Enable Link Time Optimization
codegen-units = 1 # Reduce number of codegen units to increase optimizations.
panic = "abort" # Abort on panic
strip = true # Automatically strip symbols from the binary.
opt-level = "z" # Optimize for size.
lto = true # Enable Link Time Optimization
codegen-units = 1 # Reduce number of codegen units to increase optimizations.
panic = "abort" # Abort on panic
strip = true # Automatically strip symbols from the binary.

[dependencies]
ntapi = "0.4.1"

[dependencies.windows]
version = "0.44.0"
version = "0.57.0"
features = [
"Win32_System_Com",
"Win32_UI_Shell_PropertiesSystem",
"Win32_Foundation",
"Win32_Media_Audio",
"Win32_Security",
"Win32_System_Com_StructuredStorage",
"Win32_System_Threading"
"Win32_System_SystemInformation",
"Win32_System_Threading",
"Win32_System_Variant",
"Win32_UI_Shell_PropertiesSystem",
]
44 changes: 37 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,49 @@
# LowAudioLatency

[![Downloads][1]][2] [![GitHub stars][3]][4]

[1]: https://img.shields.io/github/downloads/spddl/LowAudioLatency/total.svg
[2]: https://github.com/spddl/LowAudioLatency/releases "Downloads"

[3]: https://img.shields.io/github/stars/spddl/LowAudioLatency.svg
[4]: https://github.com/spddl/LowAudioLatency/stargazers "GitHub stars"

only a rewrite of the original [miniant-git/REAL](https://github.com/miniant-git/REAL)
## About This Project

LowAudioLatency sets the Windows audio buffer to the smallest possible value, similar to [miniant-git/REAL](https://github.com/miniant-git/REAL). LAL not only checks the output devices (headphones, speakers) but also the input devices (microphones). Additionally, it removes the real-time connection to the first CPU thread, as it is not necessary for this function. If the smallest buffer size is already the default buffer size, the program will terminate.

> [!IMPORTANT]
> Please note that not every audio driver supports this feature, and not all hardware has a driver with this capability.
## Usage

Simply run the executable file to minimize the audio latency for the output and input device:

```
low_audio_latency.exe
```

The program checks and sets the smallest possible buffer size for the default output and input device.
If the smallest buffer size is the default buffer size, the program terminates itself.
You can also specify EDataFlow and ERole yourself with an optional buffer value:

>**If a driver supports small buffer sizes (<10ms buffers), will all applications in Windows 10 automatically use small buffers to render and capture audio?**
```
low_audio_latency.exe eRender,eConsole,336 eCapture,eCommunications,336
```

## Supported parameters

| Name | Description | Required | Allowed values |
| --------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ----------------------------------------------------------------- |
| [EDataFlow](https://learn.microsoft.com/en-us/windows/win32/api/mmdeviceapi/ne-mmdeviceapi-edataflow#constants) | The EDataFlow enumeration defines constants that indicate the direction in which audio data flows between an audio endpoint device and an application. | Yes | Enumeration ID or `eRender`, `eCapture`, or `eAll` |
| [ERole](https://learn.microsoft.com/en-us/windows/win32/api/mmdeviceapi/ne-mmdeviceapi-erole#constants) | The ERole enumeration defines constants that indicate the role that the system has assigned to an audio endpoint device. | Yes | Enumeration ID or `eConsole`, `eMultimedia`, or `eCommunications` |
| [pMinPeriodInFrames](https://learn.microsoft.com/en-us/windows/win32/api/audioclient/nf-audioclient-iaudioclient3-initializesharedaudiostream#parameters) | Periodicity requested by the client. This value must be an integral multiple of the value returned in the <i>pFundamentalPeriodInFrames</i> parameter to <a href="/windows/desktop/api/audioclient/nf-audioclient-iaudioclient3-getsharedmodeengineperiod">IAudioClient3::GetSharedModeEnginePeriod</a>. <i>PeriodInFrames</i> must also be greater than or equal to the value returned in <i>pMinPeriodInFrames</i> and less than or equal to the value returned in <i>pMaxPeriodInFrames</i>. | No | 0 determines the lowest value itself |

> [!Note]
>
>No. By default, all applications in Windows 10 will use 10ms buffers to render and capture audio. If an application needs to use small buffers, then it needs to use the new AudioGraph settings or the WASAPI IAudioClient3 interface, in order to do so. However, if one application in Windows 10 requests the usage of small buffers, then the Audio Engine will start transferring audio using that particular buffer size. In that case, all applications that use the same endpoint and mode will automatically switch to that small buffer size. When the low latency application exits, the Audio Engine will switch to 10ms buffers again.
> ### If a driver supports small buffer sizes, will all applications in Windows 10 and later automatically use small buffers to render and capture audio?
>
> No, by default all applications in Windows 10 and later will use 10-ms buffers to render and capture audio. If an application needs to use small buffers, then it needs to use the new AudioGraph settings or the WASAPI IAudioClient3 interface, in order to do so. However, if one application requests the usage of small buffers, then the audio engine will start transferring audio using that particular buffer size. In that case, all applications that use the same endpoint and mode will automatically switch to that small buffer size. When the low latency application exits, the audio engine will switch to 10-ms buffers again.
>
> quote: [Low-Latency Audio FAQ](https://learn.microsoft.com/en-us/windows-hardware/drivers/audio/low-latency-audio#faq)
## Requirement

quote: https://docs.microsoft.com/en-us/windows-hardware/drivers/audio/low-latency-audio
Windows 10 for the core task [IAudioClient3](https://learn.microsoft.com/en-us/windows/win32/api/audioclient/nn-audioclient-iaudioclient3) and Windows 11 for [ProcessPowerThrottling](https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/ne-processthreadsapi-process_information_class)
27 changes: 27 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,29 @@
ECHO OFF
@REM cargo clean

:loop
CLS

IF exist "%~dp0\target\release\low_audio_latency.exe" (
FOR /F "usebackq" %%A IN ('%~dp0\target\release\low_audio_latency.exe') DO SET /A beforeSize=%%~zA
) ELSE (
SET /A beforeSize=0
)

cargo build --release

FOR /F "usebackq" %%A IN ('%~dp0\target\release\low_audio_latency.exe') DO SET /A size=%%~zA
SET /A diffSize = %size% - %beforeSize%
SET /A size=(%size%/1024)+1
IF "%diffSize%" EQU "0" (
ECHO %size% kb
) ELSE (
IF "%diffSize%" GTR "0" (
ECHO %size% kb [+%diffSize% b]
) ELSE (
ECHO %size% kb [%diffSize% b]
)
)

PAUSE
GOTO loop
1 change: 1 addition & 0 deletions run.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
:loop
CLS

cargo run

PAUSE
Expand Down
Loading

0 comments on commit cad953f

Please sign in to comment.