37{
38 int i, k[2], maxk, stdin_in_use=
FALSE;
39 short *leftsample, *rightsample, *stereosample;
40 FILE *channel[2];
41 char *filename[2], *tempname;
42
45
48
50
51 for (i = 0; i < 2; i++)
52 {
54 if (filename[i] ==
NULL)
56 if (strcmp (filename[i], "-") == 0)
57 {
58 if (stdin_in_use)
60 "Cannot use <stdin> for both input files");
61 filename[i] = "<stdin>";
62 channel[i] = stdin;
64 }
65 else
66 {
67 channel[i] = fopen(filename[i], "rb");
68 }
69 if (channel[i] ==
NULL)
70 fatalerror(
"Error opening input file '%s': %s\n", filename[i],strerror(
errno));
71 else
72 inform(
"Using file '%s' as input\n", filename[i]);
73 }
74 for (i = 0; i < 2; i++)
75 {
76 assert ( channel[i] !=
NULL);
79 inform(
"Warning: '%s' is no mono file\n", filename[i]);
80 }
81
85 {
88 }
89 else
90 {
92 }
95 else
97
100
102
106 if (leftsample ==
NULL || rightsample ==
NULL || stereosample ==
NULL)
108
111 {
112 if ((strcmp(
outfilename,
"<stdout>")!=0) && (fseek(
out, 0, SEEK_SET) != 0))
115 }
116
119 {
120 maxk = 0;
121 for (i = 0; i < 2; i++)
122 {
123 k[i] = fread(i==0? leftsample : rightsample,
124 sizeof(*leftsample),
126 channel[i]);
127 if (k[i] == -1)
128 fatalerror(
"Error reading file '%s': %s\n", filename[i],strerror(
errno));
129 if (k[i] > maxk)
130 maxk = k[i];
131 }
132 if (maxk == 0)
134
135
136
137
138 for (i = 0; i < k[0]; i++)
139 stereosample[2 * i] = leftsample[i];
140
141
142
143 for (; i < maxk; i++)
144 stereosample[2 * i] = 0;
145
146
147
148
149 for (i = 0; i < k[1]; i++)
150 stereosample[2 * i + 1] = rightsample[i];
151
152
153
154 for (; i < maxk; i++)
155 stereosample[2 * i + 1] = 0;
156
157 if (!fwrite(stereosample,
sizeof(*leftsample), 2 * maxk,
out)) {
158 fatalerror(
"Error writing to file '%s': %s\n",
160 }
161 }
162
166}
static char version[AST_MAX_EXTENSION]
static struct channel_usage channels
void argerrornum(char *s, Errornum code)
void fatalperror(const char *string)
void readwavheader(FILE *anyin)
void argerrortxt(char *s, char *message)
void fatalerror(const char *format,...)
int inform(const char *format,...)
void checknoargs(int argcount, char *args[])
char * parsefilearg(int argcount, char *args[])
void parseargs(int argcount, char *args[], int fileswitch)
void startstopwatch(void)