LECTURE 3 /dev/dsp ¤Îµ¡Ç½¤òÄ´¤Ù¤ë

¡û ¤Ï¤¸¤á¤Ë

LECTURE 1 ¤Ç¤Ï¡¢/dev/dsp ¤ËÂФ·¤Æ½ñ¤­¹þ¤ß¤ò¹Ô¤¦¤³¤È¤Ç¥µ¥¦¥ó¥É¤òºÆÀ¸¤¹¤ëÊýË¡¤òÀâÌÀ¤·¤Þ¤·¤¿¡£¤½¤ÎºÝ¡¢¥µ¥¦¥ó¥É¥Õ¥©¡¼¥Þ¥Ã¥È¤Ï AFMT_S16_LE ¤ò»ØÄꤷ¤Þ¤·¤¿¤¬¼ÂºÝ¤ËÀßÄꤵ¤ì¤¿ÃͤϳÎǧ¤·¤Æ¤¤¤Þ¤»¤ó¡£»ÈÍѤ·¤Æ¤¤¤ë¥É¥é¥¤¥Ð ¡Ê ¤ª¤è¤Ó¥µ¥¦¥ó¥É¥«¡¼¥É ) ¤¬ AFMT_S16_LE ¤È¤¤¤¦¥Õ¥©¡¼¥Þ¥Ã¥È¤ò¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤Ê¤¤¤«¤â¤·¤ì¤Þ¤»¤ó¡£

¼Â¹Ô»þ¤ËÂн褹¤ë¾ì¹ç¤Ï ioctl() ¤ÎÂè 3 °ú¿ô¤ÎÃͤòÄ´¤Ù¤ì¤ÐÎɤ¤¤Ç¤¹¤¬¡¢¥µ¥¦¥ó¥É¥Õ¥©¡¼¥Þ¥Ã¥È°Ê³°¤ÎÍÍ¡¹¤Êµ¡Ç½¤Ë¤Ä¤¤¤Æ¡¢/dev/dsp ¤¬¤É¤Î¤è¤¦¤Êµ¡Ç½¤ò¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤ë¤Î¤«¤¢¤é¤«¤¸¤áÃΤ뤳¤È¤¬¤Ç¤­¤ë¤ÈÊØÍø¤Ç¤¹¡£

¤³¤³¤Ç¤Ï¡¢/dev/dsp ¤ËÀßÄꤵ¤ì¤Æ¤¤¤ë¥Ñ¥é¥á¡¼¥¿¤ä¡¢¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤ëµ¡Ç½¤òÄ´¤Ù¤ëÊýË¡¤Ë¤Ä¤¤¤ÆÀâÌÀ¤·¤Þ¤¹¡£

¡û ¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à

/dev/dsp ¤ËÀßÄꤵ¤ì¤Æ¤¤¤ë¥Ñ¥é¥á¡¼¥¿¡¢¤ª¤è¤Ó¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤ëµ¡Ç½¾ðÊó¤ò¼èÆÀ¤·¤Æɽ¼¨¤¹¤ë¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à dsptest.c ¤Ç¤¹¡£¤Ï¤¸¤á¤Ë ¤Î¥Ú¡¼¥¸¤«¤é¡¢Á´¤Æ¤Î¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤ò¸Ç¤á¤¿ tar ¥Ü¡¼¥ë¤ò¥À¥¦¥ó¥í¡¼¥É¤¹¤ë¤³¤È¤â¤Ç¤­¤Þ¤¹¡£

gcc -o dsptest dsptest.c

¤È¤·¤Æ¥³¥ó¥Ñ¥¤¥ë¤·¤Þ¤¹¡£¥³¥ó¥Ñ¥¤¥ë¥ª¥×¥·¥ç¥ó¤Ï³Æ¼«¤Î´Ä¶­¤Ê¤É¤Ë±þ¤¸¤Æ½¤Àµ¤·¤Æ²¼¤µ¤¤¡£sound.c ¤Ç¤Ï¿ô³Ø´Ø¿ô¤ò»ÈÍѤ·¤Æ¤¤¤¿¤¿¤á -lm ¥ª¥×¥·¥ç¥ó¤òɬÍפȤ·¤Þ¤·¤¿¤¬¡¢dsptest.c ¤Ç¤ÏÉÔÍפǤ¹¡£¤Ê¤ª¡¢¼«Ê¬¤Î´Ä¶­ ( Sound Blaster Live! + ¥«¡¼¥Í¥ë 2.2.20 ÉÕ°¤Î¥É¥é¥¤¥Ð ) ¤Ç¼Â¹Ô¤¹¤ë¤È°Ê²¼¤Îɽ¼¨¤Ë¤Ê¤ê¤Þ¤·¤¿¡£


Sampling rate : 8000 Hz
Channels      : 1
Sample size   : 16 bits
Block size    : 2048 bytes

Supported formats
  signed 16 bit, little-endian ( default )

DSP capabilities
  revision    : 0
  duplex      : ¡û
  realtime    : ¡û
  batch       : ¡ß
  coprocessor : ¡û
  trigger     : ¡û
  mmap        : ¡û

--- dsptest.c ---

    1	#include <fcntl.h>
    2	#include <linux/soundcard.h>
    3	#include <stdio.h>
    4	#include <sys/ioctl.h>
    5	#include <unistd.h>
    6	
    7	
    8	static int dsp_parameters( int fd );
    9	static int dsp_supported_format( int fd );
   10	static int dsp_capabilities( int fd );
   11	
   12	
   13	int 
   14	main( void )
   15	{
   16		int fd;
   17	
   18		if ( ( fd = open( "/dev/dsp", O_RDONLY ) ) == -1 ) {
   19			perror( "open()" );
   20			return 1;
   21		}
   22	
   23		/* /dev/dsp ¤Î¥Ç¥Õ¥©¥ë¥È¥Ñ¥é¥á¡¼¥¿¤ò¼èÆÀ */
   24		if ( dsp_parameters( fd ) == -1 ) {
   25			perror( "dsp_parameters() failed\n" );
   26			close( fd );
   27			return 1;
   28		}
   29	
   30		/* /dev/dsp ¤Ç¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¥Õ¥©¡¼¥Þ¥Ã¥È¾ðÊó¤ò¼èÆÀ */
   31		if ( dsp_supported_format( fd ) == -1 ) {
   32			perror( "supported_format() failed\n" );
   33			close( fd );
   34			return 1;
   35		}
   36	
   37		/* /dev/dsp ¤Ç¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë DSP µ¡Ç½¾ðÊó¤ò¼èÆÀ */
   38		if ( dsp_capabilities( fd ) == -1 ) {
   39			perror( "dsp_capabilities() failed\n" );
   40			close( fd );
   41			return 1;
   42		}
   43	
   44		close( fd );
   45		return 0;
   46	}
   47	
   48	
   49	/*
   50	 * /dev/dsp ¤Î¥Ç¥Õ¥©¥ë¥È¥Ñ¥é¥á¡¼¥¿¤ò¼èÆÀ
   51	 */
   52	static int 
   53	dsp_parameters( int fd )
   54	{
   55		int rate;
   56		int channels;
   57		int bits;
   58		int blksize;
   59	
   60	
   61		/* ¥µ¥ó¥×¥ê¥ó¥°¥ì¡¼¥ÈÃͤò¼èÆÀ */
   62		if ( ioctl( fd, SOUND_PCM_READ_RATE, &rate ) == -1 ) {
   63			perror( "ioctl( SOUND_PCM_READ_RATE )" );
   64			return -1;
   65		}
   66	
   67		/* ¥Á¥ã¥ó¥Í¥ë¿ô¤ò¼èÆÀ */
   68		if ( ioctl( fd, SOUND_PCM_READ_CHANNELS, &channels ) == -1 ) {
   69			perror( "ioctl( SOUND_PCM_READ_CHANNELS )" );
   70			return -1;
   71		}
   72	
   73		/* Î̻Ҳ½¥Ó¥Ã¥È¿ô¤ò¼èÆÀ */
   74		if ( ioctl( fd, SOUND_PCM_READ_BITS, &bits ) == -1 ) {
   75			perror( "ioctl( SOUND_PCM_READ_BITS )" );
   76			return -1;
   77		}
   78	
   79		/* ¥É¥é¥¤¥Ð¤¬ÆâÉô¤Ë»ý¤Ã¤Æ¤¤¤ë¥Ð¥Ã¥Õ¥¡¤Î¥Ö¥í¥Ã¥¯¥µ¥¤¥º¤ò¼èÆÀ */
   80		if ( ioctl( fd, SNDCTL_DSP_GETBLKSIZE, &blksize ) == -1 ) {
   81			perror( "ioctl( SNDCTL_DSP_GETBLKSIZE )" );
   82			return -1;
   83		}
   84	
   85		printf( "\n" );
   86		printf( "Sampling rate : %d Hz\n",    rate );
   87		printf( "Channels      : %d\n",       channels );
   88		printf( "Sample size   : %d bits\n",  bits );
   89		printf( "Block size    : %d bytes\n", blksize );
   90		printf( "\n" );
   91	
   92		return 0;
   93	}
   94	
   95	
   96	/*
   97	 * /dev/dsp ¤Î¥Ç¥Õ¥©¥ë¥È¤Î¥µ¥¦¥ó¥É¥Õ¥©¡¼¥Þ¥Ã¥È¡¢¤ª¤è¤Ó
   98	 * ¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¥µ¥¦¥ó¥É¥Õ¥©¡¼¥Þ¥Ã¥È¤òÄ´¤Ù¤ë¡£
   99	 */
  100	static int 
  101	dsp_supported_format( int fd )
  102	{
  103	/* format_table ¤ËÀßÄꤵ¤ì¤Æ¤¤¤ë¥µ¥¦¥ó¥É¥Õ¥©¡¼¥Þ¥Ã¥È¤Î¿ô */
  104	#define FORMAT_NUM 8
  105	
  106		int format_table[ FORMAT_NUM ] = {
  107			AFMT_MU_LAW,   /* mu-law */
  108			AFMT_A_LAW,    /* A-law  */
  109			AFMT_U8,       /* unsigned 8 bit */
  110			AFMT_S8,       /* signed 8 bit */
  111			AFMT_S16_LE,   /* signed 16 bit, little-endian */
  112			AFMT_S16_BE,   /* signed 16 bit, big-endian */
  113			AFMT_U16_LE,   /* unsigned 16 bit, little-endian */
  114			AFMT_U16_BE    /* unsigned 16 bit, big-endian */
  115		};
  116	
  117		char* format_msgtbl[ FORMAT_NUM ] = {
  118			"  mu-law",
  119			"  A-law",
  120			"  unsigned 8 bit",
  121			"  signed 8 bit",
  122			"  signed 16 bit, little-endian",
  123			"  signed 16 bit, big-endian",
  124			"  unsigned 16 bit, little-endian",
  125			"  unsigned 16 bit, big-endian"
  126		};
  127	
  128		int formats, default_format;
  129		int i;
  130	
  131		/* ¥Ç¥Õ¥©¥ë¥È¥Õ¥©¡¼¥Þ¥Ã¥ÈÌ䤤¹ç¤ï¤»ÍѤÎÃͤòÀßÄê */
  132		default_format = AFMT_QUERY;
  133	
  134		/* ¥Ç¥Õ¥©¥ë¥È¤Î¥µ¥¦¥ó¥É¥Õ¥©¡¼¥Þ¥Ã¥È¤ò¼èÆÀ */
  135		if ( ioctl( fd, SOUND_PCM_SETFMT, &default_format ) == -1 ) {
  136			perror( "ioctl( SOUND_PCM_SETFMT )" );
  137			return -1;
  138		}
  139	
  140		/* ¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¥Õ¥©¡¼¥Þ¥Ã¥È¤ò¼èÆÀ */
  141		if ( ioctl( fd, SOUND_PCM_GETFMTS, &formats ) == -1 ) {
  142			perror( "ioctl( SOUND_PCM_GETFMTS )" );
  143			return -1;
  144		}
  145	
  146		printf( "Supported formats\n" );
  147	
  148		/* ¼èÆÀ¤·¤¿¥Õ¥©¡¼¥Þ¥Ã¥È¾ðÊó¤ò²òÀϤ·¤Æɽ¼¨¤¹¤ë */
  149		for ( i = 0; i < FORMAT_NUM; i ++ ) {
  150			if ( formats & format_table[i] ) {
  151				printf( "%s", format_msgtbl[i] );
  152	
  153				( default_format == format_table[i] ) ?
  154					printf( " ( default )\n" ) : printf( "\n" );
  155			}
  156		}
  157	
  158		return 0;
  159	}
  160	
  161	
  162	/*
  163	 * /dev/dsp ¤Ç¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë DSP µ¡Ç½¤Ë¤Ä¤¤¤ÆÄ´¤Ù¤ë
  164	 */
  165	static int 
  166	dsp_capabilities( int fd )
  167	{
  168	/* caps_table ¤ËÀßÄꤵ¤ì¤Æ¤¤¤ëµ¡Ç½¤Î¿ô */
  169	#define CAPS_NUM 7
  170	
  171		int caps_table[ CAPS_NUM ] = {
  172			DSP_CAP_REVISION,  /* ¥Ð¡¼¥¸¥ç¥ó */
  173			DSP_CAP_DUPLEX,    /* Ï¿²»ºÆÀ¸¤òƱ»þ¤Ë¹Ô¤¨¤ë */
  174			DSP_CAP_REALTIME,  /* SNDCTL_DSP_GET[IO]PTR ¤ò»È¤Ã¤Æ¡¢ºÆÀ¸Ãæ¤Î
  175					      ¥Ð¥Ã¥Õ¥¡°ÌÃÖ¤òÀµ³Î¤ËÃΤ뤳¤È¤¬½ÐÍè¤ë */
  176			DSP_CAP_BATCH,     /* Ï¿²»ºÆÀ¸¤Ë¥í¡¼¥«¥ë¥¹¥È¡¼¥ì¥Ã¥¸¤ò»È¤¦ */
  177			DSP_CAP_COPROC,    /* codec ¤Ç¤Ï¤Ê¤¯ DSP ¥Á¥Ã¥×¤¬Â¸ºß¤·¤Æ¤¤¤ë */
  178			DSP_CAP_TRIGGER,   /* Ï¿²»ºÆÀ¸¤Î triggering ¤¬¹Ô¤¨¤ë */
  179			DSP_CAP_MMAP       /* Ï¿²»ºÆÀ¸¤Ë¥Ï¡¼¥É¥¦¥§¥¢¤Î¥Ð¥Ã¥Õ¥¡¤ò»È¤¨¤ë */
  180		};
  181	
  182		char* caps_msgtbl[ CAPS_NUM ] = {
  183			"  revision    : ",
  184			"  duplex      : ",
  185			"  realtime    : ",
  186			"  batch       : ",
  187			"  coprocessor : ",
  188			"  trigger     : ",
  189			"  mmap        : "
  190		};
  191	
  192		char* msgtbl[2] = {	"¡û", "¡ß" };
  193		int   i, caps;
  194	
  195		/* DSP µ¡Ç½¾ðÊó¤ò¼èÆÀ */
  196		if ( ioctl( fd, SNDCTL_DSP_GETCAPS, &caps ) == -1 ) {
  197			perror( "ioctl( SNDCTL_DSP_GETCAPS )" );
  198			return -1;
  199		}
  200	
  201		printf( "\nDSP capabilities\n" );
  202	
  203		/* ¼èÆÀ¤·¤¿µ¡Ç½¾ðÊó¤ò²òÀϤ·¤Æɽ¼¨¤¹¤ë */
  204		for ( i = 0; i < CAPS_NUM; i ++ ) {
  205			printf( "%s", caps_msgtbl[i] );
  206	
  207			/* ¥ê¥Ó¥¸¥ç¥ó¤À¤±Â¾¤Î¤È¼è¤ê½Ð¤·Êý¤¬°Û¤Ê¤ë */
  208			if ( i == 0 ) {
  209				printf( "%d\n", ( caps & DSP_CAP_REVISION ) );
  210			}
  211			else {
  212				( ( caps & caps_table[i] ) != 0 ) ?
  213					printf( "%s\n", msgtbl[0] ):
  214					printf( "%s\n", msgtbl[1] );
  215			}
  216		}
  217	
  218		printf( "\n" );
  219		return 0;
  220	}
  221	
  222	
  223	/* End of dsptest.c */


¡û ¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤ÎÀâÌÀ

¤Ç¤Ï¡¢¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤Ë¤Ä¤¤¤ÆÀâÌÀ¤·¤Æ¤¤¤­¤Þ¤¹¡£

  • 13 ¡Á 46 ¹ÔÌÜ ( main() )

    main() ´Ø¿ô¤Ç¤Ï¡¢³Æ¼ï¤Î¾ðÊó¤ò¼èÆÀ¤¹¤ë¤¿¤á¤Î¼«ºî´Ø¿ô¤ò¼Â¹Ô¤·¤Æ¤¤¤ë¤À¤±¤Ç¤¹¡£ ¼«ºî´Ø¿ô¤Ë¤Ä¤¤¤Æ¤³¤ì¤«¤éÀâÌÀ¤·¤Æ¤¤¤­¤Þ¤¹¡£

  • 49 ¡Á 93 ¹ÔÌÜ ( dsp_parameters() )

    dsp_parameters() ¤Ï¡¢/dev/dsp ¤Ë¸½ºßÀßÄꤵ¤ì¤Æ¤¤¤ë¥µ¥ó¥×¥ê¥ó¥°¥ì¡¼¥È¡¢¥Á¥ã¥ó¥Í¥ë¿ô¡¢ Î̻Ҳ½¥Ó¥Ã¥È¿ô¡¢¥É¥é¥¤¥ÐÆâÉô¤Î¥Ð¥Ã¥Õ¥¡¥µ¥¤¥º¤ò¼èÆÀ¤¹¤ë¤¿¤á¤Î´Ø¿ô¤Ç¤¹¡£

    • 61 ¡Á 65 ¹ÔÌÜ

      ¸½ºßÀßÄꤵ¤ì¤Æ¤¤¤ë¥µ¥ó¥×¥ê¥ó¥°¥ì¡¼¥È¤ò¼èÆÀ¤·¤Æ¤¤¤Þ¤¹¡£ioctl() ¤ÎÂè 2 °ú¿ô¤Ë SOUND_PCM_READ_RATE ¤òÀßÄꤷ¤Æ¼Â¹Ô¤¹¤ë¤È¡¢Âè 3 °ú¿ô¤Ë»ØÄꤷ¤¿ÊÑ¿ô¤Ë ¸½ºß¤Î¥µ¥ó¥×¥ê¥ó¥°¥ì¡¼¥ÈÃͤ¬ÀßÄꤵ¤ì¤Þ¤¹¡£

        int rate;
        ioctl( fd, SOUND_PCM_READ_RATE, &rate );
      
      

    • 67 ¡Á 71 ¹ÔÌÜ

      ¸½ºßÀßÄꤵ¤ì¤Æ¤¤¤ë¥Á¥ã¥ó¥Í¥ë¿ô¤ò¼èÆÀ¤·¤Æ¤¤¤Þ¤¹¡£ioctl() ¤ÎÂè 2 °ú¿ô¤Ë SOUND_PCM_READ_CHANNELS ¤òÀßÄꤷ¤Æ¼Â¹Ô¤¹¤ë¤È¡¢Âè 3 °ú¿ô¤Ë»ØÄꤷ¤¿ÊÑ¿ô¤Ë¸½ºß¤Î ¥Á¥ã¥ó¥Í¥ë¿ô¤¬ÀßÄꤵ¤ì¤Þ¤¹¡£

        int channels;
        ioctl( fd, SOUND_PCM_READ_CHANNELS, &channels );
      
      

    • 73 ¡Á 77 ¹ÔÌÜ

      ¸½ºßÀßÄꤵ¤ì¤Æ¤¤¤ëÎ̻Ҳ½¥Ó¥Ã¥È¿ô¤ò¼èÆÀ¤·¤Æ¤¤¤Þ¤¹¡£ioctl() ¤ÎÂè 2 °ú¿ô¤Ë SOUND_PCM_READ_BITS ¤òÀßÄꤷ¤Æ¼Â¹Ô¤¹¤ë¤È¡¢Âè 3 °ú¿ô¤Ë»ØÄꤷ¤¿ÊÑ¿ô¤Ë¸½ºß¤Î Î̻Ҳ½¥Ó¥Ã¥È¿ô¤¬ÀßÄꤵ¤ì¤Þ¤¹¡£

        int bits;
        ioctl( fd, SOUND_PCM_READ_BITS, &bits );
      
      

      ¤³¤³¤Þ¤Ç¤Î SOUND_PCM_READ_RATE¡¢SOUND_PCM_READ_CHANNELS¡¢ SOUND_PCM_READ_BITS ¤Ï¡¢ ¤Ï¤¸¤á¤Ë#»²¹Í¾ðÊó ¤Ç¾Ò²ð¤·¤Æ¤¤¤ë Vortex of Sound ¤«¤éÍî¤È¤·¤ÆÍ褿 au88x-1.1.2.tar.gz ¤Ç¤Ï¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¤Ç¤·¤¿( ¤³¤ì°Ê¹ß¤Î¥Ð¡¼¥¸¥ç¥ó¤Ç¤Ï¥µ¥Ý¡¼¥È¤µ¤ì¤ë¤«¤â¡©)¡£ ¥æ¡¼¥¶¶õ´Ö¤«¤éÃͤòÀßÄꤹ¤ëÊý¤Ï¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤ë¤Î¤Ë¡¢ ²¿¸Î¼èÆÀ¤¹¤ëÊý¤ò¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤Ê¤¤¤Î¤«¡¢¸Ä¿ÍŪ¤ËÆæ¤Ç¤¹¡£¡£¡£

      ¤Ê¤ª¡¢¤³¤Î¾ì¹ç ioctl() ¤¬¥¨¥é¡¼¤È¤Ê¤Ã¤Æ dsptest ¤Ï½ªÎ»¤·¤Þ¤·¤¿¡£

    • 79 ¡Á 83 ¹ÔÌÜ

      ¥µ¥¦¥ó¥É¥É¥é¥¤¥Ð¤¬¥Ç¡¼¥¿¤ÎžÁ÷¤Ë»ÈÍѤ¹¤ë¥Ð¥Ã¥Õ¥¡¥µ¥¤¥º¤ò¼èÆÀ¤·¤Æ¤¤¤Þ¤¹¡£ ioctl() ¤ÎÂè 2 °ú¿ô¤Ë SNDCTL_DSP_GETBLKSIZE ¤òÀßÄꤷ¤Æ¼Â¹Ô¤¹¤ë¤È¡¢ Âè 3 °ú¿ô¤Ë»ØÄꤷ¤¿ÊÑ¿ô¤Ë¥Ð¥Ã¥Õ¥¡¥µ¥¤¥º¤¬ÀßÄꤵ¤ì¤Þ¤¹¡£

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

  • 96 ¡Á 159 ¹ÔÌÜ ( dsp_supported_format() )

    dsp_supported_format() ¤Ï¡¢/dev/dsp ¤¬¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤ë¥µ¥¦¥ó¥É¥Õ¥©¡¼¥Þ¥Ã¥È¤òÄ´¤Ù¤ë¤¿¤á¤Î´Ø¿ô¤Ç¤¹¡£LECTURE 1 ¤Ç¾Ò²ð¤·¤¿ 8 ¸Ä¤Î¥Õ¥©¡¼¥Þ¥Ã¥È¤Ë¤Ä¤¤¤Æ¡¢¤½¤ì¤¾¤ì¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤ë¤«¤É¤¦¤«¤òÄ´¤Ù¤Æ¤¤¤Þ¤¹¡£ soundcard.h ¤ò¸«¤ë¤È¤½¤Î¾¤Î¥Õ¥©¡¼¥Þ¥Ã¥È¤âµ­ºÜ¤µ¤ì¤Æ¤¤¤Þ¤¹¤¬ dsptest.c ¤Ç¤Ï¥Á¥§¥Ã¥¯¤·¤Æ¤¤¤Þ¤»¤ó¡£

    ËÜ¥Ú¡¼¥¸¤ò½ñ¤­¾å¤²¤¿¸å¤Ëµ¤ÉÕ¤¤¤¿¤Î¤Ç¤¹¤¬¡¢¥â¥¸¥å¡¼¥ë¤Ë¤è¤ë¤Î¤«¤â¤·¤ì¤Þ¤»¤ó¤¬ /dev/dsp ¤ò O_RDONLY ¤Ç³«¤¤¤Æ¤¤¤ë¤« O_WRONLY ¤Ç³«¤¤¤Æ¤¤¤ë¤«¤Ë¤è¤Ã¤Æ¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤ë ¥Õ¥©¡¼¥Þ¥Ã¥È¤¬°Û¤Ê¤ë¾ì¹ç¤¬¤¢¤ëÍͤǤ¹¡£

    • 134 ¡Á 138 ¹ÔÌÜ

      ¤³¤³¤Ç¤Ï¤Þ¤º¡¢¥Ç¥Õ¥©¥ë¥È¤È¤·¤ÆÀßÄꤵ¤ì¤Æ¤¤¤ë¥µ¥¦¥ó¥É¥Õ¥©¡¼¥Þ¥Ã¥È¤ò¼èÆÀ¤·¤Æ¤¤¤Þ¤¹¡£ ioctl() ¤ÎÂè 2 °ú¿ô¤Ë SOUND_PCM_SETFMT ¤â¤·¤¯¤Ï SNDCTL_DSP_SETFMT ¤òÀßÄꤷ¤Þ¤¹ ( SOUND_PCM_SETFMT ¤Ï SNDCTL_DSP_SETFMT ¤Î¥¨¥¤¥ê¥¢¥¹ )¡£¤½¤·¤Æ¡¢ Âè 3 °ú¿ô¤Ë AFMT_QUERY ¤òÀßÄꤷ¤¿ÊÑ¿ô¤Î¥¢¥É¥ì¥¹¤ò»ØÄꤷ¤Æ ioctl() ¤ò¼Â¹Ô¤¹¤ë¤È¡¢ Âè 3 °ú¿ô¤Ë¥Ç¥Õ¥©¥ë¥È¤Î¥µ¥¦¥ó¥É¥Õ¥©¡¼¥Þ¥Ã¥È¤¬ÀßÄꤵ¤ì¤Þ¤¹¡£

        int default_format = AFMT_QUERY;
        ioctl( fd, SOUND_PCM_SETFMT, &default_format );
      
      

    • 140 ¡Á 144 ¹ÔÌÜ

      /dev/dsp ¤¬¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤ë¥µ¥¦¥ó¥É¥Õ¥©¡¼¥Þ¥Ã¥È¤ò¼èÆÀ¤·¤Æ¤¤¤Þ¤¹¡£ioctl() ¤ÎÂè 2 °ú¿ô¤Ë SOUND_PCM_GETFMTS ¤â¤·¤¯¤Ï SNDCTL_DSP_GETFMTS ¤òÀßÄꤷ¤Þ¤¹ ( SOUND_PCM_GETFMTS ¤Ï SNDCTL_DSP_GETFMTS ¤Î¥¨¥¤¥ê¥¢¥¹ )¡£ioctl() ¤ò¼Â¹Ô¤¹¤ë¤È¡¢ Âè 3 °ú¿ô¤Ë»ØÄꤷ¤¿ÊÑ¿ô¤Ë¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¥µ¥¦¥ó¥É¥Õ¥©¡¼¥Þ¥Ã¥È¤Î¥Ó¥Ã¥È¥Þ¥¹¥¯ ¤¬ÀßÄꤵ¤ì¤Þ¤¹¡£

        int format;
        ioctl( fd, SOUND_PCM_GETFMTS, &format );
      
      

      ¤³¤Î¥Ó¥Ã¥È¥Þ¥¹¥¯¤È³Æ¥µ¥¦¥ó¥É¥Õ¥©¡¼¥Þ¥Ã¥È ( AFMT_U8 Åù ) ¤Î¥Ó¥Ã¥ÈËè¤Î AND ±é»» ¤ò¹Ô¤Ã¤¿·ë²Ì¤¬ 1 ¤Ç¤¢¤ì¤Ð¡¢ ¤½¤Î¥Õ¥©¡¼¥Þ¥Ã¥È¤Ï¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¤È¤¤¤¦¤³¤È¤Ë¤Ê¤ê¤Þ¤¹¡£

  • 162 ¡Á 220 ¹ÔÌÜ ( dsp_capabilities() )

    dsp_capabilities() ¤Ï¡¢/dev/dsp ¤Ç¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë DSP µ¡Ç½¾ðÊó¤ò¼èÆÀ¤·¤Þ¤¹¡£

    • 171 ¡Á 180 ¹ÔÌÜ

      ¥µ¥Ý¡¼¥È¤Î̵ͭ¤òÄ´¤Ù¤ë DSP µ¡Ç½¤ò»ØÄꤷ¤Æ¤¤¤Þ¤¹¡£¤½¤ì¤¾¤ì¤ÎÆâÍƤˤĤ¤¤Æ¡¢°Ê²¼¤Ë µ­¤·¤Þ¤¹¡£

      Äê¿ô̾
      ÀâÌÀ
      DSP_CAP_REVISIONSNDCTL_DSP_GETCAPS ¤ò»È¤Ã¤¿ ioctl() ¤Ë¤è¤ë¥¢¥¯¥»¥¹ ¤Î¥Ð¡¼¥¸¥ç¥óÈÖ¹æ
      DSP_CAP_DUPLEX Ï¿²»ºÆÀ¸¤òƱ»þ¤Ë¹Ô¤¨¤ë(Á´Æó½Å)
      DSP_CAP_REALTIMESNDCTL_DSP_GETIPTR¡¢¤â¤·¤¯¤Ï SNDCTL_DSP_GETOPTR ¤ò»È¤Ã¤Æ¡¢¸½ºß¤Î½ÐÎϥХåե¡¤Ë¤ª¤±¤ë°ÌÃÖ¤òÀµ³Î¤Ë ÃΤ뤳¤È¤¬¤Ç¤­¤ë
      DSP_CAP_BATCH Ï¿²»ºÆÀ¸ÍѤΥХåե¡¤È¤·¤Æ¡¢¥í¡¼¥«¥ë¥¹¥È¡¼¥ì¥Ã¥¸¤ò »ÈÍѤ¹¤ë
      DSP_CAP_COPROC ¥½¥Õ¥È¥¦¥§¥¢¤Ë¤è¤ë CODEC ¤Ç¤Ï¤Ê¤¯¡¢DSP ¥Á¥Ã¥×¤ò ¥Ï¡¼¥É¥¦¥§¥¢¤È¤·¤Æ»ý¤Ã¤Æ¤¤¤ë
      DSP_CAP_TRIGGER Ï¿²»ºÆÀ¸¤Î¥È¥ê¥¬¡¼µ¡Ç½¤ò»È¤¦¤³¤È¤¬½ÐÍè¤ë
      DSP_CAP_MMAP ¥Ï¡¼¥É¥¦¥§¥¢¥ì¥Ù¥ë¤ÎÏ¿²»ºÆÀ¸ÍѥХåե¡¤ËľÀÜ ¥¢¥¯¥»¥¹¤¹¤ë¤³¤È¤¬½ÐÍè¤ë

    • 195 ¡Á 199 ¹ÔÌÜ

      DSP µ¡Ç½¾ðÊó¤ò¼èÆÀ¤·¤Æ¤¤¤Þ¤¹¡£iotcl() ¤ÎÂè 2 °ú¿ô¤Ë SNDCTL_DSP_GETCAPS ¤òÀßÄꤷ¤Æ ¼Â¹Ô¤¹¤ë¤È¡¢Âè 3 °ú¿ô¤Ë DSP µ¡Ç½¤Î¥Ó¥Ã¥È¥Þ¥¹¥¯¤¬ÀßÄꤵ¤ì¤Þ¤¹¡£

        int caps;
        ioctl( fd, SNDCTL_DSP_GETCAPS, &caps );
      
      

      ¤³¤Î¥Ó¥Ã¥È¥Þ¥¹¥¯¤È³Æ DSP µ¡Ç½ ( DSP_CAP_DUPLEX Åù ) ¤Î¥Ó¥Ã¥ÈËè¤Î AND ±é»»¤ò¹Ô¤Ã¤¿ ·ë²Ì¤¬ 1 ¤Ç¤¢¤ì¤Ð¡¢¤½¤Î DSP µ¡Ç½¤Ï¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¤È¤¤¤¦¤³¤È¤Ë¤Ê¤ê¤Þ¤¹¡£¤¿¤À¤· DSP_CAP_REVISION ¤ÏÆÃÊ̤ǡ¢AND ±é»»¤Î·ë²Ì¤½¤Î¤â¤Î¤¬ SNDCTL_DSP_GETCAPS ¤ò»È¤Ã¤¿ ioctl() ¤Ë¤è¤ë¥¢¥¯¥»¥¹¤Î¥Ð¡¼¥¸¥ç¥óÈÖ¹æ¤È¤Ê¤ê¤Þ¤¹¡£

      °Ê²¼ 2002/8/20 Äɵ­

      DSP_CAP_DUPLEX ¤Ë´Ø¤·¤Æ¤Ï¡¢SNDCTL_DSP_GETCAPS ¥³¥Þ¥ó¥É¤òȯ¹Ô¤¹¤ëÁ°¤Ë²¼µ­¤Î ioctl() ¥³¥Þ¥ó¥É¤òȯ¹Ô¤¹¤ë¤Ù¤­¤Ç¤¢¤ë¤È¤¤¤¦µ­½Ò¤ò OSS ¥×¥í¥°¥é¥Þ¡¼¥º¥¬¥¤¥É¤Çȯ¸«¤·¤Þ¤·¤¿¡£

        ioctl( fd, SNDCTL_DSP_SETDUPLEX, 0 );
      
      

      Á´Æó½Å¥â¡¼¥É¤¬¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ì¤Ð¤³¤Î¥³¥Þ¥ó¥É¤ÇÁ´Æó½Å¥â¡¼¥É¤Ë°Ü¹Ô¤¹¤ë¤Î¤Ç¡¢ ¤½¤Î¸å¤Ç SNDCTL_DSP_GETCAPS ¤ò»È¤Ã¤ÆÄ´¤Ù¤ë¤Ù¤­¤À¤È¤¤¤¦¤³¤È¤Ç¤·¤ç¤¦¡£¤¬¡¢ ¤¤¤¯¤Ä¤«Ä´¤Ù¤¿¥É¥é¥¤¥Ð¤Î¥³¡¼¥É¤Ç¤Ï¡¢SNDCTL_DSP_SETDUPLEX ¥³¥Þ¥ó¥É¤Î¼Â¹Ô¤¬ À®¸ù¤¹¤ë¤â¤Î¤Ï¤â¤È¤â¤È SNDCTL_DSP_GETCAPS »þ¤Ë DSP_CAP_DUPLEX ¤òÀßÄꤷ¤ÆÊÖ¤¹ÍÍ¤Ë ¤Ê¤Ã¤Æ¤¤¤ë¤ß¤¿¤¤¤Ç¤¹¡£¤â¤Á¤í¤óÁ´¤Æ¤Î¥É¥é¥¤¥Ð¤Î¥³¡¼¥É¤ò¸«¤¿¤ï¤±¤Ç¤Ï¤Ê¤¤¤Î¤Ç ¥«¡¼¥É¤È¥É¥é¥¤¥Ð¼¡Âè¤È¤¤¤¦¤³¤È¤Ë¤Ï¤Ê¤ê¤Þ¤¹¤¬¡¢ ¸Ä¿ÍŪ¤Ë¤Ï¸½¾õ¤ÇËÜÅö¤ËɬÍפʤΤ«µ¿Ìä¡£¡£¡£

      Äɵ­¤³¤³¤Þ¤Ç

dsptest.c ¤ÎÀâÌÀ¤Ï°Ê¾å¤Ç¤¹¡£¼«Ê¬¤¬»È¤Ã¤Æ¤¤¤ë¥µ¥¦¥ó¥É¥«¡¼¥É¤È¥É¥é¥¤¥Ð¤¬¤É¤ÎÍͤʵ¡Ç½¤ò»ý¤Ã¤Æ¤¤¤ë¤Î¤«¡¢¤³¤Î¥×¥í¥°¥é¥à¤ÇÄ´¤Ù¤Æ¤ß¤Þ¤·¤ç¤¦! ( Ä´¤Ù¤¿¤«¤é¤É¤¦¤È¤¤¤¦¤ï¤±¤Ç¤â¤Ê¤¤¤Ç¤¹¤¬¡£¡£¡£ )