--- libgig/trunk/src/gig.h 2004/09/05 00:46:28 231 +++ libgig/trunk/src/gig.h 2005/02/10 19:16:31 365 @@ -63,9 +63,6 @@ #define GIG_EG_CTR_ATTACK_INFLUENCE_EXTRACT(x) ((x >> 1) & 0x03) #define GIG_EG_CTR_DECAY_INFLUENCE_EXTRACT(x) ((x >> 3) & 0x03) #define GIG_EG_CTR_RELEASE_INFLUENCE_EXTRACT(x) ((x >> 5) & 0x03) -#define GIG_VELOCITY_TRANSFORM_NONLINEAR(x,dynamic,scale) (-0.1666235937e0+0.5143775427e-4*x*x+0.5318278732e-1*dynamic*dynamic-0.3560390502e-4*scale*scale+0.4683631221e-2*x-0.9484386143e-1*dynamic+0.8030068910e-2*scale) -#define GIG_VELOCITY_TRANSFORM_LINEAR(x,dynamic,scale) (((1.0+scale*3.0/128.0)/110.0)*x+dynamic/5.0+dynamic*scale) -#define GIG_VELOCITY_TRANSFORM_SPECIAL(x,dynamic,scale) (-0.1630504921e0+0.5794551347e-4*x*x+0.8361491099e-2*dynamic*dynamic-0.4303475615e-5*scale*scale+0.2085522765e-2*x+0.1313747345e-1*dynamic+0.3220916836e-2*scale) /** Gigasampler specific classes and definitions */ namespace gig { @@ -222,7 +219,7 @@ dimension_velocity = 0x82, ///< Key Velocity (this is the only dimension where the ranges can exactly be defined). dimension_channelaftertouch = 0x83, ///< Channel Key Pressure dimension_releasetrigger = 0x84, ///< Special dimension for triggering samples on releasing a key. - dimension_keyboard = 0x85, ///< Key Position + dimension_keyboard = 0x85, ///< Dimension for keyswitching dimension_modwheel = 0x01, ///< Modulation Wheel (MIDI Controller 1) dimension_breath = 0x02, ///< Breath Controller (Coarse, MIDI Controller 2) dimension_foot = 0x04, ///< Foot Pedal (Coarse, MIDI Controller 4) @@ -277,18 +274,24 @@ vcf_type_bandreject = 0x03 } vcf_type_t; - /** Defines the envelope of a crossfade. */ + /** + * Defines the envelope of a crossfade. + * + * Note: The default value for crossfade points is 0,0,0,0. Layers with + * such a default value should be treated as if they would not have a + * crossfade. + */ struct crossfade_t { #if WORDS_BIGENDIAN - uint8_t in_start; ///< Start position of fade in. - uint8_t in_end; ///< End position of fade in. - uint8_t out_start; ///< Start position of fade out. - uint8_t out_end; ///< End postition of fade out. - #else // little endian uint8_t out_end; ///< End postition of fade out. uint8_t out_start; ///< Start position of fade out. uint8_t in_end; ///< End position of fade in. uint8_t in_start; ///< Start position of fade in. + #else // little endian + uint8_t in_start; ///< Start position of fade in. + uint8_t in_end; ///< End position of fade in. + uint8_t out_start; ///< Start position of fade out. + uint8_t out_end; ///< End postition of fade out. #endif // WORDS_BIGENDIAN }; @@ -303,6 +306,7 @@ class File; class Instrument; class Sample; + class Region; /** Encapsulates articulation information of a dimension region. * @@ -449,6 +453,7 @@ double* pVelocityAttenuationTable; ///< Points to the velocity table corresponding to the velocity parameters of this DimensionRegion. leverage_ctrl_t DecodeLeverageController(_lev_ctrl_t EncodedController); + double* CreateVelocityTable(curve_type_t curveType, uint8_t depth, uint8_t scaling); }; /** Encapsulates sample waves used for playback. */ @@ -487,10 +492,13 @@ protected: static unsigned int Instances; ///< Number of instances of class Sample. static unsigned long DecompressionBufferSize; ///< Current size of the decompression buffer. - static void* pDecompressionBuffer; ///< Small buffer used for decompression only. + static unsigned char* pDecompressionBuffer; ///< Small buffer used for decompression only. unsigned long FrameOffset; ///< Current offset (sample points) in current sample frame (for decompression only). unsigned long* FrameTable; ///< For positioning within compressed samples only: stores the offset values for each frame. unsigned long SamplePos; ///< For compressed samples only: stores the current position (in sample points). + unsigned long SamplesInLastFrame; ///< For compressed samples only: length of the last sample frame. + unsigned long WorstCaseFrameSize; ///< For compressed samples only: size (in bytes) of the largest possible sample frame. + unsigned long SamplesPerFrame; ///< For compressed samples only: number of samples in a full sample frame. buffer_t RAMCache; ///< Buffers samples (already uncompressed) in RAM. Sample(File* pFile, RIFF::List* waveList, unsigned long WavePoolOffset); @@ -555,6 +563,22 @@ return (A > B) ? B : A; } inline long Abs(long val) { return (val > 0) ? val : -val; } + + // Guess size (in bytes) of a compressed sample + inline unsigned long GuessSize(unsigned long samples) { + // 16 bit: assume all frames are compressed - 1 byte + // per sample and 5 bytes header per 2048 samples + + // 24 bit: assume next best compression rate - 1.5 + // bytes per sample and 13 bytes header per 256 + // samples + const unsigned long size = + BitDepth == 24 ? samples + (samples >> 1) + (samples >> 8) * 13 + : samples + (samples >> 10) * 5; + // Double for stereo and add one worst case sample + // frame + return (Channels == 2 ? size << 1 : size) + WorstCaseFrameSize; + } private: void ScanCompressedSample(); friend class File; @@ -566,12 +590,13 @@ class Region : public DLS::Region { public: unsigned int Dimensions; ///< Number of defined dimensions. - dimension_def_t pDimensionDefinitions[5]; ///< Defines the five possible dimensions (the dimension's controller and number of bits/splits). + dimension_def_t pDimensionDefinitions[8]; ///< Defines the five (gig2) or eight (gig3) possible dimensions (the dimension's controller and number of bits/splits). uint32_t DimensionRegions; ///< Total number of DimensionRegions this Region contains. - DimensionRegion* pDimensionRegions[32]; ///< Pointer array to the 32 possible dimension regions (reflects NULL for dimension regions not in use). Avoid to access the array directly and better use GetDimensionRegionByValue() instead, but of course in some cases it makes sense to use the array (e.g. iterating through all DimensionRegions). + DimensionRegion* pDimensionRegions[256]; ///< Pointer array to the 32 (gig2) or 256 (gig3) possible dimension regions (reflects NULL for dimension regions not in use). Avoid to access the array directly and better use GetDimensionRegionByValue() instead, but of course in some cases it makes sense to use the array (e.g. iterating through all DimensionRegions). + unsigned int Layers; ///< Amount of defined layers (1 - 32). A value of 1 actually means no layering, a value > 1 means there is Layer dimension. The same information can of course also be obtained by accessing pDimensionDefinitions. - DimensionRegion* GetDimensionRegionByValue(uint Dim4Val, uint Dim3Val, uint Dim2Val, uint Dim1Val, uint Dim0Val); - DimensionRegion* GetDimensionRegionByBit(uint8_t Dim4Bit, uint8_t Dim3Bit, uint8_t Dim2Bit, uint8_t Dim1Bit, uint8_t Dim0Bit); + DimensionRegion* GetDimensionRegionByValue(const uint DimValues[8]); + DimensionRegion* GetDimensionRegionByBit(const uint8_t DimBits[8]); Sample* GetSample(); protected: uint8_t VelocityTable[128]; ///< For velocity dimensions with custom defined zone ranges only: used for fast converting from velocity MIDI value to dimension bit number. @@ -642,7 +667,7 @@ Instrument* GetFirstInstrument(); ///< Returns a pointer to the first Instrument object of the file, NULL otherwise. Instrument* GetNextInstrument(); ///< Returns a pointer to the next Instrument object of the file, NULL otherwise. Instrument* GetInstrument(uint index); - ~File() {}; + ~File(); protected: typedef std::list SampleList; typedef std::list InstrumentList;