Skip to main content

AudioSource

Struct AudioSource 

Source
pub struct AudioSource { /* private fields */ }
Expand description

A raw audio source.

Runs while any clone exists, until its input ends: a file that does not loop, or a push source whose senders are gone. Cheap to clone. Every broadcast it feeds reads all of its samples.

Implementations§

Source§

impl AudioSource

Source

pub async fn microphone(config: Config) -> Result<Self, Error>

Creates a microphone source.

The device opens only when LocalBroadcast::set_audio publishes the source. A failure then shows in that broadcast’s status, and the audio slot stays failed until the next set_audio: a failed microphone is not opened again. The same source set on two broadcasts opens the device twice.

For echo cancellation, set config.aec to the canceller of the speaker’s engine, from playback::Engine::canceller. Only one open microphone attaches to it at a time, and a publication that replaces this one attaches once this one has closed.

Cancellation safe: dropping the future only abandons the device query.

§Errors

Returns Error::Device if no microphone matches the config.

Source

pub fn microphone_unchecked(config: Config) -> Self

Wraps a microphone config without looking for the device.

A missing device then shows only when a broadcast publishes the source.

Source

pub async fn file( path: impl AsRef<Path>, at_end: FileEnd, ) -> Result<Self, Error>

Decodes an audio file in real time.

at_end says whether the source ends with the file or starts it again. Reads WAV, MP3, and the AAC of an MP4 file, which goes through MediaFile::audio. The file is probed before this returns, and decoding starts on its own thread.

Cancellation safe: dropping the future stops the decode thread.

§Errors

Fails if the file cannot be read, holds no audio track, or uses a codec this build cannot decode.

Source

pub fn tone(hz: f32, layout: Layout) -> Result<Self, Error>

Returns a steady sine tone at hz, at 48 kHz in layout.

§Errors

Fails if the thread that generates the tone cannot be started.

Source

pub fn test_pattern(layout: Layout) -> Result<Self, Error>

Returns the beeping tone that goes with VideoSource::test_pattern.

It beeps for a tenth of a second every second, on the timeline the pattern’s marker flashes on, so a viewer can check lip sync.

§Errors

Fails if the thread that generates the tone cannot be started.

Source

pub fn push(format: AudioFormat) -> (FrameSender<Frame>, Self)

Returns a source fed by the returned sender.

The source ends when every sender is dropped. A broadcast that falls more than a few seconds behind loses the oldest frames and counts them in its stats. The sender’s demand is true while a broadcast publishes the source.

Source

pub fn spawn<F>( name: &'static str, format: AudioFormat, run: F, ) -> Result<Self, Error>
where F: FnOnce(FrameSender<Frame>) -> Result<(), Error> + Send + 'static,

Runs run on a dedicated thread named name that feeds the source.

As VideoSource::spawn, for PCM in format. The source ends once run returns and every clone of its sender is dropped. An error of run is logged. run should return once FrameSender::push reports SourceClosed.

§Errors

Fails if the thread cannot be started.

Source

pub fn format(&self) -> Option<AudioFormat>

Returns the format of the samples, or None for a microphone.

A microphone’s format is known only once the publication opens it.

Source

pub fn label(&self) -> &str

Returns a short name of the source, for logs.

Trait Implementations§

Source§

impl Clone for AudioSource

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AudioSource

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more