|
¡û ¤Ï¤¸¤á¤Ë
LECTURE 12 Ê£¿ô¤Î²»¤ò¤¹Ã±½ã¥ß¥¥µ ¤Ç¤Ï¡¢¡Ö2 ¤Ä¤Î²»¸»¤òñ½ã¤Ë¹çÀ®¤·¤Æ 1 ¤Ä¤Î²»¤òºî¤ê½Ð¤¹¡×ÄãÀǽ¥ß¥¥µ¤ò½ñ¤¤¤Æ¤ß¤Þ¤·¤¿¡£º£²ó¤Ï¡¢²»¤ÎÄê°Ì¡Ê²»¸»¤Î°ÌÃ֡ˤòÊѲ½¤µ¤»¤ëµ¡Ç½¤Î¤ß¤ò»ý¤Ã¤¿¥×¥í¥°¥é¥à¤ò½ñ¤¤¤Æ¤ß¤¿¤¤¤È»×¤¤¤Þ¤¹¡£Á°²ó¤ÎÄãÀǽ¥ß¥¥µ¤Èº£²ó¤ÎÄê°ÌÄ´À°¤ÎÃ챤ò»È¤Ã¤Æ GUI ¤Ç¤âÍÑ°Õ¤¹¤ì¤Ð¡¢²»¼Á¤Ë¤Ï¹´¤é¤Ê¤¤¡Ê¡©¡ËºÇÄã¸Â¤Îµ¡Ç½¤òÈ÷¤¨¤¿¥ß¥¥µ¤òºî¤ì¤ë¡Ä¤¢¤¢¡¢¤»¤á¤Æ²»ÎÌÄ´À°µ¡Ç½¤òÉÕ¤±¤Ê¤±¤ì¤Ð¡Ä
¤Á¤Ê¤ß¤Ë¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤ò¼Â¹Ô¤·¤Æ¤¤¤ë¤È¡¢ÀΤɤ³¤«¤ÎÍ·±àÃϤ˹Ԥä¿»þ¤ËÆþ¤Ã¤¿¥Û¥é¡¼·Ï¤Î¥¢¥È¥é¥¯¥·¥ç¥ó¤Ç¡¢Í©Îî¤ÎÀ¼¤¬º¸±¦¤ËÆ°¤¯Å٤ˤ¾¤¯¤¾¤¯¤·¤¿¤Î¤ò»×¤¤½Ð¤·¤Þ¤·¤¿¡£Í©Îî¤ÎÀ¼¤¬¤¢¤ì¤ÐºÆÀ¸¤·¤Æ¤ß¤¿¤¤¤ó¤Ç¤¹¤¬¡£
¡û ²»¤ÎÄê°Ì¡Ê¥Ñ¥ó¡Ë¤Ë¤Ä¤¤¤Æ
ËÜ¥Ú¡¼¥¸¤Ç°·¤¦²»¤ÎÄê°Ì¡Ê¥Ñ¥ó¤È¤â¸À¤¦ÍͤǤ¹¡Ë¤È¤Ï¡¢Ê¹¤¼ê¤ËÂФ·¤Æ²»¸»¤¬¤É¤³¤ËÇÛÃÖ¤µ¤ì¤ë¤«¤òɽ¤·¤Þ¤¹¡£Î㤨¤Ðʹ¤¼ê¤Îº¸Êý¸þ¤Ë¤¢¤ì¤ÐÂçÉôʬ¤Î²»¤Ïº¸¤«¤éʹ¤³¤¨¡¢±¦Êý¸þ¤Ë¤¢¤ì¤Ð±¦¤«¤éʹ¤³¤¨¤ë¤ï¤±¤Ç¤¹¡£
Àµ³Î¤Ë¤ÏΩÂÎŪ¤Ê°ÌÃÖ´Ø·¸¤ò¹Íθ¤·¤¿¤ê¡¢±ó¤¤¶á¤¤¤È¤¤¤Ã¤¿µ÷Î¥´Ö¤Ë¤è¤ë²»Î̤ÎÊѲ½¤âȯÀ¸¤·¤Þ¤¹¤¬¡¢ËÜ¥Ú¡¼¥¸¤Î¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤Ç¤Ï¡¢º¸±¦¤òľÀþ¾å¤Ë°ÜÆ°¤·µ÷Î¥¤Ë¤è¤ë²»Î̤ÎÊѲ½¤ÏȯÀ¸¤·¤Ê¤¤¤È¤·¤Æ°·¤¤¤Þ¤¹¡ÊÄãÀǽ¡Ë¡£
¡û ¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à
»ØÄꤷ¤¿ WAVE ¥Õ¥¡¥¤¥ë¤ò¡¢º¸±¦¤Î²»Î̤ΥХé¥ó¥¹¤òÊѲ½¤µ¤»¤Ê¤¬¤éºÆÀ¸¤¹¤ë¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à pan.c ¤Ç¤¹¡£¤Ï¤¸¤á¤Ë ¤Î¥Ú¡¼¥¸¤«¤é¡¢Á´¤Æ¤Î¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤ò¸Ç¤á¤¿ tar ¥Ü¡¼¥ë¤ò¥À¥¦¥ó¥í¡¼¥É¤¹¤ë¤³¤È¤â¤Ç¤¤Þ¤¹¡£
pthread ¤ò»È¤Ã¤Æ¤¤¤Þ¤¹¤Î¤Ç
gcc -o pan pan.c -lpthread
¤ÎÍÍ¤Ë -lpthread ¥ª¥×¥·¥ç¥ó¤òÉÕ¤±¤Æ¥³¥ó¥Ñ¥¤¥ë¤·¤Þ¤¹¡£
°ú¿ô¤Ë WAVE ¥Õ¥¡¥¤¥ë¤ÎÀäÂХѥ¹¤ò»ØÄꤷ¤Æ¼Â¹Ô¤¹¤ë¤È¡¢°Ê²¼¤ÎÍͤʥá¥Ë¥å¡¼¤¬É½¼¨¤µ¤ì¤Þ¤¹¡£ÈÖ¹æ¤òÆþÎϤ·¤Æ Enter ¤ò²¡¤¹¤È¡¢»ØÄꤷ¤¿ÆâÍƤ˽¾¤Ã¤Æ WAVE ¥Õ¥¡¥¤¥ë¤òºÆÀ¸¤·¤Þ¤¹¡£ºÆÀ¸Ãæ¤Ïº¸±¦¤Î²»Î̤ΥХé¥ó¥¹¤¬¼«Æ°Åª¤ËÊѲ½¤·¤Þ¤¹¡£
Select menu ... 1. Play specified wave file. 2. Stop playing. 99. Exit. Command ?
»ØÄê¤Ç¤¤ë WAVE ¥Õ¥¡¥¤¥ë¤Ï
- PCM ¥Õ¥©¡¼¥Þ¥Ã¥È
- Î̻Ҳ½¥Ó¥Ã¥È¿ô 16 ¥Ó¥Ã¥È
- 1 ¥Á¥ã¥ó¥Í¥ë
¤Ç¤¹¡£
--- pan.c ---
1 #include <fcntl.h> 2 #include <limits.h> 3 #include <stdio.h> 4 #include <stdlib.h> 5 #include <string.h> 6 #include <linux/soundcard.h> 7 #include <pthread.h> 8 #include <sys/ioctl.h> 9 #include <unistd.h> 10 11 12 #define COMMAND_STOP 0 13 #define COMMAND_PLAY 1 14 #define COMMAND_EXIT 2 15 16 #define PAN_MIN 0 17 #define PAN_MAX 256 18 #define PAN_STEP 4 19 20 #define BUFSIZE 4096 21 22 23 /* WAVE ¥Õ¥¡¥¤¥ë¤Î¾ðÊó¤ò³ÊǼ¤¹¤ë¹½Â¤ÂÎ */ 24 typedef struct { 25 FILE* fp; /* ¥Õ¥¡¥¤¥ë¹½Â¤ÂÎ */ 26 short is_pcm; /* PCM ¥Õ¥©¡¼¥Þ¥Ã¥È¤Î¾ì¹ç¤Ï 1¡¢¤½¤ì°Ê³°¤Ï 0 */ 27 short channel; /* ¥â¥Î¥é¥ë¤Î¾ì¹ç¤Ï 1¡¢¥¹¥Æ¥ì¥ª¤Î¾ì¹ç¤Ï 2 */ 28 int rate; /* ¥µ¥ó¥×¥ê¥ó¥°¼þÇÈ¿ô */ 29 short bits; /* Î̻Ҳ½¥Ó¥Ã¥È¿ô */ 30 long offset; /* ¥Õ¥¡¥¤¥ëÀèƬ¤«¤é PCM ¥Ç¡¼¥¿¤Þ¤Ç¤Î¥ª¥Õ¥»¥Ã¥È */ 31 int len; /* PCM ¥Ç¡¼¥¿Éô¤ÎŤµ */ 32 int current; /* ¸½ºß¤ÎºÆÀ¸°ÌÃÖ */ 33 } 34 WAVE; 35 36 37 /* ºÆÀ¸¤ËɬÍפʥǡ¼¥¿¤ò¤Þ¤È¤á¤¿¹½Â¤ÂÎ */ 38 typedef struct { 39 pthread_t thread_id; 40 int command; 41 int dsp; 42 WAVE wave; 43 short buffer[ BUFSIZE / sizeof( short ) ]; 44 /* 45 * PAN_MIN(0) <= pan <= PAN_MAX(256) 46 * pan == PAN_MIN ¤¬ L ¤Î¤ß¤Ç pan == PAN_MAX ¤¬ R ¤Î¤ß 47 */ 48 int pan; 49 } 50 Context; 51 52 static Context context; 53 54 55 static int read_file( char* fname, WAVE* wave ); 56 static int setup_dsp( int* fd, WAVE* wave ); 57 static void show_menu( void ); 58 static void* play_thread( void* param ); 59 static void fill_buffer( short* dst, WAVE* wave, int pan ); 60 static void shutdown(); 61 62 63 int 64 main( int argc, char** argv ) 65 { 66 pthread_attr_t attr; 67 int ret; 68 69 if ( argc != 2 ) { 70 fprintf( stderr, "usage : ./wave filename\n" ); 71 return 1; 72 } 73 74 if ( read_file( argv[1], &( context.wave ) ) != 0 ) { 75 fprintf( stderr, "Failed to read wave files.\n" ); 76 return 1; 77 } 78 79 if ( setup_dsp( &( context.dsp ), &( context.wave ) ) != 0 ) { 80 fprintf( stderr, "Failed to setup /dev/dsp.\n" ); 81 return 1; 82 } 83 84 pthread_attr_init( &attr ); 85 pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_JOINABLE ); 86 87 ret = pthread_create( &( context.thread_id ), &attr, 88 play_thread, ( void* )( &context ) ); 89 90 pthread_attr_destroy( &attr ); 91 92 if ( ret ) { 93 fprintf( stderr, "Failed to create thread.\n" ); 94 shutdown(); 95 return 1; 96 } 97 98 show_menu(); 99 pthread_join( context.thread_id, NULL ); 100 shutdown(); 101 102 return 0; 103 } 104 105 106 static int 107 read_file( char* fname, WAVE* wave ) 108 { 109 char buf[32]; 110 int len; 111 112 if ( ( wave->fp = fopen( fname, "r" ) ) == NULL ) { 113 fprintf( stderr, "Failed to open %s\n", fname ); 114 goto err; 115 } 116 117 /* 118 * ÀèƬ 4 ¥Ð¥¤¥È¤¬ "RIFF" ¤Ç¤¢¤ë¤³¤È¤ò³Îǧ 119 * ¹¹¤Ë 4 ¥Ð¥¤¥È¥¹¥¥Ã¥×¤·¤Æ¤ª¤¯ 120 */ 121 fread( buf, 8, 1, wave->fp ); 122 123 if ( strncmp( buf, "RIFF", 4 ) != 0 ) { 124 fprintf( stderr, "Specified file is not RIFF file.\n" ); 125 goto err; 126 } 127 128 129 /* ¼¡¤Î 4 ¥Ð¥¤¥È¤¬ "WAVE" ¤Ç¤¢¤ë¤³¤È¤ò³Îǧ */ 130 fread( buf, 4, 1, wave->fp ); 131 132 if ( strncmp( buf, "WAVE", 4 ) != 0 ) { 133 fprintf( stderr, "Specified file is not WAVE file.\n" ); 134 goto err; 135 } 136 137 /* fmt ¥Á¥ã¥ó¥¯¤òõ¤¹ */ 138 while ( 1 ) { 139 fread( buf, 8, 1, wave->fp ); 140 len = *( int* )( &buf[4] ); 141 142 if ( strncmp( buf, "fmt ", 4 ) != 0 ) { 143 if ( fseek( wave->fp, len, SEEK_CUR ) == -1 ) { 144 fprintf( stderr, "Failed to find fmt chunk.\n" ); 145 goto err; 146 } 147 } 148 else { 149 break; 150 } 151 } 152 153 fread( buf, len, 1, wave->fp ); 154 155 wave->is_pcm = *( ( short* )( &buf[0] ) ); 156 wave->channel = *( ( short* )( &buf[2] ) ); 157 wave->rate = *( ( int* )( &buf[4] ) ); 158 wave->bits = *( ( short* )( &buf[14] ) ); 159 160 /* 161 * PCM / 16 bits / Monoral °Ê³°¤Î WAVE ¥Ç¡¼¥¿¤Ë¤Ä¤¤¤Æ¤Ï 162 * ËÜ¥×¥í¥°¥é¥à¤Ç¤ÏÂоݳ° 163 */ 164 if ( wave->is_pcm != 1 ) { 165 fprintf( stderr, "WAVE file must be PCM format.\n" ); 166 goto err; 167 } 168 169 if ( wave->bits != 16 ) { 170 fprintf( stderr, "WAVE file must be 16 bits .\n" ); 171 goto err; 172 } 173 174 if ( wave->channel != 1 ) { 175 fprintf( stderr, "WAVE file must be monoral.\n" ); 176 goto err; 177 } 178 179 /* data ¥Á¥ã¥ó¥¯¤òõ¤¹ */ 180 while ( 1 ) { 181 fread( buf, 8, 1, wave->fp ); 182 len = *( int* )( &buf[4] ); 183 184 if ( strncmp( buf, "data", 4 ) != 0 ) { 185 if ( fseek( wave->fp, len, SEEK_CUR ) == -1 ) { 186 fprintf( stderr, "Failed to find data chunk.\n" ); 187 goto err; 188 } 189 } 190 else { 191 break; 192 } 193 } 194 195 wave->len = len; 196 197 if ( ( wave->offset = ftell( wave->fp ) ) == -1 ) { 198 fprintf( stderr, "Failed to find offset of PCM data.\n" ); 199 goto err; 200 } 201 202 printf( "\n" ); 203 printf( "WAVE file format of %s:\n", fname ); 204 printf( " rate = %d\n", wave->rate ); 205 printf( " channel = %d\n", wave->channel ); 206 printf( " bits = %d\n", wave->bits ); 207 printf( " offsets = %ld\n", wave->offset ); 208 printf( " length = %d\n", wave->len ); 209 printf( "\n" ); 210 211 return 0; 212 213 err: 214 if ( wave->fp != NULL ) { 215 fclose( wave->fp ); 216 } 217 218 return 1; 219 } 220 221 222 static int 223 setup_dsp( int* dsp, WAVE* wave ) 224 { 225 int fragment = 0x0004000c; /* size = 4096 bytes, num of fragments = 4. */ 226 int format = AFMT_S16_LE; 227 int rate; 228 int channel = 2; 229 230 rate = ( int )wave->rate; 231 232 if ( ( *dsp = open( "/dev/dsp", O_WRONLY ) ) == -1 ) { 233 perror( "open()" ); 234 return 1; 235 } 236 237 if ( ioctl( *dsp, SNDCTL_DSP_SETFRAGMENT, &fragment ) == -1 ) { 238 perror( "ioctl( SNDCTL_DSP_SETFRAGMENT )" ); 239 close( *dsp ); 240 return 1; 241 } 242 243 if ( ioctl( *dsp, SNDCTL_DSP_SETFMT, &format ) == -1 ) { 244 perror( "ioctl( SNDCTL_DSP_SETFMT )" ); 245 close( *dsp ); 246 return 1; 247 } 248 249 if ( ioctl( *dsp, SNDCTL_DSP_SPEED, &rate ) == -1 ) { 250 perror( "ioctl( SNDCTL_DSP_SPEED )" ); 251 close( *dsp ); 252 return 1; 253 } 254 255 if ( ioctl( *dsp, SNDCTL_DSP_CHANNELS, &channel ) == -1 ) { 256 perror( "ioctl( SNDCTL_DSP_CHANNELS )" ); 257 close( *dsp ); 258 return 1; 259 } 260 261 return 0; 262 } 263 264 265 static void 266 show_menu( void ) 267 { 268 char line[4]; 269 int command; 270 271 while ( 1 ) { 272 printf( "Select menu ...\n" ); 273 printf( " 1. Play specified wave file.\n" ); 274 printf( " 2. Stop playing.\n" ); 275 printf( " 99. Exit.\n" ); 276 printf( "\n" ); 277 printf( "Command ? " ); 278 279 fgets( line, sizeof( line ), stdin ); 280 sscanf( line, "%d\n", &command ); 281 282 switch ( command ) { 283 case 1: 284 context.command = COMMAND_PLAY; 285 break; 286 case 2: 287 context.command = COMMAND_STOP; 288 break; 289 case 99: 290 context.command = COMMAND_EXIT; 291 return; 292 } 293 } 294 } 295 296 297 static void* 298 play_thread( void* param ) 299 { 300 static int sign = 1; 301 Context* context = ( Context* )param; 302 303 while ( context->command != COMMAND_EXIT ) { 304 memset( ( void* )( context->buffer ), 0, BUFSIZE ); 305 306 switch ( context->command ) { 307 case COMMAND_PLAY: 308 context->pan += PAN_STEP * sign; 309 310 if ( context->pan > PAN_MAX ) { 311 context->pan = PAN_MAX; 312 sign *= -1; 313 } 314 else if ( context->pan < 0 ) { 315 context->pan = 0; 316 sign *= -1; 317 } 318 319 fill_buffer( ( void* )( context->buffer ), 320 &( context->wave ), context->pan ); 321 break; 322 323 case COMMAND_STOP: 324 default: 325 break; 326 } 327 328 write( context->dsp, ( void* )( context->buffer ), BUFSIZE ); 329 } 330 331 pthread_exit( NULL ); 332 } 333 334 335 static void 336 fill_buffer( short* dst, WAVE* wave, int pan ) 337 { 338 /* 339 * buf ¤ÏÆþÎϲ»¸»¤ÈƱ¤¸ÆâÍƤòžÁ÷¤¹¤ë¤¿¤á¤Î¥Ð¥Ã¥Õ¥¡¡£ 340 * BUFSIZE ¤Ï½ÐÎÏÍѥХåե¡¥µ¥¤¥º¤Ç¤¢¤ê¡¢½ÐÎϤϥ¹¥Æ¥ì¥ª/ÆþÎϤϥâ¥Î¥é¥ë 341 * ¤Ç¤¢¤ë¤¿¤á¡¢BUFSIZE / 2 ¤È¤·¤Æ¤¤¤ë¡£ 342 */ 343 short buf[ ( BUFSIZE / 2 ) / sizeof( short ) ]; 344 int copied = 0; 345 int i; 346 347 while ( 1 ) { 348 int src_left = wave->len - wave->current; 349 int dst_left = BUFSIZE / 2 - copied; 350 int copy_len = src_left > dst_left ? dst_left : src_left; 351 352 if ( src_left == 0 ) { 353 fseek( wave->fp, wave->offset, SEEK_SET ); 354 wave->current = 0; 355 continue; 356 } 357 358 if ( dst_left == 0 ) { 359 break; 360 } 361 362 fread( ( void* )( buf + copied / sizeof( short ) ), 363 copy_len, 1, wave->fp ); 364 365 for ( i = 0; i < copy_len / sizeof( short ); i ++ ) { 366 dst[ ( copied / sizeof( short ) + i ) * 2 + 0 ] = 367 buf[i] * ( PAN_MAX - pan ) / PAN_MAX; /* L */ 368 dst[ ( copied / sizeof( short ) + i ) * 2 + 1 ] = 369 buf[i] * pan / PAN_MAX; /* R */ 370 } 371 372 wave->current += copy_len; 373 copied += copy_len; 374 } 375 } 376 377 378 static void 379 shutdown( void ) 380 { 381 fclose( context.wave.fp ); 382 close( context.dsp ); 383 } 384 385 386 /* End of pan.c */
¡û ¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤ÎÀâÌÀ
¤Ç¤Ï¡¢¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤Ë¤Ä¤¤¤ÆÀâÌÀ¤·¤Æ¤¤¤¤Þ¤¹¡£pthread ¤òÍѤ¤¤Æ WAVE ¥Õ¥¡¥¤¥ëºÆÀ¸ÍÑ¥¹¥ì¥Ã¥É¤òÀ¸À®¤¹¤ëÅù¡¢´ðËÜŪ¤Ê¹½Â¤¤Ï LECTURE 12 Ê£¿ô¤Î²»¤ò¤¹Ã±½ã¥ß¥¥µ ¤È¤Û¤ÜƱ¤¸¤Ç¤¹¡£¤è¤Ã¤Æ¡¢ÀâÌÀ¤¬ÉÔ¤·¤Æ¤¤¤ëÉôʬÅù¤Ë¤Ä¤¤¤Æ¤Ï¤½¤Á¤é¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡£
- 37 ¡Á 52 ¹ÔÌÜ
WAVE ¥Õ¥¡¥¤¥ëºÆÀ¸¥¹¥ì¥Ã¥É¤Ç»ÈÍѤ¹¤ëÊÑ¿ô¤ò°ì¤Ä¤Î¹½Â¤ÂΤˤޤȤá¤ÆÄêµÁ¤·¤¿¾å¤Ç¡¢¥Õ¥¡¥¤¥ë¥¹¥³¡¼¥×¤ò»ý¤Ä context ÊÑ¿ô¤òÀë¸À¤·¤Æ¤¤¤Þ¤¹¡£LECTURE 12 Ê£¿ô¤Î²»¤ò¤¹Ã±½ã¥ß¥¥µ ¤Î¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤ÎÆâÍƤˡ¢pan ¤È¤¤¤¦¥á¥ó¥Ð¤òÄɲ䷤Ƥ¤¤Þ¤¹¡£¥³¥á¥ó¥È¤ÎÄ̤ꡢpan ¤Ï PAN_MIN (0) ¤«¤é PAN_MAX (256) ¤ÎÃͤ¬ÀßÄꤵ¤ì¤Þ¤¹¡£PAN_MIN ¤Î¾ì¹ç¤Ï L ¥Á¥ã¥ó¥Í¥ë¤Î¤ß¡¢PAN_MAX ¤Î¾ì¹ç¤Ï R ¥Á¥ã¥ó¥Í¥ë¤Î¤ß¤Î²»¤ò°ÕÌ£¤·¤Þ¤¹¡£
- 63 ¡Á 103 ¹ÔÌÜ ( main() )
pan.c ¤Î main ´Ø¿ô¤Ç¤¹¡£³Æ½èÍý¤Ë¤Ä¤¤¤Æ°Ê²¼¤ÇÀâÌÀ¤·¤Æ¤¤¤¤Þ¤¹¡£
- 74 ¡Á 82 ¹ÔÌÜ
74 ¡Á 77 ¹ÔÌܤǡ¢»ØÄꤵ¤ì¤¿ WAVE ¥Õ¥¡¥¤¥ë¤òÆɤ߹þ¤à¼«ºî´Ø¿ô read_file() ¤ò¼Â¹Ô¤·¤Æ¤¤¤Þ¤¹¡£LECTURE 12 Ê£¿ô¤Î²»¤ò¤¹Ã±½ã¥ß¥¥µ ¤Î¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤Î read_file() ¤È¤Ï¡¢°ì¤Ä¤Î¥Õ¥¡¥¤¥ë¤Î¤ß¤òÆɤ߹þ¤à°Ê³°¤ÏƱ¤¸¤Ç¤¹¡£
¤½¤Î¸å 79 ¡Á 82 ¹ÔÌܤǡ¢¼«ºî´Ø¿ô setup_dsp() ¤ò¼Â¹Ô¤·¡¢/dev/dsp ¤Î½é´ü²½¤ò¹Ô¤Ã¤Æ¤¤¤Þ¤¹¡£Á°²ó¤Î¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤Î setup_dsp() ¤È¤Ï¡¢¥Ç¥Ð¥¤¥¹¤ÎÀßÄê¤ò 2 ¥Á¥ã¥ó¥Í¥ë¤Ë¸ÇÄꤷ¤Æ¤¤¤ëÅÀ¤Î¤ß°Û¤Ê¤ê¤Þ¤¹¡£¤³¤ì¤Ï¡¢1 ¥Á¥ã¥ó¥Í¥ë¤Î WAVE ¥Õ¥¡¥¤¥ë¥Ç¡¼¥¿¤«¤é LR ¤Î 2 ¥Á¥ã¥ó¥Í¥ë¤Ë²»Î̤ò¿¶¤êʬ¤±¤ÆºÆÀ¸¤¹¤ë¤¿¤á¤Ç¤¹¡£
- 84 ¡Á 103 ¹ÔÌÜ
Á°²ó¤Î¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤ÈÁ´¤¯Æ±¤¸¤Ç¤¹¡£
- 265 ¡Á 294 ¹ÔÌÜ ( show_menu() )
¶ñÂÎŪ¤Ê¥³¥Þ¥ó¥É¤¬°Û¤Ê¤ë°Ê³°¤Ï¡¢Á°²ó¤Î¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤ÈƱ¤¸¤Ç¤¹¡£
- 297 ¡Á 332 ¹ÔÌÜ ( play_thread() )
WAVE ¥Õ¥¡¥¤¥ëºÆÀ¸¥¹¥ì¥Ã¥É¤Î¼Â¹Ô´Ø¿ô¤Ç¤¹¡£Á°²ó¤Î¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤È¤Ï¡¢²»¤Î²Ã»»¤ò¹Ô¤ï¤Ê¤¤¤³¤È¤È¡¢fill_buffer() ¤Ë¤è¤Ã¤ÆºÆÀ¸ÍѥХåե¡¤Ë WAVE ¥Õ¥¡¥¤¥ë¥Ç¡¼¥¿¤òžÁ÷¤¹¤ëºÝ¤Ë¡¢º¸±¦¤Î²»Î̤òÄ´À°¤¹¤ë¤¿¤á¤Î context->pan ÊÑ¿ô¤òÁàºî¤·¤Æ¤¤¤ëÅÀ¤Ç¤¹¡£
307 ¡Á 321 ¹ÔÌܤˤª¤¤¤Æ¡¢¤Þ¤º context->pan ¤ÎÃͤò¹¹¿·¤·¤¿¾å¤Ç fill_buffer() ¤Ë¤è¤êºÆÀ¸ÍѥХåե¡¤Ë WAVE ¥Õ¥¡¥¤¥ë¥Ç¡¼¥¿¤òžÁ÷¤·¤Æ¤¤¤Þ¤¹¡£context->pan ¤ÏºÇ½é¤Ï 0 ¤«¤é»Ï¤Þ¤ê¡¢PAN_MAX ¤ËÅþ㤹¤ë¤Þ¤Ç¤Ï PAN_STEP ¤º¤ÄÁý²Ã¤·¤Æ¤¤¤¤Þ¤¹¡£PAN_MAX ¤ËÅþ㤷¤¿°Ê¹ß¤Ï¡¢PAN_MIN (0) ¤Ë¤Ê¤ë¤Þ¤Ç PAN_STEP ¤º¤Ä¸º¾¯¤·¤Æ¤¤¤¤Þ¤¹¡£¤³¤ì¤Ï¤Ä¤Þ¤ê¡¢ºÇ½é¤Ïº¸¥Á¥ã¥ó¥Í¥ë¤Î¤ß¤«¤é²»¤¬½ÐÎϤµ¤ì¡¢¼¡Âè¤Ë±¦¥Á¥ã¥ó¥Í¥ë¤Î¤ß¤Ë°ÜÆ°¤·¤Æ¤¤¤¯¤³¤È¤òɽ¤·¤Æ¤¤¤Þ¤¹¡£
- 335 ¡Á 375 ¹ÔÌÜ ( fill_buffer() )
»ØÄê¥Ð¥Ã¥Õ¥¡ ( dst ) ¤Ë WAVE ¥Õ¥¡¥¤¥ë¥Ç¡¼¥¿¤òžÁ÷¤·¤Þ¤¹¡£
Á°²ó¤Î¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤È¤Ï¡¢362 ¡Á 370 ¹ÔÌܤˤưìÅٴؿôÆâÉô¤Î¥Ð¥Ã¥Õ¥¡¤Ë WAVE ¥Õ¥¡¥¤¥ë¥Ç¡¼¥¿¤òžÁ÷¤·¡¢¤½¤³¤«¤é dst ¤Îº¸±¦¤Î¥Á¥ã¥ó¥Í¥ë¤Ë¿¶¤êʬ¤±¤Æ¤¤¤ëÅÀ¤¬°Û¤Ê¤ê¤Þ¤¹¡£
2 ¥Á¥ã¥ó¥Í¥ë¤Î¾ì¹ç¡¢²»À¼¥Ç¡¼¥¿¤Ï LRLRLR... ¤Î½ç¤ËʤӤޤ¹¡£¤è¤Ã¤Æ 366 ¡Á 367 ¹ÔÌܤǺ¸¥Á¥ã¥ó¥Í¥ëÍѥǡ¼¥¿¤òºîÀ®¤·¡¢368 ¡Á 369 ¹ÔÌܤDZ¦¥Á¥ã¥ó¥Í¥ëÍѥǡ¼¥¿¤òºîÀ®¤·¤Æ¤¤¤Þ¤¹¡£¤½¤ì¤¾¤ì¤Î¥Ç¡¼¥¿¤Ï°Ê²¼¤ÎÍͤˤ·¤Æ·×»»¤·¤Þ¤¹¡£
º¸ : ÆþÎϥǡ¼¥¿ * ( PAN_MAX - pan ) / PAN_MAX; ±¦ : ÆþÎϥǡ¼¥¿ * pan / PAN_MAX;
¤³¤ì¤Ë¤è¤ê¡¢pan == PAN_MIN (0) ¤Î¾ì¹ç¤Ë¤Ï
º¸ : ÆþÎϥǡ¼¥¿ ±¦ : 0
¤È¤Ê¤ê¡¢pan == PAN_MAX ¤Î¾ì¹ç¤Ë¤Ï
º¸ : 0 ±¦ : ÆþÎϥǡ¼¥¿
¤È¤Ê¤ê¤Þ¤¹¡£
- 378 ¡Á 383 ¹ÔÌÜ ( shutdown() )
¥ê¥½¡¼¥¹²òÊü½èÍý¤Ç¤¹¡£WAVE ¥Õ¥¡¥¤¥ë¤Î¥Õ¥¡¥¤¥ë¥Ý¥¤¥ó¥¿¤ò²òÊü¤·¡¢/dev/dsp ¤â²òÊü¤·¤Æ¤¤¤Þ¤¹¡£
°Ê¾å¤Ç pan.c ¤ÎÀâÌÀ¤Ï½ª¤ï¤ê¤Ç¤¹¡£