2 |
* * |
* * |
3 |
* libgig - C++ cross-platform Gigasampler format file access library * |
* libgig - C++ cross-platform Gigasampler format file access library * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003-2015 by Christian Schoenebeck * |
* Copyright (C) 2003-2016 by Christian Schoenebeck * |
6 |
* <cuse@users.sourceforge.net> * |
* <cuse@users.sourceforge.net> * |
7 |
* * |
* * |
8 |
* This library is free software; you can redistribute it and/or modify * |
* This library is free software; you can redistribute it and/or modify * |
30 |
#include <iostream> |
#include <iostream> |
31 |
#include <assert.h> |
#include <assert.h> |
32 |
|
|
33 |
|
/// libgig's current file format version (for extending the original Giga file |
34 |
|
/// format with libgig's own custom data / custom features). |
35 |
|
#define GIG_FILE_EXT_VERSION 2 |
36 |
|
|
37 |
/// Initial size of the sample buffer which is used for decompression of |
/// Initial size of the sample buffer which is used for decompression of |
38 |
/// compressed sample wave streams - this value should always be bigger than |
/// compressed sample wave streams - this value should always be bigger than |
39 |
/// the biggest sample piece expected to be read by the sampler engine, |
/// the biggest sample piece expected to be read by the sampler engine, |
95 |
void Decompress16(int compressionmode, const unsigned char* params, |
void Decompress16(int compressionmode, const unsigned char* params, |
96 |
int srcStep, int dstStep, |
int srcStep, int dstStep, |
97 |
const unsigned char* pSrc, int16_t* pDst, |
const unsigned char* pSrc, int16_t* pDst, |
98 |
unsigned long currentframeoffset, |
file_offset_t currentframeoffset, |
99 |
unsigned long copysamples) |
file_offset_t copysamples) |
100 |
{ |
{ |
101 |
switch (compressionmode) { |
switch (compressionmode) { |
102 |
case 0: // 16 bit uncompressed |
case 0: // 16 bit uncompressed |
132 |
|
|
133 |
void Decompress24(int compressionmode, const unsigned char* params, |
void Decompress24(int compressionmode, const unsigned char* params, |
134 |
int dstStep, const unsigned char* pSrc, uint8_t* pDst, |
int dstStep, const unsigned char* pSrc, uint8_t* pDst, |
135 |
unsigned long currentframeoffset, |
file_offset_t currentframeoffset, |
136 |
unsigned long copysamples, int truncatedBits) |
file_offset_t copysamples, int truncatedBits) |
137 |
{ |
{ |
138 |
int y, dy, ddy, dddy; |
int y, dy, ddy, dddy; |
139 |
|
|
318 |
// *************** Sample *************** |
// *************** Sample *************** |
319 |
// * |
// * |
320 |
|
|
321 |
unsigned int Sample::Instances = 0; |
size_t Sample::Instances = 0; |
322 |
buffer_t Sample::InternalDecompressionBuffer; |
buffer_t Sample::InternalDecompressionBuffer; |
323 |
|
|
324 |
/** @brief Constructor. |
/** @brief Constructor. |
339 |
* @param fileNo - number of an extension file where this sample |
* @param fileNo - number of an extension file where this sample |
340 |
* is located, 0 otherwise |
* is located, 0 otherwise |
341 |
*/ |
*/ |
342 |
Sample::Sample(File* pFile, RIFF::List* waveList, unsigned long WavePoolOffset, unsigned long fileNo) : DLS::Sample((DLS::File*) pFile, waveList, WavePoolOffset) { |
Sample::Sample(File* pFile, RIFF::List* waveList, file_offset_t WavePoolOffset, unsigned long fileNo) : DLS::Sample((DLS::File*) pFile, waveList, WavePoolOffset) { |
343 |
static const DLS::Info::string_length_t fixedStringLengths[] = { |
static const DLS::Info::string_length_t fixedStringLengths[] = { |
344 |
{ CHUNK_ID_INAM, 64 }, |
{ CHUNK_ID_INAM, 64 }, |
345 |
{ 0, 0 } |
{ 0, 0 } |
481 |
const int iReadAtOnce = 32*1024; |
const int iReadAtOnce = 32*1024; |
482 |
char* buf = new char[iReadAtOnce * orig->FrameSize]; |
char* buf = new char[iReadAtOnce * orig->FrameSize]; |
483 |
Sample* pOrig = (Sample*) orig; //HACK: remove constness for now |
Sample* pOrig = (Sample*) orig; //HACK: remove constness for now |
484 |
unsigned long restorePos = pOrig->GetPos(); |
file_offset_t restorePos = pOrig->GetPos(); |
485 |
pOrig->SetPos(0); |
pOrig->SetPos(0); |
486 |
SetPos(0); |
SetPos(0); |
487 |
for (unsigned long n = pOrig->Read(buf, iReadAtOnce); n; |
for (file_offset_t n = pOrig->Read(buf, iReadAtOnce); n; |
488 |
n = pOrig->Read(buf, iReadAtOnce)) |
n = pOrig->Read(buf, iReadAtOnce)) |
489 |
{ |
{ |
490 |
Write(buf, n); |
Write(buf, n); |
569 |
void Sample::ScanCompressedSample() { |
void Sample::ScanCompressedSample() { |
570 |
//TODO: we have to add some more scans here (e.g. determine compression rate) |
//TODO: we have to add some more scans here (e.g. determine compression rate) |
571 |
this->SamplesTotal = 0; |
this->SamplesTotal = 0; |
572 |
std::list<unsigned long> frameOffsets; |
std::list<file_offset_t> frameOffsets; |
573 |
|
|
574 |
SamplesPerFrame = BitDepth == 24 ? 256 : 2048; |
SamplesPerFrame = BitDepth == 24 ? 256 : 2048; |
575 |
WorstCaseFrameSize = SamplesPerFrame * FrameSize + Channels; // +Channels for compression flag |
WorstCaseFrameSize = SamplesPerFrame * FrameSize + Channels; // +Channels for compression flag |
585 |
const int mode_l = pCkData->ReadUint8(); |
const int mode_l = pCkData->ReadUint8(); |
586 |
const int mode_r = pCkData->ReadUint8(); |
const int mode_r = pCkData->ReadUint8(); |
587 |
if (mode_l > 5 || mode_r > 5) throw gig::Exception("Unknown compression mode"); |
if (mode_l > 5 || mode_r > 5) throw gig::Exception("Unknown compression mode"); |
588 |
const unsigned long frameSize = bytesPerFrame[mode_l] + bytesPerFrame[mode_r]; |
const file_offset_t frameSize = bytesPerFrame[mode_l] + bytesPerFrame[mode_r]; |
589 |
|
|
590 |
if (pCkData->RemainingBytes() <= frameSize) { |
if (pCkData->RemainingBytes() <= frameSize) { |
591 |
SamplesInLastFrame = |
SamplesInLastFrame = |
604 |
|
|
605 |
const int mode = pCkData->ReadUint8(); |
const int mode = pCkData->ReadUint8(); |
606 |
if (mode > 5) throw gig::Exception("Unknown compression mode"); |
if (mode > 5) throw gig::Exception("Unknown compression mode"); |
607 |
const unsigned long frameSize = bytesPerFrame[mode]; |
const file_offset_t frameSize = bytesPerFrame[mode]; |
608 |
|
|
609 |
if (pCkData->RemainingBytes() <= frameSize) { |
if (pCkData->RemainingBytes() <= frameSize) { |
610 |
SamplesInLastFrame = |
SamplesInLastFrame = |
620 |
|
|
621 |
// Build the frames table (which is used for fast resolving of a frame's chunk offset) |
// Build the frames table (which is used for fast resolving of a frame's chunk offset) |
622 |
if (FrameTable) delete[] FrameTable; |
if (FrameTable) delete[] FrameTable; |
623 |
FrameTable = new unsigned long[frameOffsets.size()]; |
FrameTable = new file_offset_t[frameOffsets.size()]; |
624 |
std::list<unsigned long>::iterator end = frameOffsets.end(); |
std::list<file_offset_t>::iterator end = frameOffsets.end(); |
625 |
std::list<unsigned long>::iterator iter = frameOffsets.begin(); |
std::list<file_offset_t>::iterator iter = frameOffsets.begin(); |
626 |
for (int i = 0; iter != end; i++, iter++) { |
for (int i = 0; iter != end; i++, iter++) { |
627 |
FrameTable[i] = *iter; |
FrameTable[i] = *iter; |
628 |
} |
} |
663 |
* the cached sample data in bytes |
* the cached sample data in bytes |
664 |
* @see ReleaseSampleData(), Read(), SetPos() |
* @see ReleaseSampleData(), Read(), SetPos() |
665 |
*/ |
*/ |
666 |
buffer_t Sample::LoadSampleData(unsigned long SampleCount) { |
buffer_t Sample::LoadSampleData(file_offset_t SampleCount) { |
667 |
return LoadSampleDataWithNullSamplesExtension(SampleCount, 0); // 0 amount of NullSamples |
return LoadSampleDataWithNullSamplesExtension(SampleCount, 0); // 0 amount of NullSamples |
668 |
} |
} |
669 |
|
|
722 |
* size of the cached sample data in bytes |
* size of the cached sample data in bytes |
723 |
* @see ReleaseSampleData(), Read(), SetPos() |
* @see ReleaseSampleData(), Read(), SetPos() |
724 |
*/ |
*/ |
725 |
buffer_t Sample::LoadSampleDataWithNullSamplesExtension(unsigned long SampleCount, uint NullSamplesCount) { |
buffer_t Sample::LoadSampleDataWithNullSamplesExtension(file_offset_t SampleCount, uint NullSamplesCount) { |
726 |
if (SampleCount > this->SamplesTotal) SampleCount = this->SamplesTotal; |
if (SampleCount > this->SamplesTotal) SampleCount = this->SamplesTotal; |
727 |
if (RAMCache.pStart) delete[] (int8_t*) RAMCache.pStart; |
if (RAMCache.pStart) delete[] (int8_t*) RAMCache.pStart; |
728 |
unsigned long allocationsize = (SampleCount + NullSamplesCount) * this->FrameSize; |
file_offset_t allocationsize = (SampleCount + NullSamplesCount) * this->FrameSize; |
729 |
SetPos(0); // reset read position to begin of sample |
SetPos(0); // reset read position to begin of sample |
730 |
RAMCache.pStart = new int8_t[allocationsize]; |
RAMCache.pStart = new int8_t[allocationsize]; |
731 |
RAMCache.Size = Read(RAMCache.pStart, SampleCount) * this->FrameSize; |
RAMCache.Size = Read(RAMCache.pStart, SampleCount) * this->FrameSize; |
789 |
* FormatTag must be DLS_WAVE_FORMAT_PCM. Trying to resize samples with |
* FormatTag must be DLS_WAVE_FORMAT_PCM. Trying to resize samples with |
790 |
* other formats will fail! |
* other formats will fail! |
791 |
* |
* |
792 |
* @param iNewSize - new sample wave data size in sample points (must be |
* @param NewSize - new sample wave data size in sample points (must be |
793 |
* greater than zero) |
* greater than zero) |
794 |
* @throws DLS::Excecption if FormatTag != DLS_WAVE_FORMAT_PCM |
* @throws DLS::Excecption if FormatTag != DLS_WAVE_FORMAT_PCM |
795 |
* or if \a iNewSize is less than 1 |
* @throws DLS::Exception if \a NewSize is less than 1 or unrealistic large |
796 |
* @throws gig::Exception if existing sample is compressed |
* @throws gig::Exception if existing sample is compressed |
797 |
* @see DLS::Sample::GetSize(), DLS::Sample::FrameSize, |
* @see DLS::Sample::GetSize(), DLS::Sample::FrameSize, |
798 |
* DLS::Sample::FormatTag, File::Save() |
* DLS::Sample::FormatTag, File::Save() |
799 |
*/ |
*/ |
800 |
void Sample::Resize(int iNewSize) { |
void Sample::Resize(file_offset_t NewSize) { |
801 |
if (Compressed) throw gig::Exception("There is no support for modifying compressed samples (yet)"); |
if (Compressed) throw gig::Exception("There is no support for modifying compressed samples (yet)"); |
802 |
DLS::Sample::Resize(iNewSize); |
DLS::Sample::Resize(NewSize); |
803 |
} |
} |
804 |
|
|
805 |
/** |
/** |
823 |
* @returns the new sample position |
* @returns the new sample position |
824 |
* @see Read() |
* @see Read() |
825 |
*/ |
*/ |
826 |
unsigned long Sample::SetPos(unsigned long SampleCount, RIFF::stream_whence_t Whence) { |
file_offset_t Sample::SetPos(file_offset_t SampleCount, RIFF::stream_whence_t Whence) { |
827 |
if (Compressed) { |
if (Compressed) { |
828 |
switch (Whence) { |
switch (Whence) { |
829 |
case RIFF::stream_curpos: |
case RIFF::stream_curpos: |
841 |
} |
} |
842 |
if (this->SamplePos > this->SamplesTotal) this->SamplePos = this->SamplesTotal; |
if (this->SamplePos > this->SamplesTotal) this->SamplePos = this->SamplesTotal; |
843 |
|
|
844 |
unsigned long frame = this->SamplePos / 2048; // to which frame to jump |
file_offset_t frame = this->SamplePos / 2048; // to which frame to jump |
845 |
this->FrameOffset = this->SamplePos % 2048; // offset (in sample points) within that frame |
this->FrameOffset = this->SamplePos % 2048; // offset (in sample points) within that frame |
846 |
pCkData->SetPos(FrameTable[frame]); // set chunk pointer to the start of sought frame |
pCkData->SetPos(FrameTable[frame]); // set chunk pointer to the start of sought frame |
847 |
return this->SamplePos; |
return this->SamplePos; |
848 |
} |
} |
849 |
else { // not compressed |
else { // not compressed |
850 |
unsigned long orderedBytes = SampleCount * this->FrameSize; |
file_offset_t orderedBytes = SampleCount * this->FrameSize; |
851 |
unsigned long result = pCkData->SetPos(orderedBytes, Whence); |
file_offset_t result = pCkData->SetPos(orderedBytes, Whence); |
852 |
return (result == orderedBytes) ? SampleCount |
return (result == orderedBytes) ? SampleCount |
853 |
: result / this->FrameSize; |
: result / this->FrameSize; |
854 |
} |
} |
857 |
/** |
/** |
858 |
* Returns the current position in the sample (in sample points). |
* Returns the current position in the sample (in sample points). |
859 |
*/ |
*/ |
860 |
unsigned long Sample::GetPos() const { |
file_offset_t Sample::GetPos() const { |
861 |
if (Compressed) return SamplePos; |
if (Compressed) return SamplePos; |
862 |
else return pCkData->GetPos() / FrameSize; |
else return pCkData->GetPos() / FrameSize; |
863 |
} |
} |
896 |
* @returns number of successfully read sample points |
* @returns number of successfully read sample points |
897 |
* @see CreateDecompressionBuffer() |
* @see CreateDecompressionBuffer() |
898 |
*/ |
*/ |
899 |
unsigned long Sample::ReadAndLoop(void* pBuffer, unsigned long SampleCount, playback_state_t* pPlaybackState, |
file_offset_t Sample::ReadAndLoop(void* pBuffer, file_offset_t SampleCount, playback_state_t* pPlaybackState, |
900 |
DimensionRegion* pDimRgn, buffer_t* pExternalDecompressionBuffer) { |
DimensionRegion* pDimRgn, buffer_t* pExternalDecompressionBuffer) { |
901 |
unsigned long samplestoread = SampleCount, totalreadsamples = 0, readsamples, samplestoloopend; |
file_offset_t samplestoread = SampleCount, totalreadsamples = 0, readsamples, samplestoloopend; |
902 |
uint8_t* pDst = (uint8_t*) pBuffer; |
uint8_t* pDst = (uint8_t*) pBuffer; |
903 |
|
|
904 |
SetPos(pPlaybackState->position); // recover position from the last time |
SetPos(pPlaybackState->position); // recover position from the last time |
936 |
// reading, swap all sample frames so it reflects |
// reading, swap all sample frames so it reflects |
937 |
// backward playback |
// backward playback |
938 |
|
|
939 |
unsigned long swapareastart = totalreadsamples; |
file_offset_t swapareastart = totalreadsamples; |
940 |
unsigned long loopoffset = GetPos() - loop.LoopStart; |
file_offset_t loopoffset = GetPos() - loop.LoopStart; |
941 |
unsigned long samplestoreadinloop = Min(samplestoread, loopoffset); |
file_offset_t samplestoreadinloop = Min(samplestoread, loopoffset); |
942 |
unsigned long reverseplaybackend = GetPos() - samplestoreadinloop; |
file_offset_t reverseplaybackend = GetPos() - samplestoreadinloop; |
943 |
|
|
944 |
SetPos(reverseplaybackend); |
SetPos(reverseplaybackend); |
945 |
|
|
987 |
// reading, swap all sample frames so it reflects |
// reading, swap all sample frames so it reflects |
988 |
// backward playback |
// backward playback |
989 |
|
|
990 |
unsigned long swapareastart = totalreadsamples; |
file_offset_t swapareastart = totalreadsamples; |
991 |
unsigned long loopoffset = GetPos() - loop.LoopStart; |
file_offset_t loopoffset = GetPos() - loop.LoopStart; |
992 |
unsigned long samplestoreadinloop = (this->LoopPlayCount) ? Min(samplestoread, pPlaybackState->loop_cycles_left * loop.LoopLength - loopoffset) |
file_offset_t samplestoreadinloop = (this->LoopPlayCount) ? Min(samplestoread, pPlaybackState->loop_cycles_left * loop.LoopLength - loopoffset) |
993 |
: samplestoread; |
: samplestoread; |
994 |
unsigned long reverseplaybackend = loop.LoopStart + Abs((loopoffset - samplestoreadinloop) % loop.LoopLength); |
file_offset_t reverseplaybackend = loop.LoopStart + Abs((loopoffset - samplestoreadinloop) % loop.LoopLength); |
995 |
|
|
996 |
SetPos(reverseplaybackend); |
SetPos(reverseplaybackend); |
997 |
|
|
1071 |
* @returns number of successfully read sample points |
* @returns number of successfully read sample points |
1072 |
* @see SetPos(), CreateDecompressionBuffer() |
* @see SetPos(), CreateDecompressionBuffer() |
1073 |
*/ |
*/ |
1074 |
unsigned long Sample::Read(void* pBuffer, unsigned long SampleCount, buffer_t* pExternalDecompressionBuffer) { |
file_offset_t Sample::Read(void* pBuffer, file_offset_t SampleCount, buffer_t* pExternalDecompressionBuffer) { |
1075 |
if (SampleCount == 0) return 0; |
if (SampleCount == 0) return 0; |
1076 |
if (!Compressed) { |
if (!Compressed) { |
1077 |
if (BitDepth == 24) { |
if (BitDepth == 24) { |
1086 |
else { |
else { |
1087 |
if (this->SamplePos >= this->SamplesTotal) return 0; |
if (this->SamplePos >= this->SamplesTotal) return 0; |
1088 |
//TODO: efficiency: maybe we should test for an average compression rate |
//TODO: efficiency: maybe we should test for an average compression rate |
1089 |
unsigned long assumedsize = GuessSize(SampleCount), |
file_offset_t assumedsize = GuessSize(SampleCount), |
1090 |
remainingbytes = 0, // remaining bytes in the local buffer |
remainingbytes = 0, // remaining bytes in the local buffer |
1091 |
remainingsamples = SampleCount, |
remainingsamples = SampleCount, |
1092 |
copysamples, skipsamples, |
copysamples, skipsamples, |
1109 |
remainingbytes = pCkData->Read(pSrc, assumedsize, 1); |
remainingbytes = pCkData->Read(pSrc, assumedsize, 1); |
1110 |
|
|
1111 |
while (remainingsamples && remainingbytes) { |
while (remainingsamples && remainingbytes) { |
1112 |
unsigned long framesamples = SamplesPerFrame; |
file_offset_t framesamples = SamplesPerFrame; |
1113 |
unsigned long framebytes, rightChannelOffset = 0, nextFrameOffset; |
file_offset_t framebytes, rightChannelOffset = 0, nextFrameOffset; |
1114 |
|
|
1115 |
int mode_l = *pSrc++, mode_r = 0; |
int mode_l = *pSrc++, mode_r = 0; |
1116 |
|
|
1260 |
* @throws gig::Exception if sample is compressed |
* @throws gig::Exception if sample is compressed |
1261 |
* @see DLS::LoadSampleData() |
* @see DLS::LoadSampleData() |
1262 |
*/ |
*/ |
1263 |
unsigned long Sample::Write(void* pBuffer, unsigned long SampleCount) { |
file_offset_t Sample::Write(void* pBuffer, file_offset_t SampleCount) { |
1264 |
if (Compressed) throw gig::Exception("There is no support for writing compressed gig samples (yet)"); |
if (Compressed) throw gig::Exception("There is no support for writing compressed gig samples (yet)"); |
1265 |
|
|
1266 |
// if this is the first write in this sample, reset the |
// if this is the first write in this sample, reset the |
1269 |
__resetCRC(crc); |
__resetCRC(crc); |
1270 |
} |
} |
1271 |
if (GetSize() < SampleCount) throw Exception("Could not write sample data, current sample size to small"); |
if (GetSize() < SampleCount) throw Exception("Could not write sample data, current sample size to small"); |
1272 |
unsigned long res; |
file_offset_t res; |
1273 |
if (BitDepth == 24) { |
if (BitDepth == 24) { |
1274 |
res = pCkData->Write(pBuffer, SampleCount * FrameSize, 1) / FrameSize; |
res = pCkData->Write(pBuffer, SampleCount * FrameSize, 1) / FrameSize; |
1275 |
} else { // 16 bit |
} else { // 16 bit |
1303 |
* @returns allocated decompression buffer |
* @returns allocated decompression buffer |
1304 |
* @see DestroyDecompressionBuffer() |
* @see DestroyDecompressionBuffer() |
1305 |
*/ |
*/ |
1306 |
buffer_t Sample::CreateDecompressionBuffer(unsigned long MaxReadSize) { |
buffer_t Sample::CreateDecompressionBuffer(file_offset_t MaxReadSize) { |
1307 |
buffer_t result; |
buffer_t result; |
1308 |
const double worstCaseHeaderOverhead = |
const double worstCaseHeaderOverhead = |
1309 |
(256.0 /*frame size*/ + 12.0 /*header*/ + 2.0 /*compression type flag (stereo)*/) / 256.0; |
(256.0 /*frame size*/ + 12.0 /*header*/ + 2.0 /*compression type flag (stereo)*/) / 256.0; |
1310 |
result.Size = (unsigned long) (double(MaxReadSize) * 3.0 /*(24 Bit)*/ * 2.0 /*stereo*/ * worstCaseHeaderOverhead); |
result.Size = (file_offset_t) (double(MaxReadSize) * 3.0 /*(24 Bit)*/ * 2.0 /*stereo*/ * worstCaseHeaderOverhead); |
1311 |
result.pStart = new int8_t[result.Size]; |
result.pStart = new int8_t[result.Size]; |
1312 |
result.NullExtensionSize = 0; |
result.NullExtensionSize = 0; |
1313 |
return result; |
return result; |
1357 |
// *************** DimensionRegion *************** |
// *************** DimensionRegion *************** |
1358 |
// * |
// * |
1359 |
|
|
1360 |
uint DimensionRegion::Instances = 0; |
size_t DimensionRegion::Instances = 0; |
1361 |
DimensionRegion::VelocityTableMap* DimensionRegion::pVelocityTables = NULL; |
DimensionRegion::VelocityTableMap* DimensionRegion::pVelocityTables = NULL; |
1362 |
|
|
1363 |
DimensionRegion::DimensionRegion(Region* pParent, RIFF::List* _3ewl) : DLS::Sampler(_3ewl) { |
DimensionRegion::DimensionRegion(Region* pParent, RIFF::List* _3ewl) : DLS::Sampler(_3ewl) { |
3850 |
if ((int32_t)WavePoolTableIndex == -1) return NULL; |
if ((int32_t)WavePoolTableIndex == -1) return NULL; |
3851 |
File* file = (File*) GetParent()->GetParent(); |
File* file = (File*) GetParent()->GetParent(); |
3852 |
if (!file->pWavePoolTable) return NULL; |
if (!file->pWavePoolTable) return NULL; |
3853 |
unsigned long soughtoffset = file->pWavePoolTable[WavePoolTableIndex]; |
// for new files or files >= 2 GB use 64 bit wave pool offsets |
3854 |
unsigned long soughtfileno = file->pWavePoolTableHi[WavePoolTableIndex]; |
if (file->pRIFF->IsNew() || (file->pRIFF->GetCurrentFileSize() >> 31)) { |
3855 |
Sample* sample = file->GetFirstSample(pProgress); |
// use 64 bit wave pool offsets (treating this as large file) |
3856 |
while (sample) { |
uint64_t soughtoffset = |
3857 |
if (sample->ulWavePoolOffset == soughtoffset && |
uint64_t(file->pWavePoolTable[WavePoolTableIndex]) | |
3858 |
sample->FileNo == soughtfileno) return static_cast<gig::Sample*>(sample); |
uint64_t(file->pWavePoolTableHi[WavePoolTableIndex]) << 32; |
3859 |
sample = file->GetNextSample(); |
Sample* sample = file->GetFirstSample(pProgress); |
3860 |
|
while (sample) { |
3861 |
|
if (sample->ullWavePoolOffset == soughtoffset) |
3862 |
|
return static_cast<gig::Sample*>(sample); |
3863 |
|
sample = file->GetNextSample(); |
3864 |
|
} |
3865 |
|
} else { |
3866 |
|
// use extension files and 32 bit wave pool offsets |
3867 |
|
file_offset_t soughtoffset = file->pWavePoolTable[WavePoolTableIndex]; |
3868 |
|
file_offset_t soughtfileno = file->pWavePoolTableHi[WavePoolTableIndex]; |
3869 |
|
Sample* sample = file->GetFirstSample(pProgress); |
3870 |
|
while (sample) { |
3871 |
|
if (sample->ullWavePoolOffset == soughtoffset && |
3872 |
|
sample->FileNo == soughtfileno) return static_cast<gig::Sample*>(sample); |
3873 |
|
sample = file->GetNextSample(); |
3874 |
|
} |
3875 |
} |
} |
3876 |
return NULL; |
return NULL; |
3877 |
} |
} |
4580 |
uint32_t fileOffset = |
uint32_t fileOffset = |
4581 |
(*pScriptRefs)[i].script->pChunk->GetFilePos() - |
(*pScriptRefs)[i].script->pChunk->GetFilePos() - |
4582 |
(*pScriptRefs)[i].script->pChunk->GetPos() - |
(*pScriptRefs)[i].script->pChunk->GetPos() - |
4583 |
CHUNK_HEADER_SIZE; |
CHUNK_HEADER_SIZE(ckSCSL->GetFile()->GetFileOffsetSize()); |
4584 |
ckSCSL->WriteUint32(&fileOffset); |
ckSCSL->WriteUint32(&fileOffset); |
4585 |
// jump over flags entry (containing the bypass flag) |
// jump over flags entry (containing the bypass flag) |
4586 |
ckSCSL->SetPos(sizeof(uint32_t), RIFF::stream_curpos); |
ckSCSL->SetPos(sizeof(uint32_t), RIFF::stream_curpos); |
4788 |
if (script->pChunk) { |
if (script->pChunk) { |
4789 |
uint32_t offset = script->pChunk->GetFilePos() - |
uint32_t offset = script->pChunk->GetFilePos() - |
4790 |
script->pChunk->GetPos() - |
script->pChunk->GetPos() - |
4791 |
CHUNK_HEADER_SIZE; |
CHUNK_HEADER_SIZE(script->pChunk->GetFile()->GetFileOffsetSize()); |
4792 |
if (offset == soughtOffset) |
if (offset == soughtOffset) |
4793 |
{ |
{ |
4794 |
_ScriptPooolRef ref; |
_ScriptPooolRef ref; |
5351 |
int iTotalSamples = WavePoolCount; |
int iTotalSamples = WavePoolCount; |
5352 |
|
|
5353 |
// check if samples should be loaded from extension files |
// check if samples should be loaded from extension files |
5354 |
|
// (only for old gig files < 2 GB) |
5355 |
int lastFileNo = 0; |
int lastFileNo = 0; |
5356 |
for (int i = 0 ; i < WavePoolCount ; i++) { |
if (!file->IsNew() && !(file->GetCurrentFileSize() >> 31)) { |
5357 |
if (pWavePoolTableHi[i] > lastFileNo) lastFileNo = pWavePoolTableHi[i]; |
for (int i = 0 ; i < WavePoolCount ; i++) { |
5358 |
|
if (pWavePoolTableHi[i] > lastFileNo) lastFileNo = pWavePoolTableHi[i]; |
5359 |
|
} |
5360 |
} |
} |
5361 |
String name(pRIFF->GetFileName()); |
String name(pRIFF->GetFileName()); |
5362 |
int nameLen = name.length(); |
int nameLen = name.length(); |
5366 |
for (int fileNo = 0 ; ; ) { |
for (int fileNo = 0 ; ; ) { |
5367 |
RIFF::List* wvpl = file->GetSubList(LIST_TYPE_WVPL); |
RIFF::List* wvpl = file->GetSubList(LIST_TYPE_WVPL); |
5368 |
if (wvpl) { |
if (wvpl) { |
5369 |
unsigned long wvplFileOffset = wvpl->GetFilePos(); |
file_offset_t wvplFileOffset = wvpl->GetFilePos(); |
5370 |
RIFF::List* wave = wvpl->GetFirstSubList(); |
RIFF::List* wave = wvpl->GetFirstSubList(); |
5371 |
while (wave) { |
while (wave) { |
5372 |
if (wave->GetListType() == LIST_TYPE_WAVE) { |
if (wave->GetListType() == LIST_TYPE_WAVE) { |
5374 |
const float subprogress = (float) iSampleIndex / (float) iTotalSamples; |
const float subprogress = (float) iSampleIndex / (float) iTotalSamples; |
5375 |
__notify_progress(pProgress, subprogress); |
__notify_progress(pProgress, subprogress); |
5376 |
|
|
5377 |
unsigned long waveFileOffset = wave->GetFilePos(); |
file_offset_t waveFileOffset = wave->GetFilePos(); |
5378 |
pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset, fileNo)); |
pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset, fileNo)); |
5379 |
|
|
5380 |
iSampleIndex++; |
iSampleIndex++; |
5859 |
void File::UpdateChunks(progress_t* pProgress) { |
void File::UpdateChunks(progress_t* pProgress) { |
5860 |
bool newFile = pRIFF->GetSubList(LIST_TYPE_INFO) == NULL; |
bool newFile = pRIFF->GetSubList(LIST_TYPE_INFO) == NULL; |
5861 |
|
|
|
b64BitWavePoolOffsets = pVersion && pVersion->major == 3; |
|
|
|
|
5862 |
// update own gig format extension chunks |
// update own gig format extension chunks |
5863 |
// (not part of the GigaStudio 4 format) |
// (not part of the GigaStudio 4 format) |
5864 |
// |
RIFF::List* lst3LS = pRIFF->GetSubList(LIST_TYPE_3LS); |
5865 |
|
if (!lst3LS) { |
5866 |
|
lst3LS = pRIFF->AddSubList(LIST_TYPE_3LS); |
5867 |
|
} |
5868 |
|
// Make sure <3LS > chunk is placed before <ptbl> chunk. The precise |
5869 |
|
// location of <3LS > is irrelevant, however it should be located |
5870 |
|
// before the actual wave data |
5871 |
|
RIFF::Chunk* ckPTBL = pRIFF->GetSubChunk(CHUNK_ID_PTBL); |
5872 |
|
pRIFF->MoveSubChunk(lst3LS, ckPTBL); |
5873 |
|
|
5874 |
// This must be performed before writing the chunks for instruments, |
// This must be performed before writing the chunks for instruments, |
5875 |
// because the instruments' script slots will write the file offsets |
// because the instruments' script slots will write the file offsets |
5876 |
// of the respective instrument script chunk as reference. |
// of the respective instrument script chunk as reference. |
5877 |
if (pScriptGroups) { |
if (pScriptGroups) { |
5878 |
RIFF::List* lst3LS = pRIFF->GetSubList(LIST_TYPE_3LS); |
// Update instrument script (group) chunks. |
5879 |
if (pScriptGroups->empty()) { |
for (std::list<ScriptGroup*>::iterator it = pScriptGroups->begin(); |
5880 |
if (lst3LS) pRIFF->DeleteSubChunk(lst3LS); |
it != pScriptGroups->end(); ++it) |
5881 |
} else { |
{ |
5882 |
if (!lst3LS) lst3LS = pRIFF->AddSubList(LIST_TYPE_3LS); |
(*it)->UpdateChunks(pProgress); |
|
|
|
|
// Update instrument script (group) chunks. |
|
|
|
|
|
for (std::list<ScriptGroup*>::iterator it = pScriptGroups->begin(); |
|
|
it != pScriptGroups->end(); ++it) |
|
|
{ |
|
|
(*it)->UpdateChunks(pProgress); |
|
|
} |
|
5883 |
} |
} |
5884 |
} |
} |
5885 |
|
|
5886 |
|
// in case no libgig custom format data was added, then remove the |
5887 |
|
// custom "3LS " chunk again |
5888 |
|
if (!lst3LS->CountSubChunks()) { |
5889 |
|
pRIFF->DeleteSubChunk(lst3LS); |
5890 |
|
lst3LS = NULL; |
5891 |
|
} |
5892 |
|
|
5893 |
// first update base class's chunks |
// first update base class's chunks |
5894 |
DLS::File::UpdateChunks(pProgress); |
DLS::File::UpdateChunks(pProgress); |
5895 |
|
|