<commit_before>

	var Visualizer = function(can, audio,conf){
		var canvas = can;
		var audioCtx = audio;
		var canvasCtx;
		var analyser = audioCtx.createAnalyser();
		var config = conf || { };
		var animation;
		var bufferLength = config.bufferLength || 1024;

		var dataArray = new Uint8Array();
		var worker = new Worker("js/visualizerWorker.js");



		worker.onmessage = function(event){
			switch(event.data.command) {
				case 'process': 
				console.info(event.data);
				dataArray = Uint8Array.from(event.data.data);
				console.info(dataArray);
				console.log("new buffer recieved");
				break;
				case  'stop':
				cancelAnimationFrame(animation);
				dataArray = new Uint8Array();
				draw();
				console.info("stop order recieved");
				break;
				case  'start':
				update();
				console.info("start order recieved");
				break;
		}
		};
		var init = function(){
			console.info("initialization of DOM elements of the visualizer");
			 if(!!!canvas){
			 	canvas = document.getElementById("canvas");
			 }
			 canvasCtx = canvas.getContext('2d');
			 analyser.fftSize = 2048;
		}
		
		

		 
	    var draw = function() {  
		    canvasCtx.save();  
		   
		    analyser.getByteTimeDomainData(dataArray);
		    canvasCtx.fillStyle = 'rgb(200, 200, 200)';
		    canvasCtx.fillRect(0, 0, canvas.width, canvas.height);
		    canvasCtx.lineWidth = 1;

		    var gradient=canvasCtx.createLinearGradient(0,0,170,0);
			gradient.addColorStop("0","magenta");
			gradient.addColorStop("0.5","blue");
			gradient.addColorStop("1.0","red");

		    canvasCtx.strokeStyle = gradient;
		    canvasCtx.beginPath();
		    var sliceWidth = canvas.width * 1.0 / bufferLength;
		    var x = 0;
		      
		    for(var i = 0; i < bufferLength; i++) {
		      var v = dataArray[i] / 128.0;
		      var y = v * canvas.height/2;

		      if(i === 0) {
		        canvasCtx.moveTo(x, y);
		      } else {
		        canvasCtx.lineTo(x, y);
		      }

		      x += sliceWidth;
		    }
		    canvasCtx.lineTo(canvas.width, canvas.height/2);
		    canvasCtx.stroke(); 
		    canvasCtx.restore();
	  };

	  var update = function(){
	  	draw();
	  	animation = requestAnimationFrame(update);  
	  }
	  var getWorker = function(){
	  	return worker;
	  }
	  var stream = function(source){
	  		source.connect(analyser);
	  }
	  return {
	  	 update,
	  	 init,
	  	 getWorker,
	  	 stream
	  };
	}
<commit_msg>Amelioration visuel son<commit_after>

	var Visualizer = function(can, audio,conf){
		var canvas = can;
		var audioCtx = audio;
		var canvasCtx;
		var analyser = audioCtx.createAnalyser();
		var config = conf || { };
		var animation;
		var bufferLength = config.bufferLength || 1024;
        var lastSoundWaves = [];
        var numberSoundWavesKeep = 2;
        var skipWaves = 50;
        var currentWaves = 1;
        
		var dataArray = new Uint8Array();
		var worker = new Worker("js/visualizerWorker.js");

        var Point = function(pointX, pointY){
            
            var x = pointX;
            var y = pointY;
            
            return {
                x,y
            };
        }
        
		worker.onmessage = function(event){
			switch(event.data.command) {
				case 'process': 
				console.info(event.data);
				dataArray = Uint8Array.from(event.data.data);
				console.info(dataArray);
				console.log("new buffer recieved");
				break;
				case  'stop':
				cancelAnimationFrame(animation);
				dataArray = new Uint8Array();
				draw();
				console.info("stop order recieved");
				break;
				case  'start':
				update();
				console.info("start order recieved");
				break;
		}
		};
		var init = function(){
			console.info("initialization of DOM elements of the visualizer");
			 if(!!!canvas){
			 	canvas = document.getElementById("canvas");
			 }
			 canvasCtx = canvas.getContext('2d');
			 analyser.fftSize = 2048;
		}
		
		
        
        function pushSoundWave(points){
            currentWaves++;
            if(currentWaves%skipWaves==0){
                 if(lastSoundWaves.length >= numberSoundWavesKeep){
                     lastSoundWaves.pop();
                }
                lastSoundWaves.push(points);     
            }
             
        }

		 
	    var draw = function() {  
            var soundWave = [];
            
		    canvasCtx.save();  
		   
		    analyser.getByteTimeDomainData(dataArray);
		    canvasCtx.fillStyle = 'rgb(0,0,0)';
		    canvasCtx.fillRect(0, 0, canvas.width, canvas.height);
		    canvasCtx.lineWidth = 5;

		    canvasCtx.strokeStyle = "purple";
		    canvasCtx.beginPath();
		    var sliceWidth = canvas.width / bufferLength;
		    var x = 0;
		      
		    for(var i = 0; i < bufferLength; i++) {
              
		      var v = dataArray[i] / 128.0;
		      var y = v * canvas.height/2;

		      if(i === 0) {
		        canvasCtx.moveTo(x, y);
		      } else {
                canvasCtx.lineTo(x, y); 
                soundWave.push(new Point(x, y));
		      }
		      x += sliceWidth;
		    }
            
		    canvasCtx.lineTo(canvas.width, canvas.height/2);
            canvasCtx.lineTo(0, canvas.height/2);
            canvasCtx.stroke();
            canvasCtx.restore();
            drawSoundWaves();
            pushSoundWave();
		    
	  };
      
      function drawSoundWaves(){
           
          console.log("drawing sound + " + lastSoundWaves.length);
          canvasCtx.strokeStyle = getRandomColor();
          canvasCtx.lineWidth = 0.3;
          for(wave in lastSoundWaves){
              canvasCtx.save();  
              for(p in wave){
                 canvasCtx.lineTo(p.x, p.y);     
              }
              canvasCtx.lineTo(canvas.width, canvas.height/2);
              canvasCtx.lineTo(0, canvas.height/2);
              canvasCtx.stroke(); 
              canvasCtx.restore();  
          }
      }
        
        
    function getRandomColor() {
        var letters = '0123456789ABCDEF'.split('');
        var color = '#';
        for (var i = 0; i < 6; i++ ) {
            color += letters[Math.floor(Math.random() * 16)];
        }
        return color;
    }
	  var update = function(){
	  	draw();
	  	animation = requestAnimationFrame(update);  
	  }
	  var getWorker = function(){
	  	return worker;
	  }
	  var stream = function(source){
	  		source.connect(analyser);
	  }
	  return {
	  	 update,
	  	 init,
	  	 getWorker,
	  	 stream
	  };
	}

{'fraction_non_alphanumeric': 0.12629432067775337, 'fraction_numerical': 0.015531848133040477, 'mean_word_length': 1.9296875, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 4, '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': '3281104', 'n_tokens_mistral': 2330, 'n_tokens_neox': 1976, 'n_words': 395}