Soundfile.hpp

Go to the documentation of this file.
00001 /*
00002  * C S O U N D   V S T
00003  *
00004  * A VST plugin version of Csound, with Python scripting.
00005  *
00006  * L I C E N S E
00007  *
00008  * This software is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * This software is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this software; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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

Generated on Sun Nov 9 00:04:52 2008 for Csound and CsoundAC by  doxygen 1.5.6