From 53258529017c297898ea0b8b5a55a24934123853 Mon Sep 17 00:00:00 2001 From: nu774 Date: Tue, 17 Jan 2012 19:40:38 +0900 Subject: [PATCH] a bit refinement on error message --- CoreAudioHelper.h | 2 +- flacmodule.cpp | 2 +- flacsrc.cpp | 2 +- libsndfilesrc.cpp | 2 +- main.cpp | 49 +++++++++++++++++++++++++++++------------------ soxdsp.cpp | 12 ++++++------ taksrc.cpp | 5 ++--- version.cpp | 4 ++-- win32util.cpp | 4 ++-- wvpacksrc.cpp | 11 +++++------ 10 files changed, 51 insertions(+), 42 deletions(-) diff --git a/CoreAudioHelper.h b/CoreAudioHelper.h index 707d4b60..3f2dd194 100644 --- a/CoreAudioHelper.h +++ b/CoreAudioHelper.h @@ -15,7 +15,7 @@ long err = expr; \ if (err) { \ std::stringstream ss; \ - ss << "ERROR " << err << ": " << #expr; \ + ss << err << ": " << #expr; \ throw std::runtime_error(ss.str()); \ } \ } while (0) diff --git a/flacmodule.cpp b/flacmodule.cpp index 58cc7b57..dec1b156 100644 --- a/flacmodule.cpp +++ b/flacmodule.cpp @@ -1,6 +1,6 @@ #include "flacmodule.h" -#define CHECK(expr) do { if (!(expr)) throw std::runtime_error("ERROR"); } \ +#define CHECK(expr) do { if (!(expr)) throw std::runtime_error("!!!"); } \ while (0) FLACModule::FLACModule(const std::wstring &path) diff --git a/flacsrc.cpp b/flacsrc.cpp index e94a0525..1f04ddbb 100644 --- a/flacsrc.cpp +++ b/flacsrc.cpp @@ -7,7 +7,7 @@ namespace flac { template void try__(T expr, const char *msg) { - if (!expr) throw std::runtime_error(format("ERROR: %s", msg)); + if (!expr) throw std::runtime_error(msg); } inline void want(bool expr) diff --git a/libsndfilesrc.cpp b/libsndfilesrc.cpp index 4adb0dbb..2ae8879e 100644 --- a/libsndfilesrc.cpp +++ b/libsndfilesrc.cpp @@ -33,7 +33,7 @@ uint32_t convert_chanmap(uint32_t value) } } -#define CHECK(expr) do { if (!(expr)) throw std::runtime_error("ERROR"); } \ +#define CHECK(expr) do { if (!(expr)) throw std::runtime_error("!?"); } \ while (0) LibSndfileModule::LibSndfileModule(const std::wstring &path) diff --git a/main.cpp b/main.cpp index 7e7d3c4b..d0a397dd 100644 --- a/main.cpp +++ b/main.cpp @@ -595,16 +595,21 @@ x::shared_ptr mapped_source(const x::shared_ptr &src, channels = srcx->getChannels(); } // remix - if ((opts.remix_preset || opts.remix_file) && opts.libsoxrate.loaded()) { - std::vector > matrix; - matrix_from_preset(opts, &matrix); - if (opts.verbose > 1 || opts.logfilename) { - LOG("Matrix mixer: %dch -> %dch\n", - matrix[0].size(), matrix.size()); + if (opts.remix_preset || opts.remix_file) { + if (!opts.libsoxrate.loaded()) + LOG("WARNING: mixer requires libsoxrate. Mixing disabled\n"); + else { + std::vector > matrix; + matrix_from_preset(opts, &matrix); + if (opts.verbose > 1 || opts.logfilename) { + LOG("Matrix mixer: %dch -> %dch\n", + matrix[0].size(), matrix.size()); + } + srcx.reset(new MatrixMixer(srcx, opts.libsoxrate, + matrix, threading)); + channels = 0; + nchannels = srcx->getSampleFormat().m_nchannels; } - srcx.reset(new MatrixMixer(srcx, opts.libsoxrate, matrix, threading)); - channels = 0; - nchannels = srcx->getSampleFormat().m_nchannels; } // map with --chanmap option if (opts.chanmap.size()) { @@ -673,6 +678,8 @@ x::shared_ptr delayed_source(const x::shared_ptr &src, IPartialSource *p = dynamic_cast(src.get()); if (p) { int nsamples = lrint(-0.001 * opts.delay * rate); + if (src->length() >= 0 && nsamples > src->length()) + nsamples = src->length(); p->setRange(nsamples, -1); if (opts.verbose > 1 || opts.logfilename) LOG("Delay of %dms: trunc %d samples\n", opts.delay, @@ -768,15 +775,19 @@ preprocess_input(const x::shared_ptr &src, srcx.reset(new SoxDSPProcessor(engine, srcx)); } } - if (opts.lowpass > 0 && opts.libsoxrate.loaded()) { - if (opts.verbose > 1 || opts.logfilename) - LOG("Applying LPF: %dHz\n", opts.lowpass); - x::shared_ptr - engine(new SoxLowpassFilter(opts.libsoxrate, - srcx->getSampleFormat(), - opts.lowpass, - threading)); - srcx.reset(new SoxDSPProcessor(engine, srcx)); + if (opts.lowpass > 0) { + if (!opts.libsoxrate.loaded()) + LOG("WARNING: --lowpass requires libsoxrate. LPF disabled\n"); + else { + if (opts.verbose > 1 || opts.logfilename) + LOG("Applying LPF: %dHz\n", opts.lowpass); + x::shared_ptr + engine(new SoxLowpassFilter(opts.libsoxrate, + srcx->getSampleFormat(), + opts.lowpass, + threading)); + srcx.reset(new SoxDSPProcessor(engine, srcx)); + } } if (opts.normalize) srcx = do_normalize(srcx, opts); @@ -1413,7 +1424,7 @@ int wmain1(int argc, wchar_t **argv) } catch (const std::exception &e) { if (opts.print_available_formats) Log::instance()->enable_stderr(); - LOG("%s\n", e.what()); + LOG("ERROR: %s\n", e.what()); result = 2; } delete Log::instance(); diff --git a/soxdsp.cpp b/soxdsp.cpp index d186acf0..d9e0c416 100644 --- a/soxdsp.cpp +++ b/soxdsp.cpp @@ -3,7 +3,7 @@ #include #include "soxdsp.h" -#define CHECK(expr) do { if (!(expr)) throw std::runtime_error("ERROR"); } \ +#define CHECK(expr) do { if (!(expr)) throw std::runtime_error("!?"); } \ while (0) SoxModule::SoxModule(const std::wstring &path) @@ -92,11 +92,11 @@ SoxResampler::SoxResampler(const SoxModule &module, const SampleFormat &format, lsx_rate_t *converter = m_module.rate_create( format.m_nchannels, format.m_rate, rate); if (!converter) - throw std::runtime_error("ERROR: SoxResampler"); + throw std::runtime_error("lsx_rate_create()"); m_processor = x::shared_ptr(converter, m_module.rate_close); m_module.rate_config(converter, SOX_RATE_USE_THREADS, static_cast(mt)); if (m_module.rate_start(converter) < 0) - throw std::runtime_error("ERROR: SoxResampler"); + throw std::runtime_error("lsx_rate_config()"); } SoxLowpassFilter::SoxLowpassFilter(const SoxModule &module, @@ -111,14 +111,14 @@ SoxLowpassFilter::SoxLowpassFilter(const SoxModule &module, int num_taps = 0; double *coefs = m_module.design_lpf(Fp, Fc, Fn, 0, 120.0, &num_taps, 0); if (!coefs) - throw std::runtime_error("SoxLowpassFilter: failed to design lpf"); + throw std::runtime_error("lsx_design_lpf()"); x::shared_ptr __delete_lator__(coefs, m_module.free); lsx_fir_t *converter = m_module.fir_create(format.m_nchannels, coefs, num_taps, num_taps >> 1, mt); if (!converter) - throw std::runtime_error("ERROR: SoxLowpassFilter"); + throw std::runtime_error("lsx_fir_create()"); m_processor = x::shared_ptr(converter, m_module.fir_close); if (m_module.fir_start(converter) < 0) - throw std::runtime_error("ERROR: SoxLowpassFilter"); + throw std::runtime_error("lsx_fir_start()"); } diff --git a/taksrc.cpp b/taksrc.cpp index bb92b17f..4d6e7a16 100644 --- a/taksrc.cpp +++ b/taksrc.cpp @@ -5,7 +5,7 @@ #include "itunetags.h" #include "cuesheet.h" -#define CHECK(expr) do { if (!(expr)) throw std::runtime_error("ERROR"); } \ +#define CHECK(expr) do { if (!(expr)) throw std::runtime_error("!?"); } \ while (0) TakModule::TakModule(const std::wstring &path) @@ -36,8 +36,7 @@ TakModule::TakModule(const std::wstring &path) namespace tak { template void try__(T expr, const char *s) { - if (expr != tak_res_Ok) - throw std::runtime_error(format("ERROR: %s", s)); + if (expr != tak_res_Ok) throw std::runtime_error(s); } } diff --git a/version.cpp b/version.cpp index c52fcf50..27e208e0 100644 --- a/version.cpp +++ b/version.cpp @@ -1,8 +1,8 @@ const char *get_qaac_version() { #ifdef REFALAC - return "0.33"; + return "0.34"; #else - return "1.22"; + return "1.23"; #endif } diff --git a/win32util.cpp b/win32util.cpp index 25c4b94c..3523d2d0 100644 --- a/win32util.cpp +++ b/win32util.cpp @@ -21,9 +21,9 @@ void throw_win32_error(const std::string &msg, DWORD code) LocalFree(pszMsg); } else if (code < 0xfe00) - ss = format("ERROR %d: %s", code, msg.c_str()); + ss = format("%d: %s", code, msg.c_str()); else - ss = format("ERROR %08x: %s", code, msg.c_str()); + ss = format("%08x: %s", code, msg.c_str()); throw std::runtime_error(ss); } diff --git a/wvpacksrc.cpp b/wvpacksrc.cpp index 824f8e08..f96e8168 100644 --- a/wvpacksrc.cpp +++ b/wvpacksrc.cpp @@ -6,7 +6,7 @@ #include "cuesheet.h" #include "chanmap.h" -#define CHECK(expr) do { if (!(expr)) throw std::runtime_error("ERROR"); } \ +#define CHECK(expr) do { if (!(expr)) throw std::runtime_error("!?"); } \ while (0) WavpackModule::WavpackModule(const std::wstring &path) @@ -101,7 +101,7 @@ WavpackSource::WavpackSource(const WavpackModule &module, InputStream &stream, m_module.OpenFileInputEx(&reader, &m_stream, m_cstream.get(), error, flags, 0); if (!wpc) - throw std::runtime_error(format("WavpackOpenFileInputEx: %s", error)); + throw std::runtime_error(format("WavpackOpenFileInputEx(): %s", error)); m_wpc = x::shared_ptr(wpc, m_module.CloseFile); int mode = m_module.GetMode(wpc); @@ -126,10 +126,9 @@ WavpackSource::WavpackSource(const WavpackModule &module, InputStream &stream, void WavpackSource::skipSamples(int64_t count) { - if (!m_module.SeekSample(m_wpc.get(), - static_cast(PartialSource::getSamplesRead() + count))) - throw std::runtime_error("WavpackSeekSample"); - + uint64_t cur = PartialSource::getSamplesRead(); + if (!m_module.SeekSample(m_wpc.get(), static_cast(cur + count))) + throw std::runtime_error("WavpackSeekSample()"); } template