-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.c
737 lines (667 loc) · 22.8 KB
/
main.c
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
/*
* function: ReplayGain support for Wave files (http://www.replaygain.org)
*
* Reads in a Vorbis file, figures out the peak and ReplayGain levels and
* applies the Gain tags to the Wave file
*
* This program is distributed under the GNU General Public License, version
* 2.1. A copy of this license is included with this source.
*
* Copyright (C) 2002-2004 John Edwards
* Additional code by Magnus Holmgren and Gian-Carlo Pascutto
* Linux patch by Marc Brooker
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <ctype.h>
#include "getopt.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "config.h"
#include "gain_analysis.h"
#include "i18n.h"
#include "audio.h"
#include "misc.h"
#include "wavegain.h"
#include "main.h"
#include "dither.h"
#ifdef _WIN32
#include <windows.h>
#endif
#ifdef ENABLE_RECURSIVE
#include "recurse.h"
#endif
/*This is an ugly way of doing this - but it works for the moment*/
#ifndef MAX_PATH
#define MAX_PATH 512
#endif
int write_to_log = 0;
char log_file_name[MAX_PATH];
extern double total_samples;
extern double total_files;
/**
* \brief Allocate a FILE_LIST node.
*
* Allocate a FILE_LIST node. filename is set to file while track_peak and
* track_gain are set to NO_PEAK and NO_GAIN respectively. The rest of the
* fields are set to zero.
*
* \param file name of file to get a node for.
* \return the allocated node or NULL (in which case a message has been
* printed).
*/
static FILE_LIST* alloc_node(const char* file)
{
FILE_LIST* node;
node = calloc(1, sizeof(*node));
if (node != NULL) {
node->filename = strdup(file);
if (node->filename != NULL) {
node->track_peak = NO_PEAK;
node->track_gain = NO_GAIN;
node->dc_offset[0] = 0.;
node->dc_offset[1] = 0.;
node->offset[0] = 0.;
node->offset[1] = 0.;
return node;
}
free(node);
}
fprintf(stderr, _("Out of memory\n"));
return NULL;
}
/**
* \brief Allocate a new FILE_LIST node and add it to the end of a list.
*
* Allocate a new FILE_LIST node and add it to the end of a list.
*
* \param list pointer to the list (first node) pointer. If the list
* pointer contains NULL, it is set to the new node. Otherwise
* the new node is added the last node in the list.
* \param file name of the file to get a node for.
* \return 0 if successful and -1 if the node couldn't be allocated (in
* which case a message has been printed).
*/
int add_to_list(FILE_LIST** list, const char* file)
{
if (*list == NULL) {
*list = alloc_node(file);
if (*list == NULL)
return -1;
}
else {
FILE_LIST* node = *list;
while (node->next_file != NULL)
node = node->next_file;
node->next_file = alloc_node(file);
if (node->next_file == NULL)
return -1;
}
return 0;
}
/**
* Free all nodes in a FILE_LIST list.
*
* \param list pointer to first node in list. Can be NULL, in which case
* nothing is done.
*/
void free_list(FILE_LIST* list)
{
FILE_LIST* next;
while (list != NULL) {
next = list->next_file;
free((void *) list->filename);
free(list);
list = next;
}
}
static char s_floatToAscii[256];
const char* ftos(double f, const char* format)
{
sprintf(s_floatToAscii, format, f);
return s_floatToAscii;
}
/**
* \brief Processs the file in file_list.
*
* Process the files in file_list. If settings->album is set, the files are
* considered to belong to one album.
*
* \param file_list list of files to process.
* \param settings settings and global variables.
* \return 0 if successful and -1 if an error occured (in which case a
* message has been printed).
*/
int process_files(FILE_LIST* file_list, SETTINGS* settings, const char* dir __attribute__((unused)))
{
FILE_LIST* file;
double factor_clip,
audiophile_gain = 0.,
Gain,
scale,
dB,
album_dc_offset[2] = {0., 0.};
settings->album_peak = NO_PEAK;
if (file_list == NULL)
return 0;
settings->first_file = 1;
/* Undo previously applied gain */
if (settings->undo) {
for (file = file_list; file; file = file->next_file) {
if (file->filename == NULL)
continue;
if (!write_gains(file->filename, 0, 0, 0, 0, 0, settings)) {
fprintf(stderr, " Error processing GAIN for file - %s\n", file->filename);
continue;
}
}
}
else {
/* Analyze the files */
for (file = file_list; file; file = file->next_file) {
int dc_l;
int dc_r;
if (file->filename == NULL)
continue;
if (!get_gain(file->filename, &file->track_peak, &file->track_gain,
file->dc_offset, file->offset, settings)) {
file->filename = NULL;
continue;
}
dc_l = (int)(file->dc_offset[0] * 32768 * -1);
dc_r = (int)(file->dc_offset[1] * 32768 * -1);
if (dc_l < -1 || dc_l > 1 || dc_r < -1 || dc_r > 1)
settings->need_to_process = 1;
album_dc_offset[0] += file->offset[0];
album_dc_offset[1] += file->offset[1];
}
album_dc_offset[0] /= total_samples;
album_dc_offset[1] /= total_samples;
if (!settings->no_offset && settings->adc) {
int dc_l = (int)(album_dc_offset[0] * 32768 * -1);
int dc_r = (int)(album_dc_offset[1] * 32768 * -1);
fprintf(stderr, " ********************* Album DC Offset | %4d | %4d | ***************\n",
dc_l, dc_r);
if(write_to_log) {
write_log(" ********************* Album DC Offset | %4d | %4d | ***************\n",
dc_l, dc_r);
}
}
fprintf(stderr, "\n");
if(write_to_log)
write_log("\n");
if (settings->audiophile) {
Gain = GetAlbumGain() + settings->man_gain;
scale = pow(10., Gain * 0.05);
settings->set_album_gain = 0;
if(settings->clip_prev) {
factor_clip = (32767./( settings->album_peak + 1));
if(scale < factor_clip)
factor_clip = 1.0;
else
factor_clip /= scale;
scale *= factor_clip;
}
if (settings->scale) {
fprintf(stdout, "%8.6lf", scale);
}
if (scale > 0.0)
dB = 20. * log10(scale);
else
dB = 0.0;
audiophile_gain = dB;
if (audiophile_gain < 0.1 && audiophile_gain > -0.1 && !settings->need_to_process) {
fprintf(stderr, " No Album Gain adjustment or DC Offset correction required, exiting.\n");
if(write_to_log)
write_log(" No Album Gain adjustment or DC Offset correction required, exiting.\n");
settings->set_album_gain = 1;
}
else {
fprintf(stderr, " Recommended Album Gain: %+6.2f dB\tScale: %6.4f\n\n", audiophile_gain, scale);
if(write_to_log)
write_log(" Recommended Album Gain: %+6.2f dB\tScale: %6.4f\n\n", audiophile_gain, scale);
}
}
if(settings->apply_gain) { /* Write radio and audiophile gains. */
total_files = 0.0;
for (file = file_list; file; file = file->next_file) {
if (file->filename == NULL)
continue;
if (settings->audiophile && settings->set_album_gain == 1)
break;
if (settings->radio && (file->track_gain < 0.1 && file->track_gain > -0.1) && !settings->need_to_process) {
fprintf(stderr, " No Title Gain adjustment or DC Offset correction required for file: %s, skipping.\n", file->filename);
if(write_to_log)
write_log(" No Title Gain adjustment or DC Offset correction required for file: %s, skipping.\n", file->filename);
}
else if (!write_gains(file->filename, file->track_gain, audiophile_gain, file->track_peak,
file->dc_offset, album_dc_offset, settings)) {
fprintf(stderr, " Error processing GAIN for file - %s\n", file->filename);
continue;
}
}
}
}
fprintf(stderr, "\n WaveGain Processing completed normally\n");
if(write_to_log)
write_log("\n WaveGain Processing completed normally\n\n");
#ifdef _WIN32
if (settings->cmd) { /* execute user command */
FILE_LIST* file;
char buff[MAX_PATH];
char *b, *p, *q;
double track_scale = 1.0;
SetEnvironmentVariable("ALBUM_GAIN", ftos(audiophile_gain, "%.2lf"));
SetEnvironmentVariable("ALBUM_SCALE", ftos(scale, "%.5lf"));
SetEnvironmentVariable("ALBUM_NEW_PEAK", ftos(settings->album_peak * scale, "%.0lf"));
SetEnvironmentVariable("ALBUM_PEAK", ftos(settings->album_peak, "%.0lf"));
for (file = file_list; file; file = file->next_file) {
if (file->filename == NULL)
continue;
if (dir[0] == '.' && dir[1] == '\\') dir += 2;
strcpy(buff, file->filename);
b = (buff[0] == '.' && buff[1] == '\\') ? buff+2 : buff;
SetEnvironmentVariable("INPUT_FILE", b);
p = strrchr(b, '\\');
if (p) {
p[0] = '\0'; ++p;
SetEnvironmentVariable("INPUT_FDIR", b);
SetEnvironmentVariable("INPUT_RDIR", b); // assume dir = "."
}
else {
p = b;
SetEnvironmentVariable("INPUT_FDIR", ".");
SetEnvironmentVariable("INPUT_RDIR", dir);
}
q = strrchr(p, '.');
if (q) q[0] = '\0';
SetEnvironmentVariable("INPUT_NAME", p);
track_scale = (pow(10., file->track_gain * 0.05));
SetEnvironmentVariable("TRACK_SCALE", ftos(track_scale, "%.5lf"));
SetEnvironmentVariable("TRACK_GAIN", ftos(file->track_gain, "%.2lf"));
SetEnvironmentVariable("TRACK_NEW_PEAK", ftos(file->track_peak, "%.0lf"));
SetEnvironmentVariable("TRACK_PEAK", ftos(file->track_peak / track_scale, "%.0lf"));
SetEnvironmentVariable("DC_OFFSET_L", ftos((int)(file->dc_offset[0]*(-32768)), "%.0lf"));
SetEnvironmentVariable("DC_OFFSET_R", ftos((int)(file->dc_offset[1]*(-32768)), "%.0lf"));
fprintf(stderr, "\n Executing command on \"%s\":\n\n", file->filename);
system(settings->cmd);
}
}
#endif
return 0;
}
/**
* Print out a list of options and the command line syntax.
*/
static void usage(void)
{
fprintf(stdout, _("WaveGain v" WAVEGAIN_VERSION " Compiled " __DATE__ ".\n"));
fprintf(stdout, _("Copyright (c) 2002-2010 John Edwards <[email protected]>\n"));
fprintf(stdout, _("Additional code by Magnus Holmgren, Gian-Carlo Pascutto, and Tycho\n\n"));
#ifdef _WIN32
fprintf(stdout, " Usage: wavegain [options] input.wav [...] [-e cmd [args]]\n\n");
#else
fprintf(stdout, " Usage: wavegain [options] input.wav [...]\n\n");
#endif
fprintf(stdout, " OPTIONS\n");
fprintf(stdout, " -h, --help Prints this help information.\n");
fprintf(stdout, " -a, --album Use ReplayGain Audiophile/Album gain setting, or\n");
fprintf(stdout, " -r, --radio Use ReplayGain Radio/Single Track gain setting(DEFAULT).\n");
fprintf(stdout, " -q, --adc Apply Album based DC Offset correction.\n");
fprintf(stdout, " DEFAULT is Track based DC Offset correction.\n");
fprintf(stdout, " -p, --no_offset Do NOT apply DC Offset correction.\n");
fprintf(stdout, " -c, --calculate Calculates and prints gain settings, and DC Offsets BUT\n");
fprintf(stdout, " DOES NOT APPLY THEM - This is the DEFAULT.\n");
fprintf(stdout, " -x, --scale Writes scale values to stdout in the format: n.nnnnnn\n");
fprintf(stdout, " In Album mode it only writes the Album Scale value, and\n");
fprintf(stdout, " in Title mode it only writes the Title Scale values.\n");
fprintf(stdout, " ONLY works in Calculation mode.\n");
fprintf(stdout, " -y, --apply Calculates and APPLIES gain settings, and applies\n");
fprintf(stdout, " DC Offset correction.\n");
fprintf(stdout, " -w, --write Writes a 'gain' chunk into the Wave Header.\n");
fprintf(stdout, " Stores the scalefactor applied to the wave data as a\n");
fprintf(stdout, " double floating point number. Only written when gain\n");
fprintf(stdout, " is applied. Presence will result in file being skipped\n");
fprintf(stdout, " if reprocessed.\n");
fprintf(stdout, " (Unless '--force' or '--undo-gain' are specified.)\n");
fprintf(stdout, " --force Forces the reprocessing of a file that contains a 'gain'\n");
fprintf(stdout, " chunk and will result in the new scalefactor overwriting\n");
fprintf(stdout, " the existing value.\n");
fprintf(stdout, " --undo-gain Reads the scalefactor in the 'gain' chunk and uses the\n");
fprintf(stdout, " value to reverse the previously applied gain. This will NOT\n");
fprintf(stdout, " recreate a bit identical version of the original file, but\n");
fprintf(stdout, " it will be rescaled to the original level.\n");
#ifdef ENABLE_RECURSIVE
fprintf(stdout, " -z, --recursive Search for files recursively, each folder as an album\n");
#endif
fprintf(stdout, " -l, --log Write log file.(Default filename = WGLog.txt)\n");
fprintf(stdout, " -f, --logfile Specify log filename. (Assumes -l if present.)\n");
fprintf(stdout, " -n, --noclip NO Clipping Prevention.\n");
fprintf(stdout, " -d, --dither X Dither output, where X =\n");
fprintf(stdout, " 0 for dither OFF (default).\n");
fprintf(stdout, " 1 for dither without Noise Shaping.\n");
fprintf(stdout, " 2 for dither with Light Noise Shaping.\n");
fprintf(stdout, " 3 for dither with Medium Noise Shaping.\n");
fprintf(stdout, " 4 for dither with Heavy Noise Shaping.\n");
fprintf(stdout, " -t, --limiter Apply 6dB Hard Limiter to output.\n");
fprintf(stdout, " -g, --gain X Apply additional Manual Gain adjustment in decibels, where\n");
fprintf(stdout, " X = any floating point number between -20.0 and +12.0.\n");
fprintf(stdout, " Clipping Prevention WILL be applied UNLESS '-n' is used.\n");
fprintf(stdout, " -s, --fast Calculates and prints gain settings - DOES NOT APPLY THEM.\n");
fprintf(stdout, " NOTE: This method does NOT process all samples, it only\n");
fprintf(stdout, " processes 200 x 16k chunks of samples. Results will\n");
fprintf(stdout, " NOT be as accurate as a full analysis but, with most\n");
fprintf(stdout, " material, will be within +/- 0.5db. Files of 8,192,000\n");
fprintf(stdout, " real samples, or less, will be analysed in full.\n");
fprintf(stdout, " DC Offset is neither calculated nor corrected in\n");
fprintf(stdout, " FAST mode.\n");
fprintf(stdout, " -o, --stdout Write output file to stdout.\n");
fprintf(stdout, " FORMAT OPTIONS (One option ONLY may be used)\n");
fprintf(stdout, " -b, --bits X Set output sample format, where X =\n");
fprintf(stdout, " 1 for 8 bit unsigned PCM data.\n");
fprintf(stdout, " 2 for 16 bit signed PCM data.\n");
fprintf(stdout, " 3 for 24 bit signed PCM data.\n");
fprintf(stdout, " 4 for 32 bit signed PCM data.\n");
fprintf(stdout, " 5 for 32 bit floats.\n");
fprintf(stdout, " 6 for 16 bit 'aiff' format.\n");
fprintf(stdout, " NOTE: By default, the output file will be of the same bitwidth\n");
fprintf(stdout, " and type as the input file.\n");
#ifdef _WIN32
fprintf(stdout, " -e, --exec Cmd Execute a command after wavegain.\n");
fprintf(stdout, " The following environment variables are available:\n");
fprintf(stdout, " INPUT_FILE, INPUT_FDIR, INPUT_RDIR, INPUT_NAME,\n");
fprintf(stdout, " TRACK_GAIN, TRACK_PEAK, TRACK_SCALE, TRACK_NEW_PEAK,\n");
fprintf(stdout, " ALBUM_GAIN, ALBUM_PEAK, ALBUM_SCALE, ALBUM_NEW_PEAK,\n");
fprintf(stdout, " DC_OFFSET_L, DC_OFFSET_R\n");
#endif
fprintf(stdout, " INPUT FILES\n");
fprintf(stdout, " WaveGain input files may be 8, 16, 24 or 32 bit integer, or floating point\n");
fprintf(stdout, " wave files with 1 or 2 channels and a sample rate of 96000Hz, 88200Hz,\n");
fprintf(stdout, " 64000Hz, 48000Hz, 44100Hz, 32000Hz, 24000Hz, 22050Hz, 16000Hz, 12000Hz,\n");
fprintf(stdout, " 11025Hz or 8000Hz.\n");
fprintf(stdout, " 16 bit integer 'aiff' files are also supported.\n");
fprintf(stdout, " Wildcards (?, *) can be used in the filename, or '-' for stdin.\n");
return;
}
static const struct option long_options[] = {
{"help", 0, NULL, 'h'},
{"album", 0, NULL, 'a'},
{"radio", 0, NULL, 'r'},
{"adc", 0, NULL, 'q'},
{"no_offset", 0, NULL, 'p'},
{"calculate", 0, NULL, 'c'},
{"scale", 0, NULL, 'x'},
{"apply", 0, NULL, 'y'},
{"write", 0, NULL, 'w'},
{"force", 0, NULL, 0 },
{"undo-gain", 0, NULL, 0 },
{"fast", 0, NULL, 's'},
{"stdout", 0, NULL, 'o'},
#ifdef ENABLE_RECURSIVE
{"recursive", 0, NULL, 'z'},
#endif
{"log", 0, NULL, 'l'},
{"logfile", 1, NULL, 'f'},
{"noclip", 0, NULL, 'n'},
{"dither", 1, NULL, 'd'},
{"limiter", 0, NULL, 't'},
{"gain", 1, NULL, 'g'},
{"bits", 1, NULL, 'b'},
#ifdef _WIN32
{"exec", 1, NULL, 'e'},
#endif
{NULL, 0, NULL , 0}
};
#ifdef ENABLE_RECURSIVE
#define ARG_STRING "harqpcxywsozlf:nd:tg:b:e:"
#else
#define ARG_STRING "harqpcxywsolf:nd:tg:b:e:"
#endif
int main(int argc, char** argv)
{
SETTINGS settings;
int option_index = 1,
ret,
i,
bits;
#ifdef _WIN32
char CmdDir[MAX_PATH];
char *p;
#endif
memset(&settings, 0, sizeof(settings));
settings.first_file = 1;
settings.radio = 1;
settings.clip_prev = 1;
settings.outbitwidth = 16;
settings.format = WAV_NO_FMT;
#ifdef _WIN32
/* Is this good enough? Or do we need to consider multi-byte codepages as
* well?
*/
SetConsoleOutputCP(GetACP());
GetModuleFileName(NULL, CmdDir, MAX_PATH);
p = strrchr(CmdDir, '\\') + 1;
p[0] = '\0';
#endif
while ((ret = getopt_long(argc, argv, ARG_STRING, long_options, &option_index)) != -1) {
switch(ret) {
case 0:
if (!strcmp(long_options[option_index].name, "force")) {
settings.force = 1;
}
else if (!strcmp(long_options[option_index].name, "undo-gain")) {
settings.undo = 1;
}
else {
fprintf(stderr, "Internal error parsing command line options\n");
exit(1);
}
break;
case 'h':
usage();
exit(0);
break;
case 'a':
settings.audiophile = 1;
break;
case 'r':
settings.radio = 1;
break;
case 'q':
settings.adc = 1;
break;
case 'p':
settings.no_offset = 1;
break;
case 'c':
settings.apply_gain = 0;
break;
case 'x':
settings.scale = 1;
break;
case 'y':
settings.apply_gain = 1;
settings.scale = 0;
break;
case 'w':
settings.write_chunk = 1;
break;
case 's':
settings.fast = 1;
break;
case 'o':
settings.std_out = 1;
break;
#ifdef ENABLE_RECURSIVE
case 'z':
settings.recursive = 1;
break;
#endif
case 'l':
write_to_log = 1;
#ifdef _WIN32
strcpy(log_file_name, CmdDir);
strcat(log_file_name, LOG_NAME);
#else
strcpy(log_file_name, LOG_NAME);
#endif
break;
case 'f':
write_to_log = 1;
strcpy(log_file_name, optarg);
break;
case 'n':
settings.clip_prev = 0;
break;
case 'd':
settings.need_to_process = 1;
settings.dithering = 1;
if(sscanf(optarg, "%d", &settings.shapingtype) != 1) {
fprintf(stderr, "Warning: dither type %s not recognised, using default\n", optarg);
break;
}
if (settings.shapingtype == 0)
settings.dithering = 0;
else if (settings.shapingtype == 1)
settings.shapingtype = 0;
else if (settings.shapingtype == 2)
settings.shapingtype = 1;
else if (settings.shapingtype == 3)
settings.shapingtype = 2;
else if (settings.shapingtype == 4)
settings.shapingtype = 3;
break;
case 't':
settings.limiter = 1;
break;
case 'g':
if(sscanf(optarg, "%lf", &settings.man_gain) != 1) {
fprintf(stderr, "Warning: manual gain %s not recognised, ignoring\n", optarg);
break;
}
if(settings.man_gain < -20.0) {
fprintf(stderr, "Warning: manual gain %s is out of range, "
"applying gain of -20.0dB\n", optarg);
settings.man_gain = -20.0;
}
else if(settings.man_gain > 12.0) {
fprintf(stderr, "Warning: manual gain %s is out of range, "
"applying gain of +12.0dB\n", optarg);
settings.man_gain = 12.0;
}
break;
case 'b':
settings.need_to_process = 1;
if(sscanf(optarg, "%d", &bits) != 1) {
fprintf(stderr, "Warning: output format %s not recognised, using default\n", optarg);
break;
}
if (bits == 1) {
settings.outbitwidth = 8;
settings.format = WAV_FMT_8BIT;
break;
}
else if (bits == 2) {
settings.outbitwidth = 16;
settings.format = WAV_FMT_16BIT;
break;
}
else if (bits == 3) {
settings.outbitwidth = 24;
settings.format = WAV_FMT_24BIT;
break;
}
else if (bits == 4) {
settings.outbitwidth = 32;
settings.format = WAV_FMT_32BIT;
break;
}
else if (bits == 5) {
settings.outbitwidth = 32;
settings.format = WAV_FMT_FLOAT;
break;
}
else if (bits == 6) {
settings.outbitwidth = 16;
settings.format = WAV_FMT_AIFF;
break;
}
else {
fprintf(stderr, "Warning: output format %s not recognised, using default\n", optarg);
break;
}
break;
#ifdef _WIN32
case 'e': {
char *p;
int k;
char * lpPart[MAX_PATH]={NULL};
settings.cmd = (char *) malloc(1024*8); /* 8Kb is XP's limit */
if (settings.cmd == NULL) {
fprintf(stderr, "Failed to allocate memory for cmd...\n");
return 1;
}
p = settings.cmd;
k = GetFullPathName(argv[optind - 1], 1024*8, p, lpPart);
k = GetShortPathName(p, p, MAX_PATH);
if (k == 0) {
p += sprintf (p, "%s", argv[optind - 1]);
} else {
p += k;
}
for (k = optind; k < argc; ++k) {
p += sprintf(p, " \"%s\"", argv[k]);
}
argc = optind;
break;
}
#endif
}
}
if (settings.undo == 1) {
settings.write_chunk = 0;
settings.no_offset = 1;
}
if (optind >= argc) {
fprintf(stderr, _("No files specified.\n"));
usage();
return EXIT_SUCCESS;
}
if (write_to_log) {
write_log("Command line:\n\t");
for(i = 0; i < argc; i++)
write_log("%s ", argv[i]);
write_log("\n");
}
if (!strcmp(argv[optind], "-")) {
double track_peak, track_gain;
double dc_offset;
double offset;
if (!get_gain("-", &track_peak, &track_gain,
&dc_offset, &offset, &settings))
return -1;
}
else {
for (i = optind; i < argc; ++i) {
#ifdef ENABLE_RECURSIVE
if (process_argument(argv[i], &settings) < 0) {
free_list(settings.file_list);
return EXIT_FAILURE;
}
#else
if (add_to_list(&settings.file_list, argv[i]) < 0)
return EXIT_FAILURE;
#endif
}
/* Process files (perhaps remaining) in list */
ret = process_files(settings.file_list, &settings, ".");
free_list(settings.file_list);
settings.file_list = NULL;
if (settings.cmd) free(settings.cmd);
settings.cmd = NULL;
}
return (ret < 0) ? EXIT_FAILURE : EXIT_SUCCESS;
}