Skip to content

[PCM Offload, DRAFT] PowerPlay Sample App Implementation #2197

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

madebymozart
Copy link
Collaborator

This is the powerplay sample app, which allows a user, through oboe, to choose a new performance mode that allows the CPU to sleep significantly more, thus aiding in it's ability to save power.

@madebymozart madebymozart added P1 high priority apps related to a test or example app requires device Requires a specific Android phone model or other specific hardware to test labels Apr 8, 2025
@madebymozart madebymozart added this to the future milestone Apr 8, 2025
@madebymozart madebymozart requested review from flamme and robertwu1 April 8, 2025 14:29
@madebymozart madebymozart self-assigned this Apr 8, 2025
* Add offload support.

Fixes #2154.
@@ -0,0 +1,19 @@
# Minimal Oboe
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO - Update Readme

Copy link
Collaborator

@flamme flamme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change should be rebased so that the commit doesn't show the already merged PR.

mParent->mSampleSources[index]->mixAudio((float*)audioData, mParent->mChannelCount,
numFrames);
mParent->resetAll();
if (mParent->openStream(PerformanceMode::None) && mParent->startStream()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: Why this is opened with performance none?


builder.setErrorCallback(mErrorCallback);
builder.setPresentationCallback(mPresentationCallback);
builder.setPerformanceMode(performanceMode);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, the set will return a pointer of the builder, it may looks easier as below.

builder.setChannelCount(mChannelCount)
        ->setDataCallback(mDataCallback)
...

if (tryCount > 0) {
usleep(20 * 1000); // Sleep between tries to give the system time to settle.
wasOpenSuccessful = openStream(
PerformanceMode::None); // Try to open the stream again after the first try.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the original was setting performance mode as low latency, why it is changed to performance mode none?

mSampleBuffers.clear();
mSampleSources.clear();
void SimpleMultiPlayer::triggerUp(int32_t index) {
// if (index < mNumSampleBuffers) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: why this is commented out?

@@ -33,10 +33,10 @@ class SimpleMultiPlayer {
public:
SimpleMultiPlayer();

void setupAudioStream(int32_t channelCount);
void setupAudioStream(int32_t channelCount, oboe::PerformanceMode performanceMode);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one concern that this may break existing apps using SimpleMultiPlayer. But it is up to you to decide if a default parameter is preferred or not.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If DrumThumper is using SimpleMultiPlayer then switching to None would give it high latency! That would be a problem.

) {
__android_log_print(ANDROID_LOG_INFO, TAG, "%s", "setupAudioStreamNative()");

// TODO - Dynamically Set Performance Mode
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the latest PowerPlay you shared already support dynamic setting performance mode, right?

JNIEXPORT void JNICALL
Java_com_example_powerplay_engine_PowerPlayAudioPlayer_startPlayingNative(JNIEnv *env, jobject,
jint index,
jint offload) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is used to decide what performance mode is. It will be simpler to have the same values as performance mode defined at the kotlin layer and pass it down.

@@ -0,0 +1,104 @@
package com.example.powerplay.engine
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think new file should have copy right comment.


}

AudioManager.AUDIOFOCUS_LOSS, AudioManager.AUDIOFOCUS_LOSS_TRANSIENT, AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK -> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a todo here when focus loss, it is expected to pause music.


class PowerPlayAudioPlayer() : DefaultLifecycleObserver {
/**
*
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any comment here? Otherwise, please remove

@@ -42,5 +42,5 @@ target_link_options(liveEffect PRIVATE "-Wl,-z,max-page-size=16384")

# Enable optimization flags: if having problems with source level debugging,
# disable -Ofast ( and debug ), re-enable it after done debugging.
target_compile_options(liveEffect PRIVATE -Wall -Werror "$<$<CONFIG:RELEASE>:-Ofast>")
target_compile_options(liveEffect PRIVATE -Wall -Werror "$<$<CONFIG:RELEASE>:-O3 -ffast-math>")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be a great change. But it seems unrelated to the new PowerPlay app. If you see room for improvement, it would be easier to submit those as separate PRs.

sampleBuffer->loadSampleData(&reader);

const auto source = new OneShotSampleSource(sampleBuffer, 0);
sDTPlayer.addSampleSource(source, sampleBuffer);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who manages the deletion of source?

}

/**
* Native (JNI) implementation of DrumPlayer.getOutputReset()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change comments

MaterialTheme(
colorScheme = LightColorScheme, typography = Typography, content = content
)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add new lines to all files

val result = audioManager.requestAudioFocus(audioFocusRequest)
if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
// Start playback only when audio focus is granted
// ...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add todo here

builder.setErrorCallback(mErrorCallback);
builder.setPresentationCallback(mPresentationCallback);
builder.setPerformanceMode(performanceMode);
builder.setFramesPerDataCallback(128);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you verify whether DrumThumper works similarly to before?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DrumThumper may be OK if it passes an explicit LowLatency parameter.
But third-party apps using this as a library class may be impacted if the default behavior changes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apps related to a test or example app P1 high priority requires device Requires a specific Android phone model or other specific hardware to test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants