pub struct StreamRef(/* private fields */);
Implementations§
source§impl StreamRef
impl StreamRef
sourcepub unsafe fn from_ptr<'a>(ptr: *mut cubeb_stream) -> &'a StreamRef
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.
sourcepub unsafe fn from_ptr_mut<'a>(ptr: *mut cubeb_stream) -> &'a mut StreamRef
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.
pub fn as_ptr(&self) -> *mut cubeb_stream
source§impl StreamRef
impl StreamRef
sourcepub fn start(&self) -> Result<(), Error>
pub fn start(&self) -> Result<(), Error>
Start playback.
Examples found in repository?
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(¶ms)
.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();
}
sourcepub fn stop(&self) -> Result<(), Error>
pub fn stop(&self) -> Result<(), Error>
Stop playback.
Examples found in repository?
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(¶ms)
.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();
}
sourcepub fn latency(&self) -> Result<u32, Error>
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.
sourcepub fn input_latency(&self) -> Result<u32, Error>
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.
sourcepub fn current_device(&self) -> Result<&DeviceRef, Error>
pub fn current_device(&self) -> Result<&DeviceRef, Error>
Get the current output device for this stream.
sourcepub fn set_input_mute(&self, mute: bool) -> Result<(), Error>
pub fn set_input_mute(&self, mute: bool) -> Result<(), Error>
Set the mute state for an input stream.
sourcepub fn set_input_processing_params(
&self,
params: InputProcessingParams
) -> Result<(), Error>
pub fn set_input_processing_params( &self, params: InputProcessingParams ) -> Result<(), Error>
Set the processing parameters for an input stream.
sourcepub fn device_destroy(&self, device: DeviceRef) -> Result<(), Error>
pub fn device_destroy(&self, device: DeviceRef) -> Result<(), Error>
Destroy a cubeb_device structure.
sourcepub fn register_device_changed_callback(
&self,
callback: Option<unsafe extern "C" fn(_: *mut c_void)>
) -> Result<(), Error>
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.