libgig
4.0.0
|
.KSF audio sample file More...
#include <Korg.h>
Public Member Functions | |
KSFSample (const String &filename) | |
virtual | ~KSFSample () |
int | FrameSize () const |
Returns the size of one sample point of this sample in bytes. More... | |
bool | IsCompressed () const |
uint8_t | CompressionID () const |
bool | Use2ndStart () const |
String | FileName () const |
buffer_t | GetCache () const |
Returns current cached sample points. More... | |
buffer_t | LoadSampleData () |
Loads the whole sample wave into RAM. More... | |
buffer_t | LoadSampleData (unsigned long SampleCount) |
Reads and caches the first SampleCount numbers of SamplePoints in RAM. More... | |
buffer_t | LoadSampleDataWithNullSamplesExtension (uint NullSamplesCount) |
Loads the whole sample wave into RAM. More... | |
buffer_t | LoadSampleDataWithNullSamplesExtension (unsigned long SampleCount, uint NullSamplesCount) |
Reads and caches the first SampleCount numbers of SamplePoints in RAM. More... | |
void | ReleaseSampleData () |
Frees the cached sample from RAM if loaded with LoadSampleData() previously. More... | |
unsigned long | SetPos (unsigned long SampleCount, RIFF::stream_whence_t Whence=RIFF::stream_start) |
Sets the position within the sample (in sample points, not in bytes). More... | |
unsigned long | GetPos () const |
Returns the current position in the sample (in sample points). More... | |
unsigned long | Read (void *pBuffer, unsigned long SampleCount) |
Reads SampleCount number of sample points from the current position into the buffer pointed by pBuffer and increments the position within the sample. More... | |
Public Attributes | |
String | Name |
Sample name for drums (since this name is always stored with 16 bytes, this name must never be longer than 16 characters). More... | |
uint8_t | DefaultBank |
0..3 More... | |
uint32_t | Start |
uint32_t | Start2 |
uint32_t | LoopStart |
uint32_t | LoopEnd |
uint32_t | SampleRate |
i.e. 44100 More... | |
uint8_t | Attributes |
Bit field of flags, better call IsCompressed(), CompressionID() and Use2ndStart() instead of accessing this variable directly. More... | |
int8_t | LoopTune |
-99..+99 More... | |
uint8_t | Channels |
Number of audio channels (seems to be always 1, thus Mono for all Korg sound files ATM). More... | |
uint8_t | BitDepth |
i.e. 8 or 16 More... | |
uint32_t | SamplePoints |
Currently the library expects all Korg samples to be Mono, thus the value here might be incorrect in case you ever find a Korg sample in Stereo. If you got a Stereo one, please report it! More... | |
.KSF audio sample file
Implements access to KORG audio sample files with ".KSF" file name extension. As of to date, there are only mono samples in .KSF format. If you ever encounter a stereo sample, please report it!
Korg::KSFSample::KSFSample | ( | const String & | filename | ) |
Definition at line 90 of file Korg.cpp.
References Attributes, BitDepth, Channels, CHUNK_ID_SMD1, CHUNK_ID_SMP1, DefaultBank, RIFF::endian_big, RIFF::Chunk::GetSize(), RIFF::List::GetSubChunk(), RIFF::layout_flat, LoopEnd, LoopStart, LoopTune, Name, gig::buffer_t::NullExtensionSize, gig::buffer_t::pStart, RIFF::Chunk::ReadInt8(), Korg::readText16(), RIFF::Chunk::ReadUint32(), RIFF::Chunk::ReadUint8(), SamplePoints, SampleRate, gig::buffer_t::Size, Start, and Start2.
|
virtual |
Definition at line 126 of file Korg.cpp.
References gig::buffer_t::pStart.
uint8_t Korg::KSFSample::CompressionID | ( | ) | const |
Definition at line 321 of file Korg.cpp.
References Attributes.
String Korg::KSFSample::FileName | ( | ) | const |
Definition at line 333 of file Korg.cpp.
References RIFF::File::GetFileName().
int Korg::KSFSample::FrameSize | ( | ) | const |
buffer_t Korg::KSFSample::GetCache | ( | ) | const |
Returns current cached sample points.
A buffer_t structure will be returned which contains address pointer to the begin of the cache and the size of the cached sample data in bytes. Use LoadSampleData() to cache a specific amount of sample points in RAM.
Definition at line 219 of file Korg.cpp.
References gig::buffer_t::NullExtensionSize, gig::buffer_t::pStart, and gig::buffer_t::Size.
Referenced by LoadSampleDataWithNullSamplesExtension().
unsigned long Korg::KSFSample::GetPos | ( | ) | const |
Returns the current position in the sample (in sample points).
Definition at line 279 of file Korg.cpp.
References CHUNK_ID_SMD1, FrameSize(), RIFF::Chunk::GetPos(), RIFF::List::GetSubChunk(), and SMD1_CHUNK_HEADER_SZ.
Referenced by SetPos().
bool Korg::KSFSample::IsCompressed | ( | ) | const |
Definition at line 325 of file Korg.cpp.
References Attributes.
buffer_t Korg::KSFSample::LoadSampleData | ( | ) |
Loads the whole sample wave into RAM.
Use ReleaseSampleData() to free the memory if you don't need the cached sample data anymore.
Definition at line 139 of file Korg.cpp.
References LoadSampleDataWithNullSamplesExtension(), and SamplePoints.
buffer_t Korg::KSFSample::LoadSampleData | ( | unsigned long | SampleCount | ) |
Reads and caches the first SampleCount numbers of SamplePoints in RAM.
Use ReleaseSampleData() to free the memory space if you don't need the cached samples anymore.
SampleCount | - number of sample points to load into RAM |
Definition at line 153 of file Korg.cpp.
References LoadSampleDataWithNullSamplesExtension().
buffer_t Korg::KSFSample::LoadSampleDataWithNullSamplesExtension | ( | uint | NullSamplesCount | ) |
Loads the whole sample wave into RAM.
Use ReleaseSampleData() to free the memory if you don't need the cached sample data anymore. The method will add NullSamplesCount silence samples past the official buffer end (this won't affect the 'Size' member of the buffer_t structure, that means 'Size' always reflects the size of the actual sample data, the buffer might be bigger though). Silence samples past the official buffer are needed for differential algorithms that always have to take subsequent samples into account (resampling/interpolation would be an important example) and avoids memory access faults in such cases.
NullSamplesCount | - number of silence samples the buffer should be extended past it's data end |
Definition at line 174 of file Korg.cpp.
References SamplePoints.
Referenced by LoadSampleData().
buffer_t Korg::KSFSample::LoadSampleDataWithNullSamplesExtension | ( | unsigned long | SampleCount, |
uint | NullSamplesCount | ||
) |
Reads and caches the first SampleCount numbers of SamplePoints in RAM.
Use ReleaseSampleData() to free the memory space if you don't need the cached samples anymore. The method will add NullSamplesCount silence samples past the official buffer end (this won't affect the 'Size' member of the buffer_t structure, that means 'Size' always reflects the size of the actual sample data, the buffer might be bigger though). Silence samples past the official buffer are needed for differential algorithms that always have to take subsequent samples into account (resampling/interpolation would be an important example) and avoids memory access faults in such cases.
SampleCount | - number of sample points to load into RAM |
NullSamplesCount | - number of silence samples the buffer should be extended past it's data end |
Definition at line 197 of file Korg.cpp.
References FrameSize(), GetCache(), gig::buffer_t::NullExtensionSize, gig::buffer_t::pStart, Read(), SamplePoints, SetPos(), and gig::buffer_t::Size.
unsigned long Korg::KSFSample::Read | ( | void * | pBuffer, |
unsigned long | SampleCount | ||
) |
Reads SampleCount number of sample points from the current position into the buffer pointed by pBuffer and increments the position within the sample.
Use this method and SetPos() if you don't want to load the sample into RAM, thus for disk streaming.
Caution: If you are using more than one streaming thread, you have to use an external decompression buffer for EACH streaming thread to avoid race conditions and crashes (which is not implemented for this class yet)!
pBuffer | destination buffer |
SampleCount | number of sample points to read |
Definition at line 300 of file Korg.cpp.
References CHUNK_ID_SMD1, FrameSize(), RIFF::List::GetSubChunk(), and RIFF::Chunk::Read().
Referenced by LoadSampleDataWithNullSamplesExtension().
void Korg::KSFSample::ReleaseSampleData | ( | ) |
Frees the cached sample from RAM if loaded with LoadSampleData() previously.
Definition at line 234 of file Korg.cpp.
References gig::buffer_t::NullExtensionSize, gig::buffer_t::pStart, and gig::buffer_t::Size.
unsigned long Korg::KSFSample::SetPos | ( | unsigned long | SampleCount, |
RIFF::stream_whence_t | Whence = RIFF::stream_start |
||
) |
Sets the position within the sample (in sample points, not in bytes).
Use this method and Read() if you don't want to load the sample into RAM, thus for disk streaming.
SampleCount | number of sample points to jump |
Whence | optional: to which relation SampleCount refers to, if omited RIFF::stream_start is assumed |
Definition at line 252 of file Korg.cpp.
References CHUNK_ID_SMD1, FrameSize(), GetPos(), RIFF::List::GetSubChunk(), SamplePoints, RIFF::Chunk::SetPos(), SMD1_CHUNK_HEADER_SZ, RIFF::stream_backward, RIFF::stream_curpos, RIFF::stream_end, and RIFF::stream_start.
Referenced by LoadSampleDataWithNullSamplesExtension().
bool Korg::KSFSample::Use2ndStart | ( | ) | const |
Definition at line 329 of file Korg.cpp.
References Attributes.
uint8_t Korg::KSFSample::Attributes |
Bit field of flags, better call IsCompressed(), CompressionID() and Use2ndStart() instead of accessing this variable directly.
Definition at line 99 of file Korg.h.
Referenced by CompressionID(), IsCompressed(), KSFSample(), and Use2ndStart().
uint8_t Korg::KSFSample::BitDepth |
uint8_t Korg::KSFSample::Channels |
Number of audio channels (seems to be always 1, thus Mono for all Korg sound files ATM).
Definition at line 101 of file Korg.h.
Referenced by FrameSize(), and KSFSample().
uint8_t Korg::KSFSample::DefaultBank |
uint32_t Korg::KSFSample::LoopEnd |
Definition at line 97 of file Korg.h.
Referenced by KSFSample().
uint32_t Korg::KSFSample::LoopStart |
Definition at line 96 of file Korg.h.
Referenced by KSFSample().
int8_t Korg::KSFSample::LoopTune |
String Korg::KSFSample::Name |
Sample name for drums (since this name is always stored with 16 bytes, this name must never be longer than 16 characters).
Definition at line 92 of file Korg.h.
Referenced by KSFSample().
uint32_t Korg::KSFSample::SamplePoints |
Currently the library expects all Korg samples to be Mono, thus the value here might be incorrect in case you ever find a Korg sample in Stereo. If you got a Stereo one, please report it!
Definition at line 103 of file Korg.h.
Referenced by KSFSample(), LoadSampleData(), LoadSampleDataWithNullSamplesExtension(), and SetPos().
uint32_t Korg::KSFSample::SampleRate |
uint32_t Korg::KSFSample::Start |
Definition at line 94 of file Korg.h.
Referenced by KSFSample().
uint32_t Korg::KSFSample::Start2 |
Definition at line 95 of file Korg.h.
Referenced by KSFSample().