soundclip.h

00001 /***************************************************************************
00002  *   Copyright (C) 2005-2011 by the FIFE team                              *
00003  *   http://www.fifengine.net                                              *
00004  *   This file is part of FIFE.                                            *
00005  *                                                                         *
00006  *   FIFE is free software; you can redistribute it and/or                 *
00007  *   modify it under the terms of the GNU Lesser General Public            *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2.1 of the License, or (at your option) any later version.    *
00010  *                                                                         *
00011  *   This library 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 GNU     *
00014  *   Lesser General Public License for more details.                       *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Lesser General Public      *
00017  *   License along with this library; if not, write to the                 *
00018  *   Free Software Foundation, Inc.,                                       *
00019  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
00020  ***************************************************************************/
00021 
00022 #ifndef FIFE_SOUNDCLIP_H_
00023 #define FIFE_SOUNDCLIP_H_
00024 
00025 // Standard C++ library includes
00026 #include <vector>
00027 
00028 // Platform specific includes
00029 
00030 // 3rd party library includes
00031 
00032 // FIFE includes
00033 // These includes are split up in two parts, separated by one empty line
00034 // First block: files included from the FIFE root src directory
00035 // Second block: files included from the same folder
00036 #include "util/resource/resource.h"
00037 
00038 #include "sounddecoder.h"
00039 
00040 namespace FIFE {
00041 
00044     enum SoundPositionType {
00045         SD_SAMPLE_POS,
00046         SD_TIME_POS,
00047         SD_BYTE_POS
00048     };
00049 
00050     struct SoundBufferEntry {
00051         ALuint buffers[BUFFER_NUM];
00052         uint32_t usedbufs;
00053         uint64_t deccursor;
00054     };
00055 
00058     class SoundClip : public IResource {
00059     public:
00060 
00061         SoundClip(IResourceLoader* loader = 0);
00062         SoundClip(const std::string& name, IResourceLoader* loader = 0);
00063 
00064         ~SoundClip();
00065 
00070         bool isStream() const {
00071             return m_isstream;
00072         }
00073 
00079         uint32_t countBuffers() const {
00080             return m_buffervec.at(0)->usedbufs;
00081         }
00082 
00086         ALuint* getBuffers(uint32_t streamid = 0) const {
00087             return m_buffervec.at(streamid)->buffers;
00088         }
00089 
00093         uint32_t beginStreaming();
00094 
00099         void acquireStream(uint32_t streamid);
00100 
00104         bool setStreamPos(uint32_t streamid, SoundPositionType type, float value);
00105 
00108         float getStreamPos(uint32_t streamid, SoundPositionType type) const;
00109 
00115         bool getStream(uint32_t streamid, ALuint buffer);
00116 
00119         void quitStreaming(uint32_t streamid);
00120 
00123         void adobtDecoder(SoundDecoder* decoder) { m_decoder = decoder; m_deletedecoder = true; }
00124 
00127         void setDecoder(SoundDecoder* decoder) { m_decoder = decoder; m_deletedecoder = false; }
00128 
00131         SoundDecoder* getDecoder() const {
00132             return m_decoder;
00133         }
00134 
00135         virtual size_t getSize() { return 0; }
00136 
00137         virtual void load();
00138         virtual void free();
00139 
00140     private:
00141         bool                        m_isstream;         // is stream?
00142         SoundDecoder*       m_decoder;          // attached decoder
00143         bool                        m_deletedecoder;    // when loadFromDecoder-method is used, decoder shouldn't be deleted
00144         std::vector<SoundBufferEntry*> m_buffervec;
00145 
00146         std::string createUniqueClipName();
00147     };
00148 
00149     typedef SharedPtr<SoundClip> SoundClipPtr;
00150 }
00151 
00152 #endif