Linux uses ALSA to play sound-basic usage __linux

Source: Internet
Author: User

1. Open the device

snd_pcm_t *handle;

 /* Open PCM device for playback. *
 rc = Snd_pcm_open (&handle, 
  "Default",
  snd_pcm_stream_playback, 0);
 The IF (RC < 0)
 {
 }

     is read-write by default block blocking mode and can be set to Non-block mode.
  snd_pcm_nonblock
   or
          snd_pcm_nonblock ()


2. Non-blocking writing (in general, the blocking way to write code is good, ALSA inside has been written, do not do it yourself retry operation)
It means to try again after a while.

  int rc = Snd_pcm_writei (handle, buf, N/4);
  printf ("Done.") rc=%d\n ", RC);
  while (RC < 0)
  {
   if (rc =-eagain)
   {
    int ms =;
    Timespec ts;
    Ts.tv_sec = ms/1000;
    Ts.tv_nsec = (ms% 1000) * 1000000;
    Nanosleep (&ts, NULL);

    rc = Snd_pcm_writei (handle, buf, N/4);
   }
  


The third parameter is the number of frame. For a S16/stereo audio, its frame = 2 * 2 = 4, which is the blockalign parameter defined by Microsoft.
If the default block mode is used, the Writei function blocks until the write succeeds. When a write succeeds, the return value RC is always equal to the number of frame passed in.

When Non-block mode, returns-eagain (-11) If the internal buffer is full. Note the eagain=11, you need to add a minus sign.

This function is either fully written or returned to-eagain, and does not occur if only one part is written.

"Polar Star friends and relatives positioning": simple and practical, is a suitable for family, friends between the positioning software, real-time query the location of the other side and the map display. Very suitable for family use, less a worry, more than a security guarantee, can promptly know the whereabouts of their families, can avoid finding children, the elderly and other situations.

(In fact, the time, automatic characteristics, can be to a large extent to ensure that families encounter danger when not to drop the chain)

Do not need the other side will use the smartphone, because the software can set the white list automatic response, do not need to do anything to get the other side of the location.
Do not need to open the software reply, also do not need to start the software in advance.

Download location:360 Market (can use 360 mobile phone assistant to download, keyword "Polar Star", "Polar Star friends and relatives positioning")

-As long as the software installed on both sides, and turned on the GPS function (the general mobile phone has been opened), that is, input the other mobile phone number, query location.
-You can select a contact from your address book or select it directly from the recent Contacts menu.
-Whitelist is used to specify trusted contacts, and their query requests are automatically responded to.
-Integrated map display function, if the mobile phone has installed the Baidu map software, you can show the location of each other on the map.
-Can prevent misoperation: Send the button using a delay response design, only after pressing about 1 seconds after the confirmation sent, and the vibration and text prompts you to send success.

--------------------------------------------------------------------------------------------------------------- -------------------


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.