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 #ifndef CSOUND_SOUNDFILE_H
00023 #define CSOUND_SOUNDFILE_H
00024
00025 #ifdef SWIG
00026 %module csnd
00027 %{
00028 #include <sndfile.h>
00029 #include <iostream>
00030 #include <string>
00031 #include <vector>
00032 #include <cstring>
00033 %}
00034 %include "std_string.i"
00035 #ifdef SWIGPYTHON
00036 %typemap(in) double *outputFrame {
00037 static double buffer[16];
00038 $1 = &buffer[0];
00039 for (int i = 0, n = PySequence_Size($input); i < n; i++) {
00040 PyObject *o = PyFloat_FromDouble($1[i]);
00041 PySequence_SetItem($input, i, o);
00042 }
00043 }
00044 %typemap(in) double *inputFrame {
00045 static double buffer[16];
00046 $1 = &buffer[0];
00047 for (int i = 0, n = PySequence_Size($input); i < n; i++) {
00048 PyObject *o = PySequence_ITEM($input, i);
00049 $1[i] = PyFloat_AS_DOUBLE(o);
00050 }
00051 }
00052 %typemap(in) (double *outputFrames, int samples) {
00053 $1 = (double *) PyString_AsString($input);
00054 $2 = PyString_Size($input) / sizeof(double);
00055 }
00056 %typemap(in) (double *inputFrames, int samples) {
00057 $1 = (double *) PyString_AsString($input);
00058 $2 = PyString_Size($input) / sizeof(double);
00059 }
00060 %typemap(in) double *mixedFrames {
00061 $1 = (double *) PyString_AsString($input);
00062 }
00063
00064 #endif
00065 #else
00066 #include <sndfile.h>
00067 #include <iostream>
00068 #include <string>
00069 #include <vector>
00070 #include <cstring>
00071 #endif
00072
00073 namespace csound
00074 {
00082 class Soundfile
00083 {
00084 SNDFILE *sndfile;
00085 SF_INFO sf_info;
00086 protected:
00087 virtual void initialize() ;
00088 public:
00089 Soundfile();
00090 virtual ~Soundfile() ;
00091 virtual int getFramesPerSecond() const;
00092 virtual void setFramesPerSecond(int framesPerSecond);
00093 virtual int getChannelsPerFrame() const;
00094 virtual void setChannelsPerFrame(int channelsPerFrame);
00098 virtual int getFormat() const;
00102 virtual void setFormat(int format);
00107 virtual int getFrames() const;
00111 virtual int open(std::string filename);
00116 virtual int create(std::string filename, int framesPerSecond = 44100, int channelsPerFrame = 2, int format = SF_FORMAT_WAV | SF_FORMAT_FLOAT);
00122 virtual int seek(int frames, int whence = 0);
00123 virtual double seekSeconds(double seconds, int whence = 0);
00129 virtual int readFrame(double *outputFrame);
00136 virtual int writeFrame(double *inputFrame);
00144 virtual int readFrames(double *outputFrames, int samples);
00151 virtual int writeFrames(double *inputFrames, int samples);
00159 virtual int mixFrames(double *inputFrames, int samples, double *mixedFrames);
00164 virtual void updateHeader();
00169 virtual int close() ;
00173 virtual void error() const;
00177 virtual void blank(double duration);
00178 };
00179 }
00180 #endif