#include <stdio.h>
#include <stdlib.h>
#define SIZE  (4*44100)    // 1秒の音データ.
int main() {
  FILE *fp2;
  unsigned char 
       h[44]={0x52,0x49,0x46,0x46,   /* 識別子 RIFF を ascii code で */
              0x84,0x56,0x8,0x0,     /* ファイルサイズ-8. [可変] */ 
              0x57,0x41,0x56,0x45,   /* 識別子 WAVE を ascii code で */ 
              0x66,0x6d,0x74,0x20,   /* fmt を ascii code で */
              0x10,0x0,0x0,0x0,      /* linear PCM */
              0x1,0x0,               /* linear PCM */ 
              0x2,0x0,               /* stereo */
              0x44,0xac,0x0,0x0,     /* sampling rate = 44100 = 0xac44 */
              0x10,0xb1,0x2,0x0,     /* byte per second, 44100*4 */
              0x4,0x0,               /* 16 bit, stereo */
              0x10,0x0,              /* bit/sample, 16 bit */      
              0x64,0x61,0x74,0x61,   /* 識別子 data を ascii code で */
              0xb8,0x55,0x8,0x0};    /* 以下のデータ部分のファイルサイズ. [可変] */
  unsigned char data[SIZE];
  int c;
  int i;
  int filesize = (44+SIZE)-8;
  int datasize = SIZE;
  fp2 = fopen("mysound.wav","w");
  h[4] = filesize % 0x100; h[5] = (filesize/0x100) % 0x100;
  h[6] = (filesize/0x10000) % 0x100; h[7] = (filesize/0x1000000) % 0x100;
  h[40] = datasize % 0x100; h[41] = (datasize/0x100) % 0x100;
  h[42] = (datasize/0x10000) % 0x100; h[43] = (datasize/0x1000000) % 0x100;

  /* set data in the array data */
  for (i=0; i<SIZE; i++) data[i] = random()%0x100;

  for (i=0; i<44; i++) fputc(h[i],fp2);
  for (i=0; i<SIZE; i++) fputc(data[i],fp2);
  fclose(fp2);
}

/*
  WAVE ファイルの形式 [WAVE file format] で検索.
*/

