LECTURE 5 ¥ê¥¢¥ë¥¿¥¤¥àÀ­¤ò¹Íθ¤¹¤ë

¡û ¤Ï¤¸¤á¤Ë

¤³¤³¤Þ¤Ç¤Î LECTURE ¤ÇÏ¿²» / ºÆÀ¸¤Î¤ä¤êÊý¤Ë¤Ä¤¤¤Æ°ìÄ̤êÀâÌÀ¤·¤Æ¤­¤Þ¤·¤¿¡£¤·¤«¤·¡¢

  • ¥²¡¼¥à¤Î¸ú²Ì²»¤ÎÍͤÊû¤¤²»¤ò½ñ¤­¹þ¤ó¤À¸å¡¢¤¹¤°¤ËºÆÀ¸¤·¤ÆÍߤ·¤¤
  • ¥ê¥¢¥ë¥¿¥¤¥à¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤òºî¤ê¤¿¤¤¤Î¤Ç¡¢¥Ç¡¼¥¿¤ÎÆɤ߽ñ¤­¤¬½ÐÍè¤Ê¤¤
    ( ¥Ð¥Ã¥Õ¥¡¤¬°ìÇÕ )»þ¤Ï read() ¤ä write() ¤Ç¥Ö¥í¥Ã¥¯¤·¤ÆÍߤ·¤¯¤Ê¤¤

¤È¤¤¤Ã¤¿Í×µá¤Ë¤Ï¡¢¤³¤³¤Þ¤Ç¤ÎÃμ±¤Ç¤ÏÂбþ¤Ç¤­¤Þ¤»¤ó¡£

¤½¤³¤Ç¤³¤³¤Ç¤Ï¡¢¥ê¥¢¥ë¥¿¥¤¥àÀ­¤Î¶¯¤¤½èÍý¤ò¹Ô¤¤¤¿¤¤¾ì¹ç¤ËɬÍפȤʤë ( ¤ÈËͤ¬»×¤¦ ) ÆâÍƤ˴ؤ·¤Æ½ñ¤¤¤Æ¤ß¤¿¤¤¤È»×¤¤¤Þ¤¹¡£

¡û DMA ¥Ð¥Ã¥Õ¥¡¤È fragment

¥Ç¥Ð¥¤¥¹¥É¥é¥¤¥ÐÆâÉô¤Ç¤Ï¡¢¥µ¥¦¥ó¥É¥«¡¼¥É¤È¤Î¥Ç¡¼¥¿¤Î¤ä¤ê¤È¤ê¤Î¤¿¤á¤Ë DMA ¥Ð¥Ã¥Õ¥¡¤¬ÍÑ°Õ¤µ¤ì¤Æ¤¤¤Þ¤¹¡£¤½¤·¤Æ¤³¤Î DMA ¥Ð¥Ã¥Õ¥¡¤Ï fragment ¤È¸Æ¤Ð¤ì¤ëñ°Ì¤Çʬ³ä´ÉÍý¤µ¤ì¤Æ¤¤¤Þ¤¹ ( ¿Þ 1 )¡£

--- ¿Þ 1 ---
005fragment.jpg

¥¢¥Ë¥á¡¼¥·¥ç¥ó¤ò¹Ô¤¦Íͤʥ¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ç¤Ï¤·¤Ð¤·¤Ð ( ¤È¤¤¤¦¤«¤Û¤È¤ó¤É ) ¥À¥Ö¥ë¥Ð¥Ã¥Õ¥¡¥ê¥ó¥°¤È¤¤¤¦¼êË¡¤ò»È¤¤¤Þ¤¹¡£¤³¤ì¤ÈƱ¤¸Íͤʤâ¤Î¤Ç¡¢°ì¤Ä¤Î fragment ¤¬¥Ç¥Ð¥¤¥¹¤È¤Î¤ä¤ê¤È¤ê¤Ç¥í¥Ã¥¯¤µ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ë¤Ï¾¤Î fragment ¤ò¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤È¤Î¤ä¤ê¤È¤ê¤Ë»È¤¦¤È¤¤¤¦»ÅÁȤߤòÄ󶡤·¤Æ¤¯¤ì¤ë¤â¤Î¤Ç¤¹¡£

¥À¥Ö¥ë¥Ð¥Ã¥Õ¥¡¥ê¥ó¥°¤Ç¤Ï¥Ð¥Ã¥Õ¥¡¤Ï 2 ¤Ä¤·¤«»È¤¤¤Þ¤»¤ó¤¬¡¢fragment ¤ÏÊ£¿ô ( ¤â¤Á¤í¤ó 2 ¤Ä¤Î¾ì¹ç¤â¤¢¤êÆÀ¤ë ) ÍÑ°Õ¤µ¤ì¤Þ¤¹¡£¤³¤ì¤Ï¡¢¥Ð¥Ã¥Õ¥¡Îΰè¤ÏÂ礭¤¯¤·¤¿¤¤¤±¤ì¤É¤â¡¢¥Ç¥Ð¥¤¥¹¤È¤Î¤ä¤ê¤È¤ê¤Ç¥í¥Ã¥¯¤µ¤ì¤ë»þ´Ö¤¬Ä¹¤¤¤ÈÌäÂ꤬À¸¤¸¤ë¤È¤¤¤¦ÅÀ¤ò²ò¾Ã¤¹¤ë¤¿¤á¤Î¤â¤Î¤Ç¤¹¡£¥í¥Ã¥¯¤µ¤ì¤ëÎΰè¤Ï¾®¤µ¤¯¤¹¤ë¤±¤ì¤É¤â¡¢¥Ð¥Ã¥Õ¥¡¤È¤·¤Æ¤ÎÁíÎΰè¤ÏÂ礭¤¤¤è¤È¤¤¤¦Ìõ¤Ç¤¹¡£

Ï¿²»¡¢ºÆÀ¸»þ¤Ë¤Ï¤³¤Î fragment ¤Ë´Ø¤·¤Æ°Ê²¼¤ÎÃí°ÕÅÀ¤¬ (¼ç¤Ë) ¤¢¤ê¤Þ¤¹¡£

  1. write() ¤Ç¥Ç¡¼¥¿¤ò½ñ¤­¹þ¤ó¤Ç¤â¡¢´°Á´¤ËËþ¤¿¤µ¤ì¤¿ fragment ¤Î¥Ç¡¼¥¿¤·¤«ºÆÀ¸¤µ¤ì¤Ê¤¤
  2. Á´¤Æ¤Î fragment ¤¬Ëä¤Þ¤Ã¤Æ¤¤¤Æ¥Ð¥Ã¥Õ¥¡¤Ë¶õ¤­¤¬Ìµ¤¤¤È write() ¤¬¥Ö¥í¥Ã¥¯¤¹¤ë
  3. ¥µ¥ó¥×¥ê¥ó¥°¤·¤¿¥Ç¡¼¥¿¤Ç´°Á´¤ËËþ¤¿¤µ¤ì¤¿ fragment ¤¬Ìµ¤¤¤È read() ¤¬¥Ö¥í¥Ã¥¯¤¹¤ë
    ( 1 byte ¤À¤±Æɤߤ¿¤¤¾ì¹ç¤Ç¤â )

ºÆÀ¸»þ¤Ë¤Ï fragment ñ°Ì¤Ç½ñ¤­¹þ¤àÊý¤¬¤¹¤°¤ËºÆÀ¸¤µ¤ì¤ë¤Î¤ÇÎɤ¤¤Ç¤·¤ç¤¦¡£fragment ¤Î°ìÉô¤Ë¥Ç¡¼¥¿¤¬³ÊǼ¤µ¤ì¤Æ¤¤¤ë¾õÂ֤Ǥϡ¢Â³¤±¤Æ½ñ¤­¹þ¤à¤«¥Ç¥Ð¥¤¥¹¤ò close() ¤·¤Ê¤¤¤È²»¤ÏºÆÀ¸¤µ¤ì¤Þ¤»¤ó¡£ioctl SNDCTL_DSP_SYNC ( ¤â¤·¤¯¤Ï SOUND_PCM_SYNC¡¢SOUND_PCM_SYNC ¤Ï SNDCTL_DSP_SYNC ¤Î¥¨¥¤¥ê¥¢¥¹ ) ¥³¥Þ¥ó¥É¤ò¼Â¹Ô¤¹¤ë¤È¡¢write() ¤Ç½ñ¤«¤ì¤¿Á´¤Æ¤Î¥Ç¡¼¥¿¤¬ºÆÀ¸¤µ¤ì¤ë¤Þ¤ÇÂÔ¤Á¤Þ¤¹ ( ioctl() ¤¬¥Ö¥í¥Ã¥¯¤¹¤ë )¡£¤½¤Î¸å¥Ç¥Ð¥¤¥¹¤Ï½é´ü²½¤µ¤ì¤Þ¤¹¡£

ioctl( fd, SNDCTL_DSP_SYNC, 0 );

¥µ¥ó¥×¥ê¥ó¥°¥Ñ¥é¥á¡¼¥¿¤òÊѤ¨¤¿¤¤¾ì¹ç¤äÏ¿²» / ºÆÀ¸¥â¡¼¥É¤òÀÚÂؤ¨¤¿¤¤¾ì¹ç¤Ë¤Ï¡¢¤³¤Î ioctl SNDCTL_DSP_SYNC ¥³¥Þ¥ó¥É¤â¤·¤¯¤Ï ioctl SNDCTL_DSP_RESET ¥³¥Þ¥ó¥É¤ò¼Â¹Ô¤·¤Þ¤¹¡£¤·¤«¤·¡¢¤³¤ì¤é¤Î¥³¥Þ¥ó¥É¤ò¼Â¹Ô¤¹¤ë¤è¤ê¤Ï¥Ç¥Ð¥¤¥¹¤òºÆ open() ¤¹¤ëÊý¤¬Ë¾¤Þ¤·¤¤¤È OSS ¥×¥í¥°¥é¥Þ¡¼¥º¥¬¥¤¥É¤Ë¤Ïµ­½Ò¤µ¤ì¤Æ¤¤¤Þ¤¹¡£

SNDCTL_DSP_SYNC ¤È»÷¤¿¤è¤¦¤Ê¥³¥Þ¥ó¥É¤Ë ioctl SNDCTL_DSP_POST ( ¤â¤·¤¯¤Ï SOUND_PCM_POST ) ¥³¥Þ¥ó¥É¤¬¤¢¤ê¤Þ¤¹¡£

ioctl( fd, SNDCTL_DSP_POST, 0 );

¤³¤ì¤Ï¡¢¼¡¤Î¥Ç¡¼¥¿½ñ¤­¹þ¤ß¤Þ¤Ç´Ö¤¬¤¢¤ë¤³¤È¤ò¥É¥é¥¤¥Ð¤ËÄÌÃΤ¹¤ë¥³¥Þ¥ó¥É¤Ç¤¹¡£¤³¤ì¤ò¼õ¤±¤ë¤È»Ä¤Ã¤Æ¤¤¤ë²»¤¬ºÆÀ¸¤µ¤ì¤Þ¤¹¤¬¡¢SNDCTL_DSP_SYNC ¤È°Û¤Ê¤ê ioctl() ¤Ï¥Ö¥í¥Ã¥¯¤·¤Þ¤»¤ó¡£

¡û fragment ¤Î¥µ¥¤¥º¤ò¼èÆÀ¤¹¤ë

¸½ºß¤Î fragment ¤Î¥µ¥¤¥º¤Ï¡¢ioctl SNDCTL_DSP_GETBLKSIZE ¥³¥Þ¥ó¥É¤Ç¼èÆÀ¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£

int fragsize;
ioctl( fd, SNDCTL_DSP_GETBLKSIZE, &fragsize );

Âè 3 °ú¿ô¤Ë»ØÄꤷ¤¿ÊÑ¿ô¤Ë fragment ¤Î¥µ¥¤¥º¤¬³ÊǼ¤µ¤ì¤Þ¤¹ ( LECTURE 3 /dev/dsp ¤Îµ¡Ç½¤òÄ´¤Ù¤ë ¤Ç¤Ïñ¤Ë¥Ð¥Ã¥Õ¥¡¥µ¥¤¥º¤È½ñ¤¤¤Æ¤Þ¤·¤¿ )¡£¤³¤Î fragment ¥µ¥¤¥º¤Îñ°Ì¤ÇÆþ½ÐÎϤò¹Ô¤¦¤Î¤¬´ðËܤȤʤê¤Þ¤¹¡£

¤³¤Î ioctl() ¥³¥Þ¥ó¥É¤òȯ¹Ô¤¹¤ë¤È¡¢¤Þ¤À fragment ¥µ¥¤¥º¤¬·×»»¤µ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï´û¤ËÀßÄꤵ¤ì¤Æ¤¤¤ë¥µ¥ó¥×¥ê¥ó¥°¥Ñ¥é¥á¡¼¥¿¤ò»È¤Ã¤Æ fragment ¤Î¥µ¥¤¥º¤¬·×»»¤µ¤ì¤ë¤é¤·¤¤¤Ç¤¹ ( OSS ¥×¥í¥°¥é¥Þ¡¼¥º¥¬¥¤¥É¤è¤ê )¡£¤è¤Ã¤Æ¡¢¤³¤Î¥³¥Þ¥ó¥É¤òȯ¹Ô¤¹¤ëÁ°¤Ë¥µ¥ó¥×¥ê¥ó¥°¥Ñ¥é¥á¡¼¥¿¤òÀßÄꤷ¤¿¤ê¡¢É¬Íפʤé¤Ð fragment ¥µ¥¤¥º¤ò»ØÄꤹ¤Ù¤­¤À¤È½ñ¤«¤ì¤Æ¤¤¤Þ¤¹¡£

¤Þ¤¿¡¢¤³¤Î¥³¥Þ¥ó¥É¤Ï¥µ¥ó¥×¥ê¥ó¥°¥Ñ¥é¥á¡¼¥¿¤ò»È¤Ã¤¿²¿¤é¤«¤ÎºÇŬ²½¤ò¹Ô¤¦¤Î¤Ç¡¢read() / write() ¤ò¹Ô¤¦Á°¤ÎºÇ¸å¤Î ioctl() ¤Ë¤¹¤Ù¤­¤À¤È¤â½ñ¤«¤ì¤Æ¤¤¤Þ¤¹ ( ¤³¤Î¥³¥Þ¥ó¥É¤òȯ¹Ô¤¹¤ë¤Ê¤é¤ÐºÇ¸å¤Ë¤·¤í¡¢¤È¤¤¤¦°ÕÌ£¤À¤È»×¤¤¤Þ¤¹ )¡£

¡û fragment ¤Î¥µ¥¤¥º¤ò»ØÄꤹ¤ë

¥²¡¼¥à¤Î¸ú²Ì²»¤Ê¤É¤ÎÍͤËû¤¤²»¤òºÆÀ¸¤¹¤ëÍͤʾì¹ç¡¢¥Ç¥Õ¥©¥ë¥È¤Î fragment ¥µ¥¤¥º¤Ç¤ÏÂ礭¤¹¤®¤Æ "²»¤¬½Ð¤Ê¤¤¡¼" ¤Ê¤É¤È¤¤¤¦¤³¤È¤Ë¤Ê¤ë²ÄǽÀ­¤¬¤¢¤ê¤Þ¤¹¡£¤³¤ÎÍͤʾì¹ç¤Ë¤Ï¡¢fragment ¤Î¥µ¥¤¥º¤ò»ØÄꤹ¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹ ( ɬ¤º»ØÄêÄ̤ê¤Ë¤Ê¤ë¤È¤Ï¸Â¤é¤Ê¤¤¤Î¤Ç¤¹¤¬ )¡£

fragment ¤Î¥µ¥¤¥º¤ò»ØÄꤹ¤ë¤Ë¤Ï¡¢ioctl SNDCTL_DSP_SETFRAGMENT ¥³¥Þ¥ó¥É¤ò»È¤¤¤Þ¤¹¡£

int arg = 0xMMMMSSSS;
ioctl( fd, SNDCTL_DSP_SETFRAGMENT, &arg );

arg = 0xMMMMSSSS ¤È¤Ê¤Ã¤Æ¤¤¤Þ¤¹¤¬¡¢SSSS ¤Ç fragment ¤Î¥µ¥¤¥º¤ò»ØÄꤷ¤Þ¤¹¡£2^SSSS ¤¬ fragment ¤Î¥µ¥¤¥º¤Ë¤Ê¤ê¤Þ¤¹ ( 2 ¤Î¶Ò¾è )¡£SSSS ¤ÎºÇ¾®ÃÍ¤Ï 4 ( 2^4 = 16 ¥Ð¥¤¥È )¤Ç¡¢ºÇÂçÃͤÏÁí¥Ð¥Ã¥Õ¥¡¥µ¥¤¥º¤Î 1/2 ¤Ç¤¹¡£¤È¤¤¤Ã¤Æ¤âÁí¥Ð¥Ã¥Õ¥¡¥µ¥¤¥º¤ò¤É¤¦¤ä¤Ã¤Æ¼èÆÀ¤¹¤ë¤Î¤«¸½»þÅÀ¤ÇËͤÏʬ¤«¤Ã¤Æ¤¤¤Þ¤»¤ó m(__)m¡£

MMMM ¤Ï fragment ¤ÎºÇÂç¿ô¤ò»ØÄꤷ¤Þ¤¹¡£MMMM ¤ÎºÇ¾®ÃÍ¤Ï 2 ¤Ç¡¢ºÇÂçÃͤϥǥХ¤¥¹ÍѤ˳ÎÊݤǤ­¤ë¥Ð¥Ã¥Õ¥¡¤ÎÂ礭¤µ¤Ë¤è¤ë¤È¤À¤± OSS ¥×¥í¥°¥é¥Þ¡¼¥º¥¬¥¤¥É¤Ë¤Ï½ñ¤«¤ì¤Æ¤¤¤Þ¤¹¡£¡£¡£¤Î¤Ï¤º¤Ê¤ó¤Ç¤¹¤¬¡¢¼«Ê¬¤Î´Ä¶­¤Ç¼Â¸³¤·¤Æ¤ß¤ë¤È MMMM ¤è¤ê 1 ¸ÄÂ礭¤¯¤Ê¤Ã¤Æ¤ë¡£¡£¡£¡©¤¦¡¼¤ó¡¢¤³¤Ã¤Á¤¬»ÅÍͤʤΤ«¤â¡£¡£¡£¤¹¤¤¤Þ¤»¤ó¡¢¤ß¤Ê¤µ¤ó¼Â¸³¤·¤Æ¸«¤Æ²¼¤µ¤¤ m(__)m¡£¤Á¤Ê¤ß¤ËÆäËÀ©¸Â¤òÀߤ±¤Ê¤¤¾ì¹ç¤Ï 0x7fff ¤òÀßÄꤷ¤Æ²¼¤µ¤¤¡£

¤³¤Î ioctl() ¤ò¼Â¹Ô¤·¤¿¤«¤é¤È¤¤¤Ã¤Æ¡¢É¬¤º¤·¤â˾¤ßÄ̤ê¤Î fragment ¥µ¥¤¥º¤¬ÆÀ¤é¤ì¤ë¤ï¤±¤Ç¤Ï¤Ê¤¤¤³¤È¤ËÃí°Õ¤·¤Æ²¼¤µ¤¤¡£¥Ç¥Ð¥¤¥¹¤Ë¤è¤Ã¤Æ¤Ï¸ÇÄê¤À¤Ã¤¿¤ê¡¢Á´¤¯Æ±¤¸¥µ¥¤¥º¤Ç¤ÏÀßÄê¤Ç¤­¤Ê¤«¤Ã¤¿¤ê¤·¤Þ¤¹¡£¤è¤Ã¤Æ¡¢¤³¤Î¸å ioctl SNDCTL_DSP_GETBLKSIZE ¥³¥Þ¥ó¥É¤ò»È¤Ã¤Æ¼ÂºÝ¤ËÀßÄꤵ¤ì¤¿ fragment ¥µ¥¤¥º¤ò¥Á¥§¥Ã¥¯¤·¤Æ²¼¤µ¤¤¡£ioctl SNDCTL_DSP_SETFRAGMENT ¥³¥Þ¥ó¥É¤ÎÂè 3 °ú¿ô¤Ë¤Ï°ÕÌ£¤Î¤¢¤ëÃͤÏÊ֤äÆÍè¤Þ¤»¤ó¡£

ioctl SNDCTL_DSP_SETFRAGMENT ¥³¥Þ¥ó¥É¤Ï open() ľ¸å¡¢Â¾¤Î ioctl() ¤è¤êÁ°¤Ë¼Â¹Ô¤·¤Ê¤¤¤È¤¤¤±¤Ê¤¤ÍͤǤ¹¡£¤Þ¤¿¡¢¤â¤¦°ìÅÙÀßÄꤹ¤ëÍͤʾì¹ç¤Ï°ìÅ٥ǥХ¤¥¹¤ò close() ¤·¤ÆºÆ open() ¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¤È OSS ¥×¥í¥°¥é¥Þ¡¼¥º¥¬¥¤¥É¤Ë½ñ¤«¤ì¤Æ¤¤¤Þ¤¹¡£

¤Ê¤ª¡¢Èó¾ï¤Ë¾®¤µ¤Ê fragment ¥µ¥¤¥º¤ò»ØÄꤷ¤¿¾ì¹ç¡¢ºÆÀ¸²»¤Ë¥Î¥¤¥º¤¬Æþ¤ë¤Ê¤É¤Î¸½¾Ý¤¬µ¯¤­¤Æ¤·¤Þ¤¤¤Þ¤¹ ( write() ¤Ç¤Î½ñ¤­¹þ¤ß¤¬Äɤ¤¤Ä¤«¤Ê¤¤ )¡£¥æ¡¼¥¶¤«¤éľÀÜ»ØÄꤵ¤ì¤ë¤Î¤Ç¤Ê¤¤¸Â¤ê¡¢256 ¥Ð¥¤¥È°Ê²¼¤Î fragment ¥µ¥¤¥º¤Ï¤ª´«¤á¤Ç¤­¤Ê¤¤¤½¤¦¤Ç¤¹ ( OSS ¥×¥í¥°¥é¥Þ¡¼¥º¥¬¥¤¥É¤è¤ê )¡£·Ð¸³¤È¤·¤Æ¤Ï¡¢¤½¤ó¤Ê¤Ë¾®¤µ¤¯¤·¤Ê¤¤¤È¤¤¤±¤Ê¤¤¾õ¶·¤Ï¤¢¤ó¤Þ¤ê̵¤¤¤È»×¤¤¤Þ¤¹¡£

¡û ¥Ö¥í¥Ã¥¯¤·¤Ê¤¤Æþ½ÐÎÏ ( read() / write() )

¥ê¥¢¥ë¥¿¥¤¥à ( ¤Ë¤·¤¿¤¤ ) ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Î¾ì¹ç¡¢read() ¤ä write() ¼Â¹Ô»þ¤Ë¥Ö¥í¥Ã¥¯¤µ¤ì¤Æ¤·¤Þ¤¦¤ÈÈó¾ï¤Ëº¤¤ê¤Þ¤¹¡£UNIX ¤Ç¤Ï¡¢Èó¥Ö¥í¥Ã¥¯½èÍý¤Î¤¿¤á¤Ë select() ¥·¥¹¥Æ¥à¥³¡¼¥ë¤¬Îɤ¯»È¤ï¤ì¤Þ¤¹¡£

select() ¤Ç¤Ï¡¢¥Ö¥í¥Ã¥¯¤»¤º¤ËÆɤ߽ñ¤­¤¬²Äǽ¤Ê¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤òÄ´¤Ù¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£¤·¤«¤·¡¢²¾¤Ë¥Ö¥í¥Ã¥¯¤»¤º¤Ë½ñ¤­¹þ¤à¤³¤È¤¬¤Ç¤­¤ë¥Ð¥¤¥È¿ô¤¬ 1 ¥Ð¥¤¥È¤Ç¤¢¤Ã¤¿¾ì¹ç¡¢fragment ¥µ¥¤¥º¤Î½ñ¤­¹þ¤ß¤ò¹Ô¤¦¤È¤ä¤Ï¤ê¥Ö¥í¥Ã¥¯¤·¤Æ¤·¤Þ¤¤¤Þ¤¹ ( fragment ¥µ¥¤¥º¤¬ 1 ¥Ð¥¤¥È¤¸¤ã¤Ê¤«¤Ã¤¿¤é¤Ç¤¹¤è )¡£

¤³¤Î¾ì¹ç¡¢¥Ö¥í¥Ã¥¯¤»¤º¤ËÆɤ߽ñ¤­¤Ç¤­¤ë fragment ¤Î¥µ¥¤¥º¤ò¤¢¤é¤«¤¸¤áÃΤ뤳¤È¤¬¤Ç¤­¤ë¤ÈÈó¾ï¤ËÊØÍø¤Ç¤¹¡£¤³¤ÎÌÜŪ¤Î¤¿¤á ( ¡© ) ¤Ë SNDCTL_DSP_GETISPACE ( ¤â¤·¤¯¤Ï SOUND_PCM_GETISPACE )¡¢¤ª¤è¤Ó SNDCTL_DSP_GETOSPACE ( ¤â¤·¤¯¤Ï SOUND_PCM_GETOSPACE ) ¤È¤¤¤¦ 2 ¤Ä¤Î ioctl() ¥³¥Þ¥ó¥É¤¬Â¸ºß¤·¤Þ¤¹¡£

audio_buf_info buf;
ioctl( fd, SNDCTL_DSP_GETISPACE, &buf );
ioctl( fd, SNDCTL_DSP_GETOSPACE, &buf );

SNDCTL_DSP_GETISPACE ¤ÏÆþÎÏÍÑ¡¢SNDCTL_DSP_GETOSPACE ¤Ï½ÐÎÏÍѥХåե¡¤Î¾ðÊó¤ò¼èÆÀ¤·¤Þ¤¹¡£¼èÆÀ¤·¤¿¾ðÊó¤Ï¡¢Âè 3 °ú¿ô¤ËÀßÄꤷ¤¿ audio_buf_info ¹½Â¤ÂÎÊÑ¿ô¤Ë³ÊǼ¤µ¤ì¤Þ¤¹¡£audio_buf_info ¹½Â¤ÂÎ¤Ï <linux/soundcard.h> ¤ÇÄêµÁ¤µ¤ì¤Æ¤ª¤ê¡¢°Ê²¼¤Î¥á¥ó¥Ð¤òÊÝ»ý¤·¤Æ¤¤¤Þ¤¹¡£

  • int fragments

    ¥Ö¥í¥Ã¥¯¤»¤º¤ËÆɤ߽ñ¤­¤Ç¤­¤ë fragment ¤Î¿ô¡£read() ¤ä write() ¤Ë¤ª¤¤¤Æ fragment ¥µ¥¤¥ºÃ±°Ì¤ÇÆɤ߽ñ¤­¤·¤Æ¤¤¤ë¾ì¹ç¤Ë¸Â¤Ã¤Æ¿®Íê¤Ç¤­¤ë

  • int fragstotal

    ¥Ð¥Ã¥Õ¥¡ÍѤ˳ÎÊݤµ¤ì¤Æ¤¤¤ë fragment ¤ÎÁí¿ô

  • int fragsize

    fragment ¤Î¥µ¥¤¥º¡£ioctl SNDCTL_DSP_GETBLKSIZE ¤ÇÆÀ¤é¤ì¤ëÃͤÈƱ¤¸

  • int bytes

    ¥Ö¥í¥Ã¥¯¤»¤º¤ËÆɤ߽ñ¤­¤Ç¤­¤ë¥Ð¥¤¥È¿ô

select() ¥·¥¹¥Æ¥à¥³¡¼¥ë¤«¤éÌá¤Ã¤ÆÍ褿¸å¤Ë¤³¤ì¤é¤Î ioctl() ¥³¥Þ¥ó¥É¤ò»È¤Ã¤Æ¡¢¥Ö¥í¥Ã¥¯¤»¤º¤ËÆɤ߽ñ¤­¤Ç¤­¤ë¼ÂºÝ¤Î fragment ¤Î¿ô¤ò¼èÆÀ¤¹¤ì¤Ð read() ¤ä write() ¤Ç¥Ö¥í¥Ã¥¯¤»¤º¤ËºÑ¤ß¤Þ¤¹¡ª