Class BasicSample

Namespace
SpessaSharp.SoundBank
Assembly
SpessaSharp.dll
public class BasicSample
Inheritance
BasicSample
Inherited Members

Constructors

BasicSample(string, int, int, int, Type, int, int)

The basic representation of a sample

public BasicSample(string name, int rate, int originalKey, int pitchCorrection, BasicSample.Type type, int loopStart, int loopEnd)

Parameters

name string

The sample's name.

rate int

The sample's rate in Hz.

originalKey int

The sample's pitch as a MIDI note number.

pitchCorrection int

The sample's pitch correction in cents.

type BasicSample.Type

The sample's type, an enum that can indicate SF3.

loopStart int

The sample's loop start relative to the sample start in sample points.

loopEnd int

The sample's loop end relative to the sample start in sample points.

Fields

AudioData

The sample's audio data.

protected ArraySegment<float>? AudioData

Field Value

ArraySegment<float>?

CompressedData

The compressed sample data if the sample has been compressed.

protected ArraySegment<byte>? CompressedData

Field Value

ArraySegment<byte>?

DataOverridden

Indicates if the data was overridden, so it cannot be copied back unchanged.

protected bool DataOverridden

Field Value

bool

LinkedSample

Linked sample, unused if mono.

public BasicSample? LinkedSample

Field Value

BasicSample

LinkedTo

Sample's linked instruments (the instruments that use it) note that duplicates are allowed since one instrument can use the same sample multiple times.

public readonly List<BasicInstrument> LinkedTo

Field Value

List<BasicInstrument>

LoopEnd

The sample's loop end index, exclusive. In sample data points, relative to the start of the sample.
Maximum allowed value is the sample data length.

public int LoopEnd

Field Value

int

LoopStart

The sample's loop start index, inclusive. In sample data points, relative to the start of the sample.
Minimum allowed value is 0.

public int LoopStart

Field Value

int

Name

The sample's name.

public string Name

Field Value

string

OriginalKey

Original pitch of the sample as a MIDI note number.

public int OriginalKey

Field Value

int

PitchCorrection

Pitch correction, in cents. Can be negative.

public int PitchCorrection

Field Value

int

Rate

Sample rate in Hz.

public int Rate

Field Value

int

SType

The type of the sample.

public BasicSample.Type SType

Field Value

BasicSample.Type

Properties

IsCompressed

Indicates if the sample is compressed using vorbis SF3.

public bool IsCompressed { get; }

Property Value

bool

IsLinked

If the sample is linked to another sample.

public bool IsLinked { get; }

Property Value

bool

UseCount

The sample's use count

public int UseCount { get; }

Property Value

int

Methods

CompressSample(Encode)

Compresses the audio data

public void CompressSample(SoundBank.Encode encode)

Parameters

encode SoundBank.Encode

The compression function to use when compressing

EncodeS16LE()

Encodes s16le sample

protected ArraySegment<byte> EncodeS16LE()

Returns

ArraySegment<byte>

The encoded data

GetAudioData()

Get the float32 audio data. Note that this either decodes the compressed data or passes the ready sampleData. If neither are set then it will throw an error!

public virtual ArraySegment<float> GetAudioData()

Returns

ArraySegment<float>

The audio data

Exceptions

InvalidOperationException

Null audio data

GetRawData(bool)

Get raw data for writing the file, either a compressed bit stream or signed 16-bit little endian PCM data.

public virtual ArraySegment<byte> GetRawData(bool allowVorbis)

Parameters

allowVorbis bool

If vorbis file data is allowed.

Returns

ArraySegment<byte>

Either s16le or vorbis data.

LinkTo(BasicInstrument)

Links the sample to a given instrument

public void LinkTo(BasicInstrument instrument)

Parameters

instrument BasicInstrument

The instrument to link to

NewEmpty()

public static BasicSample NewEmpty()

Returns

BasicSample

ResampleData(int)

Resamples the audio data to a given sample rate

public void ResampleData(int newSampleRate)

Parameters

newSampleRate int

The new sample rate

Set(Type)

Sets the sample type and unlinks if needed.

public void Set(BasicSample.Type type)

Parameters

type BasicSample.Type

The type to set it to.

Exceptions

InvalidOperationException

Type unsupported

SetAudioData(ArraySegment<float>, int)

Replaces the audio data in-place.

public void SetAudioData(ArraySegment<float> audioData, int sampleRate)

Parameters

audioData ArraySegment<float>

The new audio data as Float32.

sampleRate int

The new sample rate, in Hertz.

SetCompressedData(ArraySegment<byte>)

Replaces the audio with a compressed data sample and flags the sample as compressed

public void SetCompressedData(ArraySegment<byte> data)

Parameters

data ArraySegment<byte>

The new compressed data

SetLinkedSample(BasicSample, Type)

Links a stereo sample.

public void SetLinkedSample(BasicSample sample, BasicSample.Type type)

Parameters

sample BasicSample

The sample to link to.

type BasicSample.Type

Either left, right or linked.

Exceptions

ArgumentException

Invalid sample type

TypeOf(int)

public static BasicSample.Type TypeOf(int val)

Parameters

val int

Returns

BasicSample.Type

UnlinkFrom(BasicInstrument)

Unlinks the sample from a given instrument

public void UnlinkFrom(BasicInstrument instrument)

Parameters

instrument BasicInstrument

The instrument to unlink from

Exceptions

ArgumentException

Instrument not linked to sample

UnlinkSample()

Unlinks the sample from its stereo link if it has any.

public void UnlinkSample()

ValueOf(Type)

public static int ValueOf(BasicSample.Type type)

Parameters

type BasicSample.Type

Returns

int