Ian Ni-Lewis: I Think your comment "ART switches out the GC model when the app is backgrounded, which causes several locks to be held," could possibly explain the problem but the problem is not with my app but depper down in the Android audio stack.
When playing files that have the same sample rate as the audio system reports - PROPERTY_OUTPUT_SAMPLE_RATE - for this device 48000 Hz,
then there is no audio glitch, only for files with another sample rate, for example 44100 Hz.
Here are two logs from the system when changing from foreground to background, first when playing a 48000 Hz file, second for a 44100 Hz file:
48000 Hz file:
04-16 09:55:33.045: I/ActivityManager(612): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 cmp=com.google.android.googlequicksearchbox/com.google.android.launcher.GEL (has extras)} from uid 1000 on display 0
04-16 09:55:33.108: I/GEL(27237): handleIntent(Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10600000 cmp=com.google.android.googlequicksearchbox/com.google.android.launcher.GEL (has extras) })
04-16 09:55:33.180: I/MicroDetectionWorker(27030): Micro detection mode: [mDetectionMode: [1]].
04-16 09:55:33.196: W/LocationOracle(27030): Best location was null
04-16 09:55:33.208: I/MicroRecognitionRunner(27030): Starting detection.
04-16 09:55:33.213: I/MicrophoneInputStream(27030): mic_starting
com.google.android.apps.gsa.speech.audio.ah@86a198a04-16 09:55:33.219: I/SoundTriggerHwService::Module(219): void android::SoundTriggerHwService::Module::onCallbackEvent(const android::sp<android::SoundTriggerHwService::CallbackEvent>&) mClient == 0
04-16 09:55:33.226: I/AudioFlinger(219): AudioFlinger's thread 0xab3bce10 ready to run
04-16 09:55:33.227: I/MicrophoneInputStream(27030): mic_started
com.google.android.apps.gsa.speech.audio.ah@86a198a04-16 09:55:33.296: E/LocationReceiver(27030): Received bad location: null
04-16 09:55:33.313: I/art(612): Background partial concurrent mark sweep GC freed 14085(723KB) AllocSpace objects, 7(240KB) LOS objects, 33% free, 29MB/43MB, paused 1.932ms total 240.884ms
04-16 09:55:33.314: I/Keyboard.Facilitator(1141): onFinishInput()
04-16 09:55:33.338: W/LocationOracle(27030): Best location was null
04-16 09:55:33.346: W/LocationOracle(27030): Best location was null
04-16 09:55:33.416: I/MicroDetectionWorker(27030): onReady
44100 Hz file:
04-16 09:49:49.952: I/ActivityManager(612): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 cmp=com.google.android.googlequicksearchbox/com.google.android.launcher.GEL (has extras)} from uid 1000 on display 0
04-16 09:49:50.011: I/GEL(27237): handleIntent(Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10600000 cmp=com.google.android.googlequicksearchbox/com.google.android.launcher.GEL (has extras) })
04-16 09:49:50.085: I/MicroDetectionWorker(27030): Micro detection mode: [mDetectionMode: [1]].
04-16 09:49:50.096: I/Keyboard.Facilitator(1141): onFinishInput()
04-16 09:49:50.098: W/LocationOracle(27030): Best location was null
04-16 09:49:50.134: D/AudioFlinger(219): mixer(0xab24b0a8) throttle end: throttle time(20)
04-16 09:49:50.134: I/MicroRecognitionRunner(27030): Starting detection.
04-16 09:49:50.138: I/MicrophoneInputStream(27030): mic_starting
com.google.android.apps.gsa.speech.audio.ah@d9d878f04-16 09:49:50.147: I/SoundTriggerHwService::Module(219): void android::SoundTriggerHwService::Module::onCallbackEvent(const android::sp<android::SoundTriggerHwService::CallbackEvent>&) mClient == 0
04-16 09:49:50.154: I/AudioFlinger(219): AudioFlinger's thread 0xab3bce10 ready to run
04-16 09:49:50.156: I/MicrophoneInputStream(27030): mic_started
com.google.android.apps.gsa.speech.audio.ah@d9d878f04-16 09:49:50.200: E/LocationReceiver(27030): Received bad location: null
04-16 09:49:50.213: W/LocationOracle(27030): Best location was null
04-16 09:49:50.215: I/art(612): Background partial concurrent mark sweep GC freed 8117(435KB) AllocSpace objects, 1(20KB) LOS objects, 33% free, 29MB/43MB, paused 1.087ms total 235.323ms
04-16 09:49:50.232: W/LocationOracle(27030): Best location was null
04-16 09:49:50.240: D/AudioFlinger(219): mixer(0xab24b0a8) throttle end: throttle time(20)
04-16 09:49:50.304: D/AudioFlinger(219): mixer(0xab24b0a8) throttle end: throttle time(10)
04-16 09:49:50.346: I/MicroDetectionWorker(27030): onReady
04-16 09:49:55.899: I/art(612): Background partial concurrent mark sweep GC freed 10403(503KB) AllocSpace objects, 2(60KB) LOS objects, 33% free, 29MB/43MB, paused 1.216ms total 136.761ms
04-16 09:49:56.534: D/AudioFlinger(219): mixer(0xab24b0a8) throttle end: throttle time(10)