X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Ftransform%2Fscale.c;h=c7c60dd2b456ac5bfa317bf76592a28fc2e84c38;hb=2ea1fdf12113311cbe1a4316e9e2efe4d8ac40f0;hp=6d3769b35c604cdb7ec4610309d6ba248e08c8f9;hpb=43caa4662388ccc58c0ed8d8e861c52d10d5ded2;p=libsigrok.git diff --git a/src/transform/scale.c b/src/transform/scale.c index 6d3769b3..c7c60dd2 100644 --- a/src/transform/scale.c +++ b/src/transform/scale.c @@ -14,18 +14,18 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * along with this program; if not, see . */ +#include #include -#include "libsigrok.h" +#include #include "libsigrok-internal.h" #define LOG_PREFIX "transform/scale" struct context { - double factor; + struct sr_rational factor; }; static int init(struct sr_transform *t, GHashTable *options) @@ -37,7 +37,8 @@ static int init(struct sr_transform *t, GHashTable *options) t->priv = ctx = g_malloc0(sizeof(struct context)); - ctx->factor = g_variant_get_double(g_hash_table_lookup(options, "factor")); + g_variant_get(g_hash_table_lookup(options, "factor"), "(xt)", + &ctx->factor.p, &ctx->factor.q); return SR_OK; } @@ -48,10 +49,6 @@ static int receive(const struct sr_transform *t, { struct context *ctx; const struct sr_datafeed_analog *analog; - struct sr_channel *ch; - GSList *l; - float *fdata; - int i, num_channels, c; if (!t || !t->sdi || !packet_in || !packet_out) return SR_ERR_ARG; @@ -60,16 +57,8 @@ static int receive(const struct sr_transform *t, switch (packet_in->type) { case SR_DF_ANALOG: analog = packet_in->payload; - fdata = (float *)analog->data; - num_channels = g_slist_length(analog->channels); - for (i = 0; i < analog->num_samples; i++) { - /* For now scale all values in all channels. */ - for (l = analog->channels, c = 0; l; l = l->next, c++) { - ch = l->data; - (void)ch; - fdata[i * num_channels + c] *= ctx->factor; - } - } + analog->encoding->scale.p *= ctx->factor.p; + analog->encoding->scale.q *= ctx->factor.q; break; default: sr_spew("Unsupported packet type %d, ignoring.", packet_in->type); @@ -103,9 +92,12 @@ static struct sr_option options[] = { static const struct sr_option *get_options(void) { + int64_t p = 1; + uint64_t q = 1; + /* Default to a scaling factor of 1.0. */ if (!options[0].def) - options[0].def = g_variant_ref_sink(g_variant_new_double(1.0)); + options[0].def = g_variant_ref_sink(g_variant_new("(xt)", &p, &q)); return options; }