6

I am using a thread which records the audio using AudioRecord class and placed in recorderBUffer (which is a linked list of Short[]) , a separate thread which does the encoding of this data and place it to a playerBuffer(linked list[]). For playing the Audio I am using AudioTrack class and onPeriodicNotification() I read the data from playerBuffer and write it to track.

The code is simple and straight forwards as it appears. However it doesnt work the way it should. GC_CONCURRENT eats of all the time and which is causing AudioTrack restart so frequently(I guess!). I get following messages from LogCat:-

04-09 12:25:13.757: E/Constructor(10100): inside constructor 
04-09 12:25:13.757: I/ApplicationPackageManager(10100): cscCountry is not German : INS
04-09 12:25:17.429: E/startRecording(10100): start Recording
04-09 12:25:17.445: I/AudioCapturer(10100): Audio Recorder created
04-09 12:25:17.546: I/Audio Player(10100): Audio Track instance created buffer Size : 2972
04-09 12:25:17.546: I/SpeexThread(10100): Thread Started Successfully..
04-09 12:25:17.734: D/dalvikvm(10100): GC_CONCURRENT freed 55K, 44% free 3208K/5639K, external 408K/517K, paused 4ms+6ms
04-09 12:25:17.945: D/dalvikvm(10100): GC_CONCURRENT freed 1K, 39% free 3765K/6151K, external 408K/517K, paused 3ms+8ms
04-09 12:25:18.148: D/dalvikvm(10100): GC_CONCURRENT freed <1K, 36% free 4277K/6663K, external 408K/517K, paused 3ms+8ms
04-09 12:25:18.414: D/dalvikvm(10100): GC_CONCURRENT freed <1K, 33% free 4981K/7367K, external 408K/517K, paused 3ms+9ms
04-09 12:25:18.734: D/dalvikvm(10100): GC_CONCURRENT freed <1K, 29% free 5877K/8263K, external 408K/517K, paused 3ms+9ms
04-09 12:25:18.828: W/AudioTrack(10100): obtainBuffer() track 0x1d0478 disabled, restarting
04-09 12:25:19.164: D/dalvikvm(10100): GC_CONCURRENT freed <1K, 26% free 7093K/9479K, external 408K/517K, paused 3ms+9ms
04-09 12:25:19.710: D/dalvikvm(10100): GC_CONCURRENT freed <1K, 22% free 8693K/11079K, external 408K/517K, paused 3ms+9ms
04-09 12:25:19.984: W/AudioTrack(10100): obtainBuffer() track 0x1d0478 disabled, restarting
04-09 12:25:20.414: D/dalvikvm(10100): GC_CONCURRENT freed <1K, 19% free 10741K/13127K, external 408K/517K, paused 3ms+9ms
04-09 12:25:21.156: W/AudioTrack(10100): obtainBuffer() track 0x1d0478 disabled, restarting
04-09 12:25:21.171: D/dalvikvm(10100): GC_CONCURRENT freed <1K, 16% free 12789K/15175K, external 408K/517K, paused 3ms+11ms
04-09 12:25:21.976: D/dalvikvm(10100): GC_CONCURRENT freed <1K, 14% free 14837K/17223K, external 408K/517K, paused 3ms+9ms
// same messages errors continue  
04-09 12:25:28.117: W/AudioTrack(10100): obtainBuffer() track 0x1d0478 disabled, restarting
04-09 12:25:29.242: D/dalvikvm(10100): GC_CONCURRENT freed 1K, 8% free 29172K/31559K, external 408K/517K, paused 3ms+11ms
04-09 12:25:29.273: W/AudioTrack(10100): obtainBuffer() track 0x1d0478 disabled, restarting
04-09 12:25:30.445: W/AudioTrack(10100): obtainBuffer() track 0x1d0478 disabled, restarting
04-09 12:25:30.507: D/dalvikvm(10100): GC_CONCURRENT freed 1K, 8% free 31220K/33607K, external 408K/517K, paused 4ms+12ms
04-09 12:25:31.601: W/AudioTrack(10100): obtainBuffer() track 0x1d0478 disabled, restarting
04-09 12:25:31.820: D/dalvikvm(10100): GC_CONCURRENT freed 1K, 7% free 33268K/35655K, external 408K/517K, paused 3ms+12ms
04-09 12:25:32.757: W/AudioTrack(10100): obtainBuffer() track 0x1d0478 disabled, restarting
04-09 12:25:33.187: D/dalvikvm(10100): GC_CONCURRENT freed 1K, 7% free 35316K/37703K, external 408K/517K, paused 3ms+13ms
04-09 12:25:33.929: W/AudioTrack(10100): obtainBuffer() track 0x1d0478 disabled, restarting
04-09 12:25:34.593: D/dalvikvm(10100): GC_CONCURRENT freed 1K, 7% free 37364K/39751K, external 408K/517K, paused 4ms+11ms
04-09 12:25:35.085: W/AudioTrack(10100): obtainBuffer() track 0x1d0478 disabled, restarting
04-09 12:25:36.039: D/dalvikvm(10100): GC_CONCURRENT freed 1K, 6% free 39412K/41799K, external 408K/517K, paused 3ms+12ms
04-09 12:25:36.242: W/AudioTrack(10100): obtainBuffer() track 0x1d0478 disabled, restarting
04-09 12:25:37.406: W/AudioTrack(10100): obtainBuffer() track 0x1d0478 disabled, restarting
04-09 12:25:37.617: D/dalvikvm(10100): GC_CONCURRENT freed 1K, 6% free 41460K/43847K, external 408K/517K, paused 5ms+13ms
04-09 12:25:38.640: D/dalvikvm(10100): GC_FOR_MALLOC freed 1K, 6% free 43507K/45895K, external 408K/517K, paused 933ms
04-09 12:25:38.656: I/SpeexThread(10100): exitting Thread
04-09 12:25:38.656: E/stopRecording(10100): stop Recording

The AudiTrack is restarted every few miliseconds, and GArbage Collection is called almost continuously. How can I minimize GArbage Colloection calls and what is the reason behind AudioTrack restart ? Plz Help...

Amit
  • 13,134
  • 17
  • 77
  • 148
  • 8
    Dear downvoter, if their is some problem please comment so that I can improve the question and learn...Thanks!!! – Amit Apr 10 '12 at 06:39
  • 3
    Be thankful you have a garbage collector dude, you don't want to stop it, it's cleaning up because there's an issue with your implementation, you'd need to post some of your code using AudioTrack to get some more help. (I'm not downvoter) – Rob Apr 11 '12 at 14:58
  • @Rob, thanks... I am still working on that same problem... Soon I will post my progress... – Amit Apr 12 '12 at 05:27
  • @Amit Have you been able to solve this issue yet? – Shakti Malik Jun 10 '13 at 09:03
  • @ShaktiMalik I used Memory Allocation Tool and looked which of my functions were using maximum memory. Than I redesigned the code to reduce the memory usage and the issue got solved. – Amit Jun 10 '13 at 09:10
  • @Amit Could you please elaborate which " Memory Allocation Tool" did you use ? – Shakti Malik Jun 10 '13 at 09:19
  • The tool can be downloaded from here http://www.eclipse.org/mat/ and you can get an excellent tutorial here http://www.vogella.com/articles/EclipseMemoryAnalyzer/article.html – Amit Jun 10 '13 at 11:06

1 Answers1

11

A temporaral solution of the problem was by increasing the HeapSize using dalvik.system.VMRuntime.getRuntime().setMinimumHeapSize(32 * 1024 * 1024); However this approach is not recommended and should be avoided.

By Extensive debugging I found that the real problem was due to overlapped interfaces and some leaky functions. Later I removed one of the Interface, redesigned the overall solution and re-factored the code and that solved my problem.

Please share if you have some other Solution,

Amit
  • 13,134
  • 17
  • 77
  • 148
  • 1
    I have same issue, can you please post some sample of your fixes? I know they may be specific, but may still be useful. Thanks – Carlo Moretti Jun 08 '12 at 12:36
  • 1
    I just added the above line inside the onCreate() to increase the memory size.. It worked, however later you need to refactor your code so that memory use is optimized... – Amit Jun 11 '12 at 05:05
  • 1
    It seems like this temp solution is no longer possible. I'm running into a VMRuntime symbol cannot be found. – Kurt Wagner Aug 19 '14 at 23:57