W/AudioTrack: AUDIO_OUTPUT_FLAG_
2021-09-30 本文已影响0人
大旺旺的弟弟小旺旺
采样频率不一致,本地硬件的采样频率查询方式:
AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
String sampleRate = audioManager.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE);
String PROPERTY_OUTPUT_FRAMES_PER_BUFFER = audioManager.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER);
Log.d("txOpenSLES","sampleRate:"+sampleRate+" PROPERTY_OUTPUT_FRAMES_PER_BUFFER:"+PROPERTY_OUTPUT_FRAMES_PER_BUFFER);
https://source.android.com/devices/audio/latency/design
image.png快速混音器以较高的
SCHED_FIFO
优先级运行。它只需要很短的 CPU 时间,但必须经常运行并且具有低调度抖动。 抖动表示周期时间的变化:它是实际周期时间与预计周期时间之间的差值。运行太迟会因欠载而导致异常。运行过早则会因从快速音轨中提取数据时音轨尚未提供数据而导致异常。
if (flags & AUDIO_OUTPUT_FLAG_FAST) {
if (trackFlags & IAudioFlinger::TRACK_FAST) {
ALOGV("AUDIO_OUTPUT_FLAG_FAST successful; frameCount %u", frameCount);
mAwaitBoost = true;
if (sharedBuffer == 0) {
// Theoretically double-buffering is not required for fast tracks,
// due to tighter scheduling. But in practice, to accommodate kernels with
// scheduling jitter, and apps with computation jitter, we use double-buffering.
if (mNotificationFramesAct == 0 || mNotificationFramesAct > frameCount/nBuffering) {
mNotificationFramesAct = frameCount/nBuffering;
}
}
} else {
ALOGV("AUDIO_OUTPUT_FLAG_FAST denied by server; frameCount %u", frameCount);
// once denied, do not request again if IAudioTrack is re-created
flags = (audio_output_flags_t) (flags & ~AUDIO_OUTPUT_FLAG_FAST);
mFlags = flags;
if (sharedBuffer == 0) {
if (mNotificationFramesAct == 0 || mNotificationFramesAct > frameCount/nBuffering) {
mNotificationFramesAct = frameCount/nBuffering;
}
}
}
}
if (flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) {
if (trackFlags & IAudioFlinger::TRACK_OFFLOAD) {
ALOGV("AUDIO_OUTPUT_FLAG_OFFLOAD successful");
} else {
ALOGW("AUDIO_OUTPUT_FLAG_OFFLOAD denied by server");
flags = (audio_output_flags_t) (flags & ~AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD);
mFlags = flags;
return NO_INIT;
}
}
问题发现是在使用小米k30测试游戏的时候,会有些卡,一直以为是逻辑的问题,没想到竟然是音效的问题。我查了 一下采样率也是不对的。