From d65b94cd499c52875077c56e3eaec38893c3034c Mon Sep 17 00:00:00 2001 From: Recrown Date: Fri, 14 Jul 2017 14:37:25 -0500 Subject: [PATCH] tuning with other songs --- .../zero1hd/polyjet/audio/AudioAnalyzer.java | 45 +++++++++---------- .../polyjet/audio/map/RhythmMapAlgorithm.java | 19 ++++---- .../polyjet/entity/enemies/Pellet.java | 1 - .../polyjet/ui/stages/GamePlayArea.java | 4 +- core/src/zero1hd/wavedecoder/WavDecoder.java | 13 ++++-- 5 files changed, 41 insertions(+), 41 deletions(-) diff --git a/core/src/zero1hd/polyjet/audio/AudioAnalyzer.java b/core/src/zero1hd/polyjet/audio/AudioAnalyzer.java index 4e5ea68..42e3ce1 100755 --- a/core/src/zero1hd/polyjet/audio/AudioAnalyzer.java +++ b/core/src/zero1hd/polyjet/audio/AudioAnalyzer.java @@ -47,7 +47,7 @@ public class AudioAnalyzer { public volatile MiniSender sender; - private float avgBPS; + private float avgSPB; int PUID; boolean work; @@ -64,17 +64,17 @@ public class AudioAnalyzer { int tasksDone = 0; int totalTasks = audioData.getSampleCount()/audioData.getReadWindowSize(); - bassThresholdMultiplier = 2f; - umThresholdMultiplier = 2f; + bassThresholdMultiplier = 1.7f; + umThresholdMultiplier = 1.5f; bassBinBegin = 1; - bassBinEnd = 20; + bassBinEnd = 25; UMBinBegin = 300; - UMBinEnd = 450; + UMBinEnd = 512; - bassThresholdCalcRange = thresholdRangeCalc(0.35f); - UMThresholdCalcRange = thresholdRangeCalc(0.7f); + bassThresholdCalcRange = thresholdRangeCalc(0.3f); + UMThresholdCalcRange = thresholdRangeCalc(0.35f); 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,13 +110,8 @@ public class AudioAnalyzer { //bass detection fluxVal = 0; for (int i = bassBinBegin; i < bassBinEnd && work; i++) { - if (spectrum[i] >= 0) { - fluxVal += ((spectrum[i] - lastSpectrum[i])) < 0 - ? 0 : (spectrum[i] - lastSpectrum[i]); - } else { - fluxVal += ((spectrum[i] - lastSpectrum[i])) < 0 - ? 0 : (spectrum[i] - lastSpectrum[i]); - } + fluxVal += ((spectrum[i] - lastSpectrum[i])) < 0 + ? 0 : (spectrum[i] - lastSpectrum[i]); } bassSpectralFlux.add(fluxVal); @@ -202,7 +197,7 @@ public class AudioAnalyzer { int lastID = 0; float bassBeats = 0; float umBeats = 0; - avgBPS = -1f; + avgSPB = -1f; for (int i = 0; i < umPrunned.size-1 && work; i++) { bassPeaks.add((bassPrunned.get(i) > bassPrunned.get(i+1) ? bassPrunned.get(i) : 0f)); if (bassPeaks.get(i) > bassMaxValue) { @@ -216,21 +211,21 @@ public class AudioAnalyzer { //overlapping beats if (bassPeaks.get(i) != 0 && umPeaks.get(i) != 0) { - overlappedPeaks.add(bassPeaks.get(i)+umPeaks.get(i)/2); + overlappedPeaks.add((bassPeaks.get(i)+umPeaks.get(i))/2f); } else { overlappedPeaks.add(0); } - if (avgBPS != -1) { + if (avgSPB != -1) { if (bassPeaks.get(i) == 0) { - avgBPS ++; + avgSPB ++; } else { bassBeats ++; lastID = i; } } else if (bassPeaks.get(i) != 0) { - avgBPS = 0; + avgSPB = 0; } if (bassPeaks.get(i) != 0) { @@ -244,10 +239,10 @@ public class AudioAnalyzer { } //then we minus one from the beats so it actually works out - avgBPS -= umPrunned.size-lastID; - avgBPS *= secondsPerWindow; - avgBPS /= bassBeats; - Gdx.app.debug("Audio Analyzer", "Avg BPS: " + avgBPS); + avgSPB -= umPrunned.size-lastID; + avgSPB *= secondsPerWindow; + avgSPB /= bassBeats; + Gdx.app.debug("Audio Analyzer", "Avg BPS: " + avgSPB); bassAvg /= bassBeats; umBeats /= umBeats; @@ -357,8 +352,8 @@ public class AudioAnalyzer { return audioData; } - public float getAvgBPS() { - return avgBPS; + public float getAvgSPB() { + return avgSPB; } public float getsecondsPerWindow() { diff --git a/core/src/zero1hd/polyjet/audio/map/RhythmMapAlgorithm.java b/core/src/zero1hd/polyjet/audio/map/RhythmMapAlgorithm.java index c7409a3..c97cc9f 100755 --- a/core/src/zero1hd/polyjet/audio/map/RhythmMapAlgorithm.java +++ b/core/src/zero1hd/polyjet/audio/map/RhythmMapAlgorithm.java @@ -22,7 +22,8 @@ public class RhythmMapAlgorithm implements Runnable { private float avgBass; private float avgUM; - private float avgBPS; + private float avgSPB; + private float umMax, bassMax; private float speedMod, healthMod; @@ -37,12 +38,14 @@ public class RhythmMapAlgorithm implements Runnable { overlappedPeaks = analyzer.getOverlappedPeaks(); map = new GamePlayMap(analyzer.getAudioData()); rand = new MersenneTwister(analyzer.getPUID()); - avgBPS = analyzer.getAvgBPS(); + avgSPB = analyzer.getAvgSPB(); windowPerSecond = 1/analyzer.getsecondsPerWindow(); this.speedMod = speedMod; this.healthMod = healthMod; + umMax = analyzer.getUMMaxValue(); + bassMax = analyzer.getBassMaxValue(); avgBass = analyzer.getBassAvg(); avgUM = analyzer.getUmAvg(); } @@ -53,22 +56,22 @@ public class RhythmMapAlgorithm implements Runnable { for (int index = 0; index < bassPeaks.size; index++) { if (bassPeaks.get(index) != 0 || UMPeaks.get(index) != 0) { int warningTime = (int) ((3/speedMod)*windowPerSecond); - if ((index+warningTime <= bassPeaks.size) && bassPeaks.get(index + warningTime) >= avgBass) { + if ((index+warningTime < bassPeaks.size) && bassPeaks.get(index + warningTime) >= avgBass*3f/4f) { //TODO basic void circle spawning - float endRadius = overlappedPeaks.get(index + warningTime)*Polyjet.GAME_AREA_HEIGHT/4; + float endRadius = bassPeaks.get(index + warningTime)/bassMax*(Polyjet.GAME_AREA_HEIGHT/4f); map.addToMap(Entities.VOID_CIRCLE, endRadius, rand.nextFloat()*Polyjet.GAME_AREA_WIDTH, rand.nextFloat()*Polyjet.GAME_AREA_HEIGHT, - endRadius/avgBPS, - warningTime + endRadius/avgSPB, + 3f/speedMod ); } if (bassPeaks.get(index) != 0) { map.addToMap(Entities.BAR, MathUtils.round(1.5f+rand.nextFloat()*(Polyjet.GAME_AREA_WIDTH-3)), - (8f/avgBPS)*speedMod); + (8f/avgSPB)*speedMod); } else { if (UMPeaks.get(index) != 0) { float xSpawnLocation = (rand.nextFloat()*(Polyjet.GAME_AREA_WIDTH-2))+1; @@ -76,7 +79,7 @@ public class RhythmMapAlgorithm implements Runnable { xSpawnLocation, Polyjet.GAME_AREA_HEIGHT-0.25f, 180*rand.nextFloat()+90, - speedMod*(1f/avgBPS)); + speedMod*(1f/avgSPB)); } } diff --git a/core/src/zero1hd/polyjet/entity/enemies/Pellet.java b/core/src/zero1hd/polyjet/entity/enemies/Pellet.java index abd9f80..8643a24 100755 --- a/core/src/zero1hd/polyjet/entity/enemies/Pellet.java +++ b/core/src/zero1hd/polyjet/entity/enemies/Pellet.java @@ -32,7 +32,6 @@ public class Pellet extends Actor implements Entity, Poolable { setSize(0.75f, 0.75f); hitBox.setSize(getWidth(), getHeight()); this.rate = rate; - setColor(1f, MathUtils.random(), 0f, 1f); } @Override diff --git a/core/src/zero1hd/polyjet/ui/stages/GamePlayArea.java b/core/src/zero1hd/polyjet/ui/stages/GamePlayArea.java index 8f96786..7463ee9 100755 --- a/core/src/zero1hd/polyjet/ui/stages/GamePlayArea.java +++ b/core/src/zero1hd/polyjet/ui/stages/GamePlayArea.java @@ -114,10 +114,8 @@ public class GamePlayArea extends Stage { @Override public void act(float delta) { - if (audioMap != null && time < audioMap.getPlayTime()) { - time += delta; - } if (audioMap != null) { + time = audioMap.getPlayableClip().getPosition(); ec.spawnEntity(this, audioMap.safeNextEntity()); } collisionDetector.collisionCheck(); diff --git a/core/src/zero1hd/wavedecoder/WavDecoder.java b/core/src/zero1hd/wavedecoder/WavDecoder.java index 6f1d89b..60c8f07 100755 --- a/core/src/zero1hd/wavedecoder/WavDecoder.java +++ b/core/src/zero1hd/wavedecoder/WavDecoder.java @@ -4,6 +4,7 @@ import java.io.DataInputStream; import java.io.IOException; import java.security.InvalidParameterException; +import com.badlogic.gdx.Gdx; import com.badlogic.gdx.files.FileHandle; public class WavDecoder { @@ -56,10 +57,14 @@ public class WavDecoder { String moreInfo = readBytesToString(4); if (moreInfo.equals("LIST")) { // 4 - readStream.skip(30); - if (!readBytesToString(4).equals("data")) { - throw new InvalidParameterException("failed to read data with extra info."); + while (true) { + if (readBytesToString(1).equals("d")) { + if (readBytesToString(3).equals("ata")) { + break; + } + } } + } else if (!moreInfo.equals("data")) { throw new InvalidParameterException("failed to read data."); } @@ -132,7 +137,7 @@ public class WavDecoder { for (int channel = 0; channel < getChannels(); channel++) { currentSample += readLittleEndianShort(); } - currentSample /= getChannels()*Short.MAX_VALUE+1; + currentSample /= getChannels() * Short.MAX_VALUE+1; samples[i] = currentSample; samplesRead++; } catch (IOException e) {