0

I am new to alsa and trying to implement audio recording from mic. I want to implement mute function and wrote below api. I am not sure if using snd_pcm_pause for mute is the correct way to implement mute. I am able to stop audio recording but when trying to resume audio is not recorded.

Here is how sample code for that.

    int rc;
    rc = snd_pcm_pause(pcm_handle, flag);
    if(rc < 0 && flag==0){
            printf("mic resume failed");
            return false;
    }else if(rc < 0 && flag==1){
            fprintf("mic pause failed");
            return false;
    }

    return true;
Utkarsh Patel
  • 99
  • 1
  • 2
  • 7
  • What exactly do you mean with "mute function"? Do you want to stop recording, or to continue recording but with silent samples? – CL. Jun 02 '20 at 14:39
  • I want to stop recording when we do mute and start recording when we unmute it. I do not want any slient samples to be recorded. – Utkarsh Patel Jun 03 '20 at 08:03
  • Does your device actually support pausing? What happens when you try to unpause? – CL. Jun 03 '20 at 09:14
  • My device support pause and it works fine. Also it seems that unpause also done successfully but after unpause its not recording any audio. – Utkarsh Patel Jun 03 '20 at 10:40
  • What do you mean with "not recording"? Does `snd_pcm_readi()` fail?` Are wrong samples returned? – CL. Jun 03 '20 at 12:21
  • No. snd_pcm_readi( ) is not failing. Also unmute is not failing. but after unmute audio is not recorded at all. Assume i recorded 1 min audio and then did mute. After 30 seconds of mute i did unmute and again recorded audio for 1 min after unmute. But in recorded audio, i see only 1 min audio instead of 2 min audio. Also if i don't do mute unmute, there is no problem in recording at all. Mean snd_pcm_readi and .wav file creation is fine. – Utkarsh Patel Jun 04 '20 at 07:28
  • What do you mean with "only 1 min audio"? Are there fewer samples (which would imply a lower sample rate)? – CL. Jun 04 '20 at 07:29
  • sample rate is 44100. If i record 10 mins continuously its recording just fine. I am suspecting snd_pcm_pause( ) has some issue on my hardware since its hardware dependent. Is it possible that alsa driver has some issues with pause? – Utkarsh Patel Jun 04 '20 at 07:32
  • Again, what do you mean with "only 1 min audio"? If there are fewer samples written to the file, this would imply that `snd_pcm_readi()` does return fewer samples. Did you monitor how many samples are returned? – CL. Jun 04 '20 at 07:34
  • Yes. snd_pcm_readi( ) is not returning fewer samples. I have a condition check for that which is not executing here means samples read is not less. with each snd_pcm_readi() call its reading 256 frames before mute and after unmute. – Utkarsh Patel Jun 04 '20 at 07:44
  • So what is the problem? Don't all those sample get written to the file? – CL. Jun 04 '20 at 08:09

0 Answers0