codesimian
Class SlowMP3

java.lang.Object
  extended by codesimian.CS
      extended by codesimian.DefaultCS
          extended by codesimian.SlowMP3
All Implemented Interfaces:
CodeSimian, java.io.Serializable

public class SlowMP3
extends DefaultCS

Returns the audio data from an mp3 sound file, after a delay from downloading and decompressing. A window pops up while you wait and automatically closes itself when the mp3 starts.

mp3('fileNameOrURL') or mp3('fileNameOrURL' position) or mp3('fileNameOrURL' position megabyteLimit) Default position is *(count timeIncrement). Default megabyteLimit is 12.

Interpolates between data points in the mp3. Index (P(1).D()) can be any decimal number, not just integers, so the sound is smooth with decimal indexs.

A faster way (this is not done yet) would be to only uncompress the part of the mp3 being used currently, but 8/06 I havent yet figured out how to uncompress a specific part of the mp3 instead of linearly start to whenever it stops.

Because the uncompressed data is huge, only a fraction (like a minute) of an mp3 can be uncompressed into the file and played.

Examples of codesimian code:
mp3(filename) or mp3(filename timeIndex) or mp3(filename timeIndex megabyteLimit)
sound(mp3("xx.mp3")) or sound(mp3("xx.mp3" count))
Example that plays sound at half speed: sound(mp3("xx.mp3" *(.5 count)))
Example that stops decompressing when 10 megabytes have been decompressed: sound(mp3("xx.mp3" count 10))

See Also:
Serialized Form

Nested Class Summary
static interface SlowMP3.DecompressMP3Listener
          this interface should be merged with Files.DownloadListener or at least share a superinterface
static class SlowMP3.DecompressMP3Thread
          SlowMP3 should return fake mp3 data until this Thread gets the real data, so the sound player wont get impatient and turn off.
 
Field Summary
protected  float defaultMegabyteLimit
           
protected  double frequencyTranslation
          Currently all sound is played at 22khz, but mp3s have more than 22000 sound samples per second.
protected  double timeIncrement
          If countP()<2, there is no time index, so timeIndex is used and is incremented by timeIncrement each execution.
protected  double timeIndex
          timeIndex is only used if P(1) does not exist (countP()<2).
 
Fields inherited from class codesimian.CS
DESCRIPTION, END, EXECPROXY, FUEL, HEAP, JAVACODE, MYFUEL, NAME, NEWINSTANCE, NULL, PARENT, PARSEPRIORITY, PREV, TESTER
 
Constructor Summary
SlowMP3()
           
 
Method Summary
 void decompressMP3()
           
static short[] decompressMP3(byte[] mp3Bytes, SlowMP3.DecompressMP3Listener listener)
           
 java.lang.String description()
          a short description of this CS, shorter than the javadoc, but long enough to tell what the params are for.
 double DForProxy()
          D() and DForProxy() are the 2 most important functions in CS.
 java.lang.String keyword()
          For the CodeSimian language as a String.
CodeSimian language keyword, like "+" "*" "max" ">" etc.

Override this function if you want to specify a keyword other than how I derive them from the class name, like + for Add.

Some CSs might never be intended to be used in the language by their keyword.
The best example (4/05) is Num, because it is used in the language like "3.4" instead of "num()".
 java.lang.Object L(java.lang.Class c)
          can get the short[] array containing mp3 data
 double maxD()
          maximum value D() can ever return (or any of the other primitive EXECUTE functions).
 int maxP()
          Maximum quantity of Params
 double minD()
          minimum value D() can ever return (or any of the other primitive EXECUTE functions).
 int minP()
          For DForProxy().
Minimum number of parameters in param[] needed to call DForProxy().
Defines which indexs of param[] DForProxy() can use.
Functions with a different number of parameters must override this.
OVERRIDE THIS FUNCTION IF EXEC USES A DIFFERENT NUMBER OF PARAMETERS.
Default is 1.
 boolean setL(java.lang.Object o)
          can set the short[] array containing mp3 data
 
Methods inherited from class codesimian.DefaultCS
B, C, countP, decrementMyFuel, deleteP, F, fuel, getExec, getObject, heap, I, indexP, indexPName, insertB, insertC, insertD, insertF, insertI, insertJ, insertL, insertL, insertL1, insertP, insertS, insertZ, J, javaCode, LForProxy, LForProxy, myFuel, name, newInstance, objectToCS, objectToCSArray, objectToCSArray, P, prevD, prevL, PType, S, setB, setC, setCountP, setD, setD, setExec, setF, setFuel, setI, setJ, setL, setL, setL1, setMyFuel, setName, setObject, setP, setPrevExec, setS, setZ, start, toString, V, Z
 
Methods inherited from class codesimian.CS
addP, addP, addP, addP, addP, BForProxy, CForProxy, clone, cost, D, deleteP, FForProxy, IForProxy, isIllusion, javaCode, JForProxy, L, L, L, L, overwrites, parent, parsePriority, PB, PC, PD, PF, PI, PJ, PL, prevB, prevC, prevF, prevI, prevJ, prevS, prevZ, proxyOf, PS, PZ, reflect, reflect, setB, setC, setCost, setDescription, setF, setHeap, setI, setJ, setL, setL, setParent, setParsePriority, setProxyOf, setPType, setS, setTester, setZ, SForProxy, tester, VForProxy, voidReflect, ZForProxy
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

timeIndex

protected double timeIndex
timeIndex is only used if P(1) does not exist (countP()<2). P(1) is time index. (P(0) is filename.)


frequencyTranslation

protected double frequencyTranslation
Currently all sound is played at 22khz, but mp3s have more than 22000 sound samples per second. This number is how many more times. Probably they're 44khz but have 2 channels so CodeSimian sees it as 88khz. frequencyTranslation is now 4. Maybe it should be 2, but that would require CodeSimian pay attention to stereo/mono.


timeIncrement

protected double timeIncrement
If countP()<2, there is no time index, so timeIndex is used and is incremented by timeIncrement each execution.

Exactly frequencyTranslation would fix the frequency difference, but I want a decimal number to go between indexs so its a little higher


defaultMegabyteLimit

protected float defaultMegabyteLimit
Constructor Detail

SlowMP3

public SlowMP3()
Method Detail

DForProxy

public double DForProxy()
Description copied from class: CS
D() and DForProxy() are the 2 most important functions in CS. They execute this CS. All other execute functions, by default, use DForProxy instead of reinventing-the-wheel for their own type.

For example, J() calls JForProxy() which calls DForProxy(). D() calls DForProxy() directly.

Execute this CS and cast to double. D() is the main EXECUTE function. D() uses DForProxy(). DForProxy() is the main action of every CS, the most important function. By default, all other primitive EXECUTE functions defer to D.
Functions that EXECUTE this CS: L(Class) L(int,Class,int) Z() B() C() S() I() J() F() D() V()

Specified by:
DForProxy in class DefaultCS

decompressMP3

public void decompressMP3()

L

public java.lang.Object L(java.lang.Class c)
can get the short[] array containing mp3 data

Overrides:
L in class CS
See Also:
CS.Z(), CS.B(), CS.C(), CS.S(), CS.I(), CS.J(), CS.F(), CS.D()

setL

public boolean setL(java.lang.Object o)
can set the short[] array containing mp3 data

Overrides:
setL in class DefaultCS

minP

public int minP()
Description copied from class: DefaultCS
For DForProxy().
Minimum number of parameters in param[] needed to call DForProxy().
Defines which indexs of param[] DForProxy() can use.
Functions with a different number of parameters must override this.
OVERRIDE THIS FUNCTION IF EXEC USES A DIFFERENT NUMBER OF PARAMETERS.
Default is 1.

Overrides:
minP in class DefaultCS

maxP

public int maxP()
Description copied from class: CS
Maximum quantity of Params

Overrides:
maxP in class CS

minD

public double minD()
Description copied from class: CS
minimum value D() can ever return (or any of the other primitive EXECUTE functions). Default is -Double.MAX_VALUE, but functions like Math.sin(double) range from -1 to 1, so return -1.

Overrides:
minD in class CS

maxD

public double maxD()
Description copied from class: CS
maximum value D() can ever return (or any of the other primitive EXECUTE functions). Default is Double.MAX_VALUE, but functions like Math.sin(double) range from -1 to 1, so return 1.

Overrides:
maxD in class CS

keyword

public java.lang.String keyword()
Description copied from class: DefaultCS
For the CodeSimian language as a String.
CodeSimian language keyword, like "+" "*" "max" ">" etc.

Override this function if you want to specify a keyword other than how I derive them from the class name, like + for Add.

Some CSs might never be intended to be used in the language by their keyword.
The best example (4/05) is Num, because it is used in the language like "3.4" instead of "num()".
Default: Returns class name, minus package name (and its dots), and change the first letter to lowercase.

For example, CS.MaxParams does not override keyword(), which returns "maxP".

Overrides:
keyword in class DefaultCS
See Also:
CS.parent(), CS.newInstance(), CS.name()

description

public java.lang.String description()
Description copied from class: CS
a short description of this CS, shorter than the javadoc, but long enough to tell what the params are for. Example use: in automatically generated webpages for CodeSimian. Example: "returns sum of all params" for Add.

Overrides:
description in class DefaultCS

decompressMP3

public static short[] decompressMP3(byte[] mp3Bytes,
                                    SlowMP3.DecompressMP3Listener listener)