Module: hcje/audio

Module containing utilities for managing audio. This includes a simple synthesiser for simple music and effects which merely require a text definition of the sound and no supporting media file.

Source:

Classes

AudioManager

Members

(static, constant) Instrument :module:hcje/audio~SynthInstrument

Enumeration of some standard instrument definitions. They're not particularly accurate but can serve as a starting point.

Type:
Properties:
Name Type Description
CYMBAL module:hcje/audio~SynthInstrument

Simple cymbal.

DRUM module:hcje/audio~SynthInstrument

Approximation of drum for backbeat.

PIANO module:hcje/audio~SynthInstrument

Approximation of a piano sound.

SNARE module:hcje/audio~SynthInstrument

Approximation of a snare.

Source:

Methods

(static) getAudioManager() → {module:hcje/audio~AudioManager}

Get the internal audio manager. The first call intialises the module's internal audio manager. The returned audio manager is a singleton.

Source:
Returns:
Type
module:hcje/audio~AudioManager

Type Definitions

AudioDefinition

Definition of sound based on a media file.

Type:
  • Object
Properties:
Name Type Description
title string

Identification for music. This is used as its look up key.

url string

The url to the media file.

loop boolean

Flag determining whether the tracks loop. This is ignored when as a sound effect.

fadeSeconds number

Soft stop and start fade time. This is only used for music and ignored for sound effects.

Source:

SynthAudioDefinition

Definition of synthesised sound effect or music to play.

Type:
  • Object
Properties:
Name Type Description
title string

Identification for music. This is used in messages and the look-up key for sound effects.

bpm number

Beats per minute.

fadeSeconds number

only used for music; ignored for effects. Allows soft start and stop.

loop boolean

Flag determining whether the tracks loop. This is ignored when as a sound effect.

tracks Array.<module:hcje/audio~SynthTrack>

The individual tracks that are used to generate the music or sound effect..

Source:

SynthEnvelope

ADSR envelope for synthesised sounds. This is an array of four numbers.

  • adsr[0]: attack in seconds.
  • adsr[1]: decay in seconds.
  • adsr[2]: sustain as proportion of max gain. Note although sustain is normally in percent, for this module it is a proportion.
  • adsr[3]: release in seconds.
Type:
  • Array.<number>
Source:

SynthInstrument

Information for a synthesised instrument.

Type:
  • Object
Properties:
Name Type Description
waveform string

See OscillatorNode: type property

adsr module:hcje/audio~SynthEnvelope

ADSR envelope.

sustainTime number

Duration in seconds of the sustain in the ADSR envelope.

allowMerge boolean

Merger notes. If true, a note that is played before the previous note starts to release, will just continue at the previous sustain level if the note is the the same frequency as the previous.

sweepFactor number

Sweep the frequency to an end frequency calculated as the starting frequency times the sweepFactor.

Source:

SynthNoteSequence

The music score for synthesised sounds. Each note in the sequence is defined as follows. Characters that do not match a note expression are ignored, so spaces and | characters can be inserted as required to clarify bars. Note that characters shown in square brackets are optional; the square brackets do not form part of the notation.

  • [O]N[M][F][.][A]
    • O: octave modifier: + or -: shifts the octave for the note up or down one octave from the track octave set by the SynthTrack octave property. More than one symbol can be included, so the sequence +++ would shift a base octave up three.
    • N: note: A, B, C, D, E, F, G or ~ for a rest. These must be capital letters.
    • M: modifier: # or b for sharps and flats.
    • F: fraction of note; e.g. note duration is 1/F. Defaults to a quarter note, 4. The smallest fraction is 1/8th.
    • .: whether the note duration is dotted.
    • A: arpeggio modifier @ or $. This creates an arpeggio using up to 2 extra notes to create a triad. The @ character uses a major triad and a $ character a minor triad. Note that the note duration needs to be long enough to fit in the extra notes. An example would be "C2@".
Type:
  • string
Source:

SynthTrack

Details of an individual track in synthesised sounds.

Type:
  • Object
Properties:
Name Type Description
detune number

Value by which to detune the oscillator. See OscillatorNode detune property.

maxGain number

Maximum gain at end of attack.

instrument module:hcje/audio~SynthInstrument

The instrument for the track.

octave number

The octave for the notes. There are eight available octaves from 0 to 7 with octave 4 tuned to middle A.

notes module:hcje/audio~SynthNoteSequence

The notes to decode. If set to just the = character, the notes and instruments are copied from the previous track. Only the detune property is used to adjust the copy.

Source: