--- libgig/trunk/src/gig.h 2007/04/11 18:11:09 1155 +++ libgig/trunk/src/gig.h 2007/08/31 19:09:13 1316 @@ -38,6 +38,8 @@ # define CHUNK_ID_3EWG 0x33657767 # define CHUNK_ID_EWAV 0x65776176 # define CHUNK_ID_3GNM 0x33676E6D +# define CHUNK_ID_EINF 0x65696E66 +# define CHUNK_ID_3CRC 0x33637263 #else // little endian # define LIST_TYPE_3PRG 0x67727033 # define LIST_TYPE_3EWL 0x6C776533 @@ -50,6 +52,8 @@ # define CHUNK_ID_3EWG 0x67776533 # define CHUNK_ID_EWAV 0x76617765 # define CHUNK_ID_3GNM 0x6D6E6733 +# define CHUNK_ID_EINF 0x666E6965 +# define CHUNK_ID_3CRC 0x63726333 #endif // WORDS_BIGENDIAN /** Gigasampler specific classes and definitions */ @@ -319,6 +323,35 @@ progress_t(); }; + /** @brief CRC-32 checksum implementation + * + * This class is used to calculate checksums of the sample data in + * a gig file. The checksums are stored in the 3crc chunk of the + * gig file and automatically updated when a sample is written + * with Sample::Write(). + */ + class CRC { + private: + uint32_t value; + static const uint32_t* table; + static uint32_t* initTable(); + public: + CRC() { + reset(); + } + void reset() { + value = 0xffffffff; + } + void update(unsigned char* buf, int len) { + for (int i = 0 ; i < len ; i++) { + value = table[(value ^ buf[i]) & 0xff] ^ (value >> 8); + } + } + uint32_t getValue() { + return value ^ 0xffffffff; + } + }; + // just symbol prototyping class File; class Instrument; @@ -437,6 +470,7 @@ double GetVelocityAttenuation(uint8_t MIDIKeyVelocity); double GetVelocityRelease(uint8_t MIDIKeyVelocity); double GetVelocityCutoff(uint8_t MIDIKeyVelocity); + Region* GetParent() const; // derived methods DLS::Sampler::AddSampleLoop; DLS::Sampler::DeleteSampleLoop; @@ -444,7 +478,8 @@ virtual void UpdateChunks(); protected: uint8_t* VelocityTable; ///< For velocity dimensions with custom defined zone ranges only: used for fast converting from velocity MIDI value to dimension bit number. - DimensionRegion(RIFF::List* _3ewl); + DimensionRegion(Region* pParent, RIFF::List* _3ewl); + DimensionRegion(RIFF::List* _3ewl, const DimensionRegion& src); ~DimensionRegion(); friend class Region; private: @@ -483,6 +518,7 @@ double* pVelocityAttenuationTable; ///< Points to the velocity table corresponding to the velocity parameters of this DimensionRegion. double* pVelocityReleaseTable; ///< Points to the velocity table corresponding to the release velocity parameters of this DimensionRegion double* pVelocityCutoffTable; ///< Points to the velocity table corresponding to the filter velocity parameters of this DimensionRegion + Region* pRegion; leverage_ctrl_t DecodeLeverageController(_lev_ctrl_t EncodedController); _lev_ctrl_t EncodeLeverageController(leverage_ctrl_t DecodedController); @@ -559,6 +595,7 @@ unsigned long FileNo; ///< File number (> 0 when sample is stored in an extension file, 0 when it's in the gig) RIFF::Chunk* pCk3gix; RIFF::Chunk* pCkSmpl; + CRC crc; ///< CRC-32 checksum of the raw sample data Sample(File* pFile, RIFF::List* waveList, unsigned long WavePoolOffset, unsigned long fileNo = 0); ~Sample(); @@ -695,6 +732,9 @@ /** Parses Gigasampler files and provides abstract access to the data. */ class File : protected DLS::File { public: + static const DLS::version_t VERSION_2; + static const DLS::version_t VERSION_3; + // derived attributes from DLS::Resource DLS::Resource::pInfo; DLS::Resource::pDLSID; @@ -734,10 +774,12 @@ // own protected methods virtual void LoadSamples(progress_t* pProgress); virtual void LoadInstruments(progress_t* pProgress); + void SetSampleChecksum(Sample* pSample, uint32_t crc); friend class Region; friend class Sample; friend class Group; // so Group can access protected member pRIFF private: + static const DLS::Info::FixedStringLength FixedStringLengths[]; std::list* pGroups; std::list::iterator GroupsIterator; };