sine
srcsine generates a sine-wave amplitude modulation.
freq = 200 Hz (clamp = true)
sine(freq, &option, sampling_config, &mut dst)?;sine(freq, option, sampling_config, dst)Modulation.Sine(freq, option, samplingConfig, dst);| Parameter | Type | Description |
|---|---|---|
freq |
Freq etc. |
modulation frequency |
option |
&SineOption |
additional options (see below) |
config |
SamplingConfig |
sampling configuration (see Modulation) |
dst |
&mut Vec<u8> |
output buffer |
The value of each sample amplitude), offset offset), and phase phase).
freq is specified as a Freq (150 * Hz or 150.0 * Hz). 150 * Hz and 150.0 * Hz represent the same frequency.
SineOption
Section titled “SineOption”SineOption { amplitude, offset, phase, clamp, ..Default::default()}SineOption( amplitude, offset, phase, clamp,)new SineOption{ Amplitude = amplitude, Offset = offset, Phase = phase, Clamp = clamp,}| 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] |
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.
freq must be a frequency that fits an integer number of samples in a period; otherwise an error is returned.
Example
Section titled “Example”use autd3_rs::units::{Hz, rad};use autd3_rs::value::SamplingConfig;use autd3_rs_modulation::{SineOption, modulation_buffer, sine};
let mut dst = modulation_buffer();
sine( 150 * Hz, &SineOption { amplitude: 0xFF, offset: 0x80, phase: 0.0 * rad, clamp: false, ..Default::default() }, 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, ), 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.Freq4k, dst);