title: How to do FFT in node.js?
body: <p>I'm currently trying to do FFT in node.js and having a lot of difficulty.  I've looked through and tried about three different libraries, but every one of them is poorly documented at best, which makes it really difficult.</p>
  
  <p>I have a Float32Array that is downsampled to 44100/16 being sent via websocket to my server, so I have the raw audio data.  The next part is where I need someone with prior experience with any FFT node.js package.</p>
  
  <p>I'm trying to get frequency and magnitude data, I don't much care about phase, but in any case... how to I get a npm FFT package to give me useful data?</p>
  
  <p>Here's what I've got now, and the output it's giving me is absolutely meaningless.  It's not showing me the sine tone it's getting.</p>
  
  <pre><code>var fft = require('fft-js').fft,
      fftUtil = require('fft-js').util;
  
  const WebSocket = require('ws');
  
  const wss =  new WebSocket.Server({ port: 4321 });
  
  
  var buffers = [];
  var totalBufferSize = 0;
  
  wss.on('connection', function connection(ws) {
      ws.on('message', function incoming(message) {
  
  
          buffers.push(message);
          totalBufferSize += message.length;
  
  
  
  
          if(totalBufferSize &gt; 6000) {
              var signal = new Float32Array(totalBufferSize);
  
              var offset = 0;
  
              for(var i = 0; i &lt; buffers.length; i++) {
                  signal.set(buffers[i], offset)
                  offset += buffers[i].length;
              }
  
              buffers = [];
              totalBufferSize = 0;
  
  
              // console.log(signal);
  
              var phasors = fft(signal);
  
              var frequencies = fftUtil.fftFreq(phasors, 2756), // Sample rate and coef is just used for length, and frequency step
                  magnitudes = fftUtil.fftMag(phasors); 
  
              for(var i = 1; i &lt; magnitudes.length; i++) {
                  if(magnitudes[i] &gt; 4000) {
                      console.log(frequencies[i], magnitudes[i]);
                  }
              }
          }
  
      });
  
      ws.send('something');
  });
  </code></pre>
  
  <p>The output I'm getting is that the magnitude of everything is over 4000, and also... what a standard magnitude is supposed to be, I have no idea.  My guess would have been 0, or like 1.5 for something loud...  Honestly, I'm completely in the dark here without someone who knows this package or a link to some good documentation.</p>
  
  <p>Anyways, how can I turn my audio data into some frequency information, and what will that information mean (eg. what does a magnitude of 4000 mean)?</p>