0

I'm using AudioTrack in streaming mode. About one out of 5-10 times after I stop playback of a short section of a wav file, I hear a clicking noise. It's driving me crazy because I can't consistently reproduce it. I've tried various combinations of calls to AudioTrack.flush(), AudioTrack.pause(), and AudioTrack.stop() before calling AudioTrack.release(). I've also tried calling AudioTrack.setStereoVolume() and passing in the result of AudioTrack.getMinVolume(). Nothing has worked.

Some observations:

  • It seems to happen only when I play a short section of a wav file. I can't reproduce it when I play more than 3 seconds of audio.
  • Occasionally, AudioTrack.write() returns -22 when I'm writing the end of the audio data. I don't see a spec for -22 in the Javadoc. Also, this case does not always coincide with the click.
  • The click is not consistently reproducible even if I replay the same section of the wav file.
  • The clicking sound can come out of the right or left speaker, but not both.

I'm seeing this on an Acer Iconia A500 running Android 4.0.3. I would appreciate any suggestions.

Boris Burtin
  • 811
  • 1
  • 7
  • 18

1 Answers1

1

The pop is probably because the song ended on a very high sample, and then became suddenly 0. This causes a 'pop' noise. Try fading the song out over the course of even 0.01 of a second.

The pop from going from high sample to 0 volume sounds like this: https://soundcloud.com/hertzdevil/dirac

Patashu
  • 21,443
  • 3
  • 45
  • 53
  • Good call! The pops mostly go away when I ramp down the volume to 0.75, 0.5, 0.25, and 0.01 with the last four buffers. I still occasionally get pops on the Acer Iconia, but I'm pretty sure it's not my code. It also happens in YouTube and Play Music when I play/pause a track over and over. – Boris Burtin May 03 '13 at 23:12
  • @Boris Burtin Glad to help! – Patashu May 04 '13 at 00:33
  • 1
    I spoke too soon. The gradual fades helped, but they didn't completely alleviate the problem. I think the pops are also being caused by the audio hardware going in and out of standby mode. I just played a sound twice in my app. The first time there was no pop, the second time there was. When I looked in the logs, I noticed this line, but only after the second playback: 05-14 15:58:48.780 D/AudioHardware( 90): AudioHardware pcm playback is going to standby. Any suggestions about how to keep the hardware from going into standby while my app is in the foreground? – Boris Burtin May 14 '13 at 23:03
  • @Boris Burtin Now that you have an error message (Well, diagnostic log in this case, but still a message), try googling it: https://www.google.com.au/search?q=AudioHardware+pcm+playback+is+going+to+standby&aq=f&oq=AudioHardware+pcm+playback+is+going+to+standby&aqs=chrome.0.57j0l3.242j0&sourceid=chrome&ie=UTF-8 The first hit is an SO that looks like it might solve your problem, for example. – Patashu May 14 '13 at 23:05
  • I guess I could try keeping around a pool of AudioTrack objects and not release them until my app goes into the background. If anyone has another suggestion, I'd love to hear it. – Boris Burtin May 14 '13 at 23:06
  • Thanks Patashu. I appreciate your fast response. I already did a bunch of searches for this message, but I didn't see anyone report the symptom that I'm seeing. Most of the posts that I saw dealt with the app locking up, not pops in the audio output. I'm pretty sure that the post you're referring to (6662808) falls into this category. My symptom is pretty subtle. Most people may not notice it, unless they're writing an audio processing app like I am. – Boris Burtin May 14 '13 at 23:12
  • @Boris Burtin: I am afraid I don't have any relevant experience to help further. Good luck! – Patashu May 14 '13 at 23:29