Play -1: myCustomSampledInstrument

2 [C | D | E | F | G | A | B] 3 [C | D | E | F | G | A | B] 4 [C | D | E | F | G | A | B]

Tutorial

Record sample sound and convert them into MP3 or OGG to reduce download size.

Warning: compression bring distortion to wave shape and you may notice clicks in looped samples. You need to change loop start/end to avoid clicks.

Warning: Of course, you can use the original uncompressed .wav files with the maximum sample rate and stereo. But this will increase the download size by 20-30 times.

Open any online BASE64 encoder and convert file into string

Create definition of instrument

var myCustomSampledInstrument={
	zones:[
		{
			midi:0 //MIDI program
			,originalPitch: 84*100-36*100 //root pitch in cent, may be transpose up/down
			,keyRangeLow: 12*3+6 //zone low key
			,keyRangeHigh: 127 //zone high key
			,loopStart: 0 //loop tart in seconds
			,loopEnd: 0 //loop end in seconds
			,coarseTune: 0 //use fine tune
			,fineTune: -11 //tune correction in cents
			,sampleRate: 48000 //file sample rate
			,ahdsr: true // see example
			,file:'//uUxAAAAAAAAAAAAAAAAAAAAAAAWGluZwAAAA8AAADzAA...
		}
	]
};
		

Insert BASE64 string into field 'file'.

Open any SF2 editor and open your sample. Fill other fields from sample info:

Play custom instrument

player.queueWaveTable(audioContext, audioContext.destination, myCustomSampledInstrument, 0, key, 2,0.5);

Look to code of this page to find more information.

Open any .mid file and select '-1: myCustomSampledInstrument' for any track to test sound.


source