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