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/WavAudioOStream.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: WavAudioOStream.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_WAV_AUDIO_OSTREAM
00033 #define SUBSYNTH_WAV_AUDIO_OSTREAM
00034 
00035 #include <iostream>
00036 #include "syn/Stream/WavHeader.h"
00037 #include "syn/Stream/AudioOStream.h"
00038 
00039 namespace syn
00040 {
00045    class WavAudioOStream : public AudioOStream
00046    {
00047    public:
00048       WavAudioOStream() : mIsOpen( false ), mName( "default.wav" ), mPcount( 0 )
00049       {
00050       }
00051 
00052       virtual ~WavAudioOStream(){}
00053 
00055       void setName( const std::string& name )
00056       {
00057          if (name != mName && mIsOpen == true)
00058          {
00059             this->close();
00060             mName = name;
00061             this->open( mFmt );
00062          }
00063          else
00064          {
00065             mName = name;
00066          }
00067       }
00068 
00072       bool open( const syn::AudioFormat& fmt )
00073       {
00074          mFileOStream.open( mName.c_str(), std::ios::in );
00075          mFileOStream.write( wav_header, sizeof( WavHeader ) );
00076          if (mFileOStream.good())
00077          {
00078             mIsOpen = true;
00079             mFmt = fmt;
00080             return true;
00081          }
00082          
00083          return false;
00084       }
00085 
00087       virtual bool isOpen() = 0;
00088       
00090       bool canAcceptMoreData()
00091       {
00092          if (mIsOpen == false)
00093             return false;
00094          return true;
00095       }
00096 
00100       bool write( char* data, int samples )
00101       {
00102          if (mIsOpen == false)
00103             return false;
00104         mPcount = samples;
00105          mFileOStream.write( data, numBytes );
00106 
00107          return true;
00108       }
00109 
00111       virtual int pcount() const { return mPcount; }
00112 
00114       bool close()
00115       {
00116          if (mIsOpen == false)
00117             return false;
00118 
00119          mFileOStream.close();
00120 
00121          mIsOpen = false;
00122          return true;
00123       }
00124 
00125    private:
00126       int mPcount;
00127       std::fstream mFileOStream;
00128       bool mIsOpen;
00129       syn::AudioFormat mFmt;
00130 
00132       /*#  WavHeader lnkWavHeader; */
00133    };
00134 
00135 }
00136 
00137 
00138 #endif

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