annotate TOOLS/alaw-gen.c @ 35253:48db1b241757

Try to do something sensible when malloc fails instead of continuing which is sure to crash.
author reimar
date Mon, 05 Nov 2012 20:45:40 +0000
parents b573c7c7173b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30416
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 26057
diff changeset
1 /*
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 26057
diff changeset
2 * This program is free software; you can redistribute it and/or modify
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 26057
diff changeset
3 * it under the terms of the GNU General Public License as published by
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 26057
diff changeset
4 * the Free Software Foundation; either version 2 of the License, or
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 26057
diff changeset
5 * (at your option) any later version.
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 26057
diff changeset
6 *
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 26057
diff changeset
7 * This program is distributed in the hope that it will be useful,
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 26057
diff changeset
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 26057
diff changeset
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 26057
diff changeset
10 * GNU General Public License for more details.
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 26057
diff changeset
11 *
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 26057
diff changeset
12 * You should have received a copy of the GNU General Public License along
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 26057
diff changeset
13 * with this program; if not, write to the Free Software Foundation, Inc.,
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 26057
diff changeset
14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 26057
diff changeset
15 */
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 26057
diff changeset
16
879
5d00233a4e5b alaw and ulaw table generator
arpi_esp
parents:
diff changeset
17 #include <stdio.h>
5d00233a4e5b alaw and ulaw table generator
arpi_esp
parents:
diff changeset
18 #include <stdlib.h>
5d00233a4e5b alaw and ulaw table generator
arpi_esp
parents:
diff changeset
19
5d00233a4e5b alaw and ulaw table generator
arpi_esp
parents:
diff changeset
20 // sox -t raw -A -r 8000 -b alaw.alaw -t sw alaw.out
5d00233a4e5b alaw and ulaw table generator
arpi_esp
parents:
diff changeset
21
23662
5c5fb6af79d1 Mark main() function as a function that takes no parameters.
diego
parents: 23659
diff changeset
22 int main(void){
879
5d00233a4e5b alaw and ulaw table generator
arpi_esp
parents:
diff changeset
23 int i;
5d00233a4e5b alaw and ulaw table generator
arpi_esp
parents:
diff changeset
24 FILE *f;
5d00233a4e5b alaw and ulaw table generator
arpi_esp
parents:
diff changeset
25
5d00233a4e5b alaw and ulaw table generator
arpi_esp
parents:
diff changeset
26 f=fopen("alaw.dat","wb");
5d00233a4e5b alaw and ulaw table generator
arpi_esp
parents:
diff changeset
27 for(i=0;i<256;i++) fwrite(&i,1,1,f);
5d00233a4e5b alaw and ulaw table generator
arpi_esp
parents:
diff changeset
28 fclose(f);
5d00233a4e5b alaw and ulaw table generator
arpi_esp
parents:
diff changeset
29
5d00233a4e5b alaw and ulaw table generator
arpi_esp
parents:
diff changeset
30 system("sox -t raw -A -r 8000 -b alaw.dat -t sw alaw.out");
5d00233a4e5b alaw and ulaw table generator
arpi_esp
parents:
diff changeset
31
25865
b1316c443f87 Add multiple inclusion guards to generated header file.
diego
parents: 25864
diff changeset
32 printf("// Generated by TOOLS/alaw-gen.c\n\n");
b1316c443f87 Add multiple inclusion guards to generated header file.
diego
parents: 25864
diff changeset
33
26057
044b3c830459 Add MPLAYER_ prefix to multiple inclusion guard of generated file.
diego
parents: 25865
diff changeset
34 printf("#ifndef MPLAYER_ALAW_H\n");
044b3c830459 Add MPLAYER_ prefix to multiple inclusion guard of generated file.
diego
parents: 25865
diff changeset
35 printf("#define MPLAYER_ALAW_H\n");
879
5d00233a4e5b alaw and ulaw table generator
arpi_esp
parents:
diff changeset
36
25863
3bb953467710 The alaw tables should be const.
diego
parents: 23662
diff changeset
37 printf("\nconst short alaw2short[]={\n");
879
5d00233a4e5b alaw and ulaw table generator
arpi_esp
parents:
diff changeset
38
5d00233a4e5b alaw and ulaw table generator
arpi_esp
parents:
diff changeset
39 f=fopen("alaw.out","rb");
5d00233a4e5b alaw and ulaw table generator
arpi_esp
parents:
diff changeset
40 for(i=0;i<256;i++){
5d00233a4e5b alaw and ulaw table generator
arpi_esp
parents:
diff changeset
41 signed short x;
5d00233a4e5b alaw and ulaw table generator
arpi_esp
parents:
diff changeset
42 fread(&x,2,1,f);
25864
ae6c30322f95 Change format string so that the table is nicely aligned.
diego
parents: 25863
diff changeset
43 printf("%7d",x);
879
5d00233a4e5b alaw and ulaw table generator
arpi_esp
parents:
diff changeset
44 if(i!=255) putchar(',');
5d00233a4e5b alaw and ulaw table generator
arpi_esp
parents:
diff changeset
45 if((i&7)==7) printf("\n");
5d00233a4e5b alaw and ulaw table generator
arpi_esp
parents:
diff changeset
46 }
5d00233a4e5b alaw and ulaw table generator
arpi_esp
parents:
diff changeset
47 fclose(f);
880
714bc8aadb68 missing semicolon fixed
arpi_esp
parents: 879
diff changeset
48 printf("};\n");
879
5d00233a4e5b alaw and ulaw table generator
arpi_esp
parents:
diff changeset
49
5d00233a4e5b alaw and ulaw table generator
arpi_esp
parents:
diff changeset
50 system("sox -t raw -U -r 8000 -b alaw.dat -t sw alaw.out");
5d00233a4e5b alaw and ulaw table generator
arpi_esp
parents:
diff changeset
51
25863
3bb953467710 The alaw tables should be const.
diego
parents: 23662
diff changeset
52 printf("\nconst short ulaw2short[]={\n");
879
5d00233a4e5b alaw and ulaw table generator
arpi_esp
parents:
diff changeset
53
5d00233a4e5b alaw and ulaw table generator
arpi_esp
parents:
diff changeset
54 f=fopen("alaw.out","rb");
5d00233a4e5b alaw and ulaw table generator
arpi_esp
parents:
diff changeset
55 for(i=0;i<256;i++){
5d00233a4e5b alaw and ulaw table generator
arpi_esp
parents:
diff changeset
56 signed short x;
5d00233a4e5b alaw and ulaw table generator
arpi_esp
parents:
diff changeset
57 fread(&x,2,1,f);
25864
ae6c30322f95 Change format string so that the table is nicely aligned.
diego
parents: 25863
diff changeset
58 printf("%7d",x);
879
5d00233a4e5b alaw and ulaw table generator
arpi_esp
parents:
diff changeset
59 if(i!=255) putchar(',');
5d00233a4e5b alaw and ulaw table generator
arpi_esp
parents:
diff changeset
60 if((i&7)==7) printf("\n");
5d00233a4e5b alaw and ulaw table generator
arpi_esp
parents:
diff changeset
61 }
5d00233a4e5b alaw and ulaw table generator
arpi_esp
parents:
diff changeset
62 fclose(f);
25865
b1316c443f87 Add multiple inclusion guards to generated header file.
diego
parents: 25864
diff changeset
63 printf("};\n\n");
b1316c443f87 Add multiple inclusion guards to generated header file.
diego
parents: 25864
diff changeset
64
26057
044b3c830459 Add MPLAYER_ prefix to multiple inclusion guard of generated file.
diego
parents: 25865
diff changeset
65 printf("#endif /* MPLAYER_ALAW_H */\n");
879
5d00233a4e5b alaw and ulaw table generator
arpi_esp
parents:
diff changeset
66
23659
f15f95c2671a Fix "control reaches end of non-void function" warnings.
diego
parents: 880
diff changeset
67 return 0;
879
5d00233a4e5b alaw and ulaw table generator
arpi_esp
parents:
diff changeset
68 }