Pd++  0.01
A pure C++ implementation of Pure Data objects
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
Public Member Functions | Public Attributes | List of all members
pd::SoundFiler Class Reference

Reads and writes sound files. More...

#include <SoundFiler.h>

Inheritance diagram for pd::SoundFiler:
PdMaster stk::Stk

Public Member Functions

double read (std::string file)
 
void write (std::string fileName, unsigned int nChannels, stk::FileWrite::FILE_TYPE type, Stk::StkFormat format, std::vector< double > array)
 
std::vector< double > getArray ()
 
- Public Member Functions inherited from PdMaster
void * getbytes (size_t nbytes)
 
void * resizebytes (void *old, size_t oldsize, size_t newsize)
 
void freebytes (void *fatso, size_t nbytes)
 
std::string getPath ()
 
void setSampleRate (unsigned long)
 
unsigned long getSampleRate ()
 
void setBlockSize (int)
 
int getBlockSize ()
 
double getTimeInSampleTicks ()
 
long getTimeInMilliSeconds (double time)
 
int pdBigOrSmall (double f)
 
void cos_maketable ()
 
int PD_BIGORSMALL (float f)
 
void setFFTWindow (int)
 
int getFFTWindow ()
 
double mtof (double)
 
double ftom (double)
 
double powtodb (double)
 
double dbtopow (double)
 
double rmstodb (double)
 
double dbtorms (double)
 
- Public Member Functions inherited from stk::Stk
void ignoreSampleRateChange (bool ignore=true)
 A function to enable/disable the automatic updating of class data when the STK sample rate changes. More...
 

Public Attributes

const std::string pdName = "soundfiler"
 
- Public Attributes inherited from PdMaster
int cosTableSize = COSTABSIZE
 
float * cos_table
 

Additional Inherited Members

- Public Types inherited from PdMaster
typedef union
PdMaster::_sampleint_union 
t_sampleint_union
 
- Public Types inherited from stk::Stk
typedef unsigned long StkFormat
 
- Static Public Member Functions inherited from stk::Stk
static StkFloat sampleRate (void)
 Static method that returns the current STK sample rate.
 
static void setSampleRate (StkFloat rate)
 Static method that sets the STK sample rate. More...
 
static std::string rawwavePath (void)
 Static method that returns the current rawwave path.
 
static void setRawwavePath (std::string path)
 Static method that sets the STK rawwave path.
 
static void swap16 (unsigned char *ptr)
 Static method that byte-swaps a 16-bit data type.
 
static void swap32 (unsigned char *ptr)
 Static method that byte-swaps a 32-bit data type.
 
static void swap64 (unsigned char *ptr)
 Static method that byte-swaps a 64-bit data type.
 
static void sleep (unsigned long milliseconds)
 Static cross-platform method to sleep for a number of milliseconds.
 
static bool inRange (StkFloat value, StkFloat min, StkFloat max)
 Static method to check whether a value is within a specified range.
 
static void handleError (const char *message, StkError::Type type)
 Static function for error reporting and handling using c-strings.
 
static void handleError (std::string message, StkError::Type type)
 Static function for error reporting and handling using c++ strings.
 
static void showWarnings (bool status)
 Toggle display of WARNING and STATUS messages.
 
static void printErrors (bool status)
 Toggle display of error messages before throwing exceptions.
 
- Static Public Attributes inherited from stk::Stk
static const StkFormat STK_SINT8 = 0x1
 
static const StkFormat STK_SINT16 = 0x2
 
static const StkFormat STK_SINT24 = 0x4
 
static const StkFormat STK_SINT32 = 0x8
 
static const StkFormat STK_FLOAT32 = 0x10
 
static const StkFormat STK_FLOAT64 = 0x20
 
- Protected Member Functions inherited from stk::Stk
 Stk (void)
 Default constructor.
 
virtual ~Stk (void)
 Class destructor.
 
virtual void sampleRateChanged (StkFloat newRate, StkFloat oldRate)
 This function should be implemented in subclasses that depend on the sample rate.
 
void addSampleRateAlert (Stk *ptr)
 Add class pointer to list for sample rate change notification.
 
void removeSampleRateAlert (Stk *ptr)
 Remove class pointer from list for sample rate change notification.
 
void handleError (StkError::Type type) const
 Internal function for error reporting that assumes message in oStream_ variable.
 
- Protected Attributes inherited from stk::Stk
bool ignoreSampleRateChange_
 
- Static Protected Attributes inherited from stk::Stk
static std::ostringstream oStream_
 

Detailed Description

Reads and writes sound files.

Instead of trying to detach the Pd soundfiler code, which is very difficult to port over to C++ due to the number of dependencies, I chose to use STK's read and write methods. Since their classes are already written in C++ this saves a lot of time and really shouldn't sound any different.

This does not apply to table reading, such as tabwrite4~, which uses interpolation. When reading from arrays into the audio domain we will still use this method.

Member Function Documentation

double pd::SoundFiler::read ( std::string  file)

Just like Pd's soundfiler, this class will read a file and store it in a vector which can be accessed using getArray(). Remember that the audio file data will be stored in RAM so large files can eat up lots of your applications' memory. If you want to read from disk look for readsf~, or the class ReadSF...in the future.

void pd::SoundFiler::write ( std::string  fileName,
unsigned int  nChannels,
stk::FileWrite::FILE_TYPE  type,
Stk::StkFormat  format,
std::vector< double >  array 
)

This method takes a filled array, and writes it to an audio format. This is similar to how Pd writes the contents of an array directly to a .wav. If you want to use buffered sound file writing look for writesf~ or the class WriteSF in the future...


The documentation for this class was generated from the following files: