A host backend for tests: config :mob_audio_io, backend: MobAudioIo.Fake.
It keeps streams in an Agent and answers like a device does:
open/3sends the owner{:mob_audio_io, :started, stream, info}andclose/1sends:stopped. Output, input and duplex all open; input and duplex answer{:error, :permission}afterdeny_permission/0.status/0reports 48 kHz streams with 192-frame callbacks whosecallbacksandframesgrow with wall time, soMobAudioIo.SelfTest-style checks work; inputs report the level set withset_input_level/2.devices/1lists a built-in mic and speaker unlessset_devices/2replaced them.decode_stream/3decodes WAV files (16-, 24- and 32-bit PCM, 32-bit float) in Elixir, in a process per decode that sends the owner what a device's decode thread sends::decode_started,:decodedchunks within the window (waiting fordecode_ack/2), the end; with the same options (mono,max_ms), errors,decode_cancel/1and the owner's exit. With aprocessor:(a name here) no chunks are sent, as on a device where the processor takes them.MobAudioIo.decode/2runs on it.- Processors are the built-ins plus whatever
register_processor/1added.
To drive a screen through what the hardware would do, inject/3 sends
the stream's owner any message (:device_lost, :interrupted, :xrun,
:post, ...), as Mob.Test.send_message/2 would.
State is global (one Agent): use it from async: false tests and call
reset/0 in setup.
Summary
Functions
Returns a specification to start this module under a supervisor.
Input and duplex opens answer {:error, :permission} until reset/0.
The next open/3 answers {:error, reason}.
Send the stream's owner {:mob_audio_io, kind, stream, payload}.
Make name openable, as an app's mai_register would.
Back to no streams or decodes, the built-in processors and devices, the permission granted, no queued failure.
What devices(direction) lists.
The input level (dBFS) an input or duplex stream's status reports.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec deny_permission() :: :ok
Input and duplex opens answer {:error, :permission} until reset/0.
@spec fail_next_open(term()) :: :ok
The next open/3 answers {:error, reason}.
@spec inject(MobAudioIo.stream(), atom(), term()) :: :ok | {:error, :not_open}
Send the stream's owner {:mob_audio_io, kind, stream, payload}.
@spec register_processor(String.t()) :: :ok
Make name openable, as an app's mai_register would.
@spec reset() :: :ok
Back to no streams or decodes, the built-in processors and devices, the permission granted, no queued failure.
@spec set_devices(:input | :output, [map()]) :: :ok
What devices(direction) lists.
@spec set_input_level(MobAudioIo.stream(), float()) :: :ok
The input level (dBFS) an input or duplex stream's status reports.