If something seems wrong or incomplete, please enter a comment at the bottom of this page.
- source - main - QA -
jssound module
Support wav, aiff, au, voc, sd2, flac, ... sound format using libsndfile and ogg vorbis using libogg and libvorbis.
jssound static members
- top - revision -
soundObject DecodeOggVorbis( stream )
Decodes a ogg vorbis sample to a sound object.
arguments:return value:1. <sub>streamObject</sub> _stream_: any object that has a Read function or that supports the NIStreamRead Native Interface ( file, socket, new Stream(buffer), ... ). For further details about stream objects, see jslang::Stream object and NativeInterface mechanism.
example:A sound object in a 16-bit per sample format.
``` LoadModule('jsstd'); LoadModule('jsio'); LoadModule('jssound');
var file = new File('41_30secOgg-q0.ogg'); var buffer = file.content; var stream = new Stream(buffer); var mySoundObject = DecodeOggVorbis(stream); Print('sample length: ', mySoundObject.length, '\n'); ```
DecodeSoundSplitChannelssoundObject DecodeSound( stream )
Decodes a sample from any supported sound format to a sound object.
arguments:return value:1. <sub>streamObject</sub> _stream_: any object that has a Read function or that supports the NIStreamRead Native Interface ( file, socket, new Stream(buffer), ... ). For further details about stream objects, see jslang::Stream object and native interface mechanism.
A sound object in a 16-bit per sample format.
Array SplitChannels( sound )
Split channels of the sound into an Array of monaural sound object.
arguments:return value:1. <sub>soundObject</sub> _sound_
An array that contains each individual channel of the sound.
Note
SoundObject concatenation can be achieved using the concat() method. This works becuase a sound object is a Blob with some extra properties.
Examples
example 1:``` LoadModule('jsstd'); LoadModule('jsio'); LoadModule('jssound');
var file = new File('41_30secOgg-q0.wav'); file.Open('r'); var pcm = DecodeSound(file); file.Close(); Print('sample length: '+pcm.length, '\n'); ```
example 2:``` LoadModule('jsstd'); LoadModule('jsio'); LoadModule('jssound');
var file = new File('41_30secOgg-q0.wav'); var buffer = file.content; var stream = new Stream(buffer); var pcm = DecodeSound(stream);
Print('sample length: '+pcm.length, '\n'); ```
class jssound::OggVorbisDecoder
- top -
revision -
The OggVorbisDecoder support ogg vorbis data format decoding.
constructor( stream )
Creates a new OggVorbisDecoder object. Seekable and non-seekable streams are supported.
arguments:example:1. <sub>streamObject</sub> _stream_: is the data stream from where encoded data are read from.
LoadModule('jsstd'); LoadModule('jsio'); LoadModule('jssound'); var file = new File('41_30secOgg-q0.ogg'); // file: http://xiph.org/vorbis/listen.html file.Open('r'); var dec = new OggVorbisDecoder( file ); Print( dec.bits, '\n' ); Print( dec.channels, '\n' ); Print( dec.rate, '\n' ); do { var block = dec.Read(10000); Print( 'frames: '+block.frames, '\n' ); } while(block);
Methods
ReadsoundObject Read( [.mdframes] )
Decodes a piece of audio data. If frames argument is omited, the whole stream is decoded.
arguments:return value:1. <sub>integer</sub> _frames_: the number of frames to decode. A frame is a sample of sound.
beware:A Blob object that has the following properties set: bits, rate, channels, frames
example:If all data has been decoded and the Read function is called again, the return expression is evaluated to
ALSE
.
LoadModule('jsstd'); LoadModule('jsio'); LoadModule('jssound'); var file = new File('41_30secOgg-q0.ogg'); // file: http://xiph.org/vorbis/listen.html file.Open('r'); var dec = new OggVorbisDecoder( file ); var block = dec.Read(10000); Print( 'rezolution: '+block.bits+' per channel', '\n' ); Print( block.channels == 2 ? 'stereo' : 'mono', '\n' ); Print( block.rate+' frames/seconds', '\n' ); Print( 'time: '+(block.frames/block.rate)+' seconds', '\n' );
Properties
inputStreambitsobject inputStream
Is the stream object where encoded audio data are read from.
rateinteger bits
Is the number of bits per frame and per channel.
channelsinteger rate
Is the number of frames per seconds of the sound.
framesinteger channels
Is the number of channels of the sound. 1 is mono, 2 is stereo.
integer frames
Is the length (in frames) of the sound. To compute the duration of the sound, use (frames/rate)
class jssound::SoundFileDecoder
- top - revision -
constructorThe SoundFileDecoder support various data format decoding. Main supported formats are: wav, aiff, au, voc, sd2, flac, ... For more information about supported formats, see http://www.mega-nerd.com/libsndfile/
constructor( stream )
Creates a new SoundFileDecoder object. Only seekable streams are supported.
arguments:example:1. <sub>streamObject</sub> _stream_: is the data stream from where encoded data are read from.
LoadModule('jsstd'); LoadModule('jsio'); LoadModule('jssound'); var file = new File('41_30secOgg-q0.wav'); // file: http://xiph.org/vorbis/listen.html file.Open('r'); var dec = new SoundFileDecoder( file ); Print( dec.bits, '\n' ); Print( dec.channels, '\n' ); Print( dec.rate, '\n' ); do { var block = dec.Read(10000); Print( 'frames: '+block.frames, '\n' ); } while(block);
Methods
ReadsoundObject Read( [.mdframes] )
Decodes a piece of audio data. If frames argument is omited, the whole stream is decoded.
arguments:return value:1. <sub>integer</sub> _frames_: the number of frames to decode. A frame is a sample of sound.
beware:A Blob object that has the following properties set: bits, rate, channels, frames
example:If all data has been decoded and the Read function is called again, the return expression is evaluated to
ALSE
.
LoadModule('jsstd'); LoadModule('jsio'); LoadModule('jssound'); var file = new File('41_30secOgg-q0.wav'); // file: http://xiph.org/vorbis/listen.html file.Open('r'); var dec = new SoundFileDecoder( file ); var block = dec.Read(10000); Print( 'rezolution: '+block.bits+' per channel', '\n' ); Print( block.channels == 2 ? 'stereo' : 'mono', '\n' ); Print( block.rate+' frames/seconds', '\n' ); Print( 'time: '+(block.frames/block.rate)+' seconds', '\n' );
Properties
inputStreambitsobject inputStream
Is the stream object where encoded audio data are read from.
rateinteger bits
Is the number of bits per frame and per channel.
channelsinteger rate
Is the number of frames per seconds of the sound.
framesinteger channels
Is the number of channels of the sound. 1 is mono, 2 is stereo.
integer frames
Is the length (in frames) of the sound. To compute the duration of the sound, use (frames/rate)
- top - main -