Mercurial > hg > audiostuff
comparison intercom/g711/shiftbit.c @ 2:13be24d74cd2
import intercom-0.4.1
author | Peter Meerwald <pmeerw@cosy.sbg.ac.at> |
---|---|
date | Fri, 25 Jun 2010 09:57:52 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1:9cadc470e3da | 2:13be24d74cd2 |
---|---|
1 /* | |
2 ======================================================================= | |
3 | |
4 SHIFTBIT.C | |
5 ~~~~~~~~~~ | |
6 | |
7 Description | |
8 ~~~~~~~~~~~ | |
9 | |
10 Shift samples from input file (in Qx format) such that the output file | |
11 will be in the Qy format, with sign extension. In fact, what this does | |
12 is multiply by the factor 2**(y-x) (if left-shift) or divide by the | |
13 factor 2**(x-y) (if right-shift) the input samples. | |
14 | |
15 Includes: | |
16 ~~~~~~~~~ | |
17 specific: ugstdemo.h | |
18 system: stdio.h,stat.h | |
19 | |
20 Author: | |
21 ~~~~~~~ | |
22 | |
23 Simao Ferraz de Campos Neto | |
24 DDS/Pr11 Tel: +55-192-39-1396 | |
25 CPqD/Telebras Fax: +55-192-53-4754 | |
26 13085 Campinas SP Brazil E-mail: <tdsimao@venus.cpqd.ansp.br> | |
27 | |
28 History: | |
29 ~~~~~~~~ | |
30 08.Feb.91 v1.0 Created! | |
31 | |
32 ======================================================================= | |
33 */ | |
34 | |
35 #include "ugstdemo.h" | |
36 #include <stdio.h> | |
37 | |
38 /* | |
39 * Includes dependent of the Operating System | |
40 */ | |
41 #if defined(VMS) | |
42 # include <stat.h> | |
43 #elif defined (MSDOS) | |
44 # include <sys\stat.h> | |
45 #else | |
46 # include <sys/stat.h> | |
47 #endif | |
48 | |
49 #define RIGHT 1 | |
50 #define LEFT -1 | |
51 | |
52 main(argc, argv) | |
53 int argc; | |
54 char *argv[]; | |
55 { | |
56 char inp[50], out[50]; | |
57 short *buf; | |
58 int qinp, qout, shift, dir; | |
59 FILE *Fi, *Fo; | |
60 int fi, fo; | |
61 #ifdef VMS | |
62 char mrs[15] = "mrs=512"; | |
63 #endif | |
64 struct stat info; | |
65 long l, k; | |
66 | |
67 GET_PAR_S(1, "Input file: ......... ", inp); | |
68 GET_PAR_I(2, "Input file is Q.", qinp); | |
69 GET_PAR_S(3, "Output file: ........ ", out); | |
70 GET_PAR_I(4, "Input file is Q.", qout); | |
71 | |
72 if (qout == qinp) | |
73 HARAKIRI("Makes no sense a shift of 0 ... \n", 7) | |
74 else | |
75 if (qout > qinp) | |
76 dir = RIGHT; | |
77 else | |
78 dir = LEFT; | |
79 | |
80 l = qout - qinp; | |
81 if (l < 0) | |
82 l = -l; | |
83 | |
84 for (shift = 1, k = 0; k < l; k++) | |
85 shift *= 2; | |
86 | |
87 if ((Fi = fopen(inp, RB)) == NULL) | |
88 KILL(inp, 2); | |
89 fi = fileno(Fi); | |
90 if ((Fo = fopen(out, WB)) == NULL) | |
91 KILL(inp, 3); | |
92 fo = fileno(Fo); | |
93 | |
94 stat(inp, &info); | |
95 if ((buf = (short *) malloc(info.st_size)) == NULL) | |
96 HARAKIRI("Can't alloc inp\n", 4); | |
97 l = info.st_size / 2; | |
98 | |
99 fprintf(stderr, "%s: Reading, ", inp); | |
100 for (k = 0; k < l; k += 256) | |
101 if (read(fi, &buf[k], 512) < 0) | |
102 KILL(inp, 5); | |
103 | |
104 fprintf(stderr, "shifting, "); | |
105 if (dir == RIGHT) | |
106 for (k = 0; k < l; k++) | |
107 buf[k] = (buf[k] * shift); | |
108 else | |
109 for (k = 0; k < l; k++) | |
110 buf[k] = (buf[k] / shift); | |
111 | |
112 fprintf(stderr, "and writing ... "); | |
113 for (k = 0; k < l; k += 256) | |
114 if (write(fo, &buf[k], 512) <= 0) | |
115 KILL(inp, 6); | |
116 | |
117 fprintf(stderr, "Done!\n"); | |
118 fclose(Fi); | |
119 fclose(Fo); | |
120 } |