I'm writting an application for Android where my goal is to record the user singing. After the recording, I play the record synced with the instrumental one (which is not a problem).
The problem is when I start recording at the same time as playing the audio I suspect there is a delay for the recording to start: (it is noticeable when I try to play the recording later when the recording recorded the instrumental too). The delay might be around 300ms on nexus 5.
My inquiries are:
How to get rid of the delay?
As @Lukos already mentions, it is very likely that the delay depends on the processing speeds. It simply takes some time to start the recorder.
I believe your best solution would be to start the recorder first, and then start audio playback as soon as you know the recorder is started. This way you will have some delay in the recording, but at least you are in sync. You need to make sure the playback has been initialized, so it can be started as fast as possible.
This can be achieved using the AudioRecorder callbacks.
// Assuming you have a recorder objects defined somewhere
AudioRecord recorder;
recorder.setNotificationMarkerPosition(1);
recorder.setRecordPositionUpdateListener(new AudioRecord.OnRecordPositionUpdateListener() {
@Override
public void onMarkerReached(AudioRecord recorder) {
// start audio playback
}
@Override
public void onPeriodicNotification(AudioRecord recorder) {
}
});
Note that I'm not sure about the marker position. You might be able to use 0 as well, not sure if that will give you a notification immediately after the recording started, or if it is before it is actually started. You have to do some tests there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With