pub struct DeferLock<'c> { /* private fields */ }
Expand description
An RAII lock that will suspend state updates while held. When this lock is dropped, the context will apply all pending updates.
Methods from Deref<Target = Context>§
Sourcepub fn as_raw(&self) -> *mut ALCcontext
pub fn as_raw(&self) -> *mut ALCcontext
Raw context pointer as provided by OpenAL.
Sourcepub fn is_extension_present(&self, ext: Al) -> bool
pub fn is_extension_present(&self, ext: Al) -> bool
alIsExtensionPresent()
Sourcepub fn distance_model(&self) -> DistanceModel
pub fn distance_model(&self) -> DistanceModel
alGetInteger(AL_DISTANCE_MODEL)
Sourcepub fn set_distance_model(&self, value: DistanceModel)
pub fn set_distance_model(&self, value: DistanceModel)
alDistanceModel()
Sourcepub fn using_source_distance_model(&self) -> bool
pub fn using_source_distance_model(&self) -> bool
alIsEnabled(AL_SOURCE_DISTANCE_MODEL)
Requires AL_EXT_source_distance_model
Sourcepub fn use_source_distance_model(&self, value: bool) -> AltoResult<()>
pub fn use_source_distance_model(&self, value: bool) -> AltoResult<()>
alEnable/alDisable(AL_SOURCE_DISTANCE_MODEL)
Requires AL_EXT_source_distance_model
Sourcepub fn doppler_factor(&self) -> f32
pub fn doppler_factor(&self) -> f32
alGetFloat(AL_DOPPLER_FACTOR)
Sourcepub fn set_doppler_factor(&self, value: f32) -> AltoResult<()>
pub fn set_doppler_factor(&self, value: f32) -> AltoResult<()>
alDopplerFactor()
Sourcepub fn speed_of_sound(&self) -> f32
pub fn speed_of_sound(&self) -> f32
alGetFloat(AL_SPEED_OF_SOUND)
Sourcepub fn set_speed_of_sound(&self, value: f32) -> AltoResult<()>
pub fn set_speed_of_sound(&self, value: f32) -> AltoResult<()>
alSpeedOfSound()
Sourcepub fn set_gain(&self, value: f32) -> AltoResult<()>
pub fn set_gain(&self, value: f32) -> AltoResult<()>
alListenerf(AL_GAIN)
Sourcepub fn set_position<V: Into<[f32; 3]>>(&self, value: V) -> AltoResult<()>
pub fn set_position<V: Into<[f32; 3]>>(&self, value: V) -> AltoResult<()>
alListenerfv(AL_POSITION)
Examples found in repository?
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 set_velocity<V: Into<[f32; 3]>>(&self, value: V) -> AltoResult<()>
pub fn set_velocity<V: Into<[f32; 3]>>(&self, value: V) -> AltoResult<()>
alListenerfv(AL_VELOCITY)
Examples found in repository?
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 set_orientation<V: Into<[f32; 3]>>(
&self,
value: (V, V),
) -> AltoResult<()>
pub fn set_orientation<V: Into<[f32; 3]>>( &self, value: (V, V), ) -> AltoResult<()>
alListenerfv(AL_ORIENTATION)
Examples found in repository?
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 soft_gain_limit(&self) -> AltoResult<f32>
pub fn soft_gain_limit(&self) -> AltoResult<f32>
alGetListenerf(AL_GAIN_LIMIT_SOFT)
Requires AL_SOFT_gain_clamp_ex
Sourcepub fn enumerate_soft_resamplers(&self) -> Vec<CString>
pub fn enumerate_soft_resamplers(&self) -> Vec<CString>
alGetStringiSOFT(AL_RESAMPLER_NAME_SOFT)
Requires AL_SOFT_source_resampler
Sourcepub fn meters_per_unit(&self) -> f32
pub fn meters_per_unit(&self) -> f32
alGetListenerf(AL_METERS_PER_UNIT)
Requires ALC_EXT_EFX
Sourcepub fn set_meters_per_unit(&self, value: f32) -> AltoResult<()>
pub fn set_meters_per_unit(&self, value: f32) -> AltoResult<()>
alListenerf(AL_METERS_PER_UNIT)
Requires ALC_EXT_EFX
Sourcepub fn new_buffer<F: SampleFrame, B: AsBufferData<F>>(
&self,
data: B,
freq: i32,
) -> AltoResult<Buffer>
pub fn new_buffer<F: SampleFrame, B: AsBufferData<F>>( &self, data: B, freq: i32, ) -> AltoResult<Buffer>
alGenBuffers()
To ensure well defined state, the buffer is assigned data immediately.
Examples found in repository?
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 new_static_source(&self) -> AltoResult<StaticSource>
pub fn new_static_source(&self) -> AltoResult<StaticSource>
alGenSources()
Examples found in repository?
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
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 new_streaming_source(&self) -> AltoResult<StreamingSource>
pub fn new_streaming_source(&self) -> AltoResult<StreamingSource>
alGenSources()
Examples found in repository?
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 defer_updates(&self) -> DeferLock<'_>
pub fn defer_updates(&self) -> DeferLock<'_>
alDeferUpdatesSOFT()
Requires AL_SOFT_deferred_updates
Sourcepub fn new_aux_effect_slot(&self) -> AltoResult<AuxEffectSlot>
pub fn new_aux_effect_slot(&self) -> AltoResult<AuxEffectSlot>
alGenAuxiliaryEffectSlots()
Requires ALC_EXT_EFX
Examples found in repository?
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 new_effect<E: Effect>(&self) -> AltoResult<E>
pub fn new_effect<E: Effect>(&self) -> AltoResult<E>
alGenEffects()
Requires ALC_EXT_EFX
Examples found in repository?
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 new_filter<F: Filter>(&self) -> AltoResult<F>
pub fn new_filter<F: Filter>(&self) -> AltoResult<F>
alGenFilters()
Requires ALC_EXT_EFX