diff -crN alsa-utils-1.0.14rc4/aplay/aplay.c alsa-utils-1.0.14rc4-new/aplay/aplay.c
*** alsa-utils-1.0.14rc4/aplay/aplay.c	2007-05-02 17:04:48.000000000 +0900
--- alsa-utils-1.0.14rc4-new/aplay/aplay.c	2008-08-13 05:38:56.000000000 +0900
***************
*** 101,106 ****
--- 101,111 ----
  static size_t chunk_bytes;
  static snd_output_t *log;
  
+ /* --- 2008/08/12 Silence Sensor by Masashi Ito (maitou) --- */
+ #define DEF_MAITOU_BANNER  "maitou"
+ static silence_tshold = 50;
+ static silence_number = 10;
+ 
  static int fd = -1;
  static off64_t pbrec_count = LLONG_MAX, fdcount;
  static int vocmajor, vocminor;
***************
*** 175,181 ****
  "                        (relative to buffer size if <= 0)\n"
  "-T, --stop-delay=#      delay for automatic PCM stop is # microseconds from xrun\n"
  "-v, --verbose           show PCM structure and setup (accumulative)\n"
! "-I, --separate-channels one file for each channel\n")
  		, command);
  	printf(_("Recognized sample formats are:"));
  	for (k = 0; k < SND_PCM_FORMAT_LAST; ++k) {
--- 180,190 ----
  "                        (relative to buffer size if <= 0)\n"
  "-T, --stop-delay=#      delay for automatic PCM stop is # microseconds from xrun\n"
  "-v, --verbose           show PCM structure and setup (accumulative)\n"
! "-I, --separate-channels one file for each channel\n"
! "\n Silence Sensor for Recording by Masashi Ito (maitou) 2008/08/12\n"
! "  -S, --silence-detect=#\tsilence detect ON (threshold, def=50)\n"
! "  -n, --silence-number=#\trepeat number (def=10)\n\n"
! )
  		, command);
  	printf(_("Recognized sample formats are:"));
  	for (k = 0; k < SND_PCM_FORMAT_LAST; ++k) {
***************
*** 366,371 ****
--- 375,382 ----
  		{"separate-channels", 0, 0, 'I'},
  		{"playback", 0, 0, 'P'},
  		{"capture", 0, 0, 'C'},
+ 		{"silence-detect", 1, 0, 'S'},
+ 		{"silence-number", 1, 0, 'n'},
  		{0, 0, 0, 0}
  	};
  	char *pcm_name = "default";
***************
*** 525,530 ****
--- 536,549 ----
  			if (file_type == FORMAT_DEFAULT)
  				file_type = FORMAT_WAVE;
  			break;
+ 
+ 		case 'S':
+ 			silence_tshold = (strtol(optarg, NULL, 0) > UCHAR_MAX) ? UCHAR_MAX : strtol(optarg, NULL, 0);
+ 			break;
+ 		case 'n':
+ 			silence_number = (strtol(optarg, NULL, 0) > UCHAR_MAX) ? UCHAR_MAX : strtol(optarg, NULL, 0);
+ 			break;
+ 
  		default:
  			fprintf(stderr, _("Try `%s --help' for more information.\n"), command);
  			return 1;
***************
*** 2090,2101 ****
--- 2109,2124 ----
  
  static void capture(char *orig_name)
  {
+ 
  	int tostdout=0;		/* boolean which describes output stream */
  	int filecount=0;	/* number of files written */
  	char *name = orig_name;	/* current filename */
  	char namebuf[PATH_MAX+1];
  	off64_t count, rest;		/* number of bytes to capture */
  
+ 	/* --- 2008/08/12 Silence Sensor by Masashi Ito (maitou) --- */
+ 	int i;
+ 
  	/* get number of bytes to capture */
  	count = calc_count();
  	if (count == 0)
***************
*** 2152,2166 ****
  
  		/* capture */
  		fdcount = 0;
  		while (rest > 0) {
  			size_t c = (rest <= (off64_t)chunk_bytes) ?
  				(size_t)rest : chunk_bytes;
  			size_t f = c * 8 / bits_per_frame;
  			if (pcm_read(audiobuf, f) != f)
  				break;
  			if (write(fd, audiobuf, c) != c) {
! 				perror(name);
! 				exit(EXIT_FAILURE);
  			}
  			count -= c;
  			rest -= c;
--- 2175,2257 ----
  
  		/* capture */
  		fdcount = 0;
+ 
+ 		/*
+ 		 * 
+ 		 * 2008/08/12 Silence Sensor by Masashi Ito (maitou)
+ 		 *
+ 		 */
+ 		int isSilence;
+ 		int firstSilence = 1;
+ 		int silenceCount = 0;
+ 
  		while (rest > 0) {
  			size_t c = (rest <= (off64_t)chunk_bytes) ?
  				(size_t)rest : chunk_bytes;
  			size_t f = c * 8 / bits_per_frame;
  			if (pcm_read(audiobuf, f) != f)
  				break;
+ 
+ 			for( i=0, isSilence=1; i<=c; i++ ){
+ 			  if( audiobuf[i] > silence_tshold && audiobuf[i] < (UCHAR_MAX - silence_tshold) ){
+ 			    isSilence = 0;	// 音あり
+ 			    break;
+ 			  }
+ 			}
+ 
+ 
+ 			if( isSilence ){
+ 
+ 			  /*
+ 			   * --- 無音 ---
+ 			   */
+ 			  silenceCount++;
+ 
+ 			  /* 初期無音 */
+ 			  if( firstSilence ){
+ #ifdef	 DEBUG
+ 			    if( silenceCount <= 1 ){
+ 			      fprintf( stderr, "%s: first silence.\n", DEF_MAITOU_BANNER );
+ 			    }
+ 			    continue;				/* 記録せず継続 */
+ #endif /*DEBUG*/
+ 			  }
+ 
+ 			  /* 無音ブロックの回数超過 (分割条件) */
+ 			  if( silenceCount >= silence_number ){
+ 			    fprintf( stderr, "%s: silence blocks over.\n\n", DEF_MAITOU_BANNER );
+ 			    break;				/* 記録せず終了 */
+ 			  }
+ 
+ #ifdef	 DEBUG
+ 			  /* 無音ブロックの検知中 (記録) */
+ 			  fprintf( stderr,"%s: silence block [%d]\n", DEF_MAITOU_BANNER, silenceCount );
+ #endif /*DEBUG*/
+ 
+ 			}else{
+ 
+ 			  /*
+ 			   * --- 音あり ---
+ 			   */
+ 
+ 			  /* 無音期間終了 */
+ 			  silenceCount = 0;
+ 
+ 			  /* 初期無音解除 */
+ 			  if( firstSilence ){
+ #ifdef	 DEBUG
+ 			    fprintf( stderr, "%s: start sound.\n", DEF_MAITOU_BANNER );
+ #endif
+ 			    firstSilence = 0;	/* 初期無音終了 */
+ 			  }
+ 
+ 			}
+ 
+ 
+ 			/* --- ここまで来たらとにかく記録 --- */
  			if (write(fd, audiobuf, c) != c) {
! 			  perror(name);
! 			  exit(EXIT_FAILURE);
  			}
  			count -= c;
  			rest -= c;
***************
*** 2176,2182 ****
  		/* repeat the loop when format is raw without timelimit or
  		 * requested counts of data are recorded
  		 */
! 	} while ((file_type == FORMAT_RAW && !timelimit) || count > 0);
  }
  
  void playbackv_go(int* fds, unsigned int channels, size_t loaded, off64_t count, int rtype, char **names)
--- 2267,2273 ----
  		/* repeat the loop when format is raw without timelimit or
  		 * requested counts of data are recorded
  		 */
! 	} while ( (file_type == FORMAT_RAW && !timelimit) || count > 0 );
  }
  
  void playbackv_go(int* fds, unsigned int channels, size_t loaded, off64_t count, int rtype, char **names)

