pub struct AudioDeviceManager { /* private fields */ }
Expand description

Manages the state of an audio device.

Implementations§

source§

impl AudioDeviceManager

source

pub fn new() -> Self

Create a new AudioDeviceManager.

Examples found in repository?
examples/audio_callback.rs (line 80)
79
80
81
82
83
84
85
86
87
88
fn main() -> Result<()> {
    let mut device_manager = AudioDeviceManager::new();
    device_manager.initialise(0, 2)?;

    let _handle = device_manager.add_audio_callback(AudioCallback::default());

    sleep(Duration::from_secs(2));

    Ok(())
}
More examples
Hide additional examples
examples/devices.rs (line 7)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
fn main() -> Result<()> {
    let mut audio_device_manager = AudioDeviceManager::new();
    audio_device_manager.initialise(2, 2)?;

    let device_type = audio_device_manager.current_device_type().unwrap();

    println!("Inputs:");
    for input in device_type.input_devices() {
        println!("  {}", input);
    }

    println!("Outputs:");
    for output in device_type.output_devices() {
        println!("  {}", output);
    }

    Ok(())
}
examples/test_tone.rs (line 10)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
fn main() -> Result<()> {
    let mut audio_device_manager = AudioDeviceManager::new();
    audio_device_manager.initialise(0, 2)?;

    {
        let mut device = audio_device_manager.current_device().unwrap();

        println!("Name: {}", device.name());
        println!("Type: {}", device.type_name());
        println!("Sample rate: {}", device.sample_rate());
        println!("Buffer size: {}", device.buffer_size());
        println!(
            "Available sample rates: {:?}",
            device.available_sample_rates()
        );
        println!(
            "Available buffer sizes: {:?}",
            device.available_buffer_sizes()
        );
    }

    audio_device_manager.play_test_sound();
    sleep(Duration::from_secs(1));

    Ok(())
}
source

pub fn initialise(
&mut self,
input_channels: usize,
output_channels: usize
) -> Result<()>

Resets to a default device setup.

Examples found in repository?
examples/audio_callback.rs (line 81)
79
80
81
82
83
84
85
86
87
88
fn main() -> Result<()> {
    let mut device_manager = AudioDeviceManager::new();
    device_manager.initialise(0, 2)?;

    let _handle = device_manager.add_audio_callback(AudioCallback::default());

    sleep(Duration::from_secs(2));

    Ok(())
}
More examples
Hide additional examples
examples/devices.rs (line 8)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
fn main() -> Result<()> {
    let mut audio_device_manager = AudioDeviceManager::new();
    audio_device_manager.initialise(2, 2)?;

    let device_type = audio_device_manager.current_device_type().unwrap();

    println!("Inputs:");
    for input in device_type.input_devices() {
        println!("  {}", input);
    }

    println!("Outputs:");
    for output in device_type.output_devices() {
        println!("  {}", output);
    }

    Ok(())
}
examples/test_tone.rs (line 11)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
fn main() -> Result<()> {
    let mut audio_device_manager = AudioDeviceManager::new();
    audio_device_manager.initialise(0, 2)?;

    {
        let mut device = audio_device_manager.current_device().unwrap();

        println!("Name: {}", device.name());
        println!("Type: {}", device.type_name());
        println!("Sample rate: {}", device.sample_rate());
        println!("Buffer size: {}", device.buffer_size());
        println!(
            "Available sample rates: {:?}",
            device.available_sample_rates()
        );
        println!(
            "Available buffer sizes: {:?}",
            device.available_buffer_sizes()
        );
    }

    audio_device_manager.play_test_sound();
    sleep(Duration::from_secs(1));

    Ok(())
}
source

pub fn audio_device_setup(&self) -> AudioDeviceSetup

Get the current device setup.

source

pub fn set_audio_device_setup(&mut self, setup: &AudioDeviceSetup)

Changes the current device or its settings.

source

pub fn play_test_sound(&mut self)

Play a test sound.

Examples found in repository?
examples/test_tone.rs (line 30)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
fn main() -> Result<()> {
    let mut audio_device_manager = AudioDeviceManager::new();
    audio_device_manager.initialise(0, 2)?;

    {
        let mut device = audio_device_manager.current_device().unwrap();

        println!("Name: {}", device.name());
        println!("Type: {}", device.type_name());
        println!("Sample rate: {}", device.sample_rate());
        println!("Buffer size: {}", device.buffer_size());
        println!(
            "Available sample rates: {:?}",
            device.available_sample_rates()
        );
        println!(
            "Available buffer sizes: {:?}",
            device.available_buffer_sizes()
        );
    }

    audio_device_manager.play_test_sound();
    sleep(Duration::from_secs(1));

    Ok(())
}
source

pub fn device_types(&mut self) -> Vec<impl AudioIODeviceType + '_>

Get the available device types.

source

pub fn current_device_type(&self) -> Option<impl AudioIODeviceType + '_>

Get the current device type.

Examples found in repository?
examples/devices.rs (line 10)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
fn main() -> Result<()> {
    let mut audio_device_manager = AudioDeviceManager::new();
    audio_device_manager.initialise(2, 2)?;

    let device_type = audio_device_manager.current_device_type().unwrap();

    println!("Inputs:");
    for input in device_type.input_devices() {
        println!("  {}", input);
    }

    println!("Outputs:");
    for output in device_type.output_devices() {
        println!("  {}", output);
    }

    Ok(())
}
source

pub fn current_device(&self) -> Option<impl AudioIODevice + '_>

Get the current AudioIODevice.

Examples found in repository?
examples/test_tone.rs (line 14)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
fn main() -> Result<()> {
    let mut audio_device_manager = AudioDeviceManager::new();
    audio_device_manager.initialise(0, 2)?;

    {
        let mut device = audio_device_manager.current_device().unwrap();

        println!("Name: {}", device.name());
        println!("Type: {}", device.type_name());
        println!("Sample rate: {}", device.sample_rate());
        println!("Buffer size: {}", device.buffer_size());
        println!(
            "Available sample rates: {:?}",
            device.available_sample_rates()
        );
        println!(
            "Available buffer sizes: {:?}",
            device.available_buffer_sizes()
        );
    }

    audio_device_manager.play_test_sound();
    sleep(Duration::from_secs(1));

    Ok(())
}
source

pub fn add_audio_callback(
&mut self,
callback: impl AudioIODeviceCallback + 'static
) -> AudioCallbackHandle<'_>

Registers an audio callback.

When the returned AudioCallbackHandle is dropped the callback is removed.

Examples found in repository?
examples/audio_callback.rs (line 83)
79
80
81
82
83
84
85
86
87
88
fn main() -> Result<()> {
    let mut device_manager = AudioDeviceManager::new();
    device_manager.initialise(0, 2)?;

    let _handle = device_manager.add_audio_callback(AudioCallback::default());

    sleep(Duration::from_secs(2));

    Ok(())
}
source

pub fn add_audio_device_type(
&mut self,
device_type: impl AudioIODeviceType + 'static
)

Registers an audio device type.

source

pub fn set_current_audio_device_type(&mut self, device_type: &str)

Set the current audio device type to use.

Trait Implementations§

source§

impl Default for AudioDeviceManager

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Send for AudioDeviceManager

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere
T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere
T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere
T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere
U: From<T>,

const: unstable · 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 Twhere
U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere
U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.