DaveWalley
DaveWalley

Reputation: 807

How can I tell when android AudioRecord read() method encounters an overflow?

I am using android.media.AudioRecord to get raw audio input, and then I am processing this in real-time to display immediate feedback. I can adjust various processing parameters to change the quality of the feedback, with a corresponding change in processing time.

As I increase processing time, at some point AudioRecord starts to overflow and read() starts missing chunks of data. Besides a noticable change in the display, I get the following message in LogCat (I am using eclipse to debug): "E/AudioHardwareYamaha(2579): snd_pcm_readi read error -32"

How can my app find out about this error? It is not good enough to find out while debugging, I want the app to know when this happens so it can automatically adjust the parameters, to find a sweet spot where the quality is as high as possible but the overflows are gone or infrequent. I assume this sweet spot will be different on different hardware.

I have checked here and elsewhere, but the suggestions I have found fall short:

Is there a simple way for an app to capture the error information that is being logged?

Upvotes: 1

Views: 781

Answers (1)

DaveWalley
DaveWalley

Reputation: 807

Just to answer my own question in case someone stumbles on this...

I was not able to find a good solution, but I have been using a work-around. I ended up using the clock, rather than the audio input hardware. Since I know how big my input buffer is, and I know how many input samples are made per second, and I can find how fast my code is running from the system clock, I can calculate when an overflow SHOULD occur, and write my code around that.

Not exactly what I was hoping for, but it accomplished what I needed.

Upvotes: 1

Related Questions