My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
jssound  
jssound module
doc
Updated May 31, 2009 by sou...@gmail.com

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 -

DecodeOggVorbis

soundObject DecodeOggVorbis( stream )
Decodes a ogg vorbis sample to a sound object.
arguments:
  1. 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');

DecodeSound

soundObject DecodeSound( stream )
Decodes a sample from any supported sound format to a sound object.
arguments:
  1. 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.

SplitChannels

Array SplitChannels( sound )
Split channels of the sound into an Array of monaural sound object.
arguments:
  1. soundObject sound
return value:
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

constructor( stream )
Creates a new OggVorbisDecoder object. Seekable and non-seekable streams are supported.
arguments:
  1. 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);

Methods

Read

soundObject Read( [frames] )
Decodes a piece of audio data. If frames argument is omited, the whole stream is decoded.
arguments:
  1. 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' );

Properties

inputStream

object inputStream
Is the stream object where encoded audio data are read from.

bits

integer bits
Is the number of bits per frame and per channel.

rate

integer rate
Is the number of frames per seconds of the sound.

channels

integer channels
Is the number of channels of the sound. 1 is mono, 2 is stereo.

frames

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 -

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/

constructor

constructor( stream )
Creates a new SoundFileDecoder object. Only seekable streams are supported.
arguments:
  1. 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);

Methods

Read

soundObject Read( [frames] )
Decodes a piece of audio data. If frames argument is omited, the whole stream is decoded.
arguments:
  1. 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' );

Properties

inputStream

object inputStream
Is the stream object where encoded audio data are read from.

bits

integer bits
Is the number of bits per frame and per channel.

rate

integer rate
Is the number of frames per seconds of the sound.

channels

integer channels
Is the number of channels of the sound. 1 is mono, 2 is stereo.

frames

integer frames
Is the length (in frames) of the sound. To compute the duration of the sound, use (frames/rate)

- top - main -


Sign in to add a comment
Powered by Google Project Hosting