I have a simple piece of code that creates an AudioRecord object, then uses it to record to a file. It is pretty standard and seems to work perfectly fine. I am using a Samsung GalaxyS Vibrant running stock Android 2.2.
However, I am getting messages such as these in logcat at different intervals:
04-13 14:03:30.754: V/AudioRecord(4831): Overrun user: 820, server: 1040, flowControlFlag 0
04-13 14:03:30.766: V/AudioRecord(4831): Overrun user: 820, server: 1040, flowControlFlag 1
Does anyone know what these mean? Am I overrunning the internal audio buffer and losing audio frames? It doesn't seem like it from the recorded file, but these intermittent messages are worrying me a bit.
This might be a little late, but this is merely a log message (not specifically Samsung, I've seen it with different makes, models & brands) telling you that you've started recording, but are not reading out the data from the AudioRecord.
Hence the Overrun user, the AudioRecord's buffers are full.
it seems this is an internal log used by some samsung devices. So you can not hide them but it is not harmful either. If you dont want to see it you can just filter out this from your logcat
Check your permissions.
<uses-permission android:name="android.permission.RECORD_AUDIO"></uses-permission>
this permission is necessary
I think is because read pcm data too slow, I faced the same question, when I do a little sleep between two read operations, this log become more when I set the sleep time longer.
So I think there is 2 ways to resolve this problem:
1.make read operation quick
2.make the buffer bigger, when you new a AudioRecorder set last para to 2*minBufferSize or bigger. It can allow you read more data every read operation.
Hope your can understand that, sorry for my poor english.
Related
I've seen that there is tons of posts like this, but couldn't find one that helps me.
I've read in one of them that this a generic error, and it depends on what you are doing.
In my case, I've created a socket, got its input and output stream and use the output to send some data. The strange thing is that I can send things and the server receives them. But I get this error pretty often. Like, once every 5 minutes.
Don't know if might help, but at first I had the soTimeout of the socket as 10 seconds. After reading some articles, I've increased it to 1 minute.
Don't know if I can add code that helps, because I litterally have the error when I do
output.write(byte[])
but if you think it might be something I could add, feel free to ask
Thanks in advance
My Android app uses the AWS Java SDK for uploading user photos to S3.
Whenever a user's phone's clock is 'skewed', this causes all transfers to fail. This is a well documented aspect of S3:
http://aws.amazon.com/articles/1109?_encoding=UTF8&jiveRedirect=1#04
It appears that the upstream S3 service reports this error quite clearly:
HTTP Status Code: 403 Forbidden
Error Code: RequestTimeToo-Skewed
Description: The difference between the request time and the server's
time is too large.
However when using the Java SDK, it seems as if the informative 403 code is lost ... and I have only an opaque "TransferState.Failed" to go by (which incidentally is the same error if internet connectivity is lost, if it times out, etc...).
As far as I can tell from the docs:
http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/index.html
http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/transfer/TransferProgress.html
http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/transfer/Transfer.TransferState.html
http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/transfer/Upload.html
There is no way to get the additional "RequestTimeToo-Skewed" metadata about a transfer failure.
Am I missing it? Is there any way to get additional error information when an S3 transfer fails using Amazon's Java SDK?
UPDATE #1:
A commenter kindly highlighted that I should clarity two points:
I am actually using the AWS SDK for Android (which seems very similar to the Java SDK, but is nonetheless distinct)
I am using the TransferManager class to perform my upload. Apparently, this is a high-level class that wraps the lower-level AmazonS3Client ... and this lower-level class should expose the error reporting I need, but I am still investigating the exact tradeoffs involved between TransferManager and AmazonS3Client. As far as I can tell, there is no way to get progress information via the (synchronous) AmazonS3Client.putObjectRequest which would be a blocker for me...
UPDATE #2:
My sincere thanks to Jason (of the AWS SDK team) for stopping by and helping me out here. The important information is, indeed, available as properties on an AmazonS3Exception if you use certain methods. The docs had originally confused me and I thought that a manual Thread.sleep() loop was required to poll status (and thus I could not leverage waitForCompletion or waitForException), but if you use ProgressListener on PutObjectRequest you can get full progress callbacks and the error-fidelity of AmazonS3Exception.
these two methods should help you out:
Transfer.waitForCompletion()
Transfer.waitForException()
If you detect that your transfer has failed based on a transfer progress event, you can simply call Transfer.waitForException() to be returned the exception that occurred. That exception will be an AmazonServiceException in this case, with all of the info that you need to see that the real problem was a clock skew issue.
Alternatively, the Transfer.waitForCompletion() method will unwrap the original exception from an ExecutionException and directly throw the original exception, just as if it'd all been happening on one thread. This might be a more convenient approach if you want to use a catch blocks to catch different types of errors cleanly and elegantly.
I disagree that the "catch Exception" block is "brutally broad". The point of that code is to catch any error that happens, mark the transfer as failed and rethrow the error so that the application code can know about it. If it were less broad, then that's exactly the case where exceptions could sneak through and transfer progress wouldn't be updated correctly and would be out of sync with reality.
Give those two methods and shot and let us know if that helps!
Well, I have debugged Amazon's SDK and I'm sorry to say that this information is being swallowed internally. Perhaps I will try to submit a patch.
Details: an AmazonS3Exception is being thrown internally which does in fact accurately report this exact error scenario, but a brutally broad try catch ( Exception e ) consumes it and washes away the specificity.
Here is the guilty try-catch:
https://github.com/aws/aws-sdk-java/blob/master/src/main/java/com/amazonaws/services/s3/transfer/internal/UploadMonitor.java#L145
Here is a screenshot showing that an AmazonS3Exception is correctly thrown with the right info...
I have a similiar situation like this: How do I handle/fix "Error getting response stream (ReadDone2): ReceiveFailure" when using MonoTouch? but I'm only GETing a list, not posting anything in the body.
Furthermore, I'm using RestSharp, and it works in almost all the cases, but every once in a while I receive Error getting response stream (ReadDone2): ReceiveFailure.
What can possibly be the problem?
(ps: the exact same code on Wp7 doesn't cause any errors)
There is a bug report (https://bugzilla.xamarin.com/show_bug.cgi?id=19673) which appears to have a reproducible example. So, at the least, you could add yourself to the CC list for it.
(BTW, I get the error (also using restsharp) under Linux (Mint/17, Mono 3.2.8), so it is not specific to Android. It is hard to reproduce: for me it is simply happening after between 1000 and 10,000 web service calls, and it always works when restarting. I am not seeing a CPU or memory problem. It could be some buffer build-up, or might simply be a network failure, or even remote server problem?)
Hi all! Sorry in advance for my English. :)
I am trying to make an audio recognition app with Echoprint code. One instance works fine, but we would like to listen simultaneously with several AudioRecords. For example, instead of analyzing 20 seconds of a song for recognition, we would like to have, for example, 3 audio recorders with 3 matches to improve the results.
Ex. one listening from the 0s to 20s, another one listening from 0s to 10s and another one listening from 10s to 20s. That way we will have 3 matches-responses, which we expect will give us more accuracy or more possibilities of matching audio in a short time (we need to match in 5-15 seconds max).
The thing is, I have the code from http://masl.cis.gvsu.edu/2012/01/25/android-echoprint/
I have a class that calls a library who makes all. I tried to create in the class several threads, so everyone has his own instances of the library classes, but always fail in the instantiation of the second AudioRecord:
new AudioRecord(MediaRecorder.AudioSource.MIC,FREQUENCY, CHANNEL, ENCODING, minBufferSize);
If I put a sleep in the second thread, in order to let the first finish, all is okay. The problem is in that instantiation... the error is:
AudioRecord: Could not get Audio input for record source 1
AudioRecord: Error Creating AudioRecord instance: initialization check failed.
AudioRecord: [ Android.media.AudioRecord ] Error code -20 when initializating native AudioRecord object
So, I have two questions:
One is if the problem is that it is not possible to listen simultaneously to several AudioRecords instances. Like if there were just one channel, device, input device, port or etc. to listen and if it is busy it crashes, until you make the audiorecord.release()? In both I was using mic and same channel....maybe that's the problem? If it's that...how do I do it properly?
Also I am in the emulator... in a real device it works but not in the emulator?
Best regards and truly thanks for all!
New to stackoverflow, been very helpful searching, but alas the time has come to ask a question.
I am trying to use an android 2.2 single core phone to do some research. I have implemented an algorithm that does quite a few calculations and produces a lot of data. These data must be processed, and the solution presented back to a client app within a 40ms time frame, then process again with new state data coming from the client. Also, the result of the calculations must be stored to the SD card as a data log. So being new to multithreading and android both, what should I use to do the following in my app: (As a side note, this phone, when in research mode is not intended to be used as a phone, phone will be in airplane mode with wireless off, and all apps that can be turned off will be turned off, and there is no need for UI display or interaction once it is up and running...)
need to process packets coming in over adb on serial port, these packets are state data that the program needs to perform its calcs on. These packets will be coming every 40ms, so I planned on using their arrival to trigger the start of the processing.
need to know if the algorithm is taking longer than 40ms and cancel it if so and send a message back on the serial port that it overran.
the calculation results need to be sent back over the serial connection via tcp and adb
The calculation intermediate data need to be recorded to SD. This can be quite a lot of data, on order of 140k, every 40ms.
So I have had trouble getting all the pieces together. I can't get my head around how a single core is going to keep up with all this going on at once?
So here is my thought, please tell me if I am headed in the right path. I am not asking for you to solve my problem, only any advice on how to break this beast down:
So i start a service to process the tcp packets coming in from the client
Use a service bound to the main worker thread to handle writes to the SD card
So assuming this setup, can i make the algorithm part of this somewhat deterministic so that it always runs if it gets a new tcp packet, and preempts the SD write going on in the background?
Argh...should have picked something simpler for my first program
Thanks.
Yes I think you are right, that it would be better to pick something easier for your first App ;)
But as far as I understand what you are trying to do, I don't think, that you need asynchronous multiprocessing. You get some data want to process it and pass a result. I think a HandlerThread is exactly what you are looking for. It is able to recieve Messages
with data inside. You send them to the Handler and process them in an overridden handleMessage(Message m) method. So everytime you recive a Message you could just log the Time
and see if the last one is older than your limit. If it is, you could just throw the Message or the whole queue, or send a Message to your serial-port inicating the overflow.
This could be implemented as you suggest in a Service. Another HandlerThread can be started with Thread.PRIORITY_BACKGROUND to write everything to SD.
You can send Messages even very compfortable if you apply a Messenger to the Handlers