Home Reference Source
import MorseListener from 'morse-pro/src/morse-pro-listener.js'
public class | source

MorseListener

Direct Subclass:

MorseAdaptiveListener

A class to 'listen' for Morse code from the microphone or an audio file, filter the sound and pass timings to a decoder to convert to text.

Constructor Summary

Public Constructor
public

constructor(fftSize: number, volumeFilterMin: number, volumeFilterMax: number, frequencyFilterMin: number, frequencyFilterMax: number, volumeThreshold: number, decoder: Object, spectrogramCallback: function(), frequencyFilterCallback: function(), volumeFilterCallback: function(), volumeThresholdCallback: function(), micSuccessCallback: function(), micErrorCallback: function(), fileLoadCallback: function(), fileErrorCallback: function(), EOFCallback: function())

Member Summary

Public Members
public
public
public

decoder: *

public

defaults: {"fftSize": number, "volumeFilterMin": *, "volumeFilterMax": *, "frequencyFilterMin": number, "frequencyFilterMax": number, "volumeThreshold": number}

public

fftSize: *

public
public
public
public
public
public set

Set the minimum and maximum frequency filter values to be closely surrounding a specific frequency.

public get
public set

Set the maximum threshold on the frequency filter.

public set

Set the minimum threshold on the frequency filter.

public get
public

input: *

public

jsNode: *

public
public

maxFreq: *

public
public
public
public
public
public set

Set the maximum threshold on the volume filter.

public get
public get
public set

Set the minimum threshold on the volume filter.

public get
public set

Set the threshold used to determine if an anlaysed region has sufficient sound to be "on".

Private Members
private
private
private

Method Summary

Public Methods
public
public

fileErrorCallback(error: *)

public

fileLoadCallback(audioBuffer: *)

public

flush(on: *)

Flush the current ticks to the decoder.

public
public

@access: private

public

Load audio data from an ArrayBuffer.

public

micErrorCallback(error: *)

public
public

Play a loaded audio file (through speakers) and decode it.

public

This ScriptProcessorNode is called when it is full, we then actually look at the data in the analyserNode node to measure the volume in the frequency band of interest.

public

recordOnOrOff(soundIsOn: *)

Called each tick with whether the sound is judged to be on or off.

public

spectrogramCallback(jsonData: *)

public

Start the decoder listening to the microphone.

public

stop()

Stop listening.

public

volumeFilterCallback(jsonData: *)

public

Public Constructors

public constructor(fftSize: number, volumeFilterMin: number, volumeFilterMax: number, frequencyFilterMin: number, frequencyFilterMax: number, volumeThreshold: number, decoder: Object, spectrogramCallback: function(), frequencyFilterCallback: function(), volumeFilterCallback: function(), volumeThresholdCallback: function(), micSuccessCallback: function(), micErrorCallback: function(), fileLoadCallback: function(), fileErrorCallback: function(), EOFCallback: function()) source

Params:

NameTypeAttributeDescription
fftSize number

Size of the discrete Fourier transform to use. Must be a power of 2 >= 256 (defaults to 256). A smaller fftSize gives better time resolution but worse frequency resolution.

volumeFilterMin number
  • optional
  • default: -60

Sound less than this volume (in dB) is ignored.

volumeFilterMax number
  • optional
  • default: -30

Sound greater than this volume (in dB) is ignored.

frequencyFilterMin number
  • optional
  • default: 550

Sound less than this frequency (in Hz) is ignored.

frequencyFilterMax number
  • optional
  • default: 550

Sound greater than this frequency (in Hz) is ignored.

volumeThreshold number
  • optional
  • default: 220

If the volume is greater than this then the signal is taken as "on" (part of a dit or dah) (range 0-255).

decoder Object

An instance of a configured decoder class.

spectrogramCallback function()

Called every time fftSize samples are read. Called with a dictionary parameter: { frequencyData: output of the DFT (the real values including DC component) frequencyStep: frequency resolution in Hz timeStep: time resolution in Hz filterBinLow: index of the lowest frequency bin being analysed filterBinHigh: index of the highest frequency bin being analysed filterRegionVolume: volume in the analysed region isOn: whether the analysis detected a signal or not }

frequencyFilterCallback function()

Called when the frequency filter parameters change. Called with a dictionary parameter: { min: lowest frequency in Hz max: highest frequency in Hz } The frequencies may well be different to that which is set as they are quantised.

volumeFilterCallback function()

Called when the volume filter parameters change. Called with a dictionary parameter: { min: low volume (in dB) max: high volume (in dB) } If the set volumes are not numeric or out of range then the callback will return in range numbers.

volumeThresholdCallback function()

Called with a single number as the argument when the volume filter threshold changes.

micSuccessCallback function()

Called when the microphone has successfully been connected.

micErrorCallback function()

Called with the error as the argument if there is an error connecting to the microphone.

fileLoadCallback function()

Called with the AudioBuffer object as the argument when a file has successfully been loaded (and decoded).

fileErrorCallback function()

Called with the error as the argument if there is an error in decoding a file.

EOFCallback function()

Called when the playback of a file ends.

Public Members

public analyserNode: * source

public audioContext: * source

public decoder: * source

public defaults: {"fftSize": number, "volumeFilterMin": *, "volumeFilterMax": *, "frequencyFilterMin": number, "frequencyFilterMax": number, "volumeThreshold": number} source

public fftSize: * source

public fileAudioBuffer: * source

public flushTime: number source

public freqBins: * source

public freqStep: * source

public frequencyData: * source

public set frequencyFilter(f: number) source

Set the minimum and maximum frequency filter values to be closely surrounding a specific frequency.

public get frequencyFilterMax: * source

public set frequencyFilterMax(v: number) source

Set the maximum threshold on the frequency filter. i.e. the maximum frequency to be considered. Input validation is done to set a sensible default on non-numeric input and the value is clamped to be between zero and the current maximum frequency. The actual minimum will be the maximum frequency of the frequency bin the chosen frequency lies in. Calls the frequencyFilterCallback with the new min and max.

public set frequencyFilterMin(v: number) source

Set the minimum threshold on the frequency filter. i.e. the minimum frequency to be considered. Input validation is done to set a sensible default on non-numeric input and the value is clamped to be between zero and the current maximum frequency. The actual minimum will be the minimum frequency of the frequency bin the chosen frequency lies in. Calls the frequencyFilterCallback with the new min and max.

public get frequencyFilterMin: * source

public input: * source

public jsNode: * source

public lastSoundWasOn: boolean source

public maxFreq: * source

public notStarted: boolean source

public sampleRate: * source

public sourceNode: * source

public ticks: number source

public timeStep: * source

public set volumeFilterMax(v: number) source

Set the maximum threshold on the volume filter. i.e. the maximum volume considered to be a signal. Input validation is done to set a sensible default on non-numeric input and clamp the maximum to be zero. The volumFilterMin property is also set by this to be no more than the maximum. Calls the volumeFilterCallback with the new min and max.

public get volumeFilterMax: * source

public get volumeFilterMin: * source

public set volumeFilterMin(v: number) source

Set the minimum threshold on the volume filter. i.e. the minimum volume considered to be a signal. Input validation is done to set a sensible default on non-numeric input and clamp the maximum to be zero. The volumFilterMax property is also set by this to be no less than the minimum. Calls the volumeFilterCallback with the new min and max.

public get volumeThreshold: * source

public set volumeThreshold(v: number) source

Set the threshold used to determine if an anlaysed region has sufficient sound to be "on". Input validation is done to set a sensible default on non-numeric input and the value is clamped to be between zero and 255.

Private Members

private _filterBinHigh: * source

private _filterBinLow: * source

private _volumeThreshold: * source

Public Methods

public EOFCallback() source

public fileErrorCallback(error: *) source

Params:

NameTypeAttributeDescription
error *

public fileLoadCallback(audioBuffer: *) source

Params:

NameTypeAttributeDescription
audioBuffer *

public flush(on: *) source

Flush the current ticks to the decoder. Parameter is whether the ticks represent sound (on) or not.

Params:

NameTypeAttributeDescription
on *
  • optional

public frequencyFilterCallback(jsonData: *) source

Params:

NameTypeAttributeDescription
jsonData *

public initialiseAudioNodes() source

@access: private

public loadArrayBuffer(arrayBuffer: ArrayBuffer) source

Load audio data from an ArrayBuffer. Use a FileReader to load from a file. Calls fileLoadCallback or fileErrorCallback on success or error.

Params:

NameTypeAttributeDescription
arrayBuffer ArrayBuffer

public micErrorCallback(error: *) source

Params:

NameTypeAttributeDescription
error *

public micSuccessCallback() source

public playArrayBuffer() source

Play a loaded audio file (through speakers) and decode it. Calls EOFCallback when buffer ends.

public processSound() source

This ScriptProcessorNode is called when it is full, we then actually look at the data in the analyserNode node to measure the volume in the frequency band of interest. We don't actually use the input or output of the ScriptProcesorNode. @access: private

public recordOnOrOff(soundIsOn: *) source

Called each tick with whether the sound is judged to be on or off. If a change from on to off or off to on is detected then the number of ticks of the segment is passed to the decoder. @access: private

Params:

NameTypeAttributeDescription
soundIsOn *

public spectrogramCallback(jsonData: *) source

Params:

NameTypeAttributeDescription
jsonData *

public startListening() source

Start the decoder listening to the microphone. Calls micSuccessCallback or micErrorCallback on success or error.

public stop() source

Stop listening.

public volumeFilterCallback(jsonData: *) source

Params:

NameTypeAttributeDescription
jsonData *

public volumeThresholdCallback(volume: *) source

Params:

NameTypeAttributeDescription
volume *