DoubleBuffer.hxx

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2004 MUSIC TECHNOLOGY GROUP (MTG)
00003  *                         UNIVERSITAT POMPEU FABRA
00004  *
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 #ifndef __DOUBLEBUFFER__
00023 #define __DOUBLEBUFFER__
00024 
00025 #include "ErrOutOfMemory.hxx"
00026 #include "CLAM_windows.h"
00027 #undef GetClassName
00028 
00029 namespace CLAM
00030 {
00031 
00032 struct DoubleBuffer
00033 {
00034         short*   mFrontBuffer;
00035         short*   mBackBuffer;
00036         short*   mBuffA;
00037         short*   mBuffB;
00038         unsigned mLen;
00039         //bool     mBackBufferReady;
00040         HANDLE   mBackBufferReady;
00041 
00042         DoubleBuffer()
00043                 : mBuffA( NULL ), mBuffB( NULL ), mLen(0), mBackBufferReady( false )
00044         {
00045                 mBackBufferReady = CreateEvent( NULL, TRUE, FALSE, NULL );
00046         }
00047 
00048         ~DoubleBuffer()
00049         {
00050                 if ( mBuffA )
00051                         delete [] mBuffA;
00052                 if ( mBuffB )
00053                         delete [] mBuffB;
00054         }
00055 
00056         void Allocate( unsigned nelems ) throw (ErrOutOfMemory);
00057 
00058         inline void DeAllocate()
00059         {
00060                 if ( mBuffA )
00061                         delete [] mBuffA;
00062                 if ( mBuffB )
00063                         delete [] mBuffB;
00064 
00065                 mBuffA = NULL;
00066                 mBuffB = NULL;
00067                 mFrontBuffer = NULL;
00068                 mBackBuffer = NULL;
00069         }
00070 
00071         void SwapBuffers()
00072         {
00073                 short* temp;
00074                 temp = mFrontBuffer;
00075                 mFrontBuffer = mBackBuffer;
00076                 mBackBuffer = temp;
00077                 SetEvent( mBackBufferReady );
00078         }
00079 
00080         inline unsigned GetSize() const
00081         {
00082                 return mLen;
00083         }
00084 
00085 };
00086 
00087 
00088 struct FullDuplexDoubleBuffer
00089 {
00090         DoubleBuffer* mInputDblBuff;
00091         DoubleBuffer* mOutputDblBuff;
00092 
00093         inline unsigned GetSize()
00094         {
00095                 return mInputDblBuff->mLen;
00096         }
00097 };
00098 
00099 }
00100 
00101 #endif // DoubleBuffer.hxx
00102 

Generated on Tue Aug 12 22:33:42 2008 for CLAM by  doxygen 1.5.5