⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vplay.c

📁 mips cpu 君正4730 4740的 ucosii 源码 包括系统 摄像头 网络 文件系统等等测试
💻 C
📖 第 1 页 / 共 2 页
字号:
          set_dsp_speed (&dsp_speed);          silence = ( ((u_long)*sp) * 1000) / dsp_speed;           d_printf ((stderr, "Silence for %ld ms\n", silence));          write_zeros (*sp);          break;        case 4:			/* a marker for syncronisation, no effect */          sp = (u_short *)data; COUNT(sizeof(u_short));          d_printf ((stderr, "Marker %d\n", *sp));           break;        case 5:			/* ASCII text, we copy to stderr */          output = 1;          d_printf ((stderr, "ASCII - text :\n"));          break;         case 6:			/* repeat marker, says repeatcount */          /* my specs don't say it: maybe this can be recursive, but             I don't think somebody use it */          repeat = *(u_short *)data; COUNT(sizeof(u_short));          d_printf ((stderr, "Repeat loop %d times\n", repeat));          if (filepos >= 0)	/* if < 0, one seek fails, why test another */            if ( (filepos = lseek (fd, 0, 1)) < 0 ) {              fprintf(stderr, "%s: can't play loops; %s isn't seekable\n",                       command, name);              repeat = 0;            }            else              filepos -= in_buffer;	/* set filepos after repeat */          else            repeat = 0;          break;        case 7:			/* ok, lets repeat that be rewinding tape */          if (repeat) {            if (repeat != 0xFFFF) {              d_printf ((stderr, "Repeat loop %d\n", repeat));              --repeat;            }            else              d_printf ((stderr, "Neverending loop\n"));            lseek (fd, filepos, 0);            in_buffer = 0;		/* clear the buffer */            goto Fill_the_buffer;          }          else            d_printf ((stderr, "End repeat loop\n"));          break;        case 8:			/* the extension to play Stereo, I have SB 1.0 :-( */          was_extended = 1;          eb = (Ext_Block *)data; COUNT(sizeof(Ext_Block));          dsp_speed = (int)(eb->tc);          dsp_speed = 256000000L / (65536 - dsp_speed);          dsp_stereo = eb->mode;          if (dsp_stereo == MODE_STEREO)             dsp_speed = dsp_speed >> 1;          if (eb->pack) {     /* /dev/dsp can't it */            fprintf (stderr, "%s: can't play packed .voc files\n", command);            return;          }          d_printf ((stderr, "Extended block %s %d Hz\n", 				(eb->mode ? "Stereo" : "Mono"), dsp_speed));          break;        default:          fprintf (stderr, "%s: unknown blocktype %d. terminate.\n",                    command, bp->type);          return;      } 		/* switch (bp->type) */    }			/* while (! nextblock)  */    /* put nextblock data bytes to dsp */    l = min (in_buffer, nextblock);    if (l) {        if (output && !quiet_mode)        write (2, data, l);	/* to stderr */      else {        real_l = one_chn ? one_channel(data, l, one_chn, 0) : l;        if (write (audio, data, real_l) != real_l) {//          perror (AUDIO);          exit(-1);        }      }      COUNT(l);    }  }			/* while(1) */}/* that was a big one, perhaps somebody split it :-) *//* setting the globals for playing raw data */void init_raw_data(void){  timelimit  = raw_info.timelimit;  dsp_speed  = raw_info.dsp_speed;  dsp_stereo = raw_info.dsp_stereo;  samplesize = raw_info.samplesize;}/* calculate the data count to read from/to dsp */u_long calc_count(void){  u_long count;  if (!timelimit)    count = 0x7fffffff;  else {    count = timelimit * dsp_speed;    if (dsp_stereo)      count *= 2;    if (samplesize != 8)      count *= 2;  }  return count;}/* write a .VOC-header */ void start_voc(int fd, u_long cnt){  VocHeader  vh;  BlockType  bt;  Voice_data vd;  Ext_Block  eb;   strcpy((char *)vh.magic,MAGIC_STRING);  vh.headerlen = sizeof(VocHeader);  vh.version = ACTUAL_VERSION;  vh.coded_ver = 0x1233 - ACTUAL_VERSION;  write (fd, &vh, sizeof(VocHeader));  if (dsp_stereo) {    /* write a extended block */    bt.type = 8;    bt.datalen = 4;    bt.datalen_m = bt.datalen_h = 0;    write (fd, &bt, sizeof(BlockType));    eb.tc = (u_short)(65536 - 256000000L / (dsp_speed << 1));    eb.pack = 0;    eb.mode = 1;    write (fd, &eb, sizeof(Ext_Block));  }  bt.type = 1;  cnt += sizeof(Voice_data);	/* Voice_data block follows */  bt.datalen   = (u_char)  (cnt & 0xFF);  bt.datalen_m = (u_char)( (cnt & 0xFF00) >> 8 );  bt.datalen_h = (u_char)( (cnt & 0xFF0000) >> 16 );  write (fd, &bt, sizeof(BlockType));  vd.tc = (u_char)(256 - (1000000 / dsp_speed) );  vd.pack = 0;  write (fd, &vd, sizeof(Voice_data) );} /* write a WAVE-header */void start_wave(int fd, u_long cnt){  WaveHeader wh;  wh.main_chunk = RIFF;  wh.length     = cnt + sizeof(WaveHeader) - 8;   wh.chunk_type = WAVE;  wh.sub_chunk  = FMT;  wh.sc_len     = 16;  wh.format     = PCM_CODE;  wh.modus      = dsp_stereo ? 2 : 1;  wh.sample_fq  = dsp_speed;  wh.byte_p_spl = ((samplesize == 8) ? 1 : 2) * (dsp_stereo ? 2 : 1);  wh.byte_p_sec = dsp_speed * wh.modus * wh.byte_p_spl;  wh.bit_p_spl  = samplesize;  wh.data_chunk = DATA;  wh.data_length= cnt;  write (fd, &wh, sizeof(WaveHeader));}/* closing .VOC */void end_voc(int fd){  char dummy = 0;		/* Write a Terminator */  write (fd, &dummy, 1);  if (fd != 1)    close (fd);}void end_wave_raw(int fd){				/* only close output */  if (fd != 1)    close (fd);}void start_snd (int fd, u_long count){  SndHeader snd;  char *sndinfo = "Recorded by vrec\000";  snd.magic = SND_MAGIC;  snd.dataLocation = sizeof(SndHeader) + strlen(sndinfo);  snd.dataSize = count;  switch(samplesize){  case 8:    snd.dataFormat = SND_FORMAT_LINEAR_8;    break;  case 16:    snd.dataFormat = SND_FORMAT_LINEAR_16;    break;  default:    fprintf(stderr,"%d bit: unsupported sample size for NeXt sound file!\n", 	    samplesize);    exit (-1);  }  snd.samplingRate = dsp_speed;  snd.channelCount = dsp_stereo ? 2 : 1;  write(fd, &snd, sizeof(SndHeader));  write(fd, sndinfo, strlen(sndinfo));}void end_snd (int fd){  if (fd != 1)    close (fd);}/* playing/recording raw data, this proc handels WAVE files and   recording .VOCs (as one block) */ unsigned char recram[1024 * 1024 * 6];void recplay (int fd, int loaded, u_long count, int rtype, char *name){  int l, real_l;  u_long c;  char one_chn = 0;  char to_8 = 0;  u_long recCount = 0;  abuf_size = 1024 * 8;  sync_dsp();    if (direction == PLAY) {	  if(rtype == WAVE_FMT){		   pcm_ioctl(PCM_SET_SAMPLE_RATE,dsp_speed);		  if(dsp_stereo==0){			  pcm_ioctl(PCM_SET_CHANNEL, 1);		  }else{			  pcm_ioctl(PCM_SET_CHANNEL, 2);		  }		  		  if(samplesize == 8 ){			  pcm_ioctl(PCM_SET_FORMAT, AFMT_U8);			  		  }else{			  //pcm_ioctl(PCM_SET_FORMAT, AFMT_U8);			  pcm_ioctl(PCM_SET_FORMAT,  AFMT_S16_LE);		  }	  }	  else{		  pcm_ioctl(PCM_SET_SAMPLE_RATE,48000);	  }  } if (!quiet_mode) {	 printf ("%s %s : ", 		  (direction == PLAY) ? "Playing" : "Recording",		  fmt_rec_table[rtype].what);	 if (samplesize != 8)		 printf( "%d bit, ", samplesize);	 printf ( "Speed %d Hz ", dsp_speed);	 printf ( "%d bits ", samplesize);	 printf ( "%s ...\n", dsp_stereo ? "Stereo" : "Mono"); }   if (direction == PLAY) {	   abuf_size = 0x1000 * 2;	  while (count) {		  c = count;		  if (c > abuf_size)			  	  c = abuf_size;		  if ( FS_FRead(audiobuf,1,c,myfile) > 0 ) {			  l += c; loaded = 0;	/* correct the count; ugly but ... */			  if (pcm_write(audiobuf,c) == -1) {				  return -1;			  }			  count -= l;		  }		  else{			  if (l == -1) { 				  perror (name);				  exit (-1);			  }			  count = 0;	/* Stop */		  }	  }			/* while (count) */  } else {		/* we are recording */	 abuf_size = 1024 * 4 * 2;	 while (count) {		 c = count;		 if (c > abuf_size)		 	 c = abuf_size;		 #if 0		 //if ((l = pcm_read ((char *)audiobuf, c)) > 0) {		 if ((l = pcm_read ((char *)(recram + recCount), c)) > 0) {//	 	 printf("read daata--%x-%x-%x-%x!\n",recram[recCount-4],recram[recCount-3],recram[recCount-2],recram[recCount-1]);			 recCount += l;			 if(recCount > 1 * 1024 * 1024 )				 break;            #if 0			 if (FS_FWrite (audiobuf,1,l,myfile) != l) {				 printf("can not write to File %s!!",fd);						 }			 #endif			 count -= l;			 		 }		 #endif		 printf("record audio start\r\n");		 		 l = pcm_read((char *)recram, 1024 * 1024);		 recCount = l;		 		 count = 0; 		 if (l == -1) {			 printf("Error write to File %s!!",fd);		 }	 }			/* While count */	 IS_WRITE_PCM=1;	 pcm_init();	 l=0;	 printf("Start palying voice ...\n");	 pcm_write(recram,recCount);	 printf("Finish palying voice!\n"); }}/*  let's play or record it (record_type says VOC/WAVE/raw)*/void record_play(char *name,int dir){  int fd, ofs;  audiobuf = (unsigned char*) audiobuf1;  if(dir==1)	  direction = PLAY;  else	  direction = RECORD;   if (direction == PLAY) { 	  myfile = FS_FOpen(name,"r");	  printf("file open %x\r\n",myfile); 	  if (myfile) {		  /* read SND-header */		  FS_FRead(audiobuf,1,sizeof(WaveHeader),myfile);		  /* read bytes for WAVE-header */		  if (test_wavefile (audiobuf) >= 0)			  recplay (myfile,0, count, WAVE_FMT, name);		  else {			  /* should be raw data */			  init_raw_data();			  count = calc_count();			  recplay (fd, sizeof(WaveHeader), count, RAW_DATA, name);		  }	  }	  	  if (myfile != 0)		  FS_FClose(myfile);  }  else {		/* recording ... */	  if (!name) {		  fd = 1;		  name = "stdout";	  }	  else {		  //	  myfile = FS_FOpen(name,"wb");		  //		  if (!myfile) {		  //			  printf("can not open %s",name);		  //	  }	  }	  count = calc_count() & 0xFFFFFFFE;	  /* WAVE-file should be even (I'm not sure), but wasting one byte	     isn't a problem (this can only be in 8 bit mono) */	  // if (fmt_rec_table[record_type].start)	  //	  fmt_rec_table[record_type].start(fd, count);	  recplay (myfile, sizeof(WaveHeader), count, record_type, name);	  //fmt_rec_table[record_type].end(fd);  }} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -