sonic
sonic copied to clipboard
There is noise when playing at low speed
I'm using sonic with exoplayer There is noise when playing at x0.5 It's a lot worse than what you hear on a macbook
Can you help me.
I replaced the old one with the latest sonic.java, and implemented the following methods
public void getOutput(ShortBuffer buffer) {
int framesToRead = Math.min(buffer.limit() / numChannels, numOutputSamples);
int size = framesToRead * numChannels;
if (bufferToRead == null || bufferToRead.length < size) {
bufferToRead = new short[size];
}
readShortFromStream(bufferToRead, framesToRead);
buffer.put(bufferToRead, 0, size);
}
public void queueInput(ShortBuffer buffer) {
int bufferSize = buffer.remaining();
int framesToWrite = bufferSize / numChannels;
if (bufferToWrite == null || bufferToWrite.length < buffer.limit()) {
bufferToWrite = new short[buffer.limit()];
}
buffer.get(bufferToWrite, 0, buffer.limit());
writeShortToStream(bufferToWrite, framesToWrite);
}
public void queueEndOfStream() {
int remainingFrameCount = numInputSamples;
float s = speed / pitch;
float r = rate * pitch;
int expectedOutputFrames =
numOutputSamples + (int) ((remainingFrameCount / s + numPitchSamples) / r + 0.5f);
// Add enough silence to flush both input and pitch buffers.
enlargeInputBufferIfNeeded(remainingFrameCount + 2 * maxRequired);
for (int xSample = 0; xSample < 2 * maxRequired * numChannels; xSample++) {
inputBuffer[remainingFrameCount * numChannels + xSample] = 0;
}
numInputSamples += 2 * maxRequired;
processStreamInput();
// Throw away any extra frames we generated due to the silence we added.
if (numOutputSamples > expectedOutputFrames) {
numOutputSamples = expectedOutputFrames;
}
// Empty input and pitch buffers.
numInputSamples = 0;
this.remainingInputToCopy = 0;
numPitchSamples = 0;
}
public int getOutputSize() {
return numOutputSamples * numChannels * 2;
}
Mp3 files for testing
exoplayer version 2.10.8