Class QuantizedSpectrum

  • All Implemented Interfaces:
    org.json.simple.JSONAware

    public class QuantizedSpectrum
    extends Object
    implements org.json.simple.JSONAware
    Quantizes a float-based spectrum to byte resolution (actually, scale from -127 to 127).
    Author:
    Hendrik Schreiber
    • Constructor Detail

      • QuantizedSpectrum

        public QuantizedSpectrum​(byte[] data,
                                 float maxFloat)
        Parameters:
        data - data
        maxFloat - 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 - float
        maxFloat - 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:
        toJSONString in interface org.json.simple.JSONAware
      • toRankString

        public String toRankString()
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • toColor

        public Color toColor()
        Gives a color representation of this spectrum.
        Returns:
        color
      • getPrincipalComponents

        public float[] getPrincipalComponents()
        Transforms getData() using the transformation matrix calculated via PCA for a large body of music.
        Returns:
        principal components