Struct Server

Source
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

Source

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?
examples/file_playback.rs (line 10)
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 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.

Source

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?
examples/file_playback.rs (line 11)
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 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.

Auto Trait Implementations§

§

impl Freeze for Server

§

impl RefUnwindSafe for Server

§

impl Send for Server

§

impl Sync for Server

§

impl Unpin for Server

§

impl UnwindSafe for Server

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.