21 #if defined(_MSC_VER) || defined(__CYGWIN__)    22 #error On microsoft, please rename this file to SoxWindows.H and delete this line.    26 #pragma GCC diagnostic push    27 #pragma GCC diagnostic ignored "-Wignored-attributes"    28 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"    29 #include <Eigen/Dense>    30 #pragma GCC diagnostic pop    32 #define SOX_READ_FILE_OPEN_ERROR SOX_ERROR_OFFSET-1     33 #define SOX_CLOSE_FILE_ERROR SOX_ERROR_OFFSET-2     34 #define SOX_READ_FILE_NOT_OPENED_ERROR SOX_ERROR_OFFSET-3     35 #define SOX_EOF_OR_ERROR SOX_ERROR_OFFSET-4     36 #define SOX_READ_MAXSCALE_ERROR SOX_ERROR_OFFSET-6     37 #define SOX_WRITE_FILE_OPEN_ERROR SOX_ERROR_OFFSET-7     38 #define SOX_WRITE_FILE_NOT_OPENED_ERROR SOX_ERROR_OFFSET-8     39 #define SOX_WRITE_OUT_CHANNEL_MISMATCH SOX_ERROR_OFFSET-9     40 #define SOX_WRITE_SAMPLES_WRITTEN_MISMATCH_ERROR SOX_ERROR_OFFSET-10     41 #define SOX_ROW_BOUNDS_ERROR SOX_ERROR_OFFSET-11     42 #define SOX_COL_BOUNDS_ERROR SOX_ERROR_OFFSET-12     63                         errors[
SOX_EOF_OR_ERROR]=string(
"SOX: Either an error or the EOF was hit whilst operating on the file");
    64                         errors[
SOX_READ_MAXSCALE_ERROR]=string(
"SOX: couldn't open the max file to find the value to rescale the maximum to, if you continue the audio file will not be re-scaled correctly");
    67                         errors[
SOX_WRITE_OUT_CHANNEL_MISMATCH]=string(
"SOX: you provided data to write out which doesn't match the number of channels specified during openWrite for the output file");
    94 template<
typename FP_TYPE_>
   107     int close(
bool inputFile);
   109     static void output_message(
unsigned level, 
const char *filename, 
const char *fmt, va_list ap);
   120     int openRead(
string fileName);
   126     int openRead(intptr_t buffer, 
size_t len);
   134     template <
typename Derived>
   135     int read(Eigen::DenseBase<Derived> &audioData, 
int count=0){
   136         typedef typename Derived::Scalar Scalar;
   140                 count = in->signal.length/in->signal.channels;
   141             Eigen::Array<sox_sample_t, Eigen::Dynamic, Eigen::Dynamic> readData(count*in->signal.channels,1); 
   142             size_t readCount=sox_read(in, readData.data(), count*in->signal.channels); 
   143             if (readCount==SOX_EOF) { 
   145                 audioData.resize(0,0);
   148                 if (audioData.cols()!= in->signal.channels | audioData.rows()!=readCount/in->signal.channels)
   149                      audioData.derived().resize(readCount/in->signal.channels, in->signal.channels);
   150                 if (!(maxVal != maxVal)) 
   151                   for (
int i=0; i<readCount; i++)
   152                       audioData(i/in->signal.channels,i%in->signal.channels)=(Scalar)(maxVal*(
double)readData(i)/(double)numeric_limits<sox_sample_t>::max());
   154                   double scaleFact=(double)pow(2.,(
double)
sizeof(Scalar)*8.-1.);
   155                   for (
int i=0; i<readCount; i++)
   156                       audioData(i/in->signal.channels,i%in->signal.channels)=(Scalar)(scaleFact*(
double)readData(i)/(double)numeric_limits<sox_sample_t>::max());
   174     virtual int openWrite(
const string &fileName, 
double fs, 
int channels, 
double maxVal){
   175         return openWrite(fileName, fs, channels, maxVal, 
sizeof(FP_TYPE_)*CHAR_BIT, 
false, sox_option_default, sox_option_default, sox_option_default);
   192     virtual int openWrite(
const string &fileName, 
double fs, 
int channels, 
double maxVal, 
unsigned int wordSize, 
bool switchEndian, 
int revBytes, 
int revNibbles, 
int revBits);
   202     int openMemWrite(
void *buffer, 
size_t len, 
double fs, 
int channels, 
double maxVal){
   203         return openMemWrite(buffer, len, fs, channels, maxVal, 
sizeof(FP_TYPE_)*CHAR_BIT, 
false, sox_option_default, sox_option_default, sox_option_default);
   221     virtual int openMemWrite(
void *buffer, 
size_t len, 
double fs, 
int channels, 
double maxVal, 
unsigned int wordSize, 
bool switchEndian, 
int revBytes, 
int revNibbles, 
int revBits);
   228     virtual int write(
const vector<vector<FP_TYPE_> > &audioData);
   235     template <
typename Derived>
   236     int write(
const Eigen::DenseBase<Derived> &audioData) {
   239             if (out->signal.channels!=audioData.cols())
   242                 int ch=out->signal.channels;
   243                 int len=audioData.rows();
   245                 if (outputBuffer.size()<total)
   246                     outputBuffer.resize(total);
   247                 for (
int i=0; i<audioData.cols(); i++) 
   248                     for (
int j=0; j<len; j++)
   249                         outputBuffer[j*ch+i]=(sox_sample_t)((double)audioData(j,i)*((double)numeric_limits<sox_sample_t>::max()/outputMaxVal));
   250                 size_t writeCount=sox_write(out, &outputBuffer[0], total);
   263     template <
typename Derived>
   267             if (out->signal.channels!=audioData.rows())
   270                 int ch=out->signal.channels;
   271                 int len=audioData.cols();
   273                 if (outputBuffer.size()<total)
   274                     outputBuffer.resize(total);
   275                 for (
int i=0; i<audioData.rows(); i++) 
   276                     for (
int j=0; j<len; j++)
   277                         outputBuffer[j*ch+i]=(sox_sample_t)((double)audioData(i,j)/outputMaxVal*(double)numeric_limits<sox_sample_t>::max());
   278                 size_t writeCount=sox_write(out, &outputBuffer[0], total);
   294     int closeWrite(
void);
   317             return in->signal.rate;
   326             return out->signal.rate;
   335             return in->signal.channels;
   344             return out->signal.channels;
   351     vector<string> availableFormats(
void);
   357 #ifdef HAVE_EMSCRIPTEN   364   FP_TYPE_ getSample(
unsigned int r, 
unsigned int c);
   369   unsigned int getRows();
   374   unsigned int getCols();
   380   int readJS(
unsigned int count=0);
   383   Eigen::Matrix<FP_TYPE_, Eigen::Dynamic, Eigen::Dynamic> audio; 
   384 #endif // HAVE_EMSCRIPTEN #define SOX_READ_MAXSCALE_ERROR
Sox couldn't open the filename.max to read the rescale value for the audio file. 
virtual int openWrite(const string &fileName, double fs, int channels, double maxVal)
#define SOX_WRITE_SAMPLES_WRITTEN_MISMATCH_ERROR
Error when trying to write data and the incorrect amount of data is written. 
sox_format_t * out
output file 
sox_format_t * in
input file 
double maxVal
maxVal stored in the file fileName.max 
#define SOX_COL_BOUNDS_ERROR
Error when trying to access a col out of bounds (Emscripten case) 
int openMemWrite(void *buffer, size_t len, double fs, int channels, double maxVal)
#define SOX_ROW_BOUNDS_ERROR
Error when trying to access a row out of bounds (Emscripten case) 
#define SOX_WRITE_FILE_OPEN_ERROR
Error when libsox couldn't open the output file. 
#define NO_ERROR
There is no error. 
#define SOX_READ_FILE_OPEN_ERROR
Error when libsox couldn't open the input file. 
#define SOX_WRITE_FILE_NOT_OPENED_ERROR
Error when the output file hasn't already been opened using Sox::openRead. 
int writeTransposed(const Eigen::DenseBase< Derived > &audioData)
void setMaxVal(double newMax)
double outputMaxVal
The maximum value passed to write. 
vector< sox_sample_t > outputBuffer
The output buffer for interleaving output data before writing. 
#define SOX_CLOSE_FILE_ERROR
Error when libsox couldn't close the file. 
int write(const Eigen::DenseBase< Derived > &audioData)
#define SOX_WRITE_OUT_CHANNEL_MISMATCH
Error when trying to write data and the channel count doesn't match. 
#define SOX_EOF_OR_ERROR
Sox returned from a read or write either at the end of the file or in error. 
#define SOX_READ_FILE_NOT_OPENED_ERROR
Error when the input file hasn't already been opened using Sox::openRead. 
int read(Eigen::DenseBase< Derived > &audioData, int count=0)
virtual ~SoxDebug()
Destructor.