492 |
protected: |
protected: |
493 |
static unsigned int Instances; ///< Number of instances of class Sample. |
static unsigned int Instances; ///< Number of instances of class Sample. |
494 |
static unsigned long DecompressionBufferSize; ///< Current size of the decompression buffer. |
static unsigned long DecompressionBufferSize; ///< Current size of the decompression buffer. |
495 |
static void* pDecompressionBuffer; ///< Small buffer used for decompression only. |
static unsigned char* pDecompressionBuffer; ///< Small buffer used for decompression only. |
496 |
unsigned long FrameOffset; ///< Current offset (sample points) in current sample frame (for decompression only). |
unsigned long FrameOffset; ///< Current offset (sample points) in current sample frame (for decompression only). |
497 |
unsigned long* FrameTable; ///< For positioning within compressed samples only: stores the offset values for each frame. |
unsigned long* FrameTable; ///< For positioning within compressed samples only: stores the offset values for each frame. |
498 |
unsigned long SamplePos; ///< For compressed samples only: stores the current position (in sample points). |
unsigned long SamplePos; ///< For compressed samples only: stores the current position (in sample points). |
499 |
|
unsigned long SamplesInLastFrame; ///< For compressed samples only: length of the last sample frame. |
500 |
|
unsigned long WorstCaseFrameSize; ///< For compressed samples only: size (in bytes) of the largest possible sample frame. |
501 |
|
unsigned long SamplesPerFrame; ///< For compressed samples only: number of samples in a full sample frame. |
502 |
buffer_t RAMCache; ///< Buffers samples (already uncompressed) in RAM. |
buffer_t RAMCache; ///< Buffers samples (already uncompressed) in RAM. |
503 |
|
|
504 |
Sample(File* pFile, RIFF::List* waveList, unsigned long WavePoolOffset); |
Sample(File* pFile, RIFF::List* waveList, unsigned long WavePoolOffset); |
563 |
return (A > B) ? B : A; |
return (A > B) ? B : A; |
564 |
} |
} |
565 |
inline long Abs(long val) { return (val > 0) ? val : -val; } |
inline long Abs(long val) { return (val > 0) ? val : -val; } |
566 |
|
|
567 |
|
// Guess size (in bytes) of a compressed sample |
568 |
|
inline unsigned long GuessSize(unsigned long samples) { |
569 |
|
// 16 bit: assume all frames are compressed - 1 byte |
570 |
|
// per sample and 5 bytes header per 2048 samples |
571 |
|
|
572 |
|
// 24 bit: assume next best compression rate - 1.5 |
573 |
|
// bytes per sample and 13 bytes header per 256 |
574 |
|
// samples |
575 |
|
const unsigned long size = |
576 |
|
BitDepth == 24 ? samples + (samples >> 1) + (samples >> 8) * 13 |
577 |
|
: samples + (samples >> 10) * 5; |
578 |
|
// Double for stereo and add one worst case sample |
579 |
|
// frame |
580 |
|
return (Channels == 2 ? size << 1 : size) + WorstCaseFrameSize; |
581 |
|
} |
582 |
private: |
private: |
583 |
void ScanCompressedSample(); |
void ScanCompressedSample(); |
584 |
friend class File; |
friend class File; |