Soundfile.hpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef CsoundAC_SOUNDFILE_H
00024 #define CsoundAC_SOUNDFILE_H
00025
00026 #include "Platform.hpp"
00027 #ifdef SWIG
00028 %module CsoundAC
00029 %{
00030 #include <sndfile.h>
00031 #include <iostream>
00032 #include <string>
00033 #include <vector>
00034 #include <cstring>
00035 %}
00036 %include "std_string.i"
00037 #ifdef SWIGPYTHON
00038 %typemap(in) double *outputFrame {
00039 static double buffer[16];
00040 $1 = &buffer[0];
00041 for (int i = 0, n = PySequence_Size($input); i < n; i++) {
00042 PyObject *o = PyFloat_FromDouble($1[i]);
00043 PySequence_SetItem($input, i, o);
00044 }
00045 }
00046 %typemap(in) double *inputFrame {
00047 static double buffer[16];
00048 $1 = &buffer[0];
00049 for (int i = 0, n = PySequence_Size($input); i < n; i++) {
00050 PyObject *o = PySequence_ITEM($input, i);
00051 $1[i] = PyFloat_AS_DOUBLE(o);
00052 }
00053 }
00054 %typemap(in) (double *outputFrames, int samples) {
00055 $1 = (double *) PyString_AsString($input);
00056 $2 = PyString_Size($input) / sizeof(double);
00057 }
00058 %typemap(in) (double *inputFrames, int samples) {
00059 $1 = (double *) PyString_AsString($input);
00060 $2 = PyString_Size($input) / sizeof(double);
00061 }
00062 %typemap(in) double *mixedFrames {
00063 $1 = (double *) PyString_AsString($input);
00064 }
00065
00066 #endif
00067 #else
00068 #include <sndfile.h>
00069 #include <iostream>
00070 #include <string>
00071 #include <vector>
00072 #include <cstring>
00073 #include <complex>
00074 #include <boost/numeric/ublas/matrix.hpp>
00075 #endif
00076
00077 namespace csound
00078 {
00086 class Soundfile
00087 {
00088 SNDFILE *sndfile;
00089 SF_INFO sf_info;
00090 boost::numeric::ublas::matrix<double> grainOutput;
00091 boost::numeric::ublas::matrix<double> grainBuffer;
00092 size_t sampleCount;
00093 double startTimeSeconds;
00094 protected:
00095 virtual void initialize() ;
00096 public:
00097 Soundfile();
00098 virtual ~Soundfile() ;
00099 virtual int getFramesPerSecond() const;
00100 virtual void setFramesPerSecond(int framesPerSecond);
00101 virtual int getChannelsPerFrame() const;
00102 virtual void setChannelsPerFrame(int channelsPerFrame);
00106 virtual int getFormat() const;
00110 virtual void setFormat(int format);
00115 virtual int getFrames() const;
00119 virtual int open(std::string filename);
00124 virtual int create(std::string filename, int framesPerSecond = 44100, int channelsPerFrame = 2, int format = SF_FORMAT_WAV | SF_FORMAT_FLOAT);
00130 virtual int seek(int frames, int whence = 0);
00131 virtual double seekSeconds(double seconds, int whence = 0);
00137 virtual int readFrame(double *outputFrame);
00144 virtual int writeFrame(double *inputFrame);
00152 virtual int readFrames(double *outputFrames, int samples);
00159 virtual int writeFrames(double *inputFrames, int samples);
00167 virtual int mixFrames(double *inputFrames, int samples, double *mixedFrames);
00172 virtual void updateHeader();
00177 virtual int close() ;
00181 virtual void error() const;
00185 virtual void blank(double duration);
00199 virtual void jonesParksGrain(double centerTimeSeconds,
00200 double durationSeconds,
00201 double beginningFrequencyHz,
00202 double centerFrequencyHz,
00203 double centerAmplitude,
00204 double centerPhaseOffsetRadians,
00205 double pan,
00206 bool synchronousPhase = true,
00207 bool buffer = false);
00224 virtual void cosineGrain(double centerTimeSeconds,
00225 double durationSeconds,
00226 double frequencyHz,
00227 double amplitude,
00228 double phaseOffsetRadians,
00229 double pan,
00230 bool synchronousPhase = true,
00231 bool buffer = false);
00235 virtual void mixGrain();
00236 };
00237 }
00238 #endif