protux-devel
[Top][All Lists]
Advanced

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

Re: [Protux-devel] SampleRate detecting code !


From: Martin Herren
Subject: Re: [Protux-devel] SampleRate detecting code !
Date: Mon, 10 Feb 2003 21:49:01 +0100

Hej,

much shorter and using snd_pcm_hw_params_test_rate():

/**** 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 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; rates[i] != 0; i++)
          {
            if (snd_pcm_open(&playback_handle, argv[1], 
SND_PCM_STREAM_PLAYBACK, 0) < 0)
              exit(1);
            
            if (snd_pcm_hw_params_malloc(&hw_params) < 0)
              exit(1);
            if (snd_pcm_hw_params_any(playback_handle, hw_params) < 0)
              exit(1);
            if (!snd_pcm_hw_params_test_rate(playback_handle, hw_params, 
rates[i], 0))
              fprintf(stdout, "%6i supported\n", rates[i]);
            
            snd_pcm_close(playback_handle);
          }
        exit(0);
}
/**** EOF ****/

the thing is you _have_ to call snd_pcm_hw_params_any() before calling 
snd_pcm_hw_params_test_rate() (that isn't done yet in 
MustuxAudioDeviceMapper::Bus::supports()).
Don't ask me why, it's the first time i program anything with alsa...

snd_pcm_hw_params_test_rate() returns 0 if the rate is supported, and a value < 
0 (-22) otherwise. If you don't call snd_pcm_hw_params_any(), it will always 
return < 0 (-22).

According to the doc it should return 1 if the rate is available, and 0 
otherwise, but we must assume the doc is wrong on this point !

hope that's what you wanted

/Martin

PS: my outputs:
SB Live analog out (should support up to 48kHz):

bash-2.05b$ ./detect_sample_rates hw:0,0
  8000 supported
 11025 supported
 16000 supported
 22050 supported
 32000 supported
 44100 supported
 48000 supported

SB Live digital out (should support 48kHz):

bash-2.05b$ ./detect_sample_rates hw:0,3
 48000 supported

SB16 VibraX (should support up to 44.1kHz):

bash-2.05b$ ./detect_sample_rates hw:1,0
  8000 supported
 11025 supported
 16000 supported
 22050 supported
 32000 supported
 44100 supported

of course if i use plughw:x,y, any rate will be accepted as alsa will do the 
conversion, but that's not what we want.

-- 
Martin Herren

Protux - A Free Professional Audio Tool for GNU/Linux:
-> http://www.nongnu.org/protux/
Open your Windows - Free your Mind - Enjoy:
->http://gnuwin.epfl.ch

Attachment: pgpImBshOKbE3.pgp
Description: PGP signature


reply via email to

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