Skip to content

Commit e9ac2af

Browse files
committed
setPitch_example
1 parent 4bbe4ef commit e9ac2af

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/soundfile.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,38 @@ 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+
* 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>
900932
*/
901933
setPitch(num) {
902934
var newPlaybackRate = midiToFreq(num) / midiToFreq(60);

0 commit comments

Comments
 (0)