changeset 183:376f56200aa1

Merge branch 'master' of github.com:cannam/ugly-duckling into feature/list-analysis-cards
author Lucas Thompson <dev@lucas.im>
date Wed, 22 Mar 2017 11:18:13 +0000
parents 4c5b968a1056 (current diff) 8c882ee9d097 (diff)
children 7643e60dc1dd
files src/app/waveform/waveform.component.ts
diffstat 2 files changed, 38 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/app/spectrogram/Spectrogram.ts	Wed Mar 22 11:18:04 2017 +0000
+++ b/src/app/spectrogram/Spectrogram.ts	Wed Mar 22 11:18:13 2017 +0000
@@ -79,7 +79,7 @@
     const defaults = {
       normalise: 'hybrid',
       gain: 40.0,
-      channel: 0,
+      channel: -1,
       stepSize: 512,
       blockSize: 1024
     };
@@ -87,13 +87,30 @@
     const mergedOptions: Framing & Object & {channel: number} =
       Object.assign({}, defaults, options);
 
+    const getSamples = ((buffer, channel) => {
+      const nch = buffer.numberOfChannels;
+      if (channel >= 0 || nch == 1) {
+	return buffer.getChannelData(channel);
+      } else {
+        const before = performance.now();
+	console.log("mixing down " + nch + " channels for spectrogram...");
+	const mixed = Float32Array.from(buffer.getChannelData(0));
+	const n = mixed.length;
+	for (let ch = 1; ch < nch; ++ch) {
+	  const buf = buffer.getChannelData(ch);
+	  for (let i = 0; i < n; ++i) mixed[i] += buf[i];
+	}
+	const scale = 1.0 / nch;
+	for (let i = 0; i < n; ++i) mixed[i] *= scale;
+	console.log("done in " + (performance.now() - before) + "ms");
+	return mixed;
+      }
+    });
+    
     super('entity',
-      new SpectrogramEntity(
-        buffer.getChannelData(mergedOptions.channel),
-        mergedOptions
-      ),
-      mergedOptions
-    );
+	  new SpectrogramEntity(getSamples(buffer, mergedOptions.channel),
+				mergedOptions),
+	  mergedOptions);
 
     this.configureShape(Waves.shapes.Matrix, {}, mergedOptions);
   }
--- a/src/app/waveform/waveform.component.ts	Wed Mar 22 11:18:04 2017 +0000
+++ b/src/app/waveform/waveform.component.ts	Wed Mar 22 11:18:13 2017 +0000
@@ -291,12 +291,20 @@
     });
     this.addLayer(timeAxis, waveTrack, this.timeline.timeContext, true);
 
-    const waveformLayer = new wavesUI.helpers.WaveformLayer(buffer, {
-      top: 10,
-      height: height * 0.9,
-      color: 'darkblue'
-    });
-    this.addLayer(waveformLayer, waveTrack, this.timeline.timeContext);
+    const nchannels = buffer.numberOfChannels;
+    const totalWaveHeight = height * 0.9;
+    const waveHeight = totalWaveHeight / nchannels;
+    
+    for (let ch = 0; ch < nchannels; ++ch) {
+      console.log("about to construct a waveform layer for channel " + ch);
+      const waveformLayer = new wavesUI.helpers.WaveformLayer(buffer, {
+	top: (height - totalWaveHeight)/2 + waveHeight * ch,
+	height: waveHeight,
+	color: 'darkblue',
+	channel: ch
+      });
+      this.addLayer(waveformLayer, waveTrack, this.timeline.timeContext);
+    }
 
     this.cursorLayer = new wavesUI.helpers.CursorLayer({
       height: height