mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
tests/dac_dds: Fix sine wave to fit in PCM range
The previous sine wave cast signed integers into the PCM range, causing jumps at zero transitions. This shifts everything up by the respective maximum signed integer, so that the signed idle zero becomes the unsigned PCM signal's idle half-point and can continuously cover the whole unsigned range.
This commit is contained in:
parent
00af946aef
commit
4596f79c95
@ -127,6 +127,7 @@ static void _fill_sine_samples_8(uint8_t *buf, size_t len, uint16_t period)
|
||||
for (uint16_t i = 0; i < period; ++i) {
|
||||
x += step;
|
||||
buf[i] = isin(x) >> 5;
|
||||
buf[i] += INT8_MAX + 1;
|
||||
}
|
||||
|
||||
for (uint16_t i = period; i < len; i += period) {
|
||||
@ -145,6 +146,7 @@ static void _fill_sine_samples_16(uint8_t *buf, size_t len, uint16_t period)
|
||||
x += step;
|
||||
|
||||
uint16_t y = isin(x);
|
||||
y += INT16_MAX + 1;
|
||||
buf[i] = y;
|
||||
buf[++i] = y >> 8;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user