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

Clear cached points on AdvancedAudioPlayer #776

Open
renezuidhof opened this issue Mar 17, 2024 · 5 comments
Open

Clear cached points on AdvancedAudioPlayer #776

renezuidhof opened this issue Mar 17, 2024 · 5 comments

Comments

@renezuidhof
Copy link

renezuidhof commented Mar 17, 2024

Superpowered version: 2.6.2 (d67e895)

Describe the bug
In my Android app I'm trying to use audioPlayer.openPCM16AudioInMemory to play audio from memory. After opening the audio in memory I want to edit the memory 'in place' while I expect the audioPlayer to always play whatever is in memory. This almost works, though it seems that the start point is cached in the audioPlayer and I can't see a way to clear this cached point.

Playing around with loopBetween, making sure it's start point is outside of the cached memory, seems to work. But this is not something I can use as it is not a very reliable fix.

Steps to Reproduce
Basically I do this:

audioPlayer.openPCM16AudioInMemory(workingAudioBuffer, sampleRate, durationInFrames);
audioPlayer.loopBetween(0, duration)

// The audio is playing

// At some point I do this:

std::copy(newAudioBuffer,
          newAudioBuffer + (duration * numberOfChannels),
          workingAudioBuffer);

// I expect the audioPlayer to play the new audio. But instead it plays ~1 second of 'old' audio and then the new audio.

Let me know if you would like an edited example project.

@gaborszanto
Copy link
Member

The player was never designed with your use-case in mind. Can I consider this as a feature request?

@renezuidhof
Copy link
Author

Yes, it is indeed more like a feature request. I guess I was hoping it would magically work :)

@renezuidhof
Copy link
Author

renezuidhof commented Mar 17, 2024

I was also trying to call openPCM16AudioInMemory again after changing the audio in memory. But I think the audioPlayer takes ownership over the memory so it gets freed after calling openPCM16AudioInMemory again. So opening the same memory location would cause problems. Correct me if I'm wrong.

Could this work with using the AudioInMemory class with a positive retain count? Is this something you would recommend?

@webmonch
Copy link

@gaborszanto could you please clarify the internal behaviour of the player and caching points?

Does player cache internalBufferSizeSeconds of audio when playing?
What happens when internalBufferSizeSeconds is 0? I noticed there is still caches audio in this case which I did not expect to be the case.

The value 0 enables "offline mode", where the player can not be used for real-time playback, but can process audio in an iteration

What do you mean by "can not be used for real-time playback, but can process audio in an iteration"?

@gaborszanto
Copy link
Member

Yes, the player caches approximately internalBufferSizeSeconds of audio when playing.

If that value is 0, it only caches the next chunk of audio. The size of the chunk depends on the audio format. Around 23 ms for the typical AAC file for example. That is typically too small for "live" playback, the risk of audio dropouts is too high for such small buffer size. Therefore the value 0 is only useful for "offline" playback.

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

3 participants