Skip to content

Commit b6133f9

Browse files
authored
Merge pull request #704 from Nitesh639/setPitch_example
setPitch_example
2 parents 83e46b4 + ba1662b commit b6133f9

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/soundfile.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,42 @@ class SoundFile {
897897
* @param {Number} pitchRate If the MIDI note is increased, then both the
898898
* frequency of the sound and its playback speed
899899
* 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>
900936
*/
901937
setPitch(num) {
902938
var newPlaybackRate = midiToFreq(num) / midiToFreq(60);

0 commit comments

Comments
 (0)