From 9f54e0e84f93ca4773994d4ee3c2cf3d8989790b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?poljar=20=28Damir=20Jeli=C4=87=29?= Date: Tue, 14 Jan 2014 23:03:10 +0100 Subject: [PATCH] demo: Add analog sawtooth pattern. --- hardware/demo/demo.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/hardware/demo/demo.c b/hardware/demo/demo.c index 0fc5011d..cf82630a 100644 --- a/hardware/demo/demo.c +++ b/hardware/demo/demo.c @@ -79,6 +79,7 @@ enum { PATTERN_SQUARE, PATTERN_SINE, PATTERN_TRIANGLE, + PATTERN_SAWTOOTH, }; static const char *logic_pattern_str[] = { @@ -93,6 +94,7 @@ static const char *analog_pattern_str[] = { "square", "sine", "triangle", + "sawtooth", }; struct analog_gen { @@ -233,6 +235,21 @@ static void generate_analog_pattern(const struct sr_probe_group *probe_group, ui asin(sin(2 * M_PI * frequency * t)); } + ag->num_samples = num_samples; + break; + + case PATTERN_SAWTOOTH: + frequency = sample_rate / ANALOG_SAMPLES_PER_PERIOD; + + while (num_samples % ANALOG_SAMPLES_PER_PERIOD != 0) + num_samples--; + + for (i = 0; i < num_samples; i++) { + t = (double) i / (double) sample_rate; + ag->pattern_data[i] = 2 * ANALOG_AMPLITUDE * + ((t * frequency) - floor(0.5f + t * frequency)); + } + ag->num_samples = num_samples; break; }