This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

audio recording problem in android ics

Hi,

 

We are working with the AM/DM37X Evaluation module from Mistral and Android ICS 4.0.3. We have a problem with audio capture. If we run the Sound Recorder application that comes with android, the first two seconds are not recorded. Also, if we run other similar sound capturing applications, like Sound Meter, the first seconds are not recorder.

 

After checking Android's LogCat, we noticed that during the first seconds it was constantly printing the following error:

 E/audio_hw_primary(1158): cannot open pcm_in driver: cannot set hw params: Invalid argument

 

After a period of time, it would stop printing the error and start recording. We also noticed, that it stopped the error just after the Mixer thread released a lock and went to sleep:

 I/AudioFlinger(1158): Audio hardware entering standby, mixer 0x15378, mSuspended 0

I/AudioFlinger(1158): releaseWakeLock_l() AudioOut_1

I/AudioFlinger(1158): MixerThread 0x15378 TID 1234 going to sleep

I/audio_hw_primary(1158): in_read(0x20020, 0x1bf68, 4096)

I/audio_hw_primary(1158): start_input_stream(0x20020)

I/audio_hw_primary(1158): start_input_stream: opened pcm device: 

We thought that maybe the mixer was locking some resource needed by the recorder. We disable all the touch sounds in the system setting, so that there was no mixer trying to mix sounds in the system. After this change the Sound Recorder application worked just fine from the very beginning, and if we activated the touch sounds again it had the same problem. We also tried a VOIP program, but the problem was worse, if it was able to play the sounds during a call then it didn't capture due to the same problem, and viceversa.

 

The system is also printing this error form once in a while.

E/audio_hw_primary(1158): Route MIXER CTRL name: HeadsetR Mixer AudioR2

E/audio_hw_primary(1158): Route MIXER CTRL name: HeadsetL Mixer AudioL2

E/audio_hw_primary(1158): Route MIXER CTRL name: Headset Playback Volume

E/audio_hw_primary(1158): Route MIXER CTRL name: Analog Left AUXL Capture Switch

 

Attached are the LogCat result for both situations, with the touch sounds enabled and disabled.

 6761.SoundRecorderGood_Touch_Sounds_Disabled.txt

6523.SounRecorder_Touch_Sounds_Enabled.txt

 

  • This issue is because the playback and capture channels are being operated at different sampling rates. The audio codec currently supports only one sampling rate at a time.

    There is no fix planned for this yet.

  •                

    Vishveshwar,

    I tried to change the rates in my VOIP application but the problem still persists. I decided to write a simple audio loopback application. The application captures audio with AudioRecord and plays it back with AudioTrack. I used the same rate for capture and playback, but the problem still persists. The audio loopback application works fine in android 2.3.4 but in 4.0.3 it still has the problem posted at the beginning.

    I decided to test the audio codec without the framework, therefore I changed the code of tinycap and tinyalsa, so that they could read and write from the standard input and output stream. I used these new programs to create a loopback using a pipe (#tinycap2 | tinyplay2). The loopback at this level worked fine; therefore I think that the problem is maybe at the framework level. Do you have any idea? I really need to fix this.  Thanks for your time.

    All these test were done on the mistral AM/DM37X Evaluation module.

  • Vishveshwar,

    I went deep and printed the rate received by  the pcm_open function of tinyalsa. You were wright, for capture it is receiving 8000 but for playback it is receiving 44100. The thing is, in java i am setting the rate of my AudioTracker to be 8000, but somehow this 8000 is not being received because that same java code works fine in the 2.3.4. Eventhough the codec cannot play two different sampling rates at a time, the problem is that the framework is changing my rate somehow.

    regards,

    Alberto Garcia

  • Thanks for the updates.

    As you have discovered, android seems to insist on opening the playback channel at 44.1kHz irrespective of the requested sample rate. We shall continue to try and find a fix for this issue. However we are not in a position to commit on a timeline for this.

  • Hi all,

    We got the same problem too. Does anyone have a solution for this? Thanks.

  • There is a configuration for Audio recording that could affect, check next patch,

    but it could not be the case since these values were reduced recently, but worth to check it.

    diff --git a/include/media/stagefright/AudioSource.h b/include/media/stagefright/AudioSource.h
    index d484d60..c452046 100644
    --- a/include/media/stagefright/AudioSource.h
    +++ b/include/media/stagefright/AudioSource.h
    @@ -54,11 +54,11 @@ private:
     
             // After the initial mute, we raise the volume linearly
             // over kAutoRampDurationUs.
    -        kAutoRampDurationUs = 700000,
    +        kAutoRampDurationUs = 100000,
     
             // This is the initial mute duration to suppress
             // the video recording signal tone
    -        kAutoRampStartUs = 1000000,
    +        kAutoRampStartUs = 300000,
           };
     
         AudioRecord *mRecord;

    Reducing kAutoRampStartUs to zero causes some AVSync issues, that is why I set it 300msec, and kAutoRampDurationUs could be reduced a little more  I calculated it using the wakeup time that it requires audio driver between loading it and video is loaded, in between audio goes to sleep. Switching Audio and Video loading is not helping in this case.

  • The other effect by reducing those values was that it was recorded the shutter sounds.

  • Hi Manuel,

    Thanks for your reply. I tried but it doesn't work. Like Vishveshwar said:

    "This issue is because the playback and capture channels are being operated at different sampling rates. The audio codec currently supports only one sampling rate at a time."

    We need to get audio in/out work simultaneously for VOIP applications. If we adjust the recodring sample rate in \hardware\ti\omap3\audio\Audio_hw.c to DEFAULT_OUT_SAMPLING_RATE which is 44100, the sound is recoreded but the duration became 5.5 times(8000 --> 44100) length. It seems we need to resample the audio sample rate to 8000 so that the codec could encode it correctly.

  • Jesse;

    Ok, thanks for explaining.

  • I was able to solve the problem. You are almost there. After you change in audio_hw.c the #define DEFAULT_OUT_SAMPLING_RATE 8000 to solve the rate problem, you need to change some constant in the same file.


    /* constraint imposed by ABE for CBPr mode: all period sizes must be multiples of 24 */
    #define ABE_BASE_FRAME_COUNT 24
    /* number of base blocks in a short period (low latency) */
    #define SHORT_PERIOD_MULTIPLIER 15 /* 40 ms */
    /* number of frames per short period (low latency) */
    #define SHORT_PERIOD_SIZE (ABE_BASE_FRAME_COUNT * SHORT_PERIOD_MULTIPLIER)

    SHORT_PERIOD_MULTIPLIER, was 80 because 80 times 24 at 44000 gives you a latency of aprox 40 ms, but if you change the sampling rate then you need to change SHORT_PERIOD_MULTIPLIER to 15 to get a latency of 40 ms,

    Hope this help

  • Hi Alberto,

    Thanks for your information and it works. We also found a solution that use 44100 as audio input sample rate and
    resample it to requested sample rate. It could keep the audio output quality from 44100. Referred to:
    http://gitorious.org/rowboat/hardware-ti-omap3/blobs/rowboat-jb/audio/audio_hw.c
    Thanks a lot

  • Hi Jesse,

    i tried every hint discussed here but nor able to solve the problem.

    What and where did you changed the sources to make it work.

    Thanks

    Carsten

  • Hi Carsten,

    What I did was to merge the resampler code from this link:

    https://gitorious.org/rowboat/hardware-ti-omap3/source/d1c49521f68afe303ea8092dc1a0b462ee768220:audio/audio_hw.c

  • hi Jesse

    could you please help to solve the same issue with android 4.0.

    as the file link you gave is for 4.1

    Regards 

    Setu Gupta

  • hi Jesse

    I have changed the sampling rate of audio out from 44100 to  8000.

    as well SHORT_PERIOD_MULTIPLIER 15 (from 80).

    both things are working fine but  still we are getting very poor quality of sound capturing.

    do i need to change the period_size,period_count for audio capture structure.

    Regards

    Setu Gupta

  • Dear Jesse and Setu,

    If the sampling rate is different as default, the VoIP software like Line or FreePP is not able to use the free phone feature as VoIP. (PCM open failed like the above)

    I changed the sampling rate to 8000 and SHORT_PERIOD_MULTIPLIER 15,

    but I launch the software on AM37x with Android ICS, the voice can be heard but it sounds like a small young girl.

    If both modified to 44.1kHz, it shound like a slow motion one...

    Did your devices get this issue?

    Is this can be solved by adding resampling functions?

     

    Thank you.