- struct sr_config *src;
- struct context *ctx;
- float fdata[CHUNK_SIZE];
- uint64_t sample;
- int offset, chunk_samples, samplenum, fd, l, i;
- uint8_t buf[CHUNK_SIZE], *s, *d;
-
- ctx = in->sdi->priv;
-
- /* Send header packet to the session bus. */
- std_session_send_df_header(in->sdi, LOG_PREFIX);
-
- /* Send the samplerate. */
- packet.type = SR_DF_META;
- packet.payload = &meta;
- src = sr_config_new(SR_CONF_SAMPLERATE,
- g_variant_new_uint64(ctx->samplerate));
- meta.config = g_slist_append(NULL, src);
+ struct sr_analog_encoding encoding;
+ struct sr_analog_meaning meaning;
+ struct sr_analog_spec spec;
+ struct context *inc;
+ float *fdata;
+ int total_samples, samplenum;
+ char *s, *d;
+
+ inc = in->priv;
+
+ s = in->buf->str + offset;
+ fdata = g_malloc0(CHUNK_SIZE * sizeof(float));
+ d = (char *)fdata;
+ total_samples = num_samples * inc->num_channels;
+ for (samplenum = 0; samplenum < total_samples; samplenum++) {
+ if (inc->fmt_code == WAVE_FORMAT_PCM_) {
+ switch (inc->unitsize) {
+ case 1:
+ /* 8-bit PCM samples are unsigned. */
+ fdata[samplenum] = *(uint8_t*)(s) / (float)255;
+ break;
+ case 2:
+ fdata[samplenum] = RL16S(s) / (float)INT16_MAX;
+ break;
+ case 4:
+ fdata[samplenum] = RL32S(s) / (float)INT32_MAX;
+ break;
+ }
+ } else {
+ /* BINARY32 float */
+#ifdef WORDS_BIGENDIAN
+ int i;
+ for (i = 0; i < inc->unitsize; i++)
+ d[i] = s[inc->unitsize - 1 - i];
+#else
+ memcpy(d, s, inc->unitsize);
+#endif
+ }
+ s += inc->unitsize;
+ d += inc->unitsize;
+ }
+
+ /* TODO: Use proper 'digits' value for this device (and its modes). */
+ sr_analog_init(&analog, &encoding, &meaning, &spec, 2);
+ packet.type = SR_DF_ANALOG;
+ packet.payload = &analog;
+ analog.num_samples = num_samples;
+ analog.data = fdata;
+ analog.meaning->channels = in->sdi->channels;
+ analog.meaning->mq = 0;
+ analog.meaning->mqflags = 0;
+ analog.meaning->unit = 0;