spessasynth_core 3.27.8 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +85 -51
- package/dist/index.d.ts +4057 -0
- package/dist/index.js +17178 -0
- package/dist/index.js.map +1 -0
- package/package.json +24 -6
- package/index.js +0 -132
- package/src/externals/README.md +0 -6
- package/src/externals/fflate/LICENSE +0 -21
- package/src/externals/fflate/fflate.min.js +0 -1
- package/src/externals/stbvorbis_sync/@types/stbvorbis_sync.d.ts +0 -12
- package/src/externals/stbvorbis_sync/LICENSE +0 -202
- package/src/externals/stbvorbis_sync/NOTICE +0 -6
- package/src/externals/stbvorbis_sync/stbvorbis_sync.min.js +0 -1
- package/src/midi/README.md +0 -32
- package/src/midi/basic_midi.js +0 -587
- package/src/midi/midi_builder.js +0 -203
- package/src/midi/midi_loader.js +0 -321
- package/src/midi/midi_message.js +0 -254
- package/src/midi/midi_sequence.js +0 -230
- package/src/midi/midi_tools/get_note_times.js +0 -154
- package/src/midi/midi_tools/midi_editor.js +0 -611
- package/src/midi/midi_tools/midi_writer.js +0 -105
- package/src/midi/midi_tools/rmidi_writer.js +0 -566
- package/src/midi/midi_tools/used_keys_loaded.js +0 -256
- package/src/midi/xmf_loader.js +0 -454
- package/src/sequencer/README.md +0 -9
- package/src/sequencer/events.js +0 -81
- package/src/sequencer/play.js +0 -362
- package/src/sequencer/process_event.js +0 -165
- package/src/sequencer/process_tick.js +0 -104
- package/src/sequencer/sequencer_engine.js +0 -372
- package/src/sequencer/song_control.js +0 -196
- package/src/soundfont/README.md +0 -11
- package/src/soundfont/basic_soundfont/basic_global_zone.js +0 -6
- package/src/soundfont/basic_soundfont/basic_instrument.js +0 -115
- package/src/soundfont/basic_soundfont/basic_instrument_zone.js +0 -45
- package/src/soundfont/basic_soundfont/basic_preset.js +0 -313
- package/src/soundfont/basic_soundfont/basic_preset_zone.js +0 -39
- package/src/soundfont/basic_soundfont/basic_sample.js +0 -477
- package/src/soundfont/basic_soundfont/basic_soundbank.js +0 -740
- package/src/soundfont/basic_soundfont/basic_zone.js +0 -145
- package/src/soundfont/basic_soundfont/generator.js +0 -76
- package/src/soundfont/basic_soundfont/generator_types.js +0 -151
- package/src/soundfont/basic_soundfont/modulator.js +0 -581
- package/src/soundfont/basic_soundfont/riff_chunk.js +0 -195
- package/src/soundfont/basic_soundfont/write_dls/art2.js +0 -174
- package/src/soundfont/basic_soundfont/write_dls/articulator.js +0 -49
- package/src/soundfont/basic_soundfont/write_dls/combine_zones.js +0 -374
- package/src/soundfont/basic_soundfont/write_dls/ins.js +0 -85
- package/src/soundfont/basic_soundfont/write_dls/lins.js +0 -15
- package/src/soundfont/basic_soundfont/write_dls/modulator_converter.js +0 -330
- package/src/soundfont/basic_soundfont/write_dls/rgn2.js +0 -120
- package/src/soundfont/basic_soundfont/write_dls/wave.js +0 -71
- package/src/soundfont/basic_soundfont/write_dls/write_dls.js +0 -124
- package/src/soundfont/basic_soundfont/write_dls/wsmp.js +0 -78
- package/src/soundfont/basic_soundfont/write_dls/wvpl.js +0 -35
- package/src/soundfont/basic_soundfont/write_sf2/ibag.js +0 -60
- package/src/soundfont/basic_soundfont/write_sf2/igen.js +0 -91
- package/src/soundfont/basic_soundfont/write_sf2/imod.js +0 -62
- package/src/soundfont/basic_soundfont/write_sf2/inst.js +0 -42
- package/src/soundfont/basic_soundfont/write_sf2/pbag.js +0 -57
- package/src/soundfont/basic_soundfont/write_sf2/pgen.js +0 -92
- package/src/soundfont/basic_soundfont/write_sf2/phdr.js +0 -61
- package/src/soundfont/basic_soundfont/write_sf2/pmod.js +0 -62
- package/src/soundfont/basic_soundfont/write_sf2/sdta.js +0 -131
- package/src/soundfont/basic_soundfont/write_sf2/shdr.js +0 -77
- package/src/soundfont/basic_soundfont/write_sf2/write.js +0 -287
- package/src/soundfont/dls/articulator_converter.js +0 -402
- package/src/soundfont/dls/dls_destinations.js +0 -38
- package/src/soundfont/dls/dls_instrument.js +0 -20
- package/src/soundfont/dls/dls_preset.js +0 -43
- package/src/soundfont/dls/dls_sample.js +0 -238
- package/src/soundfont/dls/dls_soundfont.js +0 -183
- package/src/soundfont/dls/dls_sources.js +0 -63
- package/src/soundfont/dls/dls_zone.js +0 -89
- package/src/soundfont/dls/read_articulation.js +0 -300
- package/src/soundfont/dls/read_instrument.js +0 -118
- package/src/soundfont/dls/read_instrument_list.js +0 -17
- package/src/soundfont/dls/read_lart.js +0 -35
- package/src/soundfont/dls/read_region.js +0 -157
- package/src/soundfont/dls/read_samples.js +0 -154
- package/src/soundfont/load_soundfont.js +0 -21
- package/src/soundfont/read_sf2/generators.js +0 -43
- package/src/soundfont/read_sf2/instrument_zones.js +0 -75
- package/src/soundfont/read_sf2/instruments.js +0 -71
- package/src/soundfont/read_sf2/modulators.js +0 -25
- package/src/soundfont/read_sf2/preset_zones.js +0 -79
- package/src/soundfont/read_sf2/presets.js +0 -80
- package/src/soundfont/read_sf2/samples.js +0 -317
- package/src/soundfont/read_sf2/soundfont.js +0 -452
- package/src/soundfont/read_sf2/zones.js +0 -28
- package/src/synthetizer/README.md +0 -7
- package/src/synthetizer/audio_engine/README.md +0 -9
- package/src/synthetizer/audio_engine/engine_components/compute_modulator.js +0 -289
- package/src/synthetizer/audio_engine/engine_components/controller_tables.js +0 -90
- package/src/synthetizer/audio_engine/engine_components/dynamic_modulator_system.js +0 -95
- package/src/synthetizer/audio_engine/engine_components/enums.js +0 -18
- package/src/synthetizer/audio_engine/engine_components/key_modifier_manager.js +0 -151
- package/src/synthetizer/audio_engine/engine_components/lfo.js +0 -26
- package/src/synthetizer/audio_engine/engine_components/lowpass_filter.js +0 -282
- package/src/synthetizer/audio_engine/engine_components/midi_audio_channel.js +0 -551
- package/src/synthetizer/audio_engine/engine_components/modulation_envelope.js +0 -181
- package/src/synthetizer/audio_engine/engine_components/modulator_curves.js +0 -89
- package/src/synthetizer/audio_engine/engine_components/soundfont_manager.js +0 -265
- package/src/synthetizer/audio_engine/engine_components/stereo_panner.js +0 -124
- package/src/synthetizer/audio_engine/engine_components/unit_converter.js +0 -73
- package/src/synthetizer/audio_engine/engine_components/voice.js +0 -525
- package/src/synthetizer/audio_engine/engine_components/volume_envelope.js +0 -402
- package/src/synthetizer/audio_engine/engine_components/wavetable_oscillator.js +0 -274
- package/src/synthetizer/audio_engine/engine_methods/controller_control/controller_change.js +0 -159
- package/src/synthetizer/audio_engine/engine_methods/controller_control/master_parameters.js +0 -53
- package/src/synthetizer/audio_engine/engine_methods/controller_control/reset_controllers.js +0 -254
- package/src/synthetizer/audio_engine/engine_methods/create_midi_channel.js +0 -20
- package/src/synthetizer/audio_engine/engine_methods/data_entry/awe32.js +0 -198
- package/src/synthetizer/audio_engine/engine_methods/data_entry/data_entry_coarse.js +0 -281
- package/src/synthetizer/audio_engine/engine_methods/data_entry/data_entry_fine.js +0 -109
- package/src/synthetizer/audio_engine/engine_methods/mute_channel.js +0 -17
- package/src/synthetizer/audio_engine/engine_methods/note_on.js +0 -220
- package/src/synthetizer/audio_engine/engine_methods/portamento_time.js +0 -92
- package/src/synthetizer/audio_engine/engine_methods/program_change.js +0 -35
- package/src/synthetizer/audio_engine/engine_methods/render_voice.js +0 -214
- package/src/synthetizer/audio_engine/engine_methods/soundfont_management/embedded_sound_bank.js +0 -42
- package/src/synthetizer/audio_engine/engine_methods/soundfont_management/get_preset.js +0 -0
- package/src/synthetizer/audio_engine/engine_methods/soundfont_management/update_preset_list.js +0 -19
- package/src/synthetizer/audio_engine/engine_methods/stopping_notes/kill_note.js +0 -23
- package/src/synthetizer/audio_engine/engine_methods/stopping_notes/note_off.js +0 -56
- package/src/synthetizer/audio_engine/engine_methods/stopping_notes/stop_all_channels.js +0 -16
- package/src/synthetizer/audio_engine/engine_methods/stopping_notes/stop_all_notes.js +0 -30
- package/src/synthetizer/audio_engine/engine_methods/stopping_notes/voice_killing.js +0 -63
- package/src/synthetizer/audio_engine/engine_methods/system_exclusive.js +0 -1058
- package/src/synthetizer/audio_engine/engine_methods/tuning_control/channel_pressure.js +0 -23
- package/src/synthetizer/audio_engine/engine_methods/tuning_control/pitch_wheel.js +0 -31
- package/src/synthetizer/audio_engine/engine_methods/tuning_control/poly_pressure.js +0 -29
- package/src/synthetizer/audio_engine/engine_methods/tuning_control/set_master_tuning.js +0 -15
- package/src/synthetizer/audio_engine/engine_methods/tuning_control/set_modulation_depth.js +0 -26
- package/src/synthetizer/audio_engine/engine_methods/tuning_control/set_octave_tuning.js +0 -19
- package/src/synthetizer/audio_engine/engine_methods/tuning_control/set_tuning.js +0 -27
- package/src/synthetizer/audio_engine/engine_methods/tuning_control/transpose_all_channels.js +0 -15
- package/src/synthetizer/audio_engine/engine_methods/tuning_control/transpose_channel.js +0 -34
- package/src/synthetizer/audio_engine/main_processor.js +0 -817
- package/src/synthetizer/audio_engine/snapshot/apply_synthesizer_snapshot.js +0 -16
- package/src/synthetizer/audio_engine/snapshot/channel_snapshot.js +0 -175
- package/src/synthetizer/audio_engine/snapshot/synthesizer_snapshot.js +0 -116
- package/src/synthetizer/audio_engine/synth_processor_options.js +0 -18
- package/src/synthetizer/synth_constants.js +0 -26
- package/src/utils/README.md +0 -8
- package/src/utils/buffer_to_wav.js +0 -197
- package/src/utils/byte_functions/big_endian.js +0 -32
- package/src/utils/byte_functions/little_endian.js +0 -77
- package/src/utils/byte_functions/string.js +0 -92
- package/src/utils/byte_functions/variable_length_quantity.js +0 -42
- package/src/utils/fill_with_defaults.js +0 -21
- package/src/utils/indexed_array.js +0 -34
- package/src/utils/loggin.js +0 -71
- package/src/utils/other.js +0 -92
- package/src/utils/sysex_detector.js +0 -58
- package/src/utils/xg_hacks.js +0 -193
|
@@ -1,317 +0,0 @@
|
|
|
1
|
-
import { RiffChunk } from "../basic_soundfont/riff_chunk.js";
|
|
2
|
-
import { IndexedByteArray } from "../../utils/indexed_array.js";
|
|
3
|
-
import { readLittleEndian, signedInt8 } from "../../utils/byte_functions/little_endian.js";
|
|
4
|
-
import { SpessaSynthInfo, SpessaSynthWarn } from "../../utils/loggin.js";
|
|
5
|
-
import { readBytesAsString } from "../../utils/byte_functions/string.js";
|
|
6
|
-
import { BasicSample } from "../basic_soundfont/basic_sample.js";
|
|
7
|
-
import { consoleColors } from "../../utils/other.js";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* samples.js
|
|
11
|
-
* purpose: parses soundfont samples
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
export const SF3_BIT_FLIT = 0x10;
|
|
15
|
-
|
|
16
|
-
export class SoundFontSample extends BasicSample
|
|
17
|
-
{
|
|
18
|
-
/**
|
|
19
|
-
* Linked sample index for retrieving linked samples in sf2
|
|
20
|
-
* @type {number}
|
|
21
|
-
*/
|
|
22
|
-
linkedSampleIndex;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* The sliced sample from the smpl chunk
|
|
26
|
-
* @type {Uint8Array}
|
|
27
|
-
*/
|
|
28
|
-
s16leData;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Creates a sample
|
|
32
|
-
* @param sampleName {string}
|
|
33
|
-
* @param sampleStartIndex {number}
|
|
34
|
-
* @param sampleEndIndex {number}
|
|
35
|
-
* @param sampleLoopStartIndex {number}
|
|
36
|
-
* @param sampleLoopEndIndex {number}
|
|
37
|
-
* @param sampleRate {number}
|
|
38
|
-
* @param samplePitch {number}
|
|
39
|
-
* @param samplePitchCorrection {number}
|
|
40
|
-
* @param linkedSampleIndex {number}
|
|
41
|
-
* @param sampleType {number}
|
|
42
|
-
* @param sampleDataArray {IndexedByteArray|Float32Array}
|
|
43
|
-
* @param sampleIndex {number} initial sample index when loading the sfont
|
|
44
|
-
* Used for SF2Pack support
|
|
45
|
-
*/
|
|
46
|
-
constructor(
|
|
47
|
-
sampleName,
|
|
48
|
-
sampleStartIndex,
|
|
49
|
-
sampleEndIndex,
|
|
50
|
-
sampleLoopStartIndex,
|
|
51
|
-
sampleLoopEndIndex,
|
|
52
|
-
sampleRate,
|
|
53
|
-
samplePitch,
|
|
54
|
-
samplePitchCorrection,
|
|
55
|
-
linkedSampleIndex,
|
|
56
|
-
sampleType,
|
|
57
|
-
sampleDataArray,
|
|
58
|
-
sampleIndex
|
|
59
|
-
)
|
|
60
|
-
{
|
|
61
|
-
// read sf3
|
|
62
|
-
// https://github.com/FluidSynth/fluidsynth/wiki/SoundFont3Format
|
|
63
|
-
const compressed = (sampleType & SF3_BIT_FLIT) > 0;
|
|
64
|
-
// remove the compression flag
|
|
65
|
-
sampleType &= ~SF3_BIT_FLIT;
|
|
66
|
-
super(
|
|
67
|
-
sampleName,
|
|
68
|
-
sampleRate,
|
|
69
|
-
samplePitch,
|
|
70
|
-
samplePitchCorrection,
|
|
71
|
-
sampleType,
|
|
72
|
-
sampleLoopStartIndex - (sampleStartIndex / 2),
|
|
73
|
-
sampleLoopEndIndex - (sampleStartIndex / 2)
|
|
74
|
-
);
|
|
75
|
-
this.dataOverriden = false;
|
|
76
|
-
this.isCompressed = compressed;
|
|
77
|
-
this.sampleName = sampleName;
|
|
78
|
-
// in bytes
|
|
79
|
-
this.startByteOffset = sampleStartIndex;
|
|
80
|
-
this.endByteOffset = sampleEndIndex;
|
|
81
|
-
this.sampleID = sampleIndex;
|
|
82
|
-
const smplStart = sampleDataArray.currentIndex;
|
|
83
|
-
|
|
84
|
-
// three data types in:
|
|
85
|
-
// SF2 (s16le)
|
|
86
|
-
// SF3 (vorbis)
|
|
87
|
-
// SF2Pack (
|
|
88
|
-
if (this.isCompressed)
|
|
89
|
-
{
|
|
90
|
-
// correct loop points
|
|
91
|
-
this.sampleLoopStartIndex += this.startByteOffset / 2;
|
|
92
|
-
this.sampleLoopEndIndex += this.startByteOffset / 2;
|
|
93
|
-
|
|
94
|
-
// copy the compressed data, it can be preserved during writing
|
|
95
|
-
this.compressedData = sampleDataArray.slice(
|
|
96
|
-
this.startByteOffset / 2 + smplStart,
|
|
97
|
-
this.endByteOffset / 2 + smplStart
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
else
|
|
101
|
-
{
|
|
102
|
-
if (sampleDataArray instanceof Float32Array)
|
|
103
|
-
{
|
|
104
|
-
// float32 array from SF2pack, copy directly
|
|
105
|
-
this.sampleData = sampleDataArray.slice(
|
|
106
|
-
this.startByteOffset / 2,
|
|
107
|
-
this.endByteOffset / 2
|
|
108
|
-
);
|
|
109
|
-
this.dataOverriden = true;
|
|
110
|
-
}
|
|
111
|
-
else
|
|
112
|
-
{
|
|
113
|
-
// regular sf2 s16le
|
|
114
|
-
this.s16leData = sampleDataArray.slice(
|
|
115
|
-
smplStart + this.startByteOffset,
|
|
116
|
-
smplStart + this.endByteOffset
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
this.linkedSampleIndex = linkedSampleIndex;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* @param samplesArray {BasicSample[]}
|
|
126
|
-
*/
|
|
127
|
-
getLinkedSample(samplesArray)
|
|
128
|
-
{
|
|
129
|
-
if (this.linkedSample || !this.isLinked)
|
|
130
|
-
{
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
const linked = samplesArray[this.linkedSampleIndex];
|
|
134
|
-
if (!linked)
|
|
135
|
-
{
|
|
136
|
-
// log as info because it's common and not really dangerous
|
|
137
|
-
SpessaSynthInfo(`%cInvalid linked sample for ${this.sampleName}. Setting to mono.`, consoleColors.warn);
|
|
138
|
-
this.unlinkSample();
|
|
139
|
-
}
|
|
140
|
-
else
|
|
141
|
-
{
|
|
142
|
-
// check for corrupted files (like FluidR3_GM.sf2 that link EVERYTHING to a single sample)
|
|
143
|
-
if (linked.linkedSample)
|
|
144
|
-
{
|
|
145
|
-
SpessaSynthInfo(
|
|
146
|
-
`%cInvalid linked sample for ${this.sampleName}: Already linked to ${linked.linkedSample.sampleName}`,
|
|
147
|
-
consoleColors.warn
|
|
148
|
-
);
|
|
149
|
-
this.unlinkSample();
|
|
150
|
-
}
|
|
151
|
-
else
|
|
152
|
-
{
|
|
153
|
-
this.setLinkedSample(linked, this.sampleType);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* @param audioData {Float32Array}
|
|
160
|
-
*/
|
|
161
|
-
setAudioData(audioData)
|
|
162
|
-
{
|
|
163
|
-
super.setAudioData(audioData);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Loads the audio data and stores it for reuse
|
|
168
|
-
* @returns {Float32Array} The audioData
|
|
169
|
-
*/
|
|
170
|
-
getAudioData()
|
|
171
|
-
{
|
|
172
|
-
if (this.sampleData)
|
|
173
|
-
{
|
|
174
|
-
return this.sampleData;
|
|
175
|
-
}
|
|
176
|
-
// SF2Pack is decoded during load time
|
|
177
|
-
// SF3 is decoded in BasicSample
|
|
178
|
-
if (this.isCompressed)
|
|
179
|
-
{
|
|
180
|
-
return super.getAudioData();
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// start loading data if it is not loaded
|
|
184
|
-
const byteLength = this.endByteOffset - this.startByteOffset;
|
|
185
|
-
if (byteLength < 1)
|
|
186
|
-
{
|
|
187
|
-
SpessaSynthWarn(`Invalid sample ${this.sampleName}! Invalid length: ${byteLength}`);
|
|
188
|
-
return new Float32Array(1);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
// SF2
|
|
193
|
-
// read the sample data
|
|
194
|
-
let audioData = new Float32Array(byteLength / 2);
|
|
195
|
-
let convertedSigned16 = new Int16Array(
|
|
196
|
-
this.s16leData.buffer
|
|
197
|
-
);
|
|
198
|
-
|
|
199
|
-
// convert to float
|
|
200
|
-
for (let i = 0; i < convertedSigned16.length; i++)
|
|
201
|
-
{
|
|
202
|
-
audioData[i] = convertedSigned16[i] / 32768;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
this.sampleData = audioData;
|
|
206
|
-
return audioData;
|
|
207
|
-
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* @param allowVorbis
|
|
212
|
-
* @returns {Uint8Array}
|
|
213
|
-
*/
|
|
214
|
-
getRawData(allowVorbis)
|
|
215
|
-
{
|
|
216
|
-
if (this.dataOverriden || this.compressedData)
|
|
217
|
-
{
|
|
218
|
-
// return vorbis or encode manually
|
|
219
|
-
return super.getRawData(allowVorbis);
|
|
220
|
-
}
|
|
221
|
-
// copy the smpl directly
|
|
222
|
-
return this.s16leData;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* Reads the generatorTranslator from the shdr read
|
|
228
|
-
* @param sampleHeadersChunk {RiffChunk}
|
|
229
|
-
* @param smplChunkData {IndexedByteArray|Float32Array}
|
|
230
|
-
* @param linkSamples {boolean}
|
|
231
|
-
* @returns {SoundFontSample[]}
|
|
232
|
-
*/
|
|
233
|
-
export function readSamples(sampleHeadersChunk, smplChunkData, linkSamples = true)
|
|
234
|
-
{
|
|
235
|
-
/**
|
|
236
|
-
* @type {SoundFontSample[]}
|
|
237
|
-
*/
|
|
238
|
-
let samples = [];
|
|
239
|
-
let index = 0;
|
|
240
|
-
while (sampleHeadersChunk.chunkData.length > sampleHeadersChunk.chunkData.currentIndex)
|
|
241
|
-
{
|
|
242
|
-
const sample = readSample(index, sampleHeadersChunk.chunkData, smplChunkData);
|
|
243
|
-
samples.push(sample);
|
|
244
|
-
index++;
|
|
245
|
-
}
|
|
246
|
-
// remove EOS
|
|
247
|
-
samples.pop();
|
|
248
|
-
|
|
249
|
-
// link samples
|
|
250
|
-
if (linkSamples)
|
|
251
|
-
{
|
|
252
|
-
samples.forEach(s => s.getLinkedSample(samples));
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
return samples;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* Reads it into a sample
|
|
260
|
-
* @param index {number}
|
|
261
|
-
* @param sampleHeaderData {IndexedByteArray}
|
|
262
|
-
* @param smplArrayData {IndexedByteArray|Float32Array}
|
|
263
|
-
* @returns {SoundFontSample}
|
|
264
|
-
*/
|
|
265
|
-
function readSample(index, sampleHeaderData, smplArrayData)
|
|
266
|
-
{
|
|
267
|
-
|
|
268
|
-
// read the sample name
|
|
269
|
-
let sampleName = readBytesAsString(sampleHeaderData, 20);
|
|
270
|
-
|
|
271
|
-
// read the sample start index
|
|
272
|
-
let sampleStartIndex = readLittleEndian(sampleHeaderData, 4) * 2;
|
|
273
|
-
|
|
274
|
-
// read the sample end index
|
|
275
|
-
let sampleEndIndex = readLittleEndian(sampleHeaderData, 4) * 2;
|
|
276
|
-
|
|
277
|
-
// read the sample looping start index
|
|
278
|
-
let sampleLoopStartIndex = readLittleEndian(sampleHeaderData, 4);
|
|
279
|
-
|
|
280
|
-
// read the sample looping end index
|
|
281
|
-
let sampleLoopEndIndex = readLittleEndian(sampleHeaderData, 4);
|
|
282
|
-
|
|
283
|
-
// read the sample rate
|
|
284
|
-
let sampleRate = readLittleEndian(sampleHeaderData, 4);
|
|
285
|
-
|
|
286
|
-
// read the original sample pitch
|
|
287
|
-
let samplePitch = sampleHeaderData[sampleHeaderData.currentIndex++];
|
|
288
|
-
if (samplePitch > 127)
|
|
289
|
-
{
|
|
290
|
-
// if it's out of range, then default to 60
|
|
291
|
-
samplePitch = 60;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
// read the sample pitch correction
|
|
295
|
-
let samplePitchCorrection = signedInt8(sampleHeaderData[sampleHeaderData.currentIndex++]);
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
// read the link to the other channel
|
|
299
|
-
let sampleLink = readLittleEndian(sampleHeaderData, 2);
|
|
300
|
-
let sampleType = readLittleEndian(sampleHeaderData, 2);
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
return new SoundFontSample(
|
|
304
|
-
sampleName,
|
|
305
|
-
sampleStartIndex,
|
|
306
|
-
sampleEndIndex,
|
|
307
|
-
sampleLoopStartIndex,
|
|
308
|
-
sampleLoopEndIndex,
|
|
309
|
-
sampleRate,
|
|
310
|
-
samplePitch,
|
|
311
|
-
samplePitchCorrection,
|
|
312
|
-
sampleLink,
|
|
313
|
-
sampleType,
|
|
314
|
-
smplArrayData,
|
|
315
|
-
index
|
|
316
|
-
);
|
|
317
|
-
}
|