MP3:
Filter:
Classes (extension) | Libraries > MP3

MP3 : Object
ExtensionExtension

Read an MP3 file or stream, or write an MP3 file (can also read Ogg)
Source: MP3.sc

Description

This class is a wrapper for the *nix command-line tools curl and lame, making it easy to access MP3 files and MP3 (shoutcast/icecast) internet streams. This implies two caveats:

To tell this class where your system's lame and curl programs are, you can check/set the class variables (you could add a line to your startup file to set them):

For file writing, the class tells lame to expect 16-bit raw audio data at 44.1 kHz, so this is what you must output - see the example below. (The reason for writing as raw data is that the "fifo" trick excludes the possibility of the fileseeking which is required for writing soundfile headers.)

Ogg format files can be read (despite the name of the class!) as long as you have the oggdec command-line tool installed. To tell the class that it should expect an ogg file rather than an MP3, set the constructor's "format" argument (the third argument) to \ogg.

Class Methods

MP3.new(path, mode: 'readfile', format: 'mp3')

Create an audio stream from an MP3 file.

Arguments:

path

A path or URL to the MP3 data.

mode

One of \readfile to read from a file, or \readurl to read from a URL, or \writefile to write to a file. The default is \readfile.

format

Set this to \ogg if you're reading an OGG file rather than an MP3.

MP3.lamepath

MP3.lamepath = value

The path to the lame executable.

MP3.curlpath

MP3.curlpath = value

The path to the curl executable.

MP3.readToBuffer(server, path, startFrame: 0, numFrames, action, bufnum, lameopts: "")

Load a static buffer from an MP3 file into a Buffer, without streaming.

Arguments:

server

The server on which to allocate the buffer.

path

The path of the MP3 file (no URLs here).

startFrame

The first frame of the soundfile to read. The default is 0, which is the beginning of the file.

numFrames

The number of frames to read. The default is -1, which will read the whole file.

action

A Function to be evaluated once the file has been read and this Buffer's instance variables have been updated. The function will be passed this Buffer as an argument.

bufnum

An explicitly specified buffer number. Generally this is not needed.

lameopts

Additional comand-line options to pass into the lame executable.

Inherited class methods

Undocumented class methods

MP3.checkForExecutable(path, execname, varname, otherposs)

MP3.oggdecpath

MP3.oggdecpath = value

Instance Methods

.start(lameopts: "")

Begin queueing up the MP3 data, i.e. before you start your SC DiskIn/DiskOut synth.

Arguments:

lameopts

Additional comand-line options to pass into the lame executable.

.fifo

The path to stream into a Buffer.

.playing

Is the MP3 currently (still) playing? i.e. it is true if you have started the MP3 and not yet stopped it. This flag will revert back to false if the MP3 file finishes, even if you haven't called the .stop method.

.stop

Stop queueing.

.restart

Stop, and then immediately start.

.finish

Stop and clean up the stream file.

Inherited instance methods

Undocumented instance methods

.format

.lameproc

.mode

.path

.pid

.sampleRate

.sampleRate = value

Examples