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
|
# include <getopt.h> // getopt
# include "qwav.hh"
# include "qwavsample.hh"
# include "qexception.hh"
# include "qmisc.hh"
#include <iostream>
#ifdef NLS
# include <locale.h>
# include <libintl.h>
# define _(s) gettext (s)
#else
# define _(s) (s)
#endif
void usage () {
cerr << " " << APPNAME << _(": fade in/out wav files\n");
cerr << " " << _("syntax: ") << APPNAME << _("[option]... file...\n");
cerr << _(" -d, --duration <duration>[j|s|m|b|k|M]: set the fade duration\n");
cerr << _(" -h, --help: show this help and exit\n");
cerr << _(" -i, --in: just fade in\n");
cerr << _(" -l, --length [[h:]m:]s[.ms]: set the fade duration.\n");
// cerr << _(" -m, --mode <mode>: select the type of fade {linear,quadpos,quadneg} \n");
cerr << _(" -o, --out: just fade out\n");
cerr << _(" -t, --test: don't modify. create and fade a test file\n");
cerr << _(" -v, --verbose: show more detailed info\n");
cerr << _(" -V, --version: show version and exit\n");
cerr << _(" see info manual for more info about options and usage\n");
}
int main (int argc, char **argv) {
int option;
qvf duration(5,qvf::SECONDS);
bool in=true,out=true,verbose=false,test=false;
static struct option long_options[] = {
{"duration",required_argument,0,'d'},
{"help",no_argument,0,'h'},
{"in",no_argument,0,'i'},
{"length",required_argument,0,'l'},
// {"mode",required_argument,0,'m'},
{"out",no_argument,0,'o'},
{"test",no_argument,0,'t'},
{"verbose",no_argument,0,'v'},
{"version",no_argument,0,'V'},
{0,0,0,0}
};
#ifdef NLS
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
#endif
// un altre dia, per defecte llegir *.wav ...
if (argc==1) {
usage();
return 1;
}
// supress getopt error message
opterr = 0;
while ((option = getopt_long(argc, argv, "d:hil:otvV",long_options,0)) != EOF)
switch (option) {
case 'd':
try { duration = qvf(optarg); }
catch (qexception e) { cerr << e << endl; }
break;
case 'h':
usage();
return 0;
break;
case 'i':
in=true;
out=false;
break;
case 'l':
try {
duration = qvf(time2ms(optarg),qvf::MILLISECONDS);
}
catch (qexception e) { cerr << e << endl; }
break;
case 'o':
out=true;
in=false;
break;
case 't':
test = true;
break;
case 'v':
verbose=true;
break;
case 'V':
cerr << APPNAME << " - " << _("version") << ' ' << VERSION
<< _("build") << ' ' << __DATE__ << '\n';
return 0;
break;
case '?':
default:
cerr << APPNAME << ": " << _("option") << " '" << argv[optind-1]
<< "' " << _("is not recognized or bad used") << '\n';
usage();
return 1;
}
if (argc<=optind) {
// haurem de fer *.wav ...
cerr << APPNAME << _(": no input file(s)") << endl;
usage();
return 1;
}
u_int32_t wavmode = test?qwav::READ:qwav::READWRITE;
while (argv[optind]) {
if (verbose)
cerr << _("fading '") << argv[optind] << "'...\n";
qwav *wav = new qwav(argv[optind],wavmode);
u_int32_t nsamples = wav->getSample(duration); // dins del rang?
if (in && out && nsamples>wav->getSamples()/2) {
cerr << APPNAME << _(": both fades overlap. they'd be done separately\n");
optind++;
continue;
}
if (in) { // fade in:
if (test) {
string name(string("fadein.")+wav->getName());
qvf size(nsamples+5*wav->getSampleRate());
qcuthandler h;
h.setOutfile(name);
h.setSize(size);
wav->cut(h);
if (verbose)
cerr << _("created testfile '") << name << "'\n";
delete wav;
wav = new qwav(name,qwav::READWRITE);
}
qwavsample sample(wav);
double factor;
for (u_int32_t i=0; i<nsamples; i++) {
factor = (double)i/(double)nsamples;
sample.prod(factor);
sample.setNext();
}
if (verbose)
cerr << _("faded in ") << nsamples << _(" samples in '") << wav->getName()
<< "'\n";
}
delete wav;
wav = new qwav(argv[optind],wavmode);
if (out) { // fade out
if (test) {
string name(string("fadeout.")+wav->getName());
qvf begin(nsamples+5*wav->getSampleRate());
qcuthandler h;
h.setOutfile(name);
h.setbegin(begin);
wav->cut(h);
if (verbose)
cerr << _("created testfile ") << name << "'\n";
delete wav;
wav = new qwav(name,qwav::READWRITE);
}
qwavsample sample(wav,wav->getSamples()-nsamples+1);
double factor;
for (int i=nsamples; i>0; i--) {
factor = (double)i/(double)nsamples;
sample.prod(factor);
sample.setNext();
}
if (verbose)
cerr << _("faded out ") << nsamples << _(" samples in '")
<< wav->getName() << "'\n";
}
optind++;
}
}
|