- // FIXME: map back through the interesting_channels squeeze map instead of using source_channel
- // directly, which will be wrong (and might even overrun).
- *srcptr = &samples_card[card_index][source_channel];
- *stride = cards[card_index].interesting_channels.size();
+ AudioDevice *device = find_audio_device(device_spec);
+ unsigned channel_index = 0;
+ for (int channel : device->interesting_channels) {
+ if (channel == source_channel) break;
+ ++channel_index;
+ }
+ assert(channel_index < device->interesting_channels.size());
+ *srcptr = &samples_card[device_spec.index][channel_index];
+ *stride = device->interesting_channels.size();
+}
+
+// TODO: Can be SSSE3-optimized if need be.
+void AudioMixer::fill_audio_bus(const vector<float> *samples_card, const InputMapping::Bus &bus, unsigned num_samples, float *output)
+{
+ if (bus.device.type == InputSourceType::SILENCE) {
+ memset(output, 0, num_samples * sizeof(*output));
+ } else {
+ assert(bus.device.type == InputSourceType::CAPTURE_CARD);
+ const float *lsrc, *rsrc;
+ unsigned lstride, rstride;
+ float *dptr = output;
+ find_sample_src_from_device(samples_card, bus.device, bus.source_channel[0], &lsrc, &lstride);
+ find_sample_src_from_device(samples_card, bus.device, bus.source_channel[1], &rsrc, &rstride);
+ for (unsigned i = 0; i < num_samples; ++i) {
+ *dptr++ = *lsrc;
+ *dptr++ = *rsrc;
+ lsrc += lstride;
+ rsrc += rstride;
+ }
+ }