File: gen_test.c

package info (click to toggle)
xwave 0.6%2B2-10
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,908 kB
  • ctags: 2,026
  • sloc: ansic: 15,177; perl: 345; makefile: 75; sh: 63
file content (67 lines) | stat: -rw-r--r-- 1,313 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <sys/types.h>

#include "audiofile.h"

#define LENGTH 5000

void main (int argc,char *argv[])
{
   unsigned char buffer[LENGTH];
   short *buf16;
   Audio_File af;
   int i,j;
   float factor;
   
   if (argc<2) return;
   
   af.fd=-1;
   af.bps=8;
   af.channels=1;
   af.comp=AF_PCM;
   af.type=AF_RIFF;
   af.freq=22050;
   af.length=LENGTH;
   af.headoffs=-1;

   /*
   factor=255.0/(float) (LENGTH/2);
   for (i=0;i<LENGTH/2;i++) buffer[i]=(char) (factor*(float)i);
   for (i=LENGTH/2,j=LENGTH;i<LENGTH;i++,j--) 
     buffer[i]=(char) (factor*(float)j);
    */
   
   for (i=0;i<=LENGTH/3;i++) buffer[i]=0;
   for (i=LENGTH/3;i<LENGTH-LENGTH/3;i++) buffer[i]=255;
   for (i=LENGTH-LENGTH/3;i<LENGTH;i++) buffer[i]=0;
   
   
   /*   
   buf16=(short*) buffer;
   for (i=0;i<LENGTH/2;i++) buf16[i]=0;

   buf16[LENGTH/2-1]=30000;
   buf16[LENGTH/2-2]=-10000;
   

   buffer[LENGTH-2]=30;
   buffer[LENGTH-1]=230;
   */
   
   if (af_open(argv[1],&af,AF_NEW)==AF_ERROR) {
      fprintf(stderr,"Couldn't open file %s !\n",argv[1]);
      return;
   }
  
   if (af_write(af,buffer,LENGTH) == AF_ERROR) {
      fprintf(stderr,"Couldn't write file %s !\n",argv[1]);
   }
   
   af_close(af);
   return;
}