예제 #1
0
int main(int argc, char **argv) {
  FILE *fpin, *fpout;
  short int data[2];
  int smpl, diff;
  short int ch, bs, bps;
  unsigned int ds;
  unsigned long start, end;
  double s_sec, e_sec;

 /* コマンドライン引数が正しく与えられなかった場合 */
  if(argc != 3) {
    printf("usage: %s <infile.wav> <outfile.dat>\n", argv[0]);
    exit(1);
  }

  /* 入力音声ファイルオープン */  
  fpin = fopen(argv[1], "rb");
  if(fpin == NULL) {
    printf("%s not found.\n", argv[1]);
    exit(1);
  }

  /* wavファイルのヘッダをダンプし, 秒数を求める */
  dump_wav(fpin, &ch, &smpl, &bs, &bps, &ds);

  /* 出力テキストファイルオープン */
  fpout = fopen(argv[2], "w");

  printf("start: ");
  scanf("%lf", &s_sec);
  start = s_sec * 44100 * 2;
  if(start % 2 != 0) start++;

  printf("end: ");
  scanf("%lf", &e_sec);
  end = e_sec * 44100 * 2;

  fseek(fpin, start, SEEK_CUR);
  printf("position: %ld\n", ftell(fpin));
  while(ftell(fpin) < end) {
    fread((void *)data, sizeof(short), 2, fpin);
    diff = data[1] - data[0];
    fprintf(fpout, "%d\n", diff);
    //fwrite((void *)&diff, sizeof(int), 1, fpout);
    fseek(fpin, -2, SEEK_CUR);
  }
  fclose(fpin);
  fclose(fpout);
  return 0;
}
예제 #2
0
int main() {
  int n,m,res;
  Sint16 buf[NB_SAMPLE],
         val1,val2;
  res=init_dump_wav("out.wav");
  printf("init:%d\n",res);
  for (n=val1=val2=0;n<30;++n) {
    for (m=0;m<NB_SAMPLE;m+=2) {
      val1=(val1+6)%628; // 100 * 2 * PI = 628
      val2=(val2+9)%628;
      buf[m]=Sint16(10000. * sin(val1/100.));
      buf[m+1]=Sint16(10000. * sin(val2/100.));
    }
    res=dump_wav((char*)buf,NB_SAMPLE*2);
    if (!res) break;
  }
  printf("dump:%d\n",res);
  res=close_dump_wav();
  printf("close:%d\n",res);
}
예제 #3
0
void sb16_play(WAVE_HDR* wave)
{
	ULONG MappedIrq;
	KIRQL Dirql;
	KAFFINITY Affinity;
	PKINTERRUPT IrqObject;
	unsigned int newmask;

	unsigned int i;
	unsigned int tmp[255];
	i=0;
	dump_wav(wave);
  	do
  	{
//  		tmp[i++]=get_dma_page(0x0fffff);
//			DPRINT1("0x%x ",tmp[i-1]);
  	}
  	while((tmp[i-1]&0xffff)!=0);
  			// free_page((tmp[0]),i-1);
  	sb16.buffer=((unsigned char*)tmp[i-1]);

   /*
    * Because this is used by alomost every subsystem including irqs it
    * must be atomic. The following code sequence disables interrupts after
    * saving the previous state of the interrupt flag
    */

   	_disable();

       memcpy(sb16.buffer,(&wave->data),wave->dLen);


				MappedIrq = HalGetInterruptVector(Internal,0,0,8+sb16.irq,&Dirql,&Affinity);



				IoConnectInterrupt(&IrqObject,DMAOutputISR,0,NULL,MappedIrq,Dirql,Dirql,0,FALSE,Affinity,FALSE);

	// mask=inb(0x21);
	newmask=((int)1<<sb16.irq);
	// outb(0x21,(mask&~newmask));

       // Restore the interrupt flag
	_enable();



	// disable_dma(sb16.dma8);
	//outb(0x0a,5);
	// clear_dma_ff(1);
	//outb(0xc,0);
	// set_dma_count(1,wave->dLen);
	//set_dma_mode(1,DMA_MODE_WRITE);
	//outb(0xb,0x49);
	//outb(0x3,(wave->dLen)&0xff);
	//outb(0x3,((unsigned int)(wave->dLen)>>8)&0xff);
	//set_dma_addr(sb16.dma8,(unsigned int)sb16.buffer);
	//outb(0x83,(((unsigned int)(sb16.buffer-IDMAP_BASE)>>16))&0xf);
	//outb(0x2,((unsigned int)sb16.buffer&0xff));
	//outb(0x2,(((unsigned int)(sb16.buffer-IDMAP_BASE)>>8))&0xff);
	//enable_dma(sb16.dma8);
	//outb(0xa,1);

	write_dsp(sb16.base,0x00D1);

	write_dsp(sb16.base,0x40);
	write_dsp(sb16.base,((unsigned char)256-(1000000/wave->nSamplesPerSec)));

//  outb(sb16.base + 4, (int) 0xa);
//  outb(sb16.base + 5, (int) 0x00);

//  outb(sb16.base + 4, (int) 4);
//  outb(sb16.base + 5, (int) 0xFF);

//  outb(sb16.base + 4, (int) 0x22);
//  outb(sb16.base + 5, (int) 0xFF);

	write_dsp(sb16.base,0x14);
	write_dsp(sb16.base,(wave->dLen&0x00ff));
	write_dsp(sb16.base,((wave->dLen)&0xff00)>>8);

//	write_dsp(sb16.base,0xc0);
//	write_dsp(sb16.base,0x0);
//	OldIRQ=HalGetInterruptVector(Internal,0,0,irq+8,&irql,&affinity);
//	DPRINT1("OldIRQ: 0x%x\n",OldIRQ);

//  status=IoConnectInterrupt(&IrqObject,playRoutine,0,NULL,OldIRQ,irql,irql,0,FALSE,affinity,FALSE);
//  if(status!=STATUS_SUCCESS) DPRINT1("Couldn't set irq\n");
//  else DPRINT1("IRQ set\n");

}