pub struct Alto(/* private fields */);
Expand description
This struct is the entry point of the API. Instantiating it will load an OpenAL implementation. From here, available devices can be queried and opened.
Implementations§
Source§impl Alto
impl Alto
Sourcepub fn load_default() -> AltoResult<Alto>
pub fn load_default() -> AltoResult<Alto>
Load the default OpenAL implementation for the platform. This will prefer OpenAL-Soft if it is present, otherwise it will search for a generic implementation.
Examples found in repository?
More examples
examples/basic.rs (line 6)
5fn run() -> AltoResult<()> {
6 let alto = Alto::load_default()?;
7
8 for s in alto.enumerate_outputs() {
9 println!("Found device: {}", s.to_str().unwrap());
10 }
11
12 let device = alto.open(None)?; // Opens the default audio device
13 let context = device.new_context(None)?; // Creates a default context
14
15 // Configure listener
16 context.set_position([1.0, 4.0, 5.0])?;
17 context.set_velocity([2.5, 0.0, 0.0])?;
18 context.set_orientation(([0.0, 0.0, 1.0], [0.0, 1.0, 0.0]))?;
19
20 let _source = context.new_static_source()?;
21
22 // Now you can load your samples and store them in a buffer with
23 // `context.new_buffer(samples, frequency)`;
24
25 Ok(())
26}
examples/sine.rs (line 8)
7fn main() {
8 let alto = if let Ok(alto) = Alto::load_default() {
9 alto
10 } else {
11 println!("No OpenAL implementation present!");
12 return;
13 };
14
15 println!("Using output: {:?}", alto.default_output().unwrap());
16 let dev = alto.open(None).unwrap();
17 let ctx = dev.new_context(None).unwrap();
18
19 let mut slot = if dev.is_extension_present(alto::ext::Alc::Efx) {
20 println!("Using EFX reverb");
21 if let Ok(slot) = (|| -> AltoResult<_> {
22 let mut slot = ctx.new_aux_effect_slot()?;
23 let mut reverb: efx::EaxReverbEffect = ctx.new_effect()?;
24 reverb.set_preset(&efx::REVERB_PRESET_GENERIC)?;
25 slot.set_effect(&reverb)?;
26 Ok(slot)
27 })() {
28 Some(slot)
29 } else {
30 println!("Broken router detected; disabling EFX");
31 None
32 }
33 } else {
34 println!("EFX not present");
35 None
36 };
37
38 {
39 let buf = ctx.new_buffer(SinWave::new(44_000 / 440, 0.25).render().take(44_000 / 440).collect::<Vec<_>>(), 44_000).unwrap();
40 let buf = Arc::new(buf);
41
42 let mut src = ctx.new_static_source().unwrap();
43 src.set_buffer(buf).unwrap();
44 src.set_looping(true);
45 if let Some(ref mut slot) = slot {
46 src.set_aux_send(0, slot).unwrap();
47 }
48
49 println!("Playing static 440hz sine wave...");
50 src.play();
51
52 std::thread::sleep(std::time::Duration::new(2, 0));
53 }
54
55 std::thread::sleep(std::time::Duration::new(1, 0));
56
57 {
58 let mut wave = SinWave::new(44_000 / 220, 0.25);
59
60 let mut src = ctx.new_streaming_source().unwrap();
61 if let Some(ref mut slot) = slot {
62 src.set_aux_send(0, slot).unwrap();
63 }
64 for _ in 0 .. 5 {
65 let buf = ctx.new_buffer(wave.render().take(44_000 / 10).collect::<Vec<_>>(), 44_000).unwrap();
66 src.queue_buffer(buf).unwrap();
67 }
68
69 println!("Playing streaming 220hz sine wave...");
70 src.play();
71
72 for _ in 0 .. 15 {
73 while src.buffers_processed() == 0 { }
74
75 let mut buf = src.unqueue_buffer().unwrap();
76 buf.set_data(wave.render().take(44_000 / 10).collect::<Vec<_>>(), 44_000).unwrap();
77 src.queue_buffer(buf).unwrap();
78 }
79
80 while src.buffers_processed() < 5 { }
81 }
82
83 std::thread::sleep(std::time::Duration::new(1, 0));
84}
Sourcepub fn load<P: AsRef<Path>>(path: P) -> AltoResult<Alto>
pub fn load<P: AsRef<Path>>(path: P) -> AltoResult<Alto>
Loads a specific OpenAL implementation from a specififed path.
Sourcepub fn default_output(&self) -> Option<CString>
pub fn default_output(&self) -> Option<CString>
alcGetString(ALC_DEFAULT_DEVICE_SPECIFIER)
Examples found in repository?
examples/sine.rs (line 15)
7fn main() {
8 let alto = if let Ok(alto) = Alto::load_default() {
9 alto
10 } else {
11 println!("No OpenAL implementation present!");
12 return;
13 };
14
15 println!("Using output: {:?}", alto.default_output().unwrap());
16 let dev = alto.open(None).unwrap();
17 let ctx = dev.new_context(None).unwrap();
18
19 let mut slot = if dev.is_extension_present(alto::ext::Alc::Efx) {
20 println!("Using EFX reverb");
21 if let Ok(slot) = (|| -> AltoResult<_> {
22 let mut slot = ctx.new_aux_effect_slot()?;
23 let mut reverb: efx::EaxReverbEffect = ctx.new_effect()?;
24 reverb.set_preset(&efx::REVERB_PRESET_GENERIC)?;
25 slot.set_effect(&reverb)?;
26 Ok(slot)
27 })() {
28 Some(slot)
29 } else {
30 println!("Broken router detected; disabling EFX");
31 None
32 }
33 } else {
34 println!("EFX not present");
35 None
36 };
37
38 {
39 let buf = ctx.new_buffer(SinWave::new(44_000 / 440, 0.25).render().take(44_000 / 440).collect::<Vec<_>>(), 44_000).unwrap();
40 let buf = Arc::new(buf);
41
42 let mut src = ctx.new_static_source().unwrap();
43 src.set_buffer(buf).unwrap();
44 src.set_looping(true);
45 if let Some(ref mut slot) = slot {
46 src.set_aux_send(0, slot).unwrap();
47 }
48
49 println!("Playing static 440hz sine wave...");
50 src.play();
51
52 std::thread::sleep(std::time::Duration::new(2, 0));
53 }
54
55 std::thread::sleep(std::time::Duration::new(1, 0));
56
57 {
58 let mut wave = SinWave::new(44_000 / 220, 0.25);
59
60 let mut src = ctx.new_streaming_source().unwrap();
61 if let Some(ref mut slot) = slot {
62 src.set_aux_send(0, slot).unwrap();
63 }
64 for _ in 0 .. 5 {
65 let buf = ctx.new_buffer(wave.render().take(44_000 / 10).collect::<Vec<_>>(), 44_000).unwrap();
66 src.queue_buffer(buf).unwrap();
67 }
68
69 println!("Playing streaming 220hz sine wave...");
70 src.play();
71
72 for _ in 0 .. 15 {
73 while src.buffers_processed() == 0 { }
74
75 let mut buf = src.unqueue_buffer().unwrap();
76 buf.set_data(wave.render().take(44_000 / 10).collect::<Vec<_>>(), 44_000).unwrap();
77 src.queue_buffer(buf).unwrap();
78 }
79
80 while src.buffers_processed() < 5 { }
81 }
82
83 std::thread::sleep(std::time::Duration::new(1, 0));
84}
Sourcepub fn default_capture(&self) -> Option<CString>
pub fn default_capture(&self) -> Option<CString>
alcGetString(ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER)
Sourcepub fn enumerate_outputs(&self) -> Vec<CString>
pub fn enumerate_outputs(&self) -> Vec<CString>
alcGetString(ALC_DEVICE_SPECIFIER)
Examples found in repository?
examples/basic.rs (line 8)
5fn run() -> AltoResult<()> {
6 let alto = Alto::load_default()?;
7
8 for s in alto.enumerate_outputs() {
9 println!("Found device: {}", s.to_str().unwrap());
10 }
11
12 let device = alto.open(None)?; // Opens the default audio device
13 let context = device.new_context(None)?; // Creates a default context
14
15 // Configure listener
16 context.set_position([1.0, 4.0, 5.0])?;
17 context.set_velocity([2.5, 0.0, 0.0])?;
18 context.set_orientation(([0.0, 0.0, 1.0], [0.0, 1.0, 0.0]))?;
19
20 let _source = context.new_static_source()?;
21
22 // Now you can load your samples and store them in a buffer with
23 // `context.new_buffer(samples, frequency)`;
24
25 Ok(())
26}
Sourcepub fn enumerate_captures(&self) -> Vec<CString>
pub fn enumerate_captures(&self) -> Vec<CString>
alcGetString(ALC_CAPTURE_DEVICE_SPECIFIER)
Sourcepub fn open(&self, spec: Option<&CStr>) -> AltoResult<OutputDevice>
pub fn open(&self, spec: Option<&CStr>) -> AltoResult<OutputDevice>
alcOpenDevice()
Examples found in repository?
examples/basic.rs (line 12)
5fn run() -> AltoResult<()> {
6 let alto = Alto::load_default()?;
7
8 for s in alto.enumerate_outputs() {
9 println!("Found device: {}", s.to_str().unwrap());
10 }
11
12 let device = alto.open(None)?; // Opens the default audio device
13 let context = device.new_context(None)?; // Creates a default context
14
15 // Configure listener
16 context.set_position([1.0, 4.0, 5.0])?;
17 context.set_velocity([2.5, 0.0, 0.0])?;
18 context.set_orientation(([0.0, 0.0, 1.0], [0.0, 1.0, 0.0]))?;
19
20 let _source = context.new_static_source()?;
21
22 // Now you can load your samples and store them in a buffer with
23 // `context.new_buffer(samples, frequency)`;
24
25 Ok(())
26}
More examples
examples/sine.rs (line 16)
7fn main() {
8 let alto = if let Ok(alto) = Alto::load_default() {
9 alto
10 } else {
11 println!("No OpenAL implementation present!");
12 return;
13 };
14
15 println!("Using output: {:?}", alto.default_output().unwrap());
16 let dev = alto.open(None).unwrap();
17 let ctx = dev.new_context(None).unwrap();
18
19 let mut slot = if dev.is_extension_present(alto::ext::Alc::Efx) {
20 println!("Using EFX reverb");
21 if let Ok(slot) = (|| -> AltoResult<_> {
22 let mut slot = ctx.new_aux_effect_slot()?;
23 let mut reverb: efx::EaxReverbEffect = ctx.new_effect()?;
24 reverb.set_preset(&efx::REVERB_PRESET_GENERIC)?;
25 slot.set_effect(&reverb)?;
26 Ok(slot)
27 })() {
28 Some(slot)
29 } else {
30 println!("Broken router detected; disabling EFX");
31 None
32 }
33 } else {
34 println!("EFX not present");
35 None
36 };
37
38 {
39 let buf = ctx.new_buffer(SinWave::new(44_000 / 440, 0.25).render().take(44_000 / 440).collect::<Vec<_>>(), 44_000).unwrap();
40 let buf = Arc::new(buf);
41
42 let mut src = ctx.new_static_source().unwrap();
43 src.set_buffer(buf).unwrap();
44 src.set_looping(true);
45 if let Some(ref mut slot) = slot {
46 src.set_aux_send(0, slot).unwrap();
47 }
48
49 println!("Playing static 440hz sine wave...");
50 src.play();
51
52 std::thread::sleep(std::time::Duration::new(2, 0));
53 }
54
55 std::thread::sleep(std::time::Duration::new(1, 0));
56
57 {
58 let mut wave = SinWave::new(44_000 / 220, 0.25);
59
60 let mut src = ctx.new_streaming_source().unwrap();
61 if let Some(ref mut slot) = slot {
62 src.set_aux_send(0, slot).unwrap();
63 }
64 for _ in 0 .. 5 {
65 let buf = ctx.new_buffer(wave.render().take(44_000 / 10).collect::<Vec<_>>(), 44_000).unwrap();
66 src.queue_buffer(buf).unwrap();
67 }
68
69 println!("Playing streaming 220hz sine wave...");
70 src.play();
71
72 for _ in 0 .. 15 {
73 while src.buffers_processed() == 0 { }
74
75 let mut buf = src.unqueue_buffer().unwrap();
76 buf.set_data(wave.render().take(44_000 / 10).collect::<Vec<_>>(), 44_000).unwrap();
77 src.queue_buffer(buf).unwrap();
78 }
79
80 while src.buffers_processed() < 5 { }
81 }
82
83 std::thread::sleep(std::time::Duration::new(1, 0));
84}
Sourcepub fn open_loopback<F: LoopbackFrame>(
&self,
spec: Option<&CStr>,
) -> AltoResult<LoopbackDevice<F>>
pub fn open_loopback<F: LoopbackFrame>( &self, spec: Option<&CStr>, ) -> AltoResult<LoopbackDevice<F>>
alcLoopbackOpenDeviceSOFT()
Requires ALC_SOFT_loopback
Sourcepub fn open_capture<F: StandardFrame>(
&self,
spec: Option<&CStr>,
freq: ALCuint,
len: ALCsizei,
) -> AltoResult<Capture<F>>
pub fn open_capture<F: StandardFrame>( &self, spec: Option<&CStr>, freq: ALCuint, len: ALCsizei, ) -> AltoResult<Capture<F>>
alcCaptureOpenDevice()
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Alto
impl RefUnwindSafe for Alto
impl Send for Alto
impl Sync for Alto
impl Unpin for Alto
impl UnwindSafe for Alto
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more