File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -897,6 +897,38 @@ 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
+ * function preload(){
906
+ * sound = loadSound('assets/beat.mp3');
907
+ * }
908
+ *
909
+ * function setup() {
910
+ * let cnv = createCanvas(100, 100);
911
+ * cnv.mousePressed(startSound);
912
+ * }
913
+ * function draw() {
914
+ * background(220);
915
+ * sRate = sound.rate();
916
+ * text('tap to play', 10, 20);
917
+ * if (midiVal) {
918
+ * text('MIDI: ' + midiVal, 10, 40);
919
+ * text('Rate: ' + sRate, 10, 60);
920
+ * }
921
+ * }
922
+ * function startSound() {
923
+ * if (sound.isPlaying()){
924
+ * sound.stop();
925
+ * }
926
+ * sound.play();
927
+ * midiVal = midiNotes[noteIndex % midiNotes.length];
928
+ * sound.setPitch(midiVal);
929
+ * noteIndex++;
930
+ * }
931
+ * </code></div>
900
932
*/
901
933
setPitch ( num ) {
902
934
var newPlaybackRate = midiToFreq ( num ) / midiToFreq ( 60 ) ;
You can’t perform that action at this time.
0 commit comments