audio analyzer tuned
This commit is contained in:
		@@ -64,17 +64,17 @@ public class AudioAnalyzer {
 | 
			
		||||
				int tasksDone = 0;
 | 
			
		||||
				int totalTasks = audioData.getSampleCount()/audioData.getReadWindowSize();
 | 
			
		||||
				
 | 
			
		||||
				bassThresholdMultiplier = 2.7f;
 | 
			
		||||
				bassThresholdMultiplier = 2.6f;
 | 
			
		||||
				umThresholdMultiplier = 2f;
 | 
			
		||||
				
 | 
			
		||||
				bassBinBegin = 2;
 | 
			
		||||
				bassBinEnd = 17;
 | 
			
		||||
				bassBinBegin = 7;
 | 
			
		||||
				bassBinEnd = 20;
 | 
			
		||||
				
 | 
			
		||||
				UMBinBegin = 300;
 | 
			
		||||
				UMBinEnd = 450;
 | 
			
		||||
				
 | 
			
		||||
				UMThresholdCalcRange = thresholdRangeCalc(0.6f);
 | 
			
		||||
				bassThresholdCalcRange = thresholdRangeCalc(0.7f);
 | 
			
		||||
				bassThresholdCalcRange = thresholdRangeCalc(0.4f);
 | 
			
		||||
				UMThresholdCalcRange = thresholdRangeCalc(0.7f);
 | 
			
		||||
				
 | 
			
		||||
				Gdx.app.debug("Read freq", String.valueOf(audioData.getFormat().getSampleRate()));
 | 
			
		||||
				Gdx.app.debug("Using following bin ranges", "\nBass freq begin: " + bassBinBegin + "\nBass freq end: " + bassBinEnd + "\nMain freq begin: " + UMBinBegin + "\nMain freq end: " + UMBinEnd);
 | 
			
		||||
@@ -110,16 +110,16 @@ public class AudioAnalyzer {
 | 
			
		||||
					//bass detection
 | 
			
		||||
					fluxVal = 0;
 | 
			
		||||
					for (int i = bassBinBegin; i < bassBinEnd && work; i++) {
 | 
			
		||||
						fluxVal += ((spectrum[i] - lastSpectrum[i])) > 0
 | 
			
		||||
								? (spectrum[i] - lastSpectrum[i]) : 0;
 | 
			
		||||
						fluxVal += ((spectrum[i] - lastSpectrum[i])) < 0
 | 
			
		||||
								? 0 : (spectrum[i] - lastSpectrum[i]);
 | 
			
		||||
					}
 | 
			
		||||
					bassSpectralFlux.add(fluxVal);
 | 
			
		||||
					
 | 
			
		||||
					//main detection
 | 
			
		||||
					fluxVal = 0;
 | 
			
		||||
					for (int i = UMBinBegin; i < UMBinEnd && work; i++) {
 | 
			
		||||
						fluxVal += ((spectrum[i] - lastSpectrum[i])) > 0
 | 
			
		||||
								? (spectrum[i] - lastSpectrum[i]) : 0;
 | 
			
		||||
						fluxVal += ((spectrum[i] - lastSpectrum[i])) < 0
 | 
			
		||||
								? 0 : (spectrum[i] - lastSpectrum[i]);
 | 
			
		||||
					}
 | 
			
		||||
					umSpectralFlux.add(fluxVal);
 | 
			
		||||
					tasksDone++;
 | 
			
		||||
@@ -199,12 +199,12 @@ public class AudioAnalyzer {
 | 
			
		||||
				float umBeats = 0;
 | 
			
		||||
				avgBPS = -1f;
 | 
			
		||||
				for (int i = 0; i < umPrunned.size-1 && work; i++) {
 | 
			
		||||
					bassPeaks.add((bassPrunned.get(i) > bassPrunned.get(i+1) ? bassPrunned.get(i) : 0));
 | 
			
		||||
					bassPeaks.add((bassPrunned.get(i) > bassPrunned.get(i+1) ? bassPrunned.get(i) : 0f));
 | 
			
		||||
					if (bassPeaks.get(i) > bassMaxValue) {
 | 
			
		||||
						bassMaxValue = bassPeaks.get(i);
 | 
			
		||||
					}
 | 
			
		||||
					
 | 
			
		||||
					umPeaks.add((umPrunned.get(i) > umPrunned.get(i+1) ? umPrunned.get(i) : 0));
 | 
			
		||||
					umPeaks.add((umPrunned.get(i) > umPrunned.get(i+1) ? umPrunned.get(i) : 0f));
 | 
			
		||||
					if (umPeaks.get(i) > UMMaxValue) {
 | 
			
		||||
						UMMaxValue = umPeaks.get(i);
 | 
			
		||||
					}
 | 
			
		||||
@@ -305,8 +305,7 @@ public class AudioAnalyzer {
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	private int thresholdRangeCalc(float durationOfRange) {
 | 
			
		||||
		float timePerWindow = (float)audioData.getReadWindowSize()/audioData.getFormat().getSampleRate();
 | 
			
		||||
		return (int) (durationOfRange/timePerWindow);
 | 
			
		||||
		return (int) (durationOfRange/(audioData.getReadWindowSize()/audioData.getFormat().getSampleRate()));
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public float getBassMaxValue() {
 | 
			
		||||
 
 | 
			
		||||
@@ -55,7 +55,7 @@ public class RhythmMapAlgorithm implements Runnable {
 | 
			
		||||
				int warningTime = (int) ((3/speedMod)*windowPerSecond);
 | 
			
		||||
				if ((index+warningTime <= bassPeaks.size) && bassPeaks.get(index + warningTime) >= avgBass) {
 | 
			
		||||
					//TODO basic void circle spawning
 | 
			
		||||
					float endRadius = overlappedPeaks.get(index + warningTime)*Polyjet.GAME_AREA_WIDTH;
 | 
			
		||||
					float endRadius = overlappedPeaks.get(index + warningTime)*Polyjet.GAME_AREA_HEIGHT;
 | 
			
		||||
					
 | 
			
		||||
					map.addToMap(Entities.VOID_CIRCLE, 
 | 
			
		||||
							endRadius, 
 | 
			
		||||
 
 | 
			
		||||
@@ -17,6 +17,8 @@ public class AudioGraph extends Actor {
 | 
			
		||||
	int dataIndex;
 | 
			
		||||
	int displayMode;
 | 
			
		||||
	
 | 
			
		||||
	float scale;
 | 
			
		||||
	
 | 
			
		||||
	public AudioGraph(int graphSizeW, int graphSizeH) {
 | 
			
		||||
		audioGraph = new Pixmap(graphSizeW, graphSizeH, Format.RGBA8888);
 | 
			
		||||
		audioGraph.setColor(0.1f, 0.1f, 0.1f, 0.75f);
 | 
			
		||||
@@ -25,24 +27,25 @@ public class AudioGraph extends Actor {
 | 
			
		||||
		textureOfGraph = new Texture(audioGraph);
 | 
			
		||||
		setWidth(graphSizeW);
 | 
			
		||||
		setHeight(graphSizeH);
 | 
			
		||||
		
 | 
			
		||||
		scale = audioGraph.getHeight();
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public void setAudioDataIndex(int audioDataIndex) {
 | 
			
		||||
		this.dataIndex = audioDataIndex;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	float scale = 0.2f;
 | 
			
		||||
	@Override
 | 
			
		||||
	public void act(float delta) {
 | 
			
		||||
		audioGraph.setColor(0f, 0f, 0f, 0.75f);
 | 
			
		||||
		audioGraph.fill();
 | 
			
		||||
		
 | 
			
		||||
		if (Gdx.input.isKeyPressed(Keys.COMMA)) {
 | 
			
		||||
			if (scale > 0.02) {
 | 
			
		||||
			if (scale > 0.05f) {
 | 
			
		||||
				scale -= 0.005f;
 | 
			
		||||
			}
 | 
			
		||||
		} else if (Gdx.input.isKeyPressed(Keys.PERIOD)) {
 | 
			
		||||
			if (scale < 1.5) {
 | 
			
		||||
			if (scale < audioGraph.getHeight()) {
 | 
			
		||||
				scale += 0.005f;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
@@ -61,7 +64,6 @@ public class AudioGraph extends Actor {
 | 
			
		||||
				try {
 | 
			
		||||
					audioGraph.drawLine(x, audioGraph.getHeight(), x, (int) (audioGraph.getHeight()-mainGraph.get(dataIndex+x-audioGraph.getWidth()/2)*scale));
 | 
			
		||||
				} catch (NullPointerException | IndexOutOfBoundsException e) {
 | 
			
		||||
					
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
@@ -71,7 +73,6 @@ public class AudioGraph extends Actor {
 | 
			
		||||
				try {
 | 
			
		||||
					audioGraph.drawLine(x, audioGraph.getHeight(), x, (int) (audioGraph.getHeight()-overlayGraph.get(dataIndex+x-audioGraph.getWidth()/2)*scale));
 | 
			
		||||
				} catch (NullPointerException | IndexOutOfBoundsException e) {
 | 
			
		||||
					
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			break;
 | 
			
		||||
@@ -81,7 +82,6 @@ public class AudioGraph extends Actor {
 | 
			
		||||
				try {
 | 
			
		||||
					audioGraph.drawLine(x, audioGraph.getHeight(), x, (int) (audioGraph.getHeight()-mainGraph.get(dataIndex+x-audioGraph.getWidth()/2)*scale));
 | 
			
		||||
				} catch (NullPointerException | IndexOutOfBoundsException e) {
 | 
			
		||||
					
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			break;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user