Microphone usage with ALSA?


hmc

Active Member
Joined
Dec 19, 2011
Messages
787
Location
Bavaria, Germany
Hi guys,

I want to port a program to the Pandora. It uses Microphone input using OSS, JACK or ALSA.

My guess was, that ALSA is the best choice, so I disabled JACK support and am now trying to configure ALSA.

However, it doesn't work. Maybe someone can help?

I can successfully record audio from the microphone using


arecord -f cd -D hw:0,1 test.wav

So I assume ALSA works correctly and the device to use is "hw:0,1".

Now, if I configure my application to use ALSA and device "hw:0,1", I get an error message, that channel count cannot be set.

In the sources, I identified this code to cause that error:



if ((err = snd_pcm_hw_params_set_channels(audio->capture_handle,
hw_params, channels)) < 0) {
sprintf(error_message, "Cannot set channel count.\n%s.", snd_strerror(err));
throw(error_message);
}


"channels" is 1.

The function snd_pcm_hw_params_set_channels() is an alsa-lib function, so I assume there must be a way to make it work correctly with the Pandora's microphone? Any experience with this?

I have changed channels to 2 and recompiled, but the same error message.

Then I commented out the entire block of code above, but this lets the application crash entirely.

Any idea how to proceed form here?

By the way: The application is "Lingot", a guitar tuner program.

Thanks!

Daniel
 
Last edited by a moderator:
oh. in case you like to try yourself: Here is my current PND of Lingot (unpatched code).

Use Ctrl-P (Preferences) to configure audio.

Lingot.pnd
 

Attachments

  • Lingot.pnd
    217.1 KB · Views: 416
Last edited by a moderator:
May be because the input is mono.

Here's my .asoundrc, if it can help:

Code:
pcm.dmixed {
    type dmix
    ipc_key 1234
    slave {
         pcm "hw:0"
         buffer_size 8192
         period_size 2048
         #periods 128
         period_time 0
         buffer_time 0
         rate 44100
    }
}


pcm.softvol {
    type softvol
    slave {
          pcm      "dmixed"
    }
    control {
          name     "Master"
          card 0
    }
}

pcm.!default {
    type     plug
    slave.pcm   "softvol"
}

pcm.dsp0 {
    type plug
    slave {
          pcm "hw:0"
    }
}

ctl.dsp0 {
    type plug
    slave.pcm "hw:0"
}

ctl.mixer0 {
    type plug
    slave.pcm "hw:0"
}

pcm.imic {
    type route
    slave {
        pcm "hw:0,1"
        channels 2
    }
    ttable {
        0.0 = 1
    }
}
pcm.xmic {
    type route
    slave {
        pcm "hw:0,1"
        channels 2
    }
    ttable {
        0.1 = 1
    }
}
 
thanks...

my .asoundrc does not contain the microphone records at all.

I wonder why yours has "channels" set to 2 for the mic records.

Can you do a short test for me? 

Load the PND I posted before, start Lingot, go into preferences and enter "hw:0,1" into the device field for ALSA, then hit OK and tell me what happens?

Thanks!
 
hw:0,1 is correct. In addition to having two channels you have to make sure that the sample rate is the same as the output rate (and that implies you have to setup output first).
 
..and how? :)

Please excuse my ignorance. I have not used alsa-lib before, nor did I write code on that level for sound card control yet.

"having two channels" - do you mean the application must use 2 channels, not 1, for the Pandora's microphone?
 
..and how? :)

Please excuse my ignorance. I have not used alsa-lib before, nor did I write code on that level for sound card control yet.

"having two channels" - do you mean the application must use 2 channels, not 1, for the Pandora's microphone?
Yes, the internal mic is on one channel, the external on the other.  Very non-standard, and it has indeed caused many problems with Linux sound apps which try to use an input source.  I'm the one who made up the "imic" and "xmic" additions to the ALSA config to get at individual channels, but one of ALSA's weaknesses is that it doesn't have a rationalized way to select input devices.  So on a given app you may or may not have the ability to select the imic/xmic sources.  Alas.
 
..and how? :)

Please excuse my ignorance. I have not used alsa-lib before, nor did I write code on that level for sound card control yet.

"having two channels" - do you mean the application must use 2 channels, not 1, for the Pandora's microphone?
Yes.
 
Thanks, guys, for the explanation.

I'll continue to try to make it work.

Btw: What's meant by "external" microphone? I only know about one built-in microphone (that's problably imic). The EXT connector has Audio Line-In, which can certainly be used for a microphone, too, but those are two normal channels, L and R. So I assume this is not what's meant with "external microphone" (or xmic)?
 
Last edited by a moderator:
Btw: What's meant by "external" microphone? I only know about one built-in microphone (that's problably imic). The EXT connector has Audio Line-In, which can certainly be used for a microphone, too, but those are two normal channels, L and R. So I assume this is not what's meant with "external microphone" (or xmic)?
Your headphone jack supports a four-conductor headphone/mic type of connection.  That's what I'm calling the "external" microphone, as opposed to the one built into the unit.
 
I use the following alsa config - it joins the microphone of the headset and mainboard to a single mono microphone and makes it the default (so hopefully no additional config is necessary)..one thing which had me puzzled for a while is that programs started from a pnd do not read a .soundrc in the home directory - so make sure you include any config in the pnd, or if you want to test with an existing pnd; copy it to the appdata folder of the pnd... 

Code:
pcm.dmixed {
    type dmix
    ipc_key 1234
    slave {
         pcm "hw:0,0"
         buffer_size 8192
         period_size 2048
         #periods 128
         period_time 0
         buffer_time 0
         rate 44100
    }
}


pcm.softvol {
    type softvol
    slave {
          pcm      "dmixed"
    }
    control {
          name     "SoftMaster"
          card 0
    }
}


pcm.convert_mic {
	type route
	slave {
		pcm "hw:0,1"
		channels 2
	}
	ttable {
		0 {
			0 1.0
			1 1.0
		}
	}
}

pcm.asymed {
	type asym
	playback {
		pcm "softvol"
	}
	capture {
		pcm "convert_mic"
	}
}

pcm.!default {
   type plug
   slave.pcm "asymed"
}

ctl.!default {
  type hw
  card 0
}
 
Last edited by a moderator:
btw; the above asoundrc does crash some programs - still debugging the cfg  ;)
 
I noticed that lingot is in the repo.

Here is how it works.

Set Audio System to OSS.

Audio device to /dev/adsp

Lower the noise threshold.

:rolleyes:
 
I noticed that lingot is in the repo.

Here is how it works.

Set Audio System to OSS.

Audio device to /dev/adsp

Lower the noise threshold.

:rolleyes:
Lingot gives me no output, no matter what audio system is set.

Also with JACK running.

Any hints? This is one of those programs I was waiting for : )

it is working now! I had to try it several times. My fault.

thanks Canseco for the port! (maybe it makes sence to set the default settings to some working combination? or can you put it in the Description)

These are working for me:


ALSA - plughw:0,1 - 11025Hz

OSS - /dev/adsp - 44100 Hz
 
Last edited by a moderator:
I noticed that lingot is in the repo.

Here is how it works.

Set Audio System to OSS.

Audio device to /dev/adsp

Lower the noise threshold.

:rolleyes:
Lingot gives me no output, no matter what audio system is set.

Also with JACK running.

Any hints? This is one of those programs I was waiting for 

it is working now! I had to try it several times. My fault.

thanks hmc for the port! (maybe it makes sence to set the default settings to some working combination? or can you put it in the Description)

These are working for me:


ALSA - plughw:0,1 - 11025Hz

OSS - /dev/adsp - 44100 Hz
It's me who compiled pnd on repo, because hmc pnd doesn't have jack support.

I will include configs in description for now, try to put default config on pnd and add hmc as maintainer if he wants.
 
It's me who compiled pnd on repo, because hmc pnd doesn't have jack support. I will include configs in description for now, try to put default config on pnd and add hmc as maintainer if he wants.
right! And thanks also for all your work with soundprogrs for the Pandora in general!

You really should write some "music-production" HowTos for the Wiki or blogs or directly as ebook

I Have the impression you are quite good in helping the Pandora community in this métier.
 
Last edited by a moderator:
Back
Top