sine
srcsine generates a sine-wave amplitude modulation.
freq = 200 Hz (clamp = true)
sine(freq, &option, &mut dst)?;sine(freq, option, dst)Modulation.Sine(freq, option, dst);| Parameter | Type | Description |
|---|---|---|
freq |
Freq<u32> etc. |
modulation frequency |
option |
&SineOption |
additional options (see below) |
dst |
&mut Vec<u8> |
output buffer |
The value of each sample amplitude), offset offset), and phase phase).
freq is specified as Freq<u32> (150 * Hz) or Freq<f32> (150.0 * Hz).
SineOption
Section titled “SineOption”SineOption { amplitude, offset, phase, clamp, sampling_config,}SineOption( amplitude, offset, phase, clamp, sampling_config,)new SineOption( amplitude, offset, phase, clamp, samplingConfig)| Field | Type | Default | Description |
|---|---|---|---|
amplitude |
u8 |
0xFF |
amplitude of the sine wave |
offset |
u8 |
0x80 |
DC offset |
phase |
Angle |
Angle::ZERO |
phase |
clamp |
bool |
false |
whether to clamp out-of-range values to [0, 255] |
sampling_config |
SamplingConfig |
SamplingConfig::FREQ_4K |
sampling configuration |
If the combination of amplitude and offset causes the waveform to fall outside the [0, 255] range, an error occurs when clamp is false.
Choose values that stay within range, or set clamp to true.
Constraints
Section titled “Constraints”Due to the constraints of SamplingConfig, the specified frequency may not be a representable frequency.
In that case, passing Nearest(freq) rounds it to the nearest representable frequency.
sine(Nearest(150.5 * Hz), &option, &mut dst)?;sine(Nearest(150.5 * Hz), option, dst)Modulation.Sine(Nearest(150.5f * Hz), option, dst);Example
Section titled “Example”use autd3_rs::units::{Hz, rad};use autd3_rs::value::SamplingConfig;use autd3_rs_modulation::{SineOption, sine};
let mut dst = Vec::new();
sine( 150 * Hz, &SineOption { amplitude: 0xFF, offset: 0x80, phase: 0.0 * rad, clamp: false, sampling_config: SamplingConfig::FREQ_4K, }, &mut dst,)?;from autd3.units import Hz, radfrom autd3.value import SamplingConfigfrom autd3_modulation import SineOption, modulation_buffer, sine
dst = modulation_buffer()
sine( 150 * Hz, SineOption( amplitude=0xFF, offset=0x80, phase=0.0 * rad, clamp=False, sampling_config=SamplingConfig.FREQ_4K, ), dst,)using AUTD3;using static AUTD3.Units;
var dst = Modulation.ModulationBuffer();
Modulation.Sine( 150 * Hz, new SineOption( amplitude: 0xFF, offset: 0x80, phase: 0.0f * rad, clamp: false, samplingConfig: SamplingConfig.Freq4k ), dst);