If something seems wrong or incomplete, please enter a comment at the bottom of this page.
- source - main - QA - jssound moduleSupport wav, aiff, au, voc, sd2, flac, ... sound format using libsndfile
and ogg vorbis using libogg and libvorbis.
jssound static members- top - revision - DecodeOggVorbissoundObject DecodeOggVorbis( stream )
Decodes a ogg vorbis sample to a sound object.
arguments:
- streamObject 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.
return value:
A sound object in a 16-bit per sample format.
example:
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'); DecodeSoundsoundObject DecodeSound( stream )
Decodes a sample from any supported sound format to a sound object.
arguments:
- streamObject 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.
return value:
A sound object in a 16-bit per sample format.
SplitChannelsArray SplitChannels( sound )
Split channels of the sound into an Array of monaural sound object.
arguments:
- soundObject sound
return value:
An array that contains each individual channel of the sound.
NoteSoundObject concatenation can be achieved using the concat() method. This works becuase a sound object is a Blob with some extra properties.
Examplesexample 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.
constructorconstructor( stream )
Creates a new OggVorbisDecoder object. Seekable and non-seekable streams are supported.
arguments:
- streamObject stream: is the data stream from where encoded data are read from.
example:
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); MethodsReadsoundObject Read( [frames] )
Decodes a piece of audio data. If frames argument is omited, the whole stream is decoded.
arguments:
- integer frames: the number of frames to decode. A frame is a sample of sound.
return value:
A Blob object that has the following properties set: bits, rate, channels, frames
beware:
If all data has been decoded and the Read function is called again, the return expression is evaluated to ALSE.
example:
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' ); PropertiesinputStreamobject inputStream
Is the stream object where encoded audio data are read from.
bitsinteger bits
Is the number of bits per frame and per channel.
rateinteger rate
Is the number of frames per seconds of the sound.
channelsinteger channels
Is the number of channels of the sound. 1 is mono, 2 is stereo.
framesinteger frames
Is the length (in frames) of the sound.
To compute the duration of the sound, use (frames/rate)
class jssound::SoundFileDecoder- top - revision - The 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/
constructorconstructor( stream )
Creates a new SoundFileDecoder object. Only seekable streams are supported.
arguments:
- streamObject stream: is the data stream from where encoded data are read from.
example:
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); MethodsReadsoundObject Read( [frames] )
Decodes a piece of audio data. If frames argument is omited, the whole stream is decoded.
arguments:
- integer frames: the number of frames to decode. A frame is a sample of sound.
return value:
A Blob object that has the following properties set: bits, rate, channels, frames
beware:
If all data has been decoded and the Read function is called again, the return expression is evaluated to ALSE.
example:
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' ); PropertiesinputStreamobject inputStream
Is the stream object where encoded audio data are read from.
bitsinteger bits
Is the number of bits per frame and per channel.
rateinteger rate
Is the number of frames per seconds of the sound.
channelsinteger channels
Is the number of channels of the sound. 1 is mono, 2 is stereo.
framesinteger frames
Is the length (in frames) of the sound.
To compute the duration of the sound, use (frames/rate)
- top - main -
|