# HG changeset patch # User Chris Cannam # Date 1489164354 0 # Node ID 68fe21cfda2a5ed57a7bf959ba6203aef8b44f53 # Parent 7740f7fd7c3ccee505220b4ddfeb128a21504020 Avoid NaNs, etc diff -r 7740f7fd7c3c -r 68fe21cfda2a package.json --- a/package.json Fri Mar 10 14:46:18 2017 +0000 +++ b/package.json Fri Mar 10 16:45:54 2017 +0000 @@ -27,7 +27,7 @@ "requirejs": "^2.3.2", "rxjs": "5.0.0-beta.12", "ts-helpers": "^1.1.1", - "waves-ui": "github:cannam/waves-ui#648f193ee8874042b969853f318587a424d6e8cd", + "waves-ui": "github:cannam/waves-ui#4d6c03b5dbe70b223c7770835529b6d4b1962a71", "zone.js": "^0.6.23" }, "devDependencies": { diff -r 7740f7fd7c3c -r 68fe21cfda2a src/app/waveform/waveform.component.ts --- a/src/app/waveform/waveform.component.ts Fri Mar 10 14:46:18 2017 +0000 +++ b/src/app/waveform/waveform.component.ts Fri Mar 10 16:45:54 2017 +0000 @@ -116,20 +116,30 @@ // it is guaranteed to include at least one sample from every // column, and could sample some values more than once. But it // should be good enough in most cases (todo: show this) - if (matrix.length === 0) return 0.0; + if (matrix.length === 0) { + return 0.0; + } const w = matrix.length; const h = matrix[0].length; const n = w * h; - const m = (n > 10000 ? 10000 : n); // should base that on the %ile + const m = (n > 50000 ? 50000 : n); // should base that on the %ile let m_per = Math.floor(m / w); if (m_per < 1) m_per = 1; let sample = []; for (let x = 0; x < w; ++x) { for (let i = 0; i < m_per; ++i) { const y = Math.floor(Math.random() * h); - sample.push(matrix[x][y]); + const value = matrix[x][y]; + if (!isNaN(value) && value !== Infinity) { + sample.push(value); + } } } + if (sample.length === 0) { + console.log("WARNING: No samples gathered, even though we hoped for " + + (m_per * w) + " of them"); + return 0.0; + } sample.sort((a,b) => { return a - b; }); const ix = Math.floor((sample.length * percentile) / 100); console.log("Estimating " + percentile + "-%ile of " + @@ -417,14 +427,17 @@ const stepDuration = (features as FixedSpacedFeatures).stepDuration; const matrixData = (features.data as Float32Array[]); if (matrixData.length === 0) return; - const targetValue = this.estimatePercentile(matrixData, 97); + console.log("matrix data length = " + matrixData.length); + console.log("height of first column = " + matrixData[0].length); + const targetValue = this.estimatePercentile(matrixData, 95); const gain = (targetValue > 0.0 ? (1.0 / targetValue) : 1.0); console.log("setting gain to " + gain); const matrixEntity = new wavesUI.utils.PrefilledMatrixEntity(matrixData); let matrixLayer = new wavesUI.helpers.MatrixLayer(matrixEntity, { gain, - height, - normalise: 'hybrid', + height: height * 0.8, + top: height * 0.1, + normalise: 'none', mapper: this.iceMapper() }); this.colouredLayers.set(this.addLayer(