Updated SoX binary to v14.4.2-Git (2014-10-06), compiled with ICL 15.0 and MSVC 12.0.

This commit is contained in:
LoRd_MuldeR 2014-10-06 16:46:41 +02:00
parent 3df2215a0e
commit 373702e07e
7 changed files with 964 additions and 4 deletions

View File

@ -19,6 +19,7 @@ a:visited { color: #0000EE; }
<a name="4.11"></a>Changes between v4.10 and v4.11 [<font color="darkred">unreleased</font>]:<br><ul>
<li>Updated MediaInfo to v0.7.70 (2014-09-03), compiled with ICL 15.0 and MSVC 12.0
<li>Updated SoX to v14.4.2-Git (2012-10-06), compiled with ICL 15.0 and MSVC 12.0
<li>Updated Opus libraries to v1.1.x and Opus-Tools v0.1.9 to latest Git Master (2014-10-04)
<li>Updated mpg123 decoder to v1.20.1 (2014-06-17), compiled with GCC 4.9.0
<li>Updated Vorbis encoder to OggEnc v2.87 (2014-06-24), using libvorbis v1.3.4 and aoTuV b6.03_2014
@ -91,7 +92,7 @@ a:visited { color: #0000EE; }
<li>Updated mpg123 decoder to v1.15.3 (2013-04-03), compiled with GCC 4.8.0
<li>Updated MediaInfo to v0.7.62 (2013-02-22), compiled with ICL 12.1.7 and MSVC 10.0
<li>Updated Monkey's Audio binary to v4.11 (2013-01-20)
<li>Updated SoX to to v14.4.1 (2012-02-09), compiled with ICL 13.0 and MSVC 10.0
<li>Updated SoX to v14.4.1 (2012-02-09), compiled with ICL 13.0 and MSVC 10.0
<li>Updated GnuPG to v1.4.13, compiled with GCC 4.7.2
<li>Updated language files (big thank-you to all contributors !!!)
<li>Fixed handling of certain characters when passing meta tags on the command-line

View File

@ -0,0 +1,498 @@
src/DynamicAudioNormalizerSoX.c | 479 ++++++++++++++++++++++++++++++++++++++++
src/effects.h | 1 +
2 files changed, 480 insertions(+)
diff --git a/src/DynamicAudioNormalizerSoX.c b/src/DynamicAudioNormalizerSoX.c
new file mode 100644
index 0000000..e901f94
--- /dev/null
+++ b/src/DynamicAudioNormalizerSoX.c
@@ -0,0 +1,479 @@
+/* ================================================================================== */
+/* Dynamic Audio Normalizer - SoX Effect Wrapper */
+/* Copyright (c) 2014 LoRd_MuldeR <mulder2@gmx.de>. Some rights reserved. */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining a copy */
+/* of this software and associated documentation files (the "Software"), to deal */
+/* in the Software without restriction, including without limitation the rights */
+/* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
+/* copies of the Software, and to permit persons to whom the Software is */
+/* furnished to do so, subject to the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be included in */
+/* all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
+/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
+/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
+/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
+/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
+/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN */
+/* THE SOFTWARE. */
+/* */
+/* http://opensource.org/licenses/MIT */
+/* ================================================================================== */
+
+/*Shut up warnings*/
+#define _CRT_SECURE_NO_WARNINGS
+
+/*printf() macros*/
+#ifndef __STDC_FORMAT_MACROS
+#define __STDC_FORMAT_MACROS 1
+#endif
+
+/*SoX internal stuff*/
+#include "sox_i.h"
+
+/*Win32 Unicode support*/
+#ifdef _WIN32
+#include "unicode_support.h"
+#else
+#define lsx_fopen(X,Y) fopen((X),(Y))
+#endif /*_WIN32*/
+
+/*StdLib*/
+#include <string.h>
+#include <stdarg.h>
+#include <ctype.h>
+#include <inttypes.h>
+
+/*Linkage*/
+#if defined(_MSC_VER) && defined(_MT)
+#define MDYNAMICAUDIONORMALIZER_STATIC
+static const char *LINKAGE = "Static";
+#else
+static const char *LINKAGE = "Shared";
+#endif
+
+/*Dynamic Audio Normalizer*/
+#include <DynamicAudioNormalizer.h>
+
+/* ================================================================================== */
+/* Private Data */
+/* ================================================================================== */
+
+typedef struct
+{
+ uint32_t frameLenMsec;
+ uint32_t filterSize;
+ double peakValue;
+ double maxAmplification;
+ double targetRms;
+ double compressFactor;
+ int channelsCoupled;
+ int enableDCCorrection;
+ int altBoundaryMode;
+ FILE *logFile;
+}
+settings_t;
+
+typedef struct
+{
+ settings_t settings;
+ MDynamicAudioNormalizer_Handle *instance;
+ double **temp;
+ size_t tempSize;
+}
+priv_t;
+
+/* ================================================================================== */
+/* Internal Functions */
+/* ================================================================================== */
+
+static int parseArgInt(const char *const str, uint32_t *parameter, const uint32_t min_val, const uint32_t max_val)
+{
+ uint32_t temp;
+ if(sscanf(str, "%u", &temp) == 1)
+ {
+ *parameter = max(min_val, min(max_val, temp));
+ return 1;
+ }
+ lsx_fail("Failed to parse integral value `%s'", str);
+ return 0;
+}
+
+static int parseArgDbl(const char *const str, double *parameter, const double min_val, const double max_val)
+{
+ double temp;
+ if(sscanf(str, "%lf", &temp) == 1)
+ {
+ *parameter = max(min_val, min(max_val, temp));
+ return 1;
+ }
+ lsx_fail("Failed to parse floating point value `%s'", str);
+ return 0;
+}
+
+#define TRY_PARSE(TYPE, PARAM, MIN, MAX) do \
+{ \
+ if(!parseArg##TYPE(optstate.arg, &(PARAM), (MIN), (MAX))) \
+ { \
+ return 0; \
+ } \
+} \
+while(0)
+
+static void dynaudnorm_defaults(settings_t *settings)
+{
+ memset(settings, 0, sizeof(settings_t));
+
+ settings->frameLenMsec = 500;
+ settings->filterSize = 31;
+ settings->peakValue = 0.95;
+ settings->maxAmplification = 10.0;
+ settings->targetRms = 0.0;
+ settings->compressFactor = 0.0;
+ settings->channelsCoupled = 1;
+ settings->enableDCCorrection = 0;
+ settings->altBoundaryMode = 0;
+}
+
+static int dynaudnorm_parse_args(settings_t *settings, int argc, char **argv)
+{
+ static const char *const opts = "+f:g:p:m:r:ncbs:l:";
+ lsx_getopt_t optstate; char c;
+ lsx_getopt_init(argc, argv, opts, NULL, lsx_getopt_flag_opterr, 1, &optstate);
+
+ while((c = lsx_getopt(&optstate)) != -1)
+ {
+ switch(tolower(c))
+ {
+ case 'f':
+ TRY_PARSE(Int, settings->frameLenMsec, 10, 8000);
+ break;
+ case 'g':
+ TRY_PARSE(Int, settings->filterSize, 3, 301);
+ settings->filterSize += ((settings->filterSize + 1) % 2);
+ break;
+ case 'p':
+ TRY_PARSE(Dbl, settings->peakValue, 0.0, 1.0);
+ break;
+ case 'm':
+ TRY_PARSE(Dbl, settings->maxAmplification, 1.0, 100.0);
+ break;
+ case 'r':
+ TRY_PARSE(Dbl, settings->targetRms, 0.0, 1.0);
+ break;
+ case 'n':
+ settings->channelsCoupled = 0;
+ break;
+ case 'c':
+ settings->enableDCCorrection = 1;
+ break;
+ case 'b':
+ settings->altBoundaryMode = 1;
+ break;
+ case 's':
+ TRY_PARSE(Dbl, settings->compressFactor, 0.0, 30.0);
+ break;
+ case 'l':
+ if(!settings->logFile)
+ {
+ settings->logFile = lsx_fopen(optstate.arg, "w");
+ if(!settings->logFile)
+ {
+ lsx_warn("Failed to open logfile `%s'", optstate.arg);
+ }
+ }
+ break;
+ default:
+ return 0;
+ }
+ }
+
+ return 1;
+}
+
+static void dynaudnorm_deinterleave(double **temp, const sox_sample_t *const in, const size_t samples_per_channel, const unsigned channels)
+{
+ size_t i, c, in_pos = 0;
+
+ for(i = 0; i < samples_per_channel; i++)
+ {
+ for(c = 0; c < channels; c++)
+ {
+ temp[c][i] = ((double)in[in_pos++]) / ((double)SOX_INT32_MAX);
+ }
+ }
+}
+
+static void dynaudnorm_interleave(sox_sample_t *const out, const double *const *const temp, const size_t samples_per_channel, const unsigned channels)
+{
+ size_t i, c, out_pos = 0;
+
+ for(i = 0; i < samples_per_channel; i++)
+ {
+ for(c = 0; c < channels; c++)
+ {
+ out[out_pos++] = (sox_sample_t) round(min(1.0, max(-1.0, temp[c][i])) * ((double)SOX_INT32_MAX));
+ }
+ }
+}
+
+static void dynaudnorm_print(sox_effect_t *effp, const char *const fmt, ...)
+{
+ if(effp->global_info->global_info->output_message_handler)
+ {
+ va_list arg_list;
+ va_start(arg_list, fmt);
+ vfprintf(stderr, fmt, arg_list);
+ va_end(arg_list);
+ }
+}
+
+static void dynaudnorm_log(const int logLevel, const char *const message)
+{
+ switch(logLevel)
+ {
+ case 0:
+ lsx_report("%s", message);
+ break;
+ case 1:
+ lsx_warn("%s", message);
+ break;
+ case 2:
+ lsx_fail("%s", message);
+ break;
+ }
+}
+
+static void dynaudnorm_update_buffsize(const sox_effect_t *const effp, priv_t *const p, const size_t input_samples)
+{
+ size_t c;
+ if(input_samples > p->tempSize)
+ {
+ lsx_warn("Increasing buffer size: %" PRIu64 " -> %" PRIu64, (uint64_t)p->tempSize, (uint64_t)input_samples);
+ for(c = 0; c < effp->in_signal.channels; c++)
+ {
+ p->temp[c] = lsx_realloc(p->temp[c], input_samples * sizeof(double));
+ }
+ p->tempSize = input_samples;
+ }
+}
+
+/* ================================================================================== */
+/* SoX Callback Functions */
+/* ================================================================================== */
+
+static int dynaudnorm_kill(sox_effect_t *effp)
+{
+ lsx_report("dynaudnorm_kill()");
+ lsx_report("flows=%" PRIu64 ", flow=%" PRIu64 , (uint64_t)effp->flows, (uint64_t)effp->flow);
+ return SOX_SUCCESS;
+}
+
+static int dynaudnorm_create(sox_effect_t *effp, int argc, char **argv)
+{
+ priv_t *const p = (priv_t *)effp->priv;
+
+ lsx_report("dynaudnorm_create()");
+ lsx_report("flows=%" PRIu64 ", flow=%" PRIu64 , (uint64_t)effp->flows, (uint64_t)effp->flow);
+
+ memset(effp->priv, 0, sizeof(priv_t));
+ dynaudnorm_defaults(&p->settings);
+
+ if(!dynaudnorm_parse_args(&p->settings, argc, argv))
+ {
+ return lsx_usage(effp);
+ }
+
+ return SOX_SUCCESS;
+}
+
+static int dynaudnorm_stop(sox_effect_t *effp)
+{
+ priv_t *const p = (priv_t *)effp->priv;
+ size_t c;
+
+ lsx_report("dynaudnorm_stop()");
+
+ if(p->instance)
+ {
+ MDYNAMICAUDIONORMALIZER_FUNCTION(destroyInstance)(&p->instance);
+ p->instance = NULL;
+ }
+
+ if(p->settings.logFile)
+ {
+ fclose(p->settings.logFile);
+ p->settings.logFile = NULL;
+ }
+
+ if(p->temp)
+ {
+ for(c = 0; c < effp->in_signal.channels; c++)
+ {
+ free(p->temp[c]);
+ p->temp[c] = NULL;
+ }
+ free(p->temp);
+ p->temp = NULL;
+ }
+
+ return SOX_SUCCESS;
+}
+
+static int dynaudnorm_start(sox_effect_t *effp)
+{
+ priv_t *const p = (priv_t *)effp->priv;
+
+ lsx_report("dynaudnorm_start()");
+ lsx_report("flows=%" PRIu64 ", flow=%" PRIu64 ", in_signal.rate=%.2f, in_signal.channels=%" PRIu64, (uint64_t)effp->flows, (uint64_t)effp->flow, effp->in_signal.rate, (uint64_t)effp->in_signal.channels);
+
+ if((effp->flow == 0) && (effp->global_info->global_info->verbosity > 1))
+ {
+ uint32_t versionMajor, versionMinor, versionPatch;
+ const char *buildDate, *buildTime, *buildCompiler, *buildArch; int buildDebug;
+
+ MDYNAMICAUDIONORMALIZER_FUNCTION(getVersionInfo)(&versionMajor, &versionMinor, &versionPatch);
+ MDYNAMICAUDIONORMALIZER_FUNCTION(getBuildInfo)(&buildDate, &buildTime, &buildCompiler, &buildArch, &buildDebug);
+
+ dynaudnorm_print(effp, "\n---------------------------------------------------------------------------\n");
+ dynaudnorm_print(effp, "Dynamic Audio Normalizer (SoX Wrapper), Version %u.%02u-%u, %s\n", versionMajor, versionMinor, versionPatch, LINKAGE);
+ dynaudnorm_print(effp, "Copyright (c) 2014 LoRd_MuldeR <mulder2@gmx.de>. Some rights reserved.\n");
+ dynaudnorm_print(effp, "Built on %s at %s with %s for %s.\n\n", buildDate, buildTime, buildCompiler, buildArch);
+ dynaudnorm_print(effp, "This program is free software: you can redistribute it and/or modify\n");
+ dynaudnorm_print(effp, "it under the terms of the GNU General Public License <http://www.gnu.org/>.\n");
+ dynaudnorm_print(effp, "Note that this program is distributed with ABSOLUTELY NO WARRANTY.\n");
+ dynaudnorm_print(effp, "---------------------------------------------------------------------------\n\n");
+ }
+
+ p->tempSize = (size_t) max(ceil(effp->in_signal.rate), 8192.0); /*initial buffer size is one second*/
+
+ p->instance = MDYNAMICAUDIONORMALIZER_FUNCTION(createInstance)
+ (
+ effp->in_signal.channels,
+ (uint32_t) round(effp->in_signal.rate),
+ p->settings.frameLenMsec,
+ p->settings.filterSize,
+ p->settings.peakValue,
+ p->settings.maxAmplification,
+ p->settings.targetRms,
+ p->settings.compressFactor,
+ p->settings.channelsCoupled,
+ p->settings.enableDCCorrection,
+ p->settings.altBoundaryMode,
+ p->settings.logFile
+ );
+
+ if(p->instance)
+ {
+ size_t c;
+ p->temp = (double**) lsx_calloc(effp->in_signal.channels, sizeof(double*));
+ for(c = 0; c < effp->in_signal.channels; c++)
+ {
+ p->temp[c] = (double*) lsx_calloc(p->tempSize, sizeof(double));
+ }
+ }
+
+ return (p->instance) ? SOX_SUCCESS : SOX_EINVAL;
+}
+
+static int dynaudnorm_flow(sox_effect_t *effp, const sox_sample_t *ibuf, sox_sample_t *obuf, size_t *isamp, size_t *osamp)
+{
+ priv_t *const p = (priv_t *)effp->priv;
+ const size_t input_samples = min((*isamp), (*osamp)) / effp->in_signal.channels; /*this is per channel!*/
+ int64_t output_samples = 0;
+
+ lsx_debug("dynaudnorm_flow()");
+ dynaudnorm_update_buffsize(effp, p, input_samples);
+
+ if(input_samples > 0)
+ {
+ dynaudnorm_deinterleave(p->temp, ibuf, input_samples, effp->in_signal.channels);
+ if(!MDYNAMICAUDIONORMALIZER_FUNCTION(processInplace)(p->instance, p->temp, ((int64_t) input_samples), &output_samples))
+ {
+ return SOX_EOF;
+ }
+ if(output_samples > 0)
+ {
+ dynaudnorm_interleave(obuf, ((const double**) p->temp), ((size_t) output_samples), effp->in_signal.channels);
+ }
+ }
+
+
+ *isamp = (size_t)(input_samples * effp->in_signal.channels);
+ *osamp = (size_t)(output_samples * effp->in_signal.channels);
+
+ return SOX_SUCCESS;
+}
+
+static int dynaudnorm_drain(sox_effect_t * effp, sox_sample_t * obuf, size_t * osamp)
+{
+ priv_t *const p = (priv_t *)effp->priv;
+ const size_t input_samples = (*osamp) / effp->in_signal.channels; /*this is per channel!*/
+ int64_t output_samples = 0;
+
+ lsx_debug("dynaudnorm_drain()");
+ dynaudnorm_update_buffsize(effp, p, input_samples);
+
+ if(input_samples > 0)
+ {
+ if(!MDYNAMICAUDIONORMALIZER_FUNCTION(flushBuffer)(p->instance, p->temp, ((int64_t) input_samples), &output_samples))
+ {
+ return SOX_EOF;
+ }
+ if(output_samples > 0)
+ {
+ dynaudnorm_interleave(obuf, ((const double**) p->temp), ((size_t) output_samples), effp->in_signal.channels);
+ }
+ }
+ else
+ {
+ lsx_warn("drain() was called with zero-size output buffer!");
+ }
+
+ *osamp = (size_t)(output_samples * effp->in_signal.channels);
+ return SOX_SUCCESS;
+}
+
+/* ================================================================================== */
+/* SoX Public API */
+/* ================================================================================== */
+
+sox_effect_handler_t const * lsx_dynaudnorm_effect_fn(void)
+{
+ static sox_effect_handler_t handler =
+ {
+ "dynaudnorm", NULL, SOX_EFF_MCHAN,
+ dynaudnorm_create, dynaudnorm_start, dynaudnorm_flow, dynaudnorm_drain, dynaudnorm_stop, dynaudnorm_kill, sizeof(priv_t)
+ };
+
+ static char const * lines[] =
+ {
+ "[options]",
+ "",
+ "Algorithm Tweaks:",
+ " -f <value> Frame length, in milliseconds",
+ " -g <value> Gauss filter size, in frames",
+ " -p <value> Target peak magnitude, 0.1-1.0",
+ " -m <value> Maximum gain factor",
+ " -r <value> Target RMS value",
+ " -n Disable channel coupling",
+ " -c Enable the DC bias correction",
+ " -b Use alternative boundary mode",
+ " -s <value> Compress the input data",
+ "",
+ "Diagnostics:",
+ " -l <file> Create a log file",
+ "",
+ "",
+ "Please refer to the manual for a detailed explanation!"
+ };
+
+ static char *usage;
+ handler.usage = lsx_usage_lines(&usage, lines, array_length(lines));
+
+ MDYNAMICAUDIONORMALIZER_FUNCTION(setLogFunction)(dynaudnorm_log);
+ return &handler;
+}
diff --git a/src/effects.h b/src/effects.h
index 450a5c2..78fdabf 100644
--- a/src/effects.h
+++ b/src/effects.h
@@ -88,3 +88,4 @@
EFFECT(upsample)
EFFECT(vad)
EFFECT(vol)
+ EFFECT(dynaudnorm)

View File

@ -0,0 +1,461 @@
src/effects_i.c | 3 +-
src/formats.c | 9 ++-
src/libsox_i.c | 7 +-
src/noiseprof.c | 3 +-
src/sox.c | 30 ++++++--
src/unicode_support.c | 199 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/unicode_support.h | 50 +++++++++++++
7 files changed, 286 insertions(+), 15 deletions(-)
diff --git a/src/effects_i.c b/src/effects_i.c
index 685e962..deee444 100644
--- a/src/effects_i.c
+++ b/src/effects_i.c
@@ -20,6 +20,7 @@
#define LSX_EFF_ALIAS
#include "sox_i.h"
+#include "unicode_support.h"
#include <string.h>
#include <ctype.h>
@@ -463,7 +464,7 @@ FILE * lsx_open_input_file(sox_effect_t * effp, char const * filename, sox_bool
effp->global_info->global_info->stdin_in_use_by = effp->handler.name;
file = stdin;
}
- else if (!(file = fopen(filename, text_mode ? "r" : "rb"))) {
+ else if (!(file = lsx_fopen(filename, text_mode ? "r" : "rb"))) {
lsx_fail("couldn't open file %s: %s", filename, strerror(errno));
return NULL;
}
diff --git a/src/formats.c b/src/formats.c
index 1a8c503..d356800 100644
--- a/src/formats.c
+++ b/src/formats.c
@@ -19,6 +19,7 @@
*/
#include "sox_i.h"
+#include "unicode_support.h"
#include <assert.h>
#include <ctype.h>
@@ -400,7 +401,7 @@ static FILE * xfopen(char const * identifier, char const * mode, lsx_io_type * i
#endif
return f;
}
- return fopen(identifier, mode);
+ return lsx_fopen(identifier, mode);
}
/* Hack to rewind pipes (a small amount).
@@ -852,8 +853,8 @@ static sox_format_t * open_write(
ft->fp = stdout;
}
else {
- struct stat st;
- if (!stat(path, &st) && (st.st_mode & S_IFMT) == S_IFREG &&
+ struct _stat st;
+ if (!lsx_stat(path, &st) && (st.st_mode & S_IFMT) == S_IFREG &&
(overwrite_permitted && !overwrite_permitted(path))) {
lsx_fail("permission to overwrite `%s' denied", path);
goto error;
@@ -863,7 +864,7 @@ static sox_format_t * open_write(
buffer? fmemopen(buffer, buffer_size, "w+b") :
buffer_ptr? open_memstream(buffer_ptr, buffer_size_ptr) :
#endif
- fopen(path, "w+b");
+ lsx_fopen(path, "w+b");
if (ft->fp == NULL) {
lsx_fail("can't open output file `%s': %s", path, strerror(errno));
goto error;
diff --git a/src/libsox_i.c b/src/libsox_i.c
index a5afb8e..f834136 100644
--- a/src/libsox_i.c
+++ b/src/libsox_i.c
@@ -20,6 +20,7 @@
#include "sox_i.h"
+#include "unicode_support.h"
#ifdef HAVE_IO_H
#include <io.h>
@@ -48,8 +49,8 @@
#ifdef WIN32
static int check_dir(char * buf, size_t buflen, char const * name)
{
- struct stat st;
- if (!name || stat(name, &st) || (st.st_mode & S_IFMT) != S_IFDIR)
+ struct _stat st;
+ if (!name || lsx_stat(name, &st) || (st.st_mode & S_IFMT) != S_IFDIR)
{
return 0;
}
@@ -102,7 +103,7 @@ FILE * lsx_tmpfile(void)
fildes = mkstemp(name);
#ifdef HAVE_UNISTD_H
lsx_debug(FAKE_MKSTEMP "mkstemp, name=%s (unlinked)", name);
- unlink(name);
+ lsx_unlink(name);
#else
lsx_debug(FAKE_MKSTEMP "mkstemp, name=%s (O_TEMPORARY)", name);
#endif
diff --git a/src/noiseprof.c b/src/noiseprof.c
index 8fe6d4f..fd798ca 100644
--- a/src/noiseprof.c
+++ b/src/noiseprof.c
@@ -19,6 +19,7 @@
*/
#include "noisered.h"
+#include "unicode_support.h"
#include <assert.h>
#include <string.h>
@@ -75,7 +76,7 @@ static int sox_noiseprof_start(sox_effect_t * effp)
effp->global_info->global_info->stdout_in_use_by = effp->handler.name;
data->output_file = stdout;
}
- else if ((data->output_file = fopen(data->output_filename, "wb")) == NULL) {
+ else if ((data->output_file = lsx_fopen(data->output_filename, "wb")) == NULL) {
lsx_fail("Couldn't open profile file %s: %s", data->output_filename, strerror(errno));
return SOX_EOF;
}
diff --git a/src/sox.c b/src/sox.c
index fcdac94..89685e0 100644
--- a/src/sox.c
+++ b/src/sox.c
@@ -24,6 +24,7 @@
#include "soxconfig.h"
#include "sox.h"
#include "util.h"
+#include "unicode_support.h"
#include <ctype.h>
#include <errno.h>
@@ -238,10 +239,10 @@ static void cleanup(void)
if (file_count) {
if (ofile->ft) {
if (!success && ofile->ft->io_type == lsx_io_file) { /* If we failed part way through */
- struct stat st; /* writing a normal file, remove it. */
- if (!stat(ofile->ft->filename, &st) &&
+ struct _stat st; /* writing a normal file, remove it. */
+ if (!lsx_stat(ofile->ft->filename, &st) &&
(st.st_mode & S_IFMT) == S_IFREG)
- unlink(ofile->ft->filename);
+ lsx_unlink(ofile->ft->filename);
}
sox_close(ofile->ft); /* Assume we can unlink a file before closing it. */
}
@@ -905,7 +906,7 @@ static char * * strtoargv(char * s, int * argc)
static void read_user_effects(char const *filename)
{
- FILE *file = fopen(filename, "r");
+ FILE *file = lsx_fopen(filename, "r");
const size_t buffer_size_step = 1024;
size_t buffer_size = buffer_size_step;
char *s = lsx_malloc(buffer_size); /* buffer for one input line */
@@ -2136,7 +2137,7 @@ static void read_comment_file(sox_comments_t * comments, char const * const file
int c;
size_t text_length = 100;
char * text = lsx_malloc(text_length + 1);
- FILE * file = fopen(filename, "r");
+ FILE * file = lsx_fopen(filename, "r");
if (file == NULL) {
lsx_fail("Cannot open comment file `%s'", filename);
@@ -2848,7 +2849,7 @@ static sox_bool cmp_comment_text(char const * c1, char const * c2)
return c1 && c2 && !strcasecmp(c1, c2);
}
-int main(int argc, char **argv)
+int sox_main(int argc, char **argv)
{
size_t i;
char mybase[6];
@@ -3051,3 +3052,20 @@ int main(int argc, char **argv)
return 0;
}
+
+int main(int argc, char **argv)
+{
+ int sox_argc;
+ char **sox_argv;
+ int exit_code;
+
+ lsx_init_console();
+ lsx_init_commandline_arguments(&sox_argc, &sox_argv);
+
+ exit_code = sox_main(sox_argc, sox_argv);
+
+ lsx_uninit_console();
+ lsx_free_commandline_arguments(&sox_argc, &sox_argv);
+
+ return exit_code;
+}
diff --git a/src/unicode_support.c b/src/unicode_support.c
new file mode 100644
index 0000000..7519a8a
--- /dev/null
+++ b/src/unicode_support.c
@@ -0,0 +1,199 @@
+/* Copyright (c) 2004-2012 LoRd_MuldeR <mulder2@gmx.de>
+ File: unicode_support.c
+
+ This file was originally part of a patch included with LameXP,
+ released under the same license as the original audio tools.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+#if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64
+
+#include "unicode_support.h"
+
+#include <windows.h>
+#include <io.h>
+
+static UINT g_old_output_cp = ((UINT)-1);
+
+static char *utf16_to_utf8(const wchar_t *input)
+{
+ char *Buffer;
+ int BuffSize = 0, Result = 0;
+
+ BuffSize = WideCharToMultiByte(CP_UTF8, 0, input, -1, NULL, 0, NULL, NULL);
+ Buffer = (char*) malloc(sizeof(char) * BuffSize);
+ if(Buffer)
+ {
+ Result = WideCharToMultiByte(CP_UTF8, 0, input, -1, Buffer, BuffSize, NULL, NULL);
+ }
+
+ return ((Result > 0) && (Result <= BuffSize)) ? Buffer : NULL;
+}
+
+static char *utf16_to_ansi(const wchar_t *input)
+{
+ char *Buffer;
+ int BuffSize = 0, Result = 0;
+
+ BuffSize = WideCharToMultiByte(CP_ACP, 0, input, -1, NULL, 0, NULL, NULL);
+ Buffer = (char*) malloc(sizeof(char) * BuffSize);
+ if(Buffer)
+ {
+ Result = WideCharToMultiByte(CP_ACP, 0, input, -1, Buffer, BuffSize, NULL, NULL);
+ }
+
+ return ((Result > 0) && (Result <= BuffSize)) ? Buffer : NULL;
+}
+
+static wchar_t *utf8_to_utf16(const char *input)
+{
+ wchar_t *Buffer;
+ int BuffSize = 0, Result = 0;
+
+ BuffSize = MultiByteToWideChar(CP_UTF8, 0, input, -1, NULL, 0);
+ Buffer = (wchar_t*) malloc(sizeof(wchar_t) * BuffSize);
+ if(Buffer)
+ {
+ Result = MultiByteToWideChar(CP_UTF8, 0, input, -1, Buffer, BuffSize);
+ }
+
+ return ((Result > 0) && (Result <= BuffSize)) ? Buffer : NULL;
+}
+
+void lsx_init_commandline_arguments(int *argc, char ***argv)
+{
+ int i, nArgs;
+ LPWSTR *szArglist;
+
+ szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
+
+ if(NULL == szArglist)
+ {
+ fprintf(stderr, "\nFATAL: CommandLineToArgvW failed\n\n");
+ exit(-1);
+ }
+
+ *argv = (char**) malloc(sizeof(char*) * nArgs);
+ *argc = nArgs;
+
+ if(NULL == *argv)
+ {
+ fprintf(stderr, "\nFATAL: Malloc failed\n\n");
+ exit(-1);
+ }
+
+ for(i = 0; i < nArgs; i++)
+ {
+ (*argv)[i] = utf16_to_utf8(szArglist[i]);
+ if(NULL == (*argv)[i])
+ {
+ fprintf(stderr, "\nFATAL: utf16_to_utf8 failed\n\n");
+ exit(-1);
+ }
+ }
+
+ LocalFree(szArglist);
+}
+
+void lsx_free_commandline_arguments(int *argc, char ***argv)
+{
+ int i = 0;
+
+ if(*argv != NULL)
+ {
+ for(i = 0; i < *argc; i++)
+ {
+ if((*argv)[i] != NULL)
+ {
+ free((*argv)[i]);
+ (*argv)[i] = NULL;
+ }
+ }
+ free(*argv);
+ *argv = NULL;
+ }
+}
+
+FILE *lsx_fopen(const char *filename_utf8, const char *mode_utf8)
+{
+ FILE *ret = NULL;
+ wchar_t *filename_utf16 = utf8_to_utf16(filename_utf8);
+ wchar_t *mode_utf16 = utf8_to_utf16(mode_utf8);
+
+ if(filename_utf16 && mode_utf16)
+ {
+ FILE *fh = NULL;
+ int err = _wfopen_s(&fh, filename_utf16, mode_utf16);
+ if(err == 0) ret = fh;
+ }
+
+ if(filename_utf16) free(filename_utf16);
+ if(mode_utf16) free(mode_utf16);
+
+ return ret;
+}
+
+int lsx_stat(const char *path_utf8, struct _stat *buf)
+{
+ int ret = -1;
+
+ wchar_t *path_utf16 = utf8_to_utf16(path_utf8);
+ if(path_utf16)
+ {
+ ret = _wstat(path_utf16, buf);
+ free(path_utf16);
+ }
+
+ return ret;
+}
+
+int lsx_unlink(const char *path_utf8)
+{
+ int ret = -1;
+
+ wchar_t *path_utf16 = utf8_to_utf16(path_utf8);
+ if(path_utf16)
+ {
+ ret = _wunlink(path_utf16);
+ free(path_utf16);
+ }
+
+ return ret;
+}
+
+void lsx_init_console(void)
+{
+ g_old_output_cp = GetConsoleOutputCP();
+ SetConsoleOutputCP(CP_UTF8);
+}
+
+void lsx_uninit_console(void)
+{
+ if(g_old_output_cp != ((UINT)-1))
+ {
+ SetConsoleOutputCP(g_old_output_cp);
+ }
+}
+
+#endif
\ No newline at end of file
diff --git a/src/unicode_support.h b/src/unicode_support.h
new file mode 100644
index 0000000..36dc0c5
--- /dev/null
+++ b/src/unicode_support.h
@@ -0,0 +1,50 @@
+/* Copyright (c) 2004-2012 LoRd_MuldeR <mulder2@gmx.de>
+ File: unicode_support.h
+
+ This file was originally part of a patch included with LameXP,
+ released under the same license as the original audio tools.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+#ifndef UNICODE_SUPPORT_H_INCLUDED
+#define UNICODE_SUPPORT_H_INCLUDED
+
+#include <stdio.h>
+#include <sys/stat.h>
+
+#define WIN_UNICODE 1
+
+//char *utf16_to_utf8(const wchar_t *input);
+//char *utf16_to_ansi(const wchar_t *input);
+//wchar_t *utf8_to_utf16(const char *input);
+
+void lsx_init_commandline_arguments(int *argc, char ***argv);
+void lsx_free_commandline_arguments(int *argc, char ***argv);
+FILE *lsx_fopen(const char *filename_utf8, const char *mode_utf8);
+int lsx_stat(const char *path_utf8, struct _stat *buf);
+int lsx_unlink(const char *path_utf8);
+void lsx_init_console(void);
+void lsx_uninit_console(void);
+
+#endif
\ No newline at end of file

Binary file not shown.

View File

@ -34,8 +34,8 @@
#define VER_LAMEXP_MINOR_HI 1
#define VER_LAMEXP_MINOR_LO 1
#define VER_LAMEXP_TYPE Alpha
#define VER_LAMEXP_PATCH 3
#define VER_LAMEXP_BUILD 1574
#define VER_LAMEXP_PATCH 4
#define VER_LAMEXP_BUILD 1575
#define VER_LAMEXP_CONFG 1558
///////////////////////////////////////////////////////////////////////////////

View File

@ -80,7 +80,7 @@ g_lamexp_tools[] =
{"704ff390fb14960a766b79aa35a7527a8417bc5e649f5330bb3cd2ad61d227fe26b5dd9190aac5f6789540a23da50f01", CPU_TYPE_ALL_SSE, "opusenc.sse2.exe", 20141005, "v1.1"},
{"bdfa8dec142b6327a33af6bb314d7beb924588d1b73f2ef3f46b31fa6046fe2f4e64ca78b025b7eb9290a78320e2aa57", CPU_TYPE_ALL_ALL, "refalac.exe", 56, ""},
{"d041b60de6c5c6e77cbad84440db57bbeb021af59dd0f7bebd3ede047d9e2ddc2a0c14179472687ba91063743d23e337", CPU_TYPE_ALL_ALL, "shorten.exe", 361, ""},
{"cf988bfbb53e77a1dcaefbd5c08789abb4d67cc210723f1f8ba7850f17d34ebb7d0c426b67b963e7d2290a2744865244", CPU_TYPE_ALL_ALL, "sox.exe", 1441, ""},
{"2e305f1a1c630ec9670de2f884a570d1424d08ffabcb4b6211371b76adbb2af66c308520e1a9674b1d20aecb3df32724", CPU_TYPE_ALL_ALL, "sox.exe", 1442, ""},
{"5a4261e1b41a59d1a5bc92e1d2766422a67454d77e06ea29af392811b7b4704e0f3e494ab9cb6375ce9e39257867c5ed", CPU_TYPE_ALL_ALL, "speexdec.exe", 12, ""},
{"75d4c18dbb74e2dbf7342698428248d45cc4070d5f95da8831ef755e63dcd7ff9c3a760f289e8ef8b5c06b82548edbd8", CPU_TYPE_ALL_ALL, "tag.exe", 100, ""},
{"a83628880da0b7519ec368a74a92da5a5099d8d46aa0583131f92d7321f47c9e16a1841b2a3fb8ffcca7205ef4b1bb0a", CPU_TYPE_ALL_ALL, "tta.exe", 21, ""},