comparison src/app/spectrogram/Spectrogram.ts @ 168:19ca3aaf7807

Give spectrogram a step duration
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 27 Mar 2017 18:17:27 +0100
parents fafba3b9ba6b
children 53ea6406d601
comparison
equal deleted inserted replaced
167:d8f2eb7ac0c5 168:19ca3aaf7807
7 import Waves from 'waves-ui'; 7 import Waves from 'waves-ui';
8 8
9 class SpectrogramEntity extends Waves.utils.MatrixEntity { 9 class SpectrogramEntity extends Waves.utils.MatrixEntity {
10 10
11 private samples: Float32Array; 11 private samples: Float32Array;
12 private sampleRate: number;
12 private framing: Framing; 13 private framing: Framing;
13 private fft: RealFft; 14 private fft: RealFft;
14 private real: Float32Array; 15 private real: Float32Array;
15 private nCols: number; 16 private nCols: number;
16 private columnHeight: number; 17 private columnHeight: number;
17 private window: Float32Array; 18 private window: Float32Array;
18 19
19 constructor(samples: Float32Array, options: Framing & Object) { 20 constructor(samples: Float32Array, options: Framing & Object, sampleRate: number) {
20 super(); 21 super();
21 this.samples = samples; 22 this.samples = samples;
23 this.sampleRate = sampleRate;
22 this.framing = options; 24 this.framing = options;
23 this.real = new Float32Array(this.framing.blockSize); 25 this.real = new Float32Array(this.framing.blockSize);
24 this.nCols = Math.floor(this.samples.length / this.framing.stepSize); //!!! not correct 26 this.nCols = Math.floor(this.samples.length / this.framing.stepSize); //!!! not correct
25 this.columnHeight = Math.round(this.framing.blockSize / 2) + 1; 27 this.columnHeight = Math.round(this.framing.blockSize / 2) + 1;
26 this.fft = new KissRealFft(this.framing.blockSize); 28 this.fft = new KissRealFft(this.framing.blockSize);
37 39
38 getColumnHeight(): number { 40 getColumnHeight(): number {
39 return this.columnHeight; 41 return this.columnHeight;
40 } 42 }
41 43
44 getStepDuration(): number {
45 return this.framing.stepSize / this.sampleRate;
46 }
47
42 getColumn(n: number): Float32Array { 48 getColumn(n: number): Float32Array {
43 49
44 const startSample = n * this.framing.stepSize; 50 const startSample = n * this.framing.stepSize;
45 const sz = this.framing.blockSize; 51 const sz = this.framing.blockSize;
46 52
108 } 114 }
109 }); 115 });
110 116
111 super('entity', 117 super('entity',
112 new SpectrogramEntity(getSamples(buffer, mergedOptions.channel), 118 new SpectrogramEntity(getSamples(buffer, mergedOptions.channel),
113 mergedOptions), 119 mergedOptions,
120 buffer.sampleRate),
114 mergedOptions); 121 mergedOptions);
115 122
116 this.configureShape(Waves.shapes.Matrix, {}, mergedOptions); 123 this.configureShape(Waves.shapes.Matrix, {}, mergedOptions);
117 } 124 }
118 } 125 }