Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Audio recording delay

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:

  • is the delay constant on all Android devices (4.0 +)?
  • how to calculate delay without involving complex methods?
  • is it acceptable on mobile device, to open the audio recording and scale it to instrumental (which may involve audio decoding/encoding)?

How to get rid of the delay?

like image 349
GrandMarquis Avatar asked Mar 18 '26 16:03

GrandMarquis


1 Answers

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.

like image 198
Jeffrey Klardie Avatar answered Mar 21 '26 11:03

Jeffrey Klardie