File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -897,6 +897,42 @@ class SoundFile {
897
897
* @param {Number } pitchRate If the MIDI note is increased, then both the
898
898
* frequency of the sound and its playback speed
899
899
* will increase as a result.
900
+ * @example
901
+ * <div><code>
902
+ * let sound, sRate, midiVal;
903
+ * let midiNotes = [60, 64, 67, 72];
904
+ * let noteIndex = 0;
905
+ *
906
+ * function preload() {
907
+ * sound = loadSound('assets/beat.mp3');
908
+ * }
909
+ *
910
+ * function setup() {
911
+ * let cnv = createCanvas(100, 100);
912
+ * cnv.mousePressed(startSound);
913
+ * }
914
+ *
915
+ * function draw() {
916
+ * background(220);
917
+ * sRate = sound.rate();
918
+ * text('tap to play', 10, 20);
919
+ * if (midiVal) {
920
+ * text('MIDI: ' + midiVal, 10, 40);
921
+ * text('Rate: ' + sRate, 10, 60);
922
+ * }
923
+ * }
924
+ *
925
+ * function startSound() {
926
+ * if (sound.isPlaying()) {
927
+ * sound.stop();
928
+ * }
929
+ * sound.play();
930
+ * midiVal = midiNotes[noteIndex % midiNotes.length];
931
+ * sound.setPitch(midiVal);
932
+ *
933
+ * noteIndex++;
934
+ * }
935
+ * </code></div>
900
936
*/
901
937
setPitch ( num ) {
902
938
var newPlaybackRate = midiToFreq ( num ) / midiToFreq ( 60 ) ;
You can’t perform that action at this time.
0 commit comments