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

Improve play()/pause() response #43

Merged
merged 3 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class OpenSLMediaPlayerContext implements IReleasable {
public static class Parameters {
public int options = 0;
public int streamType = AudioManager.STREAM_MUSIC;
public int shortFadeDuration = 25; // [milli seconds]
public int shortFadeDuration = 15; // [milli seconds]
public int longFadeDuration = 1500; // [milli seconds]
public int resamplerQuality = RESAMPLER_QUALITY_MIDDLE;
public int hqEqualizerImplType = HQ_EQUALIZER_IMPL_BASIC_PEAKING_FILTER;
Expand Down
3 changes: 1 addition & 2 deletions library/src/main/jni/openslmediaplayer/source/AudioMixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1562,8 +1562,7 @@ bool AudioMixer::Impl::requestThreadApplyAudioSourceSetItems() noexcept
}

// wake up mixer thread
control_flags_t &ref_ctrl_flg = mixer_thread_control_flags_;
if (applied && (ref_ctrl_flg.load(std::memory_order_relaxed) & CONTROL_FLAG_REQUEST_SUSPENDED_STATE)) {
if (applied) {
utils::pt_unique_lock lock(mutex_mixer_thread_);
cond_mixer_thread_.notify_one();
}
Expand Down
19 changes: 13 additions & 6 deletions library/src/main/jni/openslmediaplayer/source/AudioSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1226,15 +1226,22 @@ uint32_t AudioSystem::Impl::determine_output_frame_size(const initialize_args_t
encoding);
const int32_t bytes_per_sample = AudioFormat::get_sample_size_from_encoding(encoding);
const int32_t min_buffer_size_in_frames = (min_buffer_size_in_bytes / (2 * bytes_per_sample));
const int32_t normal_mixer_frame_count = calc_android_NormalMixer_FrameCount(
args.system_out_frames_per_buffer, args.system_out_sampling_rate / 1000);

int32_t frame_count = 0;
while (frame_count < min_buffer_size_in_frames) {
frame_count += normal_mixer_frame_count;
}
int32_t frame_count = min_buffer_size_in_frames;

// NOTE: AudioTrackStream doubles buffer when initialize the AudioTrack, so here can return a half size one.
frame_count /= 2;

return frame_count;
// const int32_t normal_mixer_frame_count = calc_android_NormalMixer_FrameCount(
// args.system_out_frames_per_buffer, args.system_out_sampling_rate / 1000);

// int32_t frame_count = 0;
// while (frame_count < min_buffer_size_in_frames) {
// frame_count += normal_mixer_frame_count;
// }

// return frame_count;
#else
return calc_android_NormalMixer_FrameCount(args.system_out_frames_per_buffer,
args.system_out_sampling_rate / 1000) * kBufferSizeMultiple;
Expand Down