why there is no sound for the demo prgrame of alsa lib
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > why there is no sound for the demo prgrame of alsa lib




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    why there is no sound for the demo prgrame of alsa lib  
DaVinci


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-18-07 06:20 AM

[url]http://www.alsa-project.org/alsa-doc/alsa-lib/_2test_2pcm__min_8c-example.html[/ur
l]

0001 /

00002  *  This extra small demo sends a random samples to your
speakers.
00003  */
00004
00005 #include "../include/asoundlib.h"
00006
00007 static char *device = "default";                        /*
playback device */
00008
00009 snd_output_t *output = NULL;
00010 unsigned char buffer[16*1024];                          /* some
random data */
00011
00012 int main(void)
00013 {
00014         int err;
00015         unsigned int i;
00016         snd_pcm_t *handle;
00017         snd_pcm_sframes_t frames;
00018
00019         for (i = 0; i < sizeof(buffer); i++)
00020                 buffer = random() & 0xff;
00021
00022         if ((err = snd_pcm_open(&handle, device,
SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
00023                 printf("Playback open error: %s\n",
snd_strerror(err));
00024                 exit(EXIT_FAILURE);
00025         }
00026         if ((err = snd_pcm_set_params(handle,
00027                                       SND_PCM_FORMAT_U8,
00028
SND_PCM_ACCESS_RW_INTERLEAVED,
00029                                       1,
00030                                       48000,
00031                                       1,
00032                                       500000)) < 0) {   /*
0.5sec */
00033                 printf("Playback open error: %s\n",
snd_strerror(err));
00034                 exit(EXIT_FAILURE);
00035         }
00036
00037         for (i = 0; i < 16; i++) {
00038                 frames = snd_pcm_writei(handle, buffer,
sizeof(buffer));
00039                 if (frames < 0)
00040                         frames = snd_pcm_recover(handle, frames,
0);
00041                 if (frames < 0) {
00042                         printf("snd_pcm_writei failed: %s\n",
snd_strerror(err));
00043                         break;
00044                 }
00045                 if (frames > 0 && frames < (long)sizeof(buffer))
00046                         printf("Short write (expected %li, wrote
%li)\n", (long)sizeof(buffer), frames);
00047         }
00048
00049         snd_pcm_close(handle);
00050         return 0;a
thanks very much.






[ Post a follow-up to this message ]



    Re: why there is no sound for the demo prgrame of alsa lib  
DaVinci


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-18-07 06:21 PM

On 3=D4=C218=C8=D5, =CF=C2=CE=E71=CA=B124=B7=D6, "DaVinci" <apple.davi...@g=
mail.com> wrote:
> http://www.alsa-project.org/alsa-do...__min_8c-exa...
>
> 0001 /
>
> 00002  *  This extra small demo sends a random samples to your
> speakers.
> 00003  */
> 00004
> 00005 #include "../include/asoundlib.h"
> 00006
> 00007 static char *device =3D "default";                        /*
> playback device */
> 00008
> 00009 snd_output_t *output =3D NULL;
> 00010 unsigned char buffer[16*1024];                          /* some
> random data */
> 00011
> 00012 int main(void)
> 00013 {
> 00014         int err;
> 00015         unsigned int i;
> 00016         snd_pcm_t *handle;
> 00017         snd_pcm_sframes_t frames;
> 00018
> 00019         for (i =3D 0; i < sizeof(buffer); i++)
> 00020                 buffer =3D random() & 0xff;
> 00021
> 00022         if ((err =3D snd_pcm_open(&handle, device,
> SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
> 00023                 printf("Playback open error: %s\n",
> snd_strerror(err));
> 00024                 exit(EXIT_FAILURE);
> 00025         }
> 00026         if ((err =3D snd_pcm_set_params(handle,
> 00027                                       SND_PCM_FORMAT_U8,
> 00028
> SND_PCM_ACCESS_RW_INTERLEAVED,
> 00029                                       1,
> 00030                                       48000,
> 00031                                       1,
> 00032                                       500000)) < 0) {   /*
> 0.5sec */
> 00033                 printf("Playback open error: %s\n",
> snd_strerror(err));
> 00034                 exit(EXIT_FAILURE);
> 00035         }
> 00036
> 00037         for (i =3D 0; i < 16; i++) {
> 00038                 frames =3D snd_pcm_writei(handle, buffer,
> sizeof(buffer));
> 00039                 if (frames < 0)
> 00040                         frames =3D snd_pcm_recover(handle, frames,
> 0);
> 00041                 if (frames < 0) {
> 00042                         printf("snd_pcm_writei failed: %s\n",
> snd_strerror(err));
> 00043                         break;
> 00044                 }
> 00045                 if (frames > 0 && frames < (long)sizeof(buffer))
> 00046                         printf("Short write (expected %li, wrote
> %li)\n", (long)sizeof(buffer), frames);
> 00047         }
> 00048
> 00049         snd_pcm_close(handle);
> 00050         return 0;a
> thanks very much.

I have solved the problem .Thanks.






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 07:13 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register