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:
index | channels | description |
---|---|---|
0 | Depends on the currently playing buffer. | The output from the buffer being played. |
Implementations§
Source§impl BufferNode
impl BufferNode
Sourcepub fn new(server: &Server) -> Result<BufferNode>
pub fn new(server: &Server) -> Result<BufferNode>
Creates a new buffer node.
Examples found in repository?
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}
Sourcepub fn buffer(&self) -> BufferProperty
pub fn buffer(&self) -> BufferProperty
Returns the currently playing buffer. Setting this property will reset position.
Examples found in repository?
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}
Sourcepub fn ended_count(&self) -> IntProperty
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.
Sourcepub fn looping(&self) -> BoolProperty
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.
Sourcepub fn position(&self) -> DoubleProperty
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?
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}
Sourcepub fn rate(&self) -> DoubleProperty
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.