Skip to content
This is the development version of the documentation. It may change before the next release. See 0.6.x for the latest release.

Modulation

Modulation is a command that sends AM waveform data (&[u8]) to the device.

Modulation::new(config, &data);
Modulation::with_bank(bank, config, &data);
Modulation {
bank,
config,
data: &data,
loop_behavior,
transition_mode,
};

Modulation::new sets the destination bank to ModulationBank::B0, the loop to Infinite, and the transition to Immediate. To write to another bank, use Modulation::with_bank(bank, config, data). To also change the loop count or transition timing, construct it by specifying the fields directly.

Field Type Default Description
bank ModulationBank ModulationBank::B0 Bank to write to / play back
config SamplingConfig Playback sampling frequency
data &[u8] AM waveform sample sequence (at least 2 samples)
loop_behavior LoopBehavior LoopBehavior::Infinite Playback loop count
transition_mode TransitionMode TransitionMode::Immediate Transition behavior on bank switching

config is specified with SamplingConfig. data is written to a buffer allocated by modulation_buffer(). For the behavior of loop_behavior / transition_mode, see ChangeModulationBank.

Several helper functions are provided for computing modulation.

Modulation is equivalent to the three commands WriteModulationBuffer + ConfigModulation + ChangeModulationBank. When the data fits in a single frame it is fused and sent as one frame; otherwise it expands into the three commands above. The following is equivalent to Modulation { bank, config, data, loop_behavior, transition_mode }

WriteModulationBuffer {
bank,
offset: 0,
data: &data,
};
ConfigModulation {
bank,
config,
size: data.len(),
loop_behavior,
};
ChangeModulationBank {
bank,
transition_mode,
};
use autd3_rs::commands::Modulation;
use autd3_rs::geometry::{Autd3, Geometry};
use autd3_rs::units::Hz;
use autd3_rs::value::SamplingConfig;
use autd3_rs::{Client, ClientConfig};
use autd3_rs_link_nop::Nop;
use autd3_rs_modulation::{SineOption, modulation_buffer, sine};
let geometry = Geometry::new(vec![Autd3::default()]);
let client = Client::open(&geometry, Nop, ClientConfig::default()).await?;
let mut data = modulation_buffer();
sine(150 * Hz, &SineOption::default(), &mut data)?;
let mut builder = client.datagram_builder();
builder.push(Modulation::new(SamplingConfig::FREQ_4K, &data));
let frames = builder.build()?;
for frame in &frames {
client.send_checked(frame).await?;
}
client.close().await?;