File: mksndinclude.c

package info (click to toggle)
cwirc 2.0.0-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 640 kB
  • ctags: 589
  • sloc: ansic: 5,423; makefile: 292
file content (74 lines) | stat: -rw-r--r-- 1,483 bytes parent folder | download | duplicates (6)
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
68
69
70
71
72
73
74
/* This program takes a mono / 16 bit WAV file on its standard input and
   generate a C include file on its standard output containing all the samples.
   It does not do any error checking : if the format isn't exactly the one
   above, the resulting samples in the include file will be wrong. The name of
   the resulting resulting variable defined in the include file is passed as
   first argument.

   (c) Pierre-Philippe Coupard - 15/08/2003

   This program is distributed under the terms of the GNU General Public License
   See the COPYING file for details
*/
#include <stdio.h>

#include "types.h"



/* Main program */
int main(int argc,char *argv[])
{
  T_BOOL little_endian=0;
  T_U8 c1,c2;
  T_S16 sample;
  T_U8 *sptr;
  long sampleno=0;
  int i;

  sptr=(T_U8 *)&sample;

  /* Do the endianness test */
  i=1;
  if(((char *)&i)[0])
    little_endian=1;

  /* Read and ignore 44 bytes (the header) */
  for(i=0;i<44;i++)
    getc(stdin);

  printf("static const T_S16 %s[]={\n",argv[1]);

  /* Read and convert the samples */
  while(!feof(stdin))
  {
    c1=getc(stdin);
    c2=getc(stdin);

    if(little_endian)
    {
      sptr[0]=c1;
      sptr[1]=c2;
    }
    else
    {
      sptr[0]=c2;
      sptr[1]=c1;
    }

    if(sampleno>0)
    {
      printf(",");
      if(sampleno%8==0)
        printf("\n");
    }

    printf("%d",sample);
    sampleno++;
  }
  printf("};\n\n");

  printf("static const long %s_nbsamples=%ld;\n",argv[1],sampleno);

  return(0);
}