Difference between revisions of "PlaySound Command"

From GeoGebra Manual
Jump to: navigation, search
(typo)
(https://test.geogebra.org/~mike/utils/base64Encode.html )
 
(24 intermediate revisions by 5 users not shown)
Line 1: Line 1:
+
<noinclude>{{Manual Page|version=5.0}}</noinclude>{{command|scripting}}
<noinclude>{{Manual Page|version=4.0}}</noinclude>
+
;PlaySound( <URL> )
{{command|scripting}}
+
: Plays an MP3 (.mp3) file
;PlaySound[ <Note>, <Duration>, <Instrument> ]
+
:{{Examples|1=<div>
:Plays a MIDI note.  
+
:*<code><nowiki>PlaySound("http://static.geogebra.org/welcome_to_geogebra.mp3")</nowiki></code>
 +
:*<code>PlaySound("#J2sQQfwQ")</code> plays an [http://www.geogebra.org/m/J2sQQfwQ .mp3 that has been uploaded to GeoGebra]
 +
:*<code><nowiki>PlaySound("https://drive.google.com/uc?id=0B7xCmZaU3oU2eXFNUzd6ZlZJS0U&authuser=0&export=download")</nowiki></code> plays an .mp3 from Google Drive
 +
:*<code><nowiki>PlaySound("https://www.dropbox.com/s/27skpv82odjp7ej/material-1264825.mp3?dl=1")</nowiki></code> plays an .mp3 from DropBox </div>}}
 +
 
 +
:{{note| 1= To work on iOS (and also if you want immediate playback) then you can encode the .mp3 as an inline base64-encoded data: URL, see https://www.geogebra.org/m/wztkqxuv for an example. It must start with the ''exact'' string <code>data:audio/mp3;base64,</code> to work in GeoGebra Classic 5. You can use this utility to convert .MP3s into the syntax needed in GeoGebra https://test.geogebra.org/~mike/utils/base64Encode.html }}
 +
 
 +
 
 +
;PlaySound( <Boolean Play> )
 +
:Pause or resume play (not MP3 files)
 +
:<code>PlaySound(true)</code> = play,  <code>PlaySound(false)</code> = pause.
 +
 
 +
;PlaySound( <Function>, <Min Value>, <Max Value> )
 +
:Plays a sound generated by Function, a time-valued function with range [-1,1]. The time units are seconds and the sound is played from time Min Value to  Max Value. Sound is generated by 8-bit samples taken at a rate of 8000 samples per second.
 +
 
 +
:{{Example| 1=<code>PlaySound(sin(440 2Pi x), 0, 1)</code>
 +
:This plays a pure sine wave tone at 440 Hz (musical note A) for one second.}}
 +
 
 +
;PlaySound( <Function>, <Min Value>, <Max Value>, <Sample Rate>, <Sample Depth> )
 +
:Plays a sound generated by Function, a time-valued function with range [-1,1]. The time units are seconds and the sound is played from time Min Value to  Max Value.  The sampling method is specified by "Sample Depth" and "Sample Rate".
 +
:"Sample Rate" is the number of sample function values taken each second. Allowable values are 8000, 11025, 16000, 22050, or 44100
 +
:"Sample Depth" is the data size of a sample in bits. Allowable values are 8 and 16.
 +
 
 +
;PlaySound( <Note>, <Duration>, <Instrument> ) (GeoGebra Classic 5 only)
 +
:Plays a [[w:MIDI|MIDI]] note.  
 
:''Note'' is an integer from 0 to 127 that represents a musical note given by the table below. When note = 60 a Middle C is played.  
 
:''Note'' is an integer from 0 to 127 that represents a musical note given by the table below. When note = 60 a Middle C is played.  
 
:''Duration'' is the time to play the note in seconds.  
 
:''Duration'' is the time to play the note in seconds.  
:''Instrument'' is an integer that represents the synthesized instrument used to play the note. See [http://www.midi.org/techspecs/gm1sound.php technical specifications at midi.org] for possible instruments.   
+
:''Instrument'' is an integer that represents the synthesized instrument used to play the note. See [https://web.archive.org/web/20130919034922/http://www.classicalmidiconnection.com/General_Midi.html technical specifications] for possible instruments.   
 
:Most instruments are supported, but there are differences between computer platforms.
 
:Most instruments are supported, but there are differences between computer platforms.
 
::{| class="pretty"
 
::{| class="pretty"
Line 85: Line 109:
 
|50
 
|50
 
|51
 
|51
|51
+
|52
 
|53
 
|53
 
|54
 
|54
Line 179: Line 203:
 
|+
 
|+
 
|}
 
|}
 
+
<br>
 
 
 
 
;PlaySound[ <Note Sequence>, <Instrument> ]
 
: Plays a sequence of MIDI notes and commands using a [http://www.jfugue.org  JFugue ]  music string.
 
: ''Note Sequence'' is a text string that uses JFugue character commands.
 
: ''Instrument'' is the default MIDI instrument used when the string is played.
 
: The basic commands are given below. The full command set is described in
 
: [http://www.jfugue.org/jfugue-chapter1.pdf  The Complete Guide to JFugue ] (English).
 
 
 
 
 
::{| class="pretty"
 
|+  '''Basic JFugue Commands'''
 
!Character
 
!Command
 
 
 
|+
 
| A-G
 
| Play the musical note given by the letter in octave 5
 
: For sharps and flats add b or #
 
: To change octaves add the octave number, e.g. A4
 
: Note length is a quarter note unless specified otherwise
 
 
 
|+
 
| [number]   
 
|  Play the MIDI note given by the number (0-127)
 
 
 
|+
 
| +
 
| Join notes together to play them in harmony, e.g. C+E+G
 
 
 
|+
 
| R   
 
| Rest
 
 
 
|+
 
| w, h, q, i, s 
 
| Add to the end of a note or rest;  sets the length
 
:: w = whole note
 
:: h = half note
 
:: q = quarter note
 
:: i = eighth note
 
:: s = sixteenth note
 
 
 
|+
 
| /n 
 
| Add to a note or rest; sets the length to n (a decimal number)
 
:: /1 = whole note
 
:: /.5 = half note
 
:: /.25 = quarter note 
 
:: /2 = two measures
 
 
 
|+
 
| I[number]   
 
| Set the instrument
 
 
 
|+
 
| V   
 
| V followed by a number from 0 to 15 sets the MIDI channel. "V9" sets the MIDI percussion channel.
 
|+
 
| Space
 
| Play the previous note, combination of notes or rest.
 
|}
 
 
 
 
 
{{Example| 1=<code>PlaySound["C+E+G  R  Ai Bi Ci  A4i B4i C4i ", 0]</code>
 
: Plays a quarter note chord CEG;  rests for a whole note;  plays the eighth notes A, B, C;  plays them again one octave lower.
 
: Piano instrument is used.
 
}}
 
{{Example| 1=<code>PlaySound["I[56] C5q D5q I[71] G5q F5q", 0]</code>
 
: Plays notes with different instruments.  Trumpet = 56 and Clarinet = 71.
 
}}
 
{{Example| 1=<code>PlaySound["V0 A3q B3q C3q B3q V1 A2h C2h", 0]</code>
 
: Plays notes in harmony with different voices.
 
}}
 
 
 
;PlaySound[ <File> ]
 
: Plays a MIDI file (*.mid) or a text file (* .txt) containing a JFugue string.
 
: "File" is the directory path to this file, e.g. PlaySound["path/to/myFile.mid"]
 
 
 
;PlaySound[ <Function>, <Min Value>, <Max Value> ]
 
:Plays a sound generated by Function, a time-valued function with range [-1,1]. The time units are seconds and the sound is played from time Min Value to  Max Value. Sound is generated by 8-bit samples taken at a rate of 8000 samples per second.
 
 
 
{{Example| 1=<code>PlaySound[sin(440 2Pi x), 0, 1]</code>
 
:This plays a pure sine wave tone at 440 Hz (musical note A) for one second.
 
}}
 
 
 
 
 
;PlaySound[ <Function>, <Min Value>, <Max Value>, <Sample Rate>, <Sample Depth> ]
 
:Plays a sound generated by Function, a time-valued function with range [-1,1]. The time units are seconds and the sound is played from time Min Value to  Max Value.  The sampling method is specified by "Sample Depth" and "Sample Rate".
 
:"Sample Rate" is the number of sample function values taken each second. Allowable values are 8000, 11025, 16000, 22050, or 44100
 
:"Sample Depth" is the data size of a sample in bits. Allowable values are 8 and 16.
 
 
 
 
 
;PlaySound[ <Boolean Play> ]
 
:Pause or resume play.
 
:PlaySound[true] = play,  PlaySound[false] = pause.
 

Latest revision as of 11:51, 8 October 2019


PlaySound( <URL> )
Plays an MP3 (.mp3) file
Examples:
  • PlaySound("http://static.geogebra.org/welcome_to_geogebra.mp3")
  • PlaySound("#J2sQQfwQ") plays an .mp3 that has been uploaded to GeoGebra
  • PlaySound("https://drive.google.com/uc?id=0B7xCmZaU3oU2eXFNUzd6ZlZJS0U&authuser=0&export=download") plays an .mp3 from Google Drive
  • PlaySound("https://www.dropbox.com/s/27skpv82odjp7ej/material-1264825.mp3?dl=1") plays an .mp3 from DropBox


Note: To work on iOS (and also if you want immediate playback) then you can encode the .mp3 as an inline base64-encoded data: URL, see https://www.geogebra.org/m/wztkqxuv for an example. It must start with the exact string data:audio/mp3;base64, to work in GeoGebra Classic 5. You can use this utility to convert .MP3s into the syntax needed in GeoGebra https://test.geogebra.org/~mike/utils/base64Encode.html 


PlaySound( <Boolean Play> )
Pause or resume play (not MP3 files)
PlaySound(true) = play, PlaySound(false) = pause.
PlaySound( <Function>, <Min Value>, <Max Value> )
Plays a sound generated by Function, a time-valued function with range [-1,1]. The time units are seconds and the sound is played from time Min Value to Max Value. Sound is generated by 8-bit samples taken at a rate of 8000 samples per second.
Example: PlaySound(sin(440 2Pi x), 0, 1)
This plays a pure sine wave tone at 440 Hz (musical note A) for one second.


PlaySound( <Function>, <Min Value>, <Max Value>, <Sample Rate>, <Sample Depth> )
Plays a sound generated by Function, a time-valued function with range [-1,1]. The time units are seconds and the sound is played from time Min Value to Max Value. The sampling method is specified by "Sample Depth" and "Sample Rate".
"Sample Rate" is the number of sample function values taken each second. Allowable values are 8000, 11025, 16000, 22050, or 44100
"Sample Depth" is the data size of a sample in bits. Allowable values are 8 and 16.
PlaySound( <Note>, <Duration>, <Instrument> ) (GeoGebra Classic 5 only)
Plays a MIDI note.
Note is an integer from 0 to 127 that represents a musical note given by the table below. When note = 60 a Middle C is played.
Duration is the time to play the note in seconds.
Instrument is an integer that represents the synthesized instrument used to play the note. See technical specifications for possible instruments.
Most instruments are supported, but there are differences between computer platforms.
MIDI Notes
Octave C C# D D# E F F# G G# A A# B
0 0 1 2 3 4 5 6 7 8 9 10 11
1 12 13 14 15 16 17 18 19 20 21 22 23
2 24 25 26 27 28 29 30 31 32 33 34 35
3 36 37 38 39 40 41 42 43 44 45 46 47
4 48 49 50 51 52 53 54 55 56 57 58 59
5 60 61 62 63 64 65 66 67 68 69 70 71
6 72 73 74 75 76 77 78 79 80 81 82 83
7 84 85 86 87 88 89 90 91 92 93 94 95
8 96 97 98 99 100 101 102 103 104 105 106 107
9 108 109 110 111 112 113 114 115 116 117 118 119
10 120 121 122 123 124 125 126 127


© 2024 International GeoGebra Institute