MercurySoundDriver.h

Go to the documentation of this file.
00001 #ifndef MERCURYSOUNDDRIVER_H
00002 #define MERCURYSOUNDDRIVER_H
00003 
00004 #include "MercuryString.h"
00005 #include "MercurySoundSourceWAV.h"
00006 #include "MercuryThreads.h"
00007 
00008 class MercurySoundDriver
00009 {
00010     public:
00011         MercurySoundDriver();
00012         virtual ~MercurySoundDriver();
00013         
00014         virtual void Init();
00015         
00016         static MercurySoundDriver& GetInstance();
00017         static void* TheadFunctCaller(void* x);
00018         
00019         void CreateThread();
00020         void ThreadLoop();
00021         void Start();
00022         
00023         void AddSound(MercurySoundSourceWAV* sound);
00024         void RemoveSound(MercurySoundSourceWAV* sound);
00025     protected:
00026         virtual void Cleanup() {};
00027         void ProcessPlayingSounds();
00028         virtual void WriteSoundFrames() {};
00029         
00030         MString m_name;
00031         
00032         unsigned int m_rate;
00033         unsigned short m_channels;
00034     
00035         unsigned long m_bufferSize;
00036         unsigned long m_writeSize;
00037         
00038         int16_t** m_front, **m_back;
00039         int16_t* m_buffer, *m_buffer2;
00040         unsigned long m_bufferLocation;
00041         unsigned long m_sentFrames;
00042         
00043         bool m_needData;
00044         
00045         MVector< MercurySoundSourceWAV* > m_playingSounds;
00046         MercuryThread m_thread;
00047         MercuryMutex m_mutex;
00048     private:
00049         
00050 };
00051 
00052 //ensures proper destruction of the factory singleton
00053 //each include of this file increments the counter
00054 static InstanceCounter<MercurySoundDriver> MSDcounter;
00055 
00056 #endif
00057 
00058 /* 
00059  * Copyright (c) 2007 Joshua Allen
00060  * All rights reserved.
00061  *
00062  * Redistribution and use in source and binary forms, with or
00063  * without modification, are permitted provided that the following
00064  * conditions are met:
00065  *  -   Redistributions of source code must retain the above
00066  *      copyright notice, this list of conditions and the following disclaimer.
00067  *  -   Redistributions in binary form must reproduce the above copyright
00068  *      notice, this list of conditions and the following disclaimer in
00069  *      the documentation and/or other materials provided with the distribution.
00070  *  -   Neither the name of the Mercury Engine nor the names of its
00071  *      contributors may be used to endorse or promote products derived from
00072  *      this software without specific prior written permission.
00073  *
00074  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00075  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00076  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00077  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
00078  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00079  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00080  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00081  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00082  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00083  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00084  */

Hosted by SourceForge.net Logo