protux-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Protux-devel] SampleRate detecting code ! [was: Good news about 0.1


From: Martin Herren
Subject: Re: [Protux-devel] SampleRate detecting code ! [was: Good news about 0.17.1]
Date: Mon, 10 Feb 2003 16:09:05 +0100
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:0.9.4) Gecko/20011128 Netscape6/6.2.1

Luciano Giordana wrote:

On Sunday 09 February 2003 07:22 pm, Martin Herren wrote:

On Sun, 09 Feb 2003 21:57:58 +0100

Martin Herren <address@hidden> wrote:

protux can't open hw:0,3 (digital out)

the reason seems to be that the SB Live's digital out can handle only a
48kHz sample rate



if the snd_pcm_...._test_....() functions worked in ALSA, the supports() method, in MustuxAudioDEviceMapper, would mark this bus out as supporting only 48 Khz and would not let us try in 44100.

but they dont work, and ALSA says that all buses supports everthing (such 96Hkz in a SBLive !!!)

I need to find a way to check the bus capabilities, otherwise, it will keep happening...


i read myself somewhat through the alsa doc and some example code, and wrote a small program to detect the supported sample rates... it's somewhat 'heavy' as i need to open and close the device for every check, as it seems not possible to reassign a new sample rate when one was already assigned ! It uses the 'new style' API function snd_pcm_hw_params_set_rate_near(), so you _need_ to define ALSA_PCM_NEW_HW_PARAMS_API before including alsa/asoundlib.h.

i tested it with the 2 outputs of my sb live, and the result seems correct:
for hw:0,0 (analog out):
address@hidden:~/alsa$ ./detect_sample_rates hw:0,0
8000 supported
11025 supported
16000 supported
22050 supported
32000 supported
44100 supported
48000 supported

and for hw:0,3 (digital out):
address@hidden:~/alsa$ ./detect_sample_rates hw:0,3
48000 supported

(it checks the following rates: 8000, 11025, 16000, 22050, 32000, 44100, 48000, 96000, 192000)

hope that may help you...

/Martin

/**** detect_sample_rates.c ****/
#include <stdio.h>
#include <stdlib.h>
#define ALSA_PCM_NEW_HW_PARAMS_API
#include <alsa/asoundlib.h>

int main(int argc, char **argv)
{
       int i;
       int err;
       int rate;
int rates[10] = {8000, 11025, 16000, 22050, 32000, 44100, 48000, 96000, 192000, 0};
       snd_pcm_t *playback_handle;
       snd_pcm_hw_params_t *hw_params;

       if (argc < 2)
       {
fprintf(stderr, "you must give a device name as argument\n");
               exit(1);
       }

       for (i = 0; (rate = rates[i]) != 0; i++)
       {
if ((err = snd_pcm_open(&playback_handle, argv[1], SND_PCM_STREAM_PLAYBACK, 0)) < 0)
               {
fprintf(stderr, "cannot open audio device %s (%s)\n", argv[1], snd_strerror(err));
                       exit(1);
               }

               if ((err = snd_pcm_hw_params_malloc(&hw_params)) < 0)
               {
fprintf(stderr, "cannot allocate hardware parameter structure (%s)\n", snd_strerror(err));
                       exit(1);
               }

if ((err = snd_pcm_hw_params_any(playback_handle, hw_params)) < 0)
               {
fprintf(stderr, "cannot initialize hardware parameter structure(%s)\n", snd_strerror(err));
                       exit(1);
               }

if ((err = snd_pcm_hw_params_set_access(playback_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0)
               {
fprintf(stderr, "cannot set access type (%s)\n", snd_strerror(err));
               }

if ((snd_pcm_hw_params_set_format(playback_handle, hw_params, SND_PCM_FORMAT_S16_LE)) < 0)
               {
fprintf(stderr, "cannot set sample format (%s)\n", snd_strerror(err));
                       exit(1);
               }

if ((err = snd_pcm_hw_params_set_rate_near(playback_handle, hw_params, &rate, 0)) < 0)
               {
fprintf(stderr, "cannot set sample rate (%s)\n", snd_strerror(err));
                       exit(1);
               }
               if (rate == rates[i])
                       fprintf(stdout, "%i supported\n", rate);
               snd_pcm_close(playback_handle);
       }
       exit(0);
}







reply via email to

[Prev in Thread] Current Thread [Next in Thread]