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

Seek performance #156

Open
jazzbre opened this issue Jul 20, 2017 · 5 comments
Open

Seek performance #156

jazzbre opened this issue Jul 20, 2017 · 5 comments

Comments

@jazzbre
Copy link

jazzbre commented Jul 20, 2017

Right now, WaveStreamInstance::seek is implemented as succesive getAudio calls until the expected sample is hit, but that actually means that it decodes the audio data (an ogg for example) which is a big performance hit.

Couldn't we do this much more efficiently by calling stb_vorbis_seek and then just do a getAudio to get the correct sample position?

@jazzbre
Copy link
Author

jazzbre commented Jul 20, 2017

Something like this:

void WavStreamInstance::seek(time aSeconds, float *mScratch, unsigned int mScratchSize) {

    if(mOgg)
    {
        double offset = aSeconds - mStreamTime;
        if (offset < 0)
        {
            if (rewind() != SO_NO_ERROR)
            {
                // can't do generic seek backwards unless we can rewind.
                return;
            }
            offset = aSeconds;
        }
        int samples_to_seek = (int)floor(mSamplerate * offset);
    
        stb_vorbis_seek_frame(mOgg, samples_to_seek);
        mOffset = stb_vorbis_get_sample_offset(mOgg);
        getAudio(mScratch, samples_to_seek - mOffset);
        mStreamTime = aSeconds;
    } else {
        AudioSourceInstance::seek(aSeconds, mScratch, mScratchSize);
    }
}

@Unit158
Copy link

Unit158 commented Feb 17, 2018

Working on this.

@Unit158
Copy link

Unit158 commented Feb 20, 2018

I don't understand the importance of returning the samples in the scratch buffer - this poses a problem if the user expects to be able to seek backwards in a file efficiently. (Why should I seek to zero, then forward to the point I want to find?) I'm looking at solving this problem with a bit of a lack of breadth, so I'm probably an idiot and just haven't thought about the use cases enough...

EDIT: yep. im an idiot; they're just discarded...

@jarikomppa
Copy link
Owner

Yeah, the scratch buffer is just for the "tape" seeking mechanism, so we don't need to allocate a buffer inside the function (or use humongous amount of stack).

@ghost
Copy link

ghost commented Jan 4, 2021

@Unit158 Are you still working on this? For me, seeking forward doesn't even seem to work at all, and seeking backwards sometimes does. It's quite unreliable.

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

No branches or pull requests

3 participants