1
0
mirror of https://github.com/RPCS3/soundtouch.git synced 2024-11-08 20:12:27 +01:00

Added a compile-time switch to disable throwing c++ exceptions

This commit is contained in:
oparviai 2011-09-02 18:56:11 +00:00
parent a88461c737
commit ad164d96db
9 changed files with 40 additions and 41 deletions

View File

@ -143,8 +143,20 @@ namespace soundtouch
#endif #endif
#endif // SOUNDTOUCH_INTEGER_SAMPLES #endif // SOUNDTOUCH_INTEGER_SAMPLES
}; };
// define ST_NO_EXCEPTION_HANDLING switch to disable throwing std exceptions:
// #define ST_NO_EXCEPTION_HANDLING 1
#ifdef ST_NO_EXCEPTION_HANDLING
// Exceptions disabled. Throw asserts instead if enabled.
#include <assert.h>
#define ST_THROW_RT_ERROR(x) {assert((const char *)x);}
#else
// use c++ standard exceptions
#include <stdexcept>
#define ST_THROW_RT_ERROR(x) {throw std::runtime_error(x);}
#endif
// When this #define is active, eliminates a clicking sound when the "rate" or "pitch" // When this #define is active, eliminates a clicking sound when the "rate" or "pitch"
// parameter setting crosses from value <1 to >=1 or vice versa during processing. // parameter setting crosses from value <1 to >=1 or vice versa during processing.

View File

@ -36,7 +36,6 @@
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include <stdexcept>
#include <string> #include <string>
#include <stdlib.h> #include <stdlib.h>
@ -120,7 +119,7 @@ RunParameters::RunParameters(const int nParams, const char * const paramStr[])
} }
string msg = whatText; string msg = whatText;
msg += usage; msg += usage;
throw runtime_error(msg.c_str()); ST_THROW_RT_ERROR(msg.c_str());
} }
inFileName = NULL; inFileName = NULL;
@ -200,14 +199,14 @@ void RunParameters::throwIllegalParamExp(const string &str) const
msg += str; msg += str;
msg += "\".\n\n"; msg += "\".\n\n";
msg += usage; msg += usage;
throw runtime_error(msg.c_str()); ST_THROW_RT_ERROR(msg.c_str());
} }
void RunParameters::throwLicense() const void RunParameters::throwLicense() const
{ {
throw runtime_error(licenseText); ST_THROW_RT_ERROR(licenseText);
} }

View File

@ -46,7 +46,6 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include <stdio.h> #include <stdio.h>
#include <stdexcept>
#include <string> #include <string>
#include <sstream> #include <sstream>
#include <cstring> #include <cstring>
@ -54,6 +53,7 @@
#include <limits.h> #include <limits.h>
#include "WavFile.h" #include "WavFile.h"
#include "STTypes.h"
using namespace std; using namespace std;
@ -149,7 +149,7 @@ WavInFile::WavInFile(const char *fileName)
string msg = "Error : Unable to open file \""; string msg = "Error : Unable to open file \"";
msg += fileName; msg += fileName;
msg += "\" for reading."; msg += "\" for reading.";
throw runtime_error(msg); ST_THROW_RT_ERROR(msg.c_str());
} }
init(); init();
@ -164,7 +164,7 @@ WavInFile::WavInFile(FILE *file)
{ {
// didn't succeed // didn't succeed
string msg = "Error : Unable to access input stream for reading"; string msg = "Error : Unable to access input stream for reading";
throw runtime_error(msg); ST_THROW_RT_ERROR(msg.c_str());
} }
init(); init();
@ -185,13 +185,13 @@ void WavInFile::init()
{ {
// Something didn't match in the wav file headers // Something didn't match in the wav file headers
string msg = "Input file is corrupt or not a WAV file"; string msg = "Input file is corrupt or not a WAV file";
throw runtime_error(msg); ST_THROW_RT_ERROR(msg.c_str());
} }
if (header.format.fixed != 1) if (header.format.fixed != 1)
{ {
string msg = "Input file uses unsupported encoding."; string msg = "Input file uses unsupported encoding.";
throw runtime_error(msg); ST_THROW_RT_ERROR(msg.c_str());
} }
dataRead = 0; dataRead = 0;
@ -237,7 +237,7 @@ int WavInFile::read(char *buffer, int maxElems)
// ensure it's 8 bit format // ensure it's 8 bit format
if (header.format.bits_per_sample != 8) if (header.format.bits_per_sample != 8)
{ {
throw runtime_error("Error: WavInFile::read(char*, int) works only with 8bit samples."); ST_THROW_RT_ERROR("Error: WavInFile::read(char*, int) works only with 8bit samples.");
} }
assert(sizeof(char) == 1); assert(sizeof(char) == 1);
@ -288,7 +288,7 @@ int WavInFile::read(short *buffer, int maxElems)
ss << "\nOnly 8/16 bit sample WAV files supported. Can't open WAV file with "; ss << "\nOnly 8/16 bit sample WAV files supported. Can't open WAV file with ";
ss << (int)header.format.bits_per_sample; ss << (int)header.format.bits_per_sample;
ss << " bit sample format. "; ss << " bit sample format. ";
throw runtime_error(ss.str()); ST_THROW_RT_ERROR(ss.str().c_str());
} }
assert(sizeof(short) == 2); assert(sizeof(short) == 2);
@ -556,7 +556,7 @@ WavOutFile::WavOutFile(const char *fileName, int sampleRate, int bits, int chann
msg += fileName; msg += fileName;
msg += "\" for writing."; msg += "\" for writing.";
//pmsg = msg.c_str; //pmsg = msg.c_str;
throw runtime_error(msg); ST_THROW_RT_ERROR(msg.c_str());
} }
fillInHeader(sampleRate, bits, channels); fillInHeader(sampleRate, bits, channels);
@ -571,7 +571,7 @@ WavOutFile::WavOutFile(FILE *file, int sampleRate, int bits, int channels)
if (fptr == NULL) if (fptr == NULL)
{ {
string msg = "Error : Unable to access output file stream."; string msg = "Error : Unable to access output file stream.";
throw runtime_error(msg); ST_THROW_RT_ERROR(msg.c_str());
} }
fillInHeader(sampleRate, bits, channels); fillInHeader(sampleRate, bits, channels);
@ -657,7 +657,7 @@ void WavOutFile::writeHeader()
res = (int)fwrite(&hdrTemp, sizeof(hdrTemp), 1, fptr); res = (int)fwrite(&hdrTemp, sizeof(hdrTemp), 1, fptr);
if (res != 1) if (res != 1)
{ {
throw runtime_error("Error while writing to a wav file."); ST_THROW_RT_ERROR("Error while writing to a wav file.");
} }
// jump back to the end of the file // jump back to the end of the file
@ -672,14 +672,14 @@ void WavOutFile::write(const char *buffer, int numElems)
if (header.format.bits_per_sample != 8) if (header.format.bits_per_sample != 8)
{ {
throw runtime_error("Error: WavOutFile::write(const char*, int) accepts only 8bit samples."); ST_THROW_RT_ERROR("Error: WavOutFile::write(const char*, int) accepts only 8bit samples.");
} }
assert(sizeof(char) == 1); assert(sizeof(char) == 1);
res = (int)fwrite(buffer, 1, numElems, fptr); res = (int)fwrite(buffer, 1, numElems, fptr);
if (res != numElems) if (res != numElems)
{ {
throw runtime_error("Error while writing to a wav file."); ST_THROW_RT_ERROR("Error while writing to a wav file.");
} }
bytesWritten += numElems; bytesWritten += numElems;
@ -717,7 +717,7 @@ void WavOutFile::write(const short *buffer, int numElems)
ss << "\nOnly 8/16 bit sample WAV files supported. Can't open WAV file with "; ss << "\nOnly 8/16 bit sample WAV files supported. Can't open WAV file with ";
ss << (int)header.format.bits_per_sample; ss << (int)header.format.bits_per_sample;
ss << " bit sample format. "; ss << " bit sample format. ";
throw runtime_error(ss.str()); ST_THROW_RT_ERROR(ss.str().c_str());
} }
// allocate temp buffer to swap byte order if necessary // allocate temp buffer to swap byte order if necessary
@ -730,7 +730,7 @@ void WavOutFile::write(const short *buffer, int numElems)
if (res != numElems) if (res != numElems)
{ {
throw runtime_error("Error while writing to a wav file."); ST_THROW_RT_ERROR("Error while writing to a wav file.");
} }
bytesWritten += 2 * numElems; bytesWritten += 2 * numElems;
} }

View File

@ -47,7 +47,6 @@
#include <memory.h> #include <memory.h>
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <stdexcept>
#include "FIFOSampleBuffer.h" #include "FIFOSampleBuffer.h"
@ -175,7 +174,7 @@ void FIFOSampleBuffer::ensureCapacity(uint capacityRequirement)
tempUnaligned = new SAMPLETYPE[sizeInBytes / sizeof(SAMPLETYPE) + 16 / sizeof(SAMPLETYPE)]; tempUnaligned = new SAMPLETYPE[sizeInBytes / sizeof(SAMPLETYPE) + 16 / sizeof(SAMPLETYPE)];
if (tempUnaligned == NULL) if (tempUnaligned == NULL)
{ {
throw std::runtime_error("Couldn't allocate memory!\n"); ST_THROW_RT_ERROR("Couldn't allocate memory!\n");
} }
// Align the buffer to begin at 16byte cache line boundary for optimal performance // Align the buffer to begin at 16byte cache line boundary for optimal performance
temp = (SAMPLETYPE *)(((ulong)tempUnaligned + 15) & (ulong)-16); temp = (SAMPLETYPE *)(((ulong)tempUnaligned + 15) & (ulong)-16);

View File

@ -43,7 +43,6 @@
#include <assert.h> #include <assert.h>
#include <math.h> #include <math.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdexcept>
#include "FIRFilter.h" #include "FIRFilter.h"
#include "cpu_detect.h" #include "cpu_detect.h"
@ -174,7 +173,7 @@ uint FIRFilter::evaluateFilterMono(SAMPLETYPE *dest, const SAMPLETYPE *src, uint
void FIRFilter::setCoefficients(const SAMPLETYPE *coeffs, uint newLength, uint uResultDivFactor) void FIRFilter::setCoefficients(const SAMPLETYPE *coeffs, uint newLength, uint uResultDivFactor)
{ {
assert(newLength > 0); assert(newLength > 0);
if (newLength % 8) throw std::runtime_error("FIR filter length not divisible by 8"); if (newLength % 8) ST_THROW_RT_ERROR("FIR filter length not divisible by 8");
lengthDiv8 = newLength / 8; lengthDiv8 = newLength / 8;
length = lengthDiv8 * 8; length = lengthDiv8 * 8;
@ -222,8 +221,8 @@ uint FIRFilter::evaluate(SAMPLETYPE *dest, const SAMPLETYPE *src, uint numSample
void * FIRFilter::operator new(size_t s) void * FIRFilter::operator new(size_t s)
{ {
// Notice! don't use "new FIRFilter" directly, use "newInstance" to create a new instance instead! // Notice! don't use "new FIRFilter" directly, use "newInstance" to create a new instance instead!
throw std::runtime_error("Error in FIRFilter::new: Don't use 'new FIRFilter', use 'newInstance' member instead!"); ST_THROW_RT_ERROR("Error in FIRFilter::new: Don't use 'new FIRFilter', use 'newInstance' member instead!");
return NULL; return newInstance();
} }

View File

@ -42,11 +42,9 @@
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <stdexcept>
#include "RateTransposer.h" #include "RateTransposer.h"
#include "AAFilter.h" #include "AAFilter.h"
using namespace std;
using namespace soundtouch; using namespace soundtouch;
@ -108,8 +106,8 @@ public:
// depending on if we've a MMX/SSE/etc-capable CPU available or not. // depending on if we've a MMX/SSE/etc-capable CPU available or not.
void * RateTransposer::operator new(size_t s) void * RateTransposer::operator new(size_t s)
{ {
throw runtime_error("Error in RateTransoser::new: don't use \"new TDStretch\" directly, use \"newInstance\" to create a new instance instead!"); ST_THROW_RT_ERROR("Error in RateTransoser::new: don't use \"new TDStretch\" directly, use \"newInstance\" to create a new instance instead!");
return NULL; return newInstance();
} }

View File

@ -73,7 +73,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <memory.h> #include <memory.h>
#include <math.h> #include <math.h>
#include <stdexcept>
#include <stdio.h> #include <stdio.h>
#include "SoundTouch.h" #include "SoundTouch.h"
@ -146,7 +145,7 @@ void SoundTouch::setChannels(uint numChannels)
{ {
if (numChannels != 1 && numChannels != 2) if (numChannels != 1 && numChannels != 2)
{ {
throw std::runtime_error("Illegal number of channels"); ST_THROW_RT_ERROR("Illegal number of channels");
} }
channels = numChannels; channels = numChannels;
pRateTransposer->setChannels((int)numChannels); pRateTransposer->setChannels((int)numChannels);
@ -295,11 +294,11 @@ void SoundTouch::putSamples(const SAMPLETYPE *samples, uint nSamples)
{ {
if (bSrateSet == FALSE) if (bSrateSet == FALSE)
{ {
throw std::runtime_error("SoundTouch : Sample rate not defined"); ST_THROW_RT_ERROR("SoundTouch : Sample rate not defined");
} }
else if (channels == 0) else if (channels == 0)
{ {
throw std::runtime_error("SoundTouch : Number of channels not defined"); ST_THROW_RT_ERROR("SoundTouch : Number of channels not defined");
} }
// Transpose the rate of the new samples if necessary // Transpose the rate of the new samples if necessary

View File

@ -46,7 +46,6 @@
#include <assert.h> #include <assert.h>
#include <math.h> #include <math.h>
#include <float.h> #include <float.h>
#include <stdexcept>
#include "STTypes.h" #include "STTypes.h"
#include "cpu_detect.h" #include "cpu_detect.h"
@ -731,8 +730,8 @@ void TDStretch::acceptNewOverlapLength(int newOverlapLength)
void * TDStretch::operator new(size_t s) void * TDStretch::operator new(size_t s)
{ {
// Notice! don't use "new TDStretch" directly, use "newInstance" to create a new instance instead! // Notice! don't use "new TDStretch" directly, use "newInstance" to create a new instance instead!
throw std::runtime_error("Error in TDStretch::new: Don't use 'new TDStretch' directly, use 'newInstance' member instead!"); ST_THROW_RT_ERROR("Error in TDStretch::new: Don't use 'new TDStretch' directly, use 'newInstance' member instead!");
return NULL; return newInstance();
} }

View File

@ -39,15 +39,9 @@
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include <stdexcept>
#include <string>
#include "cpu_detect.h" #include "cpu_detect.h"
#include "STTypes.h" #include "STTypes.h"
using namespace std;
#include <stdio.h>
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// //
// processor instructions extension detection routines // processor instructions extension detection routines