pub struct AudioFrameProducer<T> {
    pub buffer: AudioBuffer<T>,
    /* private fields */
}
Expand description

Allows relaying rendered AudioBuffer to the AudioFrameConsumer.

Fields§

§buffer: AudioBuffer<T>

The next audio buffer frame to render samples to.

Implementations§

Creates a new instance of AudioFrameProducer.

Prefer to use create_carousel instead.

Examples found in repository?
src/carousel.rs (line 121)
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
pub fn create_carousel<T>(latency: usize, sample_frames: usize, channels: u8) ->
                                                (AudioFrameProducer<T>, AudioFrameConsumer<T>)
where T: 'static + AudioSample + Send
{
    // let sample_frames = (sample_rate as f64 * frame_duration).ceil() as usize;
    let buffer = AudioBuffer::<T>::new(sample_frames, channels);
    let (producer_tx, producer_rx) = channel::<AudioBuffer<T>>();
    let (consumer_tx, consumer_rx) = channel::<AudioBuffer<T>>();
    // if latency > 0 {
        // Add some frame buffers into circulation
        // for _ in 0..latency {
            producer_tx.send(buffer.clone()).unwrap(); // infallible
        // }
        for _ in 0..latency {
            consumer_tx.send(buffer.clone()).unwrap(); // infallible
        }
        // }
    // }
    let producer = AudioFrameProducer::new(buffer.clone(), consumer_tx, producer_rx);
    let consumer = AudioFrameConsumer::new(buffer, producer_tx, consumer_rx);
    (producer, consumer)
}

Provides the current frame buffer as Vec of samples for rendering via a closure.

The closure should ensure the size of the Vec is resized to the number of actually rendered samples.

Sends the audio frame buffer to the AudioFrameConsumer and replaces it with a recycled buffer received back from AudioFrameConsumer.

This method will block if the recycled buffer queue is empty.

Returns Err(AudioFrameError) only when sending or receiving buffers failed, which is possible only when the remote end has disconnected.

Examples found in repository?
src/host/cpal.rs (line 108)
105
106
107
108
109
110
111
112
    pub fn send_frame(&mut self) -> AudioFrameResult<()> {
        use AudioHandleAnyFormat::*;
        match self {
            I16(audio) => audio.producer.send_frame(),
            U16(audio) => audio.producer.send_frame(),
            F32(audio) => audio.producer.send_frame(),
        }
    }

Trait Implementations§

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Convert to S a sample type from self.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.