pub struct Server { /* private fields */ }
Expand description
Represents a server, the main entry point to Libaudioverse. All libaudioverse nodes must be passed a server at creation time as the first argument to their constructor and cannot migrate between them. Furthermore, it is an error to try to connect objects from different servers. By default, Libaudioverse will use one thread per core on the current system for audio mixing. This may be changed via Lav_serverSetThreads. For full details of this class, see the Libaudioverse manual.
Implementations§
Source§impl Server
impl Server
Sourcepub fn new() -> Result<Server>
pub fn new() -> Result<Server>
Creates a new server with a default sampling rate of 44,100 and a block size of 1024. This is sufficient and performant for most applications.
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 construct(sampling_rate: u32, block_size: u32) -> Result<Server>
pub fn construct(sampling_rate: u32, block_size: u32) -> Result<Server>
create a new server with the specified sampling rate and block size. The block size is the number of samples to process at once, and must be a multiple of 4.
Sourcepub fn set_output_device(&self) -> Result<()>
pub fn set_output_device(&self) -> Result<()>
Set the output of the server to the system’s default audio device with 2 channels and 2 mixahead.
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 set_output_device_details(
&self,
identifier: &CString,
channels: i32,
mixahead: i32,
) -> Result<()>
pub fn set_output_device_details( &self, identifier: &CString, channels: i32, mixahead: i32, ) -> Result<()>
Set the output device of the server. Use the literal string “default” for the default audio device. Note that it is possible to change the output device of a server even after it has been set. After the output device has been set, calls to Lav_serverGetBlock will error.