source: gs3-extensions/web-audio/trunk/js-dsp/component/wf-freq-spectrum.js@ 28388

Last change on this file since 28388 was 28388, checked in by davidb, 11 years ago

Set of JS, CSS, PNG etc web resources to support a mixture of audio player/document display capabilities

File size: 2.8 KB
Line 
1
2var WFFreqSpectrum = function(frameBufferLength,channels,samplerate,totalNumFrames) {
3
4 this.frameBufferLength = frameBufferLength;
5 this.channels = channels;
6 this.samplerate = samplerate;
7
8 this.totalNumFrames = totalNumFrames; // **** Not currently used
9
10 this.defaults();
11
12 var fftWindowSize = Math.floor(this.frameBufferLength/channels); // check this is a power of 2??
13
14 this.fft = new FFTCustom(fftWindowSize, this.samplerate);
15
16 this.freqSpectrumSequence = new Array();
17}
18
19WFFreqSpectrum.inherits(Component);
20
21//----------------------------- OVERVIEW -----------------------------------------------------
22
23WFFreqSpectrum.staticfield('Component', {
24
25 creator: "David Bainbridge",
26 description: "Overview: Computes the frequency spectrum of the (mono-valued) input frame",
27 name: "freqSpectrum",
28 tags: "signal process, frequency-spectrum",
29 dependency: [ "dsp.js" ]
30});
31
32//------------------------------ INPUTS ------------------------------------------------------
33
34WFFreqSpectrum.staticfield('ComponentInputArray', [
35 {
36 name: "monoAudioInputFrames",
37 description: "Frames of (mono, or stereo down-mixed to mono) audio."
38 }
39
40]);
41
42
43//------------------------------ PROPERTIES --------------------------------------------------
44
45WFFreqSpectrum.staticfield('ComponentPropertyArray', [
46]);
47
48
49//------------------------------ OUTPUTS -----------------------------------------------------
50
51WFFreqSpectrum.staticfield('ComponentOutputArray', [
52 {
53 name: "freqSpectrumFrames",
54 description: "Per frame frequency spectrum (potentially the power spectrum, based on the Component's parameters"
55 }
56]);
57
58
59
60WFFreqSpectrum.prototype.reset = function()
61{
62 this.maxval = 0.0;
63}
64
65
66WFFreqSpectrum.prototype.setMaxVal = function(v)
67{
68 this.maxval = v;
69}
70
71
72WFFreqSpectrum.prototype.getMaxVal = function()
73{
74 var maxVal = this.maxval;
75
76 return maxVal;
77}
78
79WFFreqSpectrum.prototype.getFreqSpectrumSequence = function() {
80 return this.freqSpectrumSequence;
81}
82
83
84// ******
85// ******
86
87
88
89WFFreqSpectrum.prototype.defaults = function() {
90};
91
92
93WFFreqSpectrum.prototype.initializeCallback = function(ccp) {
94}
95
96
97WFFreqSpectrum.prototype.executeCallBack = function(cc) {
98
99 // typeof(cc) => ComponentContext
100
101 // get the "[D" input
102
103 //console.info("*** WFFreqSpectrum::executeCallBack(): away to request 'monoAudioInputFrames'");
104
105 var frame = cc.getDataComponentFromInput("monoAudioInputFrames");
106
107 this.fft.forward(frame);
108
109 var freqSpectrumCopy = new Float32Array(this.fft.powerSpectrum); // need a copy of the array (not just a reference)
110 this.freqSpectrumSequence.push(freqSpectrumCopy);
111
112 cc.pushDataComponentToOutput("freqSpectrumFrames",this.fft.powerSpectrum);
113
114}
115
Note: See TracBrowser for help on using the repository browser.