/* Size of the analog pattern space per channel. */
#define ANALOG_BUFSIZE 4096
-#define ANALOG_AMPLITUDE 25
+#define DEFAULT_ANALOG_AMPLITUDE 25
#define ANALOG_SAMPLES_PER_PERIOD 20
/* Logic patterns we can generate. */
struct analog_gen {
int pattern;
+ float amplitude;
float pattern_data[ANALOG_BUFSIZE];
unsigned int num_samples;
struct sr_datafeed_analog packet;
static const int devopts_cg[] = {
SR_CONF_PATTERN_MODE,
+ SR_CONF_AMPLITUDE,
};
static const uint64_t samplerates[] = {
switch (ag->pattern) {
case PATTERN_SQUARE:
- value = ANALOG_AMPLITUDE;
+ value = ag->amplitude;
last_end = 0;
for (i = 0; i < num_samples; i++) {
if (i % 5 == 0)
for (i = 0; i < num_samples; i++) {
t = (double) i / (double) sample_rate;
- ag->pattern_data[i] = ANALOG_AMPLITUDE *
+ ag->pattern_data[i] = ag->amplitude *
sin(2 * M_PI * frequency * t);
}
for (i = 0; i < num_samples; i++) {
t = (double) i / (double) sample_rate;
- ag->pattern_data[i] = (2 * ANALOG_AMPLITUDE / M_PI) *
+ ag->pattern_data[i] = (2 * ag->amplitude / M_PI) *
asin(sin(2 * M_PI * frequency * t));
}
for (i = 0; i < num_samples; i++) {
t = (double) i / (double) sample_rate;
- ag->pattern_data[i] = 2 * ANALOG_AMPLITUDE *
+ ag->pattern_data[i] = 2 * ag->amplitude *
((t * frequency) - floor(0.5f + t * frequency));
}
/* Every channel group gets a generator struct. */
if (!(ag = g_try_malloc(sizeof(struct analog_gen))))
return NULL;
+ ag->amplitude = DEFAULT_ANALOG_AMPLITUDE;
ag->packet.channels = cg->channels;
ag->packet.mq = 0;
ag->packet.mqflags = 0;
case SR_CONF_NUM_ANALOG_CHANNELS:
*data = g_variant_new_int32(devc->num_analog_channels);
break;
+ case SR_CONF_AMPLITUDE:
+ if (!cg)
+ return SR_ERR_CHANNEL_GROUP;
+ ch = cg->channels->data;
+ if (ch->type != SR_CHANNEL_ANALOG)
+ return SR_ERR_ARG;
+ ag = cg->priv;
+ *data = g_variant_new_double(ag->amplitude);
+ break;
default:
return SR_ERR_NA;
}
} else
return SR_ERR_BUG;
break;
+ case SR_CONF_AMPLITUDE:
+ if (!cg)
+ return SR_ERR_CHANNEL_GROUP;
+ ch = cg->channels->data;
+ if (ch->type != SR_CHANNEL_ANALOG)
+ return SR_ERR_ARG;
+ ag = cg->priv;
+ ag->amplitude = g_variant_get_double(data);
+ break;
default:
ret = SR_ERR_NA;
}