buffer.h

Go to the documentation of this file.
00001 
00005 /* Copyright, 2001 Nevrax Ltd.
00006  *
00007  * This file is part of NEVRAX NEL.
00008  * NEVRAX NEL is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2, or (at your option)
00011  * any later version.
00012 
00013  * NEVRAX NEL is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00016  * General Public License for more details.
00017 
00018  * You should have received a copy of the GNU General Public License
00019  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00020  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00021  * MA 02111-1307, USA.
00022  */
00023 
00024 #ifndef NL_BUFFER_H
00025 #define NL_BUFFER_H
00026 
00027 #include "nel/misc/types_nl.h"
00028 #include "nel/misc/string_mapper.h"
00029 #include "sound_driver.h"
00030 
00031 namespace NLMISC {
00032     class IStream;
00033 }
00034 
00035 namespace NLSOUND {
00036 
00043 class IBuffer
00044 {
00045 public:
00047     enum TBufferFormat
00048     {
00050         FormatUnknown = 0, 
00052         FormatPcm = 1, 
00055         FormatDviAdpcm = 11, 
00056     };
00058     enum TStorageMode
00059     {
00061         StorageAuto, 
00063         StorageHardware, 
00065         StorageSoftware
00066     };
00067     
00073     virtual void setName(NLMISC::TStringId bufferName) = 0;
00075     virtual NLMISC::TStringId getName() const = 0;
00076 
00078     virtual void setFormat(TBufferFormat format, uint8 channels, uint8 bitsPerSample, uint32 frequency) = 0;
00080     virtual void getFormat(TBufferFormat &format, uint8 &channels, uint8 &bitsPerSample, uint32 &frequency) const = 0;
00082     virtual void setStorageMode(TStorageMode storageMode = IBuffer::StorageAuto) = 0;
00084     virtual TStorageMode getStorageMode() = 0;
00085 
00087     virtual uint8 *lock(uint capacity) = 0;
00089     virtual bool unlock(uint size) = 0;
00091     virtual bool fill(const uint8 *src, uint size) = 0;
00092     
00094     virtual uint getSize() const = 0;
00096     virtual float getDuration() const = 0;
00098     virtual bool isStereo() const = 0;  
00100     virtual bool isBufferLoaded() const = 0;
00101     
00103     //\name ***deprecated***
00105     void setFormat(TSampleFormat format, uint freq);
00107     void getFormat(TSampleFormat& format, uint& freq) const;
00109     static void sampleFormatToBufferFormat(TSampleFormat sampleFormat, TBufferFormat &bufferFormat, uint8 &channels, uint8 &bitsPerSample);
00111     static void bufferFormatToSampleFormat(TBufferFormat bufferFormat, uint8 channels, uint8 bitsPerSample, TSampleFormat &sampleFormat);
00113 
00115     //\name Utility functions
00117     static uint getPCMSizeFromDuration(float duration, uint8 channels, uint8 bitsPerSample, uint32 frequency);
00119     static float getDurationFromPCMSize(uint size, uint8 channels, uint8 bitsPerSample, uint32 frequency);
00121     
00123     //\name ADPCM and sample bank building utility methods
00124     struct TADPCMState
00125     {
00127         sint16  PreviousSample;
00129         uint8   StepIndex;
00130     };
00132     static void encodeADPCM(const sint16 *indata, uint8 *outdata, uint nbSample, TADPCMState &state);
00134     static void decodeADPCM(const uint8 *indata, sint16 *outdata, uint nbSample, TADPCMState &state);   
00136     static bool readWav(const uint8 *wav, uint size, std::vector<uint8> &result, TBufferFormat &bufferFormat, uint8 &channels, uint8 &bitsPerSample, uint32 &frequency);
00138     static bool writeWav(const uint8 *buffer, uint size, TBufferFormat bufferFormat, uint8 channels, uint8 bitsPerSample, uint32 frequency, NLMISC::IStream &out);
00140     static bool convertToMono16PCM(const uint8 *buffer, uint size, std::vector<sint16> &result, TBufferFormat bufferFormat, uint8 channels, uint8 bitsPerSample);
00142     static bool convertMono16PCMToMonoADPCM(const sint16 *buffer, uint samples, std::vector<uint8> &result);
00144     
00145 private:
00146     static const sint _IndexTable[16];
00147     static const uint _StepsizeTable[89];
00149     
00150 protected:
00152     IBuffer() { }
00153     
00154 public:
00156     virtual ~IBuffer() { }
00157     
00158 };
00159 
00160 } // NLSOUND
00161 
00162 #endif // NL_BUFFER_H
00163 
00164 /* End of buffer.h */

Generated on Thu Jan 7 08:26:37 2010 for NeL by  doxygen 1.6.1