Skip to content

Sample Class

spessasus edited this page Jul 27, 2024 · 1 revision

Sample class

Represents a single SoundFont2 sample.

The class should not be initialized on its own as it's used internally by the SoundFont2 class.

Methods

getAudioData()

Gets the PCM Float32Array audio data and stores it internally for reuse. Decodes compressed samples if necessary.

const data = sample.getAudioData();

The returned value is a Float32Array containing the PCM audio data for the sample.

All other methods are internal.

Properties

sampleName

The sample's name.

console.log(sample.sampleName); // "Standard SnareL"

sampleLoopStartIndex

The sample's loop start index. In sample data points, relative to start of the sample.

console.log(sample.sampleLoopStartIndex); // 5834

sampleLoopEndIndex

The sample's loop end index. In sample data points, relative to start of the sample.

console.log(sample.sampleLoopEndIndex); // 8968

sampleType

The sample type. Note that for compressed samples bit 4 is 1.

console.log(sample.sampleType); // 2 -> this means "right sample"

isCompressed

Indicates if the sample is compressed.

console.log(sample.isCompressed); // true

sampleRate

The sample rate of the sample, in hertz.

console.log(sample.sampleRate); // 44100

samplePitch

The MIDI key number of the recorded pitch of the sample.

console.log(sample.samplePitch); // 60 (Middle C)

samplePitchCorrection

The pitch correction to apply, in cents. can be negative.

console.log(sample.samplePitchCorrection); // -4 (4 cents down)

All other properties are internal.