sonic icon indicating copy to clipboard operation
sonic copied to clipboard

There is noise when playing at low speed

Open imcloud opened this issue 5 years ago • 1 comments

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.

ExoPlayer

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

w.mp3.zip

imcloud avatar Dec 18 '19 04:12 imcloud

exoplayer version 2.10.8

imcloud avatar Dec 18 '19 05:12 imcloud