+ }
+ else {
+ if (devc->num_bytes == num_channels) {
+ devc->cnt_samples++;
+ devc->cnt_samples_rle++;
+ /*
+ * Got a full sample. Convert from the OLS's little-endian
+ * sample to the local format.
+ */
+ sample = devc->sample[0] | (devc->sample[1] << 8) \
+ | (devc->sample[2] << 16) | (devc->sample[3] << 24);
+ sr_spew("Received sample 0x%.*x.", devc->num_bytes * 2, sample);
+ if (devc->flag_reg & FLAG_RLE) {
+ /*
+ * In RLE mode the high bit of the sample is the
+ * "count" flag, meaning this sample is the number
+ * of times the previous sample occurred.
+ */
+ if (devc->sample[devc->num_bytes - 1] & 0x80) {
+ /* Clear the high bit. */
+ sample &= ~(0x80 << (devc->num_bytes - 1) * 8);
+ devc->rle_count = sample;
+ devc->cnt_samples_rle += devc->rle_count;
+ sr_dbg("RLE count: %u.", devc->rle_count);
+ devc->num_bytes = 0;
+ continue;
+ }
+ }
+ devc->num_samples += devc->rle_count + 1;
+ if (devc->num_samples > devc->limit_samples) {
+ /* Save us from overrunning the buffer. */
+ devc->rle_count -= devc->num_samples - devc->limit_samples;
+ devc->num_samples = devc->limit_samples;
+ index = bytes_read;
+ }
+
+ if (num_channels < 4) {
+ /*
+ * Some channel groups may have been turned
+ * off, to speed up transfer between the
+ * hardware and the PC. Expand that here before
+ * submitting it over the session bus --
+ * whatever is listening on the bus will be
+ * expecting a full 32-bit sample, based on
+ * the number of channels.
+ */
+ j = 0;
+ memset(devc->tmp_sample, 0, 4);
+ for (i = 0; i < 4; i++) {
+ if (((devc->flag_reg >> 2) & (1 << i)) == 0) {
+ /*
+ * This channel group was
+ * enabled, copy from received
+ * sample.
+ */
+ devc->tmp_sample[i] = devc->sample[j++];
+ }
+ }
+ memcpy(devc->sample, devc->tmp_sample, 4);
+ sr_spew("Expanded sample: 0x%.8x.", sample);
+ }