Struct BufferNode

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

This node plays a buffer. The output of this node will have as many channels as the buffer does, so connecting it directly to the server will have the desired effect.

This node has no inputs.

Outputs:

indexchannelsdescription
0Depends on the currently playing buffer.The output from the buffer being played.

Implementations§

Source§

impl BufferNode

Source

pub fn new(server: &Server) -> Result<BufferNode>

Creates a new buffer node.

Examples found in repository?
examples/file_playback.rs (line 21)
6fn main() {
7    libaudioverse::initialize().unwrap();
8    
9    // server initialization
10    let server = Server::new().unwrap();
11    server.set_output_device().expect("Could not create default audio device");
12    
13    // create a new buffer
14    let buf = Buffer::new(&server).unwrap();
15    let path = CString::new("test.ogg").unwrap();
16    
17    // load audio data from test.ogg into this buffer
18    buf.load_from_file(&path).unwrap();
19    
20    // create a Buffer node, associate it with the buffer just created, and play it
21    let buf_node = BufferNode::new(&server).unwrap();
22    buf_node.buffer().set(&buf).unwrap();
23    buf_node.connect_server(0).unwrap();
24    
25    // wait for the whole file to finish playing
26    let duration = buf_node.position().get_range().unwrap().1.ceil() as u64;
27    thread::sleep(time::Duration::from_secs(duration));
28    
29    libaudioverse::shutdown().unwrap();
30}
Source

pub fn buffer(&self) -> BufferProperty

Returns the currently playing buffer. Setting this property will reset position.

Examples found in repository?
examples/file_playback.rs (line 22)
6fn main() {
7    libaudioverse::initialize().unwrap();
8    
9    // server initialization
10    let server = Server::new().unwrap();
11    server.set_output_device().expect("Could not create default audio device");
12    
13    // create a new buffer
14    let buf = Buffer::new(&server).unwrap();
15    let path = CString::new("test.ogg").unwrap();
16    
17    // load audio data from test.ogg into this buffer
18    buf.load_from_file(&path).unwrap();
19    
20    // create a Buffer node, associate it with the buffer just created, and play it
21    let buf_node = BufferNode::new(&server).unwrap();
22    buf_node.buffer().set(&buf).unwrap();
23    buf_node.connect_server(0).unwrap();
24    
25    // wait for the whole file to finish playing
26    let duration = buf_node.position().get_range().unwrap().1.ceil() as u64;
27    thread::sleep(time::Duration::from_secs(duration));
28    
29    libaudioverse::shutdown().unwrap();
30}
Source

pub fn ended_count(&self) -> IntProperty

Returns the ended_count property.

Range: [0, MAX_INT]

Default value: 0

Increments every time the buffer reaches it’s end. If the buffer is not looping, this can be used to determine when the buffer is ended, without using the callback. if the buffer is configured to loop, the counter will count up every time the end of a loop is reached. You can write to this property to reset it.

Source

pub fn looping(&self) -> BoolProperty

Returns the looping property.

Default value: False

If true, this node continues playing the same buffer from the beginning after it reaches the end.

Source

pub fn position(&self) -> DoubleProperty

Returns the position property.

Range: dynamic

Default value: 0.0

The position of playback, in seconds. The range of this property corresponds to the total duration of the buffer.

Examples found in repository?
examples/file_playback.rs (line 26)
6fn main() {
7    libaudioverse::initialize().unwrap();
8    
9    // server initialization
10    let server = Server::new().unwrap();
11    server.set_output_device().expect("Could not create default audio device");
12    
13    // create a new buffer
14    let buf = Buffer::new(&server).unwrap();
15    let path = CString::new("test.ogg").unwrap();
16    
17    // load audio data from test.ogg into this buffer
18    buf.load_from_file(&path).unwrap();
19    
20    // create a Buffer node, associate it with the buffer just created, and play it
21    let buf_node = BufferNode::new(&server).unwrap();
22    buf_node.buffer().set(&buf).unwrap();
23    buf_node.connect_server(0).unwrap();
24    
25    // wait for the whole file to finish playing
26    let duration = buf_node.position().get_range().unwrap().1.ceil() as u64;
27    thread::sleep(time::Duration::from_secs(duration));
28    
29    libaudioverse::shutdown().unwrap();
30}
Source

pub fn rate(&self) -> DoubleProperty

Returns the rate property.

Range: [0, INFINITY]

Default value: 1.0

A multiplier that applies to playback rate. 1.0 is identity. Values less than 1.0 cause a decrease in pitch and values greater than 1.0 cause an increase in pitch.

Trait Implementations§

Source§

impl Node for BufferNode

Source§

fn connect(&self, output: i32, destination: &dyn Node, input: i32) -> Result<()>

Connect the specified output of the specified node to the specified input of the specified node. It is an error if this would cause a cycle in the graph of nodes.
Source§

fn connect_property( &self, output: i32, destination: &dyn Node, slot: i32, ) -> Result<()>

Connect a node’s output to an automatable property.
Source§

fn connect_server(&self, output: i32) -> Result<()>

Connect the specified output of the specified node to the server’s input. Any node which is connected directly or indirectly to the server will remain alive even if your program lets go of it. For more details on the subject of node lifetimes, see the Libaudioverse manual.
Source§

fn disconnect( &self, output: i32, destination: &dyn Node, input: i32, ) -> Result<()>

Disconnect the output of the specified node.
Source§

fn get_input_connection_count(&self) -> Result<u32>

Get the number of inputs this node has.
Source§

fn get_output_connection_count(&self) -> Result<u32>

Get the number of outputs this node has.
Source§

fn isolate(&self) -> Result<()>

Equivalent to disconnecting all of the outputs of this node. After a call to isolate, this node will no longer be affecting audio in any way.
Source§

fn reset(&self) -> Result<()>

Reset a node. What this means depends on the node in question. Properties are not touched by node resetting.
Source§

fn add(&self) -> FloatProperty

Returns the add property. Read more
Source§

fn mul(&self) -> FloatProperty

Returns the mul property. Read more
Source§

fn state(&self) -> NodeStateProperty

Returns the state property. 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>,

Source§

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>,

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.