Android :: Android: AudioRecord Class - Callback Is Never Called

Feb 15, 2010

My Android Java Application needs to record audio data into the RAM and process it. This is why I use the class "AudioRecord" and not the "MediaRecorder" (records only to file).

Till now, I used a busy loop polling with "read()" for the audio data. this has been working so far, but it peggs the CPU too much. Between two polls, I put the thread to sleep to avoid 100% CPU usage.

However, this is not really a clean solution, since the time of the sleep is not guaranteed and you must subtract a security time in order not to loose audio snippets. This is not CPU optimal. I need as many free CPU cycles as possible for a parallel running thread.

Now I implemented the recording using the "OnRecordPositionUpdateListener". This looks very promising and the right way to do it according the SDK Docs. Everything seems to work (opening the audio device, read()ing the data etc.) but the Listner is never called.

I am working with a real Device, not under the Emulator. The Recording using a Busy Loop basically works (however not satifiying). Only the Callback Listener is never called.

Here is a snippet from my Sourcecode:

CODE:...............................

Android :: Android: AudioRecord Class - Callback is never called


Android :: AudioRecord Class - Callback Is Never Called

Feb 15, 2010

My Android Java Application needs to record audio data into the RAM and process it. This is why I use the class "AudioRecord" and not the "MediaRecorder" (records only to file).

Till now, I used a busy loop polling with "read()" for the audio data. this has been working so far, but it peggs the CPU too much. Between two polls, I put the thread to sleep to avoid 100% CPU usage. However, this is not really a clean solution, since the time of the sleep is not guaranteed and you must subtract a security time in order not to loose audio snippets. This is not CPU optimal. I need as many free CPU cycles as possible for a parallel running thread.

Now I implemented the recording using the "OnRecordPositionUpdateListener". This looks very promising and the right way to do it according the SDK Docs. Everything seems to work (opening the audio device, read()ing the data etc.) but the Listner is never called.

I am working with a real Device, not under the Emulator. The Recording using a Busy Loop basically works (however not satifiying). Only the Callback Listener is never called.

Here is a snippet from my Sourcecode:
CODE:.........................

View 2 Replies View Related

Android :: AudioRecord - OnPeriodicNotification And OnMarkerReached Are Not Called

May 13, 2010

I've seen posts regarding problems with the AudioRecord OnRecordPositionUpdateListener, but I haven't seen any real answers.

I'm using AudioRecord to record from the mic, and I want to get the input from the mic periodically so I can check sound levels and update a meter.

I set up the listener like this:

CODE:...........

What happens is that onMarkerReached gets called once, after the recorder is released, so that's not very useful.

Do I need to change the marker position and notification period? Is the listener working? Is there another way to accomplish periodically getting the mic input?

View 4 Replies View Related

Android :: OnItemClick Gets Called As Callback?

Dec 31, 2009

Could someone please shed the light as to where onItemClick() function gets called as callback when I click on the item of a ListView?

In core/java/android/widget/AdapterView.java:

onItemClick() belongs to the interface OnItemClickListener of AdapterView.

The listener is set through setOnItemClickListener() of AdapterView.

The listener is only invoked in performItemClick() of AdapterView.

The listener is also invoked indirectly in performItemClick() of ListView.

But, I still don't know where exactly onItemClick() of the listener will get called when I click on the item of a ListView. Logically it should be like:

device -> kernel driver -> dalvik VM -> my app.

Could someone please tell me the exact code that calls onItemClick() when I click on the item through the device?

In this digital era, where computing technology is pervasive, your freedom depends on the software controlling those computing devices.

Join free software movement today! It is free as in freedom, not as in free beer!

Join: http://www.fsf.org/jf?referrer=4445

View 5 Replies View Related

Android :: AudioRecord Class To Analize Raw Pcm Bytes As It Comes In The Mic

May 27, 2010

I am using the AudioRecord class to analize raw pcm bytes as it comes in the mic.

So thats working nicely. Now i need convert the pcm bytes into decibel.

I have a formula that takes sound presure in Pa into db. db = 20 * log10(Pa/ref Pa)

So the question is the bytes i am getting from audiorecorder from the buffer what is it is it amplitude pascal sound pressure or what.

I tried to putting the value into te formula but it comes back with very hight db so i do not think its right

View 4 Replies View Related

Android :: Remote Callback List Register Called On One Thread Broadcast Initiated

Feb 12, 2009

I'm an experienced C++/Java dev who has been truly enjoying that past two days of getting neck deep into the Android SDK. I can foresee a lot of sleepless nights ahead Now, being arrogant due to experience (lol) I basically wrote a hello world Activity, got it to work and promptly decided to write an out of process service with accompanying client for project #2. Android is so well thought out (if not exactly documented although that's an 'over time' issue inmho) that I had basically implented everything but callbacks into the client before realizing (and feeling like a total idiot) that there's a very nice example called RemoteService (lol @ me - again) Basically, this validated everything I'd been doing, although I did notice that because my client is in its own project and namespace and my service is in another project and namespace (but the same Eclipse workspace) that I had to have the service entry in my service's manifest AND my client's manifest (that one took me a while to figure out) in order to bind on the service. Anyhow, everything's great, I am starting to love on Android (figuratively) but I've run into <BRITISH-NESS>a bit of a sticky wicket, eh, wot?</BRITISH-NESS>.

When my client Activity binds on my service (which is running in its own process) and calls the equivalent of 'registerCallback', the interface is added perfectly to the RemoteCallbackList object and I can immediately (right on the next line of code) use the interface to send a notification to the client. Now, my problem is that when my main service thread tries to pull the interface out of the RemoteCallbackList via the broadcast methods, the RemoteCallbackList is always 'empty' - it returns 0 from beginBroadcast. After double checking ensure that I AM actually adding it to the list (because I've been a collossal idiot before) and that I am getting success back from 'register', I immediately think it's a threading issue, so: I add logging code to the service in key places to log what the thread id is repeatedly, and I think "uh, I think I need to use a handler of some sort to make the call back in the thread that handled the registration" and to double check I call beginBroadcast right after 'register' and find that it always returns back the correct number of callback interfaces. So it VERY much appears to be a threading issue (to me) so now I'm a bit stuck I've written a handler so that my main service thread can request the correct thread to actually call 'beginBroadcast' and then thought 'how is it going to know what thread that is...?' and instead am now thinking I need to pass, via a handler or something, the incoming interface from the thread that runs when the client calls the equivalent of 'registerCallback' to my main service thread. What part of the proper paradigm am I missing? BTW, as an example of the thread IDs, my main service thread is #1, the runnable I use for tasks in the main service thread shows an ID of #1, the message handler I was thinking I could use, shows an ID of #1, but the thread ID I get in my code in the service that runs when the user registers their callback is #7.

If I plan to notify clients when the service notices something it thinks they need to know, do I need to notify (somehow) the clients via the thread with ID #7 or do I need to pass the interface I get when the user registers their callback from thread #7 to thread #1 and call 'register' on the RemoteCallbackList from thread #1? Sorry for the verbosity but I figured more is better than less. Again, everything works great except this one little part.

View 9 Replies View Related

Android :: Starting An Activity From Callback Class

Aug 18, 2010

I have an activity class(Application Class ) which calls a service class(Service Class) and closes. The service class takes about 5 seconds to complete its task and calls a method which is present in another class(Callback Class). Now according to the result, the callback needs to notify the Application class.Once i get the callback from the service, I tried calling a method defined in the Application class. In this method i create a new intent of Application class and call startActivity(Application Class). But this is not working. Can anyone tell where i am going wrong and what can I do to solve this issue.

View 5 Replies View Related

Android :: Register Get / Set Hooking Callback Function At Class

Apr 7, 2010

I release a class. In the class, there are public fields that can be written. I want to register the callback function which will be called right after my field is accessed. I think I can do that by using JVM tool interface which is supposed to be used for a debugger software. JVM tool interface:

I'm not sure same interface is working on android. or, They provide another form of interface to get a notification of a field access.

View 2 Replies View Related

Android :: Application Class Being Called Twice

Oct 16, 2010

In my Android application, I overload the Application class, and I updated the tag in my manifest. This application also creates an Android Service. I have put some logs in the onCreate of my Application class, and I see it being called twice. The first time is when my application gets launched (this is expected) and then, it's usually right after the Service is being created. the log also shows that a second instance of the Application is being created. (I print the "this" value and they are different). I thought the Application would be created as a singleton. Is that happening because I create a Service?

View 3 Replies View Related

Android :: Why Generated Phone Class Called R?

Sep 1, 2010

I'm just curious, who in the world names a class R ? Is there any history behind this convention?

View 1 Replies View Related

Android :: Dialog Callback From Withing Callback?

Aug 28, 2009

I'm trying to pop up an AlertDialog when someone long presses a list item.What I end up with is nested callback objects.I'm not sure if that is the problem but simple Alert dialog examples are not working for me.

View 3 Replies View Related

Android :: Android 1.5 - Asynctask DoInBackground Not Called / Method Called

Oct 26, 2010

I am running into an issue with the way my asynctasks are executed. Here's the problem code:

firstTask = new background().new FirstTask(context);
if(firstTask.execute().get().toString().equals("1"))
secondTask = new background().new SecondTask(context);

What I'm doing here is creating a new asynctask object, assigning it to firstTask and then executing it. I then want to fire off a separate asynctask when the first one is done and making sure it returns a success value (1 in this case). This works perfectly on Android 2.0 and up. However, I am testing with Android 1.5 and problems start popping up. The code above will run the first asynctask but doInBackground() is never called despite onPreExecute() being called. If I am to execute the first task without the get() method, doInBackground() is called and everything works as expected. Except now I do not have a way to determine if the first task completed successfully so that I can tell the second task to execute. Is it safe to assume that this is a bug with asynctask on Android 1.5? Especially since the API says that the get method has been implemented since API 3. Is there any way to fix this? Or another way to determine that the first task has finished?

View 2 Replies View Related

Android :: Using AudioRecord API

May 15, 2009

I'm trying to figure out how to use the AudioRecord class.I created a callback with a logging message, but don't ever see it called.Do you see anything wrong with what I'm doing? Do you have an example of how to use the API?

View 6 Replies View Related

Android :: How To Use AudioRecord And AudioTrack?

Apr 30, 2009

I want to use AudioRecord and AudioTrack classes(in SDK 1.5) in my program. Where can I find how to use it. Is there any API demo program for this?. If not it is greatly appreciated if someone can post a sample code in this forum.

View 7 Replies View Related

Android :: Synchronizing AudioTrack And AudioRecord

Jan 21, 2010

My application uses AudioTrack in streaming mode and AudioRecord simultaneously.My problem is that I start them at the same time, but I have no guarantee that they will actually start playback ecording in the same timestamp. The reason I need this kind of accuracy is because I use echo cancellation (subtracting audio played to speaker from the recording).My echo canceller doesn't require an exact delay, but the delay introduced between AudioTrack and AudioRecord moves in the range of 250ms (between different runs), and that's too much - each run is different because they start themselves asynchronously. The API doesn't provide me a way to make sure they start in the same time, so I thought about measuring this starting delay somehow and then using it in my calculation.Does anyone have an idea how to do that, utilizing their API or in any other way?

View 2 Replies View Related

Android :: How To Add Own Audio Codec To AudioRecord?

Mar 10, 2010

I currently have a Loop back program for testing Audio on Android devices.It uses AudioRecord and AudioTrack to record PCM audio from the Mic and play PCM audio out the earpiece. So as you can see in the creation of the AudioTrack and AudioRecord the Encoding is supplied via the AudioFormat but this only allows 16 bit or 8 bit PCM.I have my own G711 Codec implementation now and I want to be able to encode the audio from the Mic and decode it going into the EarPiece, So I have encode(short lin[], int offset, byte enc[], int frames) and decode(byte enc[], short lin[], int frames) methods but I'm unsure as to how to use them to encode and the decode the audio from the AudioRecord and AudioTrack.

View 2 Replies View Related

Android :: AudioRecord Is Not Working On Emulator

Nov 11, 2010

I used AudioRecord on emulator and phone. I found that AudioRecord is not working on phone: 1> the min-buffer-size on simulator is much smaller than phone 2> The audio data I read from phone is all zero.

View 2 Replies View Related

Android :: AudioRecord On Emulator With Frequency 8 KHz

Mar 25, 2010

I'm doing a voice recording using AudioRecord class and the main requirement that the frequency must be 16000 Hz. I'm using only emulator in development process for now and met the problem that I can't set frequency more than 8000, otherwise I get bufferSize -2, and can't create instance of AudioRecord with such buffer. Thank you to Szabolcs Vrbos, he told me that this problem is only with emulator and several Samsung phones, device can record with higher frequency.I need a word from Android engineers that I will be able to record voice with 16000 Hz frequency on for instance HTC Hero (Android 1.5)or similar device with os 1.5 or higher.

View 2 Replies View Related

Android :: Relation Between MediaRecorder And AudioRecord?

Apr 1, 2010

the location where the audioflinger, surfaceflinger and cameraservice talk to MediaRecorder's APIs? Is there any relation between MediaRecorder and AudioRecord?

View 6 Replies View Related

Android :: AudioRecord On Samsung Moment

Sep 25, 2010

We have been getting reports of audio recording not working on Samsung Moment phones on 2.1-update1.

int bufferSize = AudioRecord.getMinBufferSize(sampleRate, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT); this.audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC, sampleRate, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, bufferSize);

generates these logs: I/AudioPolicyManager( 1889): getInput() inputSource 1, samplingRate 16000, format 1, channels 10, acoustics 0 W/AudioHardwareALSA( 1889): openInputStream : mInput already exists!! E/AudioRecord( 2618): Could not get audio input for record source 1 E/AudioRecord-JNI( 2618): Error creating AudioRecord instance: initialization check failed. E/AudioRecord-Java( 2618): [ android.media.AudioRecord ] Error code -20 when initializing native AudioRecord object. I can't find the "mInput already exists". anywhere in the source base, could this perhaps be an error message included by the OEM?

View 4 Replies View Related

Android :: Creating A New Class Using Eclipse New Java Class Dialog Box

Jul 7, 2010

I'm creating a new class, using eclipse "New Java Class" dialog box. I can write the superclass I want (I can't find using "browse" button), but I can't write or select an interface to implement. I click "add" but ther is nothing to select. What I'm doing wrong?

View 4 Replies View Related

Android :: How Can I Get Amplitude Volume / When Recording With AudioRecord?

Apr 6, 2010

How can I get the amplitude/volume when recording with AudioRecord?

View 2 Replies View Related

Motorola :: Android AudioRecord Fails To Initialize

Nov 12, 2010

I've been having an issue with using AudioRecord for Android. I've read as much as I can find online about it, but I cannot seem to get a good initialization. I have tried the Android 2.2 emulator, 1.5 emulator and my phone, an HTC Incredible running Froyo. The emulators and my phone fail initialization. I've tried sampling rates of 8000, 11025, and 44100, formats of CHANNEL_IN_MONO/STEREO and CHANNEL_CONFIGURATION_MONO/STEREO, 8bit and 16bit encoding (8 bit makes the getMinBufferSize fail), and Audio Source of MIC and DEFAULT. All result in the variable test becoming 0 after running a get state(failed initialization). It seems from everything I've read that this should correctly initialize the object. I have played around with the multiplier on buflen, to have it range from 512 (the result of the function) to 102400 because I had heard that HTC devices require something above 8192. For testing my problem I made a new, small project that recreates my problem as simply as possible. I pull out the constants needed into local ints then run the constructor and access the getState method for checking if it worked. Code...

View 1 Replies View Related

Android :: AudioRecord Producing No Sound Data

Dec 6, 2009

Here is my AudioRecorder class, using audio record, why is it not producing any sound data?

import java.io.FileOutputStream; import java.io.IOException; import android.content.Context; import android.media.AudioFormat; import android.media.AudioRecord; import android.media.MediaRecorder; public class AudioRecorder implements Runnable {public boolean isRecording = false; byte[] tempBuffer = new byte[AudioRecord.getMinBufferSize(44100, AudioFormat.CHANNEL_CONFIGURATION_STEREO,......

View 4 Replies View Related

Android :: Improper Audio Format While Using AudioRecord API / What To Do?

Oct 12, 2010

I am doing recording in following way and storing byte array in a binary file. But the binary file I am getting is not in any format. what can be the problem? code...

View 3 Replies View Related

Android :: NexusOne AudioRecord Randomly Goes To Standby

May 9, 2010

On the nexus one, my app goes into Audio Record Stanby randomly after 0-40 seconds. I'm using the AudioRecord class, and while the standby is reported in the terminal, the AudioRecord instance reports the same states of RECORDSTATE_RECORDING and STATE_INITIALIZED throughout the entire sequence.

The bottom line is that when this anomaly occurs, audio is not captured. and this is what im working to prevent was only able to reproduce on nexus one android2.1 not g1 android1.6

I have looked extensively through the Android C/C++ libraries such as at this file: http://android.git.kernel.org/?p=platform/hardware/msm7k.git;a=blob_p... and [url]

Most interesting to me, is this line in AudioFlinger: [url]

Specifically the bool AudioFlinger::RecordThread::threadLoop()

As you can see, minput->standby() occurs in 4 different places in the code.

View 3 Replies View Related

Android :: Communicating Between Receiver Class And An Activity Class

Jul 14, 2010

I'm just getting into Android development, and I have a question about communicating between a receiver class and an activity class. I'm very new to JAVA and Android so I hope I don't sound too stupid. I'm developing an application where I intercept an SMS message and then based on various elements of that SMS I might delete it once it's been saved to the inbox. I have a receiver class that intercepts the txt message, and I am also able to delete messages from my inbox with code in the activity class using a button at the moment. The problem I have is communicating between the receiver class and the activity class where the code to delete a message resides. I tried putting that code directly into the receiver class but as I'm sure most of you already know the BroadcastReceiver class doesn't seem to support what I need to delete messages. I've been searching for an answer to this for a while, but haven't been able to find anything. Honestly I'm not sure I know enough about JAVA and Android to even recognize a solution if I saw it.

View 2 Replies View Related

Android :: Accessing Class Level Stuff From Inner Class

Jun 27, 2010

What I want to do, is be able to access the object neoApi inside the Neoseeker class, from its inner class RunningTimer. Now, in my code, you can see what I would think to work, but when I run my application, nothing pops up. Nothing inside my TextView, no Toast, nothing at all. How can I remedy this?

package com.neoseeker.android.app;
import java.util.Timer;
import java.util.TimerTask;
import org.json.JSONObject;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;.......................

View 1 Replies View Related

Android :: Access Application Class From Class Other Then Activity

Sep 8, 2010

I'm new to Java and android development. In my application I need data which is accessible for a few activities. I've read that a good solution is to use Application class for this. So I use it like this:

public class MyApplication extends Application {
private String str;
public String getStr(){
return str;
}
public void setStr(String s){
str = s;
}
}

and I can access this variable from activity like this:........................................

View 2 Replies View Related

Android :: Call Activity Class From Other Java Class?

Oct 8, 2010

I have just started android. I just want to know that how can i call activity class from other java class. i just want to pass class object to activity class.

public class GsonParser extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MagazineThread thread=new MagazineThread();
thread.start();
}
public GsonParser(JsonMagazineParser Obj)
{

}
}

and i am just doing like from other class. GsonParser obj=new GsonParser(this);passing obj to activity class.how can i achieve that.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved