LECTURE 10 WAVE ¥Õ¥¡¥¤¥ë¤òºÆÀ¸¤¹¤ë

¡û ¤Ï¤¸¤á¤Ë

WAVE ¥Õ¥¡¥¤¥ë¤Ï Windows ¤Çɸ½àŪ¤Ë°·¤¨¤ë¥µ¥¦¥ó¥É¥Õ¥©¡¼¥Þ¥Ã¥È¤È¤·¤ÆÅо줷¡¢¸½ºß¤Ç¤ÏÈó¾ï¤Ëͭ̾¤Ê¥Õ¥¡¥¤¥ë·Á¼°¤Ç¤¹¡£CD ¤«¤é³Ú¶Ê¤òµÛ¤¤½Ð¤¹¾ì¹ç¤â¤Þ¤º¤Ï WAVE ·Á¼°¤Ç¤¹¤è¤Í¡£

¤³¤³¤Ç¤Ï PCM ·Á¼°¤Ç²»À¼¥Ç¡¼¥¿¤¬³ÊǼ¤µ¤ì¤Æ¤¤¤ë WAVE ¥Õ¥¡¥¤¥ë¤òÆɤ߹þ¤ó¤ÇºÆÀ¸¤¹¤ë¥×¥í¥°¥é¥à¤òºîÀ®¤·¤Þ¤¹¡£

¡û WAVE ¥Õ¥¡¥¤¥ë¤Î·Á¼°

¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤ÎÁ°¤Ë¡¢WAVE ¥Õ¥¡¥¤¥ë¤Î·Á¼° ( ¥Õ¥©¡¼¥Þ¥Ã¥È ) ¤Ë¤Ä¤¤¤Æ´Êñ¤ËÀâÌÀ¤·¤Þ¤¹¡£

WAVE ¥Õ¥¡¥¤¥ë¤Ï°Ê²¼¤ÎÍͤ˹½À®¤µ¤ì¤Æ¤¤¤Þ¤¹¡£

¥ª¥Õ¥»¥Ã¥È(byte)¥µ¥¤¥º(byte)Í×ÁǤÎÀâÌÀ
0 4 ʸ»úÎó "RIFF"
4 4 ¤³¤ì¤è¤ê¸å¤Î¥Ç¡¼¥¿Ä¹
8 4 ʸ»úÎó "WAVE"
12 4 ʸ»úÎó "fmt "¡£ËöÈø¤Î¶õÇò¤ËÃí°Õ
16 4 ¥Ø¥Ã¥ÀÉô¤Î¥Ç¡¼¥¿Ä¹(°Ê¸å x ¤È¤¹¤ë)
20 x ¥Ø¥Ã¥ÀÉô
--- --- ¾ì¹ç¤Ë¤è¤Ã¤Æ¤Ï¼¡¤Î "data" ¤È¤Î´Ö¤ËÊ̥ǡ¼¥¿¤¬ÁÞÆþ¤µ¤ì¤ë¾ì¹ç¤¬¤¢¤ëÍͤǤ¹¡£ ÁÞÆþ¤µ¤ì¤ë¾ì¹ç¤Ï 4 ¥Ð¥¤¥È¤Îʸ»úÎó¡¢4 ¥Ð¥¤¥È¤Î¥Ç¡¼¥¿Ä¹¡¢¥Ç¡¼¥¿ ¤Î¥»¥Ã¥È ( ¤³¤Î¥»¥Ã¥È¤ò¥Á¥ã¥ó¥¯¤È¸Æ¤Ö ) ¤ÇÁÞÆþ¤µ¤ì¤ë¤Î¤Ç¡¢ÀèƬ 4 ¥Ð¥¤¥È¤¬ "data" ¤Ç̵¤¤¾ì¹ç¤Ï "¼¡¤Î 4 ¥Ð¥¤¥È¤ÎÃͤÀ¤±Èô¤Ð¤¹" ¤È¤¤¤¦½èÍý¤ò·«¤êÊÖ¤¹É¬Íפ¬¤¢¤ê¤Þ¤¹¡£
20+x 4 ʸ»úÎó "data"
24+x 4 ¥Ç¡¼¥¿Éô¤Î¥Ç¡¼¥¿Ä¹(°Ê¸å y ¤È¤¹¤ë)
28+x y ¥Ç¡¼¥¿Éô

¥Ø¥Ã¥ÀÉô¤Ï°Ê²¼¤ÎÍͤ˹½À®¤µ¤ì¤Æ¤¤¤Þ¤¹¡£

¥ª¥Õ¥»¥Ã¥È(byte)¥µ¥¤¥º(byte)Í×ÁǤÎÀâÌÀ
0 2 ¥Õ¥©¡¼¥Þ¥Ã¥È¤Î¼ïÎà¡£PCM ¤Î¾ì¹ç¤Ï 1 ¤Ç¡¢¤½¤ì°Ê³°¤ÏÄ´ºº¤·¤Æ¤¤¤Þ¤»¤ó m(__)m
2 2 ¥Á¥ã¥ó¥Í¥ë¿ô
4 4 ¥µ¥ó¥×¥ê¥ó¥°¼þÇÈ¿ô
8 4 1 Éô֤˻ÈÍѤ¹¤ë¥Ð¥¤¥È¿ô
122 1 ¤Ä¤Î¥µ¥ó¥×¥ë¥Ç¡¼¥¿¤Î¥Ð¥¤¥È¿ô
142 Î̻Ҳ½¥Ó¥Ã¥È¿ô ( 8 ¤« 16 )
162 ¥Ø¥Ã¥ÀÉô¹½Â¤ÂΤΥµ¥¤¥º

¤¿¤À¤·¡¢ºÇ¸å¤Î "¥Ø¥Ã¥ÀÉô¹½Â¤ÂΤΥµ¥¤¥º" ¤Ï¸ºß¤·¤Ê¤¤¾ì¹ç¤¬¤¢¤ë¤é¤·¤¤¤Î¤Ç¡¢¥Ø¥Ã¥ÀÉô¤ÎľÁ°¤Î "¥Ø¥Ã¥ÀÉô¤Î¥Ç¡¼¥¿Ä¹" ¤ò¿®ÍѤ·¤Æ²¼¤µ¤¤¡£

¥Ç¡¼¥¿Éô¤Î·Á¼°¤Ï¡¢Î̻Ҳ½¥Ó¥Ã¥È¿ô¤ª¤è¤Ó¥Á¥ã¥ó¥Í¥ë¿ô¤Ë¤è¤Ã¤ÆÊѲ½¤·¤Þ¤¹¡£8 ¥Ó¥Ã¥È¤Î¾ì¹ç¤ÏÉä¹æ̵¤·¡¢16 ¥Ó¥Ã¥È¤Î¾ì¹ç¤ÏÉä¹æÍ­¤ê¤Î¿ôÃͤǤ¹¡£

  • 8 ¥Ó¥Ã¥È 1 ¥Á¥ã¥ó¥Í¥ë

    1 ¥Ð¥¤¥È¤Î PCM ¥Ç¡¼¥¿¤¬½ç¼¡³ÊǼ¤µ¤ì¤Þ¤¹

  • 8 ¥Ó¥Ã¥È 2 ¥Á¥ã¥ó¥Í¥ë

    1 ¥Ð¥¤¥È¤Î PCM ¥Ç¡¼¥¿¤¬ "º¸±¦º¸±¦..." ¤Î½ç¤Ë³ÊǼ¤µ¤ì¤Þ¤¹

  • 16 ¥Ó¥Ã¥È 1 ¥Á¥ã¥ó¥Í¥ë

    2 ¥Ð¥¤¥È¤Î PCM ¥Ç¡¼¥¿¤¬½ç¼¡³ÊǼ¤µ¤ì¤Þ¤¹

  • 16 ¥Ó¥Ã¥È 2 ¥Á¥ã¥ó¥Í¥ë

    2 ¥Ð¥¤¥È¤Î PCM ¥Ç¡¼¥¿¤¬ "º¸±¦º¸±¦..." ¤Î½ç¤Ë³ÊǼ¤µ¤ì¤Þ¤¹

3 ¥Á¥ã¥ó¥Í¥ë°Ê¾å¤Î¾ì¹ç¤Ë¤É¤ÎÍÍ¤Ë PCM ¥Ç¡¼¥¿¤¬Ê¤֤Τ«¤Ï̤Ĵºº¤Ç¤¹ m(__)m

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

WAVE ¥Õ¥¡¥¤¥ë¤òºÆÀ¸¤¹¤ë¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à wave.c ¤Ç¤¹¡£¤Ï¤¸¤á¤Ë ¤Î¥Ú¡¼¥¸¤«¤é¡¢Á´¤Æ¤Î¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤ò¸Ç¤á¤¿ tar ¥Ü¡¼¥ë¤ò¥À¥¦¥ó¥í¡¼¥É¤¹¤ë¤³¤È¤â¤Ç¤­¤Þ¤¹¡£

gcc -o wave wave.c

¤È¤·¤Æ¥³¥ó¥Ñ¥¤¥ë¤·¤Þ¤¹¡£¥³¥ó¥Ñ¥¤¥ë¥ª¥×¥·¥ç¥ó¤Ï³Æ¼«¤Î´Ä¶­¤Ê¤É¤Ë±þ¤¸¤Æ½¤Àµ¤·¤Æ²¼¤µ¤¤¡£

°ú¿ô¤Ë WAVE ¥Õ¥¡¥¤¥ë¤ÎÀäÂХѥ¹¤ò»ØÄꤷ¤Æ¼Â¹Ô¤·¤Þ¤¹¡£¥¨¥é¡¼¤¬Ìµ¤±¤ì¤Ð°Ê²¼¤ÎÎã¤ÎÍͤËɽ¼¨¤µ¤ì¡¢WAVE ¥Õ¥¡¥¤¥ë¤ÎºÆÀ¸¤¬³«»Ï¤µ¤ì¤Þ¤¹¡£²¿ % ºÆÀ¸¤·¤¿¤«¤Îɽ¼¨¤Ï¿ï»þ¹¹¿·¤µ¤ì¤Þ¤¹¡£¤Ê¤ª¡¢juice_pm_mix.wav ¤Ï¼ê¸µ¤Ë¤¢¤ë B'z ¤Î¥¢¥ë¥Ð¥à Green ¤«¤é¸Ä¿ÍÍøÍѤΤ¿¤á¤ËµÛ¤¤½Ð¤·¤¿¤â¤Î¤Ç¤¹¡£¤ß¤Ê¤µ¤ó¡¢¼«Ê¬¤Ç»ý¤Ã¤Æ¤¤¤ë CD ¤«¤é¸Ä¿ÍÍøÍѤÎÍÑÅӤ˸¤äƵۤ¤½Ð¤¹¤«¡¢Ãøºî¸¢¥Õ¥ê¡¼¤ÎÁǺà¤òõ¤¹¤«¡¢¼«Ê¬¤ÇºîÀ®¤¹¤ë¤«¤·¤¿ WAVE ¥Õ¥¡¥¤¥ë¤ò»ÈÍѤ·¤Æ²¼¤µ¤¤¡£Ãøºî¸¢Ë¡¤Ë¤ÏÃí°Õ¤·¤Þ¤·¤ç¤¦¡ª

ɽ¼¨Îã)

ryo@phoenix:~$ ./wave juice_pm_mix.wav 

WAVE file format :
 rate    = 44100
 channel = 2
 bits    = 16
 offsets = 44
 length  = 42724080

Now playing specified sound file juice_pm_mix.wav ...
 64% played.

--- wave.c ---

    1	#include <fcntl.h> 
    2	#include <stdio.h>
    3	#include <stdlib.h>
    4	#include <string.h>
    5	#include <sys/ioctl.h>
    6	#include <unistd.h>
    7	#include <linux/soundcard.h>
    8	
    9	
   10	/* WAVE ¥Õ¥¡¥¤¥ë¤Î¾ðÊó¤ò³ÊǼ¤¹¤ë¹½Â¤ÂÎ */
   11	typedef struct {
   12		FILE* fp;        /* ¥Õ¥¡¥¤¥ë¹½Â¤ÂÎ */
   13		short is_pcm;    /* PCM ¥Õ¥©¡¼¥Þ¥Ã¥È¤Î¾ì¹ç¤Ï 1¡¢¤½¤ì°Ê³°¤Ï 0 */
   14		short channel;   /* ¥â¥Î¥é¥ë¤Î¾ì¹ç¤Ï 1¡¢¥¹¥Æ¥ì¥ª¤Î¾ì¹ç¤Ï 2 */
   15		int   rate;      /* ¥µ¥ó¥×¥ê¥ó¥°¼þÇÈ¿ô */
   16		short bits;      /* Î̻Ҳ½¥Ó¥Ã¥È¿ô */
   17		long  offset;    /* ¥Õ¥¡¥¤¥ëÀèƬ¤«¤é PCM ¥Ç¡¼¥¿¤Þ¤Ç¤Î¥ª¥Õ¥»¥Ã¥È */
   18		int   len;       /* PCM ¥Ç¡¼¥¿Éô¤ÎŤµ */
   19	}
   20	WAVE;
   21	
   22	
   23	/* ´Ø¿ô¥×¥í¥È¥¿¥¤¥× */
   24	static int  wave_read_file( char* fname, WAVE* wave );
   25	static int  wave_setup_dsp( int* fd, WAVE* wave );
   26	static void wave_progress( int* processed, int current, WAVE* wave );
   27	
   28	
   29	#define BUFSIZE 64000
   30	
   31	int 
   32	main( int argc, char** argv )
   33	{
   34		WAVE wave;
   35		char buf[ BUFSIZE ];
   36		int  dsp;
   37		int  len;
   38		int  processed = 0;
   39	
   40		if ( argc != 2 ) {
   41			fprintf( stderr, "usage : wave filename\n" );
   42			return 1;
   43		}
   44	
   45		/* WAVE ¥Õ¥¡¥¤¥ë¥Ø¥Ã¥ÀÆɤ߹þ¤ß */
   46		if ( wave_read_file( argv[1], &wave ) != 0 ) {
   47			fprintf( stderr, "Failed to read specified WAVE file"
   48				 ": %s\n", argv[1] );
   49			return 1;
   50		}
   51	
   52		printf( "\n" );
   53		printf( "WAVE file format :\n" );
   54		printf( " rate    = %d\n",  wave.rate );
   55		printf( " channel = %d\n",  wave.channel );
   56		printf( " bits    = %d\n",  wave.bits );
   57		printf( " offsets = %ld\n", wave.offset );
   58		printf( " length  = %d\n",  wave.len );
   59		printf( "\n" );
   60	
   61		/* /dev/dsp ¤ÎÀßÄê */
   62		if ( wave_setup_dsp( &dsp, &wave ) != 0 ) {
   63			fprintf( stderr, "Setup /dev/dsp failed.\n" );
   64			fclose( wave.fp );
   65			return 1;
   66		}
   67	
   68		printf( "Now playing specified wave file %s ...\n", argv[1] );
   69		fflush( stdout );
   70	
   71		fseek( wave.fp, wave.offset, SEEK_SET );
   72		wave_progress( &processed, 0, &wave );
   73	
   74		while ( 1 ) {
   75			len = fread( buf, 1, BUFSIZE, wave.fp );
   76	
   77			if ( len < BUFSIZE ) {
   78				if ( feof( wave.fp ) ) {
   79					if ( write( dsp, buf, len ) == -1 ) {
   80						perror( "write()" );
   81					}
   82					else {
   83						wave_progress( &processed, len, &wave );
   84					}
   85				}
   86				else {
   87					perror( "fread()" );
   88				}
   89	
   90				break;
   91			}
   92	
   93			if ( write( dsp, buf, len ) == -1 ) {
   94				perror( "write()" );
   95				break;
   96			}
   97	
   98			wave_progress( &processed, len, &wave );
   99		}
  100	
  101		fclose( wave.fp );
  102		close( dsp );
  103	
  104		printf( "\ndone.\n" );
  105		return 0;
  106	}
  107	
  108	
  109	/*
  110	 * WAVE ¥Õ¥¡¥¤¥ë¾ðÊó¤òÆɤ߹þ¤à
  111	 */
  112	static int 
  113	wave_read_file( char* fname, WAVE* wave )
  114	{
  115		char   buf[32];
  116		int    len;
  117	
  118		if ( ( wave->fp = fopen( fname, "r" ) ) == NULL ) {
  119			fprintf( stderr, "Failed to open %s\n", fname );
  120			return -1;
  121		}
  122	
  123		/* 
  124		 * ÀèƬ 4 ¥Ð¥¤¥È¤¬ "RIFF" ¤Ç¤¢¤ë¤³¤È¤ò³Îǧ
  125		 * ¹¹¤Ë 4 ¥Ð¥¤¥È¥¹¥­¥Ã¥×¤·¤Æ¤ª¤¯
  126		 */
  127		fread( buf, 8, 1, wave->fp );
  128	
  129		if ( strncmp( buf, "RIFF", 4 ) != 0 ) {
  130			fprintf( stderr, "Specified file is not RIFF file.\n" );
  131			fclose( wave->fp );
  132			return -1;
  133		}
  134	
  135	
  136		/* ¼¡¤Î 4 ¥Ð¥¤¥È¤¬ "WAVE" ¤Ç¤¢¤ë¤³¤È¤ò³Îǧ */
  137		fread( buf, 4, 1, wave->fp );
  138	
  139		if ( strncmp( buf, "WAVE", 4 ) != 0 ) {
  140			fprintf( stderr, "Specified file is not WAVE file.\n" );
  141			fclose( wave->fp );
  142			return -1;
  143		}
  144	
  145		/* fmt ¥Á¥ã¥ó¥¯¤òõ¤¹ */
  146		while ( 1 ) {
  147			fread( buf, 8, 1, wave->fp );
  148			len = *( int* )( &buf[4] );
  149	
  150			if ( strncmp( buf, "fmt ", 4 ) != 0 ) {
  151				if ( fseek( wave->fp, len, SEEK_CUR ) == -1 ) {
  152					fprintf( stderr, "Failed to find fmt chunk.\n" );
  153					fclose( wave->fp );
  154					return -1;
  155				}
  156			}
  157			else {
  158				break;
  159			}
  160		}
  161	
  162	
  163		/* WAVE ¥Õ¥©¡¼¥Þ¥Ã¥È¤òÆɤ߹þ¤à */
  164		fread( buf, len, 1, wave->fp );
  165	
  166		wave->is_pcm  = *( ( short* )( &buf[0]  ) );
  167		wave->channel = *( ( short* )( &buf[2]  ) );
  168		wave->rate    = *( ( int*   )( &buf[4]  ) );
  169		wave->bits    = *( ( short* )( &buf[14] ) );
  170	
  171		if ( wave->is_pcm != 1 ) {
  172			wave->is_pcm = 0;
  173		}
  174	
  175		/* data ¥Á¥ã¥ó¥¯¤òõ¤¹ */
  176		while ( 1 ) {
  177			fread( buf, 8, 1, wave->fp );
  178			len = *( int* )( &buf[4] );
  179	
  180			if ( strncmp( buf, "data", 4 ) != 0 ) {
  181				if ( fseek( wave->fp, len, SEEK_CUR ) == -1 ) {
  182					fprintf( stderr, "Failed to find data chunk.\n" );
  183					fclose( wave->fp );
  184					return -1;
  185				}
  186			}
  187			else {
  188				break;
  189			}
  190		}
  191	
  192		wave->len = len;
  193	
  194		if ( ( wave->offset = ftell( wave->fp ) ) == -1 ) {
  195			fprintf( stderr, "Failed to find offset of PCM data.\n" );
  196			fclose( wave->fp );
  197			return -1;
  198		}
  199	
  200		return 0;
  201	}
  202	
  203	
  204	/*
  205	 * /dev/dsp ¤òÀßÄꤹ¤ë
  206	 */
  207	static int 
  208	wave_setup_dsp( int* dsp, WAVE* wave )
  209	{
  210		int format;
  211		int rate;
  212		int channel;
  213	
  214		/*
  215		 * PCM ¥Õ¥©¡¼¥Þ¥Ã¥È¤Ç¤¢¤ë¤«¤É¤¦¤«³Îǧ¤¹¤ë
  216		 */
  217		if ( ! wave->is_pcm ) {
  218			fprintf( stderr, "Specified file's sound data is not PCM format.\n" );
  219			fclose( wave->fp );
  220			return -1;
  221		}
  222	
  223		/*
  224		 * 8 bit ¤Î¾ì¹ç¤Ï AFMT_U8¡¢16 bit ¤Î¾ì¹ç¤Ï AFMT_S16_LE ¤ò¥Õ¥©¡¼¥Þ¥Ã¥È
  225		 * ¤È¤·¤ÆÁªÂò¤·¡¢¤½¤ì°Ê³°¤Î¿ô¤Î¾ì¹ç¤Ï¥¨¥é¡¼¤È¤¹¤ë¡£
  226		 */
  227		if ( wave->bits == 8 ) {
  228			format = AFMT_U8;
  229		}
  230		else if ( wave->bits == 16 ) {
  231			format = AFMT_S16_LE;
  232		}
  233		else {
  234			fprintf( stderr, "Specified file's sound data is %d bits,"
  235				 "not 8 nor 16 bits.\n", wave->bits );
  236			fclose( wave->fp );
  237			return -1;
  238		}
  239	
  240		rate    = ( int )wave->rate;
  241		channel = ( int )wave->channel;
  242	
  243	
  244		if ( ( *dsp = open( "/dev/dsp", O_WRONLY ) ) == -1 ) {
  245			perror( "open()" );
  246			return -1;
  247		}
  248	
  249		if ( ioctl( *dsp, SNDCTL_DSP_SETFMT, &format ) == -1 ) {
  250			perror( "ioctl( SOUND_PCM_SETFMT )" );
  251			close( *dsp );
  252			return -1;
  253		}
  254	
  255		if ( ioctl( *dsp, SOUND_PCM_WRITE_RATE, &rate ) == -1 ) {
  256			perror( "ioctl( SOUND_PCM_WRITE_RATE )" );
  257			close( *dsp );
  258			return -1;
  259		}
  260	
  261		if ( ioctl( *dsp, SOUND_PCM_WRITE_CHANNELS, &channel ) == -1 ) {
  262			perror( "ioctl( SOUND_PCM_WRITE_CHANNELS )" );
  263			close( *dsp );
  264			return -1;
  265		}
  266	
  267		return 0;
  268	}
  269	
  270	
  271	/*
  272	 * ¿ÊĽΨ¤Îɽ¼¨
  273	 */
  274	static void 
  275	wave_progress( int* processed, int current, WAVE* wave )
  276	{
  277		int progress;
  278	
  279		*processed += current;
  280		progress = (int)( ( ( double )*processed / ( double )wave->len ) * 100 );
  281		printf( "\r%3d%% played.", progress );
  282		fflush( stdout );
  283	}
  284	
  285	
  286	/* End of wave.c */

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

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

  • 10 ¹ÔÌÜ ¡Á 20 ¹ÔÌÜ

    WAVE ¥Õ¥¡¥¤¥ë¤«¤éÆɤ߹þ¤ó¤À¾ðÊó¤ò³ÊǼ¤·¤Æ¤ª¤¯¹½Â¤ÂΤòÄêµÁ¤·¤Æ¤¤¤Þ¤¹¡£ WAVE ¥Õ¥¡¥¤¥ë¤ÎºÆÀ¸¤ËɬÍפʲսê¤À¤±ÄêµÁ¤·¤Æ¤¤¤Þ¤¹¡£³Æ¥á¥ó¥Ð¤ÎÆâÍƤϥ³¥á¥ó¥È¤ÎÄ̤ê¤Ç¤¹¡£ PCM ¥Ç¡¼¥¿Éô¤Ï WAVE ¥Õ¥¡¥¤¥ë¤Ë¤è¤Ã¤ÆÂ礭¤µ¤¬ÊѤï¤ë¤· ¤È¤Æ¤Ä¤â̵¤¯Â礭¤¯¤Ê¤ë²ÄǽÀ­¤¬¤¢¤ë¤¿¤á¡¢¥á¥â¥ê¾å¤Ë°ì³ç¤·¤ÆÆɤ߹þ¤à¤³¤È¤Ï¹Ô¤ï¤º¤Ë¡¢ ¥Õ¥¡¥¤¥ëÀèƬ¤«¤é¤Î¥ª¥Õ¥»¥Ã¥È¤È¥Ç¡¼¥¿Ä¹¤Î¤ß¤òÊݸ¤·¤Æ¤ª¤¯¤³¤È¤Ë¤·¤Þ¤·¤¿¡£

  • 23 ¡Á 26 ¹ÔÌÜ

    ÆâÉô´Ø¿ô¤Î¥×¥í¥È¥¿¥¤¥×Àë¸À¤Ç¤¹¡£wave_read_file() ¤Ç WAVE ¥Õ¥¡¥¤¥ë¤ÎÆɤ߹þ¤ß¤ò¹Ô¤¤¤Þ¤¹¡£ wave_setup_dsp() ¤ÏÆɤ߹þ¤ó¤À WAVE ¥Õ¥¡¥¤¥ë¤Î¥Ñ¥é¥á¡¼¥¿¤ò»ÈÍѤ·¤Æ /dev/dsp ¤ÎÀßÄê¤ò¹Ô¤¤¤Þ¤¹¡£wave_progress() ¤Ç WAVE ¥Õ¥¡¥¤¥ëºÆÀ¸Ãæ¤ËºÆÀ¸¤Î¿ÊĽΨ¤òɽ¼¨¤·¤Þ¤¹¡£

  • 29 ¹ÔÌÜ

    °ìÅÙ¤ËÆɤ߹þ¤ó¤Ç /dev/dsp ¤Ë½ñ¤­¹þ¤à PCM ¥Ç¡¼¥¿¤Î¥Ð¥Ã¥Õ¥¡Ä¹¤òÄêµÁ¤·¤Æ¤¤¤Þ¤¹¡£

  • 31 ¡Á 106 ¹ÔÌÜ ( main() )

    main() ´Ø¿ô¤Ç¤Ï¡¢¤Þ¤º wave_read_file() ¤Ç»ØÄꤵ¤ì¤¿ WAVE ¥Õ¥¡¥¤¥ë¤Î¾ðÊó¤òÆɤ߹þ¤ß¡¢ WAVE ·¿ÊÑ¿ô¤ËÊݸ¤·¤Æ¤ª¤­¤Þ¤¹¡£¤½¤Î¸å¡¢52 ¡Á 59 ¹ÔÌܤÇÆɤ߹þ¤ó¤À¾ðÊó¤òɽ¼¨¤·¤Þ¤¹¡£

    ¼¡¤Ë wave_setup_dsp() ¤Ç¡¢Æɤ߹þ¤ó¤À WAVE ¥Õ¥¡¥¤¥ë¤Î¾ðÊó¤ò»ÈÍѤ·¤Æ /dev/dsp ¤ÎÀßÄê¤ò¹Ô¤¤¤Þ¤¹¡£

    /dev/dsp ¤ÎÀßÄ꤬½ª¤ï¤Ã¤¿¤é¡¢68 ¡Á 72 ¹ÔÌܤǺÆÀ¸ÍѤΠwhile() ¥ë¡¼¥×ľÁ°¤ÎÍÑ°Õ¤ò¤·¤Æ¤¤¤Þ¤¹¡£ 68 ¹ÔÌܤǺÆÀ¸³«»Ï¥á¥Ã¥»¡¼¥¸¤òɽ¼¨¤·¤¿¸å fflush( stdout ) ¤ò¼Â¹Ô¤·¤Æ¤¤¤Þ¤¹¤¬¡¢ ¤³¤ì¤ò¹Ô¤ï¤Ê¤¤¤È¥Ð¥Ã¥Õ¥¡¥ê¥ó¥°¤µ¤ì¤Æ²èÌ̤Ëɽ¼¨¤µ¤ì¤Ê¤¤¾ì¹ç¤¬¤¢¤ê¤Þ¤¹ ( ¤È¤¤¤¦¤«Ãø¼Ô¤Î´Ä¶­¤Ç¤Ï³Î¼Â¤Ëɽ¼¨¤µ¤ì¤Þ¤»¤ó )¡£71 ¹ÔÌܤǡ¢´û¤ËÆɤ߹þ¤ó¤À PCM ¥Ç¡¼¥¿¤ÎÀèƬ°ÌÃÖ¤Þ¤Ç WAVE ¥Õ¥¡¥¤¥ë¤Î¥Õ¥¡¥¤¥ë¥Ý¥¤¥ó¥¿¤ò fseek() ¤Ç°ÜÆ°¤·¤Æ¤ª¤­¡¢ wave_progress() ¤ÇºÇ½é¤ÎºÆÀ¸¿ÊĽΨ¤òɽ¼¨¤·¤Æ¤ª¤­¤Þ¤¹¡£

    while() ¥ë¡¼¥×¤Ç¤Ï¡¢¤Þ¤º fread() ¤Ç¥Ð¥Ã¥Õ¥¡¤Î¥µ¥¤¥ºÊ¬ PCM ¥Ç¡¼¥¿¤òÆɤ߹þ¤ß¤Þ¤¹¡£ ¥Ð¥Ã¥Õ¥¡¤Î¥µ¥¤¥ºÊ¬¥Ç¡¼¥¿¤òÆɤ߹þ¤ó¤À¾ì¹ç¤Ï¡¢93 ¡Á 96 ¹ÔÌܤÎÄ̤ê write() ¤Ç PCM ¥Ç¡¼¥¿¤ò½ñ¤­¹þ¤ß¡¢wave_progress() ¤Ç¿ÊĽΨ¤ò¹¹¿·¤·¤Þ¤¹¡£

    Æɤ߹þ¤ó¤À¥Ç¡¼¥¿Ä¹¤¬¥Ð¥Ã¥Õ¥¡¤Î¥µ¥¤¥ºÌ¤Ëþ¤Ç¤¢¤Ã¤¿¾ì¹ç¤Ï¡¢¤Þ¤º feof() ¤Ç EOF ¤«¤É¤¦¤«¤òȽÄꤷ¤Þ¤¹¡£EOF ¤Ç¤¢¤Ã¤¿¾ì¹ç¤Ï write() ¤Ç PCM ¥Ç¡¼¥¿¤Î½ñ¤­¹þ¤ß¤ò¹Ô¤¤¡¢ wave_progress() ¤Ç¿ÊĽΨ¤ò¹¹¿·¤·¤¿¾å¤Ç while() ¥ë¡¼¥×¤«¤éÈ´¤±¤Þ¤¹¡£ EOF ¤Ç¤Ê¤¤¾ì¹ç¤Ï¥¨¥é¡¼¤Ç¤¢¤ë¤¿¤á¡¢perror() ¤Ç¥¨¥é¡¼É½¼¨¤ò¤·¤Æ while() ¥ë¡¼¥×¤«¤éÈ´¤±¤Þ¤¹¡£

    while() ¥ë¡¼¥×¤«¤éÈ´¤±¤¿¤é¡¢WAVE ¥Õ¥¡¥¤¥ë¥Ý¥¤¥ó¥¿¤ª¤è¤Ó /dev/dsp ¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤òÊĤ¸¤Æ½ªÎ»¤·¤Þ¤¹¡£

  • 109 ¡Á 201 ¹ÔÌÜ ( wave_read_file() )

    WAVE ¥Õ¥¡¥¤¥ë¤òÆɤ߹þ¤ó¤Ç¡¢WAVE ·¿ÊÑ¿ô¤Ë¾ðÊó¤ò³ÊǼ¤¹¤ë´Ø¿ô¤Ç¤¹¡£

    • 123 ¡Á 133 ¹ÔÌÜ

      ÀèƬ 4 ¥Ð¥¤¥È¤¬Ê¸»úÎó "RIFF" ¤Ç¤¢¤ë¤«¤É¤¦¤«¤ò³Îǧ¤·¤Æ¤¤¤Þ¤¹¡£¤Þ¤¿¡¢Â³¤¯ 4 ¥Ð¥¤¥È¤ÏÉÔÍפǤ¢¤ë¤¿¤á¥¹¥­¥Ã¥×¤·¤Æ¤¤¤Þ¤¹¡£

    • 136 ¡Á 143 ¹ÔÌÜ

      ʸ»úÎó "WAVE" ¤ò³Îǧ¤·¤Æ¤¤¤Þ¤¹¡£

    • 145 ¡Á 160 ¹ÔÌÜ

      fmt ¥Á¥ã¥ó¥¯¤ò¸¡º÷¤·¤Æ¤¤¤Þ¤¹¡£fmt ¥Á¥ã¥ó¥¯¤Ï "WAVE" ¤Îľ¸å¤Ë³¤¯¤Ï¤º¤Ê¤Î¤Ç¡¢ ¤³¤ÎÍͤ˸¡º÷½èÍý¤ò¹Ô¤¦É¬ÍפÏ̵¤¤¤È»×¤¤¤Þ¤¹¤¬¡¢data ¥Á¥ã¥ó¥¯¤ÇƱ¤¸¸¡º÷½èÍý¤ò¼ÂÁõ¤·¤¿¤Î¤Ç¤Ä¤¤¤Ç¤Ë¹Ô¤Ã¤Æ¤Þ¤¹¡£

      ¤Þ¤ºÂ³¤¯ 8 ¥Ð¥¤¥È¤òÆɤ߹þ¤ß¡¢¸åȾ 4 ¥Ð¥¤¥È¤ò int ·¿ÊÑ¿ô len ¤Ë³ÊǼ¤·¤Æ¤¤¤Þ¤¹¡£ ¤³¤ì¤Ï¡¢¸½ºß»²¾È¤·¤Æ¤¤¤ë¥Á¥ã¥ó¥¯¤Î¥Ç¡¼¥¿Éô¤ÎŤµ¤È¤Ê¤ê¤Þ¤¹¡£Á°È¾ 4 ¥Ð¥¤¥È¤¬ "fmt " ¤Ç¤¢¤ë¤«¤É¤¦¤«¤òÄ´¤Ù¡¢"fmt " ¤Ç¤Ê¤¤¾ì¹ç¤Ï len ¤ÎŤµ¤À¤±¥¹¥­¥Ã¥×¤·¤Þ¤¹¡£ "fmt " ¤Ç¤¢¤ë¾ì¹ç¤Ï while() ¥ë¡¼¥×¤Ë¤è¤ë¸¡º÷½èÍý¤òÈ´¤±¤Þ¤¹¡£

    • 163 ¡Á 173 ¹ÔÌÜ

      fmt ¥Á¥ã¥ó¥¯¤ò¸¡½Ð¤·¤¿¤Î¤Ç¡¢¥Õ¥©¡¼¥Þ¥Ã¥È¾ðÊó¤òÆɤ߹þ¤ß¤Þ¤¹¡£É¬ÍפȤʤë¤Î¤Ï ¥Õ¥©¡¼¥Þ¥Ã¥È¼ïÊÌ¡¢¥Á¥ã¥ó¥Í¥ë¿ô¡¢¥µ¥ó¥×¥ê¥ó¥°¼þÇÈ¿ô¡¢Î̻Ҳ½¥Ó¥Ã¥È¿ô¤Ç¤¹¡£ ¤³¤ì¤é¤òÆɤ߹þ¤ó¤À¸å¡¢¥Õ¥©¡¼¥Þ¥Ã¥È¼ïÊ̤¬ 1 ( PCM ) ¤Ç¤Ê¤¤¾ì¹ç¤Ï¶¯À©Åª¤Ë 0 ¤È¤·¤Æ¤ª¤­¤Þ¤¹¡£

    • 175 ¡Á 190 ¹ÔÌÜ

      fmt ¥Á¥ã¥ó¥¯¤ÈƱÍͤΥ¢¥ë¥´¥ê¥º¥à¤Ç data ¥Á¥ã¥ó¥¯¤ò¸¡º÷¤·¤Æ¤¤¤Þ¤¹¡£"fmt " ¤ÎÂå¤ï¤ê¤Ë "data" ¤È¤¤¤¦Ê¸»úÎó¤òÈæ³Ó¤Ë»È¤Ã¤Æ¤¤¤Þ¤¹¡£fmt ¥Á¥ã¥ó¥¯¤È data ¥Á¥ã¥ó¥¯¤Î´Ö¤Ë¤ÏÊ̤ΥÁ¥ã¥ó¥¯¤¬ÁÞÆþ¤µ¤ì¤ë¤³¤È¤¬¤¢¤ë¤Î¤Ç¡¢¤³¤ì¤Ïɬ¿Ü¤Î½èÍý¤Ç¤¹¡£

    • 192 ¡Á 198 ¹ÔÌÜ

      ¤Þ¤º PCM ¥Ç¡¼¥¿Ä¹¤ò WAVE ¹½Â¤ÂΤËÊݸ¤·¤Þ¤¹¡£¤³¤Î»þÅÀ¤Ç¥Õ¥¡¥¤¥ë¥Ý¥¤¥ó¥¿¤Ï PCM ¥Ç¡¼¥¿¤ÎÀèƬ¤Ë¤¢¤ë¤Î¤Ç¡¢¥Õ¥¡¥¤¥ë¥Ý¥¤¥ó¥¿¤Î¥Õ¥¡¥¤¥ëÀèƬ¤«¤é¤Î¥ª¥Õ¥»¥Ã¥È°ÌÃÖ¤ò ftell() ¤Ç¼èÆÀ¤·Êݸ¤·¤Æ¤¤¤Þ¤¹¡£

  • 204 ¡Á 268 ¹ÔÌÜ ( wave_setup_dsp() )

    214 ¡Á 221 ¹ÔÌÜ¤Ç PCM ¥Õ¥©¡¼¥Þ¥Ã¥È¤Ç¤¢¤ë¤«¤É¤¦¤«¤ò³Îǧ¤·¤Æ¤¤¤Þ¤¹¡£PCM ¥Õ¥©¡¼¥Þ¥Ã¥È¤Ç¤Ê¤¤¾ì¹ç¤Ï¡¢¤½¤Î»þÅÀ¤Ç½ªÎ»¤·¤Þ¤¹¡£

    223 ¡Á 238 ¹ÔÌܤǤϡ¢Î̻Ҳ½¥Ó¥Ã¥È¿ô¤Ë¤è¤Ã¤Æ /dev/dsp ¤ËÀßÄꤹ¤ë¥Õ¥©¡¼¥Þ¥Ã¥È¤ò·èÄꤷ¤Æ¤¤¤Þ¤¹¡£¥Ó¥Ã¥È¿ô¤¬ 8 ¤Î¾ì¹ç¤Ï AFMT_U8¡¢¥Ó¥Ã¥È¿ô¤¬ 16 ¤Î¾ì¹ç¤Ï AFMT_S16_LE ¤Ç¤¹¡£¤½¤ì°Ê³°¤Î¾ì¹ç¤ÏÀµ¤·¤¤ WAVE ¥Õ¥¡¥¤¥ë¤Î¥Õ¥©¡¼¥Þ¥Ã¥È¤Ç¤Ï¤Ê¤¤¤¿¤á¡¢¤½¤Î»þÅÀ¤Ç½ªÎ»¤·¤Þ¤¹¡£

    244 ¹ÔÌܰʹߤǤϡ¢¤³¤ì¤Þ¤Ç¤Î¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤ÈƱ¤¸ÍÍ¤Ë ioctl() ¤Ç /dev/dsp ¤ÎÀßÄê¤ò¹Ô¤Ã¤Æ¤¤¤Þ¤¹¡£

  • 271 ¡Á 283 ¹ÔÌÜ ( wave_progress() )

    WAVE ¥Õ¥¡¥¤¥ë¤ÎºÆÀ¸Ãæ¤Ë¡¢¥³¥ó¥½¡¼¥ë²èÌ̤˸½ºß¤ÎºÆÀ¸Î¨¤òɽ¼¨¤·¤Þ¤¹¡£/dev/dsp ¤Ë½ñ¤­¹þ¤à¥Ç¡¼¥¿Ä¹ ( current ) ¤ò¤³¤ì¤Þ¤Ç¤Ë½ñ¤­¹þ¤ó¤À¥Ç¡¼¥¿Ä¹ ( processed ) ¤Ë²Ã»»¤·¡¢WAVE ¥Õ¥¡¥¤¥ë¤Î PCM ¥Ç¡¼¥¿Ä¹¤Ç³ä¤Ã¤ÆºÆÀ¸Î¨¤òµá¤á¤Æ¤¤¤Þ¤¹¡£¸å¤Ï printf() ¤Çɽ¼¨¤·¤Æ¤¤¤ë¤À¤±¤Ç¤¹¡£\r ¤Ë¤è¤Ã¤Æɽ¼¨°ÌÃÖ¤òÊѤ¨¤Ê¤¤Íͤˤ·¤Æ¤¤¤Þ¤¹¡£

    ¤Þ¤¿¡¢printf() ¤Îľ¸å¤Ç fflush() ¤Ë¤è¤Ã¤Æ¶¯À©Åª¤Ë²èÌÌɽ¼¨¤ò¹¹¿·¤·¤Æ¤¤¤Þ¤¹¡£ Á°½Ò¤ÎÄ̤ꡢ¤³¤ì¤ò¹Ô¤ï¤Ê¤¤¤È¥Ð¥Ã¥Õ¥¡¥ê¥ó¥°¤Ë¤è¤Ã¤Æ²èÌ̤Ëɽ¼¨¤¬½Ð¤Ê¤¤¾ì¹ç¤¬¤¢¤ê¤Þ¤¹ ( Ãø¼Ô¤Î´Ä¶­¤Ç¤Ï³Î¼Â¤Ëɽ¼¨¤µ¤ì¤Ê¤¤¤Ç¤¹ )¡£


°Ê¾å¤Ç wave.c ¤ÎÀâÌÀ¤Ï½ª¤ï¤ê¤Ç¤¹¡£¤ß¤Ê¤µ¤ó¡¢¹¥¤­¤Ê²»³Ú¤Ç¤âºÆÀ¸¤·¤Æ³Ú¤·¤ó¤Ç²¼¤µ¤¤¡ª