michaelwa

michaelwa

I am running through the initial membrane tutorial:

I have installed the two required libraries:

❯ apt list --installed | grep "libmad0-dev"
libmad0-dev/focal,now 0.15.1b-10ubuntu1 amd64 [installed]

❯ apt list --installed | grep "portaudio19-dev"
portaudio19-dev/focal,now 19.6.0-1build1 amd64 [installed]

I started an iex session and ran the code snippet code in separate blocks. All is well until the last block calling “start_link”, then there is a warning and an error:

7:14:06.609 [warning] The on_load function for module Elixir.Membrane.PortAudio.Sink.Native.Nif returned:
{%RuntimeError{
   message: "Bundlex cannot load nif :sink of app :membrane_portaudio_plugin\nfrom \"/home/michael_intandem/.cache/mix/installs/elixir-1.16.0-erts-14.1.1/296ba109bd28b18599af0e6d5e8838bb/_build/dev/lib/membrane_portaudio_plugin/priv/bundlex/nif/sink\", check bundlex.exs file for information about nifs.\nReason: :load_failed, Failed to load NIF library /home/michael_intandem/.cache/mix/installs/elixir-1.16.0-erts-14.1.1/296ba109bd28b18599af0e6d5e8838bb/_build/dev/lib/membrane_portaudio_plugin/priv/bundlex/nif/sink: 'libssl.so.3: cannot open shared object file: No such file or directory'\n"
 },
 [
   {Membrane.PortAudio.Sink.Native.Nif, :load_nif, 0,
    [
      file: ~c"lib/membrane_portaudio_plugin/sink_native.ex",
      line: 1,
      error_info: %{...}
    ]},
   {:code_server, :"-handle_on_load/5-fun-0-", 1,
    [file: ~c"code_server.erl", line: 1398]}
 ]}


07:14:06.586 [error] Process #PID<0.313.0> raised an exception
** (RuntimeError) Bundlex cannot load nif :sink of app :membrane_portaudio_plugin
from "/home/michael_intandem/.cache/mix/installs/elixir-1.16.0-erts-14.1.1/296ba109bd28b18599af0e6d5e8838bb/_build/dev/lib/membrane_portaudio_plugin/priv/bundlex/nif/sink", check bundlex.exs file for information about nifs.
Reason: :load_failed, Failed to load NIF library /home/michael_intandem/.cache/mix/installs/elixir-1.16.0-erts-14.1.1/296ba109bd28b18599af0e6d5e8838bb/_build/dev/lib/membrane_portaudio_plugin/priv/bundlex/nif/sink: 'libssl.so.3: cannot open shared object file: No such file or directory'

    (membrane_portaudio_plugin 0.18.3) lib/membrane_portaudio_plugin/sink_native.ex:1: Membrane.PortAudio.Sink.Native.Nif.load_nif/0
    (kernel 9.1) code_server.erl:1398: anonymous fn/1 in :code_server.handle_on_load/5

I am running:

❯ asdf current
elixir          1.16.0-otp-26   /home/michael/.tool-versions
erlang          26.1.2          /home/michael/.tool-versions

I also tried an earlier 1.15 version with the same result.

Showing Posts 1 to 9

BradS2S

BradS2S

Here’s something that I got to work in IEx. (It is up to step 3.)

# Run as: iex --dot-iex path/to/notebook.exs

# Title: Membrane tutorial

Mix.install([
  :membrane_hackney_plugin,
  :membrane_mp3_mad_plugin,
  :membrane_portaudio_plugin
])

# ── Section ──

defmodule VolumeKnob do
  @moduledoc """
  Membrane filter that changes the audio volume
  by the gain passed via options.
  """
  use Membrane.Filter

  alias Membrane.RawAudio

  def_input_pad(:input, accepted_format: RawAudio, flow_control: :auto)
  def_output_pad(:output, accepted_format: RawAudio, flow_control: :auto)

  def_options(
    gain: [
      spec: float(),
      description: """
      The factor by which the volume will be changed.

      A gain smaller than 1 reduces the volume and gain
      greater than 1 increases it.
      """
    ]
  )

  @impl true
  def handle_init(_ctx, options) do
    {[], %{gain: options.gain}}
  end

  @impl true
  def handle_buffer(:input, buffer, ctx, state) do
    stream_format = ctx.pads.input.stream_format
    sample_size = RawAudio.sample_size(stream_format)

    payload =
      for <<sample::binary-size(sample_size) <- buffer.payload>>, into: <<>> do
        value = RawAudio.sample_to_value(sample, stream_format)
        scaled_value = round(value * state.gain)
        RawAudio.value_to_sample(scaled_value, stream_format)
      end

    buffer = %Membrane.Buffer{buffer | payload: payload}
    {[buffer: {:output, buffer}], state}
  end
end

defmodule MyPipeline do
  use Membrane.Pipeline

  @impl true
  def handle_init(_ctx, path_to_mp3) do
    spec =
      child(%Membrane.Hackney.Source{
        location: path_to_mp3,
        hackney_opts: [follow_redirect: true]
      })
      |> via_out(:output)
      |> via_in(:input)
      |> child(Membrane.MP3.MAD.Decoder)
      |> via_out(:output)
      |> via_in(:input)
      |> child(%VolumeKnob{gain: 0.9})
      |> via_out(:output)
      |> via_in(:input)
      |> child(Membrane.PortAudio.Sink)

    {[spec: spec], %{}}
  end
end

mp3_url =
  "https://raw.githubusercontent.com/membraneframework/membrane_demo/master/simple_pipeline/sample.mp3"

Membrane.Pipeline.start_link(MyPipeline, mp3_url)

Also, if you haven’t had a chance to check out LiveBook, it’s an amazing notebook like Jupyter is for Python. Great option for stuff you might be reaching for iex atm.

I was able to get it working in LiveBook as well. Here’s a link to download it.

MacOS 13.4.1 (c) (22F770820d)
Erlang/OTP 26 [erts-14.2.1] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [jit:ns] [dtrace]
Elixir 1.16.0 (compiled with Erlang/OTP 26)
michaelwa

michaelwa OP

Thanks for the quick reply!

I started this effort in LiveBook but got the same error there. I removed LiveBook as a layer of complexity and went with iex route.

I downloaded your LiveBook file and run it with the same result.

10:38:00.771 [error] Process #PID<0.435.0> on node :"nejwjxlb-livebook_a4punmsz@hermes" raised an exception
** (RuntimeError) Bundlex cannot load nif :sink of app :membrane_portaudio_plugin
from "/home/michael_intandem/.cache/mix/installs/elixir-1.16.0-erts-14.1.1/296ba109bd28b18599af0e6d5e8838bb/_build/dev/lib/membrane_portaudio_plugin/priv/bundlex/nif/sink", check bundlex.exs file for information about nifs.
Reason: :load_failed, Failed to load NIF library /home/michael_intandem/.cache/mix/installs/elixir-1.16.0-erts-14.1.1/296ba109bd28b18599af0e6d5e8838bb/_build/dev/lib/membrane_portaudio_plugin/priv/bundlex/nif/sink: 'libssl.so.3: cannot open shared object file: No such file or directory'

    (membrane_portaudio_plugin 0.18.3) lib/membrane_portaudio_plugin/sink_native.ex:1: Membrane.PortAudio.Sink.Native.Nif.load_nif/0
    (kernel 9.1) code_server.erl:1398: anonymous fn/1 in :code_server.handle_on_load/5

10:38:00.772 [warning] The on_load function for module Elixir.Membrane.PortAudio.Sink.Native.Nif returned:
{%RuntimeError{
   message: "Bundlex cannot load nif :sink of app :membrane_portaudio_plugin\nfrom \"/home/michael_intandem/.cache/mix/installs/elixir-1.16.0-erts-14.1.1/296ba109bd28b18599af0e6d5e8838bb/_build/dev/lib/membrane_portaudio_plugin/priv/bundlex/nif/sink\", check bundlex.exs file for information about nifs.\nReason: :load_failed, Failed to load NIF library /home/michael_intandem/.cache/mix/installs/elixir-1.16.0-erts-14.1.1/296ba109bd28b18599af0e6d5e8838bb/_build/dev/lib/membrane_portaudio_plugin/priv/bundlex/nif/sink: 'libssl.so.3: cannot open shared object file: No such file or directory'\n"
 },
 [
   {Membrane.PortAudio.Sink.Native.Nif, :load_nif, 0,
    [
      file: ~c"lib/membrane_portaudio_plugin/sink_native.ex",
      line: 1,
      error_info: %{...}
    ]},
   {:code_server, :"-handle_on_load/5-fun-0-", 1,
    [file: ~c"code_server.erl", line: 1398]}
 ]}

I am on Pop_OS! (Ubuntu) 20.04.

Are you using “asdf” for your elixir and erlang installs?

BradS2S

BradS2S

I do use asdf..
So it looks like you are missing a file that the plugin needs to compile the sink NIF: libssl.so.3

Looks like you want the ssl3 package

sudo apt-get install libssl3-dev

michaelwa

michaelwa OP

I have not forgotten about your post. The day job is just in the way at the moment; preventing additionally testing.

BradS2S

BradS2S

haha not taking it personal at all

mat-hek

mat-hek

Membrane Core Team

@michaelwa can you check whether functions from the :crypto module work for you? If so, we probably fail to find OpenSSL. If not, it’s indeed missing, but we probably can emit a better error. Anyway, installing OpenSSL may indeed help :wink:

michaelwa

michaelwa OP

I think the root of the problem is my OS version. It is an Ubuntu 20.04 derivative (Pop_OS! 20.04). I do have openssl installed but it is version 1.1.1.

❯ openssl version
OpenSSL 1.1.1f 31 Mar 2020

The missing file, libssl.so.3, is part of the openssl3-dev package and does not seem to be compatible with this version of Ubuntu.

I think I am out of luck until I can upgrade the OS.

mat-hek

mat-hek

Membrane Core Team

As a workaround, you can opt out of precompiled PortAudio by putting this into config.exs:

config :bundlex, :disable_precompiled_os_deps, apps: [:membrane_portaudio_plugin]

and installing PortAudio manually with

sudo apt-get install alsa portaudio19-dev

I suppose it could work with Openssl 1.1 though, I’ll try to figure it out

mat-hek

mat-hek

Membrane Core Team

Ok, so it seems possible to make it work with OpenSSL 1.1, however, Ubuntu 20.04 uses an old version of GlibC as well, which is harder to support. Thus, it seems that until you upgrade the OS, you need to disable the precompiled deps completely:

config :bundlex, :disable_precompiled_os_deps, true

^ This is possible since the latest release of Bundlex, 1.4.5, so make sure it’s up to date. Then, install all the dependencies manually. For the example in the tutorial, you’ll need:

sudo apt install pkg-config alsa portaudio19-dev libmad0-dev
— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New
dillonoconnor
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New
thiagogsr
** (ArgumentError) expected :max_attempts to be a positive integer, got: {:@, [line: 10, column: 19], [{:max_attempts, [line: 10, column:...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews