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