FileDocCategorySizeDatePackage
EQUAID3V2Frame.javaAPI Docjid3 0.4610391Sun Feb 06 18:11:15 GMT 2005org.blinkenlights.jid3.v2

EQUAID3V2Frame

public class EQUAID3V2Frame extends ID3V2Frame
author
paul Frame containing equalization information for the playback of the track.

Fields Summary
private byte
m_byAdjustmentBits
private Map
m_oFrequencyToAdjustmentMap
Constructors Summary
public EQUAID3V2Frame(byte byAdjustmentBits)
Constructor.

param
byAdjustmentBits the number of bits of precision each adjustment contains


                     
      
    
        m_byAdjustmentBits = byAdjustmentBits;
        
        m_oFrequencyToAdjustmentMap = new HashMap();
    
public EQUAID3V2Frame(InputStream oIS)

        try
        {
            ID3DataInputStream oFrameDataID3DIS = new ID3DataInputStream(oIS);
            
            // adjustment bits
            m_byAdjustmentBits = (byte)oFrameDataID3DIS.readUnsignedByte();
            
            m_oFrequencyToAdjustmentMap = new HashMap();

            // read adjustments
            while (oFrameDataID3DIS.available() > 0)
            {
                // read increment/decrement choice, and frequency
                int iIncrementAndFrequency = oFrameDataID3DIS.readBEUnsigned16();
                boolean bIncrement = (iIncrementAndFrequency & 32768) > 0;
                int iFrequency = (iIncrementAndFrequency & 32767);
                byte[] abyAdjustment = new byte[m_byAdjustmentBits/8];
                oFrameDataID3DIS.readFully(abyAdjustment);
                Adjustment oAdjustment = new Adjustment(bIncrement, iFrequency, abyAdjustment);
                m_oFrequencyToAdjustmentMap.put(new Integer(iFrequency), oAdjustment);
            }
        }
        catch (Exception e)
        {
            throw new InvalidFrameID3Exception(e);
        }
    
Methods Summary
public voidaccept(ID3Visitor oID3Visitor)

        oID3Visitor.visitEQUAID3V2Frame(this);
    
public booleanequals(java.lang.Object oOther)

        if ((oOther == null) || (!(oOther instanceof EQUAID3V2Frame)))
        {
            return false;
        }
        
        EQUAID3V2Frame oOtherEQUA = (EQUAID3V2Frame)oOther;
        
        return ((m_byAdjustmentBits == oOtherEQUA.m_byAdjustmentBits) &&
                m_oFrequencyToAdjustmentMap.equals(oOtherEQUA.m_oFrequencyToAdjustmentMap));
    
public org.blinkenlights.jid3.v2.EQUAID3V2Frame$AdjustmentgetAdjustment(int iFrequency)
Get the currently set adjustment for a given frequency.

return
the set adjustment for the given frequency, or null if no adjustment has been set for it
throws
ID3Exception if the frequency specified is outside the range from 0-32767Hz

        if ((iFrequency < 0) || (iFrequency > 32767))
        {
            throw new ID3Exception("Valid frequency range for EQUA adjustments is from 0-32767Hz.");
        }
        
        return (Adjustment)m_oFrequencyToAdjustmentMap.get(new Integer(iFrequency));
    
public bytegetAdjustmentBits()
Get the number of bits of precision for each adjustment.

return
the number of bits of precision

        return m_byAdjustmentBits;
    
public org.blinkenlights.jid3.v2.EQUAID3V2Frame$Adjustment[]getAdjustments()
Get all adjustments which have been set.

return
an array of all adjustments which have been set

        return (Adjustment[])m_oFrequencyToAdjustmentMap.values().toArray(new Adjustment[0]);
    
protected byte[]getFrameId()

        return "EQUA".getBytes();
    
public org.blinkenlights.jid3.v2.EQUAID3V2Frame$AdjustmentremoveAdjustment(int iFrequency)
Remove an existing adjustment.

param
iFrequency the frequency of the adjustment to remove
return
the removed adjustment, or null if no adjustment was set at the specified frequency
throws
ID3Exception if the frequency specified is outside the range from 0-32767Hz

        if ((iFrequency < 0) || (iFrequency > 32767))
        {
            throw new ID3Exception("Valid frequency range for EQUA adjustments is from 0-32767Hz.");
        }
        
        return (Adjustment)m_oFrequencyToAdjustmentMap.remove(new Integer(iFrequency));
    
public voidsetAdjustment(org.blinkenlights.jid3.v2.EQUAID3V2Frame$Adjustment oAdjustment)
Set an adjustment for a given frequency. A new adjustment for a given frequency will replace any existing one.

param
oAdjustment the adjustment to be set

        m_oFrequencyToAdjustmentMap.put(new Integer(oAdjustment.getFrequency()), oAdjustment);
    
public voidsetAdjustmentBits(byte byAdjustmentBits)
Set the number of bits of precision for each adjustment.

param
byAdjustmentBits the number of bits of precision

        m_byAdjustmentBits = byAdjustmentBits;
    
public java.lang.StringtoString()

        // "equalization" is misspelled in the spec
        return "Equalization: Adjustment Bits = " + m_byAdjustmentBits;
    
protected voidwriteBody(ID3DataOutputStream oIDOS)

        // adjustment bits
        oIDOS.writeUnsignedByte(m_byAdjustmentBits);
        
        // adjustments
        Adjustment[] aoAdjustment = getAdjustments();
        for (int i=0; i < aoAdjustment.length; i++)
        {
            aoAdjustment[i].write(oIDOS);
        }