Difference between revisions of "Sound.init"

From MiniScript Wiki
Jump to navigation Jump to search
(Created page with "<c>Sound.init</c> synthesizes a sound from various parameters, including look-up tables that represent one cycle of the waveform and the volume envelope. === Usage Notes...")
 
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
<c>[[Sound]].init</c> synthesizes a sound from various parameters, including look-up tables
 
<c>[[Sound]].init</c> synthesizes a sound from various parameters, including look-up tables
 
that represent one cycle of the waveform and the volume envelope.
 
that represent one cycle of the waveform and the volume envelope.
 +
 +
=== Arguments ===
 +
 +
{| class="wikitable"
 +
|-
 +
! Parameter Name !! Type !! Default Value !! Meaning
 +
|-
 +
| ''duration'' || number || 1 || length of the sound in seconds
 +
|-
 +
| ''frequency'' || number || 440 || number of repeats of the waveform per second
 +
|-
 +
| ''envelope'' || [number] || [1] || volume (0 to 1) over the duration of the sound
 +
|-
 +
| ''waveform'' || [number] || [-1, 1] || wave value over an audio cycle
 +
|}
  
 
=== Usage Notes ===
 
=== Usage Notes ===
 
Call this on a new Sound object, or to reset a previous one.
 
Call this on a new Sound object, or to reset a previous one.
duration (number, default 1): length of the sound, in seconds
+
 
freq (number, default 440): number of repeats of the waveform per second
+
The frequency and envelope arguments may be either a single value, applied to the entire sound; or a list of values, in which case the frequency or amplitude will interpolate evenly over those values over the duration of the sound.
envelope (list): volume (0 to 1) over the duration of the sound
 
waveform (list): wave value (-1 to 1) over one cycle
 
  
 
== Example ==
 
== Example ==
Line 13: Line 26:
 
<ms>pew = new Sound
 
<ms>pew = new Sound
 
pew.init 0.3, [8000,100], [1,0]
 
pew.init 0.3, [8000,100], [1,0]
pew.play
+
pew.play</ms>
 +
 
 
Example 2:
 
Example 2:
hitSnd = new Sound
+
<ms>hitSnd = new Sound
 
hitSnd.init 1, 100, [1,0], Sound.noiseWave
 
hitSnd.init 1, 100, [1,0], Sound.noiseWave
 
hitSnd.play</ms>
 
hitSnd.play</ms>
 +
 +
See also: <c>[[Sound.duration]]</c>; <c>[[Sound.freq]]</c>; <c>[[Sound.envelope]]</c>; <c>[[Sound.waveform]]</c>
  
 
[[Category:Mini Micro]]
 
[[Category:Mini Micro]]

Latest revision as of 18:42, 20 January 2024

Sound.init synthesizes a sound from various parameters, including look-up tables that represent one cycle of the waveform and the volume envelope.

Arguments

Parameter Name Type Default Value Meaning
duration number 1 length of the sound in seconds
frequency number 440 number of repeats of the waveform per second
envelope [number] [1] volume (0 to 1) over the duration of the sound
waveform [number] [-1, 1] wave value over an audio cycle

Usage Notes

Call this on a new Sound object, or to reset a previous one.

The frequency and envelope arguments may be either a single value, applied to the entire sound; or a list of values, in which case the frequency or amplitude will interpolate evenly over those values over the duration of the sound.

Example

pew = new Sound
pew.init 0.3, [8000,100], [1,0]
pew.play

Example 2:

hitSnd = new Sound
hitSnd.init 1, 100, [1,0], Sound.noiseWave
hitSnd.play

See also: Sound.duration; Sound.freq; Sound.envelope; Sound.waveform