Package com.tagtraum.audiokern
Class QuantizedSpectrum
- java.lang.Object
-
- com.tagtraum.audiokern.QuantizedSpectrum
-
- All Implemented Interfaces:
org.json.simple.JSONAware
public class QuantizedSpectrum extends Object implements org.json.simple.JSONAware
Quantizes afloat-based spectrum tobyteresolution (actually, scale from -127 to 127).- Author:
- Hendrik Schreiber
-
-
Constructor Summary
Constructors Constructor Description QuantizedSpectrum(byte[] data)QuantizedSpectrum(byte[] data, float maxFloat)QuantizedSpectrum(float[] floats)QuantizedSpectrum(float[] floats, float maxFloat)QuantizedSpectrum(QuantizedSpectrum quantizedSpectrum)QuantizedSpectrum(QuantizedSpectrum quantizedSpectrum, float maxFloat)QuantizedSpectrum(String s)QuantizedSpectrum(String s, float maxFloat)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)byte[]getBytes()Get data array in byte representation.float[]getData()float[]getPrincipalComponents()inthashCode()booleanisMapPrincipalComponentsToHSB()protected voidsetMapPrincipalComponentsToHSB(boolean mapPrincipalComponentsToHSB)bytetoByte(float f)Maps a float [0.0, maxFloat] to a byte [-127, 127].static bytetoByte(float f, float maxFloat)Maps a float [0.0, maxFloat] to a byte [-127, 127].protected byte[]toBytes(float[] floats)static byte[]toBytes(float[] floats, float maxFloat)static byte[]toBytes(String string, float maxFloat)ColortoColor()Gives a color representation of this spectrum.@NotNull StringtoDataString()floattoFloat(byte b)Maps a byte [-127, 127] to a float [0.0, maxFloat].static floattoFloat(byte b, float maxFloat)Maps a byte [-127, 127] to a float [0.0, maxFloat].protected float[]toFloats(byte[] bytes)static float[]toFloats(byte[] bytes, float maxFloat)StringtoJSONString()StringtoRankString()StringtoString()
-
-
-
Constructor Detail
-
QuantizedSpectrum
public QuantizedSpectrum(byte[] data, float maxFloat)- Parameters:
data- datamaxFloat- max float value, e.g.1f, if the floats are on a scale from 0 to 1.
-
QuantizedSpectrum
public QuantizedSpectrum(byte[] data)
-
QuantizedSpectrum
public QuantizedSpectrum(String s)
-
QuantizedSpectrum
public QuantizedSpectrum(float[] floats)
-
QuantizedSpectrum
public QuantizedSpectrum(QuantizedSpectrum quantizedSpectrum)
-
QuantizedSpectrum
public QuantizedSpectrum(String s, float maxFloat)
-
QuantizedSpectrum
public QuantizedSpectrum(float[] floats, float maxFloat)
-
QuantizedSpectrum
public QuantizedSpectrum(QuantizedSpectrum quantizedSpectrum, float maxFloat)
-
-
Method Detail
-
isMapPrincipalComponentsToHSB
public boolean isMapPrincipalComponentsToHSB()
-
setMapPrincipalComponentsToHSB
protected void setMapPrincipalComponentsToHSB(boolean mapPrincipalComponentsToHSB)
-
getData
public float[] getData()
- Returns:
- data array
-
getBytes
public byte[] getBytes()
Get data array in byte representation. Precision is less than in floats.- Returns:
- data array scaled to bytes
-
toFloats
@Contract(pure=true) protected float[] toFloats(byte[] bytes)
-
toBytes
@Contract(pure=true) protected byte[] toBytes(float[] floats)
-
toFloats
@Contract(pure=true) public static float[] toFloats(byte[] bytes, float maxFloat)
-
toBytes
@Contract(pure=true) public static byte[] toBytes(float[] floats, float maxFloat)
-
toBytes
@Contract(pure=true) public static byte[] toBytes(String string, float maxFloat)
-
toByte
public byte toByte(float f)
Maps a float [0.0, maxFloat] to a byte [-127, 127].- Parameters:
f- float- Returns:
- a byte
-
toByte
public static byte toByte(float f, float maxFloat)Maps a float [0.0, maxFloat] to a byte [-127, 127].- Parameters:
f- floatmaxFloat- maxFloat- Returns:
- a byte
-
toFloat
@Contract(pure=true) public float toFloat(byte b)
Maps a byte [-127, 127] to a float [0.0, maxFloat].- Parameters:
b- byte- Returns:
- a float
-
toFloat
@Contract(pure=true) public static float toFloat(byte b, float maxFloat)Maps a byte [-127, 127] to a float [0.0, maxFloat].- Parameters:
b- byte- Returns:
- a float
-
toDataString
@NotNull public final @NotNull String toDataString()
- Returns:
- string used for xmlencoding
-
toJSONString
public String toJSONString()
- Specified by:
toJSONStringin interfaceorg.json.simple.JSONAware
-
toRankString
public String toRankString()
-
toColor
public Color toColor()
Gives a color representation of this spectrum.- Returns:
- color
-
getPrincipalComponents
public float[] getPrincipalComponents()
- Returns:
- principal components
-
-