Difference between revisions of "Sound.freq"

From MiniScript Wiki
Jump to navigation Jump to search
m
(Added a new example for frequency changes, as well as a link to example audio generated by the code.)
 
(3 intermediate revisions by the same user not shown)
Line 4: Line 4:
  
 
<ms>snd = new Sound
 
<ms>snd = new Sound
snd.init(2)
+
snd.init 2
 
snd.freq = 261.626
 
snd.freq = 261.626
 
snd.play</ms>
 
snd.play</ms>
  
It can be assigned a single frequency, or a list of frequencies, and Micro Mini will interpolate between frequencies over the duration of the sound:
+
It can be assigned a single frequency, or a list of frequencies, and Mini Micro will interpolate between frequencies over the duration of the sound:
  
 
<ms>snd = new Sound
 
<ms>snd = new Sound
snd.init(2)
+
snd.init 2
 
snd.freq = [noteFreq(58), noteFreq(43)]
 
snd.freq = [noteFreq(58), noteFreq(43)]
 
snd.play</ms>
 
snd.play</ms>
 +
 +
== Example ==
 +
Here's a script for a three tone siren each increasing and decreasing in frequency over time:
 +
[https://commons.wikimedia.org/wiki/File:MiniMicro_Sirens.ogg Link to Audio Generated]
 +
<ms>sirens = [ new Sound, new Sound, new Sound ]
 +
sirenFreq = [ 184.997, 659.255, 659.255, 184.997 ]
 +
sirenDuration = 20
 +
sirenDelay = 2.25
 +
sirenVolume = [0.1, 0.33, 0.1]
 +
 +
for siren in sirens
 +
siren.init sirenDuration, sirenFreq, sirenVolume
 +
siren.play
 +
wait sirenDelay
 +
end for</ms>
  
 
See also: <c>[[Sound.init]]</c>; <c>[[noteFreq]]</c>
 
See also: <c>[[Sound.init]]</c>; <c>[[noteFreq]]</c>
 +
 +
[[Category:Mini Micro]]

Latest revision as of 06:55, 28 April 2020

Sound.freq controls a Sound object's sound frequency, or how many times a second a waveform is repeated.

For example, a middle C on a piano produces a sound frequency of 261.626 times a second:

snd = new Sound
snd.init 2
snd.freq = 261.626
snd.play

It can be assigned a single frequency, or a list of frequencies, and Mini Micro will interpolate between frequencies over the duration of the sound:

snd = new Sound
snd.init 2
snd.freq = [noteFreq(58), noteFreq(43)]
snd.play

Example

Here's a script for a three tone siren each increasing and decreasing in frequency over time: Link to Audio Generated

sirens = [ new Sound, new Sound, new Sound ]
sirenFreq = [ 184.997, 659.255, 659.255, 184.997 ]
sirenDuration = 20
sirenDelay = 2.25
sirenVolume = [0.1, 0.33, 0.1]

for siren in sirens
	siren.init sirenDuration, sirenFreq, sirenVolume
	siren.play
	wait sirenDelay
end for

See also: Sound.init; noteFreq