Back

CreateSynth

Hello World
Content:
- Some descriptions
- Methods

Returns a Synth object which ca produces a variety of sounds, sound effects and music.

syn = app.CreateSynth( type ) → app object: Synth

Some descriptions

note length: default is 2.56 seconds.
midi note: like n'th key on a keyboard between 0 and ~125. 12 keys are one octave. Ie. the 4'th octave:
     C, C#, D, D#, E, F, F#, G, G#, A, A#, B.
duration: powers of two indicating whole, half, quarter etc. up to thirty second notes.
frequency: A4 equals 440 Hz. Each note frequency is 12√2 (~1.06) times higher than the previous.
Humans can hear a range from 10 to about 20,000 Hz. My phone's range is from 0 to about 11025 Hz


Phaser: a sound filter which creates a series of peaks and troughs in the frequency spectrum
VoltageControlledAmplifier: (Variable-Gain Amplifier) electronic amplifier that varies its gain
Voltage-Controlled Filter: electronic amplifier that varies the frequency

Example - Tetris Theme

function OnStart()
{
    syn = app.CreateSynth();
    syn.SetWaveShape( "Saw" );
    syn.SetVcaSustain( 0.5 );
    syn.SetVolume( 1, 1 );
    syn.SetNoteLength( 2 );

    syn.PlayMidiTune(
        "76:4,71:8,72:8,74:4,72:8,71:8,69:4,69:8,72:8,76:4," +
        "74:8,72:8,71:4,71:8,72:8,74:4,76:4,72:4,69:4,69:8," +
        "69:8,71:8,72:8,74:8,74:4,77:8,81:4,79:8,77:8,76:8,76:4,72:8,76:4," +
        "74:8,72:8,71:4,71:8,72:8,74:4,76:4,72:4,69:4,69:4"
    );
}
Copy All       Run      

Example - Multiple Synths Song

function OnStart()
{
    synth1 = app.CreateSynth();
    synth1.SetWaveShape( "Saw" );
    synth1.SetVcaSustain( 0.5 );
    synth1.SetVcaDecay( 500 );
    synth1.SetVolume( 1, 1 );

    synth2 = app.CreateSynth();
    synth2.SetWaveShape( "Saw" );
    synth2.SetVcaDecay( 300 );
    synth2.SetVolume( 1, 1 );

    setTimeout('synth1.PlayMidiTune("35:4,35:4,35:4,35:4,31:4,31:4,30:4,30:4")', 0*5120);
    setTimeout('synth1.PlayMidiTune("35:4,35:4,35:4,35:4,31:4,31:4,30:4,30:4")', 1*5120);
    setTimeout('synth1.PlayMidiTune("35:4,35:4,35:4,35:4,31:4,31:4,30:4,30:4")', 2*5120);
    setTimeout('synth1.PlayMidiTune("35:4,35:4,35:4,35:4,31:4,31:4,30:4,30:4")', 3*5120);
    setTimeout('synth1.PlayMidiTune("35:4,35:4,35:4,35:4,31:4,31:4,30:4,30:4")', 4*5120);
    setTimeout('synth1.PlayMidiTune("35:4,35:4,35:4,35:4,31:4,31:4,30:4,30:4")', 5*5120);

    setTimeout('synth2.PlayMidiTune("59:4,59:8,59:8,62:8,59:4,57:8,55:2,54:2")', 2*5120);
    setTimeout('synth2.PlayMidiTune("59:8,59:4,59:8,62:8,59:4,57:8,55:8,57:4,55:8,54:2")', 3*5120);
    setTimeout('synth2.PlayMidiTune("59:4,59:8,59:8,62:8,59:4,57:8,55:2,54:2")', 4*5120);
    setTimeout('synth2.PlayMidiTune("59:8,59:4,59:8,62:8,59:4,57:8,55:8,57:4,55:8,54:2")', 5*5120);
}
Copy All       Run      

Methods

The following methods are available on the Synth object:

GetType() → string: “Synth”
Start()
Stop()
boolean
number
number: fraction (0..1)
number: milliseconds
number: seconds
number: integer: 0..125
number: frequency
number: mls
string: “Signal”, “VCA”, “VCF”
string: comma “,” separated: “note1:duration1,note2:duration2,...”
string: “Sin”, “Saw”, “Square”, “White”
syn.GetType
Returns the control class name.
syn.PlayMidiTune
Play a comma-separated sequence of “midi_note:duration” pairs.
syn.PlayNote
Plays a single note
syn.PlayTone
Plays a frequency tone.
syn.SetDelay
Change the delay effect difference
syn.SetDelayEnabled
Enables the delay effect (plays every note a second time after a given delay)
syn.SetFeedback
Adds a feedback effect when delay is enabled
syn.SetFrequency
Set the current played frequency
syn.SetNoteLength
Set the length of a whole note in seconds. Defaults to 2.56
syn.SetPhaser
Initializes the phaser effect
syn.SetPhaserDryWet
Control producing of unprocessed (0) and delayed (1) signals (whatever this means)
syn.SetPhaserEnabled
En/Disables phaser effect
syn.SetPhaserFeedback
Enables phaser feedback
syn.SetPhaserRange
Set sweep range
syn.SetPhaserRate
Set sweeps per second
syn.SetVca
Initializes the VCA
syn.SetVcaAttack
Set a time where the volume should reach a maximum
syn.SetVcaDecay
Controls time in which the volume is lowered to the sustain value
syn.SetVcaEnabled
En/Disables VCA effect
syn.SetVcaRelease
Set a time where the volume should reach a minimum
syn.SetVcaSustain
Set a basis volume
syn.SetVcf
Initialize the VCF effect
syn.SetVcfAttack
Set a time where the frequencies should reach a maximum
syn.SetVcfCutoff
Set a maximum frequency which will never be exceeded
syn.SetVcfDecay
Controls time in which the frequency is lowered to the sustain value.
syn.SetVcfDepth
Set the strength of the Vcf filter
syn.SetVcfEnabled
En/Disables VCF effect
syn.SetVcfRelease
Set a time where the volume should reach a minimum
syn.SetVcfResonance
Adds a resonance tone
syn.SetVcfSustain
Set a basis frequency
syn.SetVolume
Set the overall synthesizer volume
syn.SetWaveShape
Set the wave shape of the synthesizer
syn.Start
Start playing
syn.Stop
Stop playing
60
61
62
63
64
65
66
67
68
69
70
71