fixed random values being obtained from PCM obtainer
This commit is contained in:
parent
50bc2bfdea
commit
fa8dd9622f
@ -62,7 +62,8 @@ public class PCMObtainer implements Observer, PCMSystem {
|
||||
df.setRoundingMode(RoundingMode.HALF_EVEN);
|
||||
}
|
||||
|
||||
private synchronized void calcPCMData() {
|
||||
private synchronized boolean calcPCMData() {
|
||||
boolean empty = true;
|
||||
short chanVal;
|
||||
for (int sid = 0; sid < PCM.length && sid < playingBuffer.remaining(); sid++) {
|
||||
PCM[sid] = 0;
|
||||
@ -72,8 +73,16 @@ public class PCMObtainer implements Observer, PCMSystem {
|
||||
}
|
||||
}
|
||||
PCM[sid] /= Short.MAX_VALUE + 1f;
|
||||
|
||||
if (PCM[sid] != 0) {
|
||||
empty = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return empty;
|
||||
}
|
||||
|
||||
private void checkValidityOfPlaybackBuffer() {
|
||||
// Begin comparison
|
||||
buffer.rewind();
|
||||
if (intermediateBuffer.compareTo(buffer) != 0) {
|
||||
@ -85,7 +94,7 @@ public class PCMObtainer implements Observer, PCMSystem {
|
||||
intermediateBuffer.flip();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void bufferChanged() {
|
||||
playingBuffer.rewind();
|
||||
playingBuffer.put(intermediateBuffer);
|
||||
@ -160,9 +169,11 @@ public class PCMObtainer implements Observer, PCMSystem {
|
||||
timeOfLastRead = TimeUtils.millis();
|
||||
|
||||
//calculate current pcm data and notify that there is new data
|
||||
calcPCMData();
|
||||
fft.realForward(PCM);
|
||||
updated = true;
|
||||
checkValidityOfPlaybackBuffer();
|
||||
updated = !calcPCMData();
|
||||
if (updated) {
|
||||
fft.realForward(PCM);
|
||||
}
|
||||
windowsRead++;
|
||||
|
||||
//contemplate synchronization
|
||||
|
Loading…
Reference in New Issue
Block a user