- for (i = 0, n = 1; i < limit; ++i, ++n) {
- memcpy (bufs.get_audio(i).data(), b, sizeof (Sample) * nframes);
- if (n < diskstream->n_channels().n_audio()) {
- tmpb = diskstream->playback_buffer(n);
- if (tmpb!=0) {
- b = tmpb;
+ if (limit > blimit) {
+
+ /* example case: auditioner configured for stereo output,
+ but loaded with an 8 channel file. there are only
+ 2 passthrough buffers, but n_process_buffers() will
+ return 8.
+
+ arbitrary decision: map all channels in the diskstream
+ to the outputs available.
+ */
+
+ float scaling = limit/blimit;
+
+ for (i = 0, n = 1; i < blimit; ++i, ++n) {
+
+ /* first time through just copy a channel into
+ the output buffer.
+ */
+
+ Sample* bb = bufs.get_audio (i).data();
+
+ for (nframes_t xx = 0; xx < nframes; ++xx) {
+ bb[xx] = b[xx] * scaling;
+ }
+
+ if (n < diskstream->n_channels().n_audio()) {
+ tmpb = diskstream->playback_buffer(n);
+ if (tmpb!=0) {
+ b = tmpb;
+ }
+ }
+ }
+
+ for (;i < limit; ++i, ++n) {
+
+ /* for all remaining channels, sum with existing
+ data in the output buffers
+ */
+
+ bufs.get_audio (i%blimit).accumulate_with_gain_from (b, nframes, 0, scaling);
+
+ if (n < diskstream->n_channels().n_audio()) {
+ tmpb = diskstream->playback_buffer(n);
+ if (tmpb!=0) {
+ b = tmpb;
+ }
+ }
+
+ }
+
+ limit = blimit;
+
+ } else {
+ for (i = 0, n = 1; i < blimit; ++i, ++n) {
+ memcpy (bufs.get_audio (i).data(), b, sizeof (Sample) * nframes);
+ if (n < diskstream->n_channels().n_audio()) {
+ tmpb = diskstream->playback_buffer(n);
+ if (tmpb!=0) {
+ b = tmpb;
+ }