LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-30-2011, 02:23 AM   #1
lvprabhu
LQ Newbie
 
Registered: Jun 2008
Posts: 4

Rep: Reputation: 0
snd_pcm_hw_params_set_rate_near() returns huge value


I wrote a sample program as follows to OPEN ALSA sound device and set its hw params -
Code:
    /* Open PCM device for playback. */
    rc = snd_pcm_open(&handle, "default",
                    SND_PCM_STREAM_PLAYBACK, 0);
    if (rc < 0) {
      fprintf(stderr,
            "unable to open pcm device: %s\n",
            snd_strerror(rc));
      return 1;
    }

    /* Allocate a hardware parameters object. */
    snd_pcm_hw_params_alloca(&params);

    /* Fill it in with default values. */
    snd_pcm_hw_params_any(handle, params);

    /* Set the desired hardware parameters. */

    /* Interleaved mode */
    snd_pcm_hw_params_set_access(handle, params,  SND_PCM_ACCESS_RW_INTERLEAVED);

    /* Signed 16-bit little-endian format */
    snd_pcm_hw_params_set_format(handle, params, SND_PCM_FORMAT_S16_LE);

    /* One channel (mono) */
    snd_pcm_hw_params_set_channels(handle, params, 1);

    /* 8000 bits/second sampling rate  */
    val = 8000;
    snd_pcm_hw_params_set_rate_near(handle, params,
                                  &val, &dir);

    /* Set period size to 32 frames. */
    frames = 32;
    snd_pcm_hw_params_set_period_size_near(handle,
                              params, &frames, &dir);
    fflush(stderr);

    /* Write the parameters to the driver */
    rc = snd_pcm_hw_params(handle, params);
Above lines of code works fine if I run it as an independent test program.
When I use the same lines of code in my application, it is failing in snd_pcm_hw_params_any(). It returns "Operation not permitted". So I changed the device name to "plughw:0,0", instead of "default".
With this change, its failing at snd_pcm_hw_params_set_rate_near(). It returns some huge value 192000. Also, following snd_pcm_hw_params_set_period_size() also fails with 699050.

Any idea, why I'm getting this error? Is link to some other library or some header file inclusion, in my application causing this error? I am trying to play 8k, 16 bit PCM audio.
I appreciate your help on this.

Thanks,
Latha
 
Old 08-31-2011, 10:58 AM   #2
Proud
Senior Member
 
Registered: Dec 2002
Location: England
Distribution: Used to use Mandrake/Mandriva
Posts: 2,794

Rep: Reputation: 116Reputation: 116
192000 = 8000 * 24. 24 frames per second of 8000 bits each??

As for snd_pcm_hw_params_set_period_size()
Quote:
Returns:
0 otherwise a negative error code if configuration space is empty
So should that be a signed value but you're treating it as unsigned?
Actually both methods are documented as returning like that.
http://www.alsa-project.org/alsa-doc...___params.html
http://www.suse.de/~mana/alsa090_howto.html
 
Old 09-02-2011, 04:12 AM   #3
lvprabhu
LQ Newbie
 
Registered: Jun 2008
Posts: 4

Original Poster
Rep: Reputation: 0
Thank you for your response.
Quote:
So should that be a signed value but you're treating it as unsigned?
Actually both methods are documented as returning like that.
I've assigned the return value to an integer and also printing as integer. It is strange that when I run it as a independent test program, it works fine. Only when I integrate it with my application it is failing. While compiling my test program, I linked with all the libraries I use in my application. Still my test program works fine. I am trying to figure out under what conditions it fails.

Thanks,
Latha
 
Old 09-02-2011, 04:59 AM   #4
Proud
Senior Member
 
Registered: Dec 2002
Location: England
Distribution: Used to use Mandrake/Mandriva
Posts: 2,794

Rep: Reputation: 116Reputation: 116
Quote:
Operation not permitted
An access problem? Is your integrated version running under a different user or environment than your independent test one?
Also again I may not be good with C, but when it returns 0 you'll not notice a problem with signed vs unsigned, but why would a method that's documented to return a negative error value be giving you a large positive value unless you're handling the representation wrong? A quick google indicates you can compile C ints to be signed or unsigned, there's a default but not a strict signedness. I would try get the correct negative error number/code and see what that tells you.

Last edited by Proud; 09-02-2011 at 05:07 AM.
 
  


Reply

Tags
alsa


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Slackware 13.1 huge smp is not huge cs_strong Slackware 4 11-16-2010 07:41 AM
huge.s genhappyok Slackware 9 04-14-2010 04:57 PM
Huge amount of "PHP Notice:" -> huge logs Braynid Linux - Software 4 03-18-2008 06:35 AM
dd never returns in BackTrack2 manolakis Linux - Newbie 17 03-01-2007 06:53 AM
Huge Huge Problem With Forums!!! The_Insomniac Linux - General 1 06-07-2004 08:15 AM


All times are GMT -5. The time now is 08:08 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration