pxt-calliope/docs/reference/music/create-sound-effect.md
Juri Wolf 5f7a8e5301
Updates for V4 (#197)
* update yotta defaults for 16kb devices

* refactor deprecated blocks

* updates for button events

* update button events

* update refference

* update docs

* update docs

* update button event blocks

* update docs

* update block id
2022-08-10 09:36:19 -07:00

2.5 KiB

create Sound Effect

Create a sound expression string for a sound effect.

music.createSoundEffect(WaveShape.Sine, 2000, 0, 1023, 0, 500, SoundExpressionEffect.None, InterpolationCurve.Linear)

A sound expression is set of parameters that describe a Sound that will last for some amount of time. These parameters specify a base waveform, frequency range, sound volume, and effects. Sound data is created as a Sound object and can then be played to the speaker, headphones, or at an output pin.

Parameters

  • waveShape: the primary shape of the waveform:
  • sine: sine wave shape
  • sawtooth: sawtooth wave shape
  • triangle: triangle wave shape
  • square: square wave shape
  • noise: random noise generated wave shape
  • startFrequency: a number that is the frequency of the waveform when the sound expression starts.
  • endFrequency: a number that is the frequency of the waveform when the sound expression stops.
  • startVolume: a number the initial volume of the sound expression.
  • endVolume: a number the ending volume of the sound expression.
  • duration: a number the duration in milliseconds of the sound expression.
  • effect: an effect to add to the waveform. These are:
  • tremolo: add slight changes in volume of the sound expression.
  • vibrato: add slight changes in frequency to the sound expression.
  • warble: similar to vibrato but with faster variations in the frequency changes.
  • interpolation: controls the rate of frequency change in the sound expression.
  • linear: the change in frequency is constant for the duration of the sound.
  • curve: the change in frequency is faster at the beginning of the sound and slows toward the end.
  • logarithmic: the change in frequency is rapid during the very first part of the sound.

Returns

  • a sound expression string with the the desired sound effect parameters.

Example

Create a sound expression string and assign it to a variable. Play the sound for the sound expression.

let mySound = music.createSoundEffect(WaveShape.Sine, 2000, 0, 1023, 0, 500, SoundExpressionEffect.None, InterpolationCurve.Linear)
music.playSoundEffect(mySound, SoundExpressionPlayMode.UntilDone)

See also

play sound effect, built-in sound effect