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
namestringThe sample's name.
rateintThe sample's rate in Hz.
originalKeyintThe sample's pitch as a MIDI note number.
pitchCorrectionintThe sample's pitch correction in cents.
typeBasicSample.TypeThe sample's type, an enum that can indicate SF3.
loopStartintThe sample's loop start relative to the sample start in sample points.
loopEndintThe 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
CompressedData
The compressed sample data if the sample has been compressed.
protected ArraySegment<byte>? CompressedData
Field Value
DataOverridden
Indicates if the data was overridden, so it cannot be copied back unchanged.
protected bool DataOverridden
Field Value
LinkedSample
Linked sample, unused if mono.
public BasicSample? LinkedSample
Field Value
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
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
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
Name
The sample's name.
public string Name
Field Value
OriginalKey
Original pitch of the sample as a MIDI note number.
public int OriginalKey
Field Value
PitchCorrection
Pitch correction, in cents. Can be negative.
public int PitchCorrection
Field Value
Rate
Sample rate in Hz.
public int Rate
Field Value
SType
The type of the sample.
public BasicSample.Type SType
Field Value
Properties
IsCompressed
Indicates if the sample is compressed using vorbis SF3.
public bool IsCompressed { get; }
Property Value
IsLinked
If the sample is linked to another sample.
public bool IsLinked { get; }
Property Value
UseCount
The sample's use count
public int UseCount { get; }
Property Value
Methods
CompressSample(Encode)
Compresses the audio data
public void CompressSample(SoundBank.Encode encode)
Parameters
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
allowVorbisboolIf 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
instrumentBasicInstrumentThe instrument to link to
NewEmpty()
public static BasicSample NewEmpty()
Returns
ResampleData(int)
Resamples the audio data to a given sample rate
public void ResampleData(int newSampleRate)
Parameters
newSampleRateintThe new sample rate
Set(Type)
Sets the sample type and unlinks if needed.
public void Set(BasicSample.Type type)
Parameters
typeBasicSample.TypeThe 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
audioDataArraySegment<float>The new audio data as Float32.
sampleRateintThe 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
dataArraySegment<byte>The new compressed data
SetLinkedSample(BasicSample, Type)
Links a stereo sample.
public void SetLinkedSample(BasicSample sample, BasicSample.Type type)
Parameters
sampleBasicSampleThe sample to link to.
typeBasicSample.TypeEither left, right or linked.
Exceptions
- ArgumentException
Invalid sample type
TypeOf(int)
public static BasicSample.Type TypeOf(int val)
Parameters
valint
Returns
UnlinkFrom(BasicInstrument)
Unlinks the sample from a given instrument
public void UnlinkFrom(BasicInstrument instrument)
Parameters
instrumentBasicInstrumentThe 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
typeBasicSample.Type