-
Notifications
You must be signed in to change notification settings - Fork 585
[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
base: main
Are you sure you want to change the base?
Conversation
dc35492
to
090d355
Compare
* Add offload support. Fixes #2154.
090d355
to
ca26007
Compare
@@ -0,0 +1,19 @@ | |||
# Minimal Oboe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO - Update Readme
There was a problem hiding this 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()) { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 -> { |
There was a problem hiding this comment.
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 { | ||
/** | ||
* |
There was a problem hiding this comment.
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>") |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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 | ||
) | ||
} |
There was a problem hiding this comment.
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 | ||
// ... |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
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.