Struct cubeb::StreamRef

source ·
pub struct StreamRef(/* private fields */);

Implementations§

source§

impl StreamRef

source

pub unsafe fn from_ptr<'a>(ptr: *mut cubeb_stream) -> &'a StreamRef

§Safety

This function is unsafe because it dereferences the given ptr pointer. The caller should ensure that pointer is valid.

source

pub unsafe fn from_ptr_mut<'a>(ptr: *mut cubeb_stream) -> &'a mut StreamRef

§Safety

This function is unsafe because it dereferences the given ptr pointer. The caller should ensure that pointer is valid.

source

pub fn as_ptr(&self) -> *mut cubeb_stream

source§

impl StreamRef

source

pub fn start(&self) -> Result<(), Error>

Start playback.

Examples found in repository?
examples/tone.rs (line 57)
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
fn main() {
    let ctx = common::init("Cubeb tone example").expect("Failed to create cubeb context");

    let params = cubeb::StreamParamsBuilder::new()
        .format(STREAM_FORMAT)
        .rate(SAMPLE_FREQUENCY)
        .channels(1)
        .layout(cubeb::ChannelLayout::MONO)
        .take();

    let mut position = 0u32;

    let mut builder = cubeb::StreamBuilder::<Frame>::new();
    builder
        .name("Cubeb tone (mono)")
        .default_output(&params)
        .latency(0x1000)
        .data_callback(move |_, output| {
            // generate our test tone on the fly
            for f in output.iter_mut() {
                // North American dial tone
                let t1 = (2.0 * PI * 350.0 * position as f32 / SAMPLE_FREQUENCY as f32).sin();
                let t2 = (2.0 * PI * 440.0 * position as f32 / SAMPLE_FREQUENCY as f32).sin();

                f.m = i16::from_float(0.5 * (t1 + t2));

                position += 1;
            }
            output.len() as isize
        })
        .state_callback(|state| {
            println!("stream {:?}", state);
        });

    let stream = builder.init(&ctx).expect("Failed to create cubeb stream");

    stream.start().unwrap();
    thread::sleep(Duration::from_millis(500));
    stream.stop().unwrap();
}
source

pub fn stop(&self) -> Result<(), Error>

Stop playback.

Examples found in repository?
examples/tone.rs (line 59)
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
fn main() {
    let ctx = common::init("Cubeb tone example").expect("Failed to create cubeb context");

    let params = cubeb::StreamParamsBuilder::new()
        .format(STREAM_FORMAT)
        .rate(SAMPLE_FREQUENCY)
        .channels(1)
        .layout(cubeb::ChannelLayout::MONO)
        .take();

    let mut position = 0u32;

    let mut builder = cubeb::StreamBuilder::<Frame>::new();
    builder
        .name("Cubeb tone (mono)")
        .default_output(&params)
        .latency(0x1000)
        .data_callback(move |_, output| {
            // generate our test tone on the fly
            for f in output.iter_mut() {
                // North American dial tone
                let t1 = (2.0 * PI * 350.0 * position as f32 / SAMPLE_FREQUENCY as f32).sin();
                let t2 = (2.0 * PI * 440.0 * position as f32 / SAMPLE_FREQUENCY as f32).sin();

                f.m = i16::from_float(0.5 * (t1 + t2));

                position += 1;
            }
            output.len() as isize
        })
        .state_callback(|state| {
            println!("stream {:?}", state);
        });

    let stream = builder.init(&ctx).expect("Failed to create cubeb stream");

    stream.start().unwrap();
    thread::sleep(Duration::from_millis(500));
    stream.stop().unwrap();
}
source

pub fn position(&self) -> Result<u64, Error>

Get the current stream playback position.

source

pub fn latency(&self) -> Result<u32, Error>

Get the latency for this stream, in frames. This is the number of frames between the time cubeb acquires the data in the callback and the listener can hear the sound.

source

pub fn input_latency(&self) -> Result<u32, Error>

Get the input latency for this stream, in frames. This is the number of frames between the time the audio input device records the audio, and the cubeb callback delivers it. This returns an error if the stream is output-only.

source

pub fn set_volume(&self, volume: f32) -> Result<(), Error>

Set the volume for a stream.

source

pub fn set_name(&self, name: &CStr) -> Result<(), Error>

Change a stream’s name

source

pub fn current_device(&self) -> Result<&DeviceRef, Error>

Get the current output device for this stream.

source

pub fn set_input_mute(&self, mute: bool) -> Result<(), Error>

Set the mute state for an input stream.

source

pub fn set_input_processing_params( &self, params: InputProcessingParams ) -> Result<(), Error>

Set the processing parameters for an input stream.

source

pub fn device_destroy(&self, device: DeviceRef) -> Result<(), Error>

Destroy a cubeb_device structure.

source

pub fn register_device_changed_callback( &self, callback: Option<unsafe extern "C" fn(_: *mut c_void)> ) -> Result<(), Error>

Set a callback to be notified when the output device changes.

source

pub fn user_ptr(&self) -> *mut c_void

Trait Implementations§

source§

impl AsRef<StreamRef> for Stream

source§

fn as_ref(&self) -> &StreamRef

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Borrow<StreamRef> for Stream

source§

fn borrow(&self) -> &StreamRef

Immutably borrows from an owned value. Read more
source§

impl Debug for StreamRef

source§

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

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<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.