Export to GitHub

jslibs - jsaudio.wiki


If something seems wrong or incomplete, please enter a comment at the bottom of this page.

- source - main - QA -

jsaudio module

Support 2D and 3D sound source and listener using OpenAL library.


class jsaudio::OalBuffer

constructor

constructor( soundBlob )

arguments:
  1. <sub>Blob</sub> _soundBlob_:

Methods

valueOf

integer valueOf()

Properties

frequency

integer frequency http://jslibs.googlecode.com/svn/wiki/readonly.png

is the frquency (in Hz) of the sound hold by the buffer.

size

integer size http://jslibs.googlecode.com/svn/wiki/readonly.png

is the size (in bytes) of the sound hold by the buffer.

bits

integer bits http://jslibs.googlecode.com/svn/wiki/readonly.png

is the resolution (in bits) of the sound hold by the buffer.

channels

integer channels http://jslibs.googlecode.com/svn/wiki/readonly.png

is the number of channels of the sound hold by the buffer.


class jsaudio::OalEffect

constructor

constructor()

Creates a new effect object.

Methods

valueOf

integer valueOf()

Returns the internal OpenAL buffer id.

Properties

type

integer type

set the type of effect represented by the Effect object. * undefined * Oal.EFFECT_EAXREVERB * Oal.EFFECT_REVERB * Oal.EFFECT_CHORUS * Oal.EFFECT_DISTORTION * Oal.EFFECT_ECHO * Oal.EFFECT_FLANGER * Oal.EFFECT_FREQUENCY_SHIFTER * Oal.EFFECT_VOCAL_MORPHER * Oal.EFFECT_PITCH_SHIFTER * Oal.EFFECT_RING_MODULATOR * Oal.EFFECT_AUTOWAH * Oal.EFFECT_COMPRESSOR * Oal.EFFECT_EQUALIZER

========(many) * real reverbDensity * real reverbDiffusion * real reverbGain * real reverbGainHF * real reverbDecayTime * real reverbDecayHFRatio * real reverbReflectionsGain * real reverbReflectionsDelay * real reverbLateReverbGain * real reverbLateReverbDelay * real reverbAirAbsorptionGainHF * real reverbRoomRolloffFactor * boolean reverbDecayHFLimit

  • integer chorusWaveform
  • integer chorusPhase
  • real chorusRate
  • real chorusDepth
  • real chorusFeedback
  • real chorusDelay

  • real distortionEdge

  • real distortionGain
  • real distortionLowpassCutoff
  • real distortionEqcenter
  • real distortionEqbandwidth

  • real echoDelay

  • real echoLrdelay
  • real echoDamping
  • real echoFeedback
  • real echoSpread

  • integer flangerWaveform

  • real flangerPhase
  • real flangerRate
  • real flangerDepth
  • real flangerFeedback
  • real flangerDelay

  • real frequencyShifterFrequency

  • integer frequencyShifterLeftDirection
  • integer frequencyShifterRightDirection

  • integer vocalMorpherPhonemea

  • integer vocalMorpherPhonemeaCoarseTuning
  • integer vocalMorpherPhonemeb
  • integer vocalMorpherPhonemebCoarseTuning
  • integer vocalMorpherWaveform
  • real vocalMorpherRate

  • integer pitchShifterCoarseTune

  • integer pitchShifterFineTune

  • real ringModulatorFrequency

  • real ringModulatorHighpassCutoff
  • integer ringModulatorWaveform

  • real autowahAttackTime

  • real autowahReleaseTime
  • real autowahResonance
  • real autowahPeakGain

  • boolean compressorOnoff

  • real equalizerLowGain

  • real equalizerLowCutoff
  • real equalizerMid1Gain
  • real equalizerMid1Center
  • real equalizerMid1Width
  • real equalizerMid2Gain
  • real equalizerMid2Center
  • real equalizerMid2Width
  • real equalizerHighGain
  • real equalizerHighCutoff

class jsaudio::OalFilter

constructor

constructor()

Creates a new filter object.

Methods

valueOf

integer valueOf()

Returns the internal OpenAL filter id.

Properties

type

integer type

set the type of filter represented by the Filter object. * undefined * Oal.FILTER_NULL * Oal.FILTER_LOWPASS * Oal.FILTER_HIGHPASS * Oal.FILTER_BANDPASS

========(many) * real lowpassGain * real lowpassGainHF

  • real highpassGain
  • real highpassGainLF

  • real bandpassGain

  • real bandpassGainLF
  • real bandpassGainHF

class jsaudio::OalListener

Properties

position

Array position

Gets or sets the position of the listener in the 3D environment.

metersPerUnit

Array metersPerUnit

Gets or sets the unit size of the 3D environment.


class jsaudio::Oal

Static functions

Open

void Open( [.md deviceName ] )

Open an audio device.

arguments:
  1. <sub>string</sub> _deviceName_: "Generic Hardware", "Generic Software", "DirectSound3D" (for legacy), "DirectSound", "MMSYSTEM"

If no device name is specified, we will attempt to use DS3D.

OpenAL API:

alcOpenDevice, alcCreateContext, alcMakeContextCurrent

Close

void Close()

Close the current audio device.

OpenAL API:

alcGetCurrentContext, alcMakeContextCurrent, alcGetContextsDevice, alcDestroyContext, alcCloseDevice

hasEfx

boolean hasEfx http://jslibs.googlecode.com/svn/wiki/readonly.png

is true if EFX extension is available.

maxAuxiliarySends

boolean maxAuxiliarySends http://jslibs.googlecode.com/svn/wiki/readonly.png

is the number of aux sends per source.

DopplerFactor

void DopplerFactor( value )

Selects the OpenAL Doppler factor value. The default Doppler factor value is 1.0 .

arguments:
  1. <sub>number</sub> _value_
OpenAL API:

alDopplerFactor

DopplerVelocity

void DopplerVelocity( value )

Selects the OpenAL Doppler velocity value. The default Doppler velocity value is 343.3 .

arguments:
  1. <sub>number</sub> _value_
OpenAL API:

alDopplerVelocity

SpeedOfSound

void SpeedOfSound( value )

Selects the OpenAL Speed of Sound value.

arguments:
  1. <sub>number</sub> _value_
OpenAL API:

alSpeedOfSound

DistanceModel

void DistanceModel( distanceModel )

arguments:
  1. <sub>integer</sub> _value_
OpenAL API:

alDistanceModel

Enable

void Enable( cap )

arguments:
  1. <sub>GLenum</sub> _cap_
OpenAL API:

alEnable

Disable

void Disable( cap )

arguments:
  1. <sub>GLenum</sub> _cap_
OpenAL API:

alDisable

IsEnabled

void IsEnabled( cap )

arguments:
  1. <sub>GLenum</sub> _cap_
OpenAL API:

alIsEnabled

GetString

boolean GetString( pname )

arguments:
  1. <sub>GLenum</sub> _pname_
return value:

value of a selected parameter.

OpenAL API:

alGetString

GetBoolean

boolean GetBoolean( pname )

arguments:
  1. <sub>ALenum</sub> _pname_
return value:

value of a selected parameter.

OpenAL API:

alGetBooleanv

GetInteger

integer | Array GetInteger( pname [.md, count] )

arguments:
  1. <sub>ALenum</sub> _pname_
  1. <sub>integer</sub> _count_: is the number of expected values. If _count_ is defined, the function will returns an array of values, else it returns a single value.
return value:

A single value or an array of values of a selected parameter.

OpenAL API:

alGetIntegerv

GetDouble

real | Array GetDouble( pname [.md, count] )

arguments:
  1. <sub>ALenum</sub> _pname_
  1. <sub>integer</sub> _count_: is the number of expected values. If _count_ is defined, the function will returns an array of values, else a single value.
return value:

single value or Array of values of the selected parameter.

OpenAL API:

alGetDoublev

Listener

void Listener( pname, params )

arguments:
  1. <sub>ALenum</sub> _pname_:
  1. <sub>Array</sub> _params_:
OpenAL API:

alListeneri, alListenerf, alListenerfv

GetListenerReal

real | Array GetListenerReal( source, pname [.md, count] )

arguments:
  1. <sub>integer</sub> _source_:
  1. <sub>ALenum</sub> _pname_:
  1. <sub>integer</sub> _count_: is the number of expected values. If _count_ is defined, the function will returns an array of values, else a single value.
return value:

single value or Array of values of the selected parameter.

OpenAL API:

alGetListenerfv

GenSource

integer GenSource()

OpenAL API:

alSourcei, alSourcef, alSourcefv

Source

void Source( source, pname, params )

arguments:
  1. <sub>integer</sub> _source_:
  1. <sub>ALenum</sub> _pname_:
  1. <sub>Array</sub> _params_:
OpenAL API:

alSourcei, alSourcef, alSourcefv

GetSourceReal

real | Array GetSourceReal( source, pname [.md, count] )

arguments:
  1. <sub>integer</sub> _source_:
  1. <sub>ALenum</sub> _pname_:
  1. <sub>integer</sub> _count_: is the number of expected values. If _count_ is defined, the function will returns an array of values, else a single value.
return value:

single value or Array of values of the selected parameter.

OpenAL API:

alGetSourcef

GetSourceInteger

real | Array GetSourceInteger( source, pname [.md, count] )

DeleteSource

void DeleteSource( source )

arguments:
  1. <sub>integer</sub> _source_: the source id.
OpenAL API:

alDeleteBuffers

SourceQueueBuffers

void SourceQueueBuffers( source, buffer | bufferArray )

arguments:
  1. <sub>integer</sub> _source_: the source id.
  1. <sub>integer</sub> _buffer_: the buffer id.
  1. <sub>Array</sub> _bufferArray_: an Array of buffer id.
OpenAL API:

alDeleteBuffers

SourceUnqueueBuffers

void SourceUnqueueBuffers( source, buffer | bufferArray )

arguments:
  1. <sub>integer</sub> _buffer_: the buffer id.
  1. <sub>Array</sub> _bufferArray_: an Array of buffer id.
OpenAL API:

alDeleteBuffers

Buffer

integer Buffer( soundObject )

Creates a new buffer and attach a sound data to it. The data comming from the soundObject is copied into the OpenAL system. undefined

Buffers containing audio data with more than one channel will be played without 3D spatialization features these formats are normally used for background music.

arguments:
  1. <sub>soundObject</sub> _sound_: a sound object that contains PCM audio data and the following properties: rate, channels and bits.
GetBufferReal

real | Array GetBufferReal( source, pname [.md, count] )

arguments:
  1. <sub>integer</sub> _source_:
  1. <sub>ALenum</sub> _pname_:
  1. <sub>integer</sub> _count_: is the number of expected values. If _count_ is defined, the function will returns an array of values, else a single value.
return value:

single value or Array of values of the selected parameter.

OpenAL API:

alGetBufferfv

GetBufferInteger

integer | Array GetBufferInteger( source, pname [.md, count] )

arguments:
  1. <sub>integer</sub> _source_:
  1. <sub>ALenum</sub> _pname_:
  1. <sub>integer</sub> _count_: is the number of expected values. If _count_ is defined, the function will returns an array of values, else a single value.
return value:

single value or Array of values of the selected parameter.

OpenAL API:

alGetBufferiv

DeleteBuffer

void DeleteBuffer( buffer )

arguments:
  1. <sub>integer</sub> _buffer_: the buffer id.
note:

Buffers that have been unqueued from all sources are UNUSED. Buffers that are UNUSED can be deleted, or changed by alBufferData commands.

OpenAL API:

alDeleteBuffers

PlaySource

void PlaySource( source )

Plays the given source.

arguments:
  1. <sub>integer</sub> _source_: the ID of the source to play.
StopSource

void StopSource( source )

Stop the given source.

arguments:
  1. <sub>integer</sub> _source_: the ID of the source to play.
PauseSource

void PauseSource( source )

Pause the given source.

arguments:
  1. <sub>integer</sub> _source_: the ID of the source to play.
RewindSource

void RewindSource( source )

Rewind the given source. set playback postiton to beginning.

arguments:
  1. <sub>integer</sub> _source_: the ID of the source to play.
GenEffect

void GenEffect()

OpenaL API:

alGenEffects

DeleteEffect

void DeleteEffect()

OpenaL API:

alGenEffects

PlaySound

void PlaySound( sound ) http://jslibs.googlecode.com/svn/wiki/deprecated.png

Plays a sound on the default playback device.

arguments:
  1. <sub>soundObject</sub> _sound_: sound object to play.

Examples

example 1:

A simple ogg player ``` LoadModule('jsio'); LoadModule('jsstd'); LoadModule('jssound'); LoadModule('jsaudio');

Oal.Open(); var decoder = new OggVorbisDecoder(new File('41_30secOgg-q0.ogg').Open(File.RDONLY)); var sourceId = Oal.GenSource();

var pcm; while ( pcm = decoder.Read(10000) ) {

var bufferId = Oal.Buffer(pcm); Oal.SourceQueueBuffers(sourceId, bufferId); if ( Oal.GetSourceInteger(sourceId, Oal.SOURCE_STATE) == Oal.INITIAL ) Oal.PlaySource(sourceId); };

var totalTime = decoder.frames/decoder.rate; var currentTimeOffset = Oal.GetSourceReal(sourceId, Oal.SEC_OFFSET); Sleep( 1000 * (totalTime - currentTimeOffset) ); ```


class jsaudio::OalSource

constructor

constructor()

Creates a new source object.

QueueBuffers

void QueueBuffers( buffer )

arguments:
  1. <sub>OalBuffer</sub> | BufferId: a Buffer Object or a buffer Id.
OpenAL API:

alDeleteBuffers

UnqueueBuffers

OalBuffer UnqueueBuffers()

OpenAL API:

alDeleteBuffers

Properties


class jsaudio::OalError

  • top -
code

integer code

OpenAL error number.

text

string text

OpenAL error literal.

const

string const

Const name of the OpenAL error.

toString

string toString

see Text().

more information

OpenAL Specification and Reference OpenAL 1.1 Specification and Reference


  • top - main -