* Discovery of device characteristics
@ 2013-02-17 2:39 Tim Hewett
2013-02-20 20:28 ` Clemens Ladisch
0 siblings, 1 reply; 4+ messages in thread
From: Tim Hewett @ 2013-02-17 2:39 UTC (permalink / raw)
To: alsa-devel
I'm writing software looking to discover the available sample rates, channel formats etc. for a device. I have been taking the approach of testing a sample rate from a list of potential rates, then setting the device to that rate to then test the channel formats etc..
The structure is initialised using snd_pcm_hw_params_any() then snd_pcm_hw_params_test_rate() is called for a set of rates followed by snd_pcm_hw_params_set_rate() if the previous call is successful, then snd_pcm_hw_params_test_format() for a set of formats followed by snd_pcm_hw_params_set_format() if that is successful, then snd_pcm_hw_params_test_channels(), the point being to narrow down the characteristics available for given sample rates and channel formats.
For example I have a device which supports up to 8 channels at sample rates of 44.1kHz and 48kHz but only 2 channels at 96kHz.
It works ok usually but keeps failing to detect that the device supports 24-bit channel formats, both for SND_PCM_FORMAT_S24_LE/BE and SND_PCM_FORMAT_S24_3LE/3BE. It detects the 16-bit formats without any problem.
Online source taken from http://download.atmark-techno.com/misc/demos/usb-audio-a500-howto/hw_params.c does detect the 24-bit format but doesn't set the sample rate first - each characteristic is tested in isolation - snd_pcm_hw_params_any() is called before each one.
I am wondering if my way is not the correct way to determine device characteristics.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Discovery of device characteristics
2013-02-17 2:39 Discovery of device characteristics Tim Hewett
@ 2013-02-20 20:28 ` Clemens Ladisch
2013-02-20 21:38 ` Tim Hewett
0 siblings, 1 reply; 4+ messages in thread
From: Clemens Ladisch @ 2013-02-20 20:28 UTC (permalink / raw)
To: Tim Hewett; +Cc: alsa-devel
Tim Hewett wrote:
> I'm writing software looking to discover the available sample rates,
> channel formats etc. for a device. I have been taking the approach of
> testing a sample rate from a list of potential rates, then setting the
> device to that rate to then test the channel formats etc..
>
> It works ok usually but keeps failing to detect that the device
> supports 24-bit channel formats, both for SND_PCM_FORMAT_S24_LE/BE and
> SND_PCM_FORMAT_S24_3LE/3BE. It detects the 16-bit formats without any
> problem.
Which device (driver) is this?
> Online source taken from http://download.atmark-techno.com/misc/demos/usb-audio-a500-howto/hw_params.c
> does detect the 24-bit format but doesn't set the sample rate first -
> each characteristic is tested in isolation - snd_pcm_hw_params_any()
> is called before each one.
snd_pcm_hw_params_any() is called only once; the configurations space
isn't reduced as long as no set* function is called.
> I am wondering if my way is not the correct way to determine device
> characteristics.
Your way sounds correct, but the driver code that sets the parameter
constraints might not be, or the device really doesn't support 24 bits
at the sample rate you've set.
Regards,
Clemens
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Discovery of device characteristics
2013-02-20 20:28 ` Clemens Ladisch
@ 2013-02-20 21:38 ` Tim Hewett
2013-02-21 7:43 ` Clemens Ladisch
0 siblings, 1 reply; 4+ messages in thread
From: Tim Hewett @ 2013-02-20 21:38 UTC (permalink / raw)
To: Clemens Ladisch; +Cc: Tim Hewett, alsa-devel
Clemens,
Many thanks for your reply.
I think today I may have found "the" solution, it seems to work at least.
The problem seems to be that the nested loops (each of which was testing sample rate, channel format and number of channels) were only calling snd_pcm_hw_params_any() at the top of the outer loop, so (e.g.) the next sample rate was tested after a previous one had been set. It seems that once one sample rate has been set, it isn't possible to test another one until the params are reset.
Now all the params are tested in the innermost loop, where snd_pcm_hw_params_any() is now called just before all the tests for each possible combination in isolation.
Separately I'm trying to find an API for being notified when devices are added/removed. If you (CC: anyone else) could point me in the right direction I'd be very grateful.
Regards,
Tim.
On 20 Feb 2013, at 20:28, Clemens Ladisch <clemens@ladisch.de> wrote:
> Tim Hewett wrote:
>> I'm writing software looking to discover the available sample rates,
>> channel formats etc. for a device. I have been taking the approach of
>> testing a sample rate from a list of potential rates, then setting the
>> device to that rate to then test the channel formats etc..
>>
>> It works ok usually but keeps failing to detect that the device
>> supports 24-bit channel formats, both for SND_PCM_FORMAT_S24_LE/BE and
>> SND_PCM_FORMAT_S24_3LE/3BE. It detects the 16-bit formats without any
>> problem.
>
> Which device (driver) is this?
>
>> Online source taken from http://download.atmark-techno.com/misc/demos/usb-audio-a500-howto/hw_params.c
>> does detect the 24-bit format but doesn't set the sample rate first -
>> each characteristic is tested in isolation - snd_pcm_hw_params_any()
>> is called before each one.
>
> snd_pcm_hw_params_any() is called only once; the configurations space
> isn't reduced as long as no set* function is called.
>
>> I am wondering if my way is not the correct way to determine device
>> characteristics.
>
> Your way sounds correct, but the driver code that sets the parameter
> constraints might not be, or the device really doesn't support 24 bits
> at the sample rate you've set.
>
>
> Regards,
> Clemens
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Discovery of device characteristics
2013-02-20 21:38 ` Tim Hewett
@ 2013-02-21 7:43 ` Clemens Ladisch
0 siblings, 0 replies; 4+ messages in thread
From: Clemens Ladisch @ 2013-02-21 7:43 UTC (permalink / raw)
To: Tim Hewett; +Cc: alsa-devel
Tim Hewett wrote:
> I'm trying to find an API for being notified when devices are added/removed.
Use the libudev monitoring interface:
http://www.signal11.us/oss/udev/
http://www.freedesktop.org/software/systemd/libudev/libudev-udev-monitor.html
Regards,
Clemens
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-02-21 7:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-17 2:39 Discovery of device characteristics Tim Hewett
2013-02-20 20:28 ` Clemens Ladisch
2013-02-20 21:38 ` Tim Hewett
2013-02-21 7:43 ` Clemens Ladisch
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.