gtkIOStream
1.7.0
GTK+ << C++ IOStream operators for GTK+. Now with ORBing, numerical computation, audio client and more ...
|
#include <Sox.H>
Public Member Functions | |
Sox () | |
Constructor. More... | |
virtual | ~Sox () |
Destructor. More... | |
int | openRead (string fileName) |
int | openRead (intptr_t buffer, size_t len) |
template<typename Derived > | |
int | read (Eigen::DenseBase< Derived > &audioData, int count=0) |
virtual int | openWrite (const string &fileName, double fs, int channels, double maxVal) |
virtual int | openWrite (const string &fileName, double fs, int channels, double maxVal, unsigned int wordSize, bool switchEndian, int revBytes, int revNibbles, int revBits) |
int | openMemWrite (void *buffer, size_t len, double fs, int channels, double maxVal) |
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) |
virtual int | write (const vector< vector< FP_TYPE_ > > &audioData) |
template<typename Derived > | |
int | write (const Eigen::DenseBase< Derived > &audioData) |
template<typename Derived > | |
int | writeTransposed (const Eigen::DenseBase< Derived > &audioData) |
int | closeRead (void) |
int | closeWrite (void) |
void | setMaxVal (double newMax) |
double | getMaxVal (void) |
double | getFSIn (void) |
double | getFSOut (void) |
int | getChCntIn (void) |
int | getChCntOut (void) |
vector< string > | availableFormats (void) |
void | printFormats () |
Private Member Functions | |
int | close (bool inputFile) |
Static Private Member Functions | |
static void | output_message (unsigned level, const char *filename, const char *fmt, va_list ap) |
Private Attributes | |
sox_format_t * | in |
input file More... | |
double | maxVal |
maxVal stored in the file fileName.max More... | |
sox_format_t * | out |
output file More... | |
double | outputMaxVal |
The maximum value passed to write. More... | |
vector< sox_sample_t > | outputBuffer |
The output buffer for interleaving output data before writing. More... | |
This class handles audio files using the libsox C library. libsox has advantages in that is can read and write to many many different uncompressed, compressed, lossy and non-lossy audio file formats.
The input reading uses the Eigen matrix library as the input matrix to load into.
The output writing uses a generic C++ vector<vector > > type of matrix to write out from.
In general the Eigen matrices have each channel on a column. So for example a 3 channel 1024 long audio file is returned as a matrix which is 1024x3. This class assumes that all counts are specified in per channel, for example, Sox::read(matrix, count) will read count samples for each channel. libsox on the other hand assumes all counts specify the number of samples*channels.
NOTE: In order to be able to scale correctly, all audio files should have an associated max value file, for example test.f32 and test.f32.max. The .max file will specify to what value to rescale the magnitude to get the correct time domain sclaing.
When writing to file, the max file will be auto generated. This class interleaves output data into the private outputBuffer member variable when the Sox::write method is called. If the write method is called with a total number of samples (channels*length) <= the current size of the outputBuffer, then it is not resized. If the total number of samples of the outputBuffer (channels*length) > the current size of the outputBuffer, then it is resized. For this reason, a good approach to writing output data is to use constant output total sample counts OR output total sample counts which don't continuously increase between calls.
vector< string > Sox< FP_TYPE_ >::availableFormats | ( | void | ) |
|
private |
int Sox< FP_TYPE_ >::closeRead | ( | void | ) |
int Sox< FP_TYPE_ >::closeWrite | ( | void | ) |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Open a memory pointer for reading
fs | The same rate in Hz. |
buffer | The pointer to the memory block |
len | The length of the memory block in bytes |
channels | The number of channels the file should carry. |
maxVal | The maximum value to be contained in the output vector when passed to Sox::write |
|
virtual |
Open a memory pointer for writing. Specifying the precision. If the output file is already open, then it is closed first.
buffer | The pointer to the memory block |
len | The length of the memory block in bytes |
fs | The same rate in Hz. |
channels | The number of channels the file should carry. |
maxVal | The maximum value to be contained in the output vector when passed to Sox::write |
wordSize | The number of bits in the word. |
switchEndian | Switch the endian from big to little or little to big |
revBytes | Reverse the bytes {sox_option_no = 0, sox_option_yes = 1, sox_option_default = 2} |
revNibbles | Reverse the nibbles {sox_option_no = 0, sox_option_yes = 1, sox_option_default = 2} |
revBits | Reverse the bits {sox_option_no = 0, sox_option_yes = 1, sox_option_default = 2} |
int Sox< FP_TYPE_ >::openRead | ( | string | fileName | ) |
Open a file for reading. If the input file is already open, then it is closed first.
fileName | the audio file to open, can be of many different types, wav, mp3, ogg, etc. etc. |
Definition at line 70 of file Sox.C.
int Sox< FP_TYPE_ >::openRead | ( | intptr_t | buffer, |
size_t | len | ||
) |
|
inlinevirtual |
Open a file for writing. If the output file is already open, then it is closed first.
The size of FP_TYPE_ specifies the bit width for the output file to be created.
fileName | The name and path of the file to open for writing. The extension determines the type of file. |
fs | The same rate in Hz. |
channels | The number of channels the file should carry. |
maxVal | The maximum value to be contained in the output vector when passed to Sox::write |
Definition at line 174 of file Sox.H.
|
virtual |
Open a file for writing. Specifying the precision. If the output file is already open, then it is closed first.
fileName | The name and path of the file to open for writing. The extension determines the type of file. |
fs | The same rate in Hz. |
channels | The number of channels the file should carry. |
maxVal | The maximum value to be contained in the output vector when passed to Sox::write |
wordSize | The number of bits in the word. |
switchEndian | Switch the endian from big to little or little to big |
revBytes | Reverse the bytes {sox_option_no = 0, sox_option_yes = 1, sox_option_default = 2} |
revNibbles | Reverse the nibbles {sox_option_no = 0, sox_option_yes = 1, sox_option_default = 2} |
revBits | Reverse the bits {sox_option_no = 0, sox_option_yes = 1, sox_option_default = 2} |
|
staticprivate |
void Sox< FP_TYPE_ >::printFormats | ( | ) |
|
inline |
Read audio data from an already opened file. The audioData is returned with each column as an audio channel.
audioData | The Matrix to place the read audio into. It is resized as required and will match the size of the number of samples read where each column is a channel. |
count | the number of samples per channel to read, 0 for everything |
Definition at line 135 of file Sox.H.
|
inline |
|
virtual |
Write the audio data to an already open file. The audioData is written with each column as an audio channel.
audioData | The matrix to store to file. Each vector is a channel. |
Definition at line 203 of file Sox.C.
|
inline |
Write the audio data to an already open file. The audioData is written with each column as an audio channel.
audioData | The matrix to store to file. Each column is a channel. |
|
inline |
|
private |
|
private |
|
private |
|
private |
|
private |
GTK+ IOStream
Beta
|