Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There is noise when playing at low speed #21

Open
imcloud opened this issue Dec 18, 2019 · 1 comment
Open

There is noise when playing at low speed #21

imcloud opened this issue Dec 18, 2019 · 1 comment

Comments

@imcloud
Copy link

imcloud commented Dec 18, 2019

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
Copy link
Author

imcloud commented Dec 18, 2019

exoplayer version 2.10.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant