<commit_before>//////////////////////////////////////////////////////////////////////////
// node-core-audio - main module
//////////////////////////////////////////////////////////////////////////
//
// Main javascript audio API
/* ----------------------------------------------------------------------
													Object Structures
-------------------------------------------------------------------------
	
*/
//////////////////////////////////////////////////////////////////////////
// Node.js Exports
var globalNamespace = {};
(function (exports) {
	exports.createNewAudioEngine = function() {
		newAudioEngine= new AudioEngine();
		return newAudioEngine;
	};
}(typeof exports === 'object' && exports || globalNamespace));


//////////////////////////////////////////////////////////////////////////
// Namespace (lol)
var SHOW_DEBUG_PRINTS = true;
var MAX_SUPPORTED_CHANNELS = 6;													// We need to allocate our process audio for the max channels, 
																				// so we have to set some reasonable limit																				
var log = function( a ) { if(SHOW_DEBUG_PRINTS) console.log(a); };				// A log function we can turn off
var exists = function(a) { return typeof(a) == "undefined" ? false : true; };	// Check whether a variable exists
var dflt = function(a, b) { 													// Default a to b if a is undefined
	if( typeof(a) === "undefined" ){ 
		return b; 
	} else return a; 
};


//////////////////////////////////////////////////////////////////////////
// Constructor
function AudioEngine() {
	var audioEngineImpl = require( __dirname + "/build/Debug/NodeCoreAudio" );

	var settings = {
		inputChannels: 2,
		outputChannels: 2
	};

	var callback = function(input, lastInputOverflowed, lastOutputUnderflowed) {
	//	output[0] = output[1] = output[2] = output[3] = output[4] = output[5] = input[0];
        return input; //just copy input (mono) to each channel of our 5.1 output
    }
	
	this.audioEngine = audioEngineImpl.createAudioEngine( settings, callback );
	this.audioStreamer;
	
	this.processingCallbacks = [];
	this.uiUpdateCallbacks = [];
	this.didProcessAudio = false;
	
	this.outputBuffer = [];
	this.tempBuffer = [];
	this.processBuffer = [];
	
	// Allocate a processing buffer for each of our channels
	for( var iChannel = 0; iChannel<MAX_SUPPORTED_CHANNELS; ++iChannel ) {
		this.processBuffer[iChannel] = [];
	}
	
	// Start polling the audio engine for data as fast as we can	
	var _this = this;
	setInterval( function() {	
		_this.didProcessAudio = false;
		
		// Try to process audio
		var input = _this.audioEngine.read();

		/*
		for( var iChannel=0; iChannel<input.length; ++iChannel ) {
			for( var iSample=0; iSample<input[iChannel].length; ++iSample ) {
				input[iChannel][iSample] = iSample;
			}
		}
		*/

		var outputBuffer = _this.getProcessAudio()( input[0].length, input );

		if( outputBuffer === undefined )
			console.log( "Audio processing function didn't return an output buffer" );

		_this.audioEngine.write( outputBuffer );
		
		// Call our UI updates now that all the DSP work has been done
		for( var iUpdate=0; iUpdate < _this.uiUpdateCallbacks.length; ++iUpdate ) {
			_this.uiUpdateCallbacks[iUpdate]();
		}
	}, 0 );
} // end AudioEngine();


//////////////////////////////////////////////////////////////////////////
// Main audio processing function
AudioEngine.prototype.getProcessAudio = function() {
	var self = this;

	var options = this.audioEngine.getOptions(),
		numChannels = options.inputChannels;
	
	var processAudio = function( numSamples, inputBuffer ) {	
		console.log( "processing with " + self.processingCallbacks.length + " callbacks" );

		// If we don't have any processing callbacks, just get out
		if( self.processingCallbacks.length == 0 )
			return inputBuffer;
			
		var processBuffer = self.processBuffer;
			
		// We need to deinterleave the inputbuffer
		deInterleave( inputBuffer, processBuffer, numSamples, numChannels );

		// Call through to all of our processing callbacks
		for( var iCallback = 0; iCallback < self.processingCallbacks.length; ++iCallback ) {
			processBuffer = self.processingCallbacks[iCallback]( numSamples, processBuffer );
		} // end for each callback
		
		
		if( typeof(self.audioStreamer) != "undefined" ) {
			self.audioStreamer.streamAudio( processBuffer, numSamples, numChannels );
		}

		self.outputBuffer = processBuffer;
		
		var outputBuffer = self.outputBuffer;
		
		interleave( processBuffer, outputBuffer, numSamples, numChannels );
		
		self.didProcessAudio = true;
		
		// Return our output audio to the sound card
		return outputBuffer;
	} // end processAudio()
	
	return processAudio;
} // end AudioEngine.getProcessAudio()
<commit_msg>Fix bug in main audio loop<commit_after>//////////////////////////////////////////////////////////////////////////
// node-core-audio - main module
//////////////////////////////////////////////////////////////////////////
//
// Main javascript audio API
/* ----------------------------------------------------------------------
													Object Structures
-------------------------------------------------------------------------
	
*/
//////////////////////////////////////////////////////////////////////////
// Node.js Exports
var globalNamespace = {};
(function (exports) {
	exports.createNewAudioEngine = function() {
		newAudioEngine= new AudioEngine();
		return newAudioEngine;
	};
}(typeof exports === 'object' && exports || globalNamespace));


//////////////////////////////////////////////////////////////////////////
// Namespace (lol)
var SHOW_DEBUG_PRINTS = true;
var MAX_SUPPORTED_CHANNELS = 6;													// We need to allocate our process audio for the max channels, 
																				// so we have to set some reasonable limit																				
var log = function( a ) { if(SHOW_DEBUG_PRINTS) console.log(a); };				// A log function we can turn off
var exists = function(a) { return typeof(a) == "undefined" ? false : true; };	// Check whether a variable exists
var dflt = function(a, b) { 													// Default a to b if a is undefined
	if( typeof(a) === "undefined" ){ 
		return b; 
	} else return a; 
};


//////////////////////////////////////////////////////////////////////////
// Constructor
function AudioEngine() {
	var audioEngineImpl = require( __dirname + "/build/Debug/NodeCoreAudio" );

	var settings = {
		inputChannels: 2,
		outputChannels: 2
	};

	var callback = function(input, lastInputOverflowed, lastOutputUnderflowed) {
	//	output[0] = output[1] = output[2] = output[3] = output[4] = output[5] = input[0];
        return input; //just copy input (mono) to each channel of our 5.1 output
    }
	
	this.audioEngine = audioEngineImpl.createAudioEngine( settings, callback );
	this.audioStreamer;
	
	this.processingCallbacks = [];
	this.uiUpdateCallbacks = [];
	this.didProcessAudio = false;
	
	this.outputBuffer = [];
	this.tempBuffer = [];
	this.processBuffer = [];
	
	// Allocate a processing buffer for each of our channels
	for( var iChannel = 0; iChannel<MAX_SUPPORTED_CHANNELS; ++iChannel ) {
		this.processBuffer[iChannel] = [];
	}
	
	// Start polling the audio engine for data as fast as we can	
	var _this = this;
	setInterval( function() {	
		_this.didProcessAudio = false;
		
		// Try to process audio
		var input = _this.audioEngine.read();

		/*
		for( var iChannel=0; iChannel<input.length; ++iChannel ) {
			for( var iSample=0; iSample<input[iChannel].length; ++iSample ) {
				input[iChannel][iSample] = iSample;
			}
		}
		*/

		var outputBuffer = _this.getProcessAudio()( input[0].length, input );

		if( outputBuffer === undefined ) {
			console.log( "Audio processing function didn't return an output buffer" );
		}

		_this.audioEngine.write( outputBuffer );
		
		// Call our UI updates now that all the DSP work has been done
		for( var iUpdate=0; iUpdate < _this.uiUpdateCallbacks.length; ++iUpdate ) {
			_this.uiUpdateCallbacks[iUpdate]();
		}
	}, 0 );
} // end AudioEngine();


//////////////////////////////////////////////////////////////////////////
// Returns our main audio processing function
AudioEngine.prototype.getProcessAudio = function() {
	var self = this;

	var options = this.audioEngine.getOptions(),
		numChannels = options.inputChannels;
	
	var processAudio = function( numSamples, inputBuffer ) {	

		// If we don't have any processing callbacks, just get out
		if( self.processingCallbacks.length == 0 )
			return inputBuffer;
			
		var processBuffer = self.processBuffer;
			
		// We need to deinterleave the inputbuffer
		deInterleave( inputBuffer, processBuffer, numSamples, numChannels );

		// Call through to all of our processing callbacks
		for( var iCallback = 0; iCallback < self.processingCallbacks.length; ++iCallback ) {
			processBuffer = self.processingCallbacks[iCallback]( numSamples, processBuffer );
		} // end for each callback
		
		
		if( typeof(self.audioStreamer) != "undefined" ) {
			self.audioStreamer.streamAudio( processBuffer, numSamples, numChannels );
		}
		
		var outputBuffer = self.outputBuffer;
		
		interleave( processBuffer, outputBuffer, numSamples, numChannels );
		
		self.didProcessAudio = true;
		
		// Return our output audio to the sound card
		return outputBuffer;
	} // end processAudio()
	
	return processAudio;
} // end AudioEngine.getProcessAudio()

{'fraction_non_alphanumeric': 0.22733642341274118, 'fraction_numerical': 0.004311738708634257, 'mean_word_length': 2.090606262491672, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6467129', 'n_tokens_mistral': 2744, 'n_tokens_neox': 2419, 'n_words': 718}