Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add low latency section to readme #59

Merged
merged 2 commits into from
Jun 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The plugin that captures and plays sound using the multiplatform PortAudio libra
Add the following line to your `deps` in `mix.exs`. Run `mix deps.get`.

```elixir
{:membrane_portaudio_plugin, "~> 0.19.2"}
{:membrane_portaudio_plugin, "~> 0.19.2"}
```

This package depends on the [PortAudio](http://portaudio.com/) library. The precompiled build will be pulled and linked automatically. However, should there be any problems, consider installing it manually.
Expand Down Expand Up @@ -52,7 +52,7 @@ The `mix pa_devices` task prints available audio devices and their IDs, which yo
The pipeline below should play a raw file to a default output device.

```elixir
defmodule Membrane.ReleaseTest.Pipeline do
defmodule Example.Pipeline do
use Membrane.Pipeline

alias Membrane.PortAudio
Expand All @@ -66,12 +66,15 @@ defmodule Membrane.ReleaseTest.Pipeline do
{[spec: structure], %{}}
end
end

Membrane.Pipeline.start_link(Example.Pipeline)
Process.sleep(:infinity)
```

And this one should forward sound from the default input to the default output. DO NOT USE WITHOUT HEADPHONES to avoid audio feedback.

```elixir
defmodule Membrane.ReleaseTest.Pipeline do
defmodule Example.Pipeline do
use Membrane.Pipeline

alias Membrane.PortAudio
Expand All @@ -85,9 +88,24 @@ defmodule Membrane.ReleaseTest.Pipeline do
{[spec: structure], %{}}
end
end

Membrane.Pipeline.start_link(Example.Pipeline)
Process.sleep(:infinity)
```

### Low latency

To reduce the latency of the sink and/or source, you can:
- set the `latency` option to `:low` to configure the sound card in the low latency mode,
- reduce the `portaudio_buffer_size` to make PortAudio produce/consume smaller audio chunks,

for example:

```elixir
child(:pa_src, %PortAudio.Source{latency: :low, portaudio_buffer_size: 32})
|> child(:pa_sink, %PortAudio.Sink{latency: :low, portaudio_buffer_size: 32})
```

_***Note***: the endpoint_id option was recently renamed to device_id to be more in line with PortAudio's API._
## Testing

Tests contain some cases that use PortAudio stuff instead of mocking. Such cases require the presence of at least one input and output sound card, thus they are disabled by default. To enable them, run
Expand Down