Giter Site home page Giter Site logo

analyser's People

Contributors

dy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

analyser's Issues

Lag when compared to analyserNode

I've been playing around with this module coupled with audio-source and I am experiencing some lag when compared to using the native analyserNode. The apis supplied by audio-source, audio-play, and this module are pretty intriguing (Streams!), but I'd have to get to the root of this issue. I see that there hasn't been a commit to this repo in about a year, and it is the "lab" org so no one is required to maintain this. I was wondering if maybe someone had an idea/hint at where to start tracking down the issue, as I'd be happy to dig in and get to the bottom of this myself.

Here is some code for comparison:

const Source = require('audio-source/stream');
const Speaker = require('audio-speaker/stream');
const lena = require('audio-lena/buffer');
const Analyser = require('audio-analyser');

const context = require('audio-context');
const createWaveform = require('gl-waveform');

const analyser = new Analyser();

let wfData = new Float32Array(analyser.fftSize);

const wf = createWaveform({
  container: document.querySelector('.waveform-container'),
  samples: analyser.getFloatTimeDomainData(wfData)
});

function loop() {
  requestAnimationFrame(loop);
  render();
}

function render() {
  if (!analyser) return;
  
  analyser.getFloatTimeDomainData(wfData);
  wf.push(wfData);
}

Source(lena).pipe(analyser).pipe(Speaker());
loop();

analyserNode version

const lena = require('audio-lena/buffer');
const context = require('audio-context');
const createWaveform = require('gl-waveform');

const analyser = context.createAnalyser();

let wfData = new Float32Array(analyser.fftSize);

const wf = createWaveform({
  container: document.querySelector('.waveform-container'),
  samples: analyser.getFloatTimeDomainData(wfData)
});

function loop() {
  requestAnimationFrame(loop);
  render();
}

function render() {
  if (!analyser) return;
  
  analyser.getFloatTimeDomainData(wfData);
  wf.push(wfData);
}

function init() {
  const source = context.createBufferSource();
  source.buffer = lena;
  source.connect(analyser);
  analyser.connect(context.destination);
  source.start();
  loop();
}

init();

(I tried creating require-bins for these, but was getting lots of server errors ๐Ÿ˜ข )

System facts

Firefox 53.0a2 (Dev edition)
Linux 4.40-62-generic
Ubuntu 16.04.1 LTS xenial

simple example

Hello, maybe anybody will help me. I need get frequency data from samples (array from 0 - 1).

            let analyser = new Analyser({
                // Magnitude diapasone, in dB
                minDecibels: -124,
                maxDecibels: -1,
            
                // Number of time samples to transform to frequency
                fftSize: 1024,
            
                // Number of frequencies, twice less than fftSize
                frequencyBinCount: 1024/2,
            
                // Smoothing, or the priority of the old data over the new data
                smoothingTimeConstant: 0.2,
            
                // Number of channel to analyse
                channel: 0,
            
                // Size of time data to buffer
                bufferSize: 44100,
            
                // Windowing function for fft, https://github.com/scijs/window-functions
                applyWindow: function (sampleNumber, totalSamples) {
                    console.log( 'applyWindow' )
                }
            });

i try

console.log( analyser.getFloatFrequencyData(arr1024) )

result -124 all value in array

question ?

hi

possible to link all your projects to an existing html player ? (mediaelement.js)

for exemple catch the audio output of this player to render it somewhere but let the player read/play the file...

thanks

unable to use the analyser

It might be that no one is maintaining this repo anymore, considered the last commit is quite old.
However, I'm still going to try explaining my issue.

I'm trying to pipe the sound recorded from the microphone to the analyzer to get a fft out; All I get out is a nan array and I don't really know where am I doing something wrong.

pasting here the important pieces of my code:

"use strict";

var Cylon = require("cylon");
var fs = require('fs');
var mic = require('mic');
var lame = require('lame');
var uuid = require('uuid');
var Analyser = require('audio-analyser');

var Adaptor = module.exports = function Adaptor(opts) {
	Adaptor.__super__.constructor.apply(this, arguments);
	opts = opts || {};

	this.connector = this.microphone = mic({
		rate: '16000',
		channels: '1',
		debug: false,
		exitOnSilence: 6
	});

	this.lastrecordingPath = './recordings/recording.mp3';
	this.newRecordingPath = ""

	this.encoder = new lame.Encoder({
		// input
		channels: 1, // 2 channels (left and right)
		bitDepth: 16, // 16-bit samples
		sampleRate: 16000, // 44,100 Hz sample rate

		// output
		bitRate: 128,
		outSampleRate: 22050,
		mode: lame.STEREO // STEREO (default), JOINTSTEREO, DUALCHANNEL or MONO
	});

	//setup audio analyser
	this.analyser = new Analyser({
		// Magnitude diapasone, in dB
		minDecibels: -100,
		maxDecibels: -30,

		// Number of time samples to transform to frequency
		fftSize: 1024,

		// Number of frequencies, twice less than fftSize
		frequencyBinCount: 1024 / 2,

		// Smoothing, or the priority of the old data over the new data
		smoothingTimeConstant: 0.2,

		// Number of channel to analyse
		channel: 1,

		// Size of time data to buffer
		bufferSize: 44100,

		// Windowing function for fft, https://github.com/scijs/window-functions
		applyWindow: function(sampleNumber, totalSamples) {
			//console.log(sampleNumber, totalSamples);
		},

		//...pcm-stream params, if required

	});

	this.micInputStream = this.microphone.getAudioStream();

	//write the output stream
	this.outputFileStream = fs.WriteStream(this.lastrecordingPath);

	// pipe the encoded strim to the filewriter
	this.encoder.pipe(this.outputFileStream);

	//pipe the analyser in to the encode
	this.analyser.pipe(this.encoder);

	//pipe the stream in to the analyser
	this.micInputStream.pipe(this.analyser);

	this.micInputStream.on('data', (data) => {
		console.log("Recieved Input Stream: " + data.length);
		console.log(this.analyser.getFrequencyData());
	});
};

Stream chunksize too large for realtime analysis

Audio-analyser only updates when a data event is fired, which is dependent on the chunksize/highWaterMark of the source audio stream.

When analysing an mp3 stream, the default chunksize (which is fixed for remote requests) is very large, resulting in very infrequent updates (about 2 or 3 per second - not realtime).

I worked around this by adding stream-chunker into the pipeline.

Here is a complete example from remote stream all the way to the speaker, chunked into smaller pieces causing the analyser data event to fire much more frequently (about 30/sec - realtime).

Works with any local or remote mpg source stream (remote example given here).

                                                                                                                                                                                                                                                                                      
const Lame     = require('lame');
const Speaker  = require('speaker');
const Volume   = require('pcm-volume');
const Analyser = require('audio-analyser')
const request  = require('request')
const Chunker  = require('stream-chunker');
const BUFSIZE  = 64;

var decoder   = new Lame.Decoder();	
decoder.on('format', function(format){onFormat(format)});

var chunker  = Chunker(BUFSIZE);
chunker.pipe(decoder);	

var audio_stream = request('http://media-ice.musicradio.com/ClassicFMMP3');
audio_stream.pipe(chunker);

function onFormat(format)
{
	if (volume == "undefined")
		volume = 1.0;
	
	vol      = new Volume(volume);
	speaker  = new Speaker(format);
	analyser = createAnalyser(format);
	analyser.on('data', sample);
	
	console.log(format);
	vol.pipe(speaker);	
	vol.pipe(analyser);	
	decoder.pipe(vol);
	vol.setVolume(volume);
}


function createAnalyser(format)
{
	return new Analyser({
		fftSize: 8,
	        bufferSize: BUFSIZE,
	        'pcm-stream': {
			channels: format.channels,
			sampleRate: format.sampleRate,
			bitDepth: format.bitDepth
		}
	});
}

function sample()
{
	if (analyser)
	    console.log(analyser.getFrequencyData());
}

Sample output (~1 second)

{
raw_encoding: 208,
sampleRate: 44100,
channels: 2,
signed: true,
float: false,
ulaw: false,
alaw: false,
bitDepth: 16,
lowWaterMark: 0,
highWaterMark: 512
}

[ -40.1, -44.1, -57.2, -80.5, -85.9, -80.5, -57.2, -44.1 ]
[ -33.1, -37.4, -52.1, -84.8, -90, -84.8, -52.1, -37.4 ]
[ -36.9, -41.3, -56.8, -92.4, -88.1, -92.4, -56.8, -41.3 ]
[ -35.4, -40.1, -57.4, -83, -97, -83, -57.4, -40.1 ]
[ -27.3, -31.3, -44.3, -73.3, -96.7, -73.3, -44.3, -31.3 ]
[ -31.3, -35.6, -50.6, -77.8, -87.5, -77.8, -50.6, -35.6 ]
[ -33.5, -37.7, -51.9, -81.2, -98.4, -81.2, -51.9, -37.7 ]
[ -48.4, -52, -58.2, -71.6, -83.8, -71.6, -58.2, -52 ]
[ -32.5, -36.6, -50, -75.9, -89.1, -75.9, -50, -36.6 ]
[ -28, -32, -45.1, -73.1, -97.5, -73.1, -45.1, -32 ]
[ -28.5, -32.5, -46.1, -76.7, -100, -76.7, -46.1, -32.5 ]
[ -42.8, -46.3, -57.3, -77.3, -96.5, -77.3, -57.3, -46.3 ]
[ -37.8, -41.8, -55.1, -85, -97.8, -85, -55.1, -41.8 ]
[ -39.5, -43.6, -57.7, -96.3, -99.4, -96.3, -57.7, -43.6 ]
[ -47.4, -53.3, -59.5, -61.3, -65, -61.3, -59.5, -53.3 ]
[ -23.5, -27.6, -41.3, -75.7, -89.9, -75.7, -41.3, -27.6 ]
[ -31.2, -35.3, -48.7, -72.1, -78, -72.1, -48.7, -35.3 ]
[ -32, -36.3, -51.6, -81.2, -89.8, -81.2, -51.6, -36.3 ]
[ -32.6, -36.7, -50.4, -81.2, -91.2, -81.2, -50.4, -36.7 ]
[ -57.3, -51.6, -49.4, -56.4, -71.1, -56.4, -49.4, -51.6 ]
[ -42.3, -45.8, -55.8, -69.2, -83.5, -69.2, -55.8, -45.8 ]
[ -33.3, -37.6, -51.9, -79.4, -89.2, -79.4, -51.9, -37.6 ]
[ -37, -41.4, -56.7, -89.3, -88, -89.3, -56.7, -41.4 ]
[ -34.2, -38, -50.6, -74.4, -93.5, -74.4, -50.6, -38 ]
[ -38.1, -41.8, -53.9, -79.1, -100, -79.1, -53.9, -41.8 ]
[ -38.9, -42.5, -54.2, -72.9, -86.1, -72.9, -54.2, -42.5 ]
[ -50, -53.8, -65.7, -85.8, -96.6, -85.8, -65.7, -53.8 ]
[ -41.6, -45.6, -59, -87.6, -98.6, -87.6, -59, -45.6 ]
[ -53.7, -56, -58.5, -71.8, -83.9, -71.8, -58.5, -56 ]
[ -32.6, -36.7, -50, -75.9, -89.1, -75.9, -50, -36.7 ]
[ -28.1, -32, -45.1, -73.1, -97.5, -73.1, -45.1, -32 ]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.