OSDN Git Service

Now each tool can also have a "tag" in addition to the version number.
[lamexp/LameXP.git] / etc / Patches / deprecated / AC3Filter-valdec-v0.31b-UTF8+STDOUT+Flush.V1.diff
1  tools/unicode_support.cpp        |   86 ++++++++++++++++++
2  tools/unicode_support.h          |   21 +++++
3  tools/valdec.cpp                 |  180 ++++++++++++++++++++++++--------------
4  tools/valdec.sln                 |   50 +++++++----
5  tools/valdec.vcproj              |   61 +++++++------
6  valib/lib/valib.vcproj           |   19 ++++-
7  valib/valib/auto_file.cpp        |    3 +-
8  valib/valib/sink/sink_dsound.cpp |    4 +-
9  valib/valib/sink/sink_stdout.h   |   93 ++++++++++++++++++++
10  9 files changed, 402 insertions(+), 115 deletions(-)
11
12 diff --git a/tools/unicode_support.cpp b/tools/unicode_support.cpp
13 new file mode 100644
14 index 0000000..13f89ba
15 --- /dev/null
16 +++ b/tools/unicode_support.cpp
17 @@ -0,0 +1,86 @@
18 +#include "unicode_support.h"
19 +
20 +#include <windows.h>
21 +
22 +char *utf16_to_utf8(const wchar_t *input)
23 +{
24 +       char *Buffer;
25 +       int BuffSize, Result;
26 +
27 +       BuffSize = WideCharToMultiByte(CP_UTF8, 0, input, -1, NULL, 0, NULL, NULL);
28 +       Buffer = new char[BuffSize]; //(char*) malloc(sizeof(char) * BuffSize);
29 +       Result = WideCharToMultiByte(CP_UTF8, 0, input, -1, Buffer, BuffSize, NULL, NULL);
30 +
31 +       return ((Result > 0) && (Result <= BuffSize)) ? Buffer : NULL;
32 +}
33 +
34 +wchar_t *utf8_to_utf16(const char *input)
35 +{
36 +       wchar_t *Buffer;
37 +       int BuffSize, Result;
38 +
39 +       BuffSize = MultiByteToWideChar(CP_UTF8, 0, input, -1, NULL, 0);
40 +       Buffer = new wchar_t[BuffSize]; //(wchar_t*) malloc(sizeof(wchar_t) * BuffSize);
41 +       Result = MultiByteToWideChar(CP_UTF8, 0, input, -1, Buffer, BuffSize);
42 +
43 +       return ((Result > 0) && (Result <= BuffSize)) ? Buffer : NULL;
44 +}
45 +
46 +void init_commandline_arguments_utf8(int *argc, char ***argv)
47 +{
48 +       int i, nArgs;
49 +       LPWSTR *szArglist;
50 +
51 +       szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
52 +
53 +       if(NULL == szArglist)
54 +       {
55 +               fprintf(stderr, "\nFATAL: CommandLineToArgvW failed\n\n");
56 +               exit(-1);
57 +       }
58 +
59 +       *argv = new char*[nArgs]; //malloc(sizeof(char*) * nArgs);
60 +       *argc = nArgs;
61 +
62 +       for(i = 0; i < nArgs; i++)
63 +       {
64 +               (*argv)[i] = utf16_to_utf8(szArglist[i]);
65 +       }
66 +
67 +       LocalFree(szArglist);
68 +}
69 +
70 +void free_commandline_arguments_utf8(int *argc, char ***argv)
71 +{
72 +       if(*argv != NULL)
73 +       {
74 +               for(int i = 0; i < *argc; i++)
75 +               {
76 +                       if((*argv)[i] != NULL)
77 +                       {
78 +                               delete [] ((*argv)[i]);
79 +                               (*argv)[i] = NULL;
80 +                       }
81 +               }
82 +               delete [] (*argv);
83 +               *argv = NULL;
84 +       }
85 +}
86 +
87 +FILE *fopen_utf8(const char *filename_utf8, const char *mode_utf8)
88 +{
89 +       FILE *ret = NULL;
90 +
91 +       wchar_t *filename_utf16 = utf8_to_utf16(filename_utf8);
92 +       wchar_t *mode_utf16 = utf8_to_utf16(mode_utf8);
93 +       
94 +       if(filename_utf16 && mode_utf16)
95 +       {
96 +               ret = _wfopen(filename_utf16, mode_utf16);
97 +       }
98 +
99 +       if(filename_utf16) delete [] filename_utf16;
100 +       if(mode_utf16) delete [] mode_utf16;
101 +
102 +       return ret;
103 +}
104 diff --git a/tools/unicode_support.h b/tools/unicode_support.h
105 new file mode 100644
106 index 0000000..9ad3173
107 --- /dev/null
108 +++ b/tools/unicode_support.h
109 @@ -0,0 +1,21 @@
110 +#ifndef UNICODE_SUPPORT_H_INCLUDED
111 +#define UNICODE_SUPPORT_H_INCLUDED
112 +
113 +#include <ctype.h>
114 +#include <stdio.h>
115 +#include <stdlib.h>
116 +
117 +#ifdef __cplusplus
118 +extern "C" {
119 +#endif
120 +
121 +char *utf16_to_utf8(const wchar_t *input);
122 +wchar_t *utf8_to_utf16(const char *input);
123 +void init_commandline_arguments_utf8(int *argc, char ***argv);
124 +void free_commandline_arguments_utf8(int *argc, char ***argv);
125 +FILE *fopen_utf8(const char *filename_utf8, const char *mode_utf8);
126 +
127 +#ifdef __cplusplus
128 +}
129 +#endif
130 +#endif
131 diff --git a/tools/valdec.cpp b/tools/valdec.cpp
132 index 6b24ecf..b5fe15d 100644
133 --- a/tools/valdec.cpp
134 +++ b/tools/valdec.cpp
135 @@ -15,6 +15,7 @@
136  #include "sink\sink_raw.h"
137  #include "sink\sink_wav.h"
138  #include "sink\sink_dsound.h"
139 +#include "sink\sink_stdout.h"
140  
141  // filters
142  #include "filters\dvd_graph.h"
143 @@ -22,6 +23,7 @@
144  // other
145  #include "win32\cpu.h"
146  #include "vargs.h"
147 +#include "unicode_support.h"
148  
149  
150  #define bool2str(v) ((v)? "true": "false")
151 @@ -65,7 +67,7 @@ const sample_t level_tbl[] =
152    1.0
153  };
154  
155 -int main(int argc, char *argv[])
156 +int valdec_main(int argc, char *argv[])
157  {
158    if (argc < 2)
159    {
160 @@ -77,6 +79,7 @@ int main(int argc, char *argv[])
161  "\n"
162  "This utility is a part of AC3Filter project (http://ac3filter.net)\n"
163  "Copyright (c) 2006-2009 by Alexander Vigovsky\n"
164 +"Support for Unicode file names and STDOUT output added by LoRd_MuldeR\n"
165  "\n"
166  "Usage:\n"
167  "  valdec some_file [options]\n"
168 @@ -91,6 +94,7 @@ int main(int argc, char *argv[])
169  "    -r[aw] file.raw - decode to RAW file\n"
170  "    -w[av] file.wav - decode to WAV file\n"
171  "    -n[othing] - do nothing (to be used with -i option)\n"
172 +"    -s[td]     - decode to RAW and write to STDOUT\n"
173  "  \n"
174  "  output options:\n"
175  //"    -spdif - spdif output (no other options will work in this mode)\n"
176 @@ -184,12 +188,13 @@ int main(int argc, char *argv[])
177    /////////////////////////////////////////////////////////
178    // Sinks
179  
180 -  enum { mode_undefined, mode_nothing, mode_play, mode_raw, mode_wav, mode_decode } mode = mode_undefined;
181 +  enum { mode_undefined, mode_nothing, mode_play, mode_raw, mode_wav, mode_decode, mode_stdout } mode = mode_undefined;
182    const char *out_filename = 0;
183  
184    RAWSink    raw;
185    WAVSink    wav;
186    DSoundSink dsound;
187 +  StdOutSink stdsnk;
188    NullSink   null;
189  
190    Sink *sink = 0;
191 @@ -216,7 +221,7 @@ int main(int argc, char *argv[])
192      {
193        if (parser)
194        {
195 -        printf("-ac3 : ambigous parser\n");
196 +        fprintf(stderr, "-ac3 : ambigous parser\n");
197          return 1;
198        }
199  
200 @@ -229,7 +234,7 @@ int main(int argc, char *argv[])
201      {
202        if (parser)
203        {
204 -        printf("-dts : ambigous parser\n");
205 +        fprintf(stderr, "-dts : ambigous parser\n");
206          return 1;
207        }
208  
209 @@ -242,7 +247,7 @@ int main(int argc, char *argv[])
210      {
211        if (parser)
212        {
213 -        printf("-mpa : ambigous parser\n");
214 +        fprintf(stderr, "-mpa : ambigous parser\n");
215          return 1;
216        }
217  
218 @@ -268,7 +273,7 @@ int main(int argc, char *argv[])
219  
220        if (imask < 0 || imask > array_size(mask_tbl))
221        {
222 -        printf("-spk : incorrect speaker configuration\n");
223 +        fprintf(stderr, "-spk : incorrect speaker configuration\n");
224          return 1;
225        }
226        continue;
227 @@ -280,7 +285,7 @@ int main(int argc, char *argv[])
228        iformat = int(arg_num(argv[iarg]));
229        if (iformat < 0 || iformat > array_size(format_tbl))
230        {
231 -        printf("-fmt : incorrect sample format");
232 +        fprintf(stderr, "-fmt : incorrect sample format");
233          return 1;
234        }
235        continue;
236 @@ -296,7 +301,7 @@ int main(int argc, char *argv[])
237      {
238        if (sink)
239        {
240 -        printf("-decode : ambigous output mode\n");
241 +        fprintf(stderr, "-decode : ambigous output mode\n");
242          return 1;
243        }
244  
245 @@ -312,7 +317,7 @@ int main(int argc, char *argv[])
246      {
247        if (sink)
248        {
249 -        printf("-play : ambigous output mode\n");
250 +        fprintf(stderr, "-play : ambigous output mode\n");
251          return 1;
252        }
253  
254 @@ -328,12 +333,12 @@ int main(int argc, char *argv[])
255      {
256        if (sink)
257        {
258 -        printf("-raw : ambigous output mode\n");
259 +        fprintf(stderr, "-raw : ambigous output mode\n");
260          return 1;
261        }
262        if (argc - iarg < 1)
263        {
264 -        printf("-raw : specify a file name\n");
265 +        fprintf(stderr, "-raw : specify a file name\n");
266          return 1;
267        }
268  
269 @@ -343,19 +348,40 @@ int main(int argc, char *argv[])
270        mode = mode_raw;
271        continue;
272      }
273 +   
274 +    // -s[td] - RAW output to STDOUT
275 +    if (is_arg(argv[iarg], "s", argt_exist) ||
276 +        is_arg(argv[iarg], "std", argt_exist))
277 +    {
278 +      if (sink)
279 +      {
280 +        fprintf(stderr, "-std : ambigous output mode\n");
281 +        return 1;
282 +      }
283 +      if (argc - iarg < 1)
284 +      {
285 +        fprintf(stderr, "-std : specify a file name\n");
286 +        return 1;
287 +      }
288  
289 +      //out_filename = argv[++iarg];
290 +      sink = &stdsnk;
291 +      control = 0;
292 +      mode = mode_stdout;
293 +      continue;
294 +    }
295      // -w[av] - WAV output
296      if (is_arg(argv[iarg], "w", argt_exist) ||
297          is_arg(argv[iarg], "wav", argt_exist))
298      {
299        if (sink)
300        {
301 -        printf("-wav : ambigous output mode\n");
302 +        fprintf(stderr, "-wav : ambigous output mode\n");
303          return 1;
304        }
305        if (argc - iarg < 1)
306        {
307 -        printf("-wav : specify a file name\n");
308 +        fprintf(stderr, "-wav : specify a file name\n");
309          return 1;
310        }
311  
312 @@ -372,7 +398,7 @@ int main(int argc, char *argv[])
313      {
314        if (sink)
315        {
316 -        printf("-nothing : ambigous output mode\n");
317 +        fprintf(stderr, "-nothing : ambigous output mode\n");
318          return 1;
319        }
320  
321 @@ -614,7 +640,7 @@ int main(int argc, char *argv[])
322        continue;
323      }
324  
325 -    printf("Error: unknown option: %s\n", argv[iarg]);
326 +    fprintf(stderr, "Error: unknown option: %s\n", argv[iarg]);
327      return 1;
328    }
329  
330 @@ -627,13 +653,13 @@ int main(int argc, char *argv[])
331  
332    if (!file.open(input_filename, parser, 1000000))
333    {
334 -    printf("Error: Cannot open file '%s'\n", input_filename);
335 +    fprintf(stderr, "Error: Cannot open file '%s'\n", input_filename);
336      return 1;
337    }
338      
339    if (!file.stats())
340    {
341 -    printf("Error: Cannot detect input file format\n", input_filename);
342 +    fprintf(stderr, "Error: Cannot detect input file format\n", input_filename);
343      return 1;
344    }
345  
346 @@ -643,7 +669,7 @@ int main(int argc, char *argv[])
347  
348    if (!file.is_frame_loaded())
349    {
350 -    printf("Error: Cannot load the first frame\n");
351 +    fprintf(stderr, "Error: Cannot load the first frame\n");
352      return 1;
353    }
354  
355 @@ -655,9 +681,9 @@ int main(int argc, char *argv[])
356    {
357      char info[1024];
358      file.file_info(info, sizeof(info));
359 -    printf("%s\n", info);
360 +    fprintf(stderr, "%s\n", info);
361      file.stream_info(info, sizeof(info));
362 -    printf("%s", info);
363 +    fprintf(stderr, "%s", info);
364    }
365  
366    if (mode == mode_nothing)
367 @@ -678,7 +704,7 @@ int main(int argc, char *argv[])
368    Speakers user_spk(format_tbl[iformat], mask_tbl[imask], 0, level_tbl[iformat]);
369    if (!dvd_graph.set_user(user_spk))
370    {
371 -    printf("Error: unsupported user format (%s %s %i)\n", 
372 +    fprintf(stderr, "Error: unsupported user format (%s %s %i)\n", 
373        user_spk.format_text(), user_spk.mode_text(), user_spk.sample_rate);
374      return 1;
375    }
376 @@ -686,7 +712,7 @@ int main(int argc, char *argv[])
377    Speakers in_spk = file.get_spk();
378    if (!dvd_graph.set_input(in_spk))
379    {
380 -    printf("Error: unsupported input format (%s %s %i)\n", 
381 +    fprintf(stderr, "Error: unsupported input format (%s %s %i)\n", 
382        in_spk.format_text(), in_spk.mode_text(), in_spk.sample_rate);
383      return 1;
384    }
385 @@ -718,10 +744,18 @@ int main(int argc, char *argv[])
386     
387    switch (mode)
388    {
389 +    case mode_stdout:
390 +      if (!stdsnk.is_open())
391 +      {
392 +        fprintf(stderr, "Error: failed to open standard output handle.\n");
393 +        return 1;
394 +      }
395 +      break;
396 +  
397      case mode_raw:
398        if (!out_filename || !raw.open(out_filename))
399        {
400 -        printf("Error: failed to open output file '%s'\n", out_filename);
401 +        fprintf(stderr, "Error: failed to open output file '%s'\n", out_filename);
402          return 1;
403        }
404        break;
405 @@ -729,7 +763,7 @@ int main(int argc, char *argv[])
406      case mode_wav:
407        if (!out_filename || !wav.open(out_filename))
408        {
409 -        printf("Error: failed to open output file '%s'\n", out_filename);
410 +        fprintf(stderr, "Error: failed to open output file '%s'\n", out_filename);
411          return 1;
412        }
413        break;
414 @@ -737,7 +771,7 @@ int main(int argc, char *argv[])
415      case mode_play:
416        if (!dsound.open_dsound(0))
417        {
418 -        printf("Error: failed to init DirectSound\n");
419 +        fprintf(stderr, "Error: failed to init DirectSound\n");
420          return 1;
421        }
422        break;
423 @@ -765,27 +799,28 @@ int main(int argc, char *argv[])
424  
425    int streams = 0;
426  
427 -//  fprintf(stderr, " 0.0%% Frs:      0 Err: 0 Time:   0:00.000i Level:    0dB FPS:    0 CPU: 0%%\r"); 
428 +//  ffprintf(stderr, stderr, " 0.0%% Frs:      0 Err: 0 Time:   0:00.000i Level:    0dB FPS:    0 CPU: 0%%\r"); 
429  
430    file.seek(0);
431  
432 -  #define PRINT_STAT                                                                                           \
433 -  {                                                                                                            \
434 -    if (control)                                                                                               \
435 -    {                                                                                                          \
436 -      dvd_graph.proc.get_output_levels(control->get_playback_time(), levels);                                  \
437 -      level = levels[0];                                                                                       \
438 -      for (i = 1; i < NCHANNELS; i++)                                                                          \
439 -        if (levels[i] > level)                                                                                 \
440 -          level = levels[i];                                                                                   \
441 -    }                                                                                                          \
442 -    fprintf(stderr, "%4.1f%% Frs: %-6i Err: %-i Time: %3i:%02i.%03i Level: %-4idB FPS: %-4i CPU: %.1f%%  \r",  \
443 -      file.get_pos(file.relative) * 100,                                                                       \
444 -      file.get_frames(), dvd_graph.dec.get_errors(),                                                           \
445 -      int(time/60), int(time) % 60, int(time * 1000) % 1000,                                                   \
446 -      int(value2db(level)),                                                                                    \
447 -      int(file.get_frames() / time),                                                                           \
448 -      cpu_current.usage() * 100);                                                                              \
449 +  #define PRINT_STAT                                                                                             \
450 +  {                                                                                                              \
451 +    if (control)                                                                                                 \
452 +    {                                                                                                            \
453 +      dvd_graph.proc.get_output_levels(control->get_playback_time(), levels);                                    \
454 +      level = levels[0];                                                                                         \
455 +      for (i = 1; i < NCHANNELS; i++)                                                                            \
456 +        if (levels[i] > level)                                                                                   \
457 +          level = levels[i];                                                                                     \
458 +    }                                                                                                            \
459 +    fprintf(stderr, "[%4.1f%%] Frs: %-6i Err: %-i Time: %3i:%02i.%03i Level: %-4idB FPS: %-4i CPU: %.1f%%  \r",  \
460 +      file.get_pos(file.relative) * 100,                                                                         \
461 +      file.get_frames(), dvd_graph.dec.get_errors(),                                                             \
462 +      int(time/60), int(time) % 60, int(time * 1000) % 1000,                                                     \
463 +      int(value2db(level)),                                                                                      \
464 +      int(file.get_frames() / time),                                                                             \
465 +      cpu_current.usage() * 100);                                                                                \
466 +         fflush(stderr);                                                                                            \
467    }
468  
469    #define DROP_STAT \
470 @@ -811,7 +846,7 @@ int main(int argc, char *argv[])
471          {
472            char info[1024];
473            file.stream_info(info, sizeof(info));
474 -          printf("\n\n%s", info);
475 +          fprintf(stderr, "\n\n%s", info);
476          }
477  
478          streams++;
479 @@ -825,7 +860,7 @@ int main(int argc, char *argv[])
480        chunk.set_rawdata(file.get_spk(), file.get_frame(), file.get_frame_size());
481        if (!dvd_graph.process(&chunk))
482        {
483 -        printf("\nError in dvd_graph.process()\n");
484 +        fprintf(stderr, "\nError in dvd_graph.process()\n");
485          return 1;
486        }
487  
488 @@ -833,7 +868,7 @@ int main(int argc, char *argv[])
489        {
490          if (!dvd_graph.get_chunk(&chunk))
491          {
492 -          printf("\nError in dvd_graph.get_chunk()\n");
493 +          fprintf(stderr, "\nError in dvd_graph.get_chunk()\n");
494            return 1;
495          }
496  
497 @@ -847,12 +882,12 @@ int main(int argc, char *argv[])
498              if (sink->query_input(chunk.spk))
499              {
500                DROP_STAT;
501 -              printf("Opening audio output %s %s %i...\n",
502 +              fprintf(stderr, "Opening audio output %s %s %i...\n",
503                  chunk.spk.format_text(), chunk.spk.mode_text(), chunk.spk.sample_rate);
504              }
505              else
506              {
507 -              printf("\nOutput format %s %s %i is unsupported\n",
508 +              fprintf(stderr, "\nOutput format %s %s %i is unsupported\n",
509                  chunk.spk.format_text(), chunk.spk.mode_text(), chunk.spk.sample_rate);
510                return 1;
511              }
512 @@ -860,7 +895,7 @@ int main(int argc, char *argv[])
513  
514            if (!sink->process(&chunk))
515            {
516 -            printf("\nError in sink->process()\n");
517 +            fprintf(stderr, "\nError in sink->process()\n");
518              return 1;
519            }
520          }
521 @@ -893,7 +928,7 @@ int main(int argc, char *argv[])
522  
523    if (!dvd_graph.process_to(&chunk, sink))
524    {
525 -    printf("\nProcessing error!\n");
526 +    fprintf(stderr, "\nProcessing error!\n");
527      return 1;
528    }
529  
530 @@ -907,13 +942,13 @@ int main(int argc, char *argv[])
531    // Final statistics
532  
533    PRINT_STAT;
534 -  printf("\n---------------------------------------\n");
535 +  fprintf(stderr, "\n---------------------------------------\n");
536    if (streams > 1)
537 -    printf("Streams found: %i\n", streams);
538 -  printf("Frames/errors: %i/%i\n", file.get_frames(), dvd_graph.dec.get_errors());
539 -  printf("System time: %ims\n", int(cpu_total.get_system_time() * 1000));
540 -  printf("Process time: %ims\n", int(cpu_total.get_thread_time() * 1000 ));
541 -  printf("Approx. %.2f%% realtime CPU usage\n", double(cpu_total.get_thread_time() * 100) / file.get_size(file.time));
542 +    fprintf(stderr, "Streams found: %i\n", streams);
543 +  fprintf(stderr, "Frames/errors: %i/%i\n", file.get_frames(), dvd_graph.dec.get_errors());
544 +  fprintf(stderr, "System time: %ims\n", int(cpu_total.get_system_time() * 1000));
545 +  fprintf(stderr, "Process time: %ims\n", int(cpu_total.get_thread_time() * 1000 ));
546 +  fprintf(stderr, "Approx. %.2f%% realtime CPU usage\n", double(cpu_total.get_thread_time() * 100) / file.get_size(file.time));
547  
548    /////////////////////////////////////////////////////////
549    // Print levels histogram
550 @@ -930,22 +965,35 @@ int main(int argc, char *argv[])
551      max_level = dvd_graph.proc.get_max_level();
552      dbpb = dvd_graph.proc.get_dbpb();
553  
554 -    printf("\nHistogram:\n");
555 -    printf("------------------------------------------------------------------------------\n");
556 +    fprintf(stderr, "\nHistogram:\n");
557 +    fprintf(stderr, "------------------------------------------------------------------------------\n");
558      for (i = 0; i*dbpb < 100 && i < MAX_HISTOGRAM; i++)
559      {
560 -      printf("%2idB: %4.1f ", i * dbpb, hist[i] * 100);
561 +      fprintf(stderr, "%2idB: %4.1f ", i * dbpb, hist[i] * 100);
562        for (j = 0; j < 67 && j < hist[i] * 67; j++)
563 -        printf("*");
564 -      printf("\n");
565 +        fprintf(stderr, "*");
566 +      fprintf(stderr, "\n");
567      }
568 -    printf("------------------------------------------------------------------------------\n");
569 -    printf("max_level;%f\ndbpb;%i\nhistogram;", max_level, dbpb);
570 +    fprintf(stderr, "------------------------------------------------------------------------------\n");
571 +    fprintf(stderr, "max_level;%f\ndbpb;%i\nhistogram;", max_level, dbpb);
572      for (i = 0; i < MAX_HISTOGRAM; i++)
573 -      printf("%.4f;", hist[i]);
574 -    printf("\n");
575 -    printf("------------------------------------------------------------------------------\n");
576 +      fprintf(stderr, "%.4f;", hist[i]);
577 +    fprintf(stderr, "\n");
578 +    fprintf(stderr, "------------------------------------------------------------------------------\n");
579    }
580  
581    return 0;
582  }
583 +
584 +int main(int argc, char *argv[])
585 +{
586 +  int argc_utf8;
587 +  char **argv_utf8;
588 +  int exit_code;
589 +
590 +  init_commandline_arguments_utf8(&argc_utf8, &argv_utf8);
591 +  exit_code = valdec_main(argc_utf8, argv_utf8);
592 +  free_commandline_arguments_utf8(&argc_utf8, &argv_utf8);
593 +  
594 +  return exit_code;
595 +}
596 diff --git a/tools/valdec.sln b/tools/valdec.sln
597 index 9120b95..8b0cf39 100644
598 --- a/tools/valdec.sln
599 +++ b/tools/valdec.sln
600 @@ -1,12 +1,12 @@
601  ï»¿
602  Microsoft Visual Studio Solution File, Format Version 10.00
603  # Visual Studio 2008
604 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "valdec", "valdec.vcproj", "{871889DF-6EF7-461F-AC1B-7DA682CB79A0}"
605 +Project("{EAF909A5-FA59-4C3D-9431-0FCC20D5BCF9}") = "valdec", "valdec.icproj", "{EB870031-881E-455A-A1E2-5FD222F92D61}"
606         ProjectSection(ProjectDependencies) = postProject
607 -               {30FCD216-1CAD-48FD-BF4B-337572F7EC9C} = {30FCD216-1CAD-48FD-BF4B-337572F7EC9C}
608 +               {C9AE46F3-AA5D-421B-99DF-3BBA26AEF6B1} = {C9AE46F3-AA5D-421B-99DF-3BBA26AEF6B1}
609         EndProjectSection
610  EndProject
611 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "valib", "..\valib\lib\valib.vcproj", "{30FCD216-1CAD-48FD-BF4B-337572F7EC9C}"
612 +Project("{EAF909A5-FA59-4C3D-9431-0FCC20D5BCF9}") = "valib", "..\valib\lib\valib.icproj", "{C9AE46F3-AA5D-421B-99DF-3BBA26AEF6B1}"
613  EndProject
614  Global
615         GlobalSection(SolutionConfigurationPlatforms) = preSolution
616 @@ -16,22 +16,38 @@ Global
617                 Release|x64 = Release|x64
618         EndGlobalSection
619         GlobalSection(ProjectConfigurationPlatforms) = postSolution
620 -               {871889DF-6EF7-461F-AC1B-7DA682CB79A0}.Debug|Win32.ActiveCfg = Debug|Win32
621 -               {871889DF-6EF7-461F-AC1B-7DA682CB79A0}.Debug|Win32.Build.0 = Debug|Win32
622 -               {871889DF-6EF7-461F-AC1B-7DA682CB79A0}.Debug|x64.ActiveCfg = Debug|x64
623 -               {871889DF-6EF7-461F-AC1B-7DA682CB79A0}.Debug|x64.Build.0 = Debug|x64
624 -               {871889DF-6EF7-461F-AC1B-7DA682CB79A0}.Release|Win32.ActiveCfg = Release|Win32
625 -               {871889DF-6EF7-461F-AC1B-7DA682CB79A0}.Release|Win32.Build.0 = Release|Win32
626 -               {871889DF-6EF7-461F-AC1B-7DA682CB79A0}.Release|x64.ActiveCfg = Release|x64
627 +               {EB870031-881E-455A-A1E2-5FD222F92D61}.Debug|Win32.ActiveCfg = Debug|Win32
628 +               {EB870031-881E-455A-A1E2-5FD222F92D61}.Debug|Win32.Build.0 = Debug|Win32
629 +               {EB870031-881E-455A-A1E2-5FD222F92D61}.Debug|x64.ActiveCfg = Debug|x64
630 +               {EB870031-881E-455A-A1E2-5FD222F92D61}.Debug|x64.Build.0 = Debug|x64
631 +               {EB870031-881E-455A-A1E2-5FD222F92D61}.Release|Win32.ActiveCfg = Release|Win32
632 +               {EB870031-881E-455A-A1E2-5FD222F92D61}.Release|Win32.Build.0 = Release|Win32
633 +               {EB870031-881E-455A-A1E2-5FD222F92D61}.Release|x64.ActiveCfg = Release|x64
634 +               {EB870031-881E-455A-A1E2-5FD222F92D61}.Release|x64.Build.0 = Release|x64
635 +               {C9AE46F3-AA5D-421B-99DF-3BBA26AEF6B1}.Debug|Win32.ActiveCfg = Debug|Win32
636 +               {C9AE46F3-AA5D-421B-99DF-3BBA26AEF6B1}.Debug|Win32.Build.0 = Debug|Win32
637 +               {C9AE46F3-AA5D-421B-99DF-3BBA26AEF6B1}.Debug|x64.ActiveCfg = Debug|x64
638 +               {C9AE46F3-AA5D-421B-99DF-3BBA26AEF6B1}.Debug|x64.Build.0 = Debug|x64
639 +               {C9AE46F3-AA5D-421B-99DF-3BBA26AEF6B1}.Release|Win32.ActiveCfg = Release|Win32
640 +               {C9AE46F3-AA5D-421B-99DF-3BBA26AEF6B1}.Release|Win32.Build.0 = Release|Win32
641 +               {C9AE46F3-AA5D-421B-99DF-3BBA26AEF6B1}.Release|x64.ActiveCfg = Release|x64
642 +               {C9AE46F3-AA5D-421B-99DF-3BBA26AEF6B1}.Release|x64.Build.0 = Release|x64
643                 {871889DF-6EF7-461F-AC1B-7DA682CB79A0}.Release|x64.Build.0 = Release|x64
644 -               {30FCD216-1CAD-48FD-BF4B-337572F7EC9C}.Debug|Win32.ActiveCfg = Debug|Win32
645 -               {30FCD216-1CAD-48FD-BF4B-337572F7EC9C}.Debug|Win32.Build.0 = Debug|Win32
646 -               {30FCD216-1CAD-48FD-BF4B-337572F7EC9C}.Debug|x64.ActiveCfg = Debug|x64
647 -               {30FCD216-1CAD-48FD-BF4B-337572F7EC9C}.Debug|x64.Build.0 = Debug|x64
648 -               {30FCD216-1CAD-48FD-BF4B-337572F7EC9C}.Release|Win32.ActiveCfg = Release|Win32
649 -               {30FCD216-1CAD-48FD-BF4B-337572F7EC9C}.Release|Win32.Build.0 = Release|Win32
650 -               {30FCD216-1CAD-48FD-BF4B-337572F7EC9C}.Release|x64.ActiveCfg = Release|x64
651 +               {871889DF-6EF7-461F-AC1B-7DA682CB79A0}.Release|x64.ActiveCfg = Release|x64
652 +               {871889DF-6EF7-461F-AC1B-7DA682CB79A0}.Release|Win32.Build.0 = Release|Win32
653 +               {871889DF-6EF7-461F-AC1B-7DA682CB79A0}.Release|Win32.ActiveCfg = Release|Win32
654 +               {871889DF-6EF7-461F-AC1B-7DA682CB79A0}.Debug|x64.Build.0 = Debug|x64
655 +               {871889DF-6EF7-461F-AC1B-7DA682CB79A0}.Debug|x64.ActiveCfg = Debug|x64
656 +               {871889DF-6EF7-461F-AC1B-7DA682CB79A0}.Debug|Win32.Build.0 = Debug|Win32
657 +               {871889DF-6EF7-461F-AC1B-7DA682CB79A0}.Debug|Win32.ActiveCfg = Debug|Win32
658                 {30FCD216-1CAD-48FD-BF4B-337572F7EC9C}.Release|x64.Build.0 = Release|x64
659 +               {30FCD216-1CAD-48FD-BF4B-337572F7EC9C}.Release|x64.ActiveCfg = Release|x64
660 +               {30FCD216-1CAD-48FD-BF4B-337572F7EC9C}.Release|Win32.Build.0 = Release|Win32
661 +               {30FCD216-1CAD-48FD-BF4B-337572F7EC9C}.Release|Win32.ActiveCfg = Release|Win32
662 +               {30FCD216-1CAD-48FD-BF4B-337572F7EC9C}.Debug|x64.Build.0 = Debug|x64
663 +               {30FCD216-1CAD-48FD-BF4B-337572F7EC9C}.Debug|x64.ActiveCfg = Debug|x64
664 +               {30FCD216-1CAD-48FD-BF4B-337572F7EC9C}.Debug|Win32.Build.0 = Debug|Win32
665 +               {30FCD216-1CAD-48FD-BF4B-337572F7EC9C}.Debug|Win32.ActiveCfg = Debug|Win32
666         EndGlobalSection
667         GlobalSection(SolutionProperties) = preSolution
668                 HideSolutionNode = FALSE
669 diff --git a/tools/valdec.vcproj b/tools/valdec.vcproj
670 index d6a6b98..4d3056b 100644
671 --- a/tools/valdec.vcproj
672 +++ b/tools/valdec.vcproj
673 @@ -1,7 +1,7 @@
674  <?xml version="1.0" encoding="windows-1251"?>
675  <VisualStudioProject
676         ProjectType="Visual C++"
677 -       Version="9.00"
678 +       Version="9,00"
679         Name="valdec"
680         ProjectGUID="{871889DF-6EF7-461F-AC1B-7DA682CB79A0}"
681         RootNamespace="valdec"
682 @@ -93,12 +93,11 @@
683                         />
684                 </Configuration>
685                 <Configuration
686 -                       Name="Release|Win32"
687 -                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"
688 -                       IntermediateDirectory="$(ConfigurationName)\$(ProjectName)"
689 +                       Name="Debug|x64"
690 +                       OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"
691 +                       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)\$(ProjectName)"
692                         ConfigurationType="1"
693                         CharacterSet="1"
694 -                       WholeProgramOptimization="1"
695                         >
696                         <Tool
697                                 Name="VCPreBuildEventTool"
698 @@ -114,15 +113,16 @@
699                         />
700                         <Tool
701                                 Name="VCMIDLTool"
702 +                               TargetEnvironment="3"
703                         />
704                         <Tool
705                                 Name="VCCLCompilerTool"
706 -                               Optimization="2"
707 -                               EnableIntrinsicFunctions="true"
708 +                               Optimization="0"
709                                 AdditionalIncludeDirectories="..\valib\valib"
710 -                               PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
711 -                               RuntimeLibrary="0"
712 -                               EnableFunctionLevelLinking="true"
713 +                               PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
714 +                               MinimalRebuild="true"
715 +                               BasicRuntimeChecks="3"
716 +                               RuntimeLibrary="1"
717                                 UsePrecompiledHeader="0"
718                                 WarningLevel="3"
719                                 DebugInformationFormat="3"
720 @@ -139,12 +139,10 @@
721                         <Tool
722                                 Name="VCLinkerTool"
723                                 AdditionalDependencies="dsound.lib"
724 -                               LinkIncremental="1"
725 +                               LinkIncremental="2"
726                                 GenerateDebugInformation="true"
727                                 SubSystem="1"
728 -                               OptimizeReferences="2"
729 -                               EnableCOMDATFolding="2"
730 -                               TargetMachine="1"
731 +                               TargetMachine="17"
732                         />
733                         <Tool
734                                 Name="VCALinkTool"
735 @@ -169,11 +167,12 @@
736                         />
737                 </Configuration>
738                 <Configuration
739 -                       Name="Debug|x64"
740 -                       OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"
741 -                       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)\$(ProjectName)"
742 +                       Name="Release|Win32"
743 +                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"
744 +                       IntermediateDirectory="$(ConfigurationName)\$(ProjectName)"
745                         ConfigurationType="1"
746                         CharacterSet="1"
747 +                       WholeProgramOptimization="1"
748                         >
749                         <Tool
750                                 Name="VCPreBuildEventTool"
751 @@ -189,19 +188,21 @@
752                         />
753                         <Tool
754                                 Name="VCMIDLTool"
755 -                               TargetEnvironment="3"
756                         />
757                         <Tool
758                                 Name="VCCLCompilerTool"
759 -                               Optimization="0"
760 +                               Optimization="2"
761 +                               InlineFunctionExpansion="2"
762 +                               EnableIntrinsicFunctions="true"
763 +                               FavorSizeOrSpeed="1"
764                                 AdditionalIncludeDirectories="..\valib\valib"
765 -                               PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
766 -                               MinimalRebuild="true"
767 -                               BasicRuntimeChecks="3"
768 -                               RuntimeLibrary="1"
769 +                               PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
770 +                               RuntimeLibrary="0"
771 +                               EnableFunctionLevelLinking="true"
772 +                               EnableEnhancedInstructionSet="0"
773                                 UsePrecompiledHeader="0"
774                                 WarningLevel="3"
775 -                               DebugInformationFormat="3"
776 +                               DebugInformationFormat="0"
777                         />
778                         <Tool
779                                 Name="VCManagedResourceCompilerTool"
780 @@ -214,11 +215,13 @@
781                         />
782                         <Tool
783                                 Name="VCLinkerTool"
784 -                               AdditionalDependencies="dsound.lib"
785 -                               LinkIncremental="2"
786 +                               AdditionalDependencies="LIBIOMP5MT.lib"
787 +                               LinkIncremental="1"
788                                 GenerateDebugInformation="true"
789                                 SubSystem="1"
790 -                               TargetMachine="17"
791 +                               OptimizeReferences="2"
792 +                               EnableCOMDATFolding="2"
793 +                               TargetMachine="1"
794                         />
795                         <Tool
796                                 Name="VCALinkTool"
797 @@ -324,6 +327,10 @@
798         </References>
799         <Files>
800                 <File
801 +                       RelativePath=".\unicode_support.cpp"
802 +                       >
803 +               </File>
804 +               <File
805                         RelativePath=".\valdec.cpp"
806                         >
807                 </File>
808 diff --git a/valib/lib/valib.vcproj b/valib/lib/valib.vcproj
809 index a30826e..3b04d9f 100644
810 --- a/valib/lib/valib.vcproj
811 +++ b/valib/lib/valib.vcproj
812 @@ -1,7 +1,7 @@
813  <?xml version="1.0" encoding="windows-1251"?>
814  <VisualStudioProject
815         ProjectType="Visual C++"
816 -       Version="9.00"
817 +       Version="9,00"
818         Name="valib"
819         ProjectGUID="{30FCD216-1CAD-48FD-BF4B-337572F7EC9C}"
820         RootNamespace="valib"
821 @@ -164,12 +164,15 @@
822                         <Tool
823                                 Name="VCCLCompilerTool"
824                                 Optimization="2"
825 +                               InlineFunctionExpansion="2"
826                                 EnableIntrinsicFunctions="true"
827 +                               FavorSizeOrSpeed="1"
828                                 PreprocessorDefinitions="NDEBUG"
829                                 RuntimeLibrary="0"
830                                 EnableFunctionLevelLinking="true"
831 +                               EnableEnhancedInstructionSet="0"
832                                 WarningLevel="3"
833 -                               DebugInformationFormat="3"
834 +                               DebugInformationFormat="0"
835                         />
836                         <Tool
837                                 Name="VCManagedResourceCompilerTool"
838 @@ -939,6 +942,14 @@
839                         <File
840                                 RelativePath="..\valib\sink\sink_dshow.cpp"
841                                 >
842 +                               <FileConfiguration
843 +                                       Name="Release|Win32"
844 +                                       ExcludedFromBuild="true"
845 +                                       >
846 +                                       <Tool
847 +                                               Name="VCCLCompilerTool"
848 +                                       />
849 +                               </FileConfiguration>
850                         </File>
851                         <File
852                                 RelativePath="..\valib\sink\sink_dshow.h"
853 @@ -957,6 +968,10 @@
854                                 >
855                         </File>
856                         <File
857 +                               RelativePath="..\valib\sink\sink_stdout.h"
858 +                               >
859 +                       </File>
860 +                       <File
861                                 RelativePath="..\valib\sink\sink_wav.cpp"
862                                 >
863                         </File>
864 diff --git a/valib/valib/auto_file.cpp b/valib/valib/auto_file.cpp
865 index 235ad1d..8d99c91 100644
866 --- a/valib/valib/auto_file.cpp
867 +++ b/valib/valib/auto_file.cpp
868 @@ -1,5 +1,6 @@
869  #include <limits.h>
870  #include "auto_file.h"
871 +#include "..\..\tools\unicode_support.h"
872  
873  #if defined(_MSC_VER) && (_MSC_VER >= 1400)
874  
875 @@ -40,7 +41,7 @@ AutoFile::open(const char *filename, const char *mode)
876  {
877    if (f) close();
878    filesize = max_size;
879 -  f = fopen(filename, mode);
880 +  f = fopen_utf8(filename, mode);
881    if (f)
882    {
883      if (portable_seek(f, 0, SEEK_END) == 0)
884 diff --git a/valib/valib/sink/sink_dsound.cpp b/valib/valib/sink/sink_dsound.cpp
885 index 542d31f..c5aa132 100644
886 --- a/valib/valib/sink/sink_dsound.cpp
887 +++ b/valib/valib/sink/sink_dsound.cpp
888 @@ -47,8 +47,8 @@ DSoundSink::open_dsound(HWND _hwnd, int _buf_size_ms, int _preload_ms, LPCGUID _
889  
890    // Open DirectSound
891  
892 -  if FAILED(DirectSoundCreate(_device, &ds, 0))
893 -    return false;
894 +  //if FAILED(DirectSoundCreate(_device, &ds, 0))
895 +  return false;
896  
897    if (!_hwnd) _hwnd = GetForegroundWindow();
898    if (!_hwnd) _hwnd = GetDesktopWindow();
899 diff --git a/valib/valib/sink/sink_stdout.h b/valib/valib/sink/sink_stdout.h
900 new file mode 100644
901 index 0000000..3112531
902 --- /dev/null
903 +++ b/valib/valib/sink/sink_stdout.h
904 @@ -0,0 +1,93 @@
905 +/*
906 +  RAW file output audio renderer
907 +*/
908 +
909 +#ifndef VALIB_SINK_STDOUT_H
910 +#define VALIB_SINK_STDOUT_H
911 +
912 +#include "filter.h"
913 +#include "auto_file.h"
914 +
915 +class StdOutSink : public Sink
916 +{
917 +protected:
918 +  Speakers spk;
919 +  HANDLE h;
920 +  //AutoFile f;
921 +
922 +public:
923 +  StdOutSink():
924 +  h(GetStdHandle(STD_OUTPUT_HANDLE))
925 +  {}
926 +
927 +  StdOutSink(const char *_filename): 
928 +  h(GetStdHandle(STD_OUTPUT_HANDLE))
929 +  {}
930 +
931 +  StdOutSink(FILE *_f): 
932 +  h(GetStdHandle(STD_OUTPUT_HANDLE))
933 +  {}
934 +
935 +  /////////////////////////////////////////////////////////
936 +  // RAWSink interface
937 +
938 +  bool open(const char *_filename)
939 +  {
940 +    return true; //f.open(_filename, "wb");
941 +  }
942 +
943 +  bool open(FILE *_f)
944 +  {
945 +    return true; //f.open(_f);
946 +  }
947 +
948 +  void close()
949 +  {
950 +    //f.close();
951 +    spk = spk_unknown;
952 +  }
953 +
954 +  bool is_open() const
955 +  {
956 +    return ((h != INVALID_HANDLE_VALUE) && (h != 0)); //f.is_open();
957 +  }
958 +
959 +  /////////////////////////////////////////////////////////
960 +  // Sink interface
961 +
962 +  virtual bool query_input(Speakers _spk) const  
963 +  { 
964 +    // cannot write linear format
965 +    return /*f.is_open() &&*/ _spk.format != FORMAT_LINEAR;
966 +  }
967 +
968 +  virtual bool set_input(Speakers _spk)
969 +  { 
970 +    if (!query_input(_spk))
971 +      return false;
972 +
973 +    spk = _spk;
974 +    return true;
975 +  }
976 +
977 +  virtual Speakers get_input() const
978 +  {
979 +    return spk;
980 +  }
981 +
982 +  // data write
983 +  virtual bool process(const Chunk *_chunk)               
984 +  {
985 +    if (_chunk->is_dummy())
986 +      return true;
987 +
988 +    if (spk != _chunk->spk)
989 +      if (!set_input(_chunk->spk))
990 +        return false;
991 +
992 +       DWORD bytesWritten = 0;
993 +    return WriteFile(h, _chunk->rawdata, _chunk->size, &bytesWritten, NULL); //f.write(_chunk->rawdata, _chunk->size) == _chunk->size;
994 +  }
995 +};
996 +
997 +#endif