[pulseaudio-tickets] [PulseAudio] #26: Support for nice suspend

PulseAudio trac-noreply at tango.0pointer.de
Fri Dec 22 02:32:07 PST 2006


#26: Support for nice suspend
---------------------------+------------------------------------------------
  Reporter:  art at ified.ca  |       Owner:  lennart
      Type:  enhancement   |      Status:  new    
  Priority:  low           |   Milestone:         
 Component:  daemon        |    Severity:  minor  
Resolution:                |    Keywords:         
---------------------------+------------------------------------------------
Comment (by ranma):

 Let's try this again with appropriate WikiFormatting, shall we?

 BTW, the following minimal ALSA test program survives s2disk just fine:

 {{{
 |ranma at melchior:~/projects$ ./alsa-s2disk hw:0,0
 |Opening ALSA PCM device 'hw:0,0'...
 |Open successfull, playing saw wave...
 |snd_pcm_writei failed: Streams pipe error
 }}}
 [Only one error message after resume, but continues to play fine]

 Source code:
 {{{
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <errno.h>
 #include <string.h>
 #include <alsa/asoundlib.h>

 snd_pcm_t *pcm_handle;

 int main(int argc, char **argv)
 {
         char *pcm_name = "default";
         int err, i;
         unsigned exact_rate;
         unsigned rate = 48000;
         snd_pcm_hw_params_t *hwparams;
         short buf[8192 * 2];

         if (argc == 2) {
                 pcm_name = argv[1];
         }

         printf("Opening ALSA PCM device '%s'...\n", pcm_name);
         snd_pcm_hw_params_alloca(&hwparams);

         if ((err = snd_pcm_open(&pcm_handle, pcm_name,
 SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
                 fprintf(stderr, "Could not open ALSA PCM device '%s':
 %s\n", pcm_name, snd_strerror(err));
                 return 1;
         }

         if ((err = snd_pcm_hw_params_any(pcm_handle, hwparams)) < 0) {
                 fprintf(stderr, "snd_pcm_hw_params_any failed: %s\n",
 snd_strerror(err));
                 return 1;
         }

         if ((err = snd_pcm_hw_params_set_access(pcm_handle, hwparams,
 SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) {
                 fprintf(stderr, "snd_pcm_hw_params_set_access failed:
 %s\n", snd_strerror(err));
                 return 1;
         }

         if ((err = snd_pcm_hw_params_set_format(pcm_handle, hwparams,
 SND_PCM_FORMAT_S16_LE)) < 0) {
                 fprintf(stderr, "snd_pcm_hw_params_set_format failed:
 %s\n", snd_strerror(err));
                 return 1;
         }

         exact_rate = rate;
         if ((err = snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams,
 &exact_rate, 0)) < 0) {
                 fprintf(stderr, "snd_pcm_hw_params_set_rate_near failed:
 %s\n", snd_strerror(err));
                 return 1;
         }
         if (rate != exact_rate) {
                 fprintf(stderr, "Requested rate %ldHz, got %dHz.\n",
                         rate, exact_rate);
         }

         if ((err = snd_pcm_hw_params_set_channels(pcm_handle, hwparams,
 2)) < 0) {
                 fprintf(stderr, "snd_pcm_hw_params_set_channels failed:
 %s\n", snd_strerror(err));
                 return 1;
         }

         if ((err = snd_pcm_hw_params_set_periods(pcm_handle, hwparams, 4,
 0)) < 0) {
               fprintf(stderr, "snd_pcm_hw_params_set_periods failed:
 %s\n", snd_strerror(err));
                 return 1;
         }

         if ((err = snd_pcm_hw_params_set_buffer_size(pcm_handle, hwparams,
 8192)) < 0) {
                 fprintf(stderr, "snd_pcm_hw_params_set_buffer_size failed:
 %s\n", snd_strerror(err));
                 return 1;
         }

         if ((err = snd_pcm_hw_params(pcm_handle, hwparams)) < 0) {
                 fprintf(stderr, "snd_pcm_hw_params failed: %s\n",
 snd_strerror(err));
                 return 1;
         }

         printf("Open successfull, playing saw wave...\n", pcm_name);

         for (i=0; i<8192*2; i+=2) {
                 short x = (i << 8) | (i & 0xff);
                 buf[i]   = x;
                 buf[i+1] = x;
         }

         while (1) {
                 if ((err = snd_pcm_writei(pcm_handle, buf, 8192)) < 0) {
                         fprintf(stderr, "snd_pcm_writei failed: %s\n",
 snd_strerror(err));
                         snd_pcm_prepare(pcm_handle);
                 }
         }

         snd_pcm_drop(pcm_handle);
         snd_pcm_close(pcm_handle);

         return 0;
 }
 }}}

-- 
Ticket URL: <http://www.pulseaudio.org/ticket/26>
PulseAudio <http://pulseaudio.org/>
The PulseAudio Sound Server


More information about the pulseaudio-bugs mailing list