]> sigrok.org Git - libsigrok.git/commitdiff
demo: Cast to double while calculating the pattern frequency.
authorpoljar (Damir Jelić) <redacted>
Sun, 26 Jan 2014 20:30:57 +0000 (21:30 +0100)
committerBert Vermeulen <redacted>
Tue, 28 Jan 2014 20:23:54 +0000 (21:23 +0100)
Without the cast non integer frequencies weren't possible (e.g. with a sampling
frequency of 50Hz we would end up with a signal frequency of 2Hz instead of
2.5Hz). The result were signals which had an incorrect number of samples per
period.

BugLink: http://sigrok.org/bugzilla/show_bug.cgi?id=297
hardware/demo/demo.c

index 3d59ae5f7d71357401539a23c5d74ec283d4e8f0..433f35229cdb6f284a9c539d3a6c8da93f129977 100644 (file)
@@ -206,7 +206,7 @@ static void generate_analog_pattern(const struct sr_probe_group *probe_group, ui
                break;
 
        case PATTERN_SINE:
-               frequency = sample_rate / ANALOG_SAMPLES_PER_PERIOD;
+               frequency = (double) sample_rate / ANALOG_SAMPLES_PER_PERIOD;
 
                /* Make sure the number of samples we put out is an integer
                 * multiple of our period size */
@@ -225,7 +225,7 @@ static void generate_analog_pattern(const struct sr_probe_group *probe_group, ui
                break;
 
        case PATTERN_TRIANGLE:
-               frequency = sample_rate / ANALOG_SAMPLES_PER_PERIOD;
+               frequency = (double) sample_rate / ANALOG_SAMPLES_PER_PERIOD;
 
                while (num_samples % ANALOG_SAMPLES_PER_PERIOD != 0)
                        num_samples--;
@@ -240,7 +240,7 @@ static void generate_analog_pattern(const struct sr_probe_group *probe_group, ui
                break;
 
        case PATTERN_SAWTOOTH:
-               frequency = sample_rate / ANALOG_SAMPLES_PER_PERIOD;
+               frequency = (double) sample_rate / ANALOG_SAMPLES_PER_PERIOD;
 
                while (num_samples % ANALOG_SAMPLES_PER_PERIOD != 0)
                        num_samples--;