Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

/root/src/subsynth/syn/Stream/RawAudioOStream.h

Go to the documentation of this file.
00001 
00002 /****************** <SYN heading BEGIN do not edit this line> *****************
00003  *
00004  * subsynth - modular audio synthesizer
00005  * subsynth is (C) Copyright 2001-2002 by Kevin Meinert
00006  *
00007  * Original Author: Kevin Meinert
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Library General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2 of the License, or (at your option) any later version.
00013  *
00014  * This library is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  * Library General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Library General Public
00020  * License along with this library; if not, write to the
00021  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00022  * Boston, MA 02111-1307, USA.
00023  *
00024  * -----------------------------------------------------------------
00025  * File:          $RCSfile: RawAudioOStream.h,v $
00026  * Date modified: $Date: 2002/02/16 19:24:16 $
00027  * Version:       $Revision: 1.11 $
00028  * -----------------------------------------------------------------
00029  *
00030  ****************** <SYN heading END do not edit this line> ******************/
00031 
00032 #ifndef SUBSYNTH_RAW_AUDIO_OSTREAM
00033 #define SUBSYNTH_RAW_AUDIO_OSTREAM
00034 
00035 #include <iostream>
00036 #include <fstream>
00037 #include <string>
00038 #include "syn/Stream/WavHeader.h"
00039 #include "syn/Stream/AudioOStream.h"
00040 
00041 namespace syn
00042 {
00043 
00049    class RawAudioOStream : public AudioOStream
00050    {
00051    public:
00052       RawAudioOStream() : mIsOpen( false ), mName( "untitled.raw" ), mPcount( 0 )
00053       {
00054       }
00055 
00056       virtual ~RawAudioOStream(){}
00057 
00058       void setName( const std::string& name )
00059       {
00060          if (name != mName && mIsOpen == true)
00061          {
00062             this->close();
00063             mName = name;
00064             this->open( mFmt );
00065          }
00066          else
00067          {
00068             mName = name;
00069          }
00070       }
00071 
00075       bool open( const syn::AudioFormat& fmt )
00076       {
00077          mFileOStream.open( mName.c_str(), std::ios::out | std::ios::binary );
00078          if (mFileOStream.good())
00079          {
00080             mIsOpen = true;
00081             mFmt = fmt;
00082             return true;
00083          }
00084          
00085          return false;
00086       }
00087 
00089       virtual bool isOpen() { return mIsOpen; }
00090       
00092       virtual bool canAcceptMoreData() const
00093       {
00094          return mIsOpen == true;
00095       }
00096 
00100       bool write( const void* const data, int samples )
00101       {
00102          if (mIsOpen == false)
00103             return false;
00104 
00105          mPcount = samples;
00106          mFileOStream.write( (char*) data, samples * mFmt.sampsize() );
00107 
00108          return true;
00109       }
00110 
00112       virtual int pcount() const { return mPcount; }
00113 
00115       bool close()
00116       {
00117          if (mIsOpen == false)
00118             return false;
00119 
00120          mFileOStream.close();
00121 
00122          mIsOpen = false;
00123          return mIsOpen == false;
00124       }
00125 
00126       /* commit all unwritten data, returns when all data is finished writing */
00127       virtual void flush()
00128       {
00129          mFileOStream<<std::flush;
00130       }
00131       
00132    private:
00133       std::fstream mFileOStream;
00134       bool mIsOpen;
00135       std::string mName;
00136       int mPcount;
00137       syn::AudioFormat mFmt;
00138    };
00139 
00140 }
00141 
00142 
00143 #endif

Generated at Mon Apr 15 09:26:08 2002 for subsynth by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001