@@ -31,9 +31,8 @@ void CmdLine::PrintWav(const AudioFile &myWav)
3131void CmdLine::PrintMode ()
3232{
3333 std::cout << " Profile: " ;
34+ std::cout << " mt" << opt.mt_mode ;
3435 std::cout << " " << opt.max_framelen << " s" ;
35- if (opt.zero_mean ) std::cout << " zero-mean" ;
36- if (opt.sparse_pcm ) std::cout << " sparse-pcm" ;
3736 if (opt.optimize ) {
3837 std::cout << " opt (" << std::format (" {:.1f}%" , opt.optimize_fraction *100.0 );
3938 std::cout << " ,n=" << opt.optimize_maxnfunc << " ," ;
@@ -47,8 +46,11 @@ void CmdLine::PrintMode()
4746 case opt.SearchCost ::Bitplane:cost_str=" bpn" ;break ;
4847 default :break ;
4948 }
50- std::cout << cost_str << " )\n " ;
49+ std::cout << cost_str << " )" ;
5150 }
51+ if (opt.zero_mean ) std::cout << " zero-mean" ;
52+ if (opt.sparse_pcm ) std::cout << " sparse-pcm" ;
53+ std::cout << ' \n ' ;
5254 std::cout << std::endl;
5355}
5456
@@ -65,6 +67,20 @@ void CmdLine::Split(const std::string &str,std::string &key,std::string &val,con
6567 }
6668}
6769
70+ double CmdLine::stod_safe (const std::string& str)
71+ {
72+ double d;
73+ try {
74+ d = std::stod (str);
75+ } catch (const std::invalid_argument&) {
76+ std::cerr << " stod: argument is invalid\n " ;
77+ throw ;
78+ } catch (const std::out_of_range&) {
79+ std::cerr << " stod: argument is out of range for a double\n " ;
80+ throw ;
81+ }
82+ return d;
83+ }
6884
6985int CmdLine::Parse (int argc,char *argv[])
7086{
@@ -89,7 +105,7 @@ int CmdLine::Parse(int argc,char *argv[])
89105 else if (key==" --LIST" ) mode=LIST;
90106 else if (key==" --LISTFULL" ) mode=LISTFULL;
91107 else if (key==" --VERBOSE" ) {
92- if (val.length ()) opt.verbose_level =stoi (val);
108+ if (val.length ()) opt.verbose_level =std::max ( 0 , stoi (val) );
93109 else opt.verbose_level =1 ;
94110 }
95111 else if (key==" --NORMAL" ) {
@@ -116,7 +132,7 @@ int CmdLine::Parse(int argc,char *argv[])
116132 std::vector<std::string>vs;
117133 StrUtils::SplitToken (val,vs," ," );
118134 if (vs.size ()>=2 ) {
119- opt.optimize_fraction =std::clamp (std::stod (vs[0 ]),0 .,1 .);
135+ opt.optimize_fraction =std::clamp (stod_safe (vs[0 ]),0 .,1 .);
120136 opt.optimize_maxnfunc =std::clamp (std::stoi (vs[1 ]),0 ,10000 );
121137 if (vs.size ()>=3 ) {
122138 std::string cf=StrUtils::str_up (vs[2 ]);
@@ -133,7 +149,10 @@ int CmdLine::Parse(int argc,char *argv[])
133149 }
134150 }
135151 else if (key==" --FRAMELEN" ) {
136- if (val.length ()) opt.max_framelen =stoi (val);
152+ if (val.length ()) opt.max_framelen =std::max (0 ,stoi (val));
153+ }
154+ else if (key==" --MT-MODE" ) {
155+ if (val.length ()) opt.mt_mode =std::max (0 ,stoi (val));
137156 }
138157 else if (key==" --SPARSE-PCM" ) {
139158 if (val==" NO" || val==" 0" ) opt.sparse_pcm =0 ;
@@ -179,11 +198,11 @@ int CmdLine::Process()
179198 if (mySac.OpenWrite (soutputfile)==0 ) {
180199 std::cout << " ok\n " ;
181200 PrintMode ();
182- Codec myCodec;
201+ Codec myCodec (opt) ;
183202
184203 Timer time;
185204 time.start ();
186- myCodec.EncodeFile (myWav,mySac,opt );
205+ myCodec.EncodeFile (myWav,mySac);
187206 time.stop ();
188207
189208 uint64_t infilesize=myWav.getFileSize ();
@@ -219,9 +238,10 @@ int CmdLine::Process()
219238 mySac.setKBPS (kbps);
220239 PrintWav (mySac);
221240 std::cout << " Profile: " ;
241+ std::cout << " mt" << opt.mt_mode ;
222242 std::cout << " " << static_cast <int >(mySac.mcfg .max_framelen ) << " s" ;
223243 std::cout << std::endl;
224- std::cout << " Ratio: " << std::fixed << std::setprecision (3 ) << bps << " bits per sample \n\n " ;
244+ std::cout << " Ratio: " << std::fixed << std::setprecision (3 ) << bps << " bps \n\n " ;
225245 std::cout << " Audio MD5: " ;
226246 for (auto x : md5digest) std::cout << std::hex << (int )x;
227247 std::cout << std::dec << ' \n ' ;
@@ -236,12 +256,22 @@ int CmdLine::Process()
236256 std::cout << " Create: '" << soutputfile << " ': " ;
237257 if (myWav.OpenWrite (soutputfile)==0 ) {
238258 std::cout << " ok\n " ;
239- Codec myCodec;
259+
260+ Timer time;
261+ time.start ();
262+
263+ Codec myCodec (opt);
240264 myCodec.DecodeFile (mySac,myWav);
241265 MD5::Finalize (&myWav.md5ctx );
242- bool md5diff=std::memcmp (myWav.md5ctx .digest , md5digest, 16 );
243- std::cout << ' \n ' ;
266+ time.stop ();
267+
268+ double xrate=0.0 ;
269+ if (time.elapsedS () > 0.0 )
270+ xrate=(myWav.getNumSamples ()/double (myWav.getSampleRate ()))/time.elapsedS ();
271+ std::cout << " \n Speed " << std::format (" {:.3f}x" ,xrate) << ' \n ' ;
272+
244273 std::cout << " Audio MD5: " ;
274+ bool md5diff=std::memcmp (myWav.md5ctx .digest , md5digest, 16 );
245275 if (!md5diff) std::cout << " ok\n " ;
246276 else {
247277 std::cout << " Error (" ;
0 commit comments