Struct AudioSource
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§
§impl AudioSource
impl AudioSource
pub async fn microphone(config: Config) -> Result<AudioSource, Error>
pub async fn microphone(config: Config) -> Result<AudioSource, 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.
pub fn microphone_unchecked(config: Config) -> AudioSource
pub fn microphone_unchecked(config: Config) -> AudioSource
Wraps a microphone config without looking for the device.
A missing device then shows only when a broadcast publishes the source.
pub async fn file(
path: impl AsRef<Path>,
at_end: FileEnd,
) -> Result<AudioSource, Error>
pub async fn file( path: impl AsRef<Path>, at_end: FileEnd, ) -> Result<AudioSource, 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.
pub fn tone(hz: f32, layout: Layout) -> Result<AudioSource, Error>
pub fn tone(hz: f32, layout: Layout) -> Result<AudioSource, 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.
pub fn test_pattern(layout: Layout) -> Result<AudioSource, Error>
pub fn test_pattern(layout: Layout) -> Result<AudioSource, 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.
pub fn push(format: AudioFormat) -> (FrameSender<Frame>, AudioSource)
pub fn push(format: AudioFormat) -> (FrameSender<Frame>, AudioSource)
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.
pub fn spawn<F>(
name: &'static str,
format: AudioFormat,
run: F,
) -> Result<AudioSource, Error>
pub fn spawn<F>( name: &'static str, format: AudioFormat, run: F, ) -> Result<AudioSource, Error>
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.
pub fn format(&self) -> Option<AudioFormat>
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.
Trait Implementations§
§impl Clone for AudioSource
impl Clone for AudioSource
§fn clone(&self) -> AudioSource
fn clone(&self) -> AudioSource
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more