Languages

Menu
Sites
Language
Recording by audio i/o callback is very slow (only pick up less than 45% of audio)

Hi all,

I follow the audio i/o tutorial (https://developer.tizen.org/dev-guide/2.4/org.tizen.tutorials/html/native/multimedia/audio_io_tutorial_n.htm) to build a real-time audio recording app. However, the callback is called very infrequently for recording the whole sound. For example, when I start the recording for 5 second, the callback actually only gives a 2-second clip (instead of 5).

Here is a dummy testing code which only dumps how many bytes have been recorded:

int _audio_read_total;
static void _audio_io_stream_read_cb(audio_in_h handle, size_t nbytes, void *userdata)
{
    const void *buffer = NULL;
    if (nbytes > 0) {
        int error_code = audio_in_peek(handle, &buffer, &nbytes);
        _audio_read_total += nbytes;
        dlog_print(DLOG_DEBUG, LOG_TAG, "nbytes = %d,_audio_read_total = %d", nbytes, _audio_read_total);
        error_code = audio_in_drop(handle); // remove audio data from internal buffer
    }
}
static void start_audio_recording(appdata_s *ad)
{
    int error_code = audio_in_create(48000, AUDIO_CHANNEL_MONO, AUDIO_SAMPLE_TYPE_S16_LE, &ad->input);    
    error_code = audio_in_set_stream_cb(ad->input, _audio_io_stream_read_cb, ad);
    error_code = audio_in_prepare(ad->input);}
 
 
Attached images include the result of running this code on Galaxy Gear S3. As you can see in the image, the recording callback is called from time 32.3 to time 37.7 (over 5 seconds), but only 224250 bytes are received (it should be (37.7-32.3)*48000*sizeof(short) = 518400). That means only less than 40% of audio is recorded. 
 
Could you give me some suggestion to solve this issue?
 
Yu-Chih 

Responses

3 Replies
Shaswati Saha

Would you please try modifying below line of code

audio_in_create(48000, AUDIO_CHANNEL_MONO, AUDIO_SAMPLE_TYPE_S16_LE, &ad->input);

as below:

audio_in_create(48000, AUDIO_CHANNEL_STEREO, AUDIO_SAMPLE_TYPE_S16_LE, &ad->input);

I've tried to run a native sample app named AudioIO for Mobile 2.4 in my Gear S3 2.3.2 and the result(refer to the attached image) is better than yours. In that sample app i've seen that AUDIO_CHANNEL_STEREO is used instead of AUDIO_CHANNEL_MONO. I guess, it may work.

 

Slawek Kowalski

I have the same issue on Samsung Gear S3. My recording code works great on Tizen phone but brokes on watch. I see that callback returns only the first part of audio samples - about 30-40% from start. First time I thought that recording audio bytes into a file stops callback somehow. Now I see it is deeper issue in tizen engine I suppose.

 

Did you find some solution/workaround for that issue?

 

 


 

Slawek Kowalski

Actually I found some solution. Changing sample rate from 44100 to 15000 or lower causes the callback returns more audio data, but not all. It is actually a little workaround. Of course sound quality significantly worse.