Skip to content

sine

src

sine generates a sine-wave amplitude modulation.

freq = 200 Hz (clamp = true)
sine(freq, &option, &mut 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 is given by the following equation, for amplitude (amplitude), offset (offset), and phase (phase).

freq is specified as Freq<u32> (150 * Hz) or Freq<f32> (150.0 * Hz).

SineOption {
amplitude,
offset,
phase,
clamp,
sampling_config,
}
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.

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)?;
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,
)?;