Korg::KSFSample Class Reference

.KSF audio sample file More...

`#include <Korg.h>`

## Public Member Functions

| KSFSample (const String &filename)
int | FrameSize () const
| Returns the size of one sample point of this sample in bytes.
bool | IsCompressed () const
uint8_t | CompressionID () const
bool | Use2ndStart () const
String | FileName () const
buffer_t | GetCache () const
| Returns current cached sample points.
buffer_t | LoadSampleData ()
| Loads the whole sample wave into RAM.
buffer_t | LoadSampleData (unsigned long SampleCount)
| Reads and caches the first SampleCount numbers of SamplePoints in RAM.
buffer_t | LoadSampleDataWithNullSamplesExtension (uint NullSamplesCount)
| Loads the whole sample wave into RAM.
buffer_t | LoadSampleDataWithNullSamplesExtension (unsigned long SampleCount, uint NullSamplesCount)
| Reads and caches the first SampleCount numbers of SamplePoints in RAM.
void | ReleaseSampleData ()
| Frees the cached sample from RAM if loaded with LoadSampleData() previously.
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).
unsigned long | GetPos () const
| Returns the current position in the sample (in sample points).
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.

## 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).
uint8_t | DefaultBank
| 0..3
uint32_t | Start
uint32_t | Start2
uint32_t | LoopStart
uint32_t | LoopEnd
uint32_t | SampleRate
| i.e. 44100
uint8_t | Attributes
| Bit field of flags, better call IsCompressed(), CompressionID() and Use2ndStart() instead of accessing this variable directly.
int8_t | LoopTune
| -99..+99
uint8_t | Channels
| Number of audio channels (seems to be always 1, thus Mono for all Korg sound files ATM).
uint8_t | BitDepth
| i.e. 8 or 16
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!

## Detailed Description

.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!

Definition at line 90 of file Korg.h.

## Constructor & Destructor Documentation

## KSFSample()

Korg::KSFSample::KSFSample | ( | const String & | filename | ) |

Definition at line 90 of file Korg.cpp.

## ~KSFSample()

Korg::KSFSample::~KSFSample | ( |  | ) |

virtual

Definition at line 126 of file Korg.cpp.

## Member Function Documentation

## CompressionID()

uint8_t Korg::KSFSample::CompressionID | ( |  | ) | const

Definition at line 321 of file Korg.cpp.

## FileName()

String Korg::KSFSample::FileName | ( |  | ) | const

Definition at line 333 of file Korg.cpp.

## FrameSize()

int Korg::KSFSample::FrameSize | ( |  | ) | const

Returns the size of one sample point of this sample in bytes.

Definition at line 317 of file Korg.cpp.

References BitDepth, and Channels.

Referenced by GetPos(), LoadSampleDataWithNullSamplesExtension(), Read(), and SetPos().

## GetCache()

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.

Returns
  buffer_t structure with current cached sample points

See also
  LoadSampleData();

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().

## GetPos()

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 FrameSize(), and RIFF::Chunk::GetPos().

Referenced by SetPos().

## IsCompressed()

bool Korg::KSFSample::IsCompressed | ( |  | ) | const

Definition at line 325 of file Korg.cpp.

## LoadSampleData() [1/2]

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.

Returns
  buffer_t structure with start address and size of the buffer in bytes

See also
  ReleaseSampleData(), Read(), SetPos()

Definition at line 139 of file Korg.cpp.

References LoadSampleDataWithNullSamplesExtension(), and SamplePoints.

## LoadSampleData() [2/2]

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.

Parameters

  SampleCount | - number of sample points to load into RAM

Returns
  buffer_t structure with start address and size of the cached sample data in bytes

See also
  ReleaseSampleData(), Read(), SetPos()

Definition at line 153 of file Korg.cpp.

References LoadSampleDataWithNullSamplesExtension().

## LoadSampleDataWithNullSamplesExtension() [1/2]

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.

Parameters

  NullSamplesCount | - number of silence samples the buffer should be extended past it's data end

Returns
  buffer_t structure with start address and size of the buffer in bytes

See also
  ReleaseSampleData(), Read(), SetPos()

Definition at line 174 of file Korg.cpp.

References LoadSampleDataWithNullSamplesExtension(), and SamplePoints.

Referenced by LoadSampleData(), LoadSampleData(), and LoadSampleDataWithNullSamplesExtension().

## LoadSampleDataWithNullSamplesExtension() [2/2]

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.

Parameters

  SampleCount | - number of sample points to load into RAM
  NullSamplesCount | - number of silence samples the buffer should be extended past it's data end

Returns
  buffer_t structure with start address and size of the cached sample data in bytes

See also
  ReleaseSampleData(), Read(), SetPos()

Definition at line 197 of file Korg.cpp.

References FrameSize(), GetCache(), Read(), SamplePoints, and SetPos().

## Read()

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)!

Parameters

  pBuffer | destination buffer
  SampleCount | number of sample points to read

Returns
  number of successfully read sample points

See also
  SetPos()

Definition at line 300 of file Korg.cpp.

References FrameSize(), and RIFF::Chunk::Read().

Referenced by LoadSampleDataWithNullSamplesExtension().

## ReleaseSampleData()

void Korg::KSFSample::ReleaseSampleData | ( |  | ) |

Frees the cached sample from RAM if loaded with LoadSampleData() previously.

See also
  LoadSampleData();

Definition at line 234 of file Korg.cpp.

References gig::buffer_t::pStart.

## SetPos()

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.

Parameters

  SampleCount | number of sample points to jump
  Whence | optional: to which relation SampleCount refers to, if omited RIFF::stream_start is assumed

Returns
  the new sample position

See also
  Read()

Definition at line 252 of file Korg.cpp.

References FrameSize(), GetPos(), SamplePoints, and RIFF::Chunk::SetPos().

Referenced by LoadSampleDataWithNullSamplesExtension().

## Use2ndStart()

bool Korg::KSFSample::Use2ndStart | ( |  | ) | const

Definition at line 329 of file Korg.cpp.

## Member Data Documentation

## 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.

## BitDepth

uint8_t Korg::KSFSample::BitDepth

i.e. 8 or 16

Definition at line 102 of file Korg.h.

Referenced by FrameSize().

## Channels

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().

## DefaultBank

uint8_t Korg::KSFSample::DefaultBank

0..3

Definition at line 93 of file Korg.h.

## LoopEnd

uint32_t Korg::KSFSample::LoopEnd

Definition at line 97 of file Korg.h.

## LoopStart

uint32_t Korg::KSFSample::LoopStart

Definition at line 96 of file Korg.h.

## LoopTune

int8_t Korg::KSFSample::LoopTune

-99..+99

Definition at line 100 of file Korg.h.

## Name

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.

## SamplePoints

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 LoadSampleData(), LoadSampleDataWithNullSamplesExtension(), LoadSampleDataWithNullSamplesExtension(), and SetPos().

## SampleRate

uint32_t Korg::KSFSample::SampleRate

i.e. 44100

Definition at line 98 of file Korg.h.

## Start

uint32_t Korg::KSFSample::Start

Definition at line 94 of file Korg.h.

## Start2

uint32_t Korg::KSFSample::Start2

Definition at line 95 of file Korg.h.

The documentation for this class was generated from the following files:

- Korg.h
- Korg.cpp